- Timestamp:
- 01/05/06 20:41:52 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
r502 r503 37 37 void ViewCellsManager::ParseEnvironment() 38 38 { 39 // post processing stuff 40 environment->GetIntValue("ViewCells.PostProcess.minPvsDif", mMinPvsDif); 41 environment->GetIntValue("ViewCells.PostProcess.minPvs", mMinPvs); 42 environment->GetIntValue("ViewCells.PostProcess.maxPvs", mMaxPvs); 43 39 // visualization stuff 44 40 environment->GetBoolValue("ViewCells.Visualization.exportRays", mExportRays); 45 41 environment->GetBoolValue("ViewCells.Visualization.exportGeometry", mExportGeometry); 46 42 47 43 char buf[50]; 48 44 49 45 environment->GetStringValue("ViewCells.Visualization.colorCode", buf); 50 46 51 47 if (strcmp(buf, "PVS") == 0) 52 48 mColorCode = 1; … … 65 61 { 66 62 DEL_PTR(mRenderer); 67 68 63 CLEAR_CONTAINER(mViewCells); 64 CLEAR_CONTAINER(mMeshContainer); 69 65 } 70 66 … … 73 69 { 74 70 X3dParser parser; 75 71 76 72 environment->GetFloatValue("ViewCells.height", parser.mViewCellHeight); 77 73 78 74 bool success = parser.ParseFile(filename, *this); 79 75 Debug << (int)mViewCells.size() << " view cells loaded" << endl; … … 102 98 if (!ViewCellsConstructed()) 103 99 return; 104 100 105 101 VssRayContainer::const_iterator it, it_end = rays.end(); 106 102 107 for (it = rays.begin(); it != it_end; ++ it) 108 { 103 for (it = rays.begin(); it != it_end; ++ it) 104 { 109 105 ComputeSampleContributions(*(*it)); 110 106 } … … 143 139 144 140 145 void ViewCellsManager::DeriveViewCells(const ObjectContainer &objects, 146 ViewCellContainer &viewCells, 141 void ViewCellsManager::DeriveViewCells(const ObjectContainer &objects, 142 ViewCellContainer &viewCells, 147 143 const int maxViewCells) const 148 144 { 149 145 // maximal max viewcells 150 int limit = maxViewCells > 0 ? 146 int limit = maxViewCells > 0 ? 151 147 Min((int)objects.size(), maxViewCells) : (int)objects.size(); 152 148 … … 154 150 { 155 151 Intersectable *object = objects[i]; 156 152 157 153 // extract the mesh instances 158 154 if (object->Type() == Intersectable::MESH_INSTANCE) … … 168 164 169 165 170 ViewCell *ViewCellsManager::ExtrudeViewCell(const Triangle3 &baseTri, 166 ViewCell *ViewCellsManager::ExtrudeViewCell(const Triangle3 &baseTri, 171 167 const float height) const 172 168 { 173 169 // one mesh per view cell 174 170 Mesh *mesh = new Mesh(); 175 171 176 172 //-- construct prism 177 173 178 // bottom 174 // bottom 179 175 mesh->mFaces.push_back(new Face(2,1,0)); 180 176 // top … … 188 184 Vector3 triNorm = baseTri.GetNormal(); 189 185 190 Triangle3 topTri; 186 Triangle3 topTri; 191 187 192 188 // add base vertices and calculate top vertices 193 189 for (int i = 0; i < 3; ++ i) 194 190 mesh->mVertices.push_back(baseTri.mVertices[i]); 195 196 // add top vertices 191 192 // add top vertices 197 193 for (int i = 0; i < 3; ++ i) 198 194 mesh->mVertices.push_back(baseTri.mVertices[i] + height * triNorm); 199 195 200 196 mesh->Preprocess(); 201 197 … … 217 213 218 214 std::merge(front.mPiercingRays.begin(), front.mPiercingRays.end(), 219 back.mPiercingRays.begin(), back.mPiercingRays.end(), 215 back.mPiercingRays.begin(), back.mPiercingRays.end(), 220 216 vc->mPiercingRays.begin()); 221 217 … … 321 317 { 322 318 mViewCells.clear(); 323 319 324 320 CollectViewCells(); 325 321 mViewCellsStats.Reset(); … … 336 332 337 333 ViewCellContainer viewcells; 338 334 339 335 ray.mPvsContribution = 0; 340 336 ray.mRelativePvsContribution = 0.0f; … … 343 339 Ray hray(ray); 344 340 float tmin = 0, tmax = 1.0; 345 341 346 342 //hray.Init(ray.GetOrigin(), ray.GetDir(), Ray::LINE_SEGMENT); 347 343 if (!GetSceneBbox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) 348 344 return; 349 345 350 346 Vector3 origin = hray.Extrap(tmin); 351 347 Vector3 termination = hray.Extrap(tmax); 352 348 353 349 CastLineSegment(origin, 354 350 termination, 355 351 viewcells); 356 352 357 353 // copy viewcells memory efficiently 358 354 const bool storeViewcells = false; … … 361 357 ray.mViewCells = viewcells; 362 358 } 363 359 364 360 ViewCellContainer::const_iterator it = viewcells.begin(); 365 361 … … 367 363 368 364 if (addInPlace) { 369 for (; it != viewcells.end(); ++it) { 365 for (; it != viewcells.end(); ++it) { 370 366 ViewCell *viewcell = *it; 371 367 372 368 // if ray not outside of view space 373 369 float contribution; 374 bool added = 370 bool added = 375 371 viewcell->GetPvs().AddSample(ray.mTerminationObject, 376 372 contribution … … 378 374 if (added) 379 375 ray.mPvsContribution++; 380 376 381 377 ray.mRelativePvsContribution += contribution; 382 378 } 383 379 } else { 384 for (; it != viewcells.end(); ++it) { 380 for (; it != viewcells.end(); ++it) { 385 381 ViewCell *viewcell = *it; 386 382 // if ray not outside of view space … … 390 386 )) 391 387 ray.mPvsContribution++; 392 388 393 389 ray.mRelativePvsContribution += contribution; 394 390 } 395 391 396 for (it = viewcells.begin(); it != viewcells.end(); ++it) { 392 for (it = viewcells.begin(); it != viewcells.end(); ++it) { 397 393 ViewCell *viewcell = *it; 398 394 // if ray not outside of view space … … 405 401 void ViewCellsManager::GetRaySets(const VssRayContainer &sourceRays, 406 402 const int maxSize, 407 VssRayContainer &usedRays, 403 VssRayContainer &usedRays, 408 404 VssRayContainer *savedRays) const 409 405 { … … 461 457 462 458 459 460 void ViewCellsManager::CreateViewCellsMeshes() 461 { 462 // convert to meshes 463 ViewCellContainer::const_iterator it, it_end = mViewCells.end(); 464 465 for (it = mViewCells.begin(); it != it_end; ++ it) 466 { 467 CreateMesh(*it); 468 } 469 } 470 463 471 /**********************************************************************/ 464 472 /* BspViewCellsManager implementation */ … … 466 474 467 475 468 BspViewCellsManager::BspViewCellsManager(BspTree *bspTree, 476 BspViewCellsManager::BspViewCellsManager(BspTree *bspTree, 469 477 int constructionSamples): 470 ViewCellsManager(constructionSamples), 478 ViewCellsManager(constructionSamples), 471 479 mBspTree(bspTree) 472 480 { … … 486 494 487 495 488 int BspViewCellsManager::Construct(const ObjectContainer &objects, 496 int BspViewCellsManager::Construct(const ObjectContainer &objects, 489 497 const VssRayContainer &rays) 490 498 { … … 494 502 495 503 int sampleContributions = 0; 496 504 497 505 // construct view cells using the collected samples 498 506 RayContainer constructionRays; … … 513 521 } 514 522 515 if (mViewCells.empty()) 516 { 517 // no view cells loaded 523 if (mViewCells.empty()) 524 { 525 // no view cells loaded 518 526 mBspTree->Construct(objects, constructionRays); 519 527 // collect final view cells 520 528 mBspTree->CollectViewCells(mViewCells); 521 } 529 } 522 530 else 523 531 { … … 529 537 530 538 Debug << mBspTree->GetStatistics() << endl; 531 532 EvaluateViewCellsStats();539 540 //EvaluateViewCellsStats(); 533 541 Debug << "\nView cells after construction:\n" << mViewCellsStats << endl; 534 542 … … 536 544 ComputeSampleContributions(savedRays); 537 545 546 538 547 return sampleContributions; 539 548 } 540 549 550 541 551 void BspViewCellsManager::CollectViewCells() 542 552 { 543 553 mBspTree->CollectViewCells(mViewCells); 544 554 } 555 545 556 546 557 float BspViewCellsManager::GetProbability(ViewCell *viewCell) … … 553 564 #endif 554 565 } 555 566 556 567 557 568 float BspViewCellsManager::GetRendercost(ViewCell *viewCell, float objRendercost) const … … 575 586 576 587 577 int BspViewCellsManager::PostProcess(const ObjectContainer &objects, 588 int BspViewCellsManager::PostProcess(const ObjectContainer &objects, 578 589 const VssRayContainer &rays) 579 590 { … … 601 612 cout << "exporting initial view cells (=leaves) ... "; 602 613 Exporter *exporter = Exporter::GetExporter("view_cells.x3d"); 603 614 604 615 if (exporter) 605 616 { … … 607 618 exporter->SetFilled(); 608 619 ExportViewCells(exporter); 609 620 610 621 if (mExportGeometry) 611 622 { … … 624 635 625 636 cout << "starting post processing using " << mPostProcessSamples << " samples ... "; 626 637 627 638 long startTime = GetTime(); 628 639 … … 637 648 CLEAR_CONTAINER(mBspRays); 638 649 ConstructBspRays(rays, mPostProcessSamples); 639 650 640 651 for (int i = 0; i < (int)mBspRays.size(); ++ i) 641 { 652 { 642 653 BspRay *ray = mBspRays[i]; 643 654 644 655 // traverse leaves stored in the rays and compare and merge consecutive 645 656 // leaves (i.e., the neighbors in the tree) 646 657 if (ray->intersections.size() < 2) 647 658 continue; 648 659 649 660 iit = ray->intersections.begin(); 650 661 651 662 BspLeaf *previousLeaf = (*iit).mLeaf; 652 663 ++ iit; 653 664 654 665 for (; iit != ray->intersections.end(); ++ iit) 655 666 { … … 657 668 658 669 if (ShouldMerge(leaf, previousLeaf)) 659 { 670 { 660 671 MergeBspLeafViewCells(leaf, previousLeaf); 661 672 662 673 ++ merged; 663 674 } 664 675 665 676 previousLeaf = leaf; 666 677 } … … 673 684 674 685 Debug << "Postprocessing: Merged " << merged << " view cells in " 675 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" 686 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" 676 687 << "using " << (int)mBspRays.size() << " samples" << endl << endl; 677 688 678 689 CLEAR_CONTAINER(mBspRays); 679 690 … … 704 715 CLEAR_CONTAINER(mBspRays); 705 716 ConstructBspRays(sampleRays, mVisualizationSamples); 706 717 707 718 if (1) // export view cells 708 719 { … … 715 726 delete exporter; 716 727 } 717 728 718 729 cout << "finished" << endl; 719 } 730 } 720 731 721 732 //-- visualization of the BSP splits 722 733 bool exportSplits = false; 723 734 environment->GetBoolValue("BspTree.Visualization.exportSplits", exportSplits); 724 735 725 736 if (exportSplits) 726 737 { … … 734 745 735 746 736 inline bool vc_gt(ViewCell *a, ViewCell *b) 737 { 747 inline bool vc_gt(ViewCell *a, ViewCell *b) 748 { 738 749 return a->GetPvs().GetSize() > b->GetPvs().GetSize(); 739 750 } … … 744 755 Exporter *exporter = Exporter::GetExporter("bsp_splits.x3d"); 745 756 746 if (exporter) 747 { 748 Material m; 757 if (exporter) 758 { 759 Material m; 749 760 m.mDiffuseColor = RgbColor(1, 0, 0); 750 761 exporter->SetForcedMaterial(m); 751 762 exporter->SetWireframe(); 752 763 753 764 exporter->ExportBspSplits(*mBspTree, true); 754 765 … … 759 770 760 771 exporter->SetFilled(); 761 772 762 773 // export rays 763 774 if (0) 764 775 { 765 776 VssRayContainer outRays; 766 777 767 778 int raysSize = min((int)mBspRays.size(), mVisualizationSamples); 768 779 … … 770 781 // only rays piercing geometry 771 782 outRays.push_back(mBspRays[i]->vssRay); 772 773 // export rays 783 784 // export rays 774 785 exporter->ExportRays(outRays, RgbColor(1, 1, 0)); 775 786 } … … 786 797 { 787 798 const int leafOut = 10; 788 799 789 800 ViewCell::NewMail(); 790 801 791 802 //-- some rays for output 792 803 const int raysOut = min((int)mBspRays.size(), mVisualizationSamples); 793 804 794 805 cout << "visualization using " << mVisualizationSamples << " samples" << endl; 795 806 Debug << "\nOutput view cells: " << endl; 796 807 797 808 // sort view cells to get largest view cells 798 809 #if 0 799 810 stable_sort(mViewCells.begin(), mViewCells.end(), vc_gt); 800 811 #endif 801 int limit = min(leafOut, (int)mViewCells.size()); 802 812 int limit = min(leafOut, (int)mViewCells.size()); 813 803 814 for (int i = 0; i < limit; ++ i) 804 815 { … … 815 826 #if 0 816 827 // check whether we can add the current ray to the output rays 817 for (int k = 0; k < raysOut; ++ k) 828 for (int k = 0; k < raysOut; ++ k) 818 829 { 819 830 BspRay *ray = mBspRays[k]; … … 821 832 { 822 833 BspLeaf *leaf = ray->intersections[j].mLeaf; 823 if (vc == leaf->GetViewCell()) 834 if (vc == leaf->GetViewCell()) 824 835 vcRays.push_back(ray->vssRay); 825 836 } … … 830 841 831 842 Exporter *exporter = Exporter::GetExporter(s); 832 843 833 844 exporter->SetWireframe(); 834 845 … … 841 852 else 842 853 { 843 PolygonContainervcGeom;844 854 BspNodeGeometry vcGeom; 855 845 856 //-- export view cell 846 857 mBspTree->ConstructGeometry(vc, vcGeom); 847 exporter->ExportPolygons(vcGeom); 848 CLEAR_CONTAINER(vcGeom); 849 } 850 851 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() 858 exporter->ExportPolygons(vcGeom.mPolys); 859 } 860 861 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() 852 862 << ", piercing rays=" << (int)vcRays.size() 853 863 << ", leaves=" << (int)vc->mLeaves.size() << endl; 854 864 855 865 856 866 // export rays piercing this view cell 857 867 #if 0 … … 871 881 872 882 // output PVS of view cell 873 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 883 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 874 884 { 875 885 Intersectable *intersect = (*it).first; … … 882 892 exporter->ExportIntersectable(intersect); 883 893 intersect->Mail(); 884 } 885 } 886 894 } 895 } 896 887 897 DEL_PTR(exporter); 888 898 cout << "finished" << endl; … … 895 905 bool BspViewCellsManager::MergeBspLeafViewCells(BspLeaf *front, BspLeaf *back) const 896 906 { 897 BspViewCell *viewCell = 898 dynamic_cast<BspViewCell *>(MergeViewCells(*front->GetViewCell(), 907 BspViewCell *viewCell = 908 dynamic_cast<BspViewCell *>(MergeViewCells(*front->GetViewCell(), 899 909 *back->GetViewCell())); 900 910 901 911 if (!viewCell) 902 912 return false; … … 910 920 911 921 vector<BspLeaf *>::const_iterator it; 912 922 913 923 for (it = fLeaves.begin(); it != fLeaves.end(); ++ it) 914 924 { … … 921 931 viewCell->mLeaves.push_back(*it); 922 932 } 923 933 924 934 DEL_PTR(fVc); 925 935 DEL_PTR(bVc); … … 940 950 if (fvc->GetPvs().GetSize() + fdiff < mMaxPvs) 941 951 { 942 if ((fvc->GetPvs().GetSize() < mMinPvs) || 952 if ((fvc->GetPvs().GetSize() < mMinPvs) || 943 953 (bvc->GetPvs().GetSize() < mMinPvs) || 944 954 ((fdiff < mMinPvsDif) && (bvc->GetPvs().Diff(fvc->GetPvs()) < mMinPvsDif))) … … 947 957 } 948 958 } 949 959 950 960 return false; 951 961 } … … 979 989 980 990 981 void BspViewCellsManager::ExportColor(Exporter *exporter, 991 void BspViewCellsManager::ExportColor(Exporter *exporter, 982 992 ViewCell *vc) const 983 993 { … … 994 1004 case 1: // pvs 995 1005 { 996 importance = (float)vc->GetPvs().GetSize() / 1006 importance = (float)vc->GetPvs().GetSize() / 997 1007 (float)mViewCellsStats.maxPvs; 998 1008 } … … 1002 1012 BspViewCell *bspVc = dynamic_cast<BspViewCell *>(vc); 1003 1013 1004 importance = (float)bspVc->mLeaves.size() / 1014 importance = (float)bspVc->mLeaves.size() / 1005 1015 (float)mViewCellsStats.maxLeaves; 1006 1016 } … … 1019 1029 m.mDiffuseColor.r = importance; 1020 1030 m.mDiffuseColor.g = 1.0f - m.mDiffuseColor.r; 1021 1031 1022 1032 exporter->SetForcedMaterial(m); 1023 1033 } 1024 1034 1025 void BspViewCellsManager::ExportVcGeometry(Exporter *exporter, 1035 void BspViewCellsManager::ExportVcGeometry(Exporter *exporter, 1026 1036 ViewCell *vc) const 1027 1037 { … … 1030 1040 else 1031 1041 { 1032 PolygonContainer cell;1042 BspNodeGeometry geom; 1033 1043 mBspTree->ConstructGeometry( 1034 dynamic_cast<BspViewCell *>(vc), cell); 1035 exporter->ExportPolygons(cell); 1036 } 1044 dynamic_cast<BspViewCell *>(vc), geom); 1045 exporter->ExportPolygons(geom.mPolys); 1046 } 1047 } 1048 1049 1050 void BspViewCellsManager::CreateMesh(ViewCell *vc) 1051 { 1037 1052 } 1038 1053 … … 1048 1063 /* KdViewCellsManager implementation */ 1049 1064 /**********************************************************************/ 1065 1066 1050 1067 1051 1068 KdViewCellsManager::KdViewCellsManager(KdTree *kdTree): … … 1085 1102 } 1086 1103 1087 int KdViewCellsManager::Construct(const ObjectContainer &objects, 1104 int KdViewCellsManager::Construct(const ObjectContainer &objects, 1088 1105 const VssRayContainer &rays) 1089 1106 { … … 1097 1114 // create the view cells 1098 1115 mKdTree->CreateAndCollectViewCells(mViewCells); 1099 1116 1100 1117 // cast rays 1101 1118 ComputeSampleContributions(rays); … … 1112 1129 } 1113 1130 1114 int KdViewCellsManager::PostProcess(const ObjectContainer &objects, 1131 int KdViewCellsManager::PostProcess(const ObjectContainer &objects, 1115 1132 const VssRayContainer &rays) 1116 1133 { … … 1135 1152 { 1136 1153 const int leafOut = 10; 1137 1154 1138 1155 ViewCell::NewMail(); 1139 1156 1140 1157 //-- some rays for output 1141 1158 const int raysOut = min((int)sampleRays.size(), mVisualizationSamples); … … 1144 1161 //-- some random view cells and rays for output 1145 1162 vector<KdLeaf *> kdLeaves; 1146 1163 1147 1164 for (int i = 0; i < leafOut; ++ i) 1148 1165 kdLeaves.push_back(dynamic_cast<KdLeaf *>(mKdTree->GetRandomLeaf())); 1149 1166 1150 1167 for (int i = 0; i < kdLeaves.size(); ++ i) 1151 1168 { 1152 1169 KdLeaf *leaf = kdLeaves[i]; 1153 1170 RayContainer vcRays; 1154 1171 1155 1172 cout << "creating output for view cell " << i << " ... "; 1156 #if 0 1173 #if 0 1157 1174 // check whether we can add the current ray to the output rays 1158 for (int k = 0; k < raysOut; ++ k) 1175 for (int k = 0; k < raysOut; ++ k) 1159 1176 { 1160 1177 Ray *ray = sampleRays[k]; 1161 1178 1162 1179 for (int j = 0; j < (int)ray->bspIntersections.size(); ++ j) 1163 1180 { 1164 1181 BspLeaf *leaf2 = ray->bspIntersections[j].mLeaf; 1165 1166 if (leaf->GetViewCell() == leaf2->GetViewCell()) 1182 1183 if (leaf->GetViewCell() == leaf2->GetViewCell()) 1167 1184 { 1168 1185 vcRays.push_back(ray); … … 1170 1187 } 1171 1188 } 1172 #endif 1189 #endif 1173 1190 Intersectable::NewMail(); 1174 1191 1175 1192 ViewCell *vc = leaf->mViewCell; 1176 1193 1177 1194 //bspLeaves[j]->Mail(); 1178 1195 char s[64]; sprintf(s, "kd-pvs%04d.x3d", i); 1179 1196 1180 1197 Exporter *exporter = Exporter::GetExporter(s); 1181 1198 exporter->SetFilled(); … … 1183 1200 exporter->SetWireframe(); 1184 1201 //exporter->SetFilled(); 1185 1202 1186 1203 Material m;//= RandomMaterial(); 1187 1204 m.mDiffuseColor = RgbColor(1, 1, 0); 1188 1205 exporter->SetForcedMaterial(m); 1189 1206 1190 1207 AxisAlignedBox3 box = mKdTree->GetBox(leaf); 1191 1208 exporter->ExportBox(box); 1192 1209 1193 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() 1210 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() 1194 1211 << ", piercing rays=" << (int)vcRays.size() << endl; 1195 1212 1196 1213 // export rays piercing this view cell 1197 exporter->ExportRays(vcRays, 1000, RgbColor(0, 1, 0)); 1198 1214 exporter->ExportRays(vcRays, 1000, RgbColor(0, 1, 0)); 1215 1199 1216 m.mDiffuseColor = RgbColor(1, 0, 0); 1200 1217 exporter->SetForcedMaterial(m); 1201 1218 1202 1219 // exporter->SetWireframe(); 1203 1220 exporter->SetFilled(); 1204 1221 1205 1222 ObjectPvsMap::iterator it, it_end = vc->GetPvs().mEntries.end(); 1206 1223 // output PVS of view cell 1207 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 1224 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 1208 1225 { 1209 1226 Intersectable *intersect = (*it).first; … … 1212 1229 exporter->ExportIntersectable(intersect); 1213 1230 intersect->Mail(); 1214 } 1231 } 1215 1232 } 1216 1233 1217 1234 DEL_PTR(exporter); 1218 1235 cout << "finished" << endl; … … 1226 1243 { 1227 1244 VssRay *ray = sampleRays[i]; 1228 1245 1229 1246 // check whether we can add this to the rays 1230 for (int j = 0; j < pvsOut; j++) 1247 for (int j = 0; j < pvsOut; j++) 1231 1248 { 1232 1249 if (objects[j] == ray->mTerminationObject) … … 1237 1254 } 1238 1255 1239 if (exportRays) 1256 if (exportRays) 1240 1257 { 1241 1258 Exporter *exporter = NULL; … … 1243 1260 exporter->SetWireframe(); 1244 1261 exporter->ExportKdTree(*mKdTree); 1245 1246 for (i=0; i < pvsOut; i++) 1262 1263 for (i=0; i < pvsOut; i++) 1247 1264 exporter->ExportRays(rays[i], RgbColor(1, 0, 0)); 1248 1265 1249 1266 exporter->SetFilled(); 1250 1267 1251 1268 delete exporter; 1252 1269 } 1253 1270 1254 for (int k=0; k < pvsOut; k++) 1271 for (int k=0; k < pvsOut; k++) 1255 1272 { 1256 1273 Intersectable *object = objects[k]; 1257 char s[64]; 1274 char s[64]; 1258 1275 sprintf(s, "sample-pvs%04d.x3d", k); 1259 1276 1260 1277 Exporter *exporter = Exporter::GetExporter(s); 1261 1278 exporter->SetWireframe(); 1262 1279 1263 1280 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 1264 1281 Intersectable::NewMail(); 1265 1282 1266 1283 // avoid adding the object to the list 1267 1284 object->Mail(); 1268 1285 ObjectContainer visibleObjects; 1269 1270 for (; i != object->mKdPvs.mEntries.end(); i++) 1286 1287 for (; i != object->mKdPvs.mEntries.end(); i++) 1271 1288 { 1272 1289 KdNode *node = (*i).first; 1273 1290 exporter->ExportBox(mKdTree->GetBox(node)); 1274 1291 1275 1292 mKdTree->CollectObjects(node, visibleObjects); 1276 1293 } 1277 1294 1278 1295 exporter->ExportRays(rays[k], RgbColor(0, 1, 0)); 1279 1296 exporter->SetFilled(); 1280 1297 1281 1298 for (int j = 0; j < visibleObjects.size(); j++) 1282 1299 exporter->ExportIntersectable(visibleObjects[j]); 1283 1300 1284 1301 Material m; 1285 1302 m.mDiffuseColor = RgbColor(1, 0, 0); 1286 1303 exporter->SetForcedMaterial(m); 1287 1304 exporter->ExportIntersectable(object); 1288 1305 1289 1306 delete exporter; 1290 1307 } 1291 } 1308 } 1292 1309 } 1293 1310 … … 1300 1317 1301 1318 1302 void KdViewCellsManager::ExportVcGeometry(Exporter *exporter, 1319 void KdViewCellsManager::ExportVcGeometry(Exporter *exporter, 1303 1320 ViewCell *vc) const 1304 1321 { … … 1335 1352 1336 1353 1354 void KdViewCellsManager::CreateMesh(ViewCell *vc) 1355 { 1356 } 1357 1337 1358 /**********************************************************************/ 1338 1359 /* VspKdViewCellsManager implementation */ … … 1340 1361 1341 1362 1342 VspKdViewCellsManager::VspKdViewCellsManager(VspKdTree *vspKdTree, 1363 VspKdViewCellsManager::VspKdViewCellsManager(VspKdTree *vspKdTree, 1343 1364 int constructionSamples): 1344 ViewCellsManager(constructionSamples), 1365 ViewCellsManager(constructionSamples), 1345 1366 mVspKdTree(vspKdTree) 1346 1367 { … … 1364 1385 } 1365 1386 1387 1366 1388 void VspKdViewCellsManager::CollectViewCells() 1367 1389 { … … 1369 1391 } 1370 1392 1371 int VspKdViewCellsManager::Construct(const ObjectContainer &objects, 1393 int VspKdViewCellsManager::Construct(const ObjectContainer &objects, 1372 1394 const VssRayContainer &rays) 1373 1395 { … … 1375 1397 if (ViewCellsConstructed()) 1376 1398 return 0; 1377 1399 1378 1400 VssRayContainer constructionRays; 1379 1401 VssRayContainer savedRays; 1380 1402 1381 GetRaySets(rays, 1382 mConstructionSamples, 1383 constructionRays, 1403 GetRaySets(rays, 1404 mConstructionSamples, 1405 constructionRays, 1384 1406 &savedRays); 1385 1386 Debug << "constructing vsp kd tree using " 1407 1408 Debug << "constructing vsp kd tree using " 1387 1409 << (int)constructionRays.size() << " samples" << endl; 1388 1410 … … 1397 1419 1398 1420 // collapse siblings belonging to the same view cell 1421 mVspKdTree->RefineViewCells(rays); 1422 1423 // collapse siblings belonging to the same view cell 1399 1424 mVspKdTree->CollapseTree(); 1400 1401 // collapse siblings belonging to the same view cell1402 mVspKdTree->RefineViewCells(rays);1403 1425 1404 1426 // evaluale view cell stats … … 1410 1432 // recast rest of rays 1411 1433 ComputeSampleContributions(savedRays); 1412 1413 Debug << "Computed remaining ray contribution in " << TimeDiff(startTime, GetTime()) * 1e-3 1434 1435 Debug << "Computed remaining ray contribution in " << TimeDiff(startTime, GetTime()) * 1e-3 1414 1436 << " secs" << endl; 1415 1437 … … 1428 1450 } 1429 1451 1430 int VspKdViewCellsManager::PostProcess(const ObjectContainer &objects, 1452 int VspKdViewCellsManager::PostProcess(const ObjectContainer &objects, 1431 1453 const VssRayContainer &rays) 1432 1454 { … … 1454 1476 1455 1477 //-- export leaf building blocks 1456 Exporter *exporter = Exporter::GetExporter("vspkdtree.x3d"); 1478 Exporter *exporter = Exporter::GetExporter("vspkdtree.x3d"); 1457 1479 if (!exporter) 1458 1480 return; … … 1462 1484 exporter->ExportVspKdTree(*mVspKdTree); 1463 1485 1464 if (mExportGeometry) 1486 if (mExportGeometry) 1465 1487 exporter->ExportGeometry(objects); 1466 1488 1467 if (mExportRays) 1468 { 1469 const float prob = (float)mVisualizationSamples 1489 if (mExportRays) 1490 { 1491 const float prob = (float)mVisualizationSamples 1470 1492 / ((float)sampleRays.size() + Limits::Small); 1471 1493 … … 1491 1513 if (!ViewCellsConstructed()) 1492 1514 return; 1493 1515 1494 1516 //-- export single view cells 1495 1517 for (int i = 0; i < 10; ++ i) … … 1498 1520 sprintf(s, "vsp_viewcell%04d.x3d", i); 1499 1521 Exporter *exporter = Exporter::GetExporter(s); 1500 const int idx = 1522 const int idx = 1501 1523 (int)RandomValue(0.0, (Real)((int)mViewCells.size() - 1)); 1502 1524 1503 VspKdViewCell *vc = dynamic_cast<VspKdViewCell *>(mViewCells[idx]); 1525 VspKdViewCell *vc = dynamic_cast<VspKdViewCell *>(mViewCells[idx]); 1504 1526 1505 1527 cout << "Output view cell " << i << " with pvs size " << vc->GetPvs().GetSize() << endl; … … 1508 1530 Material m; 1509 1531 m.mDiffuseColor = RgbColor(0, 1, 1); 1510 1532 1511 1533 exporter->SetForcedMaterial(m); 1512 1534 exporter->SetWireframe(); … … 1517 1539 if (mExportRays) 1518 1540 { 1519 vector<VspKdLeaf *>::const_iterator it, 1541 vector<VspKdLeaf *>::const_iterator it, 1520 1542 it_end = vc->mLeaves.end(); 1521 1543 … … 1540 1562 if ((*it)->mTerminationObject == NULL) 1541 1563 castRays.push_back(*it); 1542 else 1564 else 1543 1565 initRays.push_back(*it); 1544 1566 } … … 1560 1582 exporter->SetFilled(); 1561 1583 1562 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 1584 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 1563 1585 { 1564 1586 Intersectable *intersect = (*it).first; … … 1571 1593 exporter->ExportIntersectable(intersect); 1572 1594 intersect->Mail(); 1573 } 1595 } 1574 1596 } 1575 1597 … … 1578 1600 1579 1601 //-- export final view cells 1580 Exporter *exporter = Exporter::GetExporter("vspkdtree_merged.x3d"); 1581 1602 Exporter *exporter = Exporter::GetExporter("vspkdtree_merged.x3d"); 1603 1582 1604 //if (exportGeometry) exporter->SetWireframe(); 1583 1605 //else exporter->SetFilled(); … … 1585 1607 ExportViewCells(exporter); 1586 1608 1587 if (mExportGeometry) 1609 if (mExportGeometry) 1588 1610 { 1589 1611 exporter->SetFilled(); … … 1591 1613 } 1592 1614 1593 if (mExportRays) 1594 { 1595 const float prob = (float)mVisualizationSamples 1615 if (mExportRays) 1616 { 1617 const float prob = (float)mVisualizationSamples 1596 1618 / ((float)sampleRays.size() + Limits::Small); 1597 1619 1598 1620 exporter->SetWireframe(); 1599 1621 1600 1622 VssRayContainer rays; 1601 1623 1602 1624 for (int i = 0; i < sampleRays.size(); ++ i) 1603 1625 { … … 1605 1627 rays.push_back(sampleRays[i]); 1606 1628 } 1607 exporter->ExportRays(rays, RgbColor(1, 0, 0)); 1629 exporter->ExportRays(rays, RgbColor(1, 0, 0)); 1608 1630 } 1609 1631 … … 1630 1652 if (mColorCode == 0) // Random color 1631 1653 return; 1632 1654 1633 1655 float importance = 0; 1634 1656 … … 1637 1659 case 1: // pvs 1638 1660 { 1639 importance = (float)vc->GetPvs().GetSize() / 1661 importance = (float)vc->GetPvs().GetSize() / 1640 1662 (float)mViewCellsStats.maxPvs; 1641 1663 } … … 1645 1667 VspKdViewCell *vspKdVc = dynamic_cast<VspKdViewCell *>(vc); 1646 1668 1647 importance = (float)vspKdVc->mLeaves.size() / 1669 importance = (float)vspKdVc->mLeaves.size() / 1648 1670 (float)mViewCellsStats.maxLeaves; 1649 1671 } … … 1651 1673 case 3: // merged tree depth difference 1652 1674 { 1653 //importance = (float)GetMaxTreeDiff(vc) / 1675 //importance = (float)GetMaxTreeDiff(vc) / 1654 1676 // (float)(mVspBspTree->GetStatistics().maxDepth * 2); 1655 1677 } … … 1668 1690 1669 1691 1670 void VspKdViewCellsManager::ExportVcGeometry(Exporter *exporter, 1692 void VspKdViewCellsManager::ExportVcGeometry(Exporter *exporter, 1671 1693 ViewCell *vc) const 1672 1694 { … … 1684 1706 1685 1707 1686 /************************************************************************/ 1687 /* VspBspViewCellsManager implementation */ 1688 /************************************************************************/ 1689 1690 1691 VspBspViewCellsManager::VspBspViewCellsManager(VspBspTree *vspBspTree, 1708 void VspKdViewCellsManager::CreateMesh(ViewCell *vc) 1709 { 1710 } 1711 1712 /**************************************************************************/ 1713 /* VspBspViewCellsManager implementation */ 1714 /**************************************************************************/ 1715 1716 1717 VspBspViewCellsManager::VspBspViewCellsManager(VspBspTree *vspBspTree, 1692 1718 int constructionSamples): 1693 ViewCellsManager(constructionSamples), 1719 ViewCellsManager(constructionSamples), 1694 1720 mVspBspTree(vspBspTree) 1695 1721 { … … 1719 1745 1720 1746 1721 float VspBspViewCellsManager::GetRendercost(ViewCell *viewCell, 1747 float VspBspViewCellsManager::GetRendercost(ViewCell *viewCell, 1722 1748 float objRendercost) const 1723 1749 { … … 1743 1769 } 1744 1770 1745 int VspBspViewCellsManager::Construct(const ObjectContainer &objects, 1771 int VspBspViewCellsManager::Construct(const ObjectContainer &objects, 1746 1772 const VssRayContainer &rays) 1747 1773 { 1748 // if view cells were already constructed 1749 if (ViewCellsConstructed()) 1750 return 0; 1751 1752 Debug << "Constructing bsp view cells" << endl; 1753 1754 int sampleContributions = 0; 1755 1756 VssRayContainer sampleRays; 1757 1758 int limit = min (mConstructionSamples, (int)rays.size()); 1759 1760 1774 // if view cells were already constructed 1775 if (ViewCellsConstructed()) 1776 return 0; 1777 1778 Debug << "Constructing bsp view cells" << endl; 1779 1780 int sampleContributions = 0; 1781 1782 VssRayContainer sampleRays; 1783 1784 int limit = min (mConstructionSamples, (int)rays.size()); 1785 1761 1786 VssRayContainer constructionRays; 1762 1787 VssRayContainer savedRays; … … 1768 1793 1769 1794 mVspBspTree->Construct(constructionRays, &mSceneBox); 1770 1795 1771 1796 Debug << mVspBspTree->GetStatistics() << endl; 1772 1797 … … 1774 1799 cout << "collapsing invalid tree regions ... "; 1775 1800 long startTime = GetTime(); 1776 int collapsedLeaves = mVspBspTree->CollapseTree(); 1801 int collapsedLeaves = mVspBspTree->CollapseTree(); 1777 1802 Debug << "collapsed in " << TimeDiff(startTime, GetTime()) * 1e-3 << " seconds" << endl; 1778 1803 cout << "finished" << endl; 1779 1804 1780 1805 cout << "reseting view cell stats ... "; 1781 1806 ResetViewCells(); 1782 1807 cout << "finished" << endl; 1783 1808 1784 1809 Debug << "\nView cells after construction:\n" << mViewCellsStats << endl; 1785 1810 … … 1788 1813 cout << "exporting initial view cells (=leaves) ... "; 1789 1814 Exporter *exporter = Exporter::GetExporter("view_cells.x3d"); 1790 1815 1791 1816 if (exporter) 1792 1817 { … … 1797 1822 if (0 && mExportRays) 1798 1823 exporter->ExportRays(rays, RgbColor(1, 1, 1)); 1799 1824 1800 1825 if (mExportGeometry) 1801 1826 exporter->ExportGeometry(objects); 1802 1827 1803 1828 delete exporter; 1804 1829 } … … 1807 1832 1808 1833 startTime = GetTime(); 1834 1835 //-- merge the individual view cells: Should be done here because it makes 1836 MergeViewCells(rays, objects); 1837 //-- refines the merged view cells 1838 RefineViewCells(rays); 1839 // collapse sibling leaves that share the same view cell 1840 mVspBspTree->CollapseTree(); 1841 1842 // reset view cells and stats 1843 ResetViewCells(); 1844 1809 1845 cout << "Computing remaining ray contributions ... "; 1810 1846 // recast rest of rays … … 1812 1848 cout << "finished" << endl; 1813 1849 1814 Debug << "Computed remaining ray contribution in " << TimeDiff(startTime, GetTime()) * 1e-3 1850 Debug << "Computed remaining ray contribution in " << TimeDiff(startTime, GetTime()) * 1e-3 1815 1851 << " secs" << endl; 1816 1852 1817 1853 cout << "construction finished" << endl; 1854 1818 1855 return sampleContributions; 1819 1856 } 1820 1857 1821 1858 1822 // matt TODO: remove 1823 int VspBspViewCellsManager::MergeViewCells(const VssRayContainer &rays) const 1824 { 1825 vector<BspIntersection>::const_iterator iit; 1826 vector<BspRay *>bspRays; 1827 int merged = 0; 1828 1829 mVspBspTree->ConstructBspRays(bspRays, rays); 1830 1831 for (int i = 0; i < (int)bspRays.size(); ++ i) 1832 { 1833 BspRay *ray = bspRays[i]; 1834 1835 // traverse leaves stored in the rays and compare and merge consecutive 1836 // leaves (i.e., the neighbors in the tree) 1837 if (ray->intersections.size() < 2) 1838 continue; 1839 1840 iit = ray->intersections.begin(); 1841 1842 BspLeaf *previousLeaf = (*iit).mLeaf; 1843 ++ iit; 1844 1845 for (; iit != ray->intersections.end(); ++ iit) 1846 { 1847 BspLeaf *leaf = (*iit).mLeaf; 1848 1849 if (ShouldMerge(leaf, previousLeaf)) 1850 { 1851 mVspBspTree->MergeViewCells(leaf, previousLeaf); 1852 ++ merged; 1853 } 1854 previousLeaf = leaf; 1855 } 1856 } 1857 CLEAR_CONTAINER(bspRays); 1858 1859 return merged; 1860 } 1861 1862 1863 int VspBspViewCellsManager::PostProcess(const ObjectContainer &objects, 1864 const VssRayContainer &rays) 1865 { 1866 if (!ViewCellsConstructed()) 1867 { 1868 Debug << "view cells not constructed" << endl; 1869 return 0; 1870 } 1871 1859 void VspBspViewCellsManager::MergeViewCells(const VssRayContainer &rays, 1860 const ObjectContainer &objects) 1861 { 1872 1862 //-- post processing of bsp view cells 1873 1863 int vcSize = 0; … … 1888 1878 //-- merge or subdivide view cells 1889 1879 int merged = 0; 1890 1880 1891 1881 cout << "starting merge using " << mPostProcessSamples << " samples ... "; 1892 1882 long startTime = GetTime(); 1893 1883 1884 // TODO: should be done BEFORE the ray casting 1894 1885 merged = mVspBspTree->MergeViewCells(postProcessRays); 1895 1886 … … 1901 1892 Debug << "Postprocessing: Merged " << merged << " view cells in " 1902 1893 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl << endl; 1903 1894 1904 1895 cout << "reseting view cell stats ... "; 1905 1896 ResetViewCells(); … … 1934 1925 cout << "finished" << endl; 1935 1926 } 1936 1927 } 1928 1929 1930 void VspBspViewCellsManager::RefineViewCells(const VssRayContainer &rays) 1931 { 1937 1932 Debug << "render time before refine:" << endl; 1938 1933 mRenderer->RenderScene(); 1934 SimulationStatistics ss; 1939 1935 dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss); 1940 1936 Debug << ss << endl; 1941 1937 1942 1938 cout << "Refining the merged view cells ... "; 1943 startTime = GetTime();1939 long startTime = GetTime(); 1944 1940 1945 1941 // refining the merged view cells … … 1953 1949 Debug << "Postprocessing: refined " << refined << " view cells in " 1954 1950 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl << endl; 1955 1956 // collapse sibling leaves that share the same view cell 1957 mVspBspTree->CollapseTree(); 1958 1959 // reset view cells and stats 1960 ResetViewCells(); 1961 1962 return merged; 1951 } 1952 1953 int VspBspViewCellsManager::PostProcess(const ObjectContainer &objects, 1954 const VssRayContainer &rays) 1955 { 1956 if (!ViewCellsConstructed()) 1957 { 1958 Debug << "view cells not constructed" << endl; 1959 return 0; 1960 } 1961 1962 CreateViewCellsMeshes(); 1963 1964 return 0; 1963 1965 } 1964 1966 … … 1993 1995 bool VspBspViewCellsManager::ViewPointValid(const Vector3 &viewPoint) const 1994 1996 { 1995 return mSceneBox.IsInside(viewPoint) && 1997 return mSceneBox.IsInside(viewPoint) && 1996 1998 mVspBspTree->ViewPointValid(viewPoint); 1997 1999 } … … 2026 2028 delete exporter; 2027 2029 } 2028 2030 2029 2031 cout << "finished" << endl; 2030 } 2032 } 2031 2033 2032 2034 //-- visualization of the BSP splits 2033 2035 bool exportSplits = false; 2034 2036 environment->GetBoolValue("VspBspTree.Visualization.exportSplits", exportSplits); 2035 2037 2036 2038 if (exportSplits) 2037 2039 { … … 2044 2046 ExportBspPvs(objects, visRays); 2045 2047 } 2046 2048 2047 2049 2048 2050 void VspBspViewCellsManager::ExportSplits(const ObjectContainer &objects, … … 2051 2053 Exporter *exporter = Exporter::GetExporter("bsp_splits.x3d"); 2052 2054 2053 if (exporter) 2054 { 2055 Material m; 2055 if (exporter) 2056 { 2057 Material m; 2056 2058 m.mDiffuseColor = RgbColor(1, 0, 0); 2057 2059 exporter->SetForcedMaterial(m); 2058 2060 exporter->SetWireframe(); 2059 2061 2060 2062 exporter->ExportBspSplits(*mVspBspTree, true); 2061 2063 … … 2066 2068 2067 2069 exporter->ResetForcedMaterial(); 2068 2070 2069 2071 // export rays 2070 2072 if (mExportRays) 2071 2073 exporter->ExportRays(rays, RgbColor(1, 1, 0)); 2072 2074 2073 2075 if (mExportGeometry) 2074 2076 exporter->ExportGeometry(objects); … … 2078 2080 } 2079 2081 2082 2080 2083 void VspBspViewCellsManager::ExportBspPvs(const ObjectContainer &objects, 2081 2084 const VssRayContainer &rays) 2082 2085 { 2083 2086 const int leafOut = 10; 2084 2087 2085 2088 ViewCell::NewMail(); 2086 2089 2087 2090 cout << "visualization using " << mVisualizationSamples << " samples" << endl; 2088 2091 Debug << "\nOutput view cells: " << endl; 2089 2092 2090 2093 // sort view cells to visualize the largest view cells 2091 2094 #if 0 2092 2095 stable_sort(mViewCells.begin(), mViewCells.end(), vc_gt); 2093 2096 #endif 2094 int limit = min(leafOut, (int)mViewCells.size()); 2097 int limit = min(leafOut, (int)mViewCells.size()); 2095 2098 2096 2099 #if 1 … … 2105 2108 { 2106 2109 cout << "creating output for view cell " << i << " ... "; 2107 2110 2108 2111 VssRayContainer vcRays; 2109 2112 Intersectable::NewMail(); … … 2117 2120 #if 1 2118 2121 // check whether we can add the current ray to the output rays 2119 for (int k = 0; k < raysOut; ++ k) 2122 for (int k = 0; k < raysOut; ++ k) 2120 2123 { 2121 2124 BspRay *ray = bspRays[k]; … … 2123 2126 { 2124 2127 BspLeaf *leaf = ray->intersections[j].mLeaf; 2125 if (vc == leaf->GetViewCell()) 2128 if (vc == leaf->GetViewCell()) 2126 2129 vcRays.push_back(ray->vssRay); 2127 2130 } … … 2137 2140 exporter->SetForcedMaterial(m); 2138 2141 2139 ExportVcGeometry(exporter, vc); 2140 2141 2142 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() 2142 ExportVcGeometry(exporter, vc); 2143 2144 2145 Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() 2143 2146 << ", piercing rays=" << (int)vcRays.size() 2144 2147 << ", leaves=" << (int)vc->mLeaves.size() << endl; 2145 2148 2146 2149 //-- export rays piercing this view cell 2147 2150 #if 1 … … 2163 2166 2164 2167 // output PVS of view cell 2165 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 2168 for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 2166 2169 { 2167 2170 Intersectable *intersect = (*it).first; … … 2174 2177 exporter->ExportIntersectable(intersect); 2175 2178 intersect->Mail(); 2176 } 2177 } 2178 2179 } 2180 } 2181 2179 2182 DEL_PTR(exporter); 2180 2183 cout << "finished" << endl; … … 2188 2191 2189 2192 2190 bool VspBspViewCellsManager::ShouldMerge(BspLeaf *front, BspLeaf *back) const2191 {2192 ViewCell *fvc = front->GetViewCell();2193 ViewCell *bvc = back->GetViewCell();2194 2195 if (fvc == bvc)2196 return false;2197 2198 const int fdiff = fvc->GetPvs().Diff(bvc->GetPvs());2199 2200 if (fvc->GetPvs().GetSize() + fdiff < mMaxPvs)2201 {2202 if ((fvc->GetPvs().GetSize() < mMinPvs) ||2203 (bvc->GetPvs().GetSize() < mMinPvs) ||2204 ((fdiff < mMinPvsDif) &&2205 (bvc->GetPvs().Diff(fvc->GetPvs()) < mMinPvsDif)))2206 {2207 return true;2208 }2209 }2210 2211 return false;2212 }2213 2214 2215 2193 int VspBspViewCellsManager::CastLineSegment(const Vector3 &origin, 2216 2194 const Vector3 &termination, … … 2221 2199 2222 2200 2223 void VspBspViewCellsManager::ExportColor(Exporter *exporter, 2201 void VspBspViewCellsManager::ExportColor(Exporter *exporter, 2224 2202 ViewCell *vc) const 2225 2203 { 2226 2204 if (mColorCode == 0) // Random color 2227 2205 return; 2228 2206 2229 2207 float importance = 0; 2230 2208 … … 2233 2211 case 1: // pvs 2234 2212 { 2235 importance = (float)vc->GetPvs().GetSize() / 2213 importance = (float)vc->GetPvs().GetSize() / 2236 2214 (float)mViewCellsStats.maxPvs; 2237 2215 } … … 2241 2219 BspViewCell *bspVc = dynamic_cast<BspViewCell *>(vc); 2242 2220 2243 importance = (float)bspVc->mLeaves.size() / 2221 importance = (float)bspVc->mLeaves.size() / 2244 2222 (float)mViewCellsStats.maxLeaves; 2245 2223 } … … 2247 2225 case 3: // merge tree differene 2248 2226 { 2249 importance = (float)GetMaxTreeDiff(vc) / 2227 importance = (float)GetMaxTreeDiff(vc) / 2250 2228 (float)(mVspBspTree->GetStatistics().maxDepth * 2); 2251 2229 } … … 2264 2242 2265 2243 2266 void VspBspViewCellsManager::ExportVcGeometry(Exporter *exporter, 2244 void VspBspViewCellsManager::ExportVcGeometry(Exporter *exporter, 2267 2245 ViewCell *vc) const 2268 2246 { 2269 2247 #if 1 2248 if (vc->GetMesh()) 2249 { 2250 exporter->ExportMesh(vc->GetMesh()); 2251 return; 2252 } 2253 2270 2254 BspNodeGeometry geom; 2271 2255 mVspBspTree-> 2272 ConstructGeometry(dynamic_cast<BspViewCell *>(vc), geom .mPolys);2256 ConstructGeometry(dynamic_cast<BspViewCell *>(vc), geom); 2273 2257 exporter->ExportPolygons(geom.mPolys); 2274 2258 #else 2275 2259 2276 2260 Material m2; 2277 2261 m2.mDiffuseColor.b = 0.3f + Random(0.7f); … … 2324 2308 2325 2309 2326 2327 2328 ViewCell * 2329 VspBspViewCellsManager::GetViewCell(const Vector3 &point) 2310 ViewCell *VspBspViewCellsManager::GetViewCell(const Vector3 &point) 2330 2311 { 2331 2312 if (!mVspBspTree) … … 2333 2314 return mVspBspTree->GetViewCell(point); 2334 2315 } 2316 2317 2318 void VspBspViewCellsManager::CreateMesh(ViewCell *vc) 2319 { 2320 BspNodeGeometry geom; 2321 BspViewCell *bspVc = dynamic_cast<BspViewCell *>(vc); 2322 mVspBspTree->ConstructGeometry(bspVc, geom); 2323 2324 Mesh *mesh = new Mesh(); 2325 geom.AddToMesh(*mesh); 2326 vc->SetMesh(mesh); 2327 mMeshContainer.push_back(mesh); 2328 }
Note: See TracChangeset
for help on using the changeset viewer.