Changeset 1563 for GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
- Timestamp:
- 10/03/06 22:03:58 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1557 r1563 233 233 Mesh *m = vc->GetMesh(); 234 234 235 if (m) { 236 m->ComputeBoundingBox(); 237 return m->mBox; 235 if (m) 236 { 237 m->ComputeBoundingBox(); 238 return m->mBox; 238 239 } 239 240 240 241 AxisAlignedBox3 box; 241 242 242 box.Initialize(); 243 243 … … 289 289 { 290 290 VssRayContainer::const_iterator it, it_end = rays.end(); 291 292 291 for (it = rays.begin(); it != it_end; ++ it) 293 292 { … … 298 297 { 299 298 VssRayContainer::const_iterator it, it_end = rays.end(); 300 301 299 for (it = rays.begin(); it != it_end; ++ it) 302 300 { 303 //(*it)->Unref();304 301 if (!(*it)->IsActive()) 305 302 delete (*it); … … 322 319 mPreprocessor = preprocessor; 323 320 324 321 325 322 /////////////////////////////////////////////////////// 326 323 //-- Initial sampling for the construction of the view cell hierarchy. … … 361 358 { 362 359 //-- export initial view cell partition 363 Debug << "\nView cells after initial sampling:\n" 364 << mCurrentViewCellsStats << endl; 360 Debug << "\nView cells after initial sampling:\n" << mCurrentViewCellsStats << endl; 365 361 366 362 const string filename("viewcells.wrl"); … … 428 424 429 425 430 #if 0 431 ///////////////432 //-- Get stats after the additional sampling step433 //-- and before the bottom-up mergestep434 435 EvaluateViewCellsStats(); 436 Debug << "\noriginal view cell partition before post process:\n"437 << mCurrentViewCellsStats << endl;438 439 mRenderer->RenderScene();440 SimulationStatistics ss;441 dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss);442 443 Debug << ss << endl; 444 #endif 445 426 if (0) 427 { 428 /////////////// 429 //-- Get stats after the additional sampling step 430 //-- and before the bottom-up merge step 431 432 EvaluateViewCellsStats(); 433 Debug << "\noriginal view cell partition before post process:\n" 434 << mCurrentViewCellsStats << endl; 435 436 mRenderer->RenderScene(); 437 SimulationStatistics ss; 438 dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss); 439 440 Debug << ss << endl; 441 } 446 442 447 443 //////////////////// … … 612 608 { 613 609 ViewCellsParser parser; 614 615 610 ViewCellsManager *vm = NULL; 616 611 617 612 if (parser.ParseViewCellsFile(filename, &vm, objects, bconverter)) 618 613 { 619 long startTime = GetTime();614 const long startTime = GetTime(); 620 615 621 616 vm->ResetViewCells(); … … 671 666 for (oit = objects.begin(); oit != oit_end; ++ oit) 672 667 { 673 MeshInstance *mi = dynamic_cast<MeshInstance *>(*oit); 674 const AxisAlignedBox3 box = mi->GetBox(); 668 const AxisAlignedBox3 box = (*oit)->GetBox(); 675 669 676 670 //////////// 677 671 //-- the bounding boxes 678 stream << "<BoundingBox" << " id=\"" << mi->GetId() << "\""672 stream << "<BoundingBox" << " id=\"" << (*oit)->GetId() << "\"" 679 673 << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 680 674 << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; … … 1262 1256 const bool extrudeBaseTriangles) 1263 1257 { 1264 bool success;1265 1266 1258 /// we use predefined view cells from now on 1267 1259 mUsePredefinedViewCells = true; … … 1271 1263 { 1272 1264 Environment::GetSingleton()->GetFloatValue("ViewCells.height", parser.mViewCellHeight); 1273 success = parser.ParseFile(filename, *this); 1265 const bool success = parser.ParseFile(filename, *this); 1266 1267 if (!success) 1268 return false; 1274 1269 } 1275 1270 else … … 1277 1272 // hack: use standard mesh loading 1278 1273 // create temporary scene graph for loading the view cells geometry 1274 // note: delete the meshes as they are created two times for transformed mesh instances. 1279 1275 SceneGraphNode *root = new SceneGraphNode(); 1280 success = parser.ParseFile(filename, root, true); 1281 1282 if (success) 1283 { 1284 ObjectContainer::const_iterator oit, oit_end = root->mGeometry.end(); 1285 for (oit = root->mGeometry.begin(); oit != oit_end; ++ oit) 1276 const bool success = parser.ParseFile(filename, root, true); 1277 1278 if (!success) 1279 { 1280 DEL_PTR(root); 1281 return false; 1282 } 1283 1284 ObjectContainer::const_iterator oit, oit_end = root->mGeometry.end(); 1285 1286 for (oit = root->mGeometry.begin(); oit != oit_end; ++ oit) 1287 { 1288 Mesh *mesh; 1289 if ((*oit)->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE) 1286 1290 { 1287 if ((*oit)->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE) 1288 { 1289 TransformedMeshInstance *mit = dynamic_cast<TransformedMeshInstance *>(*oit); 1290 Mesh *mesh = MeshManager::GetSingleton()->CreateResource(); 1291 mit->GetTransformedMesh(*mesh); 1292 mesh->ComputeBoundingBox(); 1293 mViewCells.push_back(GenerateViewCell(mesh)); 1294 } 1295 else if ((*oit)->Type() == Intersectable::MESH_INSTANCE) 1296 { 1297 MeshInstance *mit = dynamic_cast<MeshInstance *>(*oit); 1298 mViewCells.push_back(GenerateViewCell(mit->GetMesh())); 1299 } 1291 TransformedMeshInstance *mit = dynamic_cast<TransformedMeshInstance *>(*oit); 1292 mesh = MeshManager::GetSingleton()->CreateResource(); 1293 mit->GetTransformedMesh(*mesh); 1300 1294 } 1301 } 1295 else if ((*oit)->Type() == Intersectable::MESH_INSTANCE) 1296 { 1297 MeshInstance *mit = dynamic_cast<MeshInstance *>(*oit); 1298 mesh = mit->GetMesh(); 1299 } 1300 mesh->ComputeBoundingBox(); 1301 mViewCells.push_back(GenerateViewCell(mesh)); 1302 } 1303 1302 1304 DEL_PTR(root); 1303 1305 } 1304 1306 1305 if (success) 1306 { 1307 // set view space box to bounding box of the view cells 1308 AxisAlignedBox3 bbox; 1309 bbox.Initialize(); 1310 ViewCellContainer::iterator it = mViewCells.begin(), it_end = mViewCells.end(); 1311 for (; it != it_end; ++ it) 1312 { 1313 bbox.Include(GetViewCellBox(*it)); 1314 } 1315 SetViewSpaceBox(bbox); 1316 1317 cout << "generated " << (int)mViewCells.size() << " view cells using the geometry from file " << filename << endl; 1318 } 1319 1320 return success; 1307 // set view space box to bounding box of the view cells 1308 AxisAlignedBox3 bbox; 1309 bbox.Initialize(); 1310 ViewCellContainer::iterator it = mViewCells.begin(), it_end = mViewCells.end(); 1311 1312 for (; it != it_end; ++ it) 1313 { 1314 bbox.Include((*it)->GetMesh()->mBox); 1315 } 1316 1317 SetViewSpaceBox(bbox); 1318 cout << "view space box: " << bbox << endl; 1319 cout << "generated " << (int)mViewCells.size() << " view cells using the geometry " << filename << endl; 1320 1321 return true; 1321 1322 } 1322 1323 … … 2539 2540 VssRayContainer savedRays; 2540 2541 2542 // choose a a number of rays based on the ratio of cast rays / requested rays 2541 2543 const int limit = min(mInitialSamples, (int)rays.size()); 2542 2543 2544 VssRayContainer::const_iterator it, it_end = rays.end(); 2544 2545 2545 2546 const float prop = (float)limit / ((float)rays.size() + Limits::Small); 2546 2547 2547 for (it = rays.begin(); it != it_end; ++ it) 2548 2548 { … … 2785 2785 return; 2786 2786 2787 int savedColorCode = mColorCode;2787 const int savedColorCode = mColorCode; 2788 2788 2789 2789 if (1) // export final view cells … … 2989 2989 const AxisAlignedBox3 *sceneBox, 2990 2990 const AxisAlignedPlane *clipPlane 2991 ) const 2992 { 2993 // out of bounds cell 2994 //if (vc->GetId() == OUT_OF_BOUNDS_ID) return; 2995 2996 // export mesh if available 2997 if (vc->GetMesh()) 2998 { 2999 exporter->ExportMesh(vc->GetMesh()); 3000 return; 3001 } 3002 3003 // otherwise construct from leaves 2991 ) const 2992 { 3004 2993 if (clipPlane) 3005 2994 { … … 3018 3007 mBspTree->ConstructGeometry(*it, geom); 3019 3008 3020 const float eps = 0.000 00001f;3009 const float eps = 0.0001f; 3021 3010 const int cf = geom.Side(plane, eps); 3022 3011 … … 3032 3021 mViewSpaceBox, 3033 3022 eps); 3034 3023 3035 3024 if (back.Valid()) 3036 { 3025 { 3037 3026 exporter->ExportPolygons(back.GetPolys()); 3038 3027 } … … 3042 3031 else 3043 3032 { 3044 BspNodeGeometry geom; 3045 mBspTree->ConstructGeometry(vc, geom); 3046 exporter->ExportPolygons(geom.GetPolys()); 3033 // export mesh if available 3034 // TODO: some bug here? 3035 if (1 && vc->GetMesh()) 3036 { 3037 exporter->ExportMesh(vc->GetMesh()); 3038 } 3039 else 3040 { 3041 BspNodeGeometry geom; 3042 mBspTree->ConstructGeometry(vc, geom); 3043 exporter->ExportPolygons(geom.GetPolys()); 3044 } 3047 3045 } 3048 3046 } … … 3158 3156 for (oit = objects.begin(); oit != oit_end; ++ oit) 3159 3157 { 3160 MeshInstance *mi = dynamic_cast<MeshInstance *>(*oit); 3161 const AxisAlignedBox3 box = mi->GetBox(); 3158 const AxisAlignedBox3 box = (*oit)->GetBox(); 3162 3159 3163 stream << "<BoundingBox" << " id=\"" << mi->GetId() << "\""3160 stream << "<BoundingBox" << " id=\"" << (*oit)->GetId() << "\"" 3164 3161 << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 3165 3162 << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; … … 4123 4120 { 4124 4121 cout << "exporting view cells after post process ... "; 4125 4126 4122 if (0) 4127 { 4128 // export view space box 4123 { // export view space box 4129 4124 exporter->SetWireframe(); 4130 4125 exporter->ExportBox(mViewSpaceBox); … … 4133 4128 4134 4129 Material m; 4135 4136 4130 m.mDiffuseColor.r = 0.0f; 4137 4131 m.mDiffuseColor.g = 0.5f; … … 4140 4134 exporter->SetForcedMaterial(m); 4141 4135 4142 if ( 0&& mExportGeometry)4136 if (1 && mExportGeometry) 4143 4137 { 4144 4138 exporter->ExportGeometry(objects); 4145 4139 } 4146 4140 4147 // export rays4148 4141 if (0 && mExportRays) 4149 4142 { 4150 4143 exporter->ExportRays(visRays, RgbColor(1, 0, 0)); 4151 4144 } 4152 4153 4145 ExportViewCellsForViz(exporter, NULL, GetClipPlane()); 4154 4146 … … 4500 4492 ) const 4501 4493 { 4502 // out of bounds cell4503 //if (vc->GetId() == OUT_OF_BOUNDS_ID) return;4504 4494 if (clipPlane) 4505 4495 { … … 4513 4503 { 4514 4504 BspNodeGeometry geom; 4515 4516 4505 BspNodeGeometry front; 4517 4506 BspNodeGeometry back; … … 4545 4534 // export mesh if available 4546 4535 // TODO: some bug here? 4547 if ( 0&& vc->GetMesh())4536 if (1 && vc->GetMesh()) 4548 4537 { 4549 4538 exporter->ExportMesh(vc->GetMesh()); … … 5070 5059 5071 5060 // matt: hack for clamping scene 5072 AxisAlignedBox3 bbox = m HierarchyManager->GetViewSpaceBox();5061 AxisAlignedBox3 bbox = mViewSpaceBox; 5073 5062 bbox.Scale(Vector3(0.5, 1, 0.5)); 5074 5063 if (CLAMP_TO_BOX)
Note: See TracChangeset
for help on using the changeset viewer.