Changeset 478
- Timestamp:
- 12/22/05 18:32:39 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r475 r478 13 13 #;../data/vienna/vienna-plane.x3d 14 14 # filename ../data/vienna/viewcells-25-sel.x3d 15 #filename ../data/atlanta/atlanta2.x3d15 filename ../data/atlanta/atlanta2.x3d 16 16 # filename ../data/soda/soda.dat 17 filename ../data/soda/soda5.dat17 # filename ../data/soda/soda5.dat 18 18 } 19 19 … … 155 155 maxViewCells 100 156 156 157 PostProcess ing{157 PostProcess { 158 158 minPvsDif 100 159 159 minPvs 10 … … 240 240 241 241 # maximal tested rays for split cost heuristics 242 maxTests 1000 242 maxTests 10000 243 243 244 244 # factors for evaluating split plane costs … … 261 261 #maxAccRayLength 100 262 262 263 maxViewCells 1500 264 263 265 # used for pvs criterium 264 266 ct_div_ci 0.0 … … 283 285 exportRays true 284 286 exportGeometry false 287 } 288 289 PostProcess { 290 maxCostRatio 5000000 291 minViewCells 1000 292 maxPvsSize 50000 285 293 } 286 294 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
r473 r478 1187 1187 "bspTree"); 1188 1188 1189 RegisterOption("ViewCells.PostProcess ing.samples",1189 RegisterOption("ViewCells.PostProcess.samples", 1190 1190 optInt, 1191 "- bsp_postprocessing_samples=",1191 "-view_cells_postprocess_samples=", 1192 1192 "200000"); 1193 1193 … … 1207 1207 "0"); 1208 1208 1209 RegisterOption("ViewCells.PostProcess ing.minPvsDif",1209 RegisterOption("ViewCells.PostProcess.minPvsDif", 1210 1210 optInt, 1211 "-view_cells_post_process ing_min_pvs_dif",1211 "-view_cells_post_process_min_pvs_dif", 1212 1212 "10"); 1213 1213 1214 RegisterOption("ViewCells.PostProcess ing.maxPvs",1214 RegisterOption("ViewCells.PostProcess.maxPvs", 1215 1215 optInt, 1216 "-view_cells_post_process ing_max_pvs",1216 "-view_cells_post_process_max_pvs", 1217 1217 "300"); 1218 1218 1219 RegisterOption("ViewCells.PostProcess ing.minPvs",1219 RegisterOption("ViewCells.PostProcess.minPvs", 1220 1220 optString, 1221 "-view_cells_post_process ing_min_pvs",1221 "-view_cells_post_process_min_pvs", 1222 1222 "10"); 1223 1223 … … 1667 1667 "1.5"); 1668 1668 1669 RegisterOption("VspBspTree.Termination.maxViewCells", 1670 optInt, 1671 "-vsp_bsp_term_axis_aligned_max_view_cells=", 1672 "1000"); 1673 1669 1674 RegisterOption("VspBspTree.Termination.maxCostRatio", 1670 1675 optFloat, … … 1750 1755 RegisterOption("VspBspTree.Factor.pvs", optFloat, "-vsp_bsp_factor_pvs=", "1.0"); 1751 1756 1757 RegisterOption("VspBspTree.PostProcess.maxCostRatio", 1758 optFloat, 1759 "-vsp_bsp_post_process_max_cost_ratio=", 1760 "1.5"); 1761 1762 RegisterOption("VspBspTree.PostProcess.minViewCells", 1763 optInt, 1764 "vsp_bsp_term_post_process_min_view_cells=", 1765 "1000"); 1766 1767 RegisterOption("VspBspTree.PostProcess.maxPvsSize", 1768 optInt, 1769 "vsp_bsp_term_post_process_max_pvs_size=", 1770 "100"); 1771 1752 1772 ////////////////////////////////////////////////////////////////////////////////// 1753 1773 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
r475 r478 231 231 int visSamples = 0; 232 232 233 environment->GetIntValue("ViewCells.PostProcess ing.samples", postProcessSamples);233 environment->GetIntValue("ViewCells.PostProcess.samples", postProcessSamples); 234 234 environment->GetIntValue("ViewCells.Visualization.samples", visSamples); 235 235 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp
r469 r478 7 7 #include <iomanip> 8 8 9 ViewCell::ViewCell(): MeshInstance(NULL), mPiercingRays(0) 9 ViewCell::ViewCell(): 10 MeshInstance(NULL), 11 mPiercingRays(0), 12 mArea(0), 13 mVolume(0) 10 14 { 11 15 } 12 16 13 ViewCell::ViewCell(Mesh *mesh): MeshInstance(mesh), mPiercingRays(0) 17 ViewCell::ViewCell(Mesh *mesh): 18 MeshInstance(mesh), 19 mPiercingRays(0), 20 mArea(0), 21 mVolume(0) 14 22 { 15 23 } … … 35 43 } 36 44 45 37 46 float ViewCell::GetVolume() const 38 47 { … … 40 49 } 41 50 51 42 52 void ViewCell::SetVolume(float volume) 43 53 { 44 54 mVolume = volume; 45 55 } 56 57 58 float ViewCell::GetArea() const 59 { 60 return mArea; 61 } 62 63 64 void ViewCell::SetArea(float area) 65 { 66 mArea = area; 67 } 68 46 69 47 70 /************************************************************************/ -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h
r471 r478 45 45 /** Returns volume of the view cell. 46 46 */ 47 virtualfloat GetVolume() const;47 float GetVolume() const; 48 48 49 /** Sets volumeof the view cell.49 /** Returns area of the view cell. 50 50 */ 51 void SetVolume(float size); 51 float GetArea() const; 52 53 /** Sets the volume of the view cell. 54 */ 55 void SetVolume(float volume); 56 57 /** Sets the area of the view cell. 58 */ 59 void SetArea(float area); 52 60 53 61 /// Ray set description of the rays passing through this node. … … 63 71 64 72 float mVolume; 73 float mArea; 65 74 }; 66 75 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r475 r478 1148 1148 if (!data.mPolygons->empty()) 1149 1149 { 1150 Polygon3 *nextPoly = (*data.mPolygons)[(int)RandomValue(0, (int)data.mPolygons->size() - 1)]; 1150 Polygon3 *nextPoly = 1151 (*data.mPolygons)[(int)RandomValue(0, (Real)((int)data.mPolygons->size() - 1))]; 1151 1152 return nextPoly->GetSupportingPlane(); 1152 1153 } … … 1175 1176 } 1176 1177 1178 1179 Plane3 BspTree::ChooseCandidatePlane(const BoundedRayContainer &rays) const 1180 { return Plane3(); 1181 /*const int candidateIdx = (int)RandomValue(0, (Real)((int)rays.size() - 1)); 1182 1183 const Vector3 minPt = rays[candidateIdx].ExtrapOrigin(); 1184 const Vector3 maxPt = rays[candidateIdx].ExtrapTermination(); 1185 1186 const Vector3 pt = (maxPt + minPt) * 0.5; 1187 const Vector3 normal = Normalize(rays[candidateIdx].mRay->GetDir()); 1188 1189 return Plane3(normal, pt);*/ 1190 } 1191 1192 Plane3 BspTree::ChooseCandidatePlane2(const BoundedRayContainer &rays) const 1193 { return Plane3(); 1194 /*Vector3 pt[3]; 1195 1196 int idx[3]; 1197 int cmaxT = 0; 1198 int cminT = 0; 1199 bool chooseMin = false; 1200 1201 for (int j = 0; j < 3; ++ j) 1202 { 1203 idx[j] = (int)RandomValue(0, (Real)((int)rays.size() * 2 - 1)); 1204 1205 if (idx[j] >= (int)rays.size()) 1206 { 1207 idx[j] -= (int)rays.size(); 1208 1209 chooseMin = (cminT < 2); 1210 } 1211 else 1212 chooseMin = (cmaxT < 2); 1213 1214 RayInfo rayInf = rays[idx[j]]; 1215 pt[j] = chooseMin ? rayInf.ExtrapOrigin() : rayInf.ExtrapTermination(); 1216 } 1217 1218 return Plane3(pt[0], pt[1], pt[2]);*/ 1219 } 1220 1221 Plane3 BspTree::ChooseCandidatePlane3(const BoundedRayContainer &rays) const 1222 { return Plane3();/* 1223 Vector3 pt[3]; 1224 1225 int idx1 = (int)RandomValue(0, (Real)((int)rays.size() - 1)); 1226 int idx2 = (int)RandomValue(0, (Real)((int)rays.size() - 1)); 1227 1228 // check if rays different 1229 if (idx1 == idx2) 1230 idx2 = (idx2 + 1) % (int)rays.size(); 1231 1232 const RayInfo ray1 = rays[idx1]; 1233 const RayInfo ray2 = rays[idx2]; 1234 1235 // normal vector of the plane parallel to both lines 1236 const Vector3 norm = Normalize(CrossProd(ray1.mRay->GetDir(), ray2.mRay->GetDir())); 1237 1238 // vector from line 1 to line 2 1239 const Vector3 vd = (ray2.ExtrapOrigin() - ray1.ExtrapOrigin()); 1240 1241 // project vector on normal to get distance 1242 const float dist = DotProd(vd, norm); 1243 1244 // point on plane lies halfway between the two planes 1245 const Vector3 planePt = ray1.ExtrapOrigin() + norm * dist * 0.5; 1246 1247 return Plane3(norm, planePt);*/ 1248 } 1249 1250 1177 1251 Plane3 BspTree::SelectPlaneHeuristics(BspLeaf *leaf, BspTraversalData &data) 1178 1252 { 1179 1253 float lowestCost = MAX_FLOAT; 1180 1254 Plane3 bestPlane; 1255 // intermediate plane 1181 1256 Plane3 plane; 1182 1257 1183 int limit = Min((int)data.mPolygons->size(), mMaxPolyCandidates); 1184 1185 int candidateIdx = limit - 1; 1186 1258 const int limit = Min((int)data.mPolygons->size(), mMaxPolyCandidates); 1259 int maxIdx = (int)data.mPolygons->size(); 1260 1187 1261 for (int i = 0; i < limit; ++ i) 1188 1262 { 1189 candidateIdx = GetNextCandidateIdx(candidateIdx, *data.mPolygons); 1263 // assure that no index is taken twice 1264 const int candidateIdx = (int)RandomValue(0, (Real)(-- maxIdx)); 1265 //Debug << "current Idx: " << maxIdx << " cand idx " << candidateIdx << endl; 1190 1266 1191 1267 Polygon3 *poly = (*data.mPolygons)[candidateIdx]; 1268 1269 // swap candidate to the end to avoid testing same plane 1270 std::swap((*data.mPolygons)[maxIdx], (*data.mPolygons)[candidateIdx]); 1271 1272 //Polygon3 *poly = (*data.mPolygons)[(int)RandomValue(0, (int)polys.size() - 1)]; 1273 1192 1274 // evaluate current candidate 1193 1275 const float candidateCost = … … 1201 1283 } 1202 1284 1203 //Debug << "lowest: " << lowestCost << endl;1204 1205 1285 //-- choose candidate planes extracted from rays 1206 // we currently use two methods 1207 // 1) take 3 ray endpoints, where two are minimum and one a maximum 1208 // point or the other way round 1209 // 2) take plane normal as plane normal and the midpoint of the ray. 1210 // PROBLEM: does not resemble any point where visibility is likely to change 1211 const BoundedRayContainer *rays = data.mRays; 1212 1213 for (int i = 0; i < mMaxRayCandidates / 2; ++ i) 1214 { 1215 candidateIdx = (int)RandomValue(0, (int)rays->size() - 1); 1216 BoundedRay *bRay = (*rays)[candidateIdx]; 1217 1218 Ray *ray = bRay->mRay; 1219 1220 const Vector3 minPt = ray->Extrap(bRay->mMinT); 1221 const Vector3 maxPt = ray->Extrap(bRay->mMaxT); 1222 1223 const Vector3 pt = (maxPt + minPt) * 0.5; 1224 1225 const Vector3 normal = ray->GetDir(); 1226 1227 plane = Plane3(normal, pt); 1228 1286 //-- different methods are available 1287 for (int i = 0; i < mMaxRayCandidates; ++ i) 1288 { 1289 plane = ChooseCandidatePlane3(*data.mRays); 1229 1290 const float candidateCost = SplitPlaneCost(plane, data); 1230 1291 1231 1292 if (candidateCost < lowestCost) 1232 1293 { 1233 bestPlane = plane; 1234 1294 bestPlane = plane; 1235 1295 lowestCost = candidateCost; 1236 1296 } 1237 1297 } 1238 1239 //Debug << "lowest: " << lowestCost << endl;1240 for (int i = 0; i < mMaxRayCandidates / 2; ++ i)1241 {1242 Vector3 pt[3];1243 int idx[3];1244 int cmaxT = 0;1245 int cminT = 0;1246 bool chooseMin = false;1247 1248 for (int j = 0; j < 3; j ++)1249 {1250 idx[j] = (int)RandomValue(0, (int)rays->size() * 2 - 1);1251 1252 if (idx[j] >= (int)rays->size())1253 {1254 idx[j] -= (int)rays->size();1255 1256 chooseMin = (cminT < 2);1257 }1258 else1259 chooseMin = (cmaxT < 2);1260 1261 BoundedRay *bRay = (*rays)[idx[j]];1262 pt[j] = chooseMin ? bRay->mRay->Extrap(bRay->mMinT) :1263 bRay->mRay->Extrap(bRay->mMaxT);1264 }1265 1266 plane = Plane3(pt[0], pt[1], pt[2]);1267 1268 const float candidateCost = SplitPlaneCost(plane, data);1269 1270 if (candidateCost < lowestCost)1271 {1272 //Debug << "choose ray plane 2: " << candidateCost << endl;1273 bestPlane = plane;1274 1275 lowestCost = candidateCost;1276 }1277 }1278 1298 1279 1299 #ifdef _DEBUG 1280 1300 Debug << "plane lowest cost: " << lowestCost << endl; 1281 1301 #endif 1302 1282 1303 return bestPlane; 1283 1304 } 1284 1305 1285 int BspTree::GetNextCandidateIdx(int currentIdx, PolygonContainer &polys)1286 {1287 const int candidateIdx = (int)RandomValue(0, currentIdx --);1288 1289 // swap candidates to avoid testing same plane 2 times1290 std::swap(polys[currentIdx], polys[candidateIdx]);1291 1292 return currentIdx;1293 //return (int)RandomValue(0, (int)polys.size() - 1);1294 }1295 1306 1296 1307 float BspTree::SplitPlaneCost(const Plane3 &candidatePlane, … … 1331 1342 limit = (int)polys.size(); 1332 1343 } 1333 1334 1344 1335 1345 for (int i = 0; i < limit; ++ i) 1336 1346 { 1337 const int testIdx = useRand ? (int)RandomValue(0, limit - 1) : i;1347 const int testIdx = useRand ? (int)RandomValue(0, (Real)(limit - 1)) : i; 1338 1348 1339 1349 Polygon3 *poly = polys[testIdx]; -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r475 r478 586 586 PolygonContainer *backPolys); 587 587 588 /** Take 3 ray endpoints, where two are minimum and one a maximum 589 point or the other way round. 590 */ 591 Plane3 ChooseCandidatePlane(const BoundedRayContainer &rays) const; 592 593 /** Take plane normal as plane normal and the midpoint of the ray. 594 PROBLEM: does not resemble any point where visibility is likely to change 595 */ 596 Plane3 ChooseCandidatePlane2(const BoundedRayContainer &rays) const; 597 598 /** Fit the plane between the two lines so that the plane has equal shortest 599 distance to both lines. 600 */ 601 Plane3 ChooseCandidatePlane3(const BoundedRayContainer &rays) const; 602 588 603 /** Selects the split plane in order to construct a tree with 589 604 certain characteristics (e.g., balanced tree, least splits, … … 619 634 */ 620 635 int AddMeshToPolygons(Mesh *mesh, PolygonContainer &polys, MeshInstance *parent); 621 622 /** returns next candidate index and reorders polygons so no candidate is chosen two times623 @param the current candidate index624 @param max the range of candidates625 */626 int GetNextCandidateIdx(int currentIdx, PolygonContainer &polys);627 636 628 637 /** Helper function which extracts a view cell on the front and the back -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
r477 r478 22 22 { 23 23 // post processing stuff 24 environment->GetIntValue("ViewCells.PostProcess ing.minPvsDif", mMinPvsDif);25 environment->GetIntValue("ViewCells.PostProcess ing.minPvs", mMinPvs);26 environment->GetIntValue("ViewCells.PostProcess ing.maxPvs", mMaxPvs);24 environment->GetIntValue("ViewCells.PostProcess.minPvsDif", mMinPvsDif); 25 environment->GetIntValue("ViewCells.PostProcess.minPvs", mMinPvs); 26 environment->GetIntValue("ViewCells.PostProcess.maxPvs", mMaxPvs); 27 27 } 28 28 … … 34 34 { 35 35 // post processing stuff 36 environment->GetIntValue("ViewCells.PostProcess ing.minPvsDif", mMinPvsDif);37 environment->GetIntValue("ViewCells.PostProcess ing.minPvs", mMinPvs);38 environment->GetIntValue("ViewCells.PostProcess ing.maxPvs", mMaxPvs);36 environment->GetIntValue("ViewCells.PostProcess.minPvsDif", mMinPvsDif); 37 environment->GetIntValue("ViewCells.PostProcess.minPvs", mMinPvs); 38 environment->GetIntValue("ViewCells.PostProcess.maxPvs", mMaxPvs); 39 39 } 40 40 … … 75 75 { 76 76 mViewCells.push_back(viewCell); 77 } 78 79 float ViewCellsManager::GetArea(ViewCell *viewCell) const 80 { 81 return viewCell->GetArea(); 82 } 83 84 85 float ViewCellsManager::GetVolume(ViewCell *viewCell) const 86 { 87 return viewCell->GetVolume(); 77 88 } 78 89 … … 282 293 283 294 284 float ViewCellsManager::GetVolume(ViewCell *viewCell) const285 {286 return viewCell->GetVolume();287 }288 289 290 float ViewCellsManager::GetArea(ViewCell *viewCell) const291 {292 return 0.0f;293 }294 295 296 295 float ViewCellsManager::GetAccVcArea() 297 296 { … … 390 389 391 390 return sampleContributions; 392 }393 394 float BspViewCellsManager::GetArea(ViewCell *viewCell) const395 {396 PolygonContainer geom;397 398 // compute view cell area399 mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(viewCell), geom);400 401 const float area = Polygon3::GetArea(geom);402 CLEAR_CONTAINER(geom);403 404 return area;405 391 } 406 392 … … 656 642 //-- some rays for output 657 643 const int raysOut = min((int)mBspRays.size(), mVisualizationSamples); 644 658 645 cout << "visualization using " << mVisualizationSamples << " samples" << endl; 659 646 Debug << "\nOutput view cells: " << endl; 660 661 if (1) 662 { 663 //-- some random view cells and rays for output 664 vector<BspLeaf *> vspBspLeaves; 665 666 for (int i = 0; i < leafOut; ++ i) 667 vspBspLeaves.push_back(mBspTree->GetRandomLeaf()); 668 669 for (int i = 0; i < (int)vspBspLeaves.size(); ++ i) 670 { 671 VssRayContainer vcRays; 672 cout << "creating output for view cell " << i << " ... "; 673 674 // check whether we can add the current ray to the output rays 675 for (int k = 0; k < raysOut; ++ k) 647 648 // sort view cells to get largest view cells 649 #if 0 650 stable_sort(mViewCells.begin(), mViewCells.end(), vc_gt); 651 #endif 652 int limit = min(leafOut, (int)mViewCells.size()); 653 654 for (int i = 0; i < limit; ++ i) 655 { 656 cout << "creating output for view cell " << i << " ... "; 657 VssRayContainer vcRays; 658 Intersectable::NewMail(); 659 #if 0 660 BspViewCell *vc = dynamic_cast<BspViewCell *>(mViewCells[i]); 661 #else 662 BspViewCell *vc = dynamic_cast<BspViewCell *>(mViewCells[Random((int)mViewCells.size())]); 663 #endif 664 cout << "creating output for view cell " << i << " ... "; 665 666 #if 0 667 // check whether we can add the current ray to the output rays 668 for (int k = 0; k < raysOut; ++ k) 669 { 670 BspRay *ray = mBspRays[k]; 671 for (int j = 0; j < (int)ray->intersections.size(); ++ j) 676 672 { 677 BspRay *ray = mBspRays[k]; 678 679 for (int j = 0; j < (int)ray->intersections.size(); ++ j) 680 { 681 BspLeaf *leaf = ray->intersections[j].mLeaf; 682 683 if (vspBspLeaves[i]->GetViewCell() == leaf->GetViewCell()) 684 { 685 vcRays.push_back(ray->vssRay); 686 } 687 } 673 BspLeaf *leaf = ray->intersections[j].mLeaf; 674 if (vc == leaf->GetViewCell()) 675 vcRays.push_back(ray->vssRay); 688 676 } 689 690 Intersectable::NewMail(); 691 692 BspViewCell *vc = dynamic_cast<BspViewCell *> 693 (vspBspLeaves[i]->GetViewCell()); 694 695 //bspLeaves[j]->Mail(); 696 char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 697 698 Exporter *exporter = Exporter::GetExporter(s); 699 exporter->SetFilled(); 700 701 ObjectPvsMap::iterator it = vc->GetPvs().mEntries.begin(); 702 703 exporter->SetWireframe(); 704 //exporter->SetFilled(); 705 706 Material m;//= RandomMaterial(); 707 m.mDiffuseColor = RgbColor(0, 1, 0); 708 exporter->SetForcedMaterial(m); 709 710 if (vc->GetMesh()) 711 exporter->ExportViewCell(vc); 712 else 677 } 678 #endif 679 //bspLeaves[j]->Mail(); 680 char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 681 682 Exporter *exporter = Exporter::GetExporter(s); 683 684 exporter->SetWireframe(); 685 686 Material m;//= RandomMaterial(); 687 m.mDiffuseColor = RgbColor(0, 1, 0); 688 exporter->SetForcedMaterial(m); 689 690 if (vc->GetMesh()) 691 exporter->ExportViewCell(vc); 692 else 693 { 694 PolygonContainer vcGeom; 695 696 //-- export view cell 697 mBspTree->ConstructGeometry(vc, vcGeom); 698 exporter->ExportPolygons(vcGeom); 699 CLEAR_CONTAINER(vcGeom); 700 } 701 702 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() 703 << ", piercing rays=" << (int)vcRays.size() << endl; 704 705 706 // export rays piercing this view cell 707 #if 0 708 exporter->ExportRays(vcRays, RgbColor(0, 1, 0)); 709 #else 710 vector<BspLeaf *>::const_iterator lit, lit_end = vc->mLeaves.end(); 711 for (lit = vc->mLeaves.begin(); lit != lit_end; ++ lit) 712 exporter->ExportRays((*lit)->mVssRays); 713 #endif 714 m.mDiffuseColor = RgbColor(1, 0, 0); 715 exporter->SetForcedMaterial(m); 716 717 ObjectPvsMap::const_iterator it, 718 it_end = vc->GetPvs().mEntries.end(); 719 720 exporter->SetFilled(); 721 722 // output PVS of view cell 723 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 724 { 725 Intersectable *intersect = (*it).first; 726 727 if (!intersect->Mailed()) 713 728 { 714 PolygonContainer vcGeom; 715 716 // export view cell geometry 717 mBspTree->ConstructGeometry(vc, vcGeom); 718 exporter->ExportPolygons(vcGeom); 719 CLEAR_CONTAINER(vcGeom); 720 } 721 722 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() 723 << ", piercing rays=" << (int)vcRays.size() << endl; 724 725 // export rays piercing this view cell 726 if (exportRays) 727 { 728 //exporter->ExportRays(vcRays, RgbColor(1, 0, 0)); 729 exporter->ExportRays(vspBspLeaves[i]->mVssRays, RgbColor(1, 1, 1)); 730 } 731 732 m.mDiffuseColor = RgbColor(0, 1, 1); 733 exporter->SetForcedMaterial(m); 734 735 //exporter->SetWireframe(); 736 exporter->SetFilled(); 737 738 // output PVS of view cell 739 for (; it != vc->GetPvs().mEntries.end(); ++ it) 740 { 741 Intersectable *intersect = (*it).first; 742 if (!intersect->Mailed()) 743 { 744 exporter->ExportIntersectable(intersect); 745 intersect->Mail(); 746 } 747 } 748 Debug << "here1 exportgeom: " << exportGeometry << endl; 749 // output rest of the objects 750 if (exportGeometry) 751 { 752 Material m;//= RandomMaterial(); 753 m.mDiffuseColor = RgbColor(0, 0, 1); 729 Material m = RandomMaterial(); 754 730 exporter->SetForcedMaterial(m); 755 731 756 for (int j = 0; j < objects.size(); ++ j) 757 if (!objects[j]->Mailed()) 758 { 759 exporter->SetForcedMaterial(m); 760 exporter->ExportIntersectable(objects[j]); 761 objects[j]->Mail(); 762 } 763 } 764 DEL_PTR(exporter); 765 cout << "finished" << endl; 766 } 767 } 768 else 769 { 770 ViewCellContainer viewCells; 771 772 mBspTree->CollectViewCells(viewCells); 773 stable_sort(viewCells.begin(), viewCells.end(), vc_gt); 774 775 int limit = min(leafOut, (int)viewCells.size()); 776 777 for (int i = 0; i < limit; ++ i) 778 { 779 cout << "creating output for view cell " << i << " ... "; 780 VssRayContainer vcRays; 781 Intersectable::NewMail(); 782 BspViewCell *vc = dynamic_cast<BspViewCell *>(viewCells[i]); 783 784 cout << "creating output for view cell " << i << " ... "; 785 786 // check whether we can add the current ray to the output rays 787 for (int k = 0; k < raysOut; ++ k) 788 { 789 BspRay *ray = mBspRays[k]; 790 791 for (int j = 0; j < (int)ray->intersections.size(); ++ j) 792 { 793 BspLeaf *leaf = ray->intersections[j].mLeaf; 794 795 if (vc == leaf->GetViewCell()) 796 { 797 vcRays.push_back(ray->vssRay); 798 } 799 } 800 } 801 802 //bspLeaves[j]->Mail(); 803 char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 804 805 Exporter *exporter = Exporter::GetExporter(s); 806 807 exporter->SetWireframe(); 808 809 Material m;//= RandomMaterial(); 810 m.mDiffuseColor = RgbColor(0, 1, 0); 811 exporter->SetForcedMaterial(m); 812 813 if (vc->GetMesh()) 814 exporter->ExportViewCell(vc); 815 else 816 { 817 PolygonContainer vcGeom; 818 // export view cell 819 mBspTree->ConstructGeometry(vc, vcGeom); 820 exporter->ExportPolygons(vcGeom); 821 CLEAR_CONTAINER(vcGeom); 822 } 823 824 825 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() 826 << ", piercing rays=" << (int)vcRays.size() << endl; 827 828 829 // export rays piercing this view cell 830 exporter->ExportRays(vcRays, RgbColor(0, 1, 0)); 831 832 m.mDiffuseColor = RgbColor(1, 0, 0); 833 exporter->SetForcedMaterial(m); 834 835 ObjectPvsMap::const_iterator it, 836 it_end = vc->GetPvs().mEntries.end(); 837 838 // output PVS of view cell 839 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 840 { 841 Intersectable *intersect = (*it).first; 842 843 if (!intersect->Mailed()) 844 { 845 Material m = RandomMaterial(); 846 847 exporter->SetForcedMaterial(m); 848 849 exporter->ExportIntersectable(intersect); 850 intersect->Mail(); 851 } 852 } 732 exporter->ExportIntersectable(intersect); 733 intersect->Mail(); 734 } 735 } 853 736 854 DEL_PTR(exporter); 855 cout << "finished" << endl; 856 } 737 DEL_PTR(exporter); 738 cout << "finished" << endl; 857 739 } 858 740 … … 864 746 { 865 747 BspViewCell *viewCell = 866 dynamic_cast<BspViewCell *>(MergeViewCells(*front->GetViewCell(), *back->GetViewCell())); 748 dynamic_cast<BspViewCell *>(MergeViewCells(*front->GetViewCell(), 749 *back->GetViewCell())); 867 750 868 751 if (!viewCell) … … 1207 1090 1208 1091 1209 1210 1092 /**********************************************************************/ 1211 1093 /* VspKdViewCellsManager implementation */ … … 1436 1318 mVspBspTree(vspBspTree) 1437 1319 { 1320 mVspBspTree->SetViewCellsManager(this); 1438 1321 } 1439 1322 … … 1468 1351 } 1469 1352 1470 1471 1353 float VspBspViewCellsManager::GetRendercost(ViewCell *viewCell, 1472 1354 float objRendercost) const … … 1511 1393 mVspBspTree->CollectViewCells(mViewCells); 1512 1394 mVspBspTree->EvaluateViewCellsStats(mViewCellsStats); 1513 1395 1514 1396 Debug << mVspBspTree->GetStatistics() << endl; 1515 1397 … … 1551 1433 const VssRayContainer &rays) 1552 1434 { 1435 if (!ViewCellsConstructed()) 1436 { 1437 Debug << "view cells not constructed" << endl; 1438 return 0; 1439 } 1440 1553 1441 if (mBspRays.empty()) 1554 1442 ConstructBspRays(rays, mConstructionSamples); 1555 1556 if (!ViewCellsConstructed())1557 {1558 Debug << "view cells not constructed" << endl;1559 return 0;1560 }1561 1443 1562 1444 //-- post processing of bsp view cells … … 1575 1457 //exporter->SetWireframe(); 1576 1458 exporter->SetFilled(); 1577 exporter->ExportBspViewCellPartition(*mVspBspTree, mViewCellsStats.maxPvs); 1578 1459 //exporter->ExportBspViewCellPartition(*mVspBspTree, mViewCellsStats.maxPvs); 1460 exporter->ExportBspViewCellPartition(*mVspBspTree); 1461 1579 1462 if (0) 1580 1463 { … … 1605 1488 vector<BspIntersection>::const_iterator iit; 1606 1489 1490 if (0) 1607 1491 for (int i = 0; i < (int)mBspRays.size(); ++ i) 1608 1492 { … … 1633 1517 } 1634 1518 } 1519 else 1520 { 1521 merged = mVspBspTree->MergeLeaves(); 1522 } 1635 1523 1636 1524 //-- stats and visualizations … … 1668 1556 if (1) // export view cells 1669 1557 { 1670 cout << "exporting view cells after merge... ";1558 cout << "exporting view cells after post process ... "; 1671 1559 Exporter *exporter = Exporter::GetExporter("merged_view_cells.x3d"); 1672 1560 1673 1561 if (exporter) 1674 1562 { 1675 exporter->ExportBspViewCellPartition(*mVspBspTree, mViewCellsStats.maxPvs); 1563 //exporter->ExportBspViewCellPartition(*mVspBspTree, mViewCellsStats.maxPvs); 1564 exporter->ExportBspViewCellPartition(*mVspBspTree); 1676 1565 delete exporter; 1677 1566 } … … 1751 1640 //-- some rays for output 1752 1641 const int raysOut = min((int)mBspRays.size(), mVisualizationSamples); 1642 1753 1643 cout << "visualization using " << mVisualizationSamples << " samples" << endl; 1754 1644 Debug << "\nOutput view cells: " << endl; 1755 1756 if (1) 1757 { 1758 //-- some random view cells and rays for output 1759 vector<BspLeaf *> vspBspLeaves; 1760 1761 for (int i = 0; i < leafOut; ++ i) 1762 vspBspLeaves.push_back(mVspBspTree->GetRandomLeaf()); 1763 1764 for (int i = 0; i < (int)vspBspLeaves.size(); ++ i) 1765 { 1766 VssRayContainer vcRays; 1767 cout << "creating output for view cell " << i << " ... "; 1768 1769 // check whether we can add the current ray to the output rays 1770 for (int k = 0; k < raysOut; ++ k) 1645 1646 // sort view cells to get largest view cells 1647 #if 0 1648 stable_sort(mViewCells.begin(), mViewCells.end(), vc_gt); 1649 #endif 1650 int limit = min(leafOut, (int)mViewCells.size()); 1651 1652 for (int i = 0; i < limit; ++ i) 1653 { 1654 cout << "creating output for view cell " << i << " ... "; 1655 VssRayContainer vcRays; 1656 Intersectable::NewMail(); 1657 #if 0 1658 BspViewCell *vc = dynamic_cast<BspViewCell *>(mViewCells[i]); 1659 #else 1660 BspViewCell *vc = dynamic_cast<BspViewCell *>(mViewCells[Random((int)mViewCells.size())]); 1661 #endif 1662 cout << "creating output for view cell " << i << " ... "; 1663 1664 #if 0 1665 // check whether we can add the current ray to the output rays 1666 for (int k = 0; k < raysOut; ++ k) 1667 { 1668 BspRay *ray = mBspRays[k]; 1669 for (int j = 0; j < (int)ray->intersections.size(); ++ j) 1771 1670 { 1772 BspRay *ray = mBspRays[k]; 1773 1774 for (int j = 0; j < (int)ray->intersections.size(); ++ j) 1775 { 1776 BspLeaf *leaf = ray->intersections[j].mLeaf; 1777 1778 if (vspBspLeaves[i]->GetViewCell() == leaf->GetViewCell()) 1779 { 1780 vcRays.push_back(ray->vssRay); 1781 } 1782 } 1671 BspLeaf *leaf = ray->intersections[j].mLeaf; 1672 if (vc == leaf->GetViewCell()) 1673 vcRays.push_back(ray->vssRay); 1783 1674 } 1784 1785 Intersectable::NewMail(); 1786 1787 BspViewCell *vc = dynamic_cast<BspViewCell *> 1788 (vspBspLeaves[i]->GetViewCell()); 1789 1790 //bspLeaves[j]->Mail(); 1791 char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 1792 1793 Exporter *exporter = Exporter::GetExporter(s); 1794 exporter->SetFilled(); 1795 1796 ObjectPvsMap::iterator it = vc->GetPvs().mEntries.begin(); 1797 1798 exporter->SetWireframe(); 1799 //exporter->SetFilled(); 1800 1801 Material m;//= RandomMaterial(); 1802 m.mDiffuseColor = RgbColor(0, 1, 0); 1803 exporter->SetForcedMaterial(m); 1804 1805 if (vc->GetMesh()) 1806 exporter->ExportViewCell(vc); 1807 else 1675 } 1676 #endif 1677 //bspLeaves[j]->Mail(); 1678 char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 1679 1680 Exporter *exporter = Exporter::GetExporter(s); 1681 1682 exporter->SetWireframe(); 1683 1684 Material m;//= RandomMaterial(); 1685 m.mDiffuseColor = RgbColor(0, 1, 0); 1686 exporter->SetForcedMaterial(m); 1687 1688 if (vc->GetMesh()) 1689 exporter->ExportViewCell(vc); 1690 else 1691 { 1692 PolygonContainer vcGeom; 1693 // export view cell 1694 mVspBspTree->ConstructGeometry(vc, vcGeom); 1695 exporter->ExportPolygons(vcGeom); 1696 CLEAR_CONTAINER(vcGeom); 1697 } 1698 1699 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() 1700 << ", piercing rays=" << (int)vcRays.size() << endl; 1701 1702 1703 // export rays piercing this view cell 1704 #if 0 1705 exporter->ExportRays(vcRays, RgbColor(0, 1, 0)); 1706 #else 1707 vector<BspLeaf *>::const_iterator lit, lit_end = vc->mLeaves.end(); 1708 for (lit = vc->mLeaves.begin(); lit != lit_end; ++ lit) 1709 exporter->ExportRays((*lit)->mVssRays); 1710 #endif 1711 m.mDiffuseColor = RgbColor(1, 0, 0); 1712 exporter->SetForcedMaterial(m); 1713 1714 ObjectPvsMap::const_iterator it, 1715 it_end = vc->GetPvs().mEntries.end(); 1716 1717 exporter->SetFilled(); 1718 1719 // output PVS of view cell 1720 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 1721 { 1722 Intersectable *intersect = (*it).first; 1723 1724 if (!intersect->Mailed()) 1808 1725 { 1809 PolygonContainer vcGeom; 1810 1811 // export view cell geometry 1812 mVspBspTree->ConstructGeometry(vc, vcGeom); 1813 exporter->ExportPolygons(vcGeom); 1814 CLEAR_CONTAINER(vcGeom); 1815 } 1816 1817 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() 1818 << ", piercing rays=" << (int)vcRays.size() << endl; 1819 1820 // export rays piercing this view cell 1821 if (exportRays) 1822 { 1823 //exporter->ExportRays(vcRays, RgbColor(1, 0, 0)); 1824 exporter->ExportRays(vspBspLeaves[i]->mVssRays, RgbColor(1, 1, 1)); 1825 } 1826 1827 m.mDiffuseColor = RgbColor(0, 1, 1); 1828 exporter->SetForcedMaterial(m); 1829 1830 //exporter->SetWireframe(); 1831 exporter->SetFilled(); 1832 1833 // output PVS of view cell 1834 for (; it != vc->GetPvs().mEntries.end(); ++ it) 1835 { 1836 Intersectable *intersect = (*it).first; 1837 if (!intersect->Mailed()) 1838 { 1839 exporter->ExportIntersectable(intersect); 1840 intersect->Mail(); 1841 } 1842 } 1843 Debug << "here1 exportgeom: " << exportGeometry << endl; 1844 // output rest of the objects 1845 if (exportGeometry) 1846 { 1847 Material m;//= RandomMaterial(); 1848 m.mDiffuseColor = RgbColor(0, 0, 1); 1726 Material m = RandomMaterial(); 1849 1727 exporter->SetForcedMaterial(m); 1850 1728 1851 for (int j = 0; j < objects.size(); ++ j) 1852 if (!objects[j]->Mailed()) 1853 { 1854 exporter->SetForcedMaterial(m); 1855 exporter->ExportIntersectable(objects[j]); 1856 objects[j]->Mail(); 1857 } 1858 } 1859 DEL_PTR(exporter); 1860 cout << "finished" << endl; 1861 } 1862 } 1863 else 1864 { 1865 ViewCellContainer viewCells; 1866 1867 mVspBspTree->CollectViewCells(viewCells); 1868 stable_sort(viewCells.begin(), viewCells.end(), vc_gt); 1869 1870 int limit = min(leafOut, (int)viewCells.size()); 1871 1872 for (int i = 0; i < limit; ++ i) 1873 { 1874 cout << "creating output for view cell " << i << " ... "; 1875 VssRayContainer vcRays; 1876 Intersectable::NewMail(); 1877 BspViewCell *vc = dynamic_cast<BspViewCell *>(viewCells[i]); 1878 1879 cout << "creating output for view cell " << i << " ... "; 1880 1881 // check whether we can add the current ray to the output rays 1882 for (int k = 0; k < raysOut; ++ k) 1883 { 1884 BspRay *ray = mBspRays[k]; 1885 1886 for (int j = 0; j < (int)ray->intersections.size(); ++ j) 1887 { 1888 BspLeaf *leaf = ray->intersections[j].mLeaf; 1889 1890 if (vc == leaf->GetViewCell()) 1891 { 1892 vcRays.push_back(ray->vssRay); 1893 } 1894 } 1895 } 1896 1897 //bspLeaves[j]->Mail(); 1898 char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 1899 1900 Exporter *exporter = Exporter::GetExporter(s); 1901 1902 exporter->SetWireframe(); 1903 1904 Material m;//= RandomMaterial(); 1905 m.mDiffuseColor = RgbColor(0, 1, 0); 1906 exporter->SetForcedMaterial(m); 1907 1908 if (vc->GetMesh()) 1909 exporter->ExportViewCell(vc); 1910 else 1911 { 1912 PolygonContainer vcGeom; 1913 // export view cell 1914 mVspBspTree->ConstructGeometry(vc, vcGeom); 1915 exporter->ExportPolygons(vcGeom); 1916 CLEAR_CONTAINER(vcGeom); 1917 } 1918 1919 1920 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() 1921 << ", piercing rays=" << (int)vcRays.size() << endl; 1922 1923 1924 // export rays piercing this view cell 1925 exporter->ExportRays(vcRays, RgbColor(0, 1, 0)); 1926 1927 m.mDiffuseColor = RgbColor(1, 0, 0); 1928 exporter->SetForcedMaterial(m); 1929 1930 ObjectPvsMap::const_iterator it, 1931 it_end = vc->GetPvs().mEntries.end(); 1932 1933 // output PVS of view cell 1934 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 1935 { 1936 Intersectable *intersect = (*it).first; 1937 1938 if (!intersect->Mailed()) 1939 { 1940 Material m = RandomMaterial(); 1941 1942 exporter->SetForcedMaterial(m); 1943 1944 exporter->ExportIntersectable(intersect); 1945 intersect->Mail(); 1946 } 1947 } 1729 exporter->ExportIntersectable(intersect); 1730 intersect->Mail(); 1731 } 1732 } 1948 1733 1949 DEL_PTR(exporter); 1950 cout << "finished" << endl; 1951 } 1734 DEL_PTR(exporter); 1735 cout << "finished" << endl; 1952 1736 } 1953 1737 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h
r477 r478 198 198 /** Returns area of one view cell. 199 199 */ 200 float GetArea(ViewCell *viewCell) const;200 virtual float GetArea(ViewCell *viewCell) const; 201 201 202 202 /** Returns volume of view cells. 203 203 */ 204 float GetVolume(ViewCell *viewCell) const;204 virtual float GetVolume(ViewCell *viewCell) const; 205 205 206 206 virtual AxisAlignedBox3 GetSceneBbox() const = 0; … … 273 273 float GetRendercost(ViewCell *viewCell, float objRendercost) const; 274 274 275 float GetArea(ViewCell *viewCell) const;276 277 275 AxisAlignedBox3 GetSceneBbox() const; 278 276 … … 320 318 AxisAlignedBox3 *sceneBbox); 321 319 322 int CastLineSegment(const Vector3 &origin, 323 const Vector3 &termination, 324 ViewCellContainer &viewcells 325 ) ; 320 int CastLineSegment(const Vector3 &origin, 321 const Vector3 &termination, 322 ViewCellContainer &viewcells); 326 323 327 324 int PostProcess(const ObjectContainer &objects, -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
r475 r478 1 #include <stack> 2 #include <time.h> 3 #include <iomanip> 4 1 5 #include "Plane3.h" 2 6 #include "VspBspTree.h" … … 8 12 #include "Ray.h" 9 13 #include "AxisAlignedBox3.h" 10 #include <stack>11 #include <time.h>12 #include <iomanip>13 14 #include "Exporter.h" 14 15 #include "Plane3.h" 15 16 #include "ViewCellBsp.h" 17 #include "ViewCellsManager.h" 18 16 19 17 20 //-- static members … … 30 33 int VspBspTree::sFrontAndBackId = 0; 31 34 35 float BspMergeCandidate::sOverallCost = Limits::Small; 32 36 33 37 /****************************************************************/ … … 38 42 mRoot(NULL), 39 43 mPvsUseArea(true), 40 mCostNormalizer(Limits::Small) 44 mCostNormalizer(Limits::Small), 45 mViewCellsManager(NULL), 46 mStoreRays(true) 41 47 { 42 48 mRootCell = new BspViewCell(); … … 75 81 environment->GetIntValue("VspBspTree.maxTests", mMaxTests); 76 82 77 // maximum number of view cells 78 environment->GetIntValue("ViewCells.maxViewCells", mMaxViewCells); 79 80 //-- 83 // maximum and minimum number of view cells 84 environment->GetIntValue("VspBspTree.Termination.maxViewCells", mMaxViewCells); 85 environment->GetIntValue("VspBspTree.PostProcess.minViewCells", mMergeMinViewCells); 86 environment->GetIntValue("VspBspTree.PostProcess.maxCostRatio", mMergeMaxCostRatio); 87 88 89 //-- debug output 81 90 Debug << "******* VSP BSP options ******** " << endl; 82 91 Debug << "max depth: " << mTermMaxDepth << endl; … … 313 322 long startTime = GetTime(); 314 323 315 while (!tStack.empty()) 324 while (!tStack.empty()) 316 325 { 317 326 tData = tStack.top(); 318 327 319 328 tStack.pop(); 329 320 330 // subdivide leaf node 321 331 BspNode *r = Subdivide(tStack, tData); … … 331 341 } 332 342 333 bool VspBspTree::TerminationCriteriaMet(const VspBspTraversalData &data, 334 const int numLeaves) const 343 bool VspBspTree::TerminationCriteriaMet(const VspBspTraversalData &data) const 335 344 { 336 345 return … … 338 347 (data.mPvs <= mTermMinPvs) || 339 348 (data.mArea <= mTermMinArea) || 340 ( (mStat.nodes / 2 + 1)>= mMaxViewCells) ||349 (mStat.nodes / 2 + 1 >= mMaxViewCells) || 341 350 // (data.GetAvgRayContribution() >= mTermMaxRayContribution) || 342 351 (data.mDepth >= mTermMaxDepth)); … … 348 357 BspNode *newNode = tData.mNode; 349 358 350 if (!TerminationCriteriaMet(tData , (int)tStack.size()))359 if (!TerminationCriteriaMet(tData)) 351 360 { 352 361 PolygonContainer coincident; … … 370 379 } 371 380 372 //-- terminate traversal 381 //-- terminate traversal and create new view cell 373 382 if (newNode->IsLeaf()) 374 383 { … … 378 387 BspViewCell *viewCell = new BspViewCell(); 379 388 leaf->SetViewCell(viewCell); 389 390 if (mStoreRays) 391 { 392 RayInfoContainer::const_iterator it, it_end = tData.mRays->end(); 393 for (it = tData.mRays->begin(); it != it_end; ++ it) 394 leaf->mVssRays.push_back((*it).mRay); 395 } 396 380 397 viewCell->mLeaves.push_back(leaf); 398 viewCell->SetArea(tData.mArea); 381 399 382 400 //-- update pvs … … 392 410 393 411 //-- cleanup 394 DEL_PTR(tData.mPolygons); 395 DEL_PTR(tData.mRays); 396 DEL_PTR(tData.mGeometry); 412 tData.Clear(); 397 413 398 414 return newNode; … … 1872 1888 return hits; 1873 1889 } 1890 1891 int VspBspTree::MergeLeaves() 1892 { 1893 vector<BspLeaf *> leaves; 1894 priority_queue<BspMergeCandidate> mergeQueue; 1895 1896 // collect the leaves, e.g., the "voxels" that will build the view cells 1897 CollectLeaves(leaves); 1898 1899 int vcSize = (int)leaves.size(); 1900 int savedVcSize = vcSize; 1901 1902 BspLeaf::NewMail(); 1903 1904 vector<BspLeaf *>::const_iterator it, it_end = leaves.end(); 1905 1906 // find merge candidates and push them into queue 1907 for (it = leaves.begin(); it != it_end; ++ it) 1908 { 1909 BspLeaf *leaf = *it; 1910 1911 // no leaf is part of two merge candidates 1912 if (!leaf->Mailed()) 1913 { 1914 leaf->Mail(); 1915 1916 vector<BspLeaf *> neighbors; 1917 FindNeighbors(leaf, neighbors, true); 1918 1919 vector<BspLeaf *>::const_iterator nit, 1920 nit_end = neighbors.end(); 1921 1922 for (nit = neighbors.begin(); nit != nit_end; ++ nit) 1923 { 1924 BspMergeCandidate mc = BspMergeCandidate(leaf, *nit); 1925 mergeQueue.push(mc); 1926 1927 BspMergeCandidate::sOverallCost += mc.GetLeaf1Cost(); 1928 BspMergeCandidate::sOverallCost += mc.GetLeaf2Cost(); 1929 } 1930 } 1931 } 1932 1933 int merged = 0; 1934 1935 Debug << "here234: " << mMergeMaxCostRatio << endl; 1936 1937 // use priority queue to merge leaves 1938 while (!mergeQueue.empty() && (vcSize > mMergeMinViewCells) )//&& 1939 //(mergeQueue.top().GetMergeCost() < 1940 //mMergeMaxCostRatio / BspMergeCandidate::sOverallCost)) 1941 { 1942 Debug << "mergecost: " << mergeQueue.top().GetMergeCost() << " " << mMergeMaxCostRatio << endl; 1943 BspMergeCandidate mc = mergeQueue.top(); 1944 mergeQueue.pop(); 1945 1946 // both view cells equal! 1947 if (mc.GetLeaf1()->GetViewCell() == mc.GetLeaf2()->GetViewCell()) 1948 continue; 1949 1950 if (mc.Valid()) 1951 { 1952 ViewCell::NewMail(); 1953 MergeViewCells(mc.GetLeaf1(), mc.GetLeaf2()); 1954 1955 ++ merged; 1956 -- vcSize; 1957 // increase absolute merge cost 1958 BspMergeCandidate::sOverallCost += mc.GetMergeCost(); 1959 } 1960 // merge candidate not valid, because one of the leaves was already 1961 // merged with another one 1962 else 1963 { 1964 // validate and reinsert into queue 1965 mc.SetValid(); 1966 mergeQueue.push(mc); 1967 //Debug << "validate " << mc.GetMergeCost() << endl; 1968 } 1969 } 1970 1971 // collapse tree according to view cell partition 1972 //CollapseTree(mRoot); 1973 1974 // revalidate leaves 1975 //ValidateViewCellLeaves(); 1976 1977 //Debug << "merged " << merged << " of " << savedVcSize << " leaves" << endl; 1978 1979 //TODO: should return sample contributions 1980 return merged; 1981 } 1982 1983 1984 bool VspBspTree::MergeViewCells(BspLeaf *l1, BspLeaf *l2) 1985 { 1986 //-- change pointer to view cells of all leaves associated 1987 //-- with the previous view cells 1988 BspViewCell *fVc = l1->GetViewCell(); 1989 BspViewCell *bVc = l2->GetViewCell(); 1990 1991 BspViewCell *vc = dynamic_cast<BspViewCell *>( 1992 mViewCellsManager->MergeViewCells(*fVc, *bVc)); 1993 1994 // if merge was unsuccessful 1995 if (!vc) return false; 1996 1997 // set new size of view cell 1998 vc->SetArea(fVc->GetVolume() + bVc->GetVolume()); 1999 2000 vector<BspLeaf *> fLeaves = fVc->mLeaves; 2001 vector<BspLeaf *> bLeaves = bVc->mLeaves; 2002 2003 vector<BspLeaf *>::const_iterator it; 2004 2005 //-- change view cells of all the other leaves the view cell belongs to 2006 for (it = fLeaves.begin(); it != fLeaves.end(); ++ it) 2007 { 2008 (*it)->SetViewCell(vc); 2009 vc->mLeaves.push_back(*it); 2010 } 2011 2012 for (it = bLeaves.begin(); it != bLeaves.end(); ++ it) 2013 { 2014 (*it)->SetViewCell(vc); 2015 vc->mLeaves.push_back(*it); 2016 } 2017 2018 vc->Mail(); 2019 2020 // clean up old view cells 2021 DEL_PTR(fVc); 2022 DEL_PTR(bVc); 2023 2024 return true; 2025 } 2026 2027 2028 void VspBspTree::SetViewCellsManager(ViewCellsManager *vcm) 2029 { 2030 mViewCellsManager = vcm; 2031 } 2032 2033 /************************************************************************/ 2034 /* BspMergeCandidate implementation */ 2035 /************************************************************************/ 2036 2037 2038 BspMergeCandidate::BspMergeCandidate(BspLeaf *l1, BspLeaf *l2): 2039 mMergeCost(0), 2040 mLeaf1(l1), 2041 mLeaf2(l2), 2042 mLeaf1Id(l1->GetViewCell()->mMailbox), 2043 mLeaf2Id(l2->GetViewCell()->mMailbox) 2044 { 2045 EvalMergeCost(); 2046 } 2047 2048 float BspMergeCandidate::GetLeaf1Cost() const 2049 { 2050 BspViewCell *vc = mLeaf1->GetViewCell(); 2051 return vc->GetPvs().GetSize() * vc->GetArea(); 2052 } 2053 2054 float BspMergeCandidate::GetLeaf2Cost() const 2055 { 2056 BspViewCell *vc = mLeaf2->GetViewCell(); 2057 return vc->GetPvs().GetSize() * vc->GetVolume(); 2058 } 2059 2060 void BspMergeCandidate::EvalMergeCost() 2061 { 2062 //-- compute pvs difference 2063 BspViewCell *vc1 = mLeaf1->GetViewCell(); 2064 BspViewCell *vc2 = mLeaf2->GetViewCell(); 2065 2066 const int diff1 = vc1->GetPvs().Diff(vc2->GetPvs()); 2067 const int vcPvs = diff1 + vc1->GetPvs().GetSize(); 2068 2069 //-- compute ratio of old cost 2070 //-- (added size of left and right view cell times pvs size) 2071 //-- to new rendering cost (size of merged view cell times pvs size) 2072 const float oldCost = GetLeaf1Cost() + GetLeaf2Cost(); 2073 2074 const float newCost = 2075 (float)vcPvs * (vc1->GetArea() + vc2->GetArea()); 2076 2077 mMergeCost = newCost - oldCost; 2078 2079 // if (vcPvs > sMaxPvsSize) // strong penalty if pvs size too large 2080 // mMergeCost += 1.0; 2081 } 2082 2083 void BspMergeCandidate::SetLeaf1(BspLeaf *l) 2084 { 2085 mLeaf1 = l; 2086 } 2087 2088 void BspMergeCandidate::SetLeaf2(BspLeaf *l) 2089 { 2090 mLeaf2 = l; 2091 } 2092 2093 BspLeaf *BspMergeCandidate::GetLeaf1() 2094 { 2095 return mLeaf1; 2096 } 2097 2098 BspLeaf *BspMergeCandidate::GetLeaf2() 2099 { 2100 return mLeaf2; 2101 } 2102 2103 bool BspMergeCandidate::Valid() const 2104 { 2105 return 2106 (mLeaf1->GetViewCell()->mMailbox == mLeaf1Id) && 2107 (mLeaf2->GetViewCell()->mMailbox == mLeaf2Id); 2108 } 2109 2110 float BspMergeCandidate::GetMergeCost() const 2111 { 2112 return mMergeCost; 2113 } 2114 2115 void BspMergeCandidate::SetValid() 2116 { 2117 mLeaf1Id = mLeaf1->GetViewCell()->mMailbox; 2118 mLeaf2Id = mLeaf2->GetViewCell()->mMailbox; 2119 2120 EvalMergeCost(); 2121 } -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h
r475 r478 20 20 class Ray; 21 21 class ViewCellsStatistics; 22 23 /*class BspNodeGeometry; 24 class BspTreeStatistics; 25 class ViewCellsStatistics; 26 class BspNode; 27 class BspLeaf; 28 class BspInterior; 29 */ 22 class ViewCellsManager; 23 30 24 31 25 /** … … 130 124 } 131 125 126 // deletes contents and sets them to NULL 127 void Clear() 128 { 129 DEL_PTR(mPolygons); 130 DEL_PTR(mRays); 131 DEL_PTR(mGeometry); 132 } 133 132 134 friend bool operator<(const VspBspTraversalData &a, const VspBspTraversalData &b) 133 135 { … … 237 239 238 240 239 int 240 CastLineSegment(const Vector3 &origin, 241 const Vector3 &termination, 242 ViewCellContainer &viewcells 243 ); 241 int CastLineSegment(const Vector3 &origin, 242 const Vector3 &termination, 243 ViewCellContainer &viewcells); 244 245 /** Merges leaves with similar PVS. 246 */ 247 int MergeLeaves(); 248 249 250 251 /** Sets pointer to view cells manager. 252 */ 253 void SetViewCellsManager(ViewCellsManager *vcm); 244 254 245 255 protected: … … 428 438 /** Returns true if tree can be terminated. 429 439 */ 430 inline bool TerminationCriteriaMet(const VspBspTraversalData &data , const int numLeaves) const;440 inline bool TerminationCriteriaMet(const VspBspTraversalData &data) const; 431 441 432 442 /** Computes accumulated ray lenght of this rays. … … 477 487 Plane3 ChooseCandidatePlane3(const RayInfoContainer &rays) const; 478 488 489 /** Merge view cells of leaves l1 and l2. 490 */ 491 bool MergeViewCells(BspLeaf *l1, BspLeaf *l2); 492 479 493 /// Pointer to the root of the tree 480 494 BspNode *mRoot; … … 549 563 /// maximal number of view cells 550 564 int mMaxViewCells; 565 /// minimal number of view cells 566 int mMergeMinViewCells; 567 /// maximal cost ratio for the merge 568 int mMergeMaxCostRatio; 569 570 ViewCellsManager *mViewCellsManager; 571 572 // if rays should be stored in leaves 573 bool mStoreRays; 551 574 552 575 private: … … 567 590 }; 568 591 592 /** 593 Candidate for leaf merging based on priority. 594 */ 595 class BspMergeCandidate 596 { 597 public: 598 599 BspMergeCandidate(BspLeaf *l1, BspLeaf *l2); 600 601 /** If this merge pair is still valid. 602 */ 603 bool Valid() const; 604 605 /** Sets this merge candidate to be valid. 606 */ 607 void SetValid(); 608 609 friend bool operator<(const BspMergeCandidate &leafa, const BspMergeCandidate &leafb) 610 { 611 return leafb.GetMergeCost() < leafa.GetMergeCost(); 612 } 613 614 void SetLeaf1(BspLeaf *l); 615 void SetLeaf2(BspLeaf *l); 616 617 BspLeaf *GetLeaf1(); 618 BspLeaf *GetLeaf2(); 619 620 /** Merge cost of this candidate pair. 621 */ 622 float GetMergeCost() const; 623 624 /** Returns cost of leaf 1. 625 */ 626 float GetLeaf1Cost() const; 627 /** Returns cost of leaf 2. 628 */ 629 float GetLeaf2Cost() const; 630 631 /// maximal pvs size 632 static int sMaxPvsSize; 633 /// overall cost used to normalize cost ratio 634 static float sOverallCost; 635 636 protected: 637 638 /** Evaluates the merge costs of the leaves. 639 */ 640 void EvalMergeCost(); 641 642 int mLeaf1Id; 643 int mLeaf2Id; 644 645 float mMergeCost; 646 647 BspLeaf *mLeaf1; 648 BspLeaf *mLeaf2; 649 }; 650 651 569 652 #endif -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp
r473 r478 1910 1910 1911 1911 1912 1913 1912 void VspKdTree::SetViewCellsManager(ViewCellsManager *vcm) 1914 1913 { … … 2023 2022 leaf->SetViewCell(vc); 2024 2023 2025 vc->Set Volume(GetBBox(leaf).GetVolume());2024 vc->SetArea(GetBBox(leaf).GetVolume()); 2026 2025 vc->mLeaves.push_back(leaf); 2027 2026 … … 2107 2106 2108 2107 // set new size of view cell 2109 vc->Set Volume(fVc->GetVolume() + bVc->GetVolume());2108 vc->SetArea(fVc->GetVolume() + bVc->GetVolume()); 2110 2109 2111 2110 vector<VspKdLeaf *> fLeaves = fVc->mLeaves; … … 2229 2228 ValidateViewCellLeaves(); 2230 2229 2231 Debug << "merged " << merged << " of " << savedVcSize << " leaves" << endl;2230 //Debug << "merged " << merged << " of " << savedVcSize << " leaves" << endl; 2232 2231 2233 2232 //TODO: should return sample contributions
Note: See TracChangeset
for help on using the changeset viewer.