- Timestamp:
- 02/04/06 12:46:14 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
r586 r587 920 920 { 921 921 environment->GetIntValue("BspTree.Construction.samples", mInitialSamples); 922 mBspTree->SetViewCellsManager(this); 922 923 } 923 924 … … 965 966 { 966 967 // no view cells loaded 967 mBspTree->Construct(objects, constructionRays );968 mBspTree->Construct(objects, constructionRays, &mViewSpaceBox); 968 969 // collect final view cells 969 970 mBspTree->CollectViewCells(mViewCells); … … 986 987 987 988 989 ResetViewCells(); 990 991 Debug << "\nView cells after " << (int)savedRays.size() 992 << " samples:\n" << mViewCellsStats << endl; 993 994 if (1) // export initial view cells 995 { 996 cout << "exporting initial view cells (=leaves) ... "; 997 Exporter *exporter = Exporter::GetExporter("view_cells.x3d"); 998 999 if (exporter) 1000 { 1001 //exporter->SetWireframe(); 1002 exporter->SetFilled(); 1003 ExportViewCellsForViz(exporter); 1004 1005 if (0 && mExportRays) 1006 exporter->ExportRays(rays, RgbColor(1, 1, 1)); 1007 1008 if (mExportGeometry) 1009 exporter->ExportGeometry(objects); 1010 1011 delete exporter; 1012 } 1013 cout << "finished" << endl; 1014 } 1015 1016 988 1017 return sampleContributions; 989 1018 } … … 992 1021 void BspViewCellsManager::CollectViewCells() 993 1022 { 994 mBspTree->CollectViewCells(mViewCells); 1023 // view cells tree constructed 1024 if (!ViewCellsTreeConstructed()) 1025 { 1026 mBspTree->CollectViewCells(mViewCells); 1027 } 1028 else 1029 { 1030 // we can use the view cells tree hierarchy to get the right set 1031 mViewCellsTree->CollectBestViewCellSet(mViewCells, mNumMergedViewCells); 1032 } 995 1033 } 996 1034 … … 1007 1045 1008 1046 1009 float BspViewCellsManager::GetRendercost(ViewCell *viewCell, float objRendercost) const 1047 float BspViewCellsManager::GetRendercost(ViewCell *viewCell, 1048 float objRendercost) const 1010 1049 { 1011 1050 return viewCell->GetPvs().GetSize() * objRendercost; … … 1072 1111 1073 1112 long startTime = GetTime(); 1074 1113 1114 VssRayContainer postProcessRays; 1115 GetRaySets(rays, mPostProcessSamples, postProcessRays); 1075 1116 1076 1117 //-- merge or subdivide view cells 1077 int merged = 0; 1078 1079 // TODO 1080 1118 int merged = mViewCellsTree->ConstructMergeTree(rays, objects); 1119 1081 1120 //-- stats and visualizations 1082 1121 cout << "finished" << endl; … … 1088 1127 << "using " << (int)rays.size() << " samples" << endl << endl; 1089 1128 1129 1090 1130 // reset view cells and stats 1091 1131 ResetViewCells(); 1132 FinalizeViewCells(true); 1133 1134 // for output we need unique ids for each view cell 1135 CreateUniqueViewCellIds(); 1136 1137 // write view cells to disc 1138 if (mExportViewCells) 1139 { 1140 char buff[100]; 1141 environment->GetStringValue("ViewCells.filename", buff); 1142 string vcFilename(buff); 1143 1144 ExportViewCells(buff); 1145 } 1092 1146 1093 1147 return merged; … … 1112 1166 return; 1113 1167 1114 if (1) // export view cells 1115 { 1168 //BspLeaf::NewMail(); 1169 if (1) // export merged view cells 1170 { 1171 1172 cout << "reseting view cells ... "; 1173 ResetViewCells(); 1174 1175 cout << "finished" << endl; 1176 1177 Exporter *exporter = Exporter::GetExporter("merged_view_cells.x3d"); 1178 Debug << "\nView cells after merge:\n" << mViewCellsStats << endl; 1179 1116 1180 cout << "exporting view cells after merge ... "; 1117 Exporter *exporter = Exporter::GetExporter("merged_view_cells.x3d");1118 1119 1181 1120 1182 if (exporter) 1121 1183 { 1184 if (0) 1185 exporter->SetWireframe(); 1186 else 1187 exporter->SetFilled(); 1122 1188 ExportViewCellsForViz(exporter); 1189 1190 if (mExportGeometry) 1191 { 1192 Material m; 1193 m.mDiffuseColor = RgbColor(0, 1, 0); 1194 exporter->SetForcedMaterial(m); 1195 exporter->SetFilled(); 1196 1197 exporter->ExportGeometry(objects); 1198 } 1199 1123 1200 delete exporter; 1124 1201 } 1125 1126 1202 cout << "finished" << endl; 1127 1203 } … … 1189 1265 1190 1266 // sort view cells to get largest view cells 1191 #if 0 1192 stable_sort(mViewCells.begin(), mViewCells.end(), vc_gt);1193 #endif 1267 if (0) 1268 stable_sort(mViewCells.begin(), mViewCells.end(), vc_gt); 1269 1194 1270 int limit = min(leafOut, (int)mViewCells.size()); 1195 1271 … … 1208 1284 cout << "creating output for view cell " << i << " ... "; 1209 1285 1210 #if 0 1211 // check whether we can add the current ray to the output rays 1212 for (int k = 0; k < raysOut; ++ k) 1213 { 1214 BspRay *ray = mBspRays[k]; 1215 for (int j = 0; j < (int)ray->intersections.size(); ++ j) 1286 if(0) 1287 { 1288 // check whether we can add the current ray to the output rays 1289 for (int k = 0; k < raysOut; ++ k) 1216 1290 { 1217 BspLeaf *leaf = ray->intersections[j].mLeaf; 1218 if (vc == leaf->GetViewCell()) 1219 vcRays.push_back(ray->vssRay); 1291 BspRay *ray = mBspRays[k]; 1292 for (int j = 0; j < (int)ray->intersections.size(); ++ j) 1293 { 1294 BspLeaf *leaf = ray->intersections[j].mLeaf; 1295 if (vc == leaf->GetViewCell()) 1296 vcRays.push_back(ray->vssRay); 1297 } 1220 1298 } 1221 1299 } 1222 #endif 1300 1223 1301 //bspLeaves[j]->Mail(); 1224 1302 char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); … … 1232 1310 exporter->SetForcedMaterial(m); 1233 1311 1234 if (vc->GetMesh()) 1235 exporter->ExportViewCell(vc); 1236 else 1237 { 1238 BspNodeGeometry vcGeom; 1239 1240 //-- export view cell 1241 #if VC_HISTORY 1242 mBspTree->ConstructGeometry(vc, vcGeom); 1243 exporter->ExportPolygons(vcGeom.mPolys); 1244 #endif 1245 } 1312 ExportViewCellGeometry(exporter, vc); 1313 1246 1314 1247 1315 Debug << i << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc) … … 1284 1352 1285 1353 1286 1287 void BspViewCellsManager::ConstructBspRays(const VssRayContainer &rays,1288 const int numSamples)1289 {1290 VssRayContainer::const_iterator it, it_end = rays.end();1291 1292 for (it = rays.begin(); it != rays.end() && mBspRays.size() < numSamples; ++ it)1293 {1294 VssRay *vssRay = *it;1295 BspRay *ray = new BspRay(vssRay);1296 1297 ViewCellContainer viewCells;1298 1299 // cast line segment to get intersections with bsp leaves1300 CastLineSegment(vssRay->mTermination, vssRay->mOrigin, viewCells);1301 #if VC_HISTORY1302 ViewCellContainer::const_iterator vit, vit_end = viewCells.end();1303 for (vit = viewCells.begin(); vit != vit_end; ++ vit)1304 {1305 ViewCell *vc = *vit;1306 ray->intersections.push_back(BspIntersection(0, vc->mLeaf));1307 }1308 #endif1309 mBspRays.push_back(ray);1310 }1311 }1312 1313 1314 1354 void BspViewCellsManager::ExportColor(Exporter *exporter, 1315 1355 ViewCell *vc) const … … 1354 1394 } 1355 1395 1396 1356 1397 void BspViewCellsManager::ExportViewCellGeometry(Exporter *exporter, 1357 ViewCell *vc) const1398 ViewCell *vc) const 1358 1399 { 1359 1400 if (vc->GetMesh()) 1360 exporter->ExportViewCell(vc); 1401 { 1402 exporter->ExportMesh(vc->GetMesh()); 1403 return; 1404 } 1405 1406 BspNodeGeometry geom; 1407 mBspTree->ConstructGeometry(vc, geom); 1408 exporter->ExportPolygons(geom.mPolys); 1409 } 1410 1411 1412 void BspViewCellsManager::CreateMesh(ViewCell *vc) 1413 { 1414 if (vc->GetMesh()) 1415 delete vc->GetMesh(); 1416 1417 BspNodeGeometry geom; 1418 1419 mBspTree->ConstructGeometry(vc, geom); 1420 1421 Mesh *mesh = new Mesh(); 1422 geom.AddToMesh(*mesh); 1423 vc->SetMesh(mesh); 1424 mMeshContainer.push_back(mesh); 1425 } 1426 1427 1428 void BspViewCellsManager::Finalize(ViewCell *viewCell, 1429 const bool createMesh) 1430 { 1431 CreateMesh(viewCell); 1432 1433 float area = 0; 1434 float volume = 0; 1435 1436 ViewCellContainer leaves; 1437 mViewCellsTree->CollectLeaves(viewCell, leaves); 1438 1439 ViewCellContainer::const_iterator it, it_end = leaves.end(); 1440 1441 for (it = leaves.begin(); it != it_end; ++ it) 1442 { 1443 BspNodeGeometry geom; 1444 BspLeaf *leaf = dynamic_cast<BspViewCell *>(*it)->mLeaf; 1445 mBspTree->ConstructGeometry(leaf, geom); 1446 1447 area += geom.GetArea(); 1448 volume += geom.GetVolume(); 1449 } 1450 1451 viewCell->SetVolume(volume); 1452 viewCell->SetArea(area); 1453 } 1454 1455 1456 ViewCell *BspViewCellsManager::GetViewCell(const Vector3 &point) const 1457 { 1458 if (!mBspTree) 1459 return NULL; 1460 1461 if (!mViewSpaceBox.IsInside(point)) 1462 return NULL; 1463 1464 return mBspTree->GetViewCell(point); 1465 } 1466 1467 1468 void BspViewCellsManager::CollectMergeCandidates(const VssRayContainer &rays, 1469 vector<MergeCandidate> &candidates) 1470 { 1471 cout << "collecting merge candidates ... " << endl; 1472 1473 if (mUseRaysForMerge) 1474 { 1475 mBspTree->CollectMergeCandidates(rays, candidates); 1476 } 1361 1477 else 1362 1478 { 1363 BspNodeGeometry geom; 1364 #if VC_HISTORY 1365 mBspTree->ConstructGeometry(vc, geom); 1366 exporter->ExportPolygons(geom.mPolys); 1367 #endif 1368 } 1369 } 1370 1371 1372 void BspViewCellsManager::CreateMesh(ViewCell *vc) 1373 { 1374 // TODO 1375 } 1376 1377 1378 ViewCell *BspViewCellsManager::GetViewCell(const Vector3 &point) const 1379 { 1380 if (!mBspTree) 1381 return NULL; 1382 1383 if (!mViewSpaceBox.IsInside(point)) 1384 return NULL; 1385 1386 return mBspTree->GetViewCell(point); 1387 } 1388 1389 1390 void BspViewCellsManager::CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates) 1391 { 1392 // TODO 1479 vector<BspLeaf *> leaves; 1480 mBspTree->CollectLeaves(leaves); 1481 mBspTree->CollectMergeCandidates(leaves, candidates); 1482 } 1483 1484 cout << "fininshed collecting candidates" << endl; 1393 1485 } 1394 1486 … … 1453 1545 return 0; 1454 1546 } 1547 1455 1548 1456 1549 bool KdViewCellsManager::ViewCellsConstructed() const … … 2154 2247 VssRayContainer savedRays; 2155 2248 2156 Debug << "samples used for subdivision: " << mInitialSamples << " rays: " << (int)rays.size() << endl; 2249 Debug << "samples used for subdivision: " << mInitialSamples 2250 << " rays: " << (int)rays.size() << endl; 2251 2157 2252 GetRaySets(rays, mInitialSamples, constructionRays, &savedRays); 2158 2253 … … 2170 2265 long startTime = GetTime(); 2171 2266 int collapsedLeaves = mVspBspTree->CollapseTree(); 2172 Debug << "collapsed in " << TimeDiff(startTime, GetTime()) * 1e-3 << " seconds" << endl; 2267 Debug << "collapsed in " << TimeDiff(startTime, GetTime()) * 1e-3 2268 << " seconds" << endl; 2269 2173 2270 cout << "finished" << endl; 2174 2271 … … 2257 2354 cout << "reseting view cells ... "; 2258 2355 ResetViewCells(); 2356 2259 2357 cout << "finished" << endl; 2260 2358 … … 2685 2783 2686 2784 // sort view cells to visualize the largest view cells 2687 #if 0 2688 stable_sort(mViewCells.begin(), mViewCells.end(), vc_gt);2689 #endif 2785 if (0) 2786 stable_sort(mViewCells.begin(), mViewCells.end(), vc_gt); 2787 2690 2788 int limit = min(leafOut, (int)mViewCells.size()); 2691 2789 2692 #if 1 2790 int raysOut; 2791 2693 2792 //-- some rays for output 2694 const int raysOut = min((int)rays.size(), mVisualizationSamples); 2695 2696 #endif 2793 if (1) 2794 raysOut = min((int)rays.size(), mVisualizationSamples); 2697 2795 2698 2796 for (int i = 0; i < limit; ++ i) … … 2709 2807 vc = mViewCells[Random((int)mViewCells.size())]; 2710 2808 2809 vector<ViewCell *> leaves; 2810 mViewCellsTree->CollectLeaves(vc, leaves); 2811 2711 2812 if (1) 2712 2813 { … … 2718 2819 { 2719 2820 ViewCell *rayvc = ray->mViewCells[j]; 2720 #if VC_HISTORY 2721 BspLeaf *leaf = rayvc->mLeaf; 2722 if (vc == rayvc) 2821 2822 if (leaves[0] == rayvc) 2723 2823 vcRays.push_back(ray); 2724 #endif2725 2824 } 2726 2825 } … … 3021 3120 3022 3121 3023 void VspBspViewCellsManager::Finalize(ViewCell *viewCell, const bool createMesh) 3122 void VspBspViewCellsManager::Finalize(ViewCell *viewCell, 3123 const bool createMesh) 3024 3124 { 3025 3125 CreateMesh(viewCell);
Note: See TracChangeset
for help on using the changeset viewer.