Changeset 752
- Timestamp:
- 04/20/06 13:25:41 (19 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/scripts/Preprocessor.vcproj
r734 r752 20 20 Name="VCCLCompilerTool" 21 21 Optimization="0" 22 AdditionalIncludeDirectories="..\support;..\support\devil\include;..\support\zlib\include;..\include..\support;"..\include ..\support";..\include;"$(QTDIR)\include\QtCore";"$(CG_INC_PATH)";"$(QTDIR)\include";"$(QTDIR)\include\QtOpenGl";"$(QTDIR)\include\QtGui";"$(GTPDIR)\NonGTP\Zlib\include";..\..\..\..\..\..\NonGTP\Xerces;..\..\..\..\..\..\NonGTP\Devil\include "22 AdditionalIncludeDirectories="..\support;..\support\devil\include;..\support\zlib\include;..\include..\support;"..\include ..\support";..\include;"$(QTDIR)\include\QtCore";"$(CG_INC_PATH)";"$(QTDIR)\include";"$(QTDIR)\include\QtOpenGl";"$(QTDIR)\include\QtGui";"$(GTPDIR)\NonGTP\Zlib\include";..\..\..\..\..\..\NonGTP\Xerces;..\..\..\..\..\..\NonGTP\Devil\include;..\src" 23 23 PreprocessorDefinitions="WIN32;_DEBUG;_LIB" 24 24 MinimalRebuild="TRUE" … … 250 250 </File> 251 251 <File 252 RelativePath="..\src\ply.h"> 253 </File> 254 <File 255 RelativePath="..\src\plyfile.c"> 256 </File> 257 <File 258 RelativePath="..\src\PlyParser.cpp"> 259 </File> 260 <File 261 RelativePath="..\src\PlyParser.h"> 262 </File> 263 <File 252 264 RelativePath="..\src\Polygon3.cpp"> 253 265 </File> -
GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
r746 r752 1078 1078 "kd_term_min_cost=", 1079 1079 "10"); 1080 1080 1081 RegisterOption("KdTree.Termination.maxNodes", 1082 optInt, 1083 "kd_term_max_nodes=", 1084 "200000"); 1085 1081 1086 RegisterOption("KdTree.Termination.maxDepth", 1082 1087 optInt, -
GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
r746 r752 1134 1134 cb = new QCheckBox("Render errors", vbox); 1135 1135 vbox->layout()->addWidget(cb); 1136 cb->setChecked( true);1136 cb->setChecked(false); 1137 1137 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderErrors(bool))); 1138 1138 … … 1229 1229 mCutViewCells = false; 1230 1230 mCutScene = false; 1231 mRenderErrors = true;1231 mRenderErrors = false; 1232 1232 mRenderFilter = true; 1233 1233 mShowRenderCost = false; -
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
r667 r752 22 22 { 23 23 mRoot = new KdLeaf(NULL, 0); 24 environment->GetIntValue("KdTree.Termination.maxNodes", mTermMaxNodes); 24 25 environment->GetIntValue("KdTree.Termination.maxDepth", mTermMaxDepth); 25 26 environment->GetIntValue("KdTree.Termination.minCost", mTermMinCost); … … 61 62 62 63 mBox.Initialize(); 63 64 64 ObjectContainer::const_iterator mi; 65 65 for ( mi = leaf->mObjects.begin(); 66 66 mi != leaf->mObjects.end(); 67 67 mi++) { 68 mBox.Include((*mi)->GetBox()); 69 } 70 71 cout <<"KdTree Root Box:"<< mBox<<endl; 68 // cout<<(*mi)->GetBox()<<endl; 69 mBox.Include((*mi)->GetBox()); 70 } 71 72 cout <<"KdTree Root Box:"<<mBox<<endl; 72 73 mRoot = Subdivide(TraversalData(leaf, mBox, 0)); 73 74 … … 90 91 AxisAlignedBox3 backBox, frontBox; 91 92 92 93 93 while (!tStack.empty()) { 94 95 #if 0 96 if ( GetMemUsage() > maxMemory ) {94 // cout<<mStat.Nodes()<<" "<<mTermMaxNodes<<endl; 95 if (mStat.Nodes() > mTermMaxNodes) { 96 // if ( GetMemUsage() > maxMemory ) { 97 97 // count statistics on unprocessed leafs 98 98 while (!tStack.empty()) { 99 EvaluateLeafStats(tStack.top());100 tStack.pop();99 EvaluateLeafStats(tStack.top()); 100 tStack.pop(); 101 101 } 102 102 break; 103 103 } 104 #endif 105 104 105 106 106 TraversalData data = tStack.top(); 107 107 tStack.pop(); 108 108 109 109 KdNode *node = SubdivideNode((KdLeaf *) data.mNode, 110 data.mBox, 111 backBox, 112 frontBox 113 ); 114 if (result == NULL) 110 data.mBox, 111 backBox, 112 frontBox 113 ); 114 115 if (result == NULL) 115 116 result = node; 116 117 … … 146 147 int 147 148 KdTree::SelectPlane(KdLeaf *leaf, 148 149 150 149 const AxisAlignedBox3 &box, 150 float &position 151 ) 151 152 { 152 153 int axis = -1; … … 164 165 bool mOnlyDrivingAxis = false; 165 166 if (mOnlyDrivingAxis) { 166 167 168 169 170 171 172 167 axis = box.Size().DrivingAxis(); 168 costRatio = BestCostRatio(leaf, 169 box, 170 axis, 171 position, 172 objectsBack, 173 objectsFront); 173 174 } else { 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 175 costRatio = MAX_FLOAT; 176 for (int i=0; i < 3; i++) { 177 float p; 178 float r = BestCostRatio(leaf, 179 box, 180 i, 181 p, 182 objectsBack, 183 objectsFront); 184 if (r < costRatio) { 185 costRatio = r; 186 axis = i; 187 position = p; 188 } 189 } 189 190 } 190 191 191 192 if (costRatio > mMaxCostRatio) { 192 //cout<<"Too big cost ratio "<<costRatio<<endl;193 193 //cout<<"Too big cost ratio "<<costRatio<<endl; 194 axis = -1; 194 195 } 195 196 break; … … 394 395 395 396 splitCandidates->push_back(SortableEntry(SortableEntry::BOX_MIN, 396 397 398 397 box.Min(axis), 398 *mi) 399 ); 399 400 400 401 401 402 splitCandidates->push_back(SortableEntry(SortableEntry::BOX_MAX, 402 403 404 403 box.Max(axis), 404 *mi) 405 ); 405 406 } 406 407 … … 411 412 float 412 413 KdTree::BestCostRatio( 413 414 415 416 417 418 419 414 KdLeaf *node, 415 const AxisAlignedBox3 &box, 416 const int axis, 417 float &position, 418 int &objectsBack, 419 int &objectsFront 420 ) 420 421 { 421 422 … … 472 473 float sum; 473 474 if (mSahUseFaces) 474 475 sum = intersectionsLeft*lbox.SurfaceArea() + intersectionsRight*rbox.SurfaceArea(); 475 476 else 476 477 sum = objectsLeft*lbox.SurfaceArea() + objectsRight*rbox.SurfaceArea(); 477 478 478 479 // cout<<"pos="<<(*ci).value<<"\t q=("<<ql<<","<<qr<<")\t r=("<<rl<<","<<rr<<")"<<endl; … … 480 481 481 482 if (sum < minSum) { 482 483 484 485 486 483 minSum = sum; 484 position = (*ci).value; 485 486 objectsBack = objectsLeft; 487 objectsFront = objectsRight; 487 488 } 488 489 } … … 530 531 float position; 531 532 int axis; 533 532 534 533 535 while (1) { … … 538 540 539 541 if (entp[axis] <= position) { 540 541 542 543 544 545 546 547 548 542 if (extp[axis] <= position) { 543 node = in->mBack; 544 // cases N1,N2,N3,P5,Z2,Z3 545 continue; 546 } else { 547 // case N4 548 node = in->mBack; 549 farChild = in->mFront; 550 } 549 551 } 550 552 else { 551 552 553 554 555 556 557 558 559 560 553 if (position <= extp[axis]) { 554 node = in->mFront; 555 // cases P1,P2,P3,N5,Z1 556 continue; 557 } else { 558 node = in->mFront; 559 farChild = in->mBack; 560 // case P4 561 } 562 } 561 563 // $$ modification 3.5.2004 - hints from Kamil Ghais 562 564 // case N4 or P4 … … 565 567 extp = ray.GetLoc() + ray.GetDir()*tdist; 566 568 maxt = tdist; 567 } else { 568 // compute intersection with all objects in this leaf 569 KdLeaf *leaf = (KdLeaf *) node; 570 if (ray.mFlags & Ray::STORE_KDLEAVES) 571 ray.kdLeaves.push_back(leaf); 572 573 ObjectContainer::const_iterator mi; 574 for ( mi = leaf->mObjects.begin(); 575 mi != leaf->mObjects.end(); 576 mi++) { 577 Intersectable *object = *mi; 578 if (!object->Mailed() ) { 579 object->Mail(); 580 if (ray.mFlags & Ray::STORE_TESTED_OBJECTS) 581 ray.testedObjects.push_back(object); 582 hits += object->CastRay(ray); 583 } 584 } 585 586 if (hits && ray.GetType() == Ray::LOCAL_RAY) 587 if (ray.intersections[0].mT <= maxt) 588 break; 589 590 // get the next node from the stack 591 if (tStack.empty()) 592 break; 593 594 entp = extp; 595 mint = maxt; 596 if (ray.GetType() == Ray::LINE_SEGMENT && mint > 1.0f) 597 break; 598 599 RayTraversalData &s = tStack.top(); 600 node = s.mNode; 601 extp = s.mExitPoint; 602 maxt = s.mMaxT; 603 tStack.pop(); 569 } else { 570 // compute intersection with all objects in this leaf 571 KdLeaf *leaf = (KdLeaf *) node; 572 if (ray.mFlags & Ray::STORE_KDLEAVES) 573 ray.kdLeaves.push_back(leaf); 574 575 ObjectContainer::const_iterator mi; 576 for ( mi = leaf->mObjects.begin(); 577 mi != leaf->mObjects.end(); 578 mi++) { 579 Intersectable *object = *mi; 580 if (!object->Mailed() ) { 581 object->Mail(); 582 if (ray.mFlags & Ray::STORE_TESTED_OBJECTS) 583 ray.testedObjects.push_back(object); 584 hits += object->CastRay(ray); 604 585 } 586 } 587 588 if (hits && ray.GetType() == Ray::LOCAL_RAY) 589 if (ray.intersections[0].mT <= maxt) 590 break; 591 592 // get the next node from the stack 593 if (tStack.empty()) 594 break; 595 596 entp = extp; 597 mint = maxt; 598 if (ray.GetType() == Ray::LINE_SEGMENT && mint > 1.0f) 599 break; 600 601 RayTraversalData &s = tStack.top(); 602 node = s.mNode; 603 extp = s.mExitPoint; 604 maxt = s.mMaxT; 605 tStack.pop(); 606 } 605 607 } 606 608 return hits; -
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h
r512 r752 221 221 222 222 bool operator<( 223 const TraversalData &b) const {223 const TraversalData &b) const { 224 224 KdLeaf *leafa = (KdLeaf *) mNode; 225 225 KdLeaf *leafb = (KdLeaf *) b.mNode; 226 226 return 227 leafa->mObjects.size()*mBox.SurfaceArea()228 <229 leafb->mObjects.size()*b.mBox.SurfaceArea();227 leafa->mObjects.size()*mBox.SurfaceArea() 228 < 229 leafb->mObjects.size()*b.mBox.SurfaceArea(); 230 230 } 231 231 … … 514 514 515 515 516 516 int mTermMaxNodes; 517 517 float mSplitBorder; 518 518 int mTermMaxDepth; -
GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp
r750 r752 7 7 int Intersectable::sReservedMailboxes = 1; 8 8 9 struct SortableVertex { 10 11 Vector3 vertex; 12 13 int originalId; 14 int newId; 15 int finalPos; 16 17 SortableVertex() {} 18 19 SortableVertex(const Vector3 &v, 20 const int id): 21 vertex(v), 22 originalId(id), 23 newId(id) 24 {} 25 26 friend bool operator<(const SortableVertex &a, 27 const SortableVertex &b) 28 { 29 if (a.vertex.x < b.vertex.x) 30 return true; 31 else 32 if (a.vertex.x > b.vertex.x) 33 return false; 34 35 if (a.vertex.y < b.vertex.y) 36 return true; 37 else 38 if (a.vertex.y > b.vertex.y) 39 return false; 40 41 if (a.vertex.z < b.vertex.z) 42 return true; 43 else 44 // if (a.z > b.z) 45 return false; 46 47 // return false; 48 } 49 50 }; 51 9 52 void 10 53 Mesh::Preprocess() 11 54 { 12 13 14 55 Cleanup(); 56 57 mBox.Initialize(); 15 58 VertexContainer::const_iterator vi = mVertices.begin(); 16 59 for (; vi != mVertices.end(); vi++) { 17 60 mBox.Include(*vi); 18 61 } 62 19 63 20 64 /** true if it is a watertight convex mesh */ … … 28 72 cout<<"KD"; 29 73 mKdTree->Construct(); 30 74 31 75 if (mKdTree->GetRoot()->IsLeaf()) { 32 76 cout<<"d"; 33 77 delete mKdTree; 34 78 mKdTree = NULL; 35 79 } 80 } 81 } 82 83 84 void 85 Mesh::IndexVertices() 86 { 87 int i; 88 // check whether the vertices can be simplfied and reindexed 89 vector<SortableVertex> svertices(mVertices.size()); 90 91 for (i=0; i < mVertices.size(); i++) 92 svertices[i] = SortableVertex(mVertices[i], i); 93 94 sort(svertices.begin(), svertices.end()); 95 96 for (i=0; i < svertices.size() - 1; i++) 97 if (svertices[i].vertex == svertices[i+1].vertex) 98 svertices[i+1].newId = svertices[i].newId; 99 100 // remove the same vertices 101 int k = 0; 102 mVertices[0] = svertices[0].vertex; 103 svertices[0].finalPos = 0; 104 105 for (i=1; i < svertices.size(); i++) { 106 if (svertices[i].newId != svertices[i-1].newId) 107 k++; 108 109 mVertices[k] = svertices[i].vertex; 110 svertices[i].finalPos = k; 111 } 112 113 mVertices.resize(k + 1); 114 115 vector<int> remapBuffer(svertices.size()); 116 for (i = 0; i < svertices.size(); i++) 117 remapBuffer[svertices[i].originalId] = svertices[i].finalPos; 118 119 // remap all faces 120 121 for (int faceIndex = 0; faceIndex < mFaces.size(); faceIndex++) { 122 Face *face = mFaces[faceIndex]; 123 for (int i = 0; i < face->mVertexIndices.size(); i++) { 124 face->mVertexIndices[i] = remapBuffer[face->mVertexIndices[i]]; 125 } 36 126 } 37 127 } … … 49 139 return box; 50 140 } 51 52 141 53 142 int … … 251 340 ExtractVerts(&u1, &v1, paxis ); 252 341 342 //$$JB changed 12.4.2006 from 0 ^^ 253 343 if (0 && size <= 4) { 254 344 // assume a convex face … … 463 553 } 464 554 555 void 556 Mesh::AssignRandomMaterial() 557 { 558 if (!mMaterial) 559 mMaterial = new Material; 560 *mMaterial = RandomMaterial(); 561 562 } 465 563 466 564 -
GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h
r750 r752 18 18 19 19 /// vertex index container 20 typedef std::vector< int> VertexIndexContainer;20 typedef std::vector<short> VertexIndexContainer; 21 21 22 22 23 23 /** Patch used as an element of the mesh */ 24 class Face { 24 struct Face { 25 25 26 public: 26 27 Face(): mVertexIndices() {} 28 27 29 Face(const int a, const int b, const int c):mVertexIndices(3) { 28 30 mVertexIndices[0] = a; … … 39 41 } 40 42 41 Face(const VertexIndexContainer &vertices):mVertexIndices(vertices) {} 43 Face(const VertexIndexContainer &vertices):mVertexIndices(vertices.size()) { 44 for (int i=0; i < vertices.size(); i++) 45 mVertexIndices[i] = vertices[i]; 46 } 42 47 43 48 /// list of vertex pointers … … 74 79 delete mFaces[i]; 75 80 } 76 81 82 83 void Clear() { 84 mVertices.clear(); 85 mFaces.clear(); 86 } 87 88 void IndexVertices(); 89 90 void AssignRandomMaterial(); 77 91 void AddTriangle(const Triangle3 &triangle); 78 92 void AddRectangle(const Rectangle3 &triangle); … … 155 169 return s<<"Mesh #vertices="<<(int)mVertices.size()<<" #faces="<<(int)mFaces.size(); 156 170 } 157 171 158 172 friend Mesh *CreateBox(const AxisAlignedBox3 &box); 159 173 }; -
GTP/trunk/Lib/Vis/Preprocessing/src/MeshKdTree.cpp
r469 r752 291 291 int 292 292 MeshKdTree::CastRay( 293 294 295 293 Ray &ray, 294 MeshInstance *instance 295 ) 296 296 { 297 297 int hits = 0; … … 303 303 304 304 AxisAlignedBox3 box = GetBox(); 305 305 306 if (!box.GetMinMaxT(ray, &mint, &maxt)) 306 307 return 0; … … 308 309 if (mint < 0) 309 310 mint = 0; 310 311 312 313 314 315 316 311 312 313 if (ray.GetType() == Ray::LOCAL_RAY && 314 ray.intersections.size() && ray.intersections[0].mT < mint) { 315 return 0; 316 } 317 317 318 maxt += Limits::Threshold; 318 319 … … 324 325 float position; 325 326 int axis; 326 327 327 328 while (1) { 328 329 if (!node->IsLeaf()) { -
GTP/trunk/Lib/Vis/Preprocessing/src/PlyParser.cpp
r749 r752 2 2 using namespace std; 3 3 #include <ply.h> 4 #include <stdio.h> 4 5 5 6 #include "PlyParser.h" … … 9 10 10 11 11 12 12 // int facesPerMesh = 100000000; 13 int facesPerMesh = 30; 14 bool useRandomMaterial = false; 15 bool indexVertices = true; 13 16 14 17 /* user's vertex and face definitions for a polygonal object */ … … 33 36 }; 34 37 38 35 39 PlyProperty vert_props[] = { /* list of property information for a vertex */ 36 40 {"x", PLY_FLOAT, PLY_FLOAT, offsetof(Vertex,x), 0, 0, 0, 0}, … … 47 51 static PlyFace **flist; 48 52 53 49 54 bool 50 PlyParser::ParseFile(const string filename, 51 SceneGraphNode **root, 52 const bool loadPolygonsAsMeshes) 55 PlyParser::ParseSingleFile(const string filename, 56 SceneGraphNode *root) 53 57 { 54 55 /* user's vertex and face definitions for a polygonal object */ 58 /*** the PLY object ***/ 59 int nverts; 60 Vertex **vlist; 61 PlyOtherElems *other_elements = NULL; 62 PlyOtherProp *vert_other; 63 int nelems; 64 char **elist; 65 int num_comments; 66 char **comments; 67 int num_obj_info; 68 char **obj_info; 69 int file_type; 56 70 57 58 59 typedef double Matrix[4][4]; 60 61 /*** the PLY object ***/ 62 63 int nverts; 64 Vertex **vlist; 65 PlyOtherElems *other_elements = NULL; 66 PlyOtherProp *vert_other; 67 int nelems; 68 char **elist; 69 int num_comments; 70 char **comments; 71 int num_obj_info; 72 char **obj_info; 73 int file_type; 74 75 int i,j; 76 PlyFile *ply; 77 int nprops; 78 int num_elems; 79 PlyProperty **plist; 80 char *elem_name; 81 float version; 82 71 int i,j; 72 PlyFile *ply; 73 int nprops; 74 int num_elems; 75 PlyProperty **plist; 76 char *elem_name; 77 float version; 78 83 79 84 80 /*** Read in the original PLY object ***/ … … 169 165 ply_close (ply); 170 166 171 172 173 174 *root = new SceneGraphNode; 175 SceneGraphNode *currentNode = *root; 176 177 178 cerr<<"Baking faces into eshes"<<endl; 167 SceneGraphNode *currentNode = root; 168 169 cerr<<"Baking faces into meshes"<<endl; 170 179 171 // bake the faces into meshes 180 Mesh *mesh = NULL; 181 int facesPerMesh = 100; 172 Mesh meshProxy; 173 // only one face per mesh 174 VertexContainer vertices; 175 182 176 for (i = 0; i < nfaces; i++) { 183 177 if (i % facesPerMesh == 0) { 184 if (mesh) { 185 mesh->Preprocess; 186 // make an instance of this mesh 187 MeshInstance *mi = new MeshInstance(mesh); 188 currentNode->mGeometry.push_back(mi); 189 } 190 mesh = new Mesh(); 178 if (meshProxy.mFaces.size()) { 179 180 if (indexVertices) 181 meshProxy.IndexVertices(); 182 183 Mesh *mesh = new Mesh(meshProxy.mVertices.size(), 184 meshProxy.mFaces.size()); 185 186 187 // cout<<"C="<<mesh->mVertices.capacity(); 188 mesh->mVertices = meshProxy.mVertices; 189 // cout<<" NC="<<mesh->mVertices.capacity()<<" S="<<mesh->mVertices.size()<<endl; 190 191 mesh->mFaces = meshProxy.mFaces; 192 193 if (useRandomMaterial) 194 mesh->AssignRandomMaterial(); 195 196 mesh->Preprocess(); 197 // make an instance of this mesh 198 MeshInstance *mi = new MeshInstance(mesh); 199 currentNode->mGeometry.push_back(mi); 191 200 } 201 202 meshProxy.Clear(); 203 } 192 204 193 194 195 196 197 198 199 vc.push_back(mesh->mVertices.size());200 mesh->mVertices.push_back(Vector3(v->x, v->y, v->z));201 202 203 mesh->mFaces.push_back(new Face(vc));205 // only one face per mesh 206 VertexIndexContainer vc; 207 208 // add vertices 209 for (int k = 0; k < flist[i]->nverts; k++) { 210 Vertex *v = vlist[flist[i]->verts[k]]; 211 vc.push_back(meshProxy.mVertices.size()); 212 meshProxy.mVertices.push_back(Vector3(v->x, v->y, v->z)); 213 } 214 215 meshProxy.mFaces.push_back(new Face(vc)); 204 216 } 205 217 218 if (meshProxy.mFaces.size()) { 219 220 if (indexVertices) 221 meshProxy.IndexVertices(); 222 223 Mesh *mesh = new Mesh(meshProxy.mVertices.size(), 224 meshProxy.mFaces.size()); 225 226 mesh->mVertices = meshProxy.mVertices; 227 228 mesh->mFaces = meshProxy.mFaces; 229 230 if (useRandomMaterial) 231 mesh->AssignRandomMaterial(); 232 233 mesh->Preprocess(); 234 // make an instance of this mesh 235 MeshInstance *mi = new MeshInstance(mesh); 236 currentNode->mGeometry.push_back(mi); 237 } 238 239 // make sure that no face gets deleted by the destructor! 240 meshProxy.Clear(); 241 206 242 for (i=0; i < nverts; i++) 207 243 free(vlist[i]); 244 208 245 free(vlist); 209 246 210 247 for (i=0; i < nfaces; i++) 211 248 free(flist[i]); 249 212 250 free(flist); 213 251 214 252 215 253 return true; 254 255 216 256 } 257 258 bool 259 PlyParser::ParseFile(const string filename, 260 SceneGraphNode **root, 261 const bool loadPolygonsAsMeshes) 262 { 263 vector<string> filelist; 264 265 if (strstr(filename.c_str(), ".plb")) { 266 // parse the filelist 267 FILE *f = fopen(filename.c_str(), "rt"); 268 char s[64]; 269 if (!f) { 270 cerr<<"Cannot open .plb file"<<endl; 271 exit(1); 272 } 273 while (fgets(s,64,f)) { 274 // remove nl 275 s[strlen(s)-1] = 0; 276 filelist.push_back(s); 277 } 278 fclose(f); 279 280 } else 281 filelist.push_back(filename); 282 283 *root = new SceneGraphNode; 284 285 for (int i=0; i < filelist.size(); i++) { 286 if (!ParseSingleFile(filelist[i], *root)) { 287 cerr<<"Ply parse error. Quiting ...\n"; 288 exit(1); 289 } 290 } 291 return true; 292 } -
GTP/trunk/Lib/Vis/Preprocessing/src/PlyParser.h
r749 r752 17 17 18 18 bool ParseFile(const string filename, ViewCellsManager &viewCells) { return false; } 19 19 20 bool 21 ParseSingleFile(const string filename, 22 SceneGraphNode *root); 23 20 24 }; 21 25 -
GTP/trunk/Lib/Vis/Preprocessing/src/Polygon3.h
r750 r752 12 12 class Polygon3; 13 13 class Plane3; 14 classFace;14 struct Face; 15 15 class Intersectable; 16 16 class AxisAlignedBox3; -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r750 r752 19 19 static void AddGeometry(SceneGraph *scene) 20 20 { 21 scene->mRoot->UpdateBox(); 22 21 23 AxisAlignedBox3 sceneBox = scene->GetBox(); 22 24 … … 131 133 Preprocessor::~Preprocessor() 132 134 { 133 Debug<<"Deleting view cells manager...\n"; 135 cout << "cleaning up" << endl; 136 137 cout << "Deleting view cells manager ... \n"; 134 138 DEL_PTR(mViewCellsManager); 135 Debug<<"done.\n"; 136 Debug<<"Deleting bsp tree...\n"; 139 cout << "done.\n"; 140 141 cout << "Deleting bsp tree ... \n"; 137 142 DEL_PTR(mBspTree); 138 Debug<<"done.\n"; 139 Debug<<"Deleting kd tree...\n"; 143 cout << "done.\n"; 144 145 cout<<"Deleting kd tree...\n"; 140 146 DEL_PTR(mKdTree); 141 Debug<<"done.\n"; 142 Debug<<"Deleting vspkd tree...\n"; 147 cout<<"done.\n"; 148 149 cout<<"Deleting vspkd tree...\n"; 143 150 DEL_PTR(mVspKdTree); 144 Debug<<"done.\n"; 145 Debug<<"Deleting vspbsp tree...\n"; 151 cout<<"done.\n"; 152 153 cout<<"Deleting vspbsp tree...\n"; 146 154 DEL_PTR(mVspBspTree); 147 Debug<<"done.\n";155 cout<<"done.\n"; 148 156 } 149 157 … … 213 221 214 222 215 if (result) {216 // HACK217 mSceneGraph->mRoot->UpdateBox();218 AddGeometry(mSceneGraph);223 if (result) 224 { 225 // HACK 226 //AddGeometry(mSceneGraph); 219 227 mSceneGraph->AssignObjectIds(); 228 220 229 int intersectables, faces; 221 230 mSceneGraph->GetStatistics(intersectables, faces); 231 222 232 cout<<filename<<" parsed successfully."<<endl; 223 233 cout<<"#NUM_OBJECTS (Total numner of objects)\n"<<intersectables<<endl; 224 234 cout<<"#NUM_FACES (Total numner of faces)\n"<<faces<<endl; 225 235 mSceneGraph->CollectObjects(&mObjects); 226 //mSceneGraph->mRoot->UpdateBox();236 mSceneGraph->mRoot->UpdateBox(); 227 237 228 238 /* Exporter *exporter = Exporter::GetExporter("testload.x3d"); -
GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h
r713 r752 90 90 */ 91 91 int AddPvs(const Pvs<T> &pvs); 92 92 93 /** Subtracts one pvs from another one. 94 WARNING: could contains bugs 93 95 @returns new pvs size 94 96 */ … … 113 115 float &pvsEnlargement); 114 116 117 118 /** Clears the pvs. 119 */ 120 void Clear(); 115 121 116 122 /** Compute continuous PVS difference */ … … 237 243 } 238 244 245 template <typename T> void Pvs<T>::Clear() 246 { 247 mEntries.clear(); 248 249 250 } 251 252 239 253 template <typename T> 240 254 PvsData<T> *Pvs<T>::Find(T sample) -
GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp
r746 r752 67 67 } 68 68 break; 69 69 70 default: 70 71 result = Preprocessor::GenerateRays(number, sampleType, rays); … … 80 81 ) 81 82 { 82 for (int i=0; i < rays.size(); i++) 83 for (int i=0; i < rays.size(); i++) { 83 84 CastRay(rays[i].mOrigin, rays[i].mDirection, rays[i].mPdf, vssRays); 85 if (i % 10000 == 0) 86 cout<<"."; 87 } 88 cout<<endl; 84 89 } 85 90 … … 298 303 exporter->SetFilled(); 299 304 // $$JB temporarily do not export the scene 300 if ( 1)305 if (0) 301 306 exporter->ExportScene(mSceneGraph->mRoot); 302 307 exporter->SetWireframe(); … … 435 440 { 436 441 // compute rendering error 437 if (renderer ) {442 if (renderer && renderer->mPvsStatFrames) { 438 443 // emit EvalPvsStat(); 439 444 // QMutex mutex; … … 504 509 SimpleRayContainer rays; 505 510 511 cout<<"Generating initial rays..."<<endl; 506 512 GenerateRays(mInitialSamples/4, SPATIAL_BOX_BASED_DISTRIBUTION, rays); 507 513 GenerateRays(mInitialSamples/4, OBJECT_BASED_DISTRIBUTION, rays); … … 509 515 GenerateRays(mInitialSamples/4, OBJECT_DIRECTION_BASED_DISTRIBUTION, rays); 510 516 517 cout<<"Casting initial rays..."<<endl; 511 518 CastRays(rays, mVssRays); 512 519 … … 536 543 if (mUseViewcells) { 537 544 545 cout<<"Computing sample contributions..."<<endl; 538 546 // evaluate contributions of the intitial rays 539 547 mViewCellsManager->ComputeSampleContributions(mVssRays, true, false); 540 548 cout<<"done.\n"; 541 549 542 550 mStats << … … 559 567 Debug<<"Valid viewcells before set validity: "<<mViewCellsManager->CountValidViewcells()<<endl; 560 568 // cull viewcells with PVS > median (0.5f) 561 mViewCellsManager->SetValidityPercentage(0, 0.5f); 569 //mViewCellsManager->SetValidityPercentage(0, 0.5f); 570 mViewCellsManager->SetValidityPercentage(0, 1.0f); 562 571 Debug<<"Valid viewcells after set validity: "<<mViewCellsManager->CountValidViewcells()<<endl; 563 572 … … 571 580 572 581 /// compute view cell contribution of rays if view cells manager already constructed 573 mViewCellsManager->ComputeSampleContributions(mVssRays, true, false);582 // mViewCellsManager->ComputeSampleContributions(mVssRays, true, false); 574 583 575 584 if (mUseImportanceSampling) { … … 651 660 if (mDirectionalSampling) 652 661 rayType = DIRECTION_BASED_DISTRIBUTION; 653 662 663 cout<<"Generating rays..."<<endl; 664 654 665 GenerateRays(mRssSamplesPerPass, rayType, rays); 666 cout<<"done."<<endl; 667 668 cout<<"Casting rays..."<<endl; 655 669 CastRays(rays, vssRays); 670 cout<<"done."<<endl; 656 671 castRays += rays.size(); 657 672 if (mUseViewcells) { 658 673 /// compute view cell contribution of rays 674 cout<<"Computing sample contributions..."<<endl; 659 675 mViewCellsManager->ComputeSampleContributions(vssRays, true, false); 676 cout<<"done."<<endl; 660 677 } 661 678 -
GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.cpp
r750 r752 96 96 cout<<"+"; 97 97 vector<Vector3> vertices; 98 vector<int>vertexIndices;98 VertexIndexContainer vertexIndices; 99 99 100 100 /* face */ … … 133 133 int index = (int)currentMesh->mVertices.size(); 134 134 for (i=0; i < vertices.size(); i++, index++) { 135 currentMesh->mVertices.push_back(vertices[i]);136 vertexIndices.push_back(index);135 currentMesh->mVertices.push_back(vertices[i]); 136 vertexIndices.push_back(index); 137 137 } 138 138 … … 184 184 fclose(file); 185 185 186 187 186 *proot = root; 188 187 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r746 r752 18 18 { 19 19 public: 20 //bool operator() (HierarchyNode *v1, HierarchyNode *v2) const21 20 bool operator() (T v1, T v2) const 22 21 { … … 39 38 40 39 // pvs penalty can be different from pvs size 41 inline float EvalPvsPenalty(const int pvs, const int lower, const int upper)40 inline static float EvalPvsPenalty(const int pvs, const int lower, const int upper) 42 41 { 43 42 // clamp to minmax values 44 #if HAS_TO_BE_REDONE45 43 if (pvs < lower) 46 44 return (float)lower; 47 45 if (pvs > upper) 48 46 return (float)upper; 49 #endif 47 50 48 return (float)pvs; 51 49 } … … 70 68 71 69 /// Fast computation of merged pvs size 72 int ComputeMergedPvsSize(const ObjectPvs &pvs1, const ObjectPvs &pvs2)70 static int ComputeMergedPvsSize(const ObjectPvs &pvs1, const ObjectPvs &pvs2) 73 71 { 74 72 // add first pvs … … 99 97 100 98 // computet render cost of merge 101 float ViewCellsTree::ComputeMergedPvsCost(const ObjectPvs &pvs1, const ObjectPvs &pvs2) const 99 float ViewCellsTree::ComputeMergedPvsCost(const ObjectPvs &pvs1, 100 const ObjectPvs &pvs2) const 102 101 { 103 102 float renderCost = 0; … … 143 142 mParent(NULL), 144 143 mMergeCost(0), 145 mIsActive(false) 144 mIsActive(false), 145 mPvsSize(0), 146 mPvsSizeValid(false) 146 147 { 147 148 } … … 156 157 mMergeCost(0), 157 158 mIsActive(false), 158 mLastUpdated(sLastUpdated) 159 mLastUpdated(sLastUpdated), 160 mPvsSize(0), 161 mPvsSizeValid(false) 159 162 { 160 163 } … … 165 168 return mPvs; 166 169 } 170 167 171 168 172 ObjectPvs &ViewCell::GetPvs() … … 205 209 { 206 210 mArea = area; 211 } 212 213 214 void ViewCell::SetColor(const RgbColor &color) 215 { 216 mColor = color; 217 } 218 219 220 RgbColor ViewCell::GetColor() const 221 { 222 return mColor; 207 223 } 208 224 … … 367 383 mUseAreaForPvs(false), 368 384 mViewCellsManager(vcm), 369 mIsCompressed(false) 385 #if 0 386 mViewCellsStorage(PVS_IN_INTERIORS) 387 #else 388 mViewCellsStorage(PVS_IN_LEAVES) 389 #endif 370 390 { 371 391 environment->GetBoolValue("ViewCells.Visualization.exportMergedViewCells", mExportMergedViewCells); … … 393 413 float ViewCellsTree::GetMemUsage() const 394 414 { 415 // TODO 395 416 return 0; 396 417 /*(sizeof(ViewCellsTree) + … … 513 534 // we start with the current view cells from the view cell manager. 514 535 // The active view cells will change with subsequent merges 515 Debug << "here2" << endl; Debug.flush();536 516 537 // todo: should rather take initial view cells 517 538 ViewCellContainer &activeViewCells = mViewCellsManager->GetViewCells(); 518 //ViewCellContainer activeViewCells; 519 520 Debug << "here2.6" << endl; Debug.flush(); 539 540 521 541 ViewCell::NewMail(); 522 542 … … 704 724 Debug << "setting root of the merge history" << endl; 705 725 mRoot = activeViewCells[0]; 706 Debug << "rootvc volume: " << mRoot->GetVolume() << endl; 726 Debug << "volume of the root view cell: " << mRoot->GetVolume() << " " << mViewCellsManager->GetViewSpaceBox().GetVolume() << endl; 727 } 728 else 729 { 730 Debug << "big error, root is NULL" << endl; 707 731 } 708 732 … … 803 827 swap(viewCells[i], viewCells.back()); 804 828 805 // mail view cell asit has not been merged829 // mail view cell that it has not been merged 806 830 viewCells[i]->Mail(); 807 831 … … 814 838 // merged in the mean time 815 839 ViewCellContainer::const_iterator ait, ait_end = mMergedViewCells.end(); 840 816 841 for (ait = mMergedViewCells.begin(); ait != ait_end; ++ ait) 817 842 { … … 825 850 } 826 851 852 // dispose old merged view cells 827 853 mMergedViewCells.clear(); 828 854 … … 836 862 const int lower = mViewCellsManager->GetMinPvsSize(); 837 863 const int upper = mViewCellsManager->GetMaxPvsSize(); 864 838 865 const float penalty = EvalPvsPenalty((*vit)->GetPvs().GetSize(), lower, upper); 839 866 … … 905 932 if (!vc) return NULL; 906 933 934 // set to the new parent view cell 907 935 l->SetParent(vc); 908 936 r->SetParent(vc); … … 932 960 pvsDiff = vc->GetPvs().GetSize() - pvs1 - pvs2; 933 961 962 963 964 //Ždon't store intermediate pvs 965 if (mViewCellsStorage == PVS_IN_LEAVES) 966 { 967 l->mPvsSize = l->GetPvs().GetSize(); 968 l->mPvsSizeValid = true; 969 970 if (!l->IsLeaf()) 971 l->GetPvs().Clear(); 972 973 r->mPvsSize = r->GetPvs().GetSize(); 974 r->mPvsSizeValid = true; 975 976 if (!r->IsLeaf()) 977 r->GetPvs().Clear(); 978 979 } 980 981 934 982 return vc; 935 983 } 936 937 984 938 985 … … 1189 1236 if (1) 1190 1237 { 1191 const float penalty = EvalPvsPenalty(vc->GetPvs().GetSize(), lower, upper); 1192 return (mAvgRenderCost - penalty) * (mAvgRenderCost - penalty) / (float)mNumActiveViewCells; 1238 const float penalty = 1239 EvalPvsPenalty(vc->GetPvs().GetSize(), lower, upper); 1240 return (mAvgRenderCost - penalty) * (mAvgRenderCost - penalty) / 1241 (float)mNumActiveViewCells; 1193 1242 } 1194 1243 … … 1233 1282 bool ViewCellsTree::ValidateMergeCandidate(MergeCandidate &mc) const 1234 1283 { 1284 // propagate up so we have only the active view cells 1235 1285 while (mc.mLeftViewCell->mParent) 1236 1286 { … … 1243 1293 } 1244 1294 1295 // this view cell was already merged 1296 //return mc.mLeftViewCell && (mc.mLeftViewCell != mc.mRightViewCell); 1245 1297 return mc.mLeftViewCell != mc.mRightViewCell; 1246 1298 } … … 1250 1302 { 1251 1303 //-- compute pvs difference 1252 const float newPvs = 1253 #if 1 // not valid if not using const cost per object!! 1254 ComputeMergedPvsSize(mc.mLeftViewCell->GetPvs(), 1255 mc.mRightViewCell->GetPvs()); 1256 #else 1257 ComputeMergedPvsCost(mc.mLeftViewCell->GetPvs(), 1258 mc.mRightViewCell->GetPvs()); 1259 #endif 1304 int newPvs; 1305 if (1) // not valid if not using const cost per object!! 1306 newPvs = ComputeMergedPvsSize(mc.mLeftViewCell->GetPvs(), mc.mRightViewCell->GetPvs()); 1307 else 1308 newPvs = (int)ComputeMergedPvsCost(mc.mLeftViewCell->GetPvs(), mc.mRightViewCell->GetPvs()); 1260 1309 1261 1310 const float newPenalty = EvalPvsPenalty(newPvs, … … 1305 1354 } 1306 1355 1307 void ViewCellsTree::CompressViewCellsPvs() 1308 { 1309 if (!mIsCompressed) 1310 { 1311 mIsCompressed = true; 1356 1357 void ViewCellsTree::SetViewCellsStorage(int stype) 1358 { 1359 if (mViewCellsStorage == stype) 1360 return; 1361 1362 // TODO 1363 switch (stype) 1364 { 1365 case COMPRESSED: 1312 1366 CompressViewCellsPvs(mRoot); 1313 } 1314 } 1367 break; 1368 default: 1369 break; 1370 } 1371 1372 mViewCellsStorage = stype; 1373 } 1374 1315 1375 1316 1376 void ViewCellsTree::CompressViewCellsPvs(ViewCell *root) … … 1344 1404 const float vol = box.GetVolume(); 1345 1405 1406 const int rootPvs = GetPvsSize(mRoot); 1407 1346 1408 Debug << "vsb volume: " << vol << endl; 1347 1409 Debug << "root volume: " << mRoot->GetVolume() << endl; 1348 Debug << "root pvs: " << mRoot->GetPvs().GetSize()<< endl;1410 Debug << "root pvs: " << rootPvs << endl; 1349 1411 1350 1412 int totalPvs; … … 1352 1414 1353 1415 float deviation = 0; 1354 totalPvs = (int)mRoot->GetPvs().GetSize();1355 totalRenderCost = avgRenderCost = expectedCost = (float) mRoot->GetPvs().GetSize();1416 totalPvs = rootPvs; 1417 totalRenderCost = avgRenderCost = expectedCost = (float)rootPvs; 1356 1418 1357 1419 ofstream stats; 1358 1420 stats.open(mergeStats.c_str()); 1359 1421 1422 //-- first view cell 1360 1423 stats 1361 1424 << "#Pass\n" << 0 << endl … … 1364 1427 << "#RenderCostDecrease\n" << 0 << endl // TODO 1365 1428 << "#TotalRenderCost\n" << totalRenderCost << endl 1366 << "#CurrentPvs\n" << mRoot->GetPvs().GetSize()<< endl1429 << "#CurrentPvs\n" << rootPvs << endl 1367 1430 << "#ExpectedCost\n" << expectedCost << endl 1368 1431 << "#AvgRenderCost\n" << avgRenderCost << endl … … 1383 1446 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 1384 1447 1385 const int parentPvs = interior->GetPvs().GetSize();1448 const int parentPvs = GetPvsSize(interior); 1386 1449 const float parentCost = (float)parentPvs * interior->GetVolume(); 1387 1450 float childCost = 0; … … 1394 1457 for (it = interior->mChildren.begin(); it != it_end; ++ it) 1395 1458 { 1396 childCost += (float)(*it)->GetPvs().GetSize() * (*it)->GetVolume(); 1397 childPvs += (*it)->GetPvs().GetSize(); 1459 int pvsSize = GetPvsSize(*it); 1460 childCost += (float) pvsSize * (*it)->GetVolume(); 1461 childPvs += pvsSize; 1398 1462 1399 1463 tqueue.push(*it); … … 1416 1480 << "#RenderCostDecrease\n" << costDecr << endl // TODO 1417 1481 << "#TotalRenderCost\n" << totalRenderCost << endl 1418 << "#CurrentPvs\n" << vc->GetPvs().GetSize()<< endl1482 << "#CurrentPvs\n" << parentPvs << endl 1419 1483 << "#ExpectedCost\n" << expectedCost << endl 1420 1484 << "#AvgRenderCost\n" << avgRenderCost << endl … … 1432 1496 1433 1497 1434 #if 01435 float ViewCellsTree::ComputeVolume(ViewCell *vc)1436 {1437 if (vc->IsLeaf())1438 {1439 return vc->GetVolume();1440 }1441 else1442 {1443 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc);1444 1445 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end();1446 1447 float volume = 0;1448 1449 for (it = interior->mChildren.begin(); it != it_end; ++ it)1450 {1451 volume += ComputeVolume(*it);1452 }1453 1454 interior->SetVolume(volume);1455 return volume;1456 }1457 }1458 #endif1459 1460 1498 void ViewCellsTree::SetRoot(ViewCell *root) 1461 1499 { … … 1558 1596 } 1559 1597 1560 int dummy = interior->GetPvs().GetSize();1598 /*int dummy = interior->GetPvs().GetSize(); 1561 1599 1562 1600 for (cit = interior->mChildren.begin(); cit != cit_end; ++ cit) 1563 1601 { 1564 1602 dummy += (*cit)->GetPvs().GetSize(); 1565 } 1566 1567 } 1568 1569 1603 }*/ 1604 1605 } 1606 1607 // TODO 1570 1608 void ViewCellsTree::GetPvs(ViewCell *vc, ObjectPvs &pvs) const 1571 1609 { 1572 1610 Intersectable::NewMail(); 1573 1611 1574 if ( !mIsCompressed)1612 if (mViewCellsStorage == PVS_IN_INTERIORS) 1575 1613 pvs = vc->GetPvs(); 1576 1614 … … 1612 1650 int ViewCellsTree::GetPvsSize(ViewCell *vc) const 1613 1651 { 1652 int pvsSize = 0; 1653 1654 if (vc->IsLeaf()) 1655 { 1656 pvsSize = vc->GetPvs().GetSize(); 1657 } 1658 1659 1614 1660 Intersectable::NewMail(); 1615 1661 1616 if (!mIsCompressed) 1617 return vc->GetPvs().GetSize(); 1618 1619 1620 ////////////////////////777 1662 ////////////////////////// 1663 switch (mViewCellsStorage) 1664 { 1665 case PVS_IN_LEAVES: //-- store pvs only in leaves 1666 { 1667 if (vc->mPvsSizeValid) 1668 { 1669 pvsSize = vc->mPvsSize; 1670 break; 1671 } 1672 1673 //-- if no valid pvs size stored as a scalar=> compute new pvs size 1674 ViewCellContainer leaves; 1675 CollectLeaves(vc, leaves); 1676 1677 ViewCellContainer::const_iterator it, it_end = leaves.end(); 1678 1679 Intersectable::NewMail(); 1680 1681 // sum different intersectables 1682 for (it = leaves.begin(); it != it_end; ++ it) 1683 { 1684 ObjectPvsMap::iterator oit, oit_end = (*it)->GetPvs().mEntries.end(); 1685 1686 // mail all from first pvs 1687 for (oit = (*it)->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 1688 { 1689 Intersectable *intersect = (*oit).first; 1690 1691 if (!intersect->Mailed()) 1692 { 1693 ++ pvsSize; 1694 intersect->Mail(); 1695 } 1696 } 1697 } 1698 1699 break; 1700 } 1701 case COMPRESSED: 1702 { 1703 //////////////////////// 1621 1704 //-- compressed pvs 1622 1705 1706 if (vc->mPvsSizeValid) 1707 return vc->mPvsSize; 1708 1709 // if no pvs size stored: compute 1623 1710 int pvsSize = 0; 1624 1711 ViewCell *root = vc; … … 1653 1740 } 1654 1741 } 1742 break; 1743 } 1744 case PVS_IN_INTERIORS: 1745 default:Debug << "in interiors: " << vc->mPvsSize << " $$ " << vc->GetPvs().GetSize() << endl; 1746 pvsSize = vc->GetPvs().GetSize(); 1747 } 1655 1748 1656 1749 return pvsSize; 1657 1658 1750 } 1659 1751 … … 1672 1764 int pvsSize = 0; 1673 1765 // only count leaves for uncompressed method for fairness 1674 if (mIsCompressed || vc->IsLeaf()) 1766 if ((mViewCellsStorage == PVS_IN_INTERIORS) || vc->IsLeaf()) 1767 { 1675 1768 pvsSize = vc->GetPvs().GetSize(); 1769 } 1676 1770 1677 1771 if (!vc->IsLeaf()) … … 1691 1785 1692 1786 1693 bool ViewCellsTree::IsCompressed() const1694 { 1695 return m IsCompressed;1787 int ViewCellsTree::ViewCellsStorage() const 1788 { 1789 return mViewCellsStorage; 1696 1790 } 1697 1791 … … 1845 1939 if (!vc->GetValid()) 1846 1940 ++ vcStat.invalid; 1847 1848 /*ViewCellsContainer leaves;1849 CollectLeaves(vc, leaves);1850 1851 vcStat.leaves = (int)leaves.size();*/1852 1941 } 1853 1942 … … 1969 2058 void ViewCellsTree::SetActiveSetToLeaves() 1970 2059 { 2060 // todo 1971 2061 } 1972 2062 … … 2026 2116 bool MergeCandidate::IsValid() const 2027 2117 { 2118 // if one has a parent, it was already merged 2028 2119 return !(mLeftViewCell->mParent || mRightViewCell->mParent); 2029 2120 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h
r746 r752 90 90 class ViewCell: public MeshInstance 91 91 { 92 friend class ViewCellsTree; 93 friend class ViewCellsManager; 94 friend class VspBspViewCellsManager; 95 friend class BspViewCellsManager; 96 friend class VspBspTree; 97 friend class BspTree; 98 99 92 100 public: 93 101 ViewCell(); … … 104 112 */ 105 113 const ObjectPvs &GetPvs() const; 114 106 115 ObjectPvs &GetPvs(); 107 116 117 /** Type of view cells. 118 */ 108 119 int Type() const; 109 120 … … 151 162 float GetRenderCost() const; 152 163 153 /** set color for visiualizations */ 154 void SetColor(const RgbColor &color) { 155 mColor = color; 156 } 157 158 /** get color for visualuzations */ 159 RgbColor GetColor() const { 160 return mColor; 161 } 164 /** set color for visiualizations. 165 */ 166 void SetColor(const RgbColor &color); 167 168 /** get color for visualuzations. 169 */ 170 RgbColor GetColor() const; 162 171 163 172 … … 173 182 virtual bool IsLeaf() const = 0; 174 183 175 static bool SmallerPvs(const ViewCell *a, 176 const ViewCell *b){184 static bool SmallerPvs(const ViewCell *a, const ViewCell *b) 185 { 177 186 return a->GetPvs().GetSize() < b->GetPvs().GetSize(); 178 187 } … … 205 214 bool IsActive() const; 206 215 216 207 217 // last mail id -> warning not thread safe! 208 218 // both mailId and mailbox should be unique for each thread!!! … … 228 238 /** color used for consistent visualization */ 229 239 RgbColor mColor; 240 241 242 /// pvs size, used for lazy pvs computation 243 int mPvsSize; 244 bool mPvsSizeValid; 245 230 246 }; 231 247 … … 233 249 class ViewCellInterior: public ViewCell 234 250 { 251 friend class ViewCellsManager; 235 252 public: 236 253 ViewCellInterior(); … … 292 309 { 293 310 friend class ViewCellsManager; 311 312 294 313 public: 295 314 ViewCellsTree(ViewCellsManager *vcm); … … 355 374 float GetMemoryCost(ViewCell *vc) const; 356 375 357 /** Compresses the pvs of the view cells from the root. 358 */ 359 void CompressViewCellsPvs(); 376 /** Sets method of storage for view cells. 377 */ 378 void SetViewCellsStorage(int type); 379 380 /** pvs storage methods */ 381 enum {PVS_IN_INTERIORS, COMPRESSED, PVS_IN_LEAVES}; 360 382 361 383 /** If view cells in this tree have compressed pvs. 362 384 */ 363 bool IsCompressed() const;385 int ViewCellsStorage() const; 364 386 365 387 /** Returns active view cell that is in the path of this view cell. … … 485 507 486 508 /// if the view cell tree hold compressed pvs 487 bool mIsCompressed;509 int mViewCellsStorage; 488 510 489 511 ViewCellsManager *mViewCellsManager; … … 494 516 495 517 496 518 /** intermediate container of merged view cells. 519 */ 497 520 ViewCellContainer mMergedViewCells; 498 521 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r750 r752 332 332 cout << "view cell construction: casting " << mInitialSamples << " initial samples ... "; 333 333 334 long startTime = GetTime(); 335 334 336 //-- construction rays => we use uniform samples for this 335 337 CastPassSamples(mInitialSamples, … … 341 343 342 344 // construct view cells 343 const int numInitialSamples = 344 ConstructSubdivision(preprocessor->mObjects, initialSamples); 345 ConstructSubdivision(preprocessor->mObjects, initialSamples); 345 346 346 347 // initial samples count for overall samples ... 347 numSamples += numInitialSamples;348 numSamples += mInitialSamples; 348 349 349 350 // rays can be passed or deleted 350 351 disposeRays(initialSamples, outRays); 351 352 353 cout << "time needed for initial construction: " 354 << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 355 356 Debug << "time needed for initial construction: " 357 << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 358 359 360 // take post processing time 361 startTime = GetTime(); 362 363 352 364 // testing the view cell filter functionality 353 365 if (0) TestFilter(preprocessor->mObjects); … … 421 433 cout << "total samples: " << numSamples << endl; 422 434 } 435 423 436 424 437 … … 457 470 PostProcess(preprocessor->mObjects, postProcessSamples); 458 471 472 cout << "time needed for post processing (merge) step: " 473 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl; 474 475 Debug << "time needed for post processing (merge) step: " 476 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl; 477 459 478 // only for debugging purpose 460 479 if (TEST_EMPTY_VIEW_CELLS) … … 481 500 } 482 501 483 // needed to fix empty view cells484 //SetValidity(0, 99999999999);485 486 487 502 // evaluation of the paritition, i.e., a number of new samples are cast 488 503 if (mEvaluateViewCells) … … 491 506 } 492 507 493 if (0)494 {495 ViewCellContainer leaves;496 mViewCellsTree->CollectLeaves(mViewCellsTree->GetRoot(), leaves);497 mViewCellsTree->ResetPvs();498 VssRayContainer dummyRays;499 CastPassSamples(mInitialSamples, mSamplingType, dummyRays);500 501 //ComputeSampleContributions(initialSamples, true, false);502 ComputeSampleContributions(dummyRays, true, false);503 504 ViewCellContainer::const_iterator it, it_end = leaves.end();505 506 for (it = leaves.begin(); it != it_end; ++ it)507 {508 mViewCellsTree->PropagatePvs(*it);509 }510 511 mViewCellsTree->ExportStats("dummy.log");512 }513 514 508 return numSamples; 515 509 } 516 510 517 511 518 void ComputeMinMaxRenderCost(float &minRenderCost, 519 float &maxRenderCost, 520 const ViewCellContainer &viewCells) 521 { 522 minRenderCost = 1e20f; 523 maxRenderCost = -1; 524 525 ViewCellContainer::const_iterator it, it_end = viewCells.end(); 526 527 for (it = viewCells.begin(); it != it_end; ++ it) 528 { 529 const float renderCost = (float)(*it)->GetPvs().GetSize() * (*it)->GetVolume(); 530 if (renderCost > maxRenderCost) 531 maxRenderCost = renderCost; 532 else if (renderCost < minRenderCost) 533 minRenderCost = renderCost; 534 } 535 } 536 537 538 void ViewCellsManager::EvalViewCellHistogram(const string filename, const int nViewCells) 512 void ViewCellsManager::EvalViewCellHistogram(const string filename, 513 const int nViewCells) 539 514 { 540 515 std::ofstream outstream; … … 554 529 Debug << "histogram minrc: " << minRenderCost << " maxrc: " << maxRenderCost << endl; 555 530 556 const int intervals = min( 10000, (int)viewCells.size());531 const int intervals = min(50, (int)viewCells.size()); 557 532 558 533 const float range = maxRenderCost - minRenderCost; … … 634 609 maxPvsSize = viewCells.back()->GetPvs().GetSize(); 635 610 611 minPvsSize = 0; 612 maxPvsSize = 1200; 613 636 614 Debug << "histogram minpvssize: " << minPvsSize << " maxpvssize: " << maxPvsSize << endl; 637 615 638 const int intervals = min( 10000, (int)viewCells.size());616 const int intervals = min(20, (int)viewCells.size()); 639 617 const int range = maxPvsSize - minPvsSize; 640 618 int stepSize = range / intervals; 641 619 620 642 621 if (!stepSize) stepSize = 1; 622 Debug << "stepsize: " << stepSize << endl; 623 cout << "stepsize: " << stepSize << endl; 643 624 644 625 const float totalRenderCost = mViewCellsTree->GetRoot()->GetRenderCost(); … … 756 737 castSamples += samplesPerPass; 757 738 758 cout << "computing sample contributions of " << (int)evaluationSamples.size() << " samples " << endl; 739 cout << "computing sample contributions of " << (int)evaluationSamples.size() 740 << " samples " << endl; 759 741 760 742 ComputeSampleContributions(evaluationSamples, true, false); … … 762 744 cout << "compute new statistics ... "; 763 745 764 ViewCellContainer::const_iterator it, it_end = leaves.end(); 765 766 for (it = leaves.begin(); it != it_end; ++ it) 767 { 768 mViewCellsTree->PropagatePvs(*it); 769 } 746 // propagate pvs or pvs size information 747 ObjectPvs pvs; 748 UpdatePvsForEvaluation(mViewCellsTree->GetRoot(), pvs); 749 770 750 771 751 // output stats … … 819 799 } 820 800 #else 821 for (int pass = histoPasses; pass < numLeaves; pass += histoPasses)801 for (int pass = histoPasses; pass <= numLeaves; pass += histoPasses) 822 802 { 823 803 cout << "computing histogram for " << pass << " view cells" << endl; … … 830 810 831 811 ////////////////////////////////////////// 832 // --evaluate histogram for pvs size812 //-- evaluate histogram for pvs size 833 813 834 814 cout << "computing pvs histogram for " << pass << " view cells" << endl; … … 892 872 { 893 873 case PER_OBJECT: 894 return 1; 874 //cout << "perobject" << endl; 875 return 1.0f; 895 876 896 877 case PER_TRIANGLE: … … 906 887 } 907 888 default: 908 return 1; 889 cout << "default" << endl; 890 return 1.0f; 909 891 } 910 892 911 893 // should not come here 912 return 0 ;894 return 0.0f; 913 895 } 914 896 … … 1355 1337 } 1356 1338 1357 1339 // fast way of merging 2 view cells 1358 1340 ViewCellInterior *ViewCellsManager::MergeViewCells(ViewCell *left, ViewCell *right) const 1359 1341 { 1360 1342 // generate parent view cell 1361 ViewCellInterior *vc = new ViewCellInterior();//GenerateViewCell(); 1362 1343 ViewCellInterior *vc = new ViewCellInterior(); 1344 1345 vc->GetPvs().Clear(); 1363 1346 vc->GetPvs() = left->GetPvs(); 1364 // merge pvs 1347 1348 // merge pvs of right cell 1365 1349 vc->GetPvs().Merge(right->GetPvs()); 1366 1350 … … 1380 1364 vc->mChildren.push_back(right); 1381 1365 1366 // update pvs size 1367 vc->mPvsSize = vc->GetPvs().GetSize(); 1368 vc->mPvsSizeValid = true; 1369 1382 1370 return vc; 1383 1371 } … … 1386 1374 ViewCellInterior *ViewCellsManager::MergeViewCells(ViewCellContainer &children) const 1387 1375 { 1388 ViewCellInterior *vc = new ViewCellInterior(); //GenerateViewCell();1376 ViewCellInterior *vc = new ViewCellInterior(); 1389 1377 1390 1378 ViewCellContainer::const_iterator it, it_end = children.end(); … … 1395 1383 vc->GetPvs().Merge((*it)->GetPvs()); 1396 1384 vc->mChildren.push_back(*it); 1397 //vc->SetupChildLink(*it);1398 1385 } 1399 1386 … … 1755 1742 float ViewCellsManager::GetRendercost(ViewCell *viewCell) const 1756 1743 { 1757 const ObjectPvs &pvs = viewCell->GetPvs();1758 1759 ObjectPvsMap::iterator it, it_end = viewCell->GetPvs().mEntries.end();1760 1761 for (it = viewCell->GetPvs().mEntries.begin(); it != it_end; ++ it)1762 {1763 1764 }1765 1766 1744 return mViewCellsTree->GetPvsSize(viewCell); 1767 1745 } … … 2022 2000 { 2023 2001 cout << "constructing spatial merge tree" << endl; 2002 2024 2003 // create spatial merge hierarchy 2025 mViewCellsTree->SetRoot(ConstructSpatialMergeTree(mBspTree->GetRoot())); 2004 ViewCell *root = ConstructSpatialMergeTree(mBspTree->GetRoot()); 2005 mViewCellsTree->SetRoot(root); 2006 2007 // compute pvs 2008 ObjectPvs pvs; 2009 UpdatePvsForEvaluation(root, pvs); 2026 2010 } 2027 2011 … … 2037 2021 cout << "finished" << endl; 2038 2022 cout << "merged view cells in " 2039 << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;2023 << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 2040 2024 2041 2025 Debug << "Postprocessing: Merged view cells in " 2042 << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl << endl;2026 << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl << endl; 2043 2027 2044 2028 … … 2076 2060 } 2077 2061 2078 if (1) // export merged view cells 2062 if (1) // export merged view cells using pvs color coding 2079 2063 { 2080 2064 mColorCode = 1; … … 2087 2071 { 2088 2072 //exporter->SetWireframe(); 2089 2073 //exporter->SetForcedMaterial(RandomMaterial()); 2074 2090 2075 if (mExportGeometry) 2091 2076 exporter->ExportGeometry(objects); … … 2629 2614 ViewCell *BspViewCellsManager::ConstructSpatialMergeTree(BspNode *root) 2630 2615 { 2616 // terminate recursion 2631 2617 if (root->IsLeaf()) 2632 2618 { 2633 ViewCell *viewCell = dynamic_cast<BspLeaf *>(root)->GetViewCell(); 2634 2635 viewCell->SetMergeCost(0.0f); 2636 2637 return viewCell; 2619 BspLeaf *leaf = dynamic_cast<BspLeaf *>(root); 2620 leaf->GetViewCell()->SetMergeCost(0.0f); 2621 return leaf->GetViewCell(); 2638 2622 } 2639 2623 … … 2641 2625 ViewCellInterior *viewCellInterior = new ViewCellInterior(); 2642 2626 2627 // evaluate merge cost for priority traversal 2643 2628 float mergeCost = 1.0f / (float)root->mTimeStamp; 2644 //Debug << "timestamp: " << root->mTimeStamp;2645 //Debug << "merge cost: " << mergeCost << endl;2646 2647 2629 viewCellInterior->SetMergeCost(mergeCost); 2648 2630 … … 2652 2634 BspNode *back = interior->GetBack(); 2653 2635 2654 // recursivly compute child hierarchies 2636 2637 //-- recursivly compute child hierarchies 2655 2638 ViewCell *backVc = ConstructSpatialMergeTree(back); 2656 2639 ViewCell *frontVc = ConstructSpatialMergeTree(front); 2657 2640 2641 2642 viewCellInterior->SetupChildLink(backVc); 2658 2643 viewCellInterior->SetupChildLink(frontVc); 2659 viewCellInterior->SetupChildLink(backVc); 2660 2644 2645 volume += backVc->GetVolume(); 2646 volume += frontVc->GetVolume(); 2647 2648 viewCellInterior->SetVolume(volume); 2649 2650 return viewCellInterior; 2651 } 2652 2653 2654 void BspViewCellsManager::UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) 2655 { 2656 // terminate traversal 2657 if (root->IsLeaf()) 2658 { 2659 pvs = root->GetPvs(); 2660 2661 root->mPvsSize = pvs.GetSize(); 2662 root->mPvsSizeValid = true; 2663 2664 return; 2665 } 2666 2667 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(root); 2668 ViewCellContainer::const_iterator vit, vit_end = interior->mChildren.end(); 2669 2670 vector<ObjectPvs> pvsList; 2671 2672 2673 for (vit = interior->mChildren.begin(); vit != vit_end; ++ vit) 2674 { 2675 ObjectPvs objPvs; 2676 2677 //-- recursivly compute child pvss 2678 UpdatePvsForEvaluation(*vit, objPvs); 2679 2680 // store pvs in vector 2681 pvsList.push_back(objPvs); 2682 } 2683 2684 #if 1 2685 Intersectable::NewMail(); 2686 2687 //-- faster way of computing pvs: 2688 // construct merged pvs by adding 2689 // and only those of the next pvs which were not mailed. 2690 // note: sumpdf is not correct!! 2691 vector<ObjectPvs>::iterator oit = pvsList.begin(); 2692 2693 for (vit = interior->mChildren.begin(); vit != vit_end; ++ vit, ++ oit) 2694 { 2695 2696 ObjectPvsMap::iterator pit, pit_end = (*oit).mEntries.end(); 2697 2698 for (pit = (*oit).mEntries.begin(); pit != pit_end; ++ pit) 2699 { 2700 2701 Intersectable *intersect = (*pit).first; 2702 2703 if (!intersect->Mailed()) 2704 { 2705 pvs.AddSample(intersect, (*pit).second.mSumPdf); 2706 intersect->Mail(); 2707 } 2708 } 2709 } 2710 2711 // store pvs in this node 2712 if (mViewCellsTree->ViewCellsStorage() == ViewCellsTree::PVS_IN_INTERIORS) 2713 { 2714 interior->mPvs = pvs; 2715 } 2716 2717 // set new pvs size 2718 interior->mPvsSize = pvs.GetSize(); 2719 interior->mPvsSizeValid = true; 2720 2721 #else 2722 // really merge cells: slow put sumpdf is correct 2723 ViewCellInterior *viewCellInterior = new ViewCellInterior(); 2661 2724 2662 2725 viewCellInterior->GetPvs().Merge(backVc->GetPvs()); 2663 2726 viewCellInterior->GetPvs().Merge(frontVc->GetPvs()); 2664 2665 volume += backVc->GetVolume(); 2666 volume += frontVc->GetVolume(); 2667 2668 viewCellInterior->SetVolume(volume); 2669 2670 return viewCellInterior; 2671 } 2672 2727 #endif 2728 2729 } 2673 2730 2674 2731 /************************************************************************/ … … 2819 2876 2820 2877 ObjectPvsMap::iterator it, it_end = vc->GetPvs().mEntries.end(); 2821 // output PVS of view cell2878 // -- output PVS of view cell 2822 2879 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 2823 2880 { … … 3448 3505 if (SAMPLE_AFTER_SUBDIVISION) 3449 3506 ComputeSampleContributions(savedRays, true, false); 3507 3450 3508 cout << "finished" << endl; 3451 3509 … … 3489 3547 ViewCell *root = ConstructSpatialMergeTree(mVspBspTree->GetRoot()); 3490 3548 mViewCellsTree->SetRoot(root); 3549 3550 // compute pvs 3551 ObjectPvs pvs; 3552 UpdatePvsForEvaluation(root, pvs); 3491 3553 } 3492 3554 … … 3494 3556 { 3495 3557 char mstats[100]; 3558 ObjectPvs pvs; 3559 3496 3560 environment->GetStringValue("ViewCells.mergeStats", mstats); 3497 3561 mViewCellsTree->ExportStats(mstats); … … 3728 3792 Debug << "number of entries before compress: " << pvsEntries << endl; 3729 3793 3730 mViewCellsTree-> CompressViewCellsPvs();3794 mViewCellsTree->SetViewCellsStorage(ViewCellsTree::COMPRESSED); 3731 3795 3732 3796 pvsEntries = mViewCellsTree->GetNumPvsEntries(mViewCellsTree->GetRoot()); … … 3768 3832 ViewCell *VspBspViewCellsManager::ConstructSpatialMergeTree(BspNode *root) 3769 3833 { 3834 // terminate recursion 3770 3835 if (root->IsLeaf()) 3771 3836 { 3772 ViewCell *viewCell = dynamic_cast<BspLeaf *>(root)->GetViewCell(); 3773 3774 viewCell->SetMergeCost(0.0f); 3775 3776 return viewCell; 3777 } 3837 BspLeaf *leaf = dynamic_cast<BspLeaf *>(root); 3838 leaf->GetViewCell()->SetMergeCost(0.0f); 3839 return leaf->GetViewCell(); 3840 } 3841 3778 3842 3779 3843 BspInterior *interior = dynamic_cast<BspInterior *>(root); 3780 3844 ViewCellInterior *viewCellInterior = new ViewCellInterior(); 3781 3845 3846 // evaluate merge cost for priority traversal 3782 3847 float mergeCost = 1.0f / (float)root->mTimeStamp; 3783 //Debug << "timestamp: " << root->mTimeStamp;3784 //Debug << "merge cost: " << mergeCost << endl;3785 3786 3848 viewCellInterior->SetMergeCost(mergeCost); 3787 3849 … … 3791 3853 BspNode *back = interior->GetBack(); 3792 3854 3793 // recursivly compute child hierarchies 3855 3856 ObjectPvs frontPvs, backPvs; 3857 3858 //-- recursivly compute child hierarchies 3794 3859 ViewCell *backVc = ConstructSpatialMergeTree(back); 3795 3860 ViewCell *frontVc = ConstructSpatialMergeTree(front); 3796 3861 3862 3863 viewCellInterior->SetupChildLink(backVc); 3797 3864 viewCellInterior->SetupChildLink(frontVc); 3798 viewCellInterior->SetupChildLink(backVc); 3799 3865 3866 volume += backVc->GetVolume(); 3867 volume += frontVc->GetVolume(); 3868 3869 viewCellInterior->SetVolume(volume); 3870 3871 return viewCellInterior; 3872 } 3873 3874 3875 3876 void VspBspViewCellsManager::UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) 3877 { 3878 // terminate traversal 3879 if (root->IsLeaf()) 3880 { 3881 pvs = root->GetPvs(); 3882 3883 root->mPvsSize = pvs.GetSize(); 3884 root->mPvsSizeValid = true; 3885 3886 return; 3887 } 3888 3889 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(root); 3890 ViewCellContainer::const_iterator vit, vit_end = interior->mChildren.end(); 3891 3892 vector<ObjectPvs> pvsList; 3893 3894 3895 for (vit = interior->mChildren.begin(); vit != vit_end; ++ vit) 3896 { 3897 ObjectPvs objPvs; 3898 3899 //-- recursivly compute child pvss 3900 UpdatePvsForEvaluation(*vit, objPvs); 3901 3902 // store pvs in vector 3903 pvsList.push_back(objPvs); 3904 } 3905 3906 #if 1 3907 Intersectable::NewMail(); 3908 3909 //-- faster way of computing pvs: 3910 // construct merged pvs by adding 3911 // and only those of the next pvs which were not mailed. 3912 // note: sumpdf is not correct!! 3913 vector<ObjectPvs>::iterator oit = pvsList.begin(); 3914 3915 for (vit = interior->mChildren.begin(); vit != vit_end; ++ vit, ++ oit) 3916 { 3917 ObjectPvsMap::iterator pit, pit_end = (*oit).mEntries.end(); 3918 3919 for (pit = (*oit).mEntries.begin(); pit != pit_end; ++ pit) 3920 { 3921 Intersectable *intersect = (*pit).first; 3922 3923 if (!intersect->Mailed()) 3924 { 3925 pvs.AddSample(intersect, (*pit).second.mSumPdf); 3926 intersect->Mail(); 3927 } 3928 } 3929 } 3930 3931 // store pvs in this node 3932 if (mViewCellsTree->ViewCellsStorage() == ViewCellsTree::PVS_IN_INTERIORS) 3933 { 3934 interior->mPvs = pvs; 3935 } 3936 3937 // set new pvs size 3938 interior->mPvsSize = pvs.GetSize(); 3939 interior->mPvsSizeValid = true; 3940 3941 #else 3942 // really merge cells: slow put sumpdf is correct 3943 ViewCellInterior *viewCellInterior = new ViewCellInterior(); 3800 3944 3801 3945 viewCellInterior->GetPvs().Merge(backVc->GetPvs()); 3802 3946 viewCellInterior->GetPvs().Merge(frontVc->GetPvs()); 3803 3804 volume += backVc->GetVolume(); 3805 volume += frontVc->GetVolume(); 3806 3807 viewCellInterior->SetVolume(volume); 3808 3809 return viewCellInterior; 3947 #endif 3948 3810 3949 } 3811 3950 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r746 r752 41 41 ViewCell *mViewCell; 42 42 43 //ViewCellContainer mViewCells;44 /// aggregated pvs45 //ObjectPvs mPvs;46 47 43 // input parameter is the render budget for the PrVS 48 44 float mRenderBudget; … … 501 497 void CreateClipPlane(); 502 498 499 virtual void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) = 0; 500 501 502 503 503 Plane3 mClipPlane; 504 504 bool mUseClipPlaneForViz; … … 633 633 bool ExportViewCells(const string filename); 634 634 635 /** Constructs merge hierarchy which corresponds to the spatial hierarchy. 636 */ 635 637 ViewCell *ConstructSpatialMergeTree(BspNode *root); 636 638 639 /** Updates the pvs in the view cells tree. 640 */ 641 void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs); 637 642 638 643 protected: … … 713 718 vector<MergeCandidate> &candidates); 714 719 720 715 721 protected: 716 722 723 virtual void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) {}; 717 724 /** Collects view cells from a hierarchy. 718 725 */ … … 778 785 void CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates); 779 786 787 virtual void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) {}; 780 788 protected: 781 789 … … 886 894 void ExportColor(Exporter *exporter, ViewCell *vc) const; 887 895 896 /** Prepare view cells for use after loading them from disc. 897 */ 888 898 void PrepareLoadedViewCells(); 889 899 900 /** Constructs merge hierarchy which corresponds to the spatial hierarchy. 901 */ 890 902 ViewCell *ConstructSpatialMergeTree(BspNode *root); 891 903 904 void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs); 905 906 907 // HACK 892 908 void TestFilter(const ObjectContainer &objects); 893 909 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
r744 r752 472 472 473 473 mSubdivisionStats 474 << "#ViewCells\n1 \n" << endl475 << "#RenderCostDecrease\n0 \n" << endl474 << "#ViewCells\n1" << endl 475 << "#RenderCostDecrease\n0" << endl 476 476 << "#TotalRenderCost\n" << mTotalCost << endl 477 477 << "#AvgRenderCost\n" << mTotalPvsSize << endl; … … 578 578 << "#ViewCells\n1\n" << endl 579 579 << "#RenderCostDecrease\n0\n" << endl 580 << "# dummy\n0\n" << endl580 << "#SplitCandidateCost\n0\n" << endl 581 581 << "#TotalRenderCost\n" << mTotalCost << endl 582 582 << "#AvgRenderCost\n" << mTotalPvsSize << endl; … … 773 773 AddToPvs(leaf, *tData.mRays, sampCon, conSamp); 774 774 775 // update single pvs parameter 776 viewCell->mPvsSize = viewCell->GetPvs().GetSize(); 777 viewCell->mPvsSizeValid = true; 778 779 775 780 mBspStats.contributingSamples += conSamp; 776 781 mBspStats.sampleContributions +=(int) sampCon; … … 869 874 << "#ViewCells\n" << mBspStats.Leaves() << endl 870 875 << "#RenderCostDecrease\n" << -costDecr << endl 871 << "# dummy\n" << splitCandidate.GetCost() << endl876 << "#SplitCandidateCost\n" << splitCandidate.GetCost() << endl 872 877 << "#TotalRenderCost\n" << mTotalCost << endl 873 878 << "#AvgRenderCost\n" << (float)mTotalPvsSize / (float)mBspStats.Leaves() << endl; … … 902 907 float sampCon = 0.0f; 903 908 AddToPvs(leaf, *tData.mRays, sampCon, conSamp); 909 910 viewCell->mPvsSize = viewCell->GetPvs().GetSize(); 911 viewCell->mPvsSizeValid = true; 904 912 905 913 mBspStats.contributingSamples += conSamp; … … 1763 1771 if ((pFront < 0.0) || (pBack < 0.0)) 1764 1772 { 1765 Debug << "vol f " << pFront << " b " << pBack << " p " << pOverall << endl; 1766 Debug << "real vol f " << pFront << " b " << geomBack.GetVolume() << " p " << pOverall << endl; 1767 Debug << "polys f " << geomFront.Size() << " b " << geomBack.Size() << " data " << data.mGeometry->Size() << endl; 1768 } 1769 1770 // clamp because of possible precision issues 1771 if (0) 1772 { 1773 if (pFront < 0) pFront = 0; 1774 if (pBack < 0) pBack = 0; 1773 Debug << "ERROR in volume:\n" 1774 << "volume f :" << pFront << " b: " << pBack << " p: " << pOverall 1775 << ", real volume f: " << pFront << " b: " << geomBack.GetVolume() 1776 << ", #polygons f: " << geomFront.Size() << " b: " << geomBack.Size() << " p: " << data.mGeometry->Size() << endl; 1775 1777 } 1776 1778 } … … 1795 1797 1796 1798 //Debug << "decrease: " << oldRenderCost - newRenderCost << endl; 1797 return (oldRenderCost - newRenderCost) / mBox.GetVolume(); 1799 const float renderCostDecrease = (oldRenderCost - newRenderCost) / mBox.GetVolume(); 1800 1801 1802 #if 1 1803 // take render cost of node into account 1804 const float normalizedOldRenderCost = oldRenderCost / mBox.GetVolume(); 1805 //Debug << "rendercostdecr: " << 0.99f * renderCostDecrease << " old render cost: " << 0.01f * normalizedOldRenderCost << endl; 1806 //return 0.5f * renderCostDecrease + 0.5f * normalizedOldRenderCost; 1807 return 0.99f * renderCostDecrease + 0.01f * normalizedOldRenderCost; 1808 #else 1809 return renderCostDecrease; 1810 #endif 1798 1811 } 1799 1812 … … 1871 1884 !geomFront.Valid() || !geomBack.Valid())) 1872 1885 { 1873 Debug << "error f: " << pFront << " b: " << pBack << endl; 1886 //Debug << "error f: " << pFront << " b: " << pBack << endl; 1887 // high penalty for this split 1874 1888 return 99999.9f; 1875 1889 } … … 1887 1901 1888 1902 // only render cost heuristics or combined with standard deviation 1889 const float penaltyOld = EvalPvsPenalty( totalPvs, lowerPvsLimit, upperPvsLimit);1890 const float penaltyFront = EvalPvsPenalty( pvsFront, lowerPvsLimit, upperPvsLimit);1891 const float penaltyBack = EvalPvsPenalty( pvsBack, lowerPvsLimit, upperPvsLimit);1903 const float penaltyOld = EvalPvsPenalty((int)totalPvs, lowerPvsLimit, upperPvsLimit); 1904 const float penaltyFront = EvalPvsPenalty((int)pvsFront, lowerPvsLimit, upperPvsLimit); 1905 const float penaltyBack = EvalPvsPenalty((int)pvsBack, lowerPvsLimit, upperPvsLimit); 1892 1906 1893 1907 const float oldRenderCost = pOverall * penaltyOld; … … 2762 2776 BspNodeGeometry nodeGeom; 2763 2777 ConstructGeometry(n, nodeGeom); 2764 2778 const float eps = 0.01f; 2779 2765 2780 // split planes from the root to this node 2766 2781 // needed to verify that we found neighbor leaf … … 2799 2814 Polygon3::ClassifyPlane(geom->GetPolys(), 2800 2815 halfSpaces[i], 2801 mEpsilon);2816 eps); 2802 2817 2803 2818 if (cf == Polygon3::FRONT_SIDE) … … 2818 2833 Polygon3::ClassifyPlane(geom->GetPolys(), 2819 2834 poly->GetSupportingPlane(), 2820 mEpsilon);2835 eps); 2821 2836 2822 2837 if (cf == Polygon3::FRONT_SIDE) … … 2839 2854 const int cf = Polygon3::ClassifyPlane(nodeGeom.GetPolys(), 2840 2855 interior->GetPlane(), 2841 mEpsilon);2856 eps); 2842 2857 2843 2858 BspNode *front = interior->GetFront(); … … 2852 2867 mBox, 2853 2868 //0.0000001f); 2854 mEpsilon);2869 eps); 2855 2870 2856 2871 if (cf == Polygon3::BACK_SIDE) … … 2891 2906 ConstructGeometry(n, nodeGeom); 2892 2907 2908 float eps = 0.01f; 2893 2909 // split planes from the root to this node 2894 2910 // needed to verify that we found neighbor leaf … … 2932 2948 const int cf = Polygon3::ClassifyPlane(nodeGeom.GetPolys(), 2933 2949 interior->GetPlane(), 2934 mEpsilon);2950 eps); 2935 2951 2936 2952 BspNode *front = interior->GetFront(); … … 2945 2961 mBox, 2946 2962 //0.0000001f); 2947 mEpsilon);2963 eps); 2948 2964 2949 2965 if (cf == Polygon3::BACK_SIDE) … … 3164 3180 3165 3181 float t; 3166 const float thresh = 1e-6f; // matt: change this 3182 const float thresh = 1e-6f; // matt: change this to adjustable value 3167 3183 3168 3184 while (1) -
GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp
r726 r752 100 100 string element(lname.LocalForm()); 101 101 102 // only create new mesh instance if define mechanism was not used 102 103 if (element == "Shape") 103 104 EndShape(); 104 if (1) 105 105 106 if (element == "Transform") 106 107 EndTransform(); … … 138 139 139 140 const int len = attributes.getLength(); 141 Matrix4x4 *rotm = NULL; 142 Matrix4x4 *scalem = NULL; 143 Matrix4x4 *translm = NULL; 140 144 141 145 for (int i = 0; i < len; ++ i) … … 153 157 if (sscanf(ptr, "%f %f %f %f", &axis.x, &axis.y, &axis.z, &angle) == 4) 154 158 { 155 Matrix4x4 rot = RotationAxisMatrix(axis, angle); 156 currentTransform *= rot; 159 rotm = new Matrix4x4(RotationAxisMatrix(axis, angle)); 157 160 } 158 161 } … … 163 166 if (sscanf(ptr, "%f %f %f %f", &transl.x, &transl.y, &transl.z) == 3) 164 167 { 165 Matrix4x4 tm = TranslationMatrix(transl); 166 167 currentTransform *= tm; 168 translm = new Matrix4x4(TranslationMatrix(transl)); 168 169 } 169 170 } 171 else if (attrName == "scale") 172 { 173 Vector3 scale; 174 175 if (sscanf(ptr, "%f %f %f %f", &scale.x, &scale.y, &scale.z) == 3) 176 { 177 scalem = new Matrix4x4(ScaleMatrix(scale.x, scale.y, scale.z)); 178 } 179 } 180 // todo: scale orientation 170 181 } 171 182 183 if (scalem) 184 currentTransform *= (*scalem); 185 if (rotm) 186 currentTransform *= (*rotm); 187 if (translm) 188 currentTransform *= (*translm); 189 190 DEL_PTR(scalem); 191 DEL_PTR(rotm); 192 DEL_PTR(translm); 193 172 194 mTransformations.push(currentTransform); 173 195 } … … 180 202 181 203 182 void 183 X3dParseHandlers::EndShape() 184 { 204 void X3dParseHandlers::EndShape() 205 { 206 // this shape is a definition => don't create mesh instance 207 if (mIsMeshDefinition) 208 { 209 mMeshDefinitions[mCurrentMeshName.c_str()] = mCurrentMesh; 210 //cout << "new definition: " << mCurrentMeshName << endl; 211 212 return; 213 } 214 215 // each polygon is one single mesh 185 216 if (mLoadPolygonsAsMeshes) 186 217 { 187 vector<VertexIndexContainer>::const_iterator it, it_end = mCurrentVertexIndices.end(); 218 219 /*vector<VertexIndexContainer>::const_iterator it, 220 it_end = mCurrentVertexIndices.end(); 188 221 189 222 for (it = mCurrentVertexIndices.begin(); it != it_end; ++ it) … … 211 244 mCurrentNode->mGeometry.push_back(mi); 212 245 213 } 214 215 delete mCurrentMesh; 216 mCurrentVertices.clear(); 217 mCurrentVertexIndices.clear(); 246 }*/ 247 248 //if (mCurrentMesh->mFaces.empty()) cout << "error!" << endl; 249 250 FaceContainer::const_iterator fit, fit_end = mCurrentMesh->mFaces.end(); 251 252 cout << "m"; 253 //cout << "m: " << mCurrentMesh->mFaces.size() << endl; 254 for (fit = mCurrentMesh->mFaces.begin(); fit != fit_end; ++ fit) 255 { 256 cout << "f"; 257 258 Face *face = *fit; 259 // only one face per mesh 260 Mesh *mesh = new Mesh(); 261 VertexIndexContainer vc; 262 263 VertexIndexContainer::const_iterator vit, vit_end = face->mVertexIndices.end(); 264 265 int i = 0; 266 for (vit = face->mVertexIndices.begin(); vit != vit_end; ++ vit, ++ i) 267 { 268 cout << "i"; 269 int index = (*vit); 270 // add vertices 271 mesh->mVertices.push_back(mCurrentMesh->mVertices[index]); 272 vc.push_back(i); 273 } 274 275 mesh->mFaces.push_back(new Face(vc)); 276 277 // NOTE: should rather be written into trafo of mesh instance 278 ApplyTransformations(mTransformations, mesh); 279 280 mesh->Preprocess(); 281 282 // make an instance of this mesh 283 MeshInstance *mi = new MeshInstance(mesh); 284 mCurrentNode->mGeometry.push_back(mi); 285 } 286 287 // LEAK!! TODO: delete if not defd 288 if (!mUsingMeshDefinition) 289 delete mCurrentMesh; 290 291 //mCurrentVertices.clear(); 292 //mCurrentVertexIndices.clear(); 218 293 } 219 294 else 220 295 { 221 if ( mCurrentMesh->mFaces.size())296 if (!mCurrentMesh->mFaces.empty()) 222 297 { 223 298 // should rather be written into the transformation … … 228 303 // make an instance of this mesh 229 304 MeshInstance *mi = new MeshInstance(mCurrentMesh); 305 230 306 mCurrentNode->mGeometry.push_back(mi); 231 307 // set the object id to a unique value … … 234 310 else 235 311 { 312 // empty mesh => discard 236 313 cout<<"X"; 314 237 315 delete mCurrentMesh; 238 316 } … … 243 321 244 322 245 void 246 X3dParseHandlers::StartIndexedFaceSet( 247 AttributeList& attributes) 323 void X3dParseHandlers::StartIndexedFaceSet(AttributeList& attributes) 248 324 { 249 325 int len = attributes.getLength(); 326 250 327 int i; 251 328 VertexIndexContainer vertices; 252 329 253 for (i=0; i < len; i++) { 254 string attrName(StrX(attributes.getName(i)).LocalForm()); 255 if (attrName == "coordIndex") { 256 StrX attrValue(attributes.getValue(i)); 257 // handle coordIndex 258 vertices.clear(); 259 const char *ptr = attrValue.LocalForm(); 260 char *endptr; 261 while(1) { 262 int index = strtol(ptr, &endptr, 10); 263 if (ptr == endptr || index == -1) { 264 if (vertices.size() > 2) { 265 Face *face = new Face(vertices); 266 267 if (!mLoadPolygonsAsMeshes) 268 { 269 mCurrentMesh->mFaces.push_back(face); 270 } 271 else 272 // every polygon is a mesh 273 { 274 mCurrentVertexIndices.push_back(vertices); 275 } 276 } 277 278 vertices.clear(); 279 if (ptr == endptr) 280 break; 281 } else { 282 vertices.push_back(index); 283 } 284 ptr = endptr; 285 } 286 } 287 } 288 } 330 mIsMeshDefinition = false; 331 mUsingMeshDefinition = false; 332 for (i = 0; i < len; ++ i) 333 { 334 string attrName(StrX(attributes.getName(i)).LocalForm()); 335 336 // this is a definition of a mesh 337 if (attrName == "DEF") 338 { 339 mIsMeshDefinition = true; 340 StrX attrValue(attributes.getValue(i)); 341 const char *ptr = attrValue.LocalForm(); 342 mCurrentMeshName = ptr; 343 344 cout << "d"; 345 } 346 347 // we use an already defined mesh 348 if (attrName == "USE") 349 { 350 StrX attrValue(attributes.getValue(i)); 351 352 // discard new mesh and assign defined mesh 353 DEL_PTR(mCurrentMesh); 354 const char *ptr = attrValue.LocalForm(); 355 356 mCurrentMesh = mMeshDefinitions[ptr]; 357 mUsingMeshDefinition = true; 358 cout << "u"; 359 } 360 361 if (attrName == "coordIndex") 362 { 363 StrX attrValue(attributes.getValue(i)); 364 // handle coordIndex 365 vertices.clear(); 366 const char *ptr = attrValue.LocalForm(); 367 368 char *endptr; 369 370 while (1) 371 { 372 int index = strtol(ptr, &endptr, 10); 373 374 if (ptr == endptr || index == -1) 375 { 376 if (vertices.size() > 2) 377 { 378 Face *face = new Face(vertices); 379 mCurrentMesh->mFaces.push_back(face); 380 } 381 382 vertices.clear(); 383 384 if (ptr == endptr) 385 break; 386 387 } 388 else 389 { 390 vertices.push_back(index); 391 } 392 ptr = endptr; 393 } 394 } 395 } 396 } 397 289 398 290 399 void … … 358 467 vertices.push_back(v); 359 468 } 360 if (mLoadPolygonsAsMeshes) 361 { 362 mCurrentVertices = vertices; 363 } 364 else 365 { 366 mCurrentMesh->mVertices = vertices; 367 } 469 470 mCurrentMesh->mVertices = vertices; 368 471 } 369 472 } … … 388 491 } 389 492 390 if (element == "Coordinate") { 493 if (element == "Coordinate") 494 { 391 495 if (mCurrentMesh) 392 496 StartCoordinate(attributes); … … 396 500 StartMaterial(attributes); 397 501 } 398 if (1) 502 399 503 if (element == "Transform") { 400 504 StartTransform(attributes); … … 599 703 X3dViewCellsParseHandlers::EndShape() 600 704 { 705 // currently processing no shape 601 706 } 602 707 … … 607 712 int len = attributes.getLength(); 608 713 int i; 714 609 715 // clear previous vertex indices 610 716 mCurrentVertexIndices.clear(); 717 718 611 719 for (i=0; i < len; i++) 612 720 { 613 721 string attrName(StrX(attributes.getName(i)).LocalForm()); 614 722 723 615 724 if (attrName == "coordIndex") 616 725 { -
GTP/trunk/Lib/Vis/Preprocessing/src/X3dParserXerces.h
r712 r752 18 18 class Material; 19 19 class ViewCellsManager; 20 21 struct ltstr 22 { 23 bool operator()(const string &s1, const string &s2) const 24 { 25 return s1 < s2; 26 } 27 }; 28 29 typedef map<string, Mesh *, ltstr> MeshDefinitions; 30 typedef map<string, Material *, ltstr> MaterialDefinitions; 20 31 21 32 class X3dParseHandlers : public HandlerBase … … 66 77 vector<VertexIndexContainer> mCurrentVertexIndices; 67 78 VertexContainer mCurrentVertices; 79 string mCurrentMeshName; 68 80 69 81 Material *mCurrentMaterial; 82 70 83 bool mLoadPolygonsAsMeshes; 71 84 72 85 typedef stack<Matrix4x4> TrafoStack; 73 86 87 bool mUsingMeshDefinition; 74 88 // stack of accumulated transformations 75 89 TrafoStack mTransformations; 76 90 91 MaterialDefinitions mMaterialDefinitions; 92 MeshDefinitions mMeshDefinitions; 93 94 bool mIsMeshDefinition; 77 95 // Handlers for X3D 78 96 void
Note: See TracChangeset
for help on using the changeset viewer.