Changeset 242 for trunk/VUT/GtpVisibilityPreprocessor/src
- Timestamp:
- 08/17/05 18:01:16 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/Camera.cpp
r191 r242 97 97 exporter->SetWireframe(); 98 98 exporter->ExportKdTree(*tree); 99 // exporter->ExportBspTree(*tree); 99 100 exporter->ExportRays(rays, 10000); 100 101 exporter->SetFilled(); -
trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h
r191 r242 9 9 10 10 class KdTree; 11 class BspTree; 11 12 class SceneGraphNode; 12 13 class Ray; … … 43 44 44 45 virtual bool 46 ExportBspTree(const BspTree &tree) = 0; 47 48 virtual bool 45 49 ExportRays(const vector<Ray> &rays, 46 50 const float length=1000, -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp
r239 r242 2 2 #include "Mesh.h" 3 3 4 #define SIDE_TOLERANCE 0.002 4 #define SIDE_TOLERANCE 0.002 // TODO: Test different values 5 5 6 Polygon3::Polygon3() 6 Polygon3::Polygon3(): mMaterial(NULL) 7 7 {} 8 8 9 Polygon3::Polygon3(const VertexContainer &vertices): mVertices(vertices) 9 Polygon3::Polygon3(const VertexContainer &vertices): mVertices(vertices), mMaterial(NULL) 10 10 {} 11 11 … … 17 17 { 18 18 mVertices.push_back(parent->mVertices[*it]); 19 mMaterial = parent->mMaterial; 20 19 21 Debug << parent->mVertices[*it] << endl; 20 22 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h
r238 r242 59 59 /// vertices are connected in counterclockwise order. 60 60 VertexContainer mVertices; 61 62 /// we can also store materials with polygons 63 Material *mMaterial; 61 64 }; 62 65 -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
r238 r242 121 121 Preprocessor::Export( const string filename, 122 122 const bool scene, 123 const bool kdtree 123 const bool kdtree, 124 const bool bsptree 124 125 ) 125 126 { … … 135 136 } 136 137 138 if (bsptree) { 139 exporter->SetWireframe(); 140 exporter->ExportBspTree(*mBspTree); 141 } 142 137 143 delete exporter; 138 144 return true; -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h
r235 r242 76 76 Export( const string filename, 77 77 const bool scene, 78 const bool kdtree 78 const bool kdtree, 79 const bool bsptree 79 80 ); 80 81 -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r223 r242 238 238 exporter->SetExportRayDensity(true); 239 239 exporter->ExportKdTree(*mKdTree); 240 exporter->ExportBspTree(*mBspTree); 241 240 242 delete exporter; 241 243 } … … 247 249 exporter->SetWireframe(); 248 250 exporter->ExportKdTree(*mKdTree); 251 exporter->ExportBspTree(*mBspTree); 249 252 250 253 for (i=0; i < pvsOut; i++) -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r241 r242 7 7 #include "Polygon3.h" 8 8 #include "Ray.h" 9 9 #include "AxisAlignedBox3.h" 10 10 #include <stack> 11 11 #include <time.h> … … 110 110 { 111 111 case Polygon3::COINCIDENT: 112 break; // do nothing112 break; // TODO: compare normals 113 113 case Polygon3::FRONT_SIDE: 114 114 frontPolys->push_back(poly); … … 676 676 } 677 677 678 AxisAlignedBox3 BspTree::GetBoundingBox() const 679 { 680 return mBox; 681 } 682 683 BspNode *BspTree::GetRoot() const 684 { 685 return mRoot; 686 } 687 678 688 void BspTree::EvaluateLeafStats(const BspTraversalData &data) 679 689 { … … 723 733 724 734 float position; 725 735 726 736 while (1) // endless loop 727 737 { … … 742 752 if (entSide < 0) 743 753 { 744 if(extSide > 0) // plane splits ray 745 { 746 node = in->GetBack(); 747 farChild = in->GetFront(); 748 } else 749 { 750 node = in->GetBack(); 754 node = in->GetBack(); 755 756 if(extSide <= 0) 751 757 continue; 752 } 753 } 758 759 farChild = in->GetFront(); // plane splits ray 760 754 761 } else if (entSide > 0) 755 762 { 756 if (extSide < 0) // plane splits ray 757 { 758 node = in->GetFront(); 759 farChild = in->GetBack(); 760 } else 761 { 762 node = in->GetFront(); 763 node = in->GetFront(); 764 765 if (extSide >= 0) 763 766 continue; 764 } 767 768 farChild = in->GetBack(); // plane splits ray 765 769 } 766 else // ray and plane are coincident // DOTO: WHATIN THIS CASE ?770 else // ray and plane are coincident // WHAT TO DO IN THIS CASE ? 767 771 { 768 //node = in->GetFront();772 node = in->GetFront(); 769 773 continue; 770 774 } 771 775 772 // case N4 or P4 773 float tdist = (position - ray.GetLoc(axis)) / ray.GetDir(axis); 774 tStack.push(RayTraversalData(farChild, extp, maxt)); 775 extp = ray.GetLoc() + ray.GetDir()*tdist; 776 maxt = tdist; 777 778 float tDist = 0; 779 extp = splitPlane->FindIntersection(entp, extp, &t); 780 776 //-- split 777 778 // push data for far child 781 779 tStack.push(BspRayTraversalData(farChild, extp, maxt)); 782 780 783 784 785 maxt = tDist; 786 } 781 // find intersection with plane between ray origin and exit point 782 extp = splitPlane->FindIntersection(ray.GetLoc(), extp, &maxt); 787 783 } else // compute intersections with objects in leaf 788 784 { … … 813 809 mint = maxt; 814 810 BspRayTraversalData &s = tStack.top(); 811 815 812 node = s.mNode; 816 813 extp = s.mExitPoint; -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r241 r242 4 4 #include "Mesh.h" 5 5 #include "Containers.h" 6 7 8 #include <queue>9 6 #include <stack> 10 7 … … 12 9 class Plane3; 13 10 //class Mesh; 14 15 //namespace GtpVisibilityPreprocessor {16 11 class BspTree; 17 12 class BspInterior; 18 13 class Polygon3; 14 class AxisAlignedBox3; 15 16 17 //namespace GtpVisibilityPreprocessor { 19 18 20 19 /** Container storing a soup of polygons used during BSP tree construction … … 245 244 void Construct(const ObjectContainer &objects); 246 245 247 int BspTree::CollectLeafPvs();246 int CollectLeafPvs(); 248 247 249 248 void CollectLeaves(vector<BspLeaf *> &leaves); 249 250 /** Returns box which bounds the whole tree. 251 */ 252 AxisAlignedBox3 GetBoundingBox()const; 253 254 /** Returns root of BSP tree. 255 */ 256 BspNode *GetRoot() const; 250 257 251 258 protected: -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
r209 r242 5 5 #include "Mesh.h" 6 6 #include "KdTree.h" 7 #include "ViewCellBsp.h" 8 #include "ViewCell.h" 9 #include "Polygon3.h"; 7 10 8 11 … … 98 101 case Intersectable::TRANSFORMED_MESH_INSTANCE: 99 102 ExportMeshInstance((MeshInstance *)object); 103 break; 104 case Intersectable::VIEWCELL: 105 ExportViewCell((ViewCell *)object); 100 106 break; 101 107 default: … … 112 118 // and use a reference to the that mesh instead 113 119 ExportMesh(object->GetMesh()); 120 } 121 122 void 123 X3dExporter::ExportViewCell(ViewCell *object) 124 { 125 if (object->GetMesh()) 126 ExportMesh(object->GetMesh()); 114 127 } 115 128 … … 183 196 } 184 197 198 199 void X3dExporter::ExportPolygon(Polygon3 *poly) 200 { 201 stream << "<Shape>" << endl; 202 stream << "<Appearance>" << endl; 203 204 // $$ tmp -> random material 205 206 float r, g, b; 207 208 if (mUseForcedMaterial) 209 { 210 r = mForcedMaterial.mDiffuseColor.r; 211 g = mForcedMaterial.mDiffuseColor.g; 212 b = mForcedMaterial.mDiffuseColor.b; 213 } 214 else if (poly->mMaterial) 215 { 216 r = poly->mMaterial->mDiffuseColor.r; 217 g = poly->mMaterial->mDiffuseColor.g; 218 b = poly->mMaterial->mDiffuseColor.b; 219 } else 220 { 221 r = RandomValue(0.5, 1.0); 222 g = RandomValue(0.5, 1.0); 223 b = RandomValue(0.5, 1.0); 224 } 225 226 stream << "<Material diffuseColor=\"" << r << " " << g << " " << b 227 << "\" specularColor=\"0.0 0.0 0.0\"/>" << endl; 228 229 stream << "</Appearance>" << endl; 230 231 232 if (mWireframe) 233 stream << "<IndexedLineSet ccw=\"TRUE\" coordIndex=\"" << endl; 234 else 235 stream << "<IndexedFaceSet ccw=\"TRUE\" coordIndex=\"" << endl; 236 237 VertexContainer::const_iterator vi = poly->mVertices.begin(); 238 239 stream << "<Coordinate point=\"" << endl; 240 241 for (; vi != poly->mVertices.end(); ++vi) 242 { 243 stream << (*vi).x << " " << (*vi).y << " " << (*vi).z; 244 stream << "," << endl; 245 } 246 247 stream<<"\" >"<<endl; 248 stream<<"</Coordinate>"<<endl; 249 250 if (mWireframe) 251 stream << "</IndexedLineSet>" << endl; 252 else 253 stream << "</IndexedFaceSet>" << endl; 254 255 stream << "</Shape>" << endl; 256 } 257 258 185 259 bool 186 260 X3dExporter::ExportBox(const AxisAlignedBox3 &box) … … 209 283 210 284 bool 211 X3dExporter::ExportKdTree(const KdTree &tree) 212 { 213 if (mExportRayDensity) { 285 X3dExporter::ExportBspTree(const BspTree &tree) 286 { 287 if (mExportRayDensity) 288 { 289 return false;//ExportKdTreeRayDensity(tree); 290 } 291 292 stack<BspNode *> tStack; 293 294 tStack.push(tree.GetRoot()); 295 296 Mesh *mesh = new Mesh; 297 298 AxisAlignedBox3 box = tree.GetBoundingBox(); 299 ExportBox(box); 300 301 while (!tStack.empty()) 302 { 303 BspNode *node = tStack.top(); 304 305 tStack.pop(); 306 307 if (!node->IsLeaf()) 308 { 309 BspInterior *interior = dynamic_cast<BspInterior *>(node); 310 311 tStack.push(interior->GetFront()); 312 tStack.push(interior->GetBack()); 313 } 314 else 315 { 316 BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 317 // NOTE: could also export polygons to see if splits work 318 if (leaf->GetViewCell()) 319 ExportViewCell(leaf->GetViewCell()); 320 } 321 } 322 323 ExportMesh(mesh); 324 delete mesh; 325 return true; 326 } 327 328 bool X3dExporter::ExportKdTree(const KdTree &tree) 329 { 330 if (mExportRayDensity) { 214 331 return ExportKdTreeRayDensity(tree); 215 332 } … … 250 367 delete mesh; 251 368 return true; 369 // TODO 370 return true; 252 371 } 253 372 -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h
r191 r242 14 14 class Intersectable; 15 15 class MeshInstance; 16 class Polygon3; 17 class ViewCell; 18 class BspTree; 16 19 17 20 class X3dExporter : public Exporter … … 34 37 ExportKdTree(const KdTree &tree); 35 38 39 bool ExportBspTree(const BspTree &tree); 40 36 41 bool 37 42 ExportScene(SceneGraphNode *root) … … 41 46 } 42 47 48 virtual void 49 ExportPolygon(Polygon3 *poly); 50 43 51 virtual bool 44 52 ExportBox(const AxisAlignedBox3 &box); … … 53 61 ExportMesh(Mesh *mesh); 54 62 63 virtual void ExportViewCell(ViewCell *viewCell); 55 64 56 65 protected: -
trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp
r237 r242 38 38 // p->mSceneGraph->Export("soda.x3d"); 39 39 if (0) { 40 p->Export(filename + "-out.x3d", true, false );41 p->Export(filename + "-kdtree.x3d", false, true );40 p->Export(filename + "-out.x3d", true, false, false); 41 p->Export(filename + "-kdtree.x3d", false, true, false); 42 42 } 43 43
Note: See TracChangeset
for help on using the changeset viewer.