Changeset 2539 for GTP/trunk/Lib/Vis
- Timestamp:
- 08/08/07 15:50:33 (17 years ago)
- Location:
- GTP/trunk/Lib/Vis
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/OnlineCullingCHC/src/RandomUpdateCullingManager.cpp
r2538 r2539 106 106 int nodesTested = 0; 107 107 108 // use different algorithm to find random candidates109 108 #if 1 109 // test a certain ratio of random candidates 110 110 HierarchyNodeContainer mynodes; 111 111 mHierarchyInterface->CollectLeaves(node, mynodes); … … 144 144 145 145 #else 146 146 // always test one random candidate 147 147 HierarchyNode *leaf = mHierarchyInterface->GetRandomLeaf(node); 148 148 -
GTP/trunk/Lib/Vis/Preprocessing/scripts/generate_viewcells.env
r2537 r2539 7 7 8 8 filename ../data/vienna/vienna_cropped.obj 9 # filename ../data/soda/soda.dat10 # filename ../data/soda/soda5.dat11 # filename ../data/artificial/cube_test.x3d12 # filename ../data/CityModel.obj13 # filename ../data/arena/arena-low-lods.obj14 9 } 15 10 … … 21 16 loadMeshes false 22 17 23 # internal raycaster 18 # internal raycaster: 0, intel: 1 24 19 rayCastMethod 0 25 # intel raycaster26 #rayCastMethod 127 20 28 21 exportVisibility false … … 32 25 33 26 34 RssPreprocessor {35 distributions mutation+spatial+object_direction36 #distributions spatial37 38 39 useImportanceSampling true40 41 Export {42 pvs false43 rssTree false44 }45 46 useViewcells true47 updateSubdivision true48 loadInitialSamples false49 storeInitialSamples false50 51 useRssTree true52 }53 54 55 56 27 VssTree { 57 useRss false58 epsilon 1e-659 60 28 maxDepth 2 61 minPvs 30 62 minRays 800 63 minSize 0.001 64 maxCostRatio 1.5 65 maxRayContribution 0.5 66 29 67 30 maxTotalMemory 50 68 31 maxStaticMemory 20 69 32 70 33 splitType regular 71 # splitType heuristic72 # splitType hybrid73 34 splitUseOnlyDrivingAxis true 74 75 interleaveDirSplits true76 dirSplitDepth 077 78 numberOfEndPointDomains 1000079 ct_div_ci 0.080 randomize false81 82 refDirBoxMaxSize 0.183 35 } 84 36 … … 88 40 small 1e-6 89 41 infinity 1e9 90 }91 92 93 Unigraphics {94 meshGrouping 195 42 } 96 43 … … 107 54 } 108 55 109 # splitMethod spatialMedian110 56 splitMethod SAH 111 57 splitBorder 0.01 … … 120 66 } 121 67 122 # splitMethod spatialMedian123 68 splitMethod SAH 124 69 splitBorder 0.01 … … 146 91 type vspOspTree 147 92 148 # percentage of total visible objects wherepvs is considered invalid93 #this ratio of the biggest pvs gives the threshold when a pvs is considered invalid 149 94 maxPvsRatio 1.0 150 95 … … 175 120 } 176 121 177 showVisualization true178 #showVisualization false122 #showVisualization true 123 showVisualization false 179 124 evaluateViewCells false 180 125 181 126 182 127 Evaluation { 183 128 samples 80000000 … … 210 155 Termination { 211 156 minPvs 0 212 maxViewCells 500000 213 } 214 157 maxViewCells 4000 158 } 159 160 # heuristics for computing local split planes 215 161 useCostHeuristics false 216 splitUseOnlyDrivingAxis false217 162 218 163 # maximum number of tests per node … … 230 175 Construction { 231 176 renderCostDecreaseWeight 0.999 232 } 233 234 Termination { 235 maxLeaves 3000 177 #renderCostDecreaseWeight 1.0 178 } 179 180 Termination { 181 maxLeaves 4000 236 182 } 237 183 238 184 minRaysForVisibility 3 239 #minRaysForVisibility 15 240 241 useCostHeuristics false 185 186 # heuristics for computing local split planes 187 useCostHeuristics true 188 # surface area or visibility based heuristics 242 189 useSah false 243 190 … … 281 228 Termination { 282 229 # maximal number of leaves 283 maxLeaves 30000 230 maxLeaves 300000 284 231 # maximal memory in MB 285 maxMemory 17 232 # maxMemory 4 233 maxMemory 200 286 234 # minimum ratio of global cost decrease 287 235 minGlobalCostRatio -1 -
GTP/trunk/Lib/Vis/Preprocessing/scripts/generate_viewcells.sh
r2535 r2539 8 8 9 9 PROGRAM=../bin/$TARGET/Preprocessor.exe 10 #PROGRAM=../bin/$TARGET/Preprocessor_itl.exe 10 11 11 12 12 EXT=obj … … 15 15 SCENE_PATH=../data/vienna 16 16 17 #SCENE=arena-high-lods 18 #SCENE_PATH=../data/Arena 19 20 17 21 ENVIRONMENT=generate_viewcells.env 18 LOG_PREFIX= ../scripts/$SCENE22 LOG_PREFIX=$SCENE 19 23 20 24 echo "starting $TARGET mode for $SCENE scene ($PROGRAM)" … … 22 26 SCENE_FILENAME=$SCENE_PATH/$SCENE.$EXT 23 27 24 OBJ_WEIGHT=2025 28 26 29 ####################################################### … … 28 31 METHOD=seq 29 32 30 # the # of bvh nodes 31 NODES=3000 33 NODES=4000 34 VIEWCELLS=4000 35 #USE_HEUR=true 36 USE_HEUR=false 37 OBJ_WEIGHT=20 32 38 33 39 … … 42 48 -hierarchy_subdivision_stats=$LOG_PREFIX-$METHOD-hierarchy-subdivisionStats.log \ 43 49 -hierarchy_construction_type=0 \ 44 -vsp_use_cost_heuristics=false \ 45 -bvh_term_max_leaves=$NODES 50 -view_cells_triangle_weight=1.0 \ 51 -view_cells_object_weight=$OBJ_WEIGHT \ 52 -vsp_use_cost_heuristics=$USE_HEUR \ 53 -bvh_term_max_leaves=$NODES \ 54 -vsp_term_max_view_cells=$VIEWCELLS 46 55 47 56 sh movefiles.sh $LOG_PREFIX-$METHOD 57 -
GTP/trunk/Lib/Vis/Preprocessing/scripts/gi_final.sh
r2535 r2539 8 8 9 9 PROGRAM=../bin/$TARGET/Preprocessor.exe 10 #PROGRAM=../bin/$TARGET/Preprocessor_itl.exe11 10 12 11 EXT=obj -
GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
r2538 r2539 407 407 glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId); 408 408 409 int offset = mObjects.size() * 3;409 int offset = (int)mObjects.size() * 3; 410 410 char *arrayPtr = mUseVbos ? NULL : (char *)mData; 411 411 … … 413 413 glNormalPointer(GL_FLOAT, 0, (char *)arrayPtr + offset * sizeof(Vector3)); 414 414 415 glDrawArrays(GL_TRIANGLES, 0, mObjects.size() * 3);415 glDrawArrays(GL_TRIANGLES, 0, (int)mObjects.size() * 3); 416 416 //DisableDrawArrays(); 417 417 } … … 1651 1651 return; 1652 1652 1653 unsigned int offset = mObjects.size() * 3;1653 size_t offset = mObjects.size() * 3; 1654 1654 char *arrayPtr = mUseVbos ? NULL : (char *)mData; 1655 1655 … … 1667 1667 mIndices = new unsigned int[mObjects.size() * 3]; 1668 1668 1669 const int offset = mObjects.size() * 3;1669 size_t offset = mObjects.size() * 3; 1670 1670 1671 1671 for (size_t i = 0; i < mObjects.size(); ++ i) … … 1703 1703 } 1704 1704 1705 cout << "\n******** ******\ndraw arrays created\n" << endl;1705 cout << "\n******** created vertex buffer objects **********" << endl; 1706 1706 } 1707 1707 -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
r2353 r2539 1750 1750 1751 1751 1752 /** Deletes the ray refs from the all the objects in the container. 1753 */ 1752 1754 static void RemoveRayRefs(const ObjectContainer &objects) 1753 1755 { … … 1826 1828 else 1827 1829 { 1830 // just output boxes of objects 1828 1831 ObjectContainer::const_iterator oit, oit_end = objects.end(); 1829 1832 … … 1842 1845 1843 1846 1847 1848 1849 ///////////////////////// 1850 1844 1851 class HierarchyNodeWrapper; 1845 1852 … … 1858 1865 myless<vector<HierarchyNodeWrapper *>::value_type> > HierarchyNodeQueue; 1859 1866 1867 /** A wrapper for a hierarchy node. This class let's us treat vsp and bvh nodes 1868 as if they were inherited from the same class. 1869 */ 1860 1870 class HierarchyNodeWrapper 1861 1871 { … … 1871 1881 1872 1882 1883 /** Class wrapping a vsp node. 1884 */ 1873 1885 class VspNodeWrapper: public HierarchyNodeWrapper 1874 1886 { … … 1893 1905 } 1894 1906 1907 ////////// 1908 1895 1909 VspNode *mNode; 1896 1910 }; 1897 1911 1898 1912 1913 /** Class wrapping a bvh node. 1914 */ 1899 1915 class BvhNodeWrapper: public HierarchyNodeWrapper 1900 1916 { … … 1918 1934 } 1919 1935 } 1936 1937 //////////// 1920 1938 1921 1939 BvhNode *mNode; … … 1950 1968 } 1951 1969 1970 ////////// 1971 1952 1972 ViewCell *mViewCell; 1953 1973 }; 1974 1975 ////////////////////////////// 1976 1954 1977 1955 1978 … … 1960 1983 { 1961 1984 HierarchyNodeQueue tqueue; 1962 //tqueue.push(new VspNodeWrapper(mVspTree->GetRoot())); 1985 1963 1986 tqueue.push(new ViewCellWrapper(mVspTree->mViewCellsTree->GetRoot())); 1964 1987 tqueue.push(new BvhNodeWrapper(mBvHierarchy->GetRoot())); … … 1970 1993 HierarchyNodeWrapper *nodeWrapper = tqueue.top(); 1971 1994 tqueue.pop(); 1972 //cout << "priority: " << nodeWrapper->GetMergeCost() << endl; 1973 // save the view cells if it is a leaf or if enough view cells have already been traversed 1974 // because of the priority queue, this will be the optimal set of view cells 1995 1996 // save the view cells if it is a leaf or if enough view cells 1997 // have already been traversed because of the priority queue, 1998 // this will be the optimal set of view cells 1999 1975 2000 if (nodeWrapper->IsLeaf() || 1976 2001 ((viewCells.size() + bvhNodes.size() + tqueue.size() + 1) >= maxSplits) || … … 2517 2542 } 2518 2543 2519 2520 } 2544 } -
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
r2524 r2539 13 13 using namespace std; 14 14 15 // $$JB HACK16 //#define KD_PVS_AREA (1e-4f)17 15 18 16 #define TYPE_INTERIOR -2 … … 32 30 33 31 34 KdNode::KdNode(KdInterior *parent): mParent(parent), mMailbox(0), mIntersectable(NULL)35 36 { 37 38 39 40 32 KdNode::KdNode(KdInterior *parent): 33 mParent(parent), mMailbox(0), mIntersectable(NULL) 34 { 35 if (parent) 36 mDepth = parent->mDepth+1; 37 else 38 mDepth = 0; 41 39 } 42 40 … … 57 55 58 56 KdTree::KdTree() 59 { 60 61 57 { 62 58 mRoot = new KdLeaf(NULL, 0); 63 59 Environment::GetSingleton()->GetIntValue("KdTree.Termination.maxNodes", mTermMaxNodes); … … 194 190 (leaf->mDepth >= mTermMaxDepth); 195 191 196 if ( criteriaMet)192 if (0 && criteriaMet) 197 193 cerr<<"\n OBJECTS="<<(int)leaf->mObjects.size()<<endl; 198 194 … … 1132 1128 1133 1129 1134 int 1135 KdTree::CastBeam( 1136 Beam &beam 1137 ) 1130 int KdTree::CastBeam(Beam &beam) 1138 1131 { 1139 1132 stack<KdNode *> nodeStack; … … 1221 1214 1222 1215 // read object ids 1223 // note: could also do thisgeometrically1216 // note: this can also be done geometrically 1224 1217 for (int i = 0; i < size; ++ i) 1225 1218 { … … 1231 1224 1232 1225 if ((oit != objects.end()) && ((*oit)->GetId() == objId)) 1233 { 1234 if (1) leaf->mObjects.push_back(*oit); 1235 } 1226 leaf->mObjects.push_back(*oit); 1236 1227 else 1237 {1238 1228 Debug << "error: object with id " << objId << " does not exist" << endl; 1239 }1240 1229 } 1241 1230 … … 1261 1250 KdInterior *interior = new KdInterior(parent); 1262 1251 1263 int axis = interior->mAxis;1264 float pos = interior->mPosition;1252 int axis; 1253 float pos; 1265 1254 1266 1255 stream.read(reinterpret_cast<char *>(&axis), sizeof(int)); … … 1310 1299 1311 1300 1312 KdNode *KdTree:: LoadNextNode(IN_STREAM &stream,1313 KdInterior *parent,1314 const ObjectContainer &objects)1301 KdNode *KdTree::ImportNextNode(IN_STREAM &stream, 1302 KdInterior *parent, 1303 const ObjectContainer &objects) 1315 1304 { 1316 1305 int nodeType; … … 1318 1307 1319 1308 if (nodeType == TYPE_LEAF) 1320 {1321 1309 return ImportBinLeaf(stream, static_cast<KdInterior *>(parent), objects); 1322 }1323 1310 1324 1311 if (nodeType == TYPE_INTERIOR) 1325 {1326 1312 return ImportBinInterior(stream, static_cast<KdInterior *>(parent)); 1327 }1328 1313 1329 1314 Debug << "error! loading failed!" << endl; 1330 1331 1315 return NULL; 1332 1316 } 1333 1317 1334 1318 1335 bool KdTree:: LoadBinTree(const string &filename, ObjectContainer &objects)1319 bool KdTree::ImportBinTree(const string &filename, ObjectContainer &objects) 1336 1320 { 1337 1321 // export binary version of mesh … … 1342 1326 1343 1327 // sort objects by their id 1344 sort(objects.begin(), objects.end(), ilt); 1328 // if (!is_sorted(objects.begin(), objects.end(), ilt)) 1329 sort(objects.begin(), objects.end(), ilt); 1345 1330 1346 1331 mBox.Initialize(); … … 1359 1344 DEL_PTR(mRoot); 1360 1345 1361 mRoot = LoadNextNode(stream, NULL, objects);1346 mRoot = ImportNextNode(stream, NULL, objects); 1362 1347 1363 1348 tStack.push(TraversalData(mRoot, mBox, 0)); … … 1380 1365 interior->mBox = tData.mBox; 1381 1366 1382 KdNode *front = LoadNextNode(stream, interior, objects);1383 KdNode *back = LoadNextNode(stream, interior, objects);1367 KdNode *front = ImportNextNode(stream, interior, objects); 1368 KdNode *back = ImportNextNode(stream, interior, objects); 1384 1369 1385 1370 interior->SetupChildLinks(back, front); -
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h
r2538 r2539 417 417 418 418 bool ExportBinTree(const std::string &filename); 419 420 /// loads kd tree from disk. note: sorts objects by id421 bool LoadBinTree(const std::string &filename, ObjectContainer &object);419 /** loads kd tree from disk. note: sorts objects by id 420 */ 421 bool ImportBinTree(const std::string &filename, ObjectContainer &object); 422 422 423 423 protected: … … 589 589 void ProcessMultipleRefs(KdLeaf *leaf) const; 590 590 591 592 ////////// 593 // binary import / export 594 591 595 void ExportBinLeaf(OUT_STREAM &stream, KdLeaf *leaf); 596 592 597 void ExportBinInterior(OUT_STREAM &stream, KdInterior *interior); 598 593 599 KdLeaf *ImportBinLeaf(IN_STREAM &stream, KdInterior *parent, const ObjectContainer &objects); 600 594 601 KdInterior *ImportBinInterior(IN_STREAM &stream, KdInterior *parent); 595 KdNode *LoadNextNode(IN_STREAM &stream, KdInterior *parent, const ObjectContainer &objects); 602 603 KdNode *ImportNextNode(IN_STREAM &stream, KdInterior *parent, const ObjectContainer &objects); 596 604 597 605 /** Adds this objects to the kd leaf objects. -
GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.cpp
r2307 r2539 79 79 const int line) 80 80 { 81 vector<char *> substrings; 82 83 // extract the triples of the form v/t/n v/t/n ... 81 84 char *pch = strtok(str + 1, " "); 82 85 86 while (pch != NULL) 87 { 88 substrings.push_back(pch); 89 pch = strtok(NULL, " "); 90 } 91 92 //for (int i = 0; i < substrings.size(); ++ i) 93 // cout << "sub: " << substrings[i] << " "; 94 83 95 VertexIndexContainer indices; 84 int i = 0; 85 while (pch != NULL) 86 {++ i; 87 const int index = (int)strtol(pch, NULL, 10) - 1; 88 89 // store vertex in hash table 90 //hashTable[index] = vertices[index]; 91 if (index >= 0) 92 indices.push_back(index); 93 94 pch = strtok(NULL, " "); 95 96 // problem: don't know how intel ray tracer tesselates 97 if ((int)indices.size() > 2) 96 97 for (int i = 0; i < substrings.size(); ++ i) 98 { 99 // discard normal and texture indices 100 // and only keep first index 101 102 char *str = strtok(substrings[i], "/"); 103 const int index = (int)strtol(str, NULL, 10) - 1; 104 105 // store indices 106 if (index >= 0) 107 indices.push_back(index); 108 109 //cout << "i " << index << " "; 110 111 // new triangle found 112 // problem: don't know how intel ray tracer tesselates 113 if ((int)indices.size() > 2) 98 114 { 99 const int i ndex_2 = (int)indices.size() - 2;100 const int i ndex_3 = (int)indices.size() - 1;115 const int idx2 = (int)indices.size() - 2; 116 const int idx3 = (int)indices.size() - 1; 101 117 102 118 triangles.push_back(Triangle3(vertices[indices[0]], 103 vertices[indices[i ndex_2]],104 vertices[indices[i ndex_3]]));119 vertices[indices[idx2]], 120 vertices[indices[idx3]])); 105 121 } 106 122 } 107 //if (line == 451703)108 // cout << "t: " << triangles.size() << endl;109 123 } 110 124 … … 230 244 while (fgets(str, 100000, file) != NULL) 231 245 { 232 246 switch (str[0]) 233 247 { 234 248 case 'v': // vertex or normal 235 {236 switch (str[1])237 249 { 238 case 'n' : 239 // normal do nothing 250 switch (str[1]) 251 { 252 case 'n' : 253 // do nothing for normals 254 break; 255 case 't': 256 // do nothing for textures 257 break; 258 default: 259 float x, y, z; //cout << "v"; 260 sscanf(str + 1, "%f %f %f", &x, &y, &z); 261 vertices.push_back(Vector3(x,y,z)); 262 263 } 240 264 break; 241 default:242 float x, y, z; //cout << "v";243 sscanf(str + 1, "%f %f %f", &x, &y, &z);244 vertices.push_back(Vector3(x,y,z));245 246 265 } 247 break;248 }249 266 case 'f': 250 267 { … … 254 271 255 272 if (!face) break; 256 273 257 274 faces.push_back(face); 258 275 … … 265 282 { 266 283 ++ line; 284 285 ////////// 286 // construct the triangles given in the current line 287 267 288 vector<Triangle3> triangles; 268 269 289 LoadTriangles(str, vertices, triangles, line); 270 290 … … 273 293 for (tit = triangles.begin(); tit != tit_end; ++ tit) 274 294 { 295 // test if it is a valid triangle 275 296 if (0 && !TriangleValid(*tit)) continue; 276 297 277 298 TriangleIntersectable *obj = new TriangleIntersectable(*tit); 278 299 root->mGeometry.push_back(obj); 279 300 } 280 301 } … … 285 306 } 286 307 } 287 308 288 309 //cout << "\n**** " << root->mGeometry.size() << " " << " lines: " << line << endl; 289 310 if (loadMeshes) -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r2452 r2539 816 816 { 817 817 mKdTree = new KdTree(); 818 819 return mKdTree->LoadBinTree(filename.c_str(), mObjects); 818 return mKdTree->ImportBinTree(filename.c_str(), mObjects); 820 819 } 821 820 … … 1191 1190 if (rays.size() > 10000) 1192 1191 { 1193 1192 1194 1193 mRayCaster->SortRays(rays); 1195 1194 cout<<"Rays sorted in "<<TimeDiff(t1, GetTime())<<" ms."<<endl; … … 1199 1198 if (mUseHwGlobalLines) 1200 1199 { 1201 1202 1203 1204 1205 1206 1200 CastRaysWithHwGlobalLines( 1201 rays, 1202 vssRays, 1203 castDoubleRays, 1204 pruneInvalidRays 1205 ); 1207 1206 } 1208 1207 else 1209 1208 { 1210 1211 1212 1213 1214 1215 1209 mRayCaster->CastRays( 1210 rays, 1211 vssRays, 1212 mViewCellsManager->GetViewSpaceBox(), 1213 castDoubleRays, 1214 pruneInvalidRays); 1216 1215 } 1217 1216 … … 1219 1218 { 1220 1219 cout << endl; 1221 1220 long t2 = GetTime(); 1222 1221 1223 1222 #if SHOW_RAYCAST_TIMING -
GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp
r2198 r2539 400 400 401 401 for (rit = rays.begin(); rit != rit_end; ++ rit) { 402 402 403 CastRay( 403 404 *rit, -
GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj
r2530 r2539 131 131 ConfigurationType="1" 132 132 CharacterSet="2" 133 WholeProgramOptimization=" TRUE">133 WholeProgramOptimization="FALSE"> 134 134 <Tool 135 135 Name="VCCLCompilerTool" -
GTP/trunk/Lib/Vis/Preprocessing/src/Timer/merror.h
r2066 r2539 249 249 #define CHKGL _BLBEGIN GLenum error; \ 250 250 if ( (error = glGetError()) != GL_NO_ERROR) \ 251 EOUT(" here4" << gluErrorString(error)); _BLEND;251 EOUT("gl error " << gluErrorString(error)); _BLEND; 252 252 253 253 #ifdef WIN32 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r2342 r2539 19 19 namespace GtpVisibilityPreprocessor { 20 20 21 22 #define TYPE_INTERIOR -2 23 #define TYPE_LEAF -3 24 25 26 static inline bool ilt(Intersectable *obj1, Intersectable *obj2) 27 { 28 return obj1->mId < obj2->mId; 29 } 21 30 22 31 … … 121 130 } 122 131 132 123 133 ViewCell::ViewCell(Mesh *mesh): 124 134 MeshInstance(mesh), … … 131 141 mPvsSizeValid(false), 132 142 mFilteredPvsSize(0) 133 //mMailbox(0)134 143 { 135 144 mId = -100; … … 302 311 // erase leaf from old view cell 303 312 ViewCellContainer::iterator it = mChildren.begin(); 304 305 313 for (; (*it) != prev; ++ it); 314 306 315 if (it == mChildren.end()) 307 {308 316 Debug << "error: child link not found" << endl; 309 }310 317 else 311 {312 318 (*it) = cur; 313 }314 319 } 315 320 … … 428 433 429 434 stack<ViewCell *> tstack; 430 431 435 tstack.push(vc); 432 436 … … 443 447 { 444 448 ViewCellInterior *interior = static_cast<ViewCellInterior *>(vc); 445 446 449 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 447 450 … … 450 453 tstack.push(*it); 451 454 } 452 453 455 } 454 456 } … … 2020 2022 } 2021 2023 2022 //#if HAS_TO_BE_REDONE 2024 2023 2025 int ViewCellsTree::CountStoredPvsEntries(ViewCell *root) const 2024 2026 { … … 2029 2031 { 2030 2032 ViewCellInterior *interior = static_cast<ViewCellInterior *>(root); 2031 2032 2033 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 2033 2034 … … 2040 2041 return pvsSize; 2041 2042 } 2042 //#endif 2043 2043 2044 2044 2045 int ViewCellsTree::ViewCellsStorage() const … … 2587 2588 2588 2589 2589 } 2590 /////////////////// 2591 // Binary export 2592 2593 void ViewCellsTree::ExportBinInterior(OUT_STREAM &stream, ViewCellInterior *interior) 2594 { 2595 #if TODO 2596 int interiorid = TYPE_INTERIOR; 2597 stream.write(reinterpret_cast<char *>(&interiorid), sizeof(int)); 2598 2599 int axis = interior->GetAxis(); 2600 float pos = interior->GetPosition(); 2601 2602 stream.write(reinterpret_cast<char *>(&axis), sizeof(int)); 2603 stream.write(reinterpret_cast<char *>(&pos), sizeof(float)); 2604 #endif 2605 } 2606 2607 2608 void ViewCellsTree::ExportBinLeaf(OUT_STREAM &stream, ViewCell *leaf) 2609 { 2610 #if TODO 2611 int type = TYPE_LEAF; 2612 2613 int id = -1; 2614 if (viewCell != mOutOfBoundsCell) 2615 id = viewCell->GetId(); 2616 2617 stream.write(reinterpret_cast<char *>(&type), sizeof(int)); 2618 stream.write(reinterpret_cast<char *>(&id), sizeof(int)); 2619 2620 int pvsSize = viewCell->GetPvs().GetSize(); 2621 stream.write(reinterpret_cast<char *>(&pvsSize), sizeof(int)); 2622 2623 ObjectPvsIterator pit = viewCell->GetPvs().GetIterator(); 2624 2625 // write PVS of view cell 2626 while (pit.HasMoreEntries()) 2627 { 2628 Intersectable *intersect = pit.Next(); 2629 id = intersect->GetId(); 2630 stream.write(reinterpret_cast<char *>(&id), sizeof(int)); 2631 } 2632 #endif 2633 } 2634 2635 2636 bool ViewCellsTree::ExportBinary(OUT_STREAM &stream) 2637 { 2638 #if TODO 2639 // export binary version of mesh 2640 queue<ViewCell *> tStack; 2641 tStack.push(mRoot); 2642 2643 while(!tStack.empty()) 2644 { 2645 ViewCell *node = tStack.front(); 2646 tStack.pop(); 2647 2648 if (node->IsLeaf()) 2649 { 2650 ExportBinLeaf(stream, static_cast<ViewCellLeaf *>(node)); 2651 } 2652 else 2653 { 2654 VspInterior *interior = static_cast<ViewCellInterior *>(node); 2655 2656 ExportBinInterior(stream, interior); 2657 2658 tStack.push(interior->GetFront()); 2659 tStack.push(interior->GetBack()); 2660 } 2661 } 2662 #endif 2663 return true; 2664 } 2665 2666 2667 ////////////////// 2668 // import binary 2669 2670 ViewCellInterior *ViewCellsTree::ImportBinInterior(IN_STREAM &stream, ViewCellInterior *parent) 2671 { 2672 ViewCellInterior *interior = new ViewCellInterior(); 2673 return interior; 2674 } 2675 2676 2677 ViewCellLeaf *ViewCellsTree::ImportBinLeaf(IN_STREAM &stream, 2678 ViewCellInterior *parent, 2679 const ObjectContainer &pvsObjects) 2680 { 2681 int leafId = TYPE_LEAF; 2682 int objId = leafId; 2683 int size; 2684 2685 stream.read(reinterpret_cast<char *>(&size), sizeof(int)); 2686 VspViewCell *leaf = new VspViewCell(); 2687 2688 MeshInstance dummyInst(NULL); 2689 2690 // read object ids 2691 for (int i = 0; i < size; ++ i) 2692 { 2693 stream.read(reinterpret_cast<char *>(&objId), sizeof(int)); 2694 dummyInst.SetId(objId); 2695 2696 ObjectContainer::const_iterator oit = 2697 lower_bound(pvsObjects.begin(), pvsObjects.end(), (Intersectable *)&dummyInst, ilt); 2698 2699 if ((oit != pvsObjects.end()) && ((*oit)->GetId() == objId)) 2700 leaf->GetPvs().AddSample(*oit, 0); 2701 else 2702 Debug << "error: object with id " << objId << " does not exist" << endl; 2703 } 2704 2705 return leaf; 2706 } 2707 2708 2709 ViewCell *ViewCellsTree::ImportNextNode(IN_STREAM &stream, 2710 ViewCellInterior *parent, 2711 const ObjectContainer &objects) 2712 { 2713 int nodeType; 2714 stream.read(reinterpret_cast<char *>(&nodeType), sizeof(int)); 2715 2716 if (nodeType == TYPE_LEAF) 2717 return ImportBinLeaf(stream, static_cast<ViewCellInterior *>(parent), objects); 2718 2719 if (nodeType == TYPE_INTERIOR) 2720 return ImportBinInterior(stream, static_cast<ViewCellInterior *>(parent)); 2721 2722 Debug << "error! loading failed!" << endl; 2723 return NULL; 2724 } 2725 2726 2727 /** Data used for tree traversal 2728 */ 2729 struct MyTraversalData 2730 { 2731 public: 2732 2733 MyTraversalData(ViewCell *node, const int depth, const AxisAlignedBox3 &box): 2734 mNode(node), mDepth(depth), mBox(box) 2735 {} 2736 2737 2738 ////////////////////// 2739 2740 /// the current node 2741 ViewCell *mNode; 2742 /// current depth 2743 int mDepth; 2744 /// the bounding box 2745 AxisAlignedBox3 mBox; 2746 }; 2747 2748 2749 bool ViewCellsTree::ImportBinary(IN_STREAM &stream, const ObjectContainer &pvsObjects) 2750 { 2751 // export binary version of mesh 2752 queue<ViewCell *> tStack; 2753 2754 // hack: we make a new root 2755 DEL_PTR(mRoot); 2756 2757 mRoot = ImportNextNode(stream, NULL, pvsObjects); 2758 2759 tStack.push(mRoot); 2760 2761 while(!tStack.empty()) 2762 { 2763 ViewCell *viewCell = tStack.front(); 2764 tStack.pop(); 2765 2766 if (!viewCell->IsLeaf()) 2767 { 2768 ViewCellInterior *interior = static_cast<ViewCellInterior *>(viewCell); 2769 2770 ViewCell *front = ImportNextNode(stream, interior, pvsObjects); 2771 ViewCell *back = ImportNextNode(stream, interior, pvsObjects); 2772 2773 interior->mChildren.push_back(front); 2774 interior->mChildren.push_back(back); 2775 2776 tStack.push(front); 2777 tStack.push(back); 2778 } 2779 else 2780 { 2781 //cout << "l"; 2782 } 2783 } 2784 2785 return true; 2786 } 2787 2788 2789 2790 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h
r2387 r2539 547 547 */ 548 548 ViewCell *GetActiveViewCell(ViewCellLeaf *vc) const; 549 550 549 /** Sets the leaves to be the currently active view cells. 551 550 */ 552 551 void SetActiveSetToLeaves(); 553 554 552 /** Propagates pvs up the tree to the root and downwards the tree. 555 553 */ 556 554 void PropagatePvs(ViewCell *vc); 557 558 555 /** Exports view cells to file. 559 556 */ 560 557 bool Export(OUT_STREAM &stream, const bool exportPvs = false); 561 562 558 /** Export statistics of this view cell tree. 563 559 */ 564 560 void ExportStats(const std::string &mergeStats); 565 566 561 /** Sets root of hierarchy. 567 562 */ 568 563 void SetRoot(ViewCell *root); 569 570 564 /** Assignes unique ids to view cells. 571 565 */ 572 566 void CreateUniqueViewCellsIds(); 573 574 567 /** Resets pvs of whole tree. 575 568 */ 576 569 void ResetPvs(); 577 578 570 /** Counts pvs of the view cell taking the kd cells into account. 579 571 */ 580 572 int CountKdPvs(const ViewCellLeaf *vc) const; 581 582 573 /** Sets pointer to view cells manager. 583 574 */ 584 575 void SetViewCellsManager(ViewCellsManager *vcm); 585 576 586 void Update(); 577 ViewCellInterior *ImportBinInterior(IN_STREAM &stream, ViewCellInterior *parent); 578 579 ViewCellLeaf *ImportBinLeaf(IN_STREAM &stream, 580 ViewCellInterior *parent, 581 const ObjectContainer &pvsObjects); 582 583 void ExportBinInterior(OUT_STREAM &stream, ViewCellInterior *interior); 584 585 void ExportBinLeaf(OUT_STREAM &stream, ViewCell *leaf); 586 587 bool ExportBinary(OUT_STREAM &stream); 588 589 bool ImportBinary(IN_STREAM &stream, const ObjectContainer &pvsObjects); 590 591 ViewCell *ImportNextNode(IN_STREAM &stream, 592 ViewCellInterior *parent, 593 const ObjectContainer &objects); 587 594 588 595 protected: … … 601 608 */ 602 609 float ComputeMergedPvsCost(const ObjectPvs &pvs1, const ObjectPvs &pvs2) const; 603 604 610 /** Returns cost of this leaf according to current heuristics. 605 611 */ 606 612 float GetCostHeuristics(ViewCell *vc) const; 607 608 613 /** Returns cost of leaf. 609 614 */ 610 615 float GetRenderCost(ViewCell *vc) const; 611 612 616 /** Evaluates the merge cost of this merge candidate pair. 613 617 */ 614 618 void EvalMergeCost(MergeCandidate &mc) const; 615 616 619 /** Variance of leaf. 617 620 */ 618 621 float GetVariance(ViewCell *vc) const; 619 620 622 /** Standard deviation of leaf. 621 623 */ 622 624 float GetDeviation(ViewCell *vc) const; 623 624 625 /** Tries to set this merge candidate to valid. 625 626 @returns false if both view cells are the same 626 627 */ 627 628 bool ValidateMergeCandidate(MergeCandidate &mc) const; 628 629 629 /** Merge view cells of leaves l1 and l2. 630 630 @returns difference in pvs size 631 631 */ 632 632 ViewCellInterior *MergeViewCells(ViewCell *l, ViewCell *r, float &pvsDiff); 633 634 633 /** Shuffles, i.e. takes border leaf from view cell 1 and adds it 635 634 to view cell 2. 636 635 */ 637 636 void ShuffleLeaf(ViewCell *leaf, ViewCellInterior *vc1, ViewCellInterior *vc2) const; 638 639 637 /** Shuffles the leaves, i.e., tests if exchanging 640 638 the leaves helps in improving the view cells. 641 639 */ 642 640 bool ShuffleLeaves(MergeCandidate &mc) const; 643 644 641 /** Calculates cost for merge of view cell 1 and 2. 645 642 */ … … 647 644 ViewCellInterior *vc1, 648 645 ViewCellInterior *vc2) const; 649 650 646 /** Exports a snapshot of the merged view cells to disc. 651 647 */ … … 653 649 const ObjectContainer &objects, 654 650 const int numNewViewCells); 655 656 651 /** Merge queue must be reset after some time because expected value 657 652 may not be valid. 658 653 */ 659 654 void ResetMergeQueue(); 660 661 655 /** Updates the current cut of view cells. 662 656 @returns number of newly merged view cells 663 657 */ 664 658 int UpdateActiveViewCells(ViewCellContainer &viewCells); 665 666 659 /** Helper function pullling pvs as high up in the tree as possible. 667 660 */ 668 661 void PullUpVisibility(ViewCellInterior *interior); 669 670 662 /** Compress pvs of view cell and children. 671 663 */ 672 664 void CompressViewCellsPvs(ViewCell *root); 673 674 665 /** Returns memory usage of view cells. 675 666 */ 676 667 float GetMemUsage() const; 677 678 668 /** Exports single view cell. 679 669 NOTE: should be in exporter!! 680 670 */ 681 671 void ExportViewCell(ViewCell *viewCell, OUT_STREAM &stream, const bool exportPvs); 682 683 672 /** Exports pvs of a view cell. 684 673 */ 685 674 void ExportPvs(ViewCell *viewCell, OUT_STREAM &stream); 686 687 675 /** Counts the logical number of entries in the pvs this view cell. 688 676 The pvs is assumed to be stored using lossless compression. 689 677 */ 690 678 int GetEntriesInPvsForCompressedStorage(ViewCell *vc) const; 691 692 679 /** Computes pvs size of this view cell. 693 680 The pvs is assumed to be stored using lossless compression. 694 681 */ 695 682 float GetPvsCostForCompressedStorage(ViewCell *vc) const; 696 697 683 /** Computes pvs size of this view cell. 698 684 The pvs is assumed to be stored in the leaves. 699 685 */ 700 686 float GetPvsCostForLeafStorage(ViewCell *vc) const; 701 702 687 /** Counts the logical number of entries in the pvs this view cell. 703 688 The pvs is assumed to be stored using the leaves. 704 689 */ 705 690 int GetEntriesInPvsForLeafStorage(ViewCell *vc) const; 706 707 691 /** Update stats for the log. 708 692 */ 709 693 void UpdateStats(std::ofstream &stats, 710 694 const ViewCellsTreeStats &vcStats); 711 712 695 713 696 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r2538 r2539 1021 1021 1022 1022 { 1023 // give just an empty container as parameter: 1024 // this loading function is used in the engine, thus it 1025 // does not need to load the entities the preprocessor works on 1023 1026 ObjectContainer preprocessorObjects; 1024 1027 … … 1058 1061 } 1059 1062 1060 if (0) 1063 if (0) //hack: should work with reset function, but something is wrong .. 1061 1064 { 1062 1065 vm->ResetViewCells(); … … 1064 1067 else 1065 1068 { 1066 //hack: should work with reset function1067 1069 ViewCellContainer leaves; 1068 1070 … … 1111 1113 OUT_STREAM stream(filename.c_str()); 1112 1114 1113 // for outputwe need unique ids for each view cell1115 // we need unique ids for each view cell 1114 1116 CreateUniqueViewCellIds(); 1115 1117 … … 1287 1289 1288 1290 ViewCellContainer viewCells; 1291 1289 1292 #ifdef USE_BIT_PVS 1290 1293 cout << "objects size: " << (int)ObjectPvsIterator::sObjects.size() << endl; 1291 1294 cout << "pvs size: " << ObjectPvs::sPvsSize << endl; 1292 1295 #endif 1296 1293 1297 // $$ JB hack - the collect best viewcells does not work? 1294 1298 #if 0 … … 1297 1301 viewCells = mViewCells; 1298 1302 #endif 1303 1299 1304 ViewCellContainer::iterator it = viewCells.begin(), it_end = viewCells.end(); 1305 1300 1306 for (; it != it_end; ++it) 1301 1307 { 1302 if (1) 1303 (*it)->UpdatePvsCost(); 1304 else 1305 (*it)->SetTrianglesInPvs((float)(*it)->GetFilteredPvsSize()); 1308 (*it)->UpdatePvsCost(); 1306 1309 } 1307 1310 … … 1364 1367 ++ smallerSum; 1365 1368 } 1366 1367 // if (0 && (i < (int)viewCells.size()))1368 // Debug << "new pvs cost increase: " << mViewCellsTree->GetTrianglesInPvs(viewCells[i])1369 // << " " << currentPvs << endl;1370 1369 1371 1370 const float volRatioDif = volDif / totalVol; … … 1843 1842 const float filterWidth) 1844 1843 { 1845 1846 1847 1848 prvs.mViewCell = currentViewCell;1849 return;1850 1851 1852 1853 1854 1855 { 1856 1857 1858 1859 1860 1861 1844 ViewCell *currentViewCell = GetViewCell(viewPoint); 1845 1846 if (mMaxFilterSize < 1) { 1847 prvs.mViewCell = currentViewCell; 1848 return; 1849 } 1850 1851 const AxisAlignedBox3 box = GetFilterBBox(viewPoint, filterWidth); 1852 1853 if (currentViewCell) 1854 { 1855 ViewCellContainer viewCells; 1856 ComputeBoxIntersections(box, viewCells); 1857 1858 ViewCell *root = ConstructLocalMergeTree2(currentViewCell, viewCells); 1859 prvs.mViewCell = root; 1860 1862 1861 } 1863 1864 { 1865 1866 1862 else 1863 { 1864 prvs.mViewCell = NULL; 1865 //prvs.mPvs = root->GetPvs(); 1867 1866 } 1868 1867 } … … 4077 4076 4078 4077 ////////// 4079 //-- some view cells for output4078 //-- export visualizations of some view cells 4080 4079 4081 4080 ViewCell::NewMail(); … … 4116 4115 for (vit = leaves.begin(); vit != vit_end; ++ vit) 4117 4116 { 4118 // prepare some rays for output4117 // prepare some rays for visualization 4119 4118 VssRayContainer::const_iterator rit, rit_end = (*vit)->GetOrCreateRays()->end(); 4120 4119 for (rit = (*vit)->GetOrCreateRays()->begin(); rit != rit_end; ++ rit) … … 4126 4125 const int raysOut = min((int)collectRays.size(), maxRays); 4127 4126 4128 // prepare some rays for output4127 // prepare some rays for visualization 4129 4128 VssRayContainer::const_iterator rit, rit_end = collectRays.end(); 4130 4129 for (rit = collectRays.begin(); rit != rit_end; ++ rit) … … 4381 4380 OUT_STREAM stream(filename.c_str()); 4382 4381 4383 // for outputwe need unique ids for each view cell4382 // we need unique ids for each view cell 4384 4383 CreateUniqueViewCellIds(); 4385 4384 … … 4611 4610 ViewCell::NewMail(); 4612 4611 4613 //-- some rays for output4612 //-- some rays for visualization 4614 4613 const int raysOut = min((int)sampleRays.size(), mVisualizationSamples); 4615 4614 Debug << "visualization using " << raysOut << " samples" << endl; 4616 4615 4617 //-- some random view cells and rays for output4616 //-- some random view cells and rays for visualization 4618 4617 vector<KdLeaf *> kdLeaves; 4619 4618 … … 5400 5399 5401 5400 ////////// 5402 //-- some view cells for output5401 //-- export some view cells for visualization 5403 5402 5404 5403 ViewCell::NewMail(); … … 5453 5452 const int raysOut = min((int)collectRays.size(), maxRays); 5454 5453 5455 // prepare some rays for output5454 // prepare some rays for visualization 5456 5455 VssRayContainer::const_iterator rit, rit_end = collectRays.end(); 5457 5456 for (rit = collectRays.begin(); rit != rit_end; ++ rit) … … 5483 5482 { 5484 5483 Intersectable::NewMail(); 5485 5486 5484 ObjectPvsIterator pit = pvs.GetIterator(); 5487 5485 … … 6585 6583 OUT_STREAM stream(filename.c_str()); 6586 6584 6587 // for outputwe need unique ids for each view cell6585 // we need unique ids for each view cell 6588 6586 CreateUniqueViewCellIds(); 6589 6587 … … 6600 6598 { 6601 6599 stream << "<BoundingBoxes>" << endl; 6600 6601 int id = 0; 6602 6602 6603 vector<KdIntersectable *>::const_iterator kit, kit_end = mPreprocessor->mKdTree->mKdIntersectables.end(); 6603 6604 int id = 0; 6605 6604 6606 6605 for (kit = mPreprocessor->mKdTree->mKdIntersectables.begin(); kit != kit_end; ++ kit, ++ id) 6607 6606 { … … 6657 6656 } 6658 6657 6658 6659 bool VspOspViewCellsManager::ExportBinaryViewCells(const string filename, 6660 const bool exportPvs, 6661 const ObjectContainer &objects) 6662 { 6663 if (!ViewCellsConstructed() || !ViewCellsTreeConstructed()) 6664 return false; 6665 6666 const long starttime = GetTime(); 6667 cout << "exporting view cells to binary format ... "; 6668 6669 OUT_STREAM stream(filename.c_str()); 6670 6671 // we need unique ids for each view cell 6672 CreateUniqueViewCellIds(); 6673 6674 int numBoundingBoxes = mPreprocessor->mKdTree->mKdIntersectables.size(); 6675 stream.write(reinterpret_cast<char *>(&numBoundingBoxes), sizeof(int)); 6676 6677 6678 /////////////// 6679 //-- export bounding boxes 6680 //-- we need the boxes to identify objects in the target engine 6681 6682 vector<KdIntersectable *>::const_iterator kit, kit_end = mPreprocessor->mKdTree->mKdIntersectables.end(); 6683 6684 int id = 0; 6685 6686 for (kit = mPreprocessor->mKdTree->mKdIntersectables.begin(); kit != kit_end; ++ kit, ++ id) 6687 { 6688 Intersectable *obj = (*kit); 6689 const AxisAlignedBox3 &box = obj->GetBox(); 6690 6691 // set kd node id 6692 obj->SetId(id); 6693 Vector3 bmin = box.Min(); 6694 Vector3 bmax = box.Max(); 6695 6696 stream.write(reinterpret_cast<char *>(&bmin), sizeof(Vector3)); 6697 stream.write(reinterpret_cast<char *>(&bmax), sizeof(Vector3)); 6698 stream.write(reinterpret_cast<char *>(&id), sizeof(int)); 6699 } 6700 6701 6702 /////////////// 6703 //-- export the view cells and the pvs 6704 6705 6706 int numViewCells = mCurrentViewCellsStats.viewCells; 6707 stream.write(reinterpret_cast<char *>(&numViewCells), sizeof(int)); 6708 6709 Vector3 vmin = mViewSpaceBox.Min(); 6710 Vector3 vmax = mViewSpaceBox.Max(); 6711 6712 stream.write(reinterpret_cast<char *>(&vmin), sizeof(Vector3)); 6713 stream.write(reinterpret_cast<char *>(&vmax), sizeof(Vector3)); 6714 6715 6716 ////////////////////// 6717 //-- export the view space hierarchy 6718 6719 mHierarchyManager->GetVspTree()->ExportBinary(stream); 6720 6721 stream.close(); 6722 6723 cout << "finished in " << TimeDiff(starttime, GetTime()) * 1e-3 << " secs" << endl; 6724 return true; 6725 } 6659 6726 6660 6727 … … 6966 7033 ////////// 6967 7034 // compare results 6968 6969 7035 cout << "ray " << i << ": " << (int)tmpRays[i]->mViewCells.size() << " " << (int)packet.mViewCells[i].size() << endl; 6970 7036 } 6971 6972 6973 7037 6974 7038 CLEAR_CONTAINER(tmpRays); 6975 7039 } 6976 7040 } 6977 cout << "=================\nhere6"<<endl; 7041 6978 7042 CLEAR_CONTAINER(tmpRays); 6979 7043 … … 6990 7054 6991 7055 6992 } 7056 7057 ViewCellsManager *LoadViewCellsBinary(const string &filename, 7058 ObjectContainer &pvsObjects, 7059 bool finalizeViewCells, 7060 BoundingBoxConverter *bconverter) 7061 { 7062 ViewCellsParser parser; 7063 ViewCellsManager *vm = NULL; 7064 7065 const long startTime = GetTime(); 7066 const bool success = false; 7067 7068 if (!success) 7069 { 7070 Debug << "Error: loading view cells failed!" << endl; 7071 DEL_PTR(vm); 7072 7073 return NULL; 7074 } 7075 7076 ViewCellContainer leaves; 7077 7078 vm->mViewCells.clear(); 7079 vm->mViewCellsTree->CollectLeaves(vm->mViewCellsTree->GetRoot(), leaves); 7080 7081 ViewCellContainer::const_iterator it, it_end = leaves.end(); 7082 7083 for (it = leaves.begin(); it != it_end; ++ it) 7084 { 7085 vm->mViewCells.push_back(*it); 7086 } 7087 7088 vm->mViewCellsFinished = true; 7089 vm->mMaxPvsSize = (int)pvsObjects.size(); 7090 7091 if (finalizeViewCells) 7092 { 7093 // create the meshes and compute view cell volumes 7094 const bool createMeshes = true; 7095 vm->FinalizeViewCells(createMeshes); 7096 } 7097 7098 cout << (int)vm->mViewCells.size() << " view cells loaded in " 7099 << TimeDiff(startTime, GetTime()) * 1e-3f << " secs" << endl; 7100 7101 Debug << (int)vm->mViewCells.size() << " view cells loaded in " 7102 << TimeDiff(startTime, GetTime()) * 1e-3f << " secs" << endl; 7103 7104 return vm; 7105 } 7106 7107 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r2538 r2539 65 65 /// root of view cells tree 66 66 ViewCell *mViewCell; 67 68 67 // input parameter is the render budget for the PrVs 69 68 float mRenderBudget; 70 71 // some characteristic values could be stored as well72 69 }; 73 70 … … 142 139 */ 143 140 ViewCellsManager(ViewCellsTree *viewCellsTree); 144 141 /** Destructor. 142 */ 145 143 virtual ~ViewCellsManager(); 146 147 144 /** Constructs view cells container taking a preprocessor 148 145 @returns the output rays (if not null) … … 178 175 const bool storeViewCells, 179 176 const bool useHitObject = false); 180 181 177 /** Compute sample contribution only for current view cell. 182 178 */ … … 185 181 ViewCell *currentViewCell, 186 182 const bool useHitObject = false); 187 188 183 /** Prints out statistics of the view cells. 189 184 */ 190 185 virtual void PrintStatistics(std::ostream &s) const; 191 192 186 /** Post processes view cells givemŽa number of rays. 193 187 */ 194 188 virtual int PostProcess(const ObjectContainer &objects, 195 189 const VssRayContainer &rays) = 0; 196 197 190 /** Show visualization of the view cells. 198 191 */ 199 192 virtual void Visualize(const ObjectContainer &objects, 200 193 const VssRayContainer &sampleRays) = 0; 201 202 194 /** collect objects intersecting a given spatial box. 203 195 */ 204 196 virtual void CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects); 205 206 197 /** type of the view cell container. 207 198 */ 208 199 virtual int GetType() const = 0; 209 210 200 /** Load the input viewcells. The input viewcells should be given as a collection 211 201 of meshes. Each mesh is assume to form a bounded polyhedron … … 217 207 */ 218 208 virtual bool LoadViewCellsGeometry(const string filename, const bool extrudeBaseTriangle); 219 220 209 /** Merges two view cells. 221 210 @note the piercing rays of the front and back will be ordered … … 223 212 */ 224 213 ViewCellInterior *MergeViewCells(ViewCell *front, ViewCell *back) const; 225 226 214 /** Merges a container of view cells. 227 215 @returns new view cell based on the merging. 228 216 */ 229 217 ViewCellInterior *MergeViewCells(ViewCellContainer &children) const; 230 231 218 /** Generates view cell of the type specified by this manager 232 219 */ 233 220 virtual ViewCell *GenerateViewCell(Mesh *mesh = NULL) const = 0; 234 235 221 /** Constructs view cell from base triangle. 236 222 The view cell is extruded along the normal vector. … … 239 225 */ 240 226 ViewCell *ExtrudeViewCell(const Triangle3 &baseTri, const float height) const; 241 227 /** Returns the intersectable that was hit by the ray. 228 */ 242 229 virtual Intersectable *GetIntersectable(const VssRay &ray, const bool isTermination) const; 243 244 230 /** Sets maximal number of samples used for the 245 231 construction of the view cells. 246 232 */ 247 233 void SetVisualizationSamples(const int visSamples); 248 249 234 /** Sets maximal number of samples used for the construction of the view cells. 250 235 */ 251 236 void SetConstructionSamples(const int constructionSamples); 252 253 237 /** Sets maximal number of samples used for the visualization of the view cells. 254 238 */ 255 239 void SetInitialSamples(const int initialSamples); 256 257 240 /** Sets maximal number of samples used for the post processing of the view cells. 258 241 */ 259 242 void SetPostProcessSamples(const int postProcessingSamples); 260 261 243 /** See set. 262 244 */ 263 245 int GetVisualizationSamples() const; 264 265 246 /** See set. 266 247 */ 267 248 int GetConstructionSamples() const; 268 269 249 /** See set. 270 250 */ 271 251 int GetPostProcessSamples() const; 272 273 252 /** Returns true if view cells are already constructed. 274 253 */ 275 254 virtual bool ViewCellsConstructed() const = 0; 276 277 255 /** cast line segment to get a list of unique viewcells which are intersected 278 256 by this line segment 279 257 */ 280 258 virtual int CastLineSegment(const Vector3 &origin, 281 const Vector3 &termination, 282 ViewCellContainer &viewcells 283 ) = 0; 284 259 const Vector3 &termination, 260 ViewCellContainer &viewcells) = 0; 285 261 /** Tests if this line segment intersects a particular view cell. 286 262 */ … … 288 264 const Vector3 &termination, 289 265 ViewCell *viewCell) = 0; 290 291 266 /** Returns a stats about the global pvs. 292 267 */ 293 268 virtual void GetPvsStatistics(PvsStatistics &stat); 294 269 /** Returns the probably visible set of the view space filtered pvs. 270 */ 295 271 virtual void GetPrVS(const Vector3 &viewPoint, PrVs &prvs, const float filterWidth); 296 297 272 /** Get a viewcell containing the specified view point. 298 273 @param active if the active or elementary view cell should be returned. 299 274 */ 300 275 virtual ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const = 0; 301 276 /** Returns the view cell with the given index (different from the id). 277 */ 302 278 ViewCell *GetViewCell(const int idx) const {return mViewCells[idx];} 303 279 /** Prints the statistics over the view cell pvss. 280 */ 304 281 virtual void PrintPvsStatistics(std::ostream &s); 305 306 282 /** Updates pvs of the view cell hierarchy if necessary. 307 283 */ 308 284 void UpdatePvs(); 309 310 285 /** Returns probability that view point lies in one view cell. 311 286 */ 312 287 virtual float GetProbability(ViewCell *viewCell) = 0; 313 314 288 /** Returns render cost of a single view cell given the render cost of an object. 315 289 */ 316 290 float GetRendercost(ViewCell *viewCell) const; 317 318 291 /** Returns reference to container of loaded / generated view cells. 319 292 */ 320 293 ViewCellContainer &GetViewCells(); 321 322 294 /** Helper function used to split ray sets uniformly 323 295 into one that is currently used and the other that … … 332 304 VssRayContainer &usedRays, 333 305 VssRayContainer *savedRays = NULL) const; 334 335 306 /** Returns accumulated area of all view cells. 336 307 */ 337 308 float GetAccVcArea(); 338 339 309 /** Returns area of one view cell. 340 310 */ 341 311 virtual float GetArea(ViewCell *viewCell) const; 342 343 312 /** Returns volume of view cell. 344 313 */ 345 314 virtual float GetVolume(ViewCell *viewCell) const; 346 347 315 /** Sets the current renderer mainly for view cells statistics. 348 316 */ 349 317 void SetRenderer(Renderer *renderer); 350 351 318 /** Computes a (random) view point in the valid view space. 352 319 @returns true if valid view point was found 353 320 */ 354 321 virtual bool GetViewPoint(Vector3 &viewPoint) const; 355 322 /** Returns the current view point given a vector for activating the halton sequence. 323 */ 356 324 virtual bool GetViewPoint(Vector3 &viewPoint, const Vector3 ¶ms) const; 357 358 325 /** Returns true if this view point is in the valid view space. 359 326 */ 360 327 virtual bool ViewPointValid(const Vector3 &viewPoint) const; 361 362 328 /** Sets a view space boundary. 363 329 */ 364 330 void SetViewSpaceBox(const AxisAlignedBox3 &box); 365 331 /** Returns the boundaries of the view space. 332 */ 366 333 AxisAlignedBox3 GetViewSpaceBox() const; 367 368 334 /** Creates mesh for this view cell. 369 335 */ 370 336 virtual void CreateMesh(ViewCell *vc) = NULL; 371 372 337 /** Writes view cells to disc. 373 338 */ … … 375 340 const bool exportPvs, 376 341 const ObjectContainer &objects); 377 378 342 /** Casts beam to collect view cells. 379 343 */ 380 344 virtual int CastBeam(Beam &beam); 381 382 345 /** Checks if view cell is considered as valid. 383 346 */ … … 385 348 int minPvsSize, 386 349 int maxPvsSize) const; 387 388 389 // resort pvss after a pass of the algorithm 350 /** Resort pvss after a pass of the algorithm. 351 */ 390 352 void SortViewCellPvs(); 391 392 // map the ray intersection objects from triangles to high level objects...353 /** Map the ray intersection objects from triangles to high level objects. 354 */ 393 355 void DeterminePvsObjects(VssRayContainer &rays, 394 356 const bool useHitObjects = false); 395 396 357 /** Sets validity of view cell 397 358 */ … … 399 360 int minPvsSize, 400 361 int maxPvsSize) const; 401 402 362 /** sets validy of all viewcells 403 363 */ 404 virtual void SetValidity(int minPvsSize, 405 int maxPvsSize) const; 406 407 364 virtual void SetValidity(int minPvsSize, int maxPvsSize) const; 408 365 /** Set valid viewcells in the range of pvs. sorts the viewcells 409 366 according to the pvs and then pickups those in the ranges 410 367 */ 411 368 void SetValidityPercentage(const float minValid, const float maxValid); 412 413 369 /** Returns number of valid view cells. 414 370 */ 415 371 int CountValidViewcells() const; 416 417 372 /** Returns maximal allowed pvs size. 418 373 */ 419 374 int GetMaxPvsSize() const; 420 421 375 /** Returns maximal allowed pvs size. 422 376 */ 423 377 int GetMinPvsSize() const; 424 425 378 /** Returns maximal ratio. i.e., currentPVs / maxPvs, 426 379 where pvs is still considered valid. 427 380 */ 428 381 float GetMaxPvsRatio() const; 429 430 382 /** Exports view cell geometry. 431 383 */ … … 435 387 const AxisAlignedPlane *clipPlane = NULL 436 388 ) const = 0; 437 438 389 /** Brings the view cells into their final state, computes meshes and volume. 439 390 */ 440 391 virtual void FinalizeViewCells(const bool createMesh); 441 442 392 /** Evaluates statistics values on view cells. 443 393 */ … … 448 398 float &totalPvs, 449 399 float &avgRenderCost); 450 451 400 /** Returns hierarchy of the view cells. 452 401 */ 453 402 ViewCellsTree *GetViewCellsTree(); 454 455 403 /** Collect candidates for the view cell merge. 456 404 */ 457 405 virtual void CollectMergeCandidates(const VssRayContainer &rays, 458 406 vector<MergeCandidate> &candidates); 459 460 407 /** Collects n view cells and stores it as the active view cells. 461 408 */ 462 409 void CollectViewCells(const int n); 463 464 410 /** Sets current view cells set to active, 465 411 i.e., the sampling is done in this view cell set. 466 412 */ 467 413 void SetViewCellsActive(); 468 469 414 /** Evaluates render cost statistics of current view cell hierarchy. 470 415 */ 471 416 virtual void EvalViewCellPartition(); 472 473 417 /** Sets maximal size of a view cell filter. 474 418 */ 475 419 void SetMaxFilterSize(const int size); 476 477 420 /** Returns maximal filter size. 478 421 */ 479 422 int GetMaxFilterSize() const; 480 481 423 /** Deletes interior nodes from the tree which have negative 482 424 merge cost set (local merge). 483 425 */ 484 426 void DeleteLocalMergeTree(ViewCell *vc) const; 485 486 427 /** Evaluautes histogram for a given number of view cells. 487 428 */ 488 429 void EvalViewCellHistogram(const string filename, const int nViewCells); 489 490 430 /** Evaluautes histogram for a given number of view cells. 491 431 */ 492 432 void EvalViewCellHistogramForPvsSize(const string filename, 493 433 const int nViewCells); 494 434 /** Evaluautes histogram for a given vector of view cells. 435 */ 495 436 void EvalViewCellHistogramForPvsSize(const string filename, 496 437 ViewCellContainer &viewCells); 497 498 438 float ComputeRenderCost(const int tri, const int obj); //const 499 500 439 /** Sets pvs size of view cell as a scalar. Used when storing pvs only in the leaves 501 440 of the hierarchy. … … 504 443 const float pvsCost, 505 444 const int entriesInPvs) const; 506 507 445 /** Returns bounding box of a view cell. 508 446 */ 509 447 AxisAlignedBox3 GetViewCellBox(ViewCell *vc); 510 511 448 /** Exports bounding boxes of objects to file. 512 449 */ 513 450 bool ExportBoundingBoxes(const string filename, 514 451 const ObjectContainer &objects) const; 515 516 452 /** Load the bounding boxes into the container. 517 453 */ 518 454 bool LoadBoundingBoxes(const string filename, 519 455 IndexedBoundingBoxContainer &boxes) const; 520 521 456 /** Returns true if pvs should be exported together with the view cells. 522 457 */ 523 458 bool GetExportPvs() const; 524 525 459 /** Efficiently merges the view cells in the container. 526 460 */ 527 461 void MergeViewCellsRecursivly(ObjectPvs &pvs, 528 462 const ViewCellContainer &viewCells) const; 529 530 /** Compress the view cells. 463 /** Compresses the view cells. 531 464 */ 532 465 virtual void CompressViewCells(); 533 466 /** Returns view cell with the given id. 467 */ 534 468 ViewCell *GetViewCellById(const int id); 535 536 469 /** Returns number of view cells. 537 470 */ … … 620 553 621 554 float GetAbsFilterWidth(); 622 623 555 /** Returns the bounding box of filter width. 624 556 */ … … 688 620 const int leftIdx, 689 621 const int rightIdx) const; 690 691 622 /** Intersects box with the tree and returns the number of intersected boxes. 692 @returns number of view cells found623 @returns number of view cells found 693 624 */ 694 625 virtual int ComputeBoxIntersections(const AxisAlignedBox3 &box, 695 626 ViewCellContainer &viewCells) const; 696 697 627 /** Tests the visibility filter functionality. 698 628 */ 699 629 virtual void TestFilter(const ObjectContainer &objects) {}; 700 701 630 /** If the view cells tree was already constructed or not. 702 631 */ 703 632 bool ViewCellsTreeConstructed() const; 704 705 633 /** Requests preprocessor to cast samplesPerPass samples of a specific type. 706 634 */ … … 711 639 int CastEvaluationSamples(const int samplesPerPass, 712 640 VssRayContainer &passSamples);// const; 713 714 641 /** Parse the options from the environment file. 715 642 */ 716 643 void ParseEnvironment(); 717 718 644 /** Creates unique view cell ids. 719 645 */ 720 646 void CreateUniqueViewCellIds(); 721 722 647 /** Finalizes, i.e., creates mesh, volume, area etc. for the view cell. 723 648 */ 724 649 virtual void Finalize(ViewCell *viewCell, const bool createMesh); 725 726 650 /** Recollects view cells and resets statistics. 727 651 */ 728 652 void ResetViewCells(); 729 730 653 /** Sets this view cell to active. 731 654 */ 732 655 void SetViewCellActive(ViewCell *vc) const; 733 734 656 /** Collects the view cells in the view cell container. 735 657 */ 736 658 virtual void CollectViewCells() = 0; 737 738 /** Evaluates view cells statistics and stores it in 739 mViewCellsStatistics. 659 /** Evaluates view cells statistics and stores it in mViewCellsStatistics. 740 660 */ 741 661 void EvaluateViewCellsStats(); … … 751 671 const bool colorCode, 752 672 const AxisAlignedPlane *clipPlane) const; 753 754 673 /** Sets exporter color. 755 674 */ … … 757 676 ViewCell *vc, 758 677 const int colorCode) const; 759 760 678 /** Creates meshes from the view cells. 761 679 */ 762 680 void CreateViewCellMeshes(); 763 764 681 /** Creates clip plane for visualization. 765 682 */ … … 776 693 */ 777 694 virtual float GetViewSpaceVolume(); 778 779 695 /** Prepares the view cells for sampling after loading them from disc. 780 696 */ 781 697 virtual void PrepareLoadedViewCells() {}; 782 783 698 /** Constructs local view cell merge hierarchy. 784 699 */ 785 700 ViewCell *ConstructLocalMergeTree(ViewCell *currentViewCell, 786 const ViewCellContainer &viewCells); 787 701 const ViewCellContainer &viewCells); 788 702 /** Constructs local view cell merge hierarchy based solely on similarity with the 789 703 current viewcell … … 791 705 ViewCell *ConstructLocalMergeTree2(ViewCell *currentViewCell, 792 706 const ViewCellContainer &viewCells); 793 794 707 /** Updates pvs of all view cells for statistical evaluation after some more sampling 795 708 */ … … 797 710 798 711 virtual void ExportStats(const string &mergeStats); 712 713 friend ViewCellsManager *LoadViewCellsBinary(const string &filename, 714 ObjectContainer &pvsObjects, 715 bool finalizeViewCells, 716 BoundingBoxConverter *bconverter); 799 717 800 718 … … 804 722 ofstream mStats; 805 723 Preprocessor *mPreprocessor; 806 807 724 /// if bounding boxes should be exported together with the view cells 808 725 bool mExportBboxesForPvs; 809 810 726 /// the clip plane for visualization 811 727 AxisAlignedPlane mClipPlaneForViz; 812 813 728 /// if the visualization is using the clip plane 814 729 bool mUseClipPlaneForViz; 815 816 730 /// Renders the view cells. 817 731 Renderer *mRenderer; 818 819 732 /// Loaded view cells 820 733 ViewCellContainer mViewCells; 821 822 734 /// the view cell hierarchy (i.e., the logical description of view cells) 823 735 ViewCellsTree *mViewCellsTree; … … 998 910 */ 999 911 ViewCell *ConstructDummyMergeTree(BspNode *root); 1000 1001 912 /** Exports visualization of the BSP splits. 1002 913 */ 1003 914 void ExportSplits(const ObjectContainer &objects); 1004 1005 915 /** test if subdivision is valid in terms of volume / area. 1006 916 */ … … 1246 1156 ViewCell *GenerateViewCell(Mesh *mesh = NULL) const; 1247 1157 1248 virtual Intersectable *GetIntersectable( 1249 const VssRay &ray,const bool isTermination) const;1158 virtual Intersectable *GetIntersectable(const VssRay &ray, 1159 const bool isTermination) const; 1250 1160 1251 1161 bool ViewCellsConstructed() const; 1252 1162 1253 1254 1163 int CastLineSegment(const Vector3 &origin, 1255 1164 const Vector3 &termination, … … 1288 1197 VssRayContainer *visRays = NULL); 1289 1198 1290 float UpdateObjectCosts(); 1291 1199 ; 1200 /** See parent class. 1201 */ 1292 1202 virtual void FinalizeViewCells(const bool createMesh); 1203 1204 bool ExportBinaryViewCells(const string filename, 1205 const bool exportPvs, 1206 const ObjectContainer &objects); 1293 1207 1294 1208 #if TEST_PACKETS … … 1300 1214 #endif 1301 1215 1216 1302 1217 protected: 1303 1218 1219 /** View cells manager taking a view cells tree and a hierarchy as input. 1220 */ 1304 1221 VspOspViewCellsManager(ViewCellsTree *vcTree, HierarchyManager *hm); 1305 1222 1306 1223 virtual void EvalViewCellPartition(); 1307 1308 1224 /** Exports view cell geometry. 1309 1225 */ … … 1334 1250 */ 1335 1251 virtual void CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects); 1336 1252 /** Update the cost of pvss for hierarchy objects. 1253 */ 1254 float UpdateObjectCosts(); 1255 1256 1257 //////////////// 1258 1259 /** Fast view cell loader in binary mode. 1260 */ 1261 friend ViewCellsManager *LoadViewCellsBinary(const string &filename, 1262 ObjectContainer &pvsObjects, 1263 bool finalizeViewCells, 1264 BoundingBoxConverter *bconverter); 1265 1266 /** Print statistics about the view cells compression. 1267 */ 1337 1268 static void PrintCompressionStats(HierarchyManager *hm, const int pvsEntries); 1338 1269 … … 1340 1271 //////////////////// 1341 1272 1273 /// if we should compress the objects after view cell evaluation: this makes 1274 /// only sense for testing purpose 1342 1275 bool mCompressObjects; 1343 1276 /// pointer to the hierarchy manager responsible for view space / object space subdivision. 1344 1277 HierarchyManager *mHierarchyManager; 1345 1278 }; -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
r2332 r2539 122 122 //Debug<<"\nhsize: " << mHashPvs.size() << endl; 123 123 } 124 /* 125 void ViewCellsParseHandlers::CreateHashVector2() 126 { 127 ObjectContainer::const_iterator oit, oit_end = mPvsObjects.end(); 128 129 for (oit = mPvsObjects.begin(); oit != oit_end; ++ oit) 130 { 131 mHashPvs[(*oit)->GetId()] = (*oit); 132 } 133 Debug<<"\nhsize: " << mHashPvs.size() << endl; 134 } 135 */ 124 125 136 126 // --------------------------------------------------------------------------- 137 127 // StdInParseHandlers: Implementation of the SAX DocumentHandler interface … … 324 314 { 325 315 sort(mPvsObjects.begin(), mPvsObjects.end(), ilt); 326 327 /*ObjectContainer::const_iterator oit, oit_end = mPvsObjects.end();328 329 int id = 0;330 for (oit = mPvsObjects.begin(); oit != oit_end; ++ oit, ++ id)331 {332 if ((*oit)->GetId() != id)333 Debug << "error" << endl;334 }*/335 316 } 336 317 … … 540 521 void ViewCellsParseHandlers::StartViewCellPvs(ObjectPvs &pvs, const char *ptr) 541 522 { 542 // handle ob ect indices523 // handle object indices 543 524 vector<int> objIndices; 544 525 char *endptr; 545 526 546 527 while (1) 547 { // read object ids 528 { 529 // read object ids 548 530 const int index = strtol(ptr, &endptr, 10); 531 549 532 if (ptr == endptr) 550 533 break; 534 551 535 objIndices.push_back(index); 552 536 ptr = endptr; 553 537 } 554 538 539 mPvsTimer.Entry(); 540 555 541 Intersectable::NewMail(); 556 557 mPvsTimer.Entry();558 542 559 543 // TODO: … … 561 545 // 2) get view cell with specified id 562 546 MeshInstance dummyInst(NULL); 547 pair<ObjectContainer::const_iterator, ObjectContainer::const_iterator> result; 563 548 564 549 vector<int>::const_iterator it, it_end = objIndices.end(); 565 550 566 pair<ObjectContainer::const_iterator, ObjectContainer::const_iterator> result;567 568 551 for (it = objIndices.begin(); it != it_end; ++ it) 569 552 { … … 578 561 } 579 562 #else 580 #if 0563 #if 0 581 564 dummyInst.SetId(objId); 582 565 … … 584 567 lower_bound(mPvsObjects.begin(), 585 568 mPvsObjects.end(), 586 (Intersectable *)&dummyInst, ilt); 569 (Intersectable *)&dummyInst, 570 ilt); 587 571 588 572 if ((oit != mPvsObjects.end()) && ((*oit)->GetId() == objId)) … … 590 574 pvs.AddSample(*oit, 1.0f); 591 575 } 592 #else576 #else 593 577 pvs.AddSample(mPvsObjects[objId], 1.0f); 594 #endif578 #endif 595 579 #endif 596 580 } -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
r2529 r2539 32 32 33 33 34 #define TYPE_INTERIOR -2 35 #define TYPE_LEAF -3 36 37 34 38 ///////////// 35 39 //-- static members … … 114 118 } 115 119 120 121 122 VspTree::VspTraversalData::VspTraversalData(): 123 mNode(NULL), 124 mDepth(0), 125 mRays(NULL), 126 mPvs(0), 127 mProbability(0.0), 128 mMaxCostMisses(0), 129 mPriority(0), 130 mCorrectedPvs(0) 131 {} 132 133 134 VspTree::VspTraversalData::VspTraversalData(VspLeaf *node, 135 const int depth, 136 RayInfoContainer *rays, 137 const float pvs, 138 const float p, 139 const AxisAlignedBox3 &box): 140 mNode(node), 141 mDepth(depth), 142 mRays(rays), 143 mProbability(p), 144 mBoundingBox(box), 145 mMaxCostMisses(0), 146 mPriority(0), 147 mCorrectedPvs(0), 148 mPvs(pvs), 149 mRenderCost(0), 150 mCorrectedRenderCost(0) 151 {} 152 153 154 float VspTree::VspTraversalData::GetAvgRayContribution() const 155 { 156 return (float)mPvs / ((float)mRays->size() + Limits::Small); 157 } 158 159 160 float VspTree::VspTraversalData::GetAvgRaysPerObject() const 161 { 162 return (float)mRays->size() / ((float)mPvs + Limits::Small); 163 } 164 165 166 float VspTree::VspTraversalData::GetCost() const 167 { 168 return mPriority; 169 } 170 171 172 void VspTree::VspTraversalData::Clear() 173 { 174 DEL_PTR(mRays); 175 176 if (mNode) 177 { // delete old view cell 178 delete mNode->GetViewCell(); 179 delete mNode; 180 mNode = NULL; 181 } 182 } 116 183 117 184 … … 3159 3226 3160 3227 3161 void VspTree:: CollectDirtyCandidate(const VssRay &ray,3162 3163 3164 3165 { 3166 3228 void VspTree::AddCandidateToDirtyList(const VssRay &ray, 3229 const bool isTermination, 3230 vector<SubdivisionCandidate *> &dirtyList, 3231 const bool onlyUnmailed) const 3232 3233 { 3167 3234 #if HACK_PERFORMANCE 3168 3235 … … 3172 3239 3173 3240 BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj); 3174 3175 3241 SubdivisionCandidate *candidate; 3176 3242 … … 3254 3320 VssRay *ray = (*rit).mRay; 3255 3321 3256 CollectDirtyCandidate(*ray, true, dirtyList, onlyUnmailed);3322 AddCandidateToDirtyList(*ray, true, dirtyList, onlyUnmailed); 3257 3323 3258 3324 #if COUNT_ORIGIN_OBJECTS 3259 CollectDirtyCandidate(*ray, false, dirtyList, onlyUnmailed);3325 AddCandidateToDirtyList(*ray, false, dirtyList, onlyUnmailed); 3260 3326 #endif 3261 3327 } … … 3788 3854 3789 3855 3790 3791 3792 } 3856 ////////// 3857 // Binary export 3858 3859 void VspTree::ExportBinInterior(OUT_STREAM &stream, VspInterior *interior) 3860 { 3861 int interiorid = TYPE_INTERIOR; 3862 stream.write(reinterpret_cast<char *>(&interiorid), sizeof(int)); 3863 3864 int axis = interior->GetAxis(); 3865 float pos = interior->GetPosition(); 3866 3867 stream.write(reinterpret_cast<char *>(&axis), sizeof(int)); 3868 stream.write(reinterpret_cast<char *>(&pos), sizeof(float)); 3869 } 3870 3871 3872 void VspTree::ExportBinLeaf(OUT_STREAM &stream, VspLeaf *leaf) 3873 { 3874 ViewCell *viewCell = mViewCellsTree->GetActiveViewCell(leaf->GetViewCell()); 3875 3876 int type = TYPE_LEAF; 3877 3878 int id = -1; 3879 if (viewCell != mOutOfBoundsCell) 3880 id = viewCell->GetId(); 3881 3882 stream.write(reinterpret_cast<char *>(&type), sizeof(int)); 3883 stream.write(reinterpret_cast<char *>(&id), sizeof(int)); 3884 3885 int pvsSize = viewCell->GetPvs().GetSize(); 3886 stream.write(reinterpret_cast<char *>(&pvsSize), sizeof(int)); 3887 3888 ObjectPvsIterator pit = viewCell->GetPvs().GetIterator(); 3889 3890 // write PVS of view cell 3891 while (pit.HasMoreEntries()) 3892 { 3893 Intersectable *intersect = pit.Next(); 3894 id = intersect->GetId(); 3895 stream.write(reinterpret_cast<char *>(&id), sizeof(int)); 3896 } 3897 } 3898 3899 3900 bool VspTree::ExportBinary(OUT_STREAM &stream) 3901 { 3902 // export binary version of mesh 3903 queue<VspNode *> tStack; 3904 tStack.push(mRoot); 3905 3906 while(!tStack.empty()) 3907 { 3908 VspNode *node = tStack.front(); 3909 tStack.pop(); 3910 3911 if (node->IsLeaf()) 3912 { 3913 ExportBinLeaf(stream, static_cast<VspLeaf *>(node)); 3914 } 3915 else 3916 { 3917 VspInterior *interior = static_cast<VspInterior *>(node); 3918 3919 ExportBinInterior(stream, interior); 3920 3921 tStack.push(interior->GetFront()); 3922 tStack.push(interior->GetBack()); 3923 } 3924 } 3925 3926 return true; 3927 } 3928 3929 3930 ////////////////// 3931 // import binary 3932 3933 VspInterior *VspTree::ImportBinInterior(IN_STREAM &stream, VspInterior *parent) 3934 { 3935 AxisAlignedPlane plane; 3936 3937 stream.read(reinterpret_cast<char *>(&plane.mAxis), sizeof(int)); 3938 stream.read(reinterpret_cast<char *>(&plane.mPosition), sizeof(float)); 3939 3940 VspInterior *interior = new VspInterior(plane); 3941 3942 return interior; 3943 } 3944 3945 3946 VspLeaf *VspTree::ImportBinLeaf(IN_STREAM &stream, 3947 VspInterior *parent, 3948 const ObjectContainer &pvsObjects) 3949 { 3950 #if TODO 3951 int leafId = TYPE_LEAF; 3952 int objId = leafId; 3953 int size; 3954 3955 stream.read(reinterpret_cast<char *>(&size), sizeof(int)); 3956 KdLeaf *leaf = new KdLeaf(parent, size); 3957 3958 MeshInstance dummyInst(NULL); 3959 3960 // read object ids 3961 // note: could also do this geometrically 3962 for (int i = 0; i < size; ++ i) 3963 { 3964 stream.read(reinterpret_cast<char *>(&objId), sizeof(int)); 3965 dummyInst.SetId(objId); 3966 3967 ObjectContainer::const_iterator oit = 3968 lower_bound(objects.begin(), objects.end(), (Intersectable *)&dummyInst, ilt); 3969 3970 if ((oit != objects.end()) && ((*oit)->GetId() == objId)) 3971 leaf->mObjects.push_back(*oit); 3972 else 3973 Debug << "error: object with id " << objId << " does not exist" << endl; 3974 } 3975 return leaf; 3976 #endif 3977 return NULL; 3978 } 3979 3980 3981 VspNode *VspTree::ImportNextNode(IN_STREAM &stream, 3982 VspInterior *parent, 3983 const ObjectContainer &objects) 3984 { 3985 int nodeType; 3986 stream.read(reinterpret_cast<char *>(&nodeType), sizeof(int)); 3987 3988 if (nodeType == TYPE_LEAF) 3989 return ImportBinLeaf(stream, static_cast<VspInterior *>(parent), objects); 3990 3991 if (nodeType == TYPE_INTERIOR) 3992 return ImportBinInterior(stream, static_cast<VspInterior *>(parent)); 3993 3994 Debug << "error! loading failed!" << endl; 3995 return NULL; 3996 } 3997 3998 3999 /** Data used for tree traversal 4000 */ 4001 struct MyTraversalData 4002 { 4003 public: 4004 4005 MyTraversalData(VspNode *node, const int depth, const AxisAlignedBox3 &box): 4006 mNode(node), mDepth(depth), mBox(box) 4007 {} 4008 4009 4010 ////////////////////// 4011 4012 /// the current node 4013 VspNode *mNode; 4014 /// current depth 4015 int mDepth; 4016 /// the bounding box 4017 AxisAlignedBox3 mBox; 4018 }; 4019 4020 4021 bool VspTree::ImportBinary(IN_STREAM &stream, ObjectContainer &pvsObjects) 4022 { 4023 // export binary version of mesh 4024 queue<MyTraversalData> tStack; 4025 4026 // sort objects by their id 4027 //sort(objects.begin(), objects.end(), ilt); 4028 4029 // hack: we make a new root 4030 DEL_PTR(mRoot); 4031 4032 mRoot = ImportNextNode(stream, NULL, pvsObjects); 4033 4034 tStack.push(MyTraversalData(mRoot, 0, mBoundingBox)); 4035 mVspStats.Reset(); 4036 mVspStats.nodes = 1; 4037 4038 while(!tStack.empty()) 4039 { 4040 MyTraversalData tData = tStack.front(); 4041 tStack.pop(); 4042 4043 VspNode *node = tData.mNode; 4044 4045 if (!node->IsLeaf()) 4046 { 4047 mVspStats.nodes += 2; 4048 4049 //Debug << "i" ; 4050 VspInterior *interior = static_cast<VspInterior *>(node); 4051 interior->SetBoundingBox(tData.mBox); 4052 4053 VspNode *front = ImportNextNode(stream, interior, pvsObjects); 4054 VspNode *back = ImportNextNode(stream, interior, pvsObjects); 4055 4056 interior->SetupChildLinks(back, front); 4057 4058 ++ mVspStats.splits[interior->GetAxis()]; 4059 4060 // compute new bounding box 4061 AxisAlignedBox3 frontBox, backBox; 4062 4063 tData.mBox.Split(interior->GetAxis(), 4064 interior->GetPosition(), 4065 frontBox, 4066 backBox); 4067 4068 tStack.push(MyTraversalData(front, tData.mDepth + 1, frontBox)); 4069 tStack.push(MyTraversalData(back, tData.mDepth + 1, backBox)); 4070 } 4071 else 4072 { 4073 //EvaluateLeafStats(tData); 4074 //cout << "l"; 4075 } 4076 } 4077 return true; 4078 } 4079 4080 4081 } -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h
r2353 r2539 147 147 148 148 149 /** 150 VspNode abstract class serving for interior and leaf node implementation 149 /** VspNode abstract class serving for interior and leaf node implementation 151 150 */ 152 151 class VspNode 153 152 { 153 friend class VspTree; 154 154 155 public: 155 156 … … 172 173 */ 173 174 virtual bool IsRoot() const; 174 175 175 /** Returns parent node. 176 176 */ 177 177 VspInterior *GetParent(); 178 179 178 /** Sets parent node. 180 179 */ 181 180 void SetParent(VspInterior *parent); 182 183 181 /** Returns true if this node is a sibling of node n. 184 182 */ 185 183 bool IsSibling(VspNode *n) const; 186 187 184 /** returns depth of the node. 188 185 */ 189 186 int GetDepth() const; 190 191 /** returns true if the whole subtree is valid 187 /** Returns true if this node (which represents the whole subtree) is valid 192 188 */ 193 189 bool TreeValid() const; 194 190 /** Sets this node to valid. 191 */ 195 192 void SetTreeValid(const bool v); 196 197 193 /** Cost of mergin this node. 198 194 */ 199 195 float GetMergeCost() {return (float)-mTimeStamp; } 200 196 197 /// timestamp of this node 201 198 int mTimeStamp; 202 199 … … 212 209 int mMailbox; 213 210 214 //int mPvsEntriesIncr; 215 //float mMemoryIncr; 216 //float mRenderCostDecr; 217 211 218 212 protected: 219 213 220 214 /// if this sub tree is a completely valid view space region 221 215 bool mTreeValid; 222 223 216 /// parent of this node 224 217 VspInterior *mParent; … … 230 223 class VspInterior: public VspNode 231 224 { 225 friend class VspTree; 226 232 227 public: 233 228 … … 237 232 238 233 ~VspInterior(); 239 240 234 /** @return false since it is an interior node 241 235 */ 242 bool IsLeaf() const { 243 return false; 244 } 245 236 bool IsLeaf() const { return false; } 246 237 247 238 int Type() const; 248 249 VspNode *GetBack() { 250 return mBack; 251 } 252 253 254 VspNode *GetFront() { 255 return mFront; 256 } 257 239 /** Returns back child. 240 */ 241 VspNode *GetBack() { return mBack; } 242 /** Returns front child. 243 */ 244 VspNode *GetFront() { return mFront; } 258 245 /** Returns split plane. 259 246 */ 260 AxisAlignedPlane GetPlane() const { 261 return mPlane; 262 } 263 264 247 AxisAlignedPlane GetPlane() const { return mPlane; } 265 248 /** Returns position of split plane. 266 249 */ 267 float GetPosition() const { 268 return mPlane.mPosition; 269 } 270 250 float GetPosition() const { return mPlane.mPosition; } 271 251 /** Returns split axis. 272 252 */ 273 int GetAxis() const { 274 return mPlane.mAxis; 275 } 276 253 int GetAxis() const { return mPlane.mAxis; } 277 254 /** Replace front or back child with new child. 278 255 */ 279 256 void ReplaceChildLink(VspNode *oldChild, VspNode *newChild); 280 281 257 /** Replace front and back child. 282 258 */ 283 259 void SetupChildLinks(VspNode *front, VspNode *back); 260 /** Returns boundiŽng box of this node. 261 */ 262 AxisAlignedBox3 GetBoundingBox() const; 263 /** Sets boundiong box of this node. 264 */ 265 void SetBoundingBox(const AxisAlignedBox3 &box); 266 /** Computes intersection of this plane with the ray segment. 267 */ 268 int ComputeRayIntersection(const RayInfo &rayData, float &t) const 269 { 270 return rayData.ComputeRayIntersection(mPlane.mAxis, mPlane.mPosition, t); 271 } 284 272 285 273 friend std::ostream &operator<<(std::ostream &s, const VspInterior &A) … … 288 276 } 289 277 290 AxisAlignedBox3 GetBoundingBox() const;291 void SetBoundingBox(const AxisAlignedBox3 &box);292 293 /** Computes intersection of this plane with the ray segment.294 */295 int ComputeRayIntersection(const RayInfo &rayData, float &t) const296 {297 return rayData.ComputeRayIntersection(mPlane.mAxis, mPlane.mPosition, t);298 }299 300 278 301 279 protected: 280 302 281 /// bounding box for this interior node: should we really store this? 303 282 AxisAlignedBox3 mBoundingBox; 304 305 283 /// Splitting plane corresponding to this node 306 284 AxisAlignedPlane mPlane; 307 308 285 /// back node 309 286 VspNode *mBack; … … 329 306 /** @return true since it is an interior node 330 307 */ 331 bool IsLeaf() const { 332 return true; 333 } 308 bool IsLeaf() const { return true; } 334 309 335 310 int Type() const; … … 337 312 /** Returns pointer of view cell. 338 313 */ 339 ViewCellLeaf *GetViewCell() const { 340 return mViewCell; 341 } 342 314 ViewCellLeaf *GetViewCell() const { return mViewCell; } 343 315 /** Sets pointer to view cell. 344 316 */ … … 383 355 public: 384 356 357 /////////// 358 //-- Helper structs / classes 359 385 360 /** Additional data which is passed down the BSP tree during traversal. 386 361 */ 387 classVspTraversalData362 struct VspTraversalData 388 363 { 389 364 public: 390 365 391 /** Returns average ray contribution. 392 */ 393 float GetAvgRayContribution() const 394 { 395 return (float)mPvs / ((float)mRays->size() + Limits::Small); 396 } 397 398 399 /** Returns average rays per object. 400 */ 401 float GetAvgRaysPerObject() const 402 { 403 return (float)mRays->size() / ((float)mPvs + Limits::Small); 404 } 405 406 VspTraversalData(): 407 mNode(NULL), 408 mDepth(0), 409 mRays(NULL), 410 mPvs(0), 411 mProbability(0.0), 412 mMaxCostMisses(0), 413 mPriority(0), 414 mCorrectedPvs(0) 415 {} 366 VspTraversalData(); 416 367 417 368 VspTraversalData(VspLeaf *node, … … 420 371 const float pvs, 421 372 const float p, 422 const AxisAlignedBox3 &box): 423 mNode(node), 424 mDepth(depth), 425 mRays(rays), 426 mProbability(p), 427 mBoundingBox(box), 428 mMaxCostMisses(0), 429 mPriority(0), 430 mCorrectedPvs(0), 431 mPvs(pvs), 432 mRenderCost(0), 433 mCorrectedRenderCost(0) 434 {} 435 436 VspTraversalData(const int depth, 437 RayInfoContainer *rays, 438 const AxisAlignedBox3 &box): 439 mNode(NULL), 440 mDepth(depth), 441 mRays(rays), 442 mProbability(0), 443 mMaxCostMisses(0), 444 mBoundingBox(box), 445 mCorrectedPvs(0), 446 mPvs(0) , 447 mRenderCost(0), 448 mCorrectedRenderCost(0) 449 {} 450 373 const AxisAlignedBox3 &box); 374 375 451 376 /** Returns cost of the traversal data. 452 377 */ 453 float GetCost() const 454 { 455 return mPriority; 456 } 457 458 /// deletes contents and sets them to NULL 459 void Clear() 460 { 461 DEL_PTR(mRays); 462 463 if (mNode) 464 { 465 // delete old view cell 466 delete mNode->GetViewCell(); 467 468 delete mNode; 469 mNode = NULL; 470 } 471 } 378 inline float GetCost() const; 379 /** Returns average ray contribution. 380 */ 381 inline float GetAvgRayContribution() const; 382 /** Returns average rays per object. 383 */ 384 inline float GetAvgRaysPerObject() const; 385 /** deletes contents and sets them to NULL. 386 */ 387 void Clear(); 388 389 390 ////////////////////// 472 391 473 392 /// the current node … … 500 419 }; 501 420 421 /** Helper struct for data that comes with a split of a node. 422 */ 502 423 struct SplitData 503 424 { … … 511 432 mFrontTriangles(0), 512 433 mBackTriangles(0), 513 mTotalTriangles(0) {} 514 434 mTotalTriangles(0) 435 {} 436 437 ////////////// 515 438 516 439 float mFrontRenderCost; … … 580 503 {} 581 504 582 float GetPriority() const 583 { 584 return mPriority; 585 } 505 float GetPriority() const { return mPriority; } 506 586 507 587 508 //////////////////// 588 509 589 510 static VspTree* sVspTree; 590 591 511 /// the current split plane 592 512 AxisAlignedPlane mSplitPlane; … … 623 543 }; 624 544 545 546 ////////////////////// 547 548 625 549 /** Default constructor creating an empty tree. 626 550 */ … … 629 553 */ 630 554 ~VspTree(); 631 632 555 /** Returns BSP Tree statistics. 633 556 */ 634 557 const VspTreeStatistics &GetStatistics() const; 635 636 558 /** Returns bounding box of the specified node. 637 559 */ 638 560 AxisAlignedBox3 GetBoundingBox(VspNode *node) const; 639 640 561 /** Returns list of BSP leaves with pvs smaller than 641 562 a certain threshold. … … 646 567 const bool onlyUnmailed = false, 647 568 const int maxPvs = -1) const; 648 649 569 /** Returns box which bounds the whole tree. 650 570 */ 651 571 AxisAlignedBox3 GetBoundingBox() const; 652 653 572 /** Returns root of the view space partitioning tree. 654 573 */ 655 574 VspNode *GetRoot() const; 656 657 575 /** Collects the leaf view cells of the tree 658 576 @param viewCells returns the view cells 659 577 */ 660 578 void CollectViewCells(ViewCellContainer &viewCells, bool onlyValid) const; 661 662 579 /** A ray is cast possible intersecting the tree. 663 580 @param the ray that is cast. … … 665 582 */ 666 583 int CastRay(Ray &ray); 667 668 669 584 /** finds neighbouring leaves of this tree node. 670 585 */ … … 672 587 vector<VspLeaf *> &neighbors, 673 588 const bool onlyUnmailed) const; 674 675 589 /** Returns random leaf of BSP tree. 676 590 @param halfspace defines the halfspace from which the leaf is taken. … … 682 596 */ 683 597 VspLeaf *GetRandomLeaf(const bool onlyUnmailed = false); 684 685 598 /** Returns epsilon of this tree. 686 599 */ 687 600 float GetEpsilon() const; 688 689 601 /** Casts line segment into the tree. 690 602 @param origin the origin of the line segment … … 696 608 ViewCellContainer &viewcells, 697 609 const bool useMailboxing = true); 698 699 700 610 /** Sets pointer to view cells manager. 701 611 */ 702 612 void SetViewCellsManager(ViewCellsManager *vcm); 703 704 613 /** Returns view cell the current point is located in. 705 614 @param point the current view point … … 708 617 */ 709 618 ViewCell *GetViewCell(const Vector3 &point, const bool active = false); 710 711 712 619 /** Returns true if this view point is in a valid view space, 713 620 false otherwise. 714 621 */ 715 622 bool ViewPointValid(const Vector3 &viewPoint) const; 716 717 623 /** Returns view cell corresponding to 718 624 the invalid view space. 719 625 */ 720 626 VspViewCell *GetOutOfBoundsCell(); 721 722 /** Writes tree to output stream723 */724 bool Export(OUT_STREAM &stream);725 726 627 /** Casts beam, i.e. a 5D frustum of rays, into tree. 727 628 Tests conservative using the bounding box of the nodes. … … 729 630 */ 730 631 int CastBeam(Beam &beam); 731 732 632 /** Checks if tree validity-flags are right 733 633 with respect to view cell valitiy. … … 735 635 */ 736 636 void ValidateTree(); 737 738 637 /** Collects rays stored in the leaves. 739 638 */ 740 639 void CollectRays(VssRayContainer &rays); 741 742 640 /** Intersects box with the tree and returns the number of intersected boxes. 743 641 @returns number of view cells found … … 745 643 int ComputeBoxIntersections(const AxisAlignedBox3 &box, 746 644 ViewCellContainer &viewCells) const; 747 748 645 /** Returns view cells of this ray, either taking precomputed cells 749 646 or by recomputation. 750 647 */ 751 648 void GetViewCells(const VssRay &ray, ViewCellContainer &viewCells); 752 753 649 /** Returns view cells tree. 754 650 */ 755 651 ViewCellsTree *GetViewCellsTree() const { return mViewCellsTree; } 756 757 652 /** Sets the view cells tree. 758 653 */ 759 654 void SetViewCellsTree(ViewCellsTree *vt) { mViewCellsTree = vt; } 760 655 /** Writes vsp tree to output stream 656 */ 657 bool Export(OUT_STREAM &stream); 658 /** Writes vsp tree to binary output stream. 659 */ 660 bool ExportBinary(OUT_STREAM &stream); 661 /** Imports tree from binary format. 662 */ 663 bool ImportBinary(IN_STREAM &stream, ObjectContainer &pvsObjects); 664 665 666 //////////// 761 667 762 668 PerfTimer mSortTimer; … … 808 714 float &pFront, 809 715 float &pBack) const; 810 716 /** If != NULL, sets the bounding box to the forced bounding box. 717 Else computes the bounding box of the view space using the 718 hit points gathered from the ray-object intersections. 719 */ 811 720 void ComputeBoundingBox(const VssRayContainer &rays, 812 721 AxisAlignedBox3 *forcedBoundingBox); 813 814 722 /** Evaluates candidate for splitting. 815 723 */ 816 void EvalSubdivisionCandidate(VspSubdivisionCandidate & splitData,724 void EvalSubdivisionCandidate(VspSubdivisionCandidate &candidate, 817 725 bool computeSplitPlane = true); 818 819 726 /** Evaluates render cost decrease of next split. 820 727 */ 821 float EvalRenderCostDecrease(VspSubdivisionCandidate & splitData,728 float EvalRenderCostDecrease(VspSubdivisionCandidate &candidate, 822 729 float &normalizedOldRenderCost, 823 730 const SplitData &data) const; 824 825 731 /** Collects view cells in the subtree under root. 826 732 */ … … 829 735 ViewCellContainer &viewCells, 830 736 bool onlyUnmailed = false) const; 831 832 737 /** Returns view cell corresponding to 833 738 the invalid view space. If it does not exist, it is created. 834 739 */ 835 740 VspViewCell *GetOrCreateOutOfBoundsCell(); 836 837 741 /** Collapses the tree with respect to the view cell partition, 838 742 i.e. leaves having the same view cell are collapsed. … … 843 747 */ 844 748 VspNode *CollapseTree(VspNode *node, int &collapsed); 845 846 749 /** Helper function revalidating the view cell leaf list after merge. 847 750 */ 848 751 void RepairViewCellsLeafLists(); 849 850 752 /** Evaluates tree stats in the BSP tree leafs. 851 753 */ … … 861 763 SubdivisionCandidate *splitCandidate, 862 764 const bool globalCriteriaMet); 863 864 765 /** Adds stats to subdivision log file. 865 766 */ … … 868 769 const float totalRenderCost, 869 770 const float avgRenderCost); 870 871 771 /** Subdivides leaf. 872 873 772 @param tData data object holding, e.g., a pointer to the leaf 874 773 @param frontData returns the data (e.g., pointer to the leaf) in front of the split plane 875 774 @param backData returns the data (e.g., pointer to the leaf) in the back of the split plane 876 877 @param rays the polygons to be filtered878 @param frontRays returns the polygons in front of the split plane879 775 880 776 @returns the root of the subdivision … … 891 787 float &pFront, 892 788 float &pBack); 893 894 789 /** Sorts split candidates along the specified axis. 895 790 The split candidates are generated on possible visibility … … 905 800 float minBand, 906 801 float maxBand); 907 908 802 /** Evaluate render cost of this pvs. 909 803 */ … … 912 806 int EvalPvsEntriesIncr(VspSubdivisionCandidate &splitCandidate, 913 807 const SplitData &sData) const; 914 915 808 /** Returns number of effective entries in the pvs. 916 809 */ … … 918 811 919 812 int EvalPvsEntriesContribution(const VssRay &ray, const bool isTermination) const; 920 921 813 /** Computes best cost for axis aligned planes. 922 814 */ … … 928 820 929 821 930 /////////////////////// ///////////////////931 // Helper function for computing heuristics822 /////////////////////// 823 //-- Helper function for computing heuristics 932 824 933 825 /** Evaluates the contribution to left and right pvs at a visibility event ve. … … 937 829 */ 938 830 inline void EvalHeuristics(const SortableEntry &ve, float &pvsLeft, float &pvsRight) const; 939 940 831 /** Evaluates contribution of min event to pvs 941 832 */ 942 833 inline float EvalMinEventContribution(const VssRay &ray, const bool isTermination) const; 943 944 834 /** Evaluates contribution of max event to pvs 945 835 */ 946 836 inline float EvalMaxEventContribution(const VssRay &ray, const bool isTermination) const; 947 948 837 /** Evaluates contribution of kd leaf when encountering a min event 949 838 */ 950 839 inline float EvalMinEventContribution(KdLeaf *leaf) const; 951 952 840 /** Evaluates contribution of kd leaf when encountering a max event 953 841 */ 954 842 inline float EvalMaxEventContribution(KdLeaf *leaf) const; 955 956 843 /** Prepares objects for the heuristics. 957 844 @returns pvs size as seen by the rays. 958 845 */ 959 846 float PrepareHeuristics(const RayInfoContainer &rays); 960 961 847 /** Prepare a single ray for heuristics. 962 848 */ 963 849 float PrepareHeuristics(const VssRay &ray, const bool isTermination); 964 965 850 /** Prepare a single kd leaf for heuristics. 966 851 */ 967 852 float PrepareHeuristics(KdLeaf *leaf); 968 853 /** Evaluates minimal and maximal depth in the tree. 854 */ 969 855 void EvalMinMaxDepth(int &minDepth, int &maxDepth); 970 971 972 973 ///////////////////////////////////////////////////////////// 974 856 /** Writes the node to disk 857 @note: should be implemented as visitor. 858 */ 859 void ExportNode(VspNode *node, OUT_STREAM &stream); 860 861 862 //////////////// 863 864 void ExportBinInterior(OUT_STREAM &stream, VspInterior *interior); 865 void ExportBinLeaf(OUT_STREAM &stream, VspLeaf *leaf); 866 867 VspInterior *ImportBinInterior(IN_STREAM &stream, VspInterior *parent); 868 VspLeaf *ImportBinLeaf(IN_STREAM &stream, VspInterior *parent, const ObjectContainer &pvsObjects); 869 870 VspNode *ImportNextNode(IN_STREAM &stream, 871 VspInterior *parent, 872 const ObjectContainer &pvsObjects); 873 874 875 ////////////////////////////////////////////////// 975 876 976 877 /** Subdivides the rays into front and back rays according to the split plane. 977 978 878 @param plane the split plane 979 879 @param rays contains the rays to be split. The rays are … … 988 888 RayInfoContainer &frontRays, 989 889 RayInfoContainer &backRays) const; 990 991 890 /** Add contributions of this ray to fron, back, and overall pvs of the parent. 891 */ 992 892 inline void UpdatePvsEntriesContribution(const VssRay &ray, 993 893 const bool isTermination, … … 996 896 float &backPvs, 997 897 float &totalPvs) const; 998 999 898 /** Classfifies the object with respect to the 1000 899 pvs of the front and back leaf and updates pvs size … … 1013 912 float &backPvs, 1014 913 float &totalPvs) const; 1015 1016 914 /** Evaluates the contribution for objects. 1017 915 */ … … 1021 919 float &backPvs, 1022 920 float &totalPvs) const; 1023 1024 921 /** Evaluates the contribution for bounding volume leaves. 1025 922 */ … … 1030 927 float &totalPvs, 1031 928 const bool countEntries) const; 1032 929 /** Updates contribution to pvs caused by this bvh leaf. 930 */ 1033 931 inline void UpdateContributionsToPvs(BvhLeaf *leaf, 1034 932 const int cf, 1035 933 SplitData &sdata) const; 1036 1037 934 /** Evaluates the contribution for kd leaves. 1038 935 */ … … 1042 939 float &backPvs, 1043 940 float &totalPvs) const; 1044 1045 941 /** Returns true if tree can be terminated. 1046 942 */ 1047 943 inline bool LocalTerminationCriteriaMet(const VspTraversalData &data) const; 1048 1049 944 /** Returns true if global tree can be terminated. 1050 945 */ 1051 946 bool GlobalTerminationCriteriaMet(const VspTraversalData &data) const; 1052 1053 947 /** Adds ray sample contributions to the PVS. 1054 948 @param sampleContributions the number contributions of the samples … … 1060 954 float &sampleContributions, 1061 955 int &contributingSamples); 1062 1063 956 /** Propagates valid flag up the tree. 1064 957 */ 1065 958 void PropagateUpValidity(VspNode *node); 1066 1067 /** Writes the node to disk1068 @note: should be implemented as visitor.1069 */1070 void ExportNode(VspNode *node, OUT_STREAM &stream);1071 1072 959 /** Returns estimated memory usage of tree. 1073 960 */ 1074 961 float GetMemUsage() const; 1075 1076 962 /** Updates view cell pvs of objects. 1077 963 */ … … 1079 965 ViewCell *front, 1080 966 ViewCell *back) const; 1081 967 /** Creates a new view cell from the traversal data. 968 */ 1082 969 void CreateViewCell(VspTraversalData &tData, 1083 970 const bool updatePvs, 1084 971 const float renderCost, 1085 972 const int pvs); 1086 1087 973 /** Collect split candidates which are affected by the last split 1088 974 and must be reevaluated. … … 1091 977 vector<SubdivisionCandidate *> &dirtyList, 1092 978 const bool onlyUnmailed); 1093 1094 void CollectDirtyCandidate(const VssRay &ray, 979 /** Adds the split candidate associated with this ray to the dirty list. 980 */ 981 void AddCandidateToDirtyList(const VssRay &ray, 1095 982 const bool isTermination, 1096 983 vector<SubdivisionCandidate *> &dirtyList, 1097 984 const bool onlyUnmailed) const; 1098 1099 985 /** Rays will be clipped to the bounding box. 1100 986 */ 1101 987 void PreprocessRays(const VssRayContainer &sampleRays, RayInfoContainer &rays); 1102 1103 988 /** Evaluate subdivision statistics. 1104 989 */ 1105 990 void EvalSubdivisionStats(const SubdivisionCandidate &tData); 1106 991 /** Prepares the construction of the vsp tree. 992 */ 1107 993 void PrepareConstruction(SplitQueue &tQueue, 1108 994 const VssRayContainer &sampleRays, 1109 995 RayInfoContainer &rays); 1110 1111 996 /** Evaluates pvs contribution of this ray. 1112 997 */ 1113 998 float EvalContributionToPvs(const VssRay &ray, const bool isTermination) const; 1114 1115 999 /** Evaluates pvs contribution of a kd node. 1116 1000 */ 1117 1001 float EvalContributionToPvs(KdLeaf *leaf) const; 1118 1119 1002 /** Creates new root of hierarchy and computes bounding box. 1120 1003 Has to be called before the preparation of the subdivision. … … 1197 1080 int mStackPtr; 1198 1081 int mDepth; 1199 1200 1082 }; 1201 1083 … … 1207 1089 /// pointer to the hierarchy of view cells 1208 1090 ViewCellsTree *mViewCellsTree; 1209 1091 /// Pointer to the hierarchy manager which is responsible for both 1092 /// view and object space 1210 1093 HierarchyManager *mHierarchyManager; 1094 /// Pointer to the bv hierarchy 1211 1095 BvHierarchy *mBvHierarchy; 1212 1096 /// Pointer to the view cells manager 1213 1097 ViewCellsManager *mViewCellsManager; 1214 1098 /// Buffer for subdivision candidates used for split heuristics evaluation 1215 1099 vector<SortableEntry> *mLocalSubdivisionCandidates; 1216 1217 1100 /// Pointer to the root of the tree 1218 1101 VspNode *mRoot; 1219 1102 /// The statistics 1220 1103 VspTreeStatistics mVspStats; 1221 1222 1104 /// View cell corresponding to the space outside the valid view space 1223 1105 VspViewCell *mOutOfBoundsCell; 1224 1225 1106 /// box around the whole view domain 1226 1107 AxisAlignedBox3 mBoundingBox; … … 1281 1162 // if rays should be stored in leaves 1282 1163 bool mStoreRays; 1283 1284 1164 /// epsilon for geometric comparisons 1285 1165 float mEpsilon; 1286 1287 1166 /// subdivision stats output file 1288 1167 std::ofstream mSubdivisionStats; 1289 1168 /// keeps track of cost during subdivision 1290 1169 float mTotalCost; 1170 /// keeps track of #pvs entries during subdivison 1291 1171 int mPvsEntries; 1292 1172 /// keeps track of overall pvs size during subdivision … … 1297 1177 /// weight between render cost decrease and node render cost 1298 1178 float mRenderCostDecreaseWeight; 1299 1179 /// maximal #of rays used for heuristics evalution 1300 1180 int mMaxTests; 1301 1302 1181 /// constant value for driving the heuristics 1303 1182 float mMemoryConst; -
GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp
r2176 r2539 357 357 MeshManager::GetSingleton()->FindEntry(meshIdx); 358 358 359 //Debug << "retrieving mesh definition: " << mCurrentMeshName << endl;360 359 cout << "u"; 361 360 } 362 else if (attrName == "DEF") // --a definition of a mesh361 else if (attrName == "DEF") // a definition of a mesh 363 362 { 364 363 const StrX attrValue(attributes.getValue(i));
Note: See TracChangeset
for help on using the changeset viewer.