Changeset 1328 for GTP/trunk/Lib/Vis/Preprocessing
- Timestamp:
- 09/11/06 00:29:47 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/Camera.cpp
r878 r1328 121 121 122 122 if (sceneGraph) 123 exporter->ExportScene(sceneGraph-> mRoot);123 exporter->ExportScene(sceneGraph->GetRoot()); 124 124 125 125 //exporter->ExportKdTree(*tree); -
GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h
r1314 r1328 64 64 KD_INTERSECTABLE, 65 65 BVH_INTERSECTABLE, 66 FACE_INTERSECTABLE66 TRIANGLE_INTERSECTABLE 67 67 }; 68 68 -
GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.cpp
r1327 r1328 1 1 #include "IntersectableWrapper.h" 2 #include "Mesh.h" 3 #include "Triangle3.h" 2 4 3 5 … … 5 7 6 8 7 AxisAlignedBox3 FaceIntersectable::GetBox() const9 AxisAlignedBox3 TriangleIntersectable::GetBox() const 8 10 { 9 11 return mItem->GetBoundingBox(); … … 11 13 12 14 13 int FaceIntersectable::CastRay(Ray &ray)15 int TriangleIntersectable::CastRay(Ray &ray) 14 16 { // TODO matt 15 17 return 0; 16 18 } 17 19 18 template<typename T> 19 bool IntersectableWrapper<T>::IsConvex() const20 21 int TriangleIntersectable::NumberOfFaces() const 20 22 { 21 return true; 22 } 23 24 template<typename T> 25 bool IntersectableWrapper<T>::IsWatertight() const 26 { 27 return true; 28 } 29 30 template<typename T> 31 float IntersectableWrapper<T>::IntersectionComplexity() 32 { 33 return 1.0f; 34 } 35 36 template<typename T> 37 int IntersectableWrapper<T>::NumberOfFaces() const 38 { 39 return 0; 40 } 41 42 template<typename T> 43 int IntersectableWrapper<T>::GetRandomSurfacePoint(Vector3 &point, 44 Vector3 &normal) 45 { 46 return 0; 47 } 48 49 template<typename T> 50 int IntersectableWrapper<T>::GetRandomVisibleSurfacePoint(Vector3 &point, 51 Vector3 &normal, 52 const Vector3 &viewpoint, 53 const int maxTries) 54 { 55 return 0; 23 return 1; 56 24 } 57 25 58 template<typename T>59 ostream &IntersectableWrapper<T>::Describe(ostream &s)60 {61 s << mItem;62 return s;63 }64 26 65 27 } -
GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.h
r1315 r1328 12 12 class BvhNode; 13 13 struct Face; 14 class Ray; 15 struct Triangle3; 16 14 17 15 18 … … 164 167 }; 165 168 166 class FaceIntersectable: public IntersectableWrapper<Face>169 class TriangleIntersectable: public IntersectableWrapper<Triangle3> 167 170 { 168 171 public: 169 FaceIntersectable(Face *item): 170 IntersectableWrapper<Face>(item) {} 172 TriangleIntersectable(Triangle3 *item): 173 IntersectableWrapper<Triangle3>(item) {} 174 175 int CastRay(Ray &ray); 176 AxisAlignedBox3 GetBox() const; 177 178 int NumberOfFaces() const; 171 179 172 180 int Type() const 173 181 { 174 return Intersectable:: FACE_INTERSECTABLE;182 return Intersectable::TRIANGLE_INTERSECTABLE; 175 183 } 176 184 }; -
GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp
r1297 r1328 798 798 } 799 799 800 } 800 801 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h
r1327 r1328 52 52 } 53 53 54 AxisAlignedBox3 GetBoundingBox() const 55 { 56 VertexIndexContainer::const_iterator vit, vit_end = (int)mVertexIndices.size(); 57 AxisAlignedBox3 box; 58 box.Initialize(); 59 60 for (vit = mVertexIndices.begin(); vit != vit_end; ++ vit) 61 { 62 box.Include(*vit); 63 } 64 65 return box; 66 } 54 //////////////////////////// 67 55 68 56 /// list of vertex pointers -
GTP/trunk/Lib/Vis/Preprocessing/src/MutualVisibility.cpp
r863 r1328 519 519 520 520 exporter->SetWireframe(); 521 // exporter->ExportScene(mSceneGraph-> mRoot);521 // exporter->ExportScene(mSceneGraph->GetRoot()); 522 522 523 523 exporter->ExportBox(mSource); -
GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.cpp
r1327 r1328 11 11 #include "ObjParser.h" 12 12 //#include "Material.h" 13 #include "Triangle3.h" 13 14 #include "Environment.h" 14 15 #include "ResourceManager.h" … … 18 19 namespace GtpVisibilityPreprocessor { 19 20 21 #define CONNECT_SEQUENTIAL_FACES 1 20 22 #define ROTATE_SCENE 0 23 21 24 // HACK 22 static void RotateMesh(Mesh *mesh) 23 { 24 VertexContainer::iterator it, it_end = mesh->mVertices.end(); 25 26 const float angle = 30.0f * PI / 180.0f; 27 const Matrix4x4 rot = RotationYMatrix(angle); 28 29 for (it = mesh->mVertices.begin(); it != it_end; ++ it) 30 { 31 (*it) = rot * (*it); 32 } 33 } 34 35 36 struct ltstr 37 { 38 bool operator()(const string s1, const string s2) const 39 { 40 return s1 < s2; 41 } 42 }; 25 static void RotateMesh(Mesh *mesh) 26 { 27 VertexContainer::iterator it, it_end = mesh->mVertices.end(); 28 29 const float angle = 30.0f * PI / 180.0f; 30 const Matrix4x4 rot = RotationYMatrix(angle); 31 32 for (it = mesh->mVertices.begin(); it != it_end; ++ it) 33 { 34 (*it) = rot * (*it); 35 } 36 } 37 38 struct ltstr 39 { 40 bool operator()(const string s1, const string s2) const 41 { 42 return s1 < s2; 43 } 44 }; 43 45 44 46 //const static int nMaxFaces = 6; 45 47 46 48 47 Face *LoadFace(char *str, 48 const VertexContainer &vertices, 49 map<int, Vector3> &hashTable) 50 { 51 // cout << "f"; 52 53 char *pch; 54 55 pch = strtok(str + 1, " "); 49 static Face *LoadFace(char *str, 50 const VertexContainer &vertices, 51 map<int, Vector3> &hashTable) 52 { 53 char *pch = strtok(str + 1, " "); 56 54 57 55 VertexIndexContainer indices; … … 59 57 { 60 58 const int index = (int)strtol(pch, NULL, 10) - 1; 61 62 59 //Debug << index << " x "; 63 60 … … 74 71 75 72 76 Mesh *CreateMesh(FaceContainer &faces, const map<int, Vector3> &hashTable) 73 static Triangle3 *LoadTriangle(char *str, 74 const VertexContainer &vertices, 75 map<int, Vector3> &hashTable) 76 { 77 char *pch = strtok(str + 1, " "); 78 79 VertexIndexContainer indices; 80 81 while (pch != NULL) 82 { 83 const int index = (int)strtol(pch, NULL, 10) - 1; 84 //Debug << index << " x "; 85 86 // store vertex in hash table 87 hashTable[index] = vertices[index]; 88 indices.push_back(index); 89 90 pch = strtok(NULL, " "); 91 } 92 //if (indices.size() > 4) return NULL; 93 94 return new Triangle3(indices[0], indices[1], indices[2]); 95 } 96 97 98 static Mesh *CreateMesh(FaceContainer &faces, 99 const map<int, Vector3> &hashTable) 77 100 { 78 101 Mesh *mesh = MeshManager::GetSingleton()->CreateResource(); … … 117 140 118 141 // HACK: associate mesh instances with triangles 119 void AssociateFacesWithInstance(MeshInstance *mi,120 vector<FaceParentInfo> &parents)142 static void AssociateFacesWithInstance(MeshInstance *mi, 143 vector<FaceParentInfo> &parents) 121 144 { 122 145 Mesh *mesh = mi->GetMesh(); … … 131 154 132 155 156 static void ProcessMesh(FaceContainer &faces, 157 map<int, Vector3> &hashTable, 158 SceneGraphNode *root, 159 vector<FaceParentInfo> *parents) 160 { 161 Mesh *mesh = CreateMesh(faces, hashTable); 162 163 // make an instance of this mesh 164 MeshInstance *mi = new MeshInstance(mesh); 165 166 if (parents) 167 { 168 AssociateFacesWithInstance(mi, *parents); 169 } 170 171 root->mGeometry.push_back(mi); 172 173 // reset tables 174 hashTable.clear(); 175 faces.clear(); 176 } 177 178 133 179 bool ObjParser::ParseFile(const string filename, 134 180 SceneGraphNode **proot, … … 139 185 if ((file = fopen(filename.c_str(), "rt")) == NULL) 140 186 return false; 141 187 cout << "here2" << endl; 142 188 map<int, Vector3> hashTable; // table associating indices with vectors 143 189 … … 169 215 case 'f': 170 216 { 217 cout << "f"; 218 #if CONNECT_SEQUENTIAL_FACES 171 219 Face *face = LoadFace(str, vertices, hashTable); 172 220 if (!face) break; 173 #if 0 221 174 222 faces.push_back(face); 223 175 224 if (faces.size() >= nMaxFaces) 176 225 { 177 Mesh *mesh = CreateMesh(faces, hashTable); 178 179 // make an instance of this mesh 180 MeshInstance *mi = new MeshInstance(mesh); 181 root->mGeometry.push_back(mi); 182 183 if (parents) 184 AssociateFacesWithInstance(mi, *parents); 185 186 // reset tables 187 hashTable.clear(); 188 faces.clear(); 226 ProcessMesh(faces, hashTable, root, parents); 189 227 } 190 228 #else 191 cout << "f";192 root->mGeometry.push_back(new FaceIntersectable(face));193 hashTable.clear();229 230 Triangle3 *triangle = LoadTriangle(str, vertices, hashTable); 231 root->mGeometry.push_back(new TriangleIntersectable(triangle)); 194 232 #endif 195 233 break; … … 200 238 } 201 239 240 #if CONNECT_SEQUENTIAL_FACES 202 241 // there could be faces remaining 203 242 if (!faces.empty()) 204 243 { 205 Mesh *mesh = CreateMesh(faces, hashTable); 206 207 // make an instance of this mesh 208 MeshInstance *mi = new MeshInstance(mesh); 209 210 if (parents) 211 AssociateFacesWithInstance(mi, *parents); 212 213 root->mGeometry.push_back(mi); 214 } 215 216 // reset tables 217 hashTable.clear(); 218 faces.clear(); 244 ProcessMesh(faces, hashTable, root, parents); 245 } 246 #endif 219 247 220 248 fclose(file); -
GTP/trunk/Lib/Vis/Preprocessing/src/Polygon3.cpp
r1076 r1328 316 316 int Polygon3::CastRay(const Ray &ray, float &t, const float nearestT) 317 317 { 318 Plane3 plane = GetSupportingPlane();319 float dot = DotProd(plane.mNormal, ray.GetDir());318 const Plane3 plane = GetSupportingPlane(); 319 const float dot = DotProd(plane.mNormal, ray.GetDir()); 320 320 321 321 // Watch for near-zero denominator 322 322 // ONLY single sided polygons!!!!! 323 323 if (dot > -Limits::Small) 324 // if (fabs(dot) < Limits::Small) 325 return Ray::NO_INTERSECTION; 324 { 325 // if (fabs(dot) < Limits::Small) 326 return Ray::NO_INTERSECTION; 327 } 326 328 327 329 t = (-plane.mD - DotProd(plane.mNormal, ray.GetLoc())) / dot; 328 330 329 331 if (t <= Limits::Small) 330 return Ray::INTERSECTION_OUT_OF_LIMITS; 331 332 if (t >= nearestT) { 333 return Ray::INTERSECTION_OUT_OF_LIMITS; // no intersection was found 332 { 333 return Ray::INTERSECTION_OUT_OF_LIMITS; 334 } 335 336 if (t >= nearestT) 337 { 338 return Ray::INTERSECTION_OUT_OF_LIMITS; // no intersection was found 334 339 } 335 340 … … 338 343 int i; 339 344 340 int paxis = plane.mNormal.DrivingAxis();345 const int paxis = plane.mNormal.DrivingAxis(); 341 346 342 347 // Project the intersection point onto the coordinate plane … … 344 349 ray.Extrap(t).ExtractVerts(&u, &v, paxis); 345 350 346 int size = (int)mVertices.size();351 const int size = (int)mVertices.size(); 347 352 348 353 mVertices.back().ExtractVerts(&u1, &v1, paxis ); … … 354 359 { 355 360 mVertices[i].ExtractVerts(&u2, &v2, paxis); 356 361 357 362 // line u1, v1, u2, v2 358 359 if ((v2 - v1)*(u1 - u) > (u2 - u1)*(v1 - v)) 363 if ((v2 - v1) * (u1 - u) > (u2 - u1)*(v1 - v)) 360 364 return Ray::NO_INTERSECTION; 361 365 362 366 u1 = u2; 363 367 v1 = v2; 364 }365 366 return Ray::INTERSECTION;368 } 369 370 return Ray::INTERSECTION; 367 371 } 368 372 … … 537 541 538 542 if ((count ++) % 2) 543 { 539 544 j = i ++; 545 } 540 546 else 547 { 541 548 j = k --; 549 } 542 550 } 543 551 } … … 575 583 } 576 584 577 } 585 586 AxisAlignedBox3 Polygon3::GetBoundingBox() const 587 { 588 VertexContainer::const_iterator vit, vit_end = mVertices.end(); 589 590 AxisAlignedBox3 box; 591 box.Initialize(); 592 593 for (vit = mVertices.begin(); vit != vit_end; ++ vit) 594 { 595 box.Include(*vit); 596 } 597 598 return box; 599 } 600 601 602 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Polygon3.h
r1076 r1328 38 38 Polygon3(MeshInstance *parent); 39 39 40 // creates an "infinite" polygon from this plane41 //Polygon3(Plane3 plane);40 ~Polygon3() {DEL_PTR(mPlane);} 41 42 42 /** Copies all the vertices of the face. 43 43 */ … … 62 62 */ 63 63 float GetArea() const; 64 65 /** Classify polygon with respect to the plane.66 @returns one of BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT67 */68 //int ClassifyPlane(const Plane3 &plane) const;69 64 70 65 /** Classify polygon with respect to the plane. … … 87 82 */ 88 83 Vector3 Center() const; 84 89 85 /** Checks if the polygon is valid, i.e., not degenerated. 90 86 @returns true if polygon is valid. … … 120 116 Polygon3 *CreateReversePolygon() const; 121 117 118 AxisAlignedBox3 GetBoundingBox() const; 119 120 //////////////////////////////////////////// 122 121 123 122 /** Classify polygons with respect to the plane. … … 127 126 const Plane3 &plane, 128 127 const float epsilon); 129 130 128 131 129 /** Counts the number of different intersectables associated with the polygons. … … 137 135 static float GetArea(const PolygonContainer &cell); 138 136 137 ////////////////////////////////////////////////////// 138 139 139 /** 140 140 Adds polygon to mesh description as a face … … 143 143 144 144 145 ////////////////////////////////////////// 145 146 146 147 /// vertices are connected in counterclockwise order. … … 156 157 RayContainer mPiercingRays; 157 158 158 ~Polygon3() {DEL_PTR(mPlane);} 159 protected: 160 159 161 Plane3 *mPlane; 162 }; 160 163 161 };162 164 163 165 // Overload << operator for C++-style output -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1299 r1328 38 38 static void AddGeometry(SceneGraph *scene) 39 39 { 40 scene-> mRoot->UpdateBox();40 scene->GetRoot()->UpdateBox(); 41 41 42 42 AxisAlignedBox3 sceneBox = scene->GetBox(); … … 62 62 63 63 MeshInstance *mi = new MeshInstance(mesh); 64 scene-> mRoot->mGeometry.push_back(mi);64 scene->GetRoot()->mGeometry.push_back(mi); 65 65 } 66 66 } … … 81 81 82 82 MeshInstance *mi = new MeshInstance(mesh); 83 scene-> mRoot->mGeometry.push_back(mi);83 scene->GetRoot()->mGeometry.push_back(mi); 84 84 } 85 85 } … … 100 100 101 101 MeshInstance *mi = new MeshInstance(mesh); 102 scene-> mRoot->mGeometry.push_back(mi);102 scene->GetRoot()->mGeometry.push_back(mi); 103 103 } 104 104 105 scene-> mRoot->UpdateBox();105 scene->GetRoot()->UpdateBox(); 106 106 } 107 107 … … 122 122 123 123 MeshInstance *planeMi = new MeshInstance(planeMesh); 124 scene-> mRoot->mGeometry.push_back(planeMi);124 scene->GetRoot()->mGeometry.push_back(planeMi); 125 125 } 126 126 } … … 136 136 mRenderSimulator(NULL), 137 137 mPass(0), 138 mRayCastMethod(0) 138 mRayCastMethod(0), 139 mSceneGraph(NULL) 139 140 { 140 141 Environment::GetSingleton()->GetBoolValue("Preprocessor.useGlRenderer", mUseGlRenderer); … … 242 243 parser = new UnigraphicsParser; 243 244 244 cout<<filename<<endl; 245 cout << filename << endl; 246 247 SceneGraphNode *sroot = mSceneGraph->GetRoot(); 245 248 246 249 if (mRayCastMethod == Preprocessor::INTEL_RAYCASTER) 247 result = parser->ParseFile(filename, &mSceneGraph->mRoot, 248 mLoadPolygonsAsMeshes, 249 &mFaceParents); 250 { cout << "here5800" << endl; 251 result = parser->ParseFile( 252 filename, 253 &sroot, 254 mLoadPolygonsAsMeshes, 255 &mFaceParents); 256 } 250 257 else 251 result = parser->ParseFile(filename, &mSceneGraph->mRoot, mLoadPolygonsAsMeshes); 252 258 { cout << "here776645" << endl; 259 result = parser->ParseFile(filename, &sroot, mLoadPolygonsAsMeshes); 260 } 261 cout << "here98809845" << endl; 253 262 delete parser; 254 263 255 264 } else { 256 265 // root for different files 257 mSceneGraph-> mRoot = new SceneGraphNode;266 mSceneGraph->SetRoot(new SceneGraphNode()); 258 267 for (int i= 0; i < filenames.size(); i++) { 259 268 if (strstr(filenames[i].c_str(), ".x3d")) … … 266 275 267 276 if (mRayCastMethod == Preprocessor::INTEL_RAYCASTER) 268 success = parser->ParseFile(filename, &node, 269 mLoadPolygonsAsMeshes, 270 &mFaceParents); 277 { cout << "here4500" << endl; 278 success = parser->ParseFile( 279 filename, 280 &node, 281 mLoadPolygonsAsMeshes, 282 &mFaceParents); 283 } 271 284 else 272 success = parser->ParseFile(filename, &node, mLoadPolygonsAsMeshes); 273 274 if (success) { 275 mSceneGraph->mRoot->mChildren.push_back(node); 276 // at least one file parsed 277 result = true; 285 { 286 cout << "here45" << endl; 287 success = parser->ParseFile(filename, &node, mLoadPolygonsAsMeshes); 288 } 289 290 if (success) 291 { cout << "here4509999" << endl; 292 mSceneGraph->GetRoot()->mChildren.push_back(node); 293 // at least one file parsed 294 result = true; 278 295 } 279 296 … … 281 298 } 282 299 } 283 284 300 cout << "here8888" << endl; 301 285 302 if (result) 286 {303 { cout << "here199" << endl; 287 304 // HACK 288 305 if (ADDITIONAL_GEOMETRY_HACK) 289 306 AddGeometry(mSceneGraph); 290 307 291 308 mSceneGraph->AssignObjectIds(); 292 309 cout << "here99" << endl; 293 310 int intersectables, faces; 294 311 mSceneGraph->GetStatistics(intersectables, faces); 295 312 cout << "here999" << endl; 296 313 cout<<filename<<" parsed successfully."<<endl; 297 314 cout<<"#NUM_OBJECTS (Total numner of objects)\n"<<intersectables<<endl; 298 315 cout<<"#NUM_FACES (Total numner of faces)\n"<<faces<<endl; 299 316 mSceneGraph->CollectObjects(&mObjects); 300 mSceneGraph-> mRoot->UpdateBox();301 317 mSceneGraph->GetRoot()->UpdateBox(); 318 cout << "here9999" << endl; 302 319 if (0) 303 320 { 304 321 Exporter *exporter = Exporter::GetExporter("testload.x3d"); 305 306 322 if (exporter) 307 323 { … … 311 327 } 312 328 } 313 314 329 315 330 return result; 316 331 } … … 356 371 // add mesh instances of the scene graph to the root of the tree 357 372 KdLeaf *root = (KdLeaf *)mKdTree->GetRoot(); 373 cout << "here3.95" << endl; 358 374 mSceneGraph->CollectObjects(&root->mObjects); 359 375 cout << "here3.97" << endl; 360 376 long startTime = GetTime(); 361 377 … … 389 405 if (exporter) { 390 406 if (scene) 391 exporter->ExportScene(mSceneGraph-> mRoot);407 exporter->ExportScene(mSceneGraph->GetRoot()); 392 408 393 409 if (kdtree) { -
GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp
r1302 r1328 278 278 // $$JB temporarily do not export the scene 279 279 if (0) 280 exporter->ExportScene(mSceneGraph-> mRoot);280 exporter->ExportScene(mSceneGraph->GetRoot()); 281 281 exporter->SetWireframe(); 282 282 … … 316 316 // $$JB temporarily do not export the scene 317 317 if (1) 318 exporter->ExportScene(mSceneGraph-> mRoot);318 exporter->ExportScene(mSceneGraph->GetRoot()); 319 319 exporter->SetWireframe(); 320 320 … … 343 343 Exporter *exporter = Exporter::GetExporter(filename); 344 344 exporter->SetFilled(); 345 exporter->ExportScene(mSceneGraph-> mRoot);345 exporter->ExportScene(mSceneGraph->GetRoot()); 346 346 // exporter->SetWireframe(); 347 347 bool result = exporter->ExportRssTree2( *tree, dir ); -
GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp
r1233 r1328 2202 2202 // exporter->ExportKdTree(*mKdTree); 2203 2203 exporter->SetWireframe(); 2204 // exporter->ExportScene(preprocessor->mSceneGraph-> mRoot);2204 // exporter->ExportScene(preprocessor->mSceneGraph->GetRoot()); 2205 2205 exporter->SetWireframe(); 2206 2206 exporter->ExportBox(box); -
GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.cpp
r1194 r1328 28 28 29 29 30 SceneGraphNode::~SceneGraphNode() 31 { 32 CLEAR_CONTAINER(mGeometry); 33 34 // recursivly delete all children 35 CLEAR_CONTAINER(mChildren); 36 } 37 38 39 /************************************************************/ 40 /* SceneGraph implementation */ 41 /************************************************************/ 42 43 44 SceneGraph::SceneGraph(): 45 mRoot(NULL) 46 { 47 } 48 49 30 50 SceneGraph::~SceneGraph() 31 51 { … … 34 54 35 55 36 SceneGraphNode ::~SceneGraphNode()56 SceneGraphNode *SceneGraph::GetRoot() 37 57 { 38 CLEAR_CONTAINER(mGeometry);39 SceneGraphNodeContainer::iterator it, it_end = mChildren.end(); 58 return mRoot; 59 } 40 60 41 // recursivly delete all children 42 CLEAR_CONTAINER(mChildren); 61 62 void SceneGraph::SetRoot(SceneGraphNode *root) 63 { 64 mRoot = root; 43 65 } 44 66 … … 48 70 { 49 71 instances->clear(); 50 int number = 0; 51 stack<SceneGraphNode *> nodeStack; 52 53 nodeStack.push(mRoot); 54 55 while (!nodeStack.empty()) { 56 SceneGraphNode *node = nodeStack.top(); 57 nodeStack.pop(); 72 int number = 0; 58 73 59 ObjectContainer::const_iterator mi = node->mGeometry.begin(); 60 for (; mi != node->mGeometry.end(); mi++) 61 instances->push_back(*mi); 62 63 SceneGraphNodeContainer::iterator ni = node->mChildren.begin(); 64 for (; ni != node->mChildren.end(); ni++) { 65 nodeStack.push(*ni); 66 number++; 67 } 68 69 } 70 return number; 74 stack<SceneGraphNode *> nodeStack; 75 nodeStack.push(mRoot); 76 77 while (!nodeStack.empty()) { 78 SceneGraphNode *node = nodeStack.top(); 79 nodeStack.pop(); 80 cout << "here3.958" << endl;cout << "here3.9587654" << endl; 81 ObjectContainer::const_iterator mi = node->mGeometry.begin(); cout << "here3.958" << endl; 82 for (; mi != node->mGeometry.end(); mi++) 83 { 84 cout << "here3.9886" << endl; 85 instances->push_back(*mi); 86 } 87 cout << "here3.969999" << endl; 88 SceneGraphNodeContainer::iterator ni = node->mChildren.begin(); 89 for (; ni != node->mChildren.end(); ni++) { 90 nodeStack.push(*ni); cout << "here3.959" << endl; 91 number++; 92 } 93 cout << "here3.96" << endl; 94 } 95 return number; 71 96 } 72 97 -
GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.h
r1166 r1328 28 28 public: 29 29 30 SceneGraph(); 30 31 ~SceneGraph(); 32 33 bool Export(const string filename); 34 35 int CollectObjects(ObjectContainer *instances); 36 37 int AssignObjectIds(); 38 39 void GetStatistics(int &intersectables, int &faces) const; 31 40 32 SceneGraphNode *mRoot; 33 bool Export(const string filename); 41 AxisAlignedBox3 GetBox() const { return mRoot->mBox; } 34 42 35 int 36 CollectObjects(ObjectContainer *instances); 37 38 int 39 AssignObjectIds(); 40 41 void 42 GetStatistics(int &intersectables, int &faces) const; 43 /** Exports binary version of the scene. 44 */ 45 void ExportScene(const string filename); 43 46 44 AxisAlignedBox3 GetBox() const { return mRoot->mBox; } 45 46 /** Exports binary version of the scene. 47 */ 48 void ExportScene(const string filename); 47 /** Loads binary version of the scene. 48 */ 49 void LoadScene(const string filename); 49 50 50 /** Loads binary version of the scene. 51 */ 52 void LoadScene(const string filename);51 SceneGraphNode *GetRoot(); 52 53 void SetRoot(SceneGraphNode *sgNnode); 53 54 54 55 protected: 56 57 SceneGraphNode *mRoot; 55 58 }; 56 59 -
GTP/trunk/Lib/Vis/Preprocessing/src/Triangle3.cpp
r863 r1328 1 1 #include "Triangle3.h" 2 #include "Ray.h" 3 #include "AxisAlignedBox3.h" 4 2 5 3 6 namespace GtpVisibilityPreprocessor { 4 7 5 float 6 Triangle3:: GetSpatialAngle(const Vector3 &point) const8 9 Triangle3::Triangle3(const Vector3 &a, const Vector3 &b, const Vector3 &c) 7 10 { 8 return 0.0f;11 Init(a, b, c); 9 12 } 10 13 14 15 void Triangle3::Init(const Vector3 &a, const Vector3 &b, const Vector3 &c) 16 { 17 mVertices[0] = a; 18 mVertices[1] = b; 19 mVertices[2] = c; 20 11 21 } 22 23 24 float Triangle3::GetSpatialAngle(const Vector3 &point) const 25 { 26 return 0.0f; 27 } 28 29 30 int Triangle3::CastRay(const Ray &ray, float &t, const float nearestT) const 31 { 32 // get triangle edge vectors and plane normal 33 const Vector3 u = mVertices[1] - mVertices[0]; 34 const Vector3 v = mVertices[2] - mVertices[0]; 35 36 const Vector3 n = u * v; // cross product 37 38 const Vector3 dir = ray.GetDir(); // ray direction vector 39 const Vector3 w0 = ray.GetLoc() - mVertices[0]; 40 41 // params to calc ray-plane intersect 42 const float a = - DotProd(n, w0); 43 const float b = DotProd(n, dir); 44 45 if (fabs(b) < Limits::Small) 46 { 47 // ray is parallel to triangle plane 48 if (a == 0) // ray lies in triangle plane 49 { 50 return Ray::INTERSECTION_OUT_OF_LIMITS; 51 } 52 else 53 { 54 return Ray::NO_INTERSECTION; // ray disjoint from plane 55 } 56 } 57 58 // get intersect point of ray with triangle plane 59 t = a / b; 60 61 if (t < 0.0) // ray goes away from triangle 62 { 63 return Ray::NO_INTERSECTION; // => no intersect 64 } 65 66 // for a segment, also test if (r > 1.0) => no intersect 67 68 // intersect point of ray and plane 69 const Vector3 pt = ray.GetLoc() + t * dir; 70 71 72 /////////////////////////////////////////////// 73 //-- is point inside triangle? 74 75 const Vector3 w = pt - mVertices[0]; 76 77 const float uu = DotProd(u, u); 78 const float uv = DotProd(u, v); 79 const float vv = DotProd(v, v); 80 81 const float wu = DotProd(w, u); 82 const float wv = DotProd(w, v); 83 const float D = uv * uv - uu * vv; 84 85 // get and test parametric coords 86 const float s = (uv * wv - vv * wu) / D; 87 88 if (s < 0.0 || s > 1.0) // pt is outside triangle 89 { 90 return Ray::NO_INTERSECTION; 91 } 92 93 const float s2 = (uv * wu - uu * wv) / D; 94 95 if (s2 < 0.0 || (s + s2) > 1.0) // pt is outside triangle 96 { 97 return Ray::NO_INTERSECTION; 98 } 99 100 return Ray::INTERSECTION; // I is in T 101 } 102 103 104 AxisAlignedBox3 Triangle3::GetBoundingBox() const 105 { 106 AxisAlignedBox3 box; 107 box.Initialize(); 108 109 box.Include(mVertices[0]); 110 box.Include(mVertices[1]); 111 box.Include(mVertices[2]); 112 113 return box; 114 } 115 116 117 Vector3 Triangle3::GetNormal() const 118 { 119 const Vector3 v1 = mVertices[0] - mVertices[1]; 120 const Vector3 v2 = mVertices[2]-mVertices[1]; 121 122 return Normalize(CrossProd(v2, v1)); 123 } 124 125 126 Vector3 Triangle3::GetCenter() const 127 { 128 return (mVertices[0] + mVertices[1] + mVertices[2]) / 3.0f; 129 } 130 131 132 float Triangle3::GetArea() const 133 { 134 Vector3 v1=mVertices[0]-mVertices[1], v2=mVertices[2]-mVertices[1]; 135 return 0.5f * Magnitude(CrossProd(v2, v1)); 136 } 137 138 139 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Triangle3.h
r860 r1328 4 4 #include "Vector3.h" 5 5 6 6 7 namespace GtpVisibilityPreprocessor { 7 8 8 struct Triangle3 { 9 10 Vector3 mVertices[3]; 11 12 Triangle3() {} 13 Triangle3(const Vector3 &a, 14 const Vector3 &b, 15 const Vector3 &c 16 ) { 17 Init(a, b, c); 18 } 9 class AxisAlignedBox3; 10 class Ray; 19 11 20 void21 Init(const Vector3 &a,22 const Vector3 &b,23 const Vector3 &c24 ) {25 mVertices[0] = a;26 mVertices[1] = b;27 mVertices[2] = c;28 29 }30 12 31 Vector3 GetNormal() const { 32 Vector3 v1=mVertices[0]-mVertices[1], v2=mVertices[2]-mVertices[1]; 33 return Normalize(CrossProd(v2,v1));34 } 13 struct Triangle3 14 { 15 Triangle3() {}; 16 Triangle3(const Vector3 &a, const Vector3 &b, const Vector3 &c); 35 17 36 Vector3 GetCenter() const { 37 return (mVertices[0] + mVertices[1] + mVertices[2])/3.0f; 38 } 18 void Init(const Vector3 &a, const Vector3 &b, const Vector3 &c); 39 19 40 float GetSpatialAngle(const Vector3 &point) const;20 Vector3 GetNormal() const; 41 21 42 float GetArea() const { 43 Vector3 v1=mVertices[0]-mVertices[1], v2=mVertices[2]-mVertices[1]; 44 return 0.5f * Magnitude(CrossProd(v2, v1)); 45 } 22 Vector3 GetCenter() const; 23 24 float GetSpatialAngle(const Vector3 &point) const; 25 26 float GetArea() const; 27 28 /// returns bounding box around this triangle 29 AxisAlignedBox3 GetBoundingBox() const; 30 31 /// Casts ray into this triangle. Returns hit 32 int CastRay(const Ray &ray, float &t, const float nearestT) const; 33 34 ////////////////////////////// 35 36 /// the triangle vertices 37 Vector3 mVertices[3]; 46 38 }; 47 39 -
GTP/trunk/Lib/Vis/Preprocessing/src/Vector3.h
r863 r1328 437 437 CrossProd (const Vector3 &A, const Vector3 &B) 438 438 { 439 return Vector3(A.y * B.z - A.z * B.y, 440 A.z * B.x - A.x * B.z, 441 A.x * B.y - A.y * B.x); 439 return 440 Vector3(A.y * B.z - A.z * B.y, 441 A.z * B.x - A.x * B.z, 442 A.x * B.y - A.y * B.x); 442 443 } 443 444 -
GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp
r1311 r1328 160 160 exporter->ExportKdTree(*mKdTree); 161 161 exporter->SetFilled(); 162 exporter->ExportScene(mSceneGraph-> mRoot);162 exporter->ExportScene(mSceneGraph->GetRoot()); 163 163 exporter->SetWireframe(); 164 164 … … 190 190 Exporter *exporter = Exporter::GetExporter(filename); 191 191 exporter->SetFilled(); 192 exporter->ExportScene(mSceneGraph-> mRoot);192 exporter->ExportScene(mSceneGraph->GetRoot()); 193 193 // exporter->SetWireframe(); 194 194 bool result = exporter->ExportVssTree2( *tree, dir ); -
GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
r1294 r1328 112 112 string result = filename; 113 113 114 int pos = filename.rfind(a, (int)filename.size() - 1);114 int pos = (int)filename.rfind(a, (int)filename.size() - 1); 115 115 if (pos == filename.size() - a.size()) { 116 116 result.replace(pos, a.size(), b); … … 149 149 150 150 if (preprocessorType == "vss") 151 151 { 152 152 preprocessor = new VssPreprocessor(); 153 153 } 154 154 else 155 155 { … … 176 176 preprocessor = new RenderSampler(); 177 177 } 178 else { 178 else 179 { 179 180 Environment::DelSingleton(); 180 181 cerr<<"Unknown preprocessor type"<<endl; … … 186 187 } 187 188 } 188 189 189 190 //////////////////////////////////////// 190 191 //-- load scene 191 192 192 193 Environment::GetSingleton()->GetStringValue("Scene.filename", buff); 193 194 string filename(buff); 194 preprocessor->LoadScene(filename); 195 195 196 if (!preprocessor->LoadScene(filename)) 197 { 198 cout << "loading file " << filename << " failed" << endl; 199 Cleanup(); 200 exit(1); 201 } 202 196 203 string rayCastFile = ReplaceSuffix(filename, ".obj", ".kdf"); 197 204 198 205 //-- initialize external ray casters 199 206 if (preprocessor->InitRayCast(rayCastFile)) 200 207 { 201 208 cout << "ray casting initialized!" << endl; 202 209 } 203 210 else 204 211 { 205 212 cout << "ray casting initialization failed" << endl; 213 Cleanup(); 206 214 exit(1); 207 215 } 208 216 cout << "here3.9" << endl; 209 217 //-- build kd tree from scene geometry 210 218 preprocessor->BuildKdTree(); 211 219 preprocessor->KdTreeStatistics(cout); 212 220 cout << "here3" << endl; 213 221 /*preprocessor->mKdTree->ExportBinTree("kd.bin.gz"); 214 222 MeshManager::GetSingleton()->ExportEntries("meshes.bin"); … … 234 242 235 243 DEL_PTR(kdTree2); 236 */ 244 */cout << "here4" << endl; 237 245 // parse view cells related options 238 246 preprocessor->PrepareViewCells(); … … 243 251 preprocessor->Export(filename + "-kdtree.x3d", false, true, false); 244 252 } 245 253 cout << "here5" << endl; 246 254 // create a preprocessor thread (note: capsulates calls to boost fuctions!) 247 255 //PreprocessorThread *pt = PreprocessorThreadFactory::Create(preprocessor);
Note: See TracChangeset
for help on using the changeset viewer.