Changeset 2347
- Timestamp:
- 05/03/07 18:46:37 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r2342 r2347 53 53 /* class BvhNode implementation */ 54 54 /***************************************************************/ 55 55 56 56 57 BvhNode::BvhNode(): … … 394 395 CollectViewCells(sc.mSampledBackObjects, backViewCells, false, false); 395 396 396 const float frontTri = (float)sc.mFrontObjects.size(); 397 const float backTri = (float)sc.mBackObjects.size(); 398 const float totalTri = (float)(*sc.mParentData.mSortedObjects[0]).size(); 397 const int frontTri = (int)sc.mFrontObjects.size(); 398 const int backTri = (int)sc.mBackObjects.size(); 399 const int totalTri = (int)(*sc.mParentData.mSortedObjects[0]).size(); 400 401 //cout << "totalTri: " << totalTri << " f: " << frontTri << " back: " << backTri << endl; 399 402 400 403 ViewCell::NewMail(3); … … 405 408 for (fit = frontViewCells.begin(); fit != fit_end; ++ fit) 406 409 { 407 ViewCell *vc = *fit; 408 vc->Mail(0); 410 (*fit)->Mail(0); 409 411 } 410 412 … … 422 424 } 423 425 426 // traverse through view cells and compute changes 424 427 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 425 428 … … 428 431 ViewCell *vc = *vit; 429 432 430 float vcTri;433 int vcTri; 431 434 int vcObj; 432 435 433 float oldVcTri =vc->GetTrianglesInPvs();436 int oldVcTri = (int)vc->GetTrianglesInPvs(); 434 437 int oldVcObj = vc->GetEntriesInPvs(); 435 438 … … 445 448 else if (vc->Mailed(1)) 446 449 { 447 vcTri = oldVcTri - totalTri + backTri;450 vcTri = oldVcTri + backTri - totalTri; 448 451 vcObj = oldVcObj; 449 452 } 450 453 else // front object 451 454 { 452 vcTri = oldVcTri - totalTri + frontTri;455 vcTri = oldVcTri + frontTri - totalTri; 453 456 vcObj = oldVcObj; 454 457 } 455 458 456 vc->SetTrianglesInPvs( vcTri);459 vc->SetTrianglesInPvs((float)vcTri); 457 460 vc->SetEntriesInPvs(vcObj); 458 461 459 462 //cout << "old pvs tri: " << oldVcTri << " new: " << vcTri << endl; 460 //cout << "old pvs obj: " << oldVcObj << " new: " << vcObj<< endl; 461 } 462 } 463 //cout << "old pvs obj: " << oldVcObj << " new: " << vcObj << endl; 464 } 465 } 466 467 468 void BvHierarchy::TestEvaluation(const BvhSubdivisionCandidate &sc) 469 { 470 ViewCellContainer viewCells, frontViewCells, backViewCells; 471 472 CollectViewCells(*sc.mParentData.mSampledObjects, viewCells, false, false); 473 474 // traverse through view cells and compute changes 475 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 476 477 for (vit = viewCells.begin(); vit != viewCells.end(); ++ vit) 478 { 479 ViewCell *vc = *vit; 480 481 int vcTri; 482 int vcObj; 483 484 int oldVcTri = (int)vc->GetTrianglesInPvs(); 485 int oldVcObj = vc->GetEntriesInPvs(); 486 487 int nTriangles = 0; 488 int nObjects = 0; 489 490 Intersectable::NewMail(); 491 492 VspViewCell *vspVc = static_cast<VspViewCell *>(vc); 493 VssRayContainer::const_iterator vit, vit_end = vspVc->mLeaves[0]->mVssRays.end(); 494 495 for (vit = vspVc->mLeaves[0]->mVssRays.begin(); vit != vit_end; ++ vit) 496 { 497 VssRay *ray = *vit; 498 499 BvhLeaf *obj = ray->mTerminationObject->mBvhLeaf; 500 501 if (!obj->Mailed()) 502 { 503 obj->Mail(); 504 505 nTriangles += (int)obj->mObjects.size(); 506 nObjects ++; 507 } 508 509 if (ray->mOriginObject) 510 { 511 obj = ray->mOriginObject->mBvhLeaf; 512 513 if (!obj->Mailed()) 514 { 515 obj->Mail(); 516 nTriangles += (int)obj->mObjects.size(); 517 nObjects ++; 518 } 519 } 520 } 521 522 cout << "old pvs tri: " << oldVcTri << " real: " << nTriangles << endl; 523 cout << "old pvs obj: " << oldVcObj << " real: " << nObjects << endl; 524 } 525 } 526 463 527 464 528 … … 467 531 BvhTraversalData &backData) 468 532 { 533 //TestEvaluation(sc); 534 469 535 // fill view cells cache 470 536 mNodeTimer.Entry(); … … 627 693 AssociateViewCellsWithObjects(*tData.mSampledObjects); 628 694 695 EvalSubdivisionCandidate2(*frontCandidate, true, false); 696 cout << "\nfc2: " << frontCandidate->GetPriority() << endl; 629 697 EvalSubdivisionCandidate(*frontCandidate, true, false); 698 cout << "fc1: " << frontCandidate->GetPriority() << endl; 630 699 EvalSubdivisionCandidate(*backCandidate, true, false); 631 700 … … 680 749 BvhLeaf *leaf = splitCandidate.mParentData.mNode; 681 750 682 // surface area heuristics is used when there is 683 // no view space subdivision available. 684 // In order to have some prioritized traversal, 685 // we use this formula instead 751 // use urface area heuristics if no view space subdivision available. 752 // For prioritized traversal we use this formula instead 686 753 if (mHierarchyManager->GetViewSpaceSubdivisionType() == 687 754 HierarchyManager::NO_VIEWSPACE_SUBDIV) … … 693 760 // take render cost of node into account 694 761 // otherwise danger of being stuck in a local minimum! 695 const float factor = mRenderCostDecreaseWeight; 696 697 priority = factor * renderCostDecr + (1.0f - factor) * oldRenderCost; 762 priority = mRenderCostDecreaseWeight * renderCostDecr + 763 (1.0f - mRenderCostDecreaseWeight) * oldRenderCost; 698 764 699 765 if (mHierarchyManager->mConsiderMemory) … … 723 789 724 790 725 void BvHierarchy::EvalSubdivisionCandidate (BvhSubdivisionCandidate &splitCandidate,791 void BvHierarchy::EvalSubdivisionCandidate2(BvhSubdivisionCandidate &splitCandidate, 726 792 const bool computeSplitPlane, 727 793 const bool preprocessViewCells) … … 778 844 mEvalTimer.Entry(); 779 845 846 // mark view cells according to what part of the split they see 847 // and compute volume 780 848 ViewCellContainer viewCells, frontViewCells, backViewCells; 781 849 … … 784 852 CollectViewCells(splitCandidate.mSampledBackObjects, backViewCells, false, false); 785 853 786 // compute view cells seen from front and back side of the split787 854 float volFront = 0, volBack = 0, parentVol = 0; 788 855 … … 810 877 if (vc->Mailed(0)) 811 878 { 812 // view cell sees front AND on back side879 // view cell sees front AND back object 813 880 ++ frontAndBackViewCells; 814 881 vc->Mail(2); … … 823 890 } 824 891 825 892 //cout << "pvol: " << parentVol << " front: " << volFront << " back: " << volBack << " diff: " << parentVol - volFront - volBack << endl; 893 894 826 895 ///////////////////// 827 896 //-- this bvh node is a pvs entry in all the view cells that see one of the objects. … … 829 898 // pvs size induced by this bvh node is #view cells 830 899 const float pvs = (float)viewCells.size(); 900 901 // for low #rays per object => the result is influenced by undersampling 831 902 const float avgRaysPerObject = AvgRaysPerObject((int)pvs, tData.mNumRays); 832 833 // for low #rays per object => the result is influenced by undersampling834 903 splitCandidate.SetAvgRaysPerObject(avgRaysPerObject); 904 835 905 const float viewSpaceVol = GetViewSpaceVolume(); 836 906 … … 841 911 splitCandidate.mNumBackViewCells = (int)backViewCells.size(); 842 912 843 // currently not working!! 844 // todo matt: fix this to cope with undersampling for new evaluation method 913 914 //////////////////////// 915 // warning: currently not working for new evaluation method! 916 917 // todo matt: fix this to cope with undersampling 845 918 splitCandidate.mCorrectedFrontVolume = 846 919 mHierarchyManager->EvalCorrectedPvs(splitCandidate.mVolumeFrontViewCells, … … 858 931 float newRenderCost = 0, oldRenderCost = 0; 859 932 860 const float frontTri = (float)splitCandidate.mFrontObjects.size(); 861 const float backTri = (float)splitCandidate.mBackObjects.size(); 862 // total #triangles in parent 863 const float totalTri = (float)(*tData.mSortedObjects[0]).size(); 864 865 866 // compute render cost decrease in the seen view cells 933 // total #triangles in parent node 934 const int totalTri = (int)(*tData.mSortedObjects[0]).size(); 935 const int frontTri = (int)splitCandidate.mFrontObjects.size(); 936 const int backTri = (int)splitCandidate.mBackObjects.size(); 937 938 if (totalTri - frontTri - backTri != 0) 939 cout << "big error!!!" << endl; 940 941 // compute render cost decrease in the view cells which can see the object 867 942 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 868 943 … … 871 946 ViewCell *vc = *vit; 872 947 948 const int oldVcTri = (int)vc->GetTrianglesInPvs(); 949 const int oldVcObj = vc->GetEntriesInPvs(); 950 873 951 // triangles in this view cell 874 float vcTri;952 int vcTri; 875 953 // #entries in this view cell 876 954 int vcObj; 877 878 float oldVcTri = vc->GetTrianglesInPvs(); 879 int oldVcObj = vc->GetEntriesInPvs(); 880 955 881 956 // both nodes in this view cell 882 957 if (vc->Mailed(2)) … … 888 963 else if (vc->Mailed(1)) 889 964 { 965 // only back node in this view cell: #triangles is decreasing 966 vcTri = oldVcTri + backTri - totalTri; 967 vcObj = oldVcObj; 968 } 969 else // (vc->Mailed(0)) 970 { 890 971 // only front node in this view cell: #triangles is decreasing 891 vcTri = oldVcTri - totalTri + backTri; 892 vcObj = oldVcObj; 893 } 894 else // (vc->Mailed(0)) 895 { 896 // // only back node in this view cell: #triangles is decreasing 897 vcTri = oldVcTri - totalTri + frontTri; 972 vcTri = oldVcTri + frontTri - totalTri; 898 973 vcObj = oldVcObj; 899 974 } 900 975 901 oldRenderCost += mViewCellsManager->ComputeRenderCost((int)oldVcTri, (int)oldVcObj) * vc->GetVolume() / viewSpaceVol; 902 newRenderCost += mViewCellsManager->ComputeRenderCost((int)vcTri, (int)vcObj) * vc->GetVolume() / viewSpaceVol; 976 const float oldRc = mViewCellsManager->ComputeRenderCost(oldVcTri, oldVcObj); 977 const float newRc = mViewCellsManager->ComputeRenderCost(vcTri, vcObj); 978 979 // compute weighted render cost 980 oldRenderCost += oldRc * vc->GetVolume() / viewSpaceVol; 981 newRenderCost += newRc * vc->GetVolume() / viewSpaceVol; 903 982 //cout << "old rc=" << oldRenderCost << " new rc " << newRenderCost << endl; 904 983 } 905 984 985 986 const float dummyFrontVol = EvalViewCellsVolume(splitCandidate.mSampledFrontObjects) / viewSpaceVol; 987 const float dummyBackVol = EvalViewCellsVolume(splitCandidate.mSampledBackObjects) / viewSpaceVol; 988 const float dummyParentVol = EvalViewCellsVolume(leaf->mObjects) / viewSpaceVol; 989 990 const int dummyNumFrontViewCells = CountViewCells(splitCandidate.mSampledFrontObjects); 991 const int dummyNumBackViewCells = CountViewCells(splitCandidate.mSampledBackObjects); 992 const int dummyPvs = CountViewCells(*tData.mSampledObjects); 993 994 const int dummyPvsEntriesIncr = - dummyPvs + dummyNumFrontViewCells + dummyNumBackViewCells; 995 996 const float relfrontCost = dummyFrontVol * (float)splitCandidate.mFrontObjects.size(); 997 const float relBackCost = dummyBackVol * (float)splitCandidate.mBackObjects.size(); 998 const float relParentCost = dummyParentVol * (float)leaf->mObjects.size(); 999 906 1000 // compute global decrease in render cost 907 const float renderCostDecr = (oldRenderCost - newRenderCost); 908 909 // for each view cell seen from front and back there is a new entry 910 const int pvsEntriesIncr = frontAndBackViewCells; 911 1001 const float dummyNewRenderCost = relfrontCost + relBackCost; 1002 const float dummyRenderCostDecr = relParentCost - dummyNewRenderCost; 1003 1004 1005 1006 // compute global decrease in render cost 1007 const float renderCostDecr = oldRenderCost - newRenderCost; 1008 1009 // for each view cell seeing both front and back object there is a new pvs entry 1010 splitCandidate.SetPvsEntriesIncr(frontAndBackViewCells); 912 1011 splitCandidate.SetRenderCostDecrease(renderCostDecr); 1012 1013 float pseudoOldRenderCost = parentVol * (float)leaf->mObjects.size() / viewSpaceVol; 1014 1015 //cout << "cor. entries: " << dummyPvsEntriesIncr << " entries: " << frontAndBackViewCells << endl; 1016 cout << "\nv1: " << renderCostDecr << " " << pseudoOldRenderCost << " " << newRenderCost << endl; 1017 cout << "v2: " << dummyRenderCostDecr << " " << relParentCost << " " << dummyNewRenderCost << endl; 1018 1019 // at last computed priority based on render cost reduction / memory increase 1020 const float priority = EvalPriority(splitCandidate, renderCostDecr, pseudoOldRenderCost); 1021 cout << "\nfc0: " << priority << endl; 1022 const float priority2 = EvalPriority(splitCandidate, dummyRenderCostDecr, relParentCost); 1023 splitCandidate.SetPriority(priority2); 1024 1025 #if STORE_VIEWCELLS_WITH_BVH 1026 if (preprocessViewCells) 1027 ReleaseViewCells(*splitCandidate.mParentData.mSampledObjects); 1028 #endif 1029 1030 mEvalTimer.Exit(); 1031 } 1032 1033 1034 void BvHierarchy::EvalSubdivisionCandidate(BvhSubdivisionCandidate &splitCandidate, 1035 const bool computeSplitPlane, 1036 const bool preprocessViewCells) 1037 { 1038 mPlaneTimer.Entry(); 1039 1040 #if STORE_VIEWCELLS_WITH_BVH 1041 if (preprocessViewCells) // fill view cells cache 1042 AssociateViewCellsWithObjects(*splitCandidate.mParentData.mSampledObjects); 1043 #endif 1044 1045 if (computeSplitPlane) 1046 { 1047 splitCandidate.mFrontObjects.clear(); 1048 splitCandidate.mBackObjects.clear(); 1049 splitCandidate.mSampledFrontObjects.clear(); 1050 splitCandidate.mSampledBackObjects.clear(); 1051 1052 const bool sufficientSamples = 1053 splitCandidate.mParentData.mNumRays > mMinRaysForVisibility; 1054 1055 //if (!sufficientSamples) cout << splitCandidate.mParentData.mNumRays << " "; 1056 1057 const bool useVisibiliyBasedHeuristics = 1058 !mUseSah && 1059 (mHierarchyManager->GetViewSpaceSubdivisionType() == 1060 HierarchyManager::KD_BASED_VIEWSPACE_SUBDIV) && 1061 sufficientSamples; 1062 1063 // compute best object partition 1064 const float ratio = SelectObjectPartition(splitCandidate.mParentData, 1065 splitCandidate.mFrontObjects, 1066 splitCandidate.mBackObjects, 1067 useVisibiliyBasedHeuristics); 1068 1069 // cost ratio violated? 1070 const bool maxCostRatioViolated = mTermMaxCostRatio < ratio; 1071 const int previousMisses = splitCandidate.mParentData.mMaxCostMisses; 1072 1073 splitCandidate.SetMaxCostMisses(maxCostRatioViolated ? 1074 previousMisses + 1 : previousMisses); 1075 1076 StoreSampledObjects(splitCandidate.mSampledFrontObjects, splitCandidate.mFrontObjects); 1077 StoreSampledObjects(splitCandidate.mSampledBackObjects, splitCandidate.mBackObjects); 1078 } 1079 1080 mPlaneTimer.Exit(); 1081 1082 mEvalTimer.Entry(); 1083 1084 const BvhTraversalData &tData = splitCandidate.mParentData; 1085 BvhLeaf *leaf = tData.mNode; 1086 1087 // avg contribution of a ray to a pvs 1088 const float pvs = (float)CountViewCells(*tData.mSampledObjects); 1089 //const float avgRayContri = AvgRayContribution((int)pvs, tData.mNumRays); 1090 const float avgRaysPerObject = AvgRaysPerObject((int)pvs, tData.mNumRays); 1091 1092 // high avg ray contri, the result is influenced by undersampling 1093 splitCandidate.SetAvgRaysPerObject(avgRaysPerObject); 1094 const float viewSpaceVol = GetViewSpaceVolume(); 1095 1096 const float oldVolume = EvalViewCellsVolume(*tData.mSampledObjects) / viewSpaceVol; 1097 const float oldRatio = (tData.mVolume > 0) ? oldVolume / tData.mVolume : 1; 1098 const float parentVol = tData.mCorrectedVolume * oldRatio; 1099 1100 // this leaf is a pvs entry in all the view cells 1101 // that see one of the objects. 1102 splitCandidate.mVolumeFrontViewCells = EvalViewCellsVolume(splitCandidate.mSampledFrontObjects) / viewSpaceVol; 1103 splitCandidate.mVolumeBackViewCells = EvalViewCellsVolume(splitCandidate.mSampledBackObjects) / viewSpaceVol; 1104 1105 splitCandidate.mNumFrontViewCells = CountViewCells(splitCandidate.mSampledFrontObjects); 1106 splitCandidate.mNumBackViewCells = CountViewCells(splitCandidate.mSampledBackObjects); 1107 1108 splitCandidate.mCorrectedFrontVolume = 1109 mHierarchyManager->EvalCorrectedPvs(splitCandidate.mVolumeFrontViewCells, parentVol, avgRaysPerObject); 1110 1111 splitCandidate.mCorrectedBackVolume = 1112 mHierarchyManager->EvalCorrectedPvs(splitCandidate.mVolumeBackViewCells, parentVol, avgRaysPerObject); 1113 1114 #if 0 1115 const float relfrontCost = splitCandidate.mCorrectedFrontVolume * splitCandidate.mFrontObjects.size(); 1116 const float relBackCost = splitCandidate.mCorrectedBackVolume * splitCandidate.mBackObjects.size(); 1117 const float relParentCost = parentVol * leaf->mObjects.size(); 1118 #else 1119 const float relfrontCost = splitCandidate.mVolumeFrontViewCells * splitCandidate.mFrontObjects.size(); 1120 const float relBackCost = splitCandidate.mVolumeBackViewCells * splitCandidate.mBackObjects.size(); 1121 const float relParentCost = oldVolume * leaf->mObjects.size(); 1122 #endif 1123 // compute global decrease in render cost 1124 const float newRenderCost = relfrontCost + relBackCost; 1125 const float renderCostDecr = relParentCost - newRenderCost; 1126 1127 splitCandidate.SetRenderCostDecrease(renderCostDecr); 1128 1129 // increase in pvs entries 1130 const int pvsEntriesIncr = EvalPvsEntriesIncr(splitCandidate, 1131 avgRaysPerObject, 1132 (int)pvs, 1133 splitCandidate.mNumFrontViewCells, 1134 splitCandidate.mNumBackViewCells); 1135 913 1136 splitCandidate.SetPvsEntriesIncr(pvsEntriesIncr); 914 1137 915 //cout << "bvh render cost decrease=" << renderCostDecr << endl; 916 917 // at last computed priority based on render cost reduction / memory increase 918 const float priority = EvalPriority(splitCandidate, renderCostDecr, oldRenderCost); 1138 #ifdef GTP_DEBUG 1139 Debug << "old render cost: " << oldRenderCost << endl; 1140 Debug << "new render cost: " << newRenderCost << endl; 1141 Debug << "render cost decrease: " << renderCostDecr << endl; 1142 #endif 1143 1144 float priority = EvalPriority(splitCandidate, 1145 renderCostDecr, 1146 relParentCost); 1147 1148 // compute global decrease in render cost 919 1149 splitCandidate.SetPriority(priority); 920 1150 … … 948 1178 mHierarchyManager->EvalCorrectedPvs((float)backViewCells, parentPvs, avgRaysPerObjects); 949 1179 950 if (0) 951 cout << "bvh pvs" 952 << " avg ray contri: " << avgRaysPerObjects << " ratio: " << oldPvsRatio 953 << " parent: " << parentPvs << " " << " old vol: " << oldPvsSize 954 << " frontpvs: " << frontViewCells << " corr. " << splitCandidate.mCorrectedFrontPvs 955 << " backpvs: " << frontViewCells << " corr. " << splitCandidate.mCorrectedBackPvs << endl; 1180 #if GTP_DEBUG 1181 Debug << "bvh node pvs" 1182 << " avg ray contri: " << avgRaysPerObjects << " ratio: " << oldPvsRatio 1183 << " parent: " << parentPvs << " " << " old vol: " << oldPvsSize 1184 << " frontpvs: " << frontViewCells << " corr. " << splitCandidate.mCorrectedFrontPvs 1185 << " backpvs: " << frontViewCells << " corr. " << splitCandidate.mCorrectedBackPvs << endl; 1186 #endif 956 1187 957 1188 return (int)(splitCandidate.mCorrectedFrontPvs + splitCandidate.mCorrectedBackPvs - parentPvs); … … 971 1202 if (terminationCriteriaMet) 972 1203 { 973 cout<< "bvh local termination criteria met:" << endl;974 cout<< "objects: " << (int)tData.mNode->mObjects.size() << " (" << mTermMinObjects << ")" << endl;1204 Debug << "bvh local termination criteria met:" << endl; 1205 Debug << "objects: " << (int)tData.mNode->mObjects.size() << " (" << mTermMinObjects << ")" << endl; 975 1206 } 976 1207 #endif … … 1011 1242 ++ mCreatedLeaves; 1012 1243 1013 1014 /*if (data.mProbability <= mTermMinProbability) 1015 { 1016 ++ mBvhStats.minProbabilityNodes; 1017 }*/ 1018 1019 //////////////////////////////////////////// 1244 //////////////// 1020 1245 // depth related stuff 1021 1246 … … 1034 1259 1035 1260 1036 ////////////////////// //////////////////////1261 ////////////////////// 1037 1262 // objects related stuff 1038 1263 … … 1082 1307 1083 1308 #ifdef _DEBUG 1084 cout<< "depth: " << data.mDepth << " objects: " << (int)leaf->mObjects.size()1085 << " rays: " << data.mNumRays << " rays / objects "1086 << (float)data.mNumRays / (float)leaf->mObjects.size() << endl;1309 Debug << "depth: " << data.mDepth << " objects: " << (int)leaf->mObjects.size() 1310 << " rays: " << data.mNumRays << " rays / objects " 1311 << (float)data.mNumRays / (float)leaf->mObjects.size() << endl; 1087 1312 #endif 1088 1313 } … … 1128 1353 1129 1354 const float oldRenderCost = (float)tData.mNode->mObjects.size() * parentBox.SurfaceArea(); 1130 const float newRenderCost = (float)objectsFront.size() * fbox.SurfaceArea() + 1355 const float newRenderCost = (float)objectsFront.size() * fbox.SurfaceArea() + (float)objectsBack.size() * bbox.SurfaceArea(); 1131 1356 1132 1357 const float ratio = newRenderCost / oldRenderCost; … … 1301 1526 1302 1527 #ifdef GTP_DEBUG 1303 cout<< "\n\nobjects=(" << (int)objectsBack.size() << "," << (int)objectsFront.size() << " of "1304 << (int)tData.mNode->mObjects.size() << ")\t area=("1305 << areaLeft << ", " << areaRight << ", " << boxArea << ")" << endl1306 << "cost= " << newCost << " oldCost=" << totalRenderCost / boxArea << endl;1528 Debug << "\n\nobjects=(" << (int)objectsBack.size() << "," << (int)objectsFront.size() << " of " 1529 << (int)tData.mNode->mObjects.size() << ")\t area=(" 1530 << areaLeft << ", " << areaRight << ", " << boxArea << ")" << endl 1531 << "cost= " << newCost << " oldCost=" << totalRenderCost / boxArea << endl; 1307 1532 #endif 1308 1533 … … 1435 1660 1436 1661 #ifdef GTP_DEBUG 1437 cout<< "\n\nobjects=(" << (int)objectsBack.size() << "," << (int)objectsFront.size() << " of "1438 << (int)tData.mNode->mObjects.size() << ")\t area=("1439 << areaLeft << ", " << areaRight << ", " << boxArea << ")" << endl1440 << "cost= " << newCost << " oldCost=" << totalRenderCost / boxArea << endl;1662 Debug << "\n\nobjects=(" << (int)objectsBack.size() << "," << (int)objectsFront.size() << " of " 1663 << (int)tData.mNode->mObjects.size() << ")\t area=(" 1664 << areaLeft << ", " << areaRight << ", " << boxArea << ")" << endl 1665 << "cost= " << newCost << " oldCost=" << totalRenderCost / boxArea << endl; 1441 1666 #endif 1442 1667 … … 1495 1720 ObjectContainer &objectsBack) 1496 1721 { 1497 //////// /////////////////////////////////////1498 // -- go through the lists, count the number of objects1499 // --left and right and evaluate the cost funcion1722 //////// 1723 // traverse split candidates, count the number of objects 1724 // left and right and evaluate the cost funcion 1500 1725 1501 1726 // prepare the heuristics, set mailboxes and counters … … 1603 1828 1604 1829 #ifdef GTP_DEBUG 1605 Debug << "\n §§§§ bvh eval const decrease §§§§" << endl1830 Debug << "\neval bvh split cost decrease" << endl 1606 1831 << "back pvs: " << (int)objectsBack.size() << " front pvs: " 1607 1832 << (int)objectsFront.size() << " total pvs: " << nTotalObjects << endl … … 1713 1938 } 1714 1939 1940 1941 1715 1942 /////////////////////////////////////////////////////////// 1716 1943 1717 1944 1718 void BvHierarchy::EvalHeuristicsContribution(Intersectable *obj, 1945 void BvHierarchy::EvalHeuristicsContribution(Intersectable *obj, 1719 1946 float &volLeft, 1720 1947 float &volRight) … … 1804 2031 } 1805 2032 1806 // if #rays high consider only use a subset of the rays for2033 // if #rays high, consider only use a subset of the rays for 1807 2034 // visibility based heuristics 1808 2035 VssRay::NewMail(); 1809 2036 1810 /*if ((mMaxTests < tData.mNumRays) && mUseCostHeuristics && useVisibilityBasedHeuristics)1811 {1812 VssRayContainer rays;1813 1814 // maximal 2 objects share the same ray1815 rays.reserve(tData.mNumRays * 2);1816 CollectRays(tData.mNode->mObjects, rays);1817 1818 const float prop = (float)mMaxTests / (float)rays.size();1819 1820 VssRayContainer::const_iterator rit, rit_end = rays.end();1821 1822 // mail rays which will not be considered1823 for (rit = rays.begin(); rit != rit_end; ++ rit)1824 {1825 if (Random(1.0f) > prop)1826 {1827 (*rit)->Mail();1828 }1829 }1830 }*/1831 2037 1832 2038 //////////////////////////////////// … … 1992 2198 //-- surface area heuristics 1993 2199 1994 // eraly exit1995 //if (leaf->mObjects.empty()) return 0.0f;1996 1997 2200 const AxisAlignedBox3 box = GetBoundingBox(leaf); 1998 2201 const float area = box.SurfaceArea(); … … 2854 3057 backData.mSortedObjects[i] = new ObjectContainer(); 2855 3058 2856 frontData.mSortedObjects[i]->reserve( (int)sc.mFrontObjects.size());2857 backData.mSortedObjects[i]->reserve( (int)sc.mBackObjects.size());3059 frontData.mSortedObjects[i]->reserve(sc.mFrontObjects.size()); 3060 backData.mSortedObjects[i]->reserve(sc.mBackObjects.size()); 2858 3061 2859 3062 ObjectContainer::const_iterator oit, oit_end = sc.mParentData.mSortedObjects[i]->end(); -
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
r2332 r2347 579 579 const bool preprocessViewCells); 580 580 581 void EvalSubdivisionCandidate2(BvhSubdivisionCandidate &splitData, 582 const bool computeSplitPlane, 583 const bool preprocessViewCells); 584 581 585 /** Returns vector of leaves. 582 586 */ … … 990 994 991 995 void UpdateViewCells(const BvhSubdivisionCandidate &sc); 996 void TestEvaluation(const BvhSubdivisionCandidate &sc); 992 997 993 998 -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
r2342 r2347 49 49 #define USE_AVGRAYCONTRI 0 50 50 51 #define BOUND_RENDERCOST 052 53 static const float MIN_RENDERCOST = 100.0f;54 55 51 56 52 -
GTP/trunk/Lib/Vis/Preprocessing/src/RayInfo.cpp
r2332 r2347 109 109 110 110 111 112 113 111 void GetRayInfoSets(const RayInfoContainer &sourceRays, 114 112 const int maxSize, -
GTP/trunk/Lib/Vis/Preprocessing/src/RayInfo.h
r2332 r2347 120 120 } 121 121 122 123 122 124 #if USE_FIXEDPOINT_T 123 125 float RayInfo::GetMinT () const -
GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj
r2342 r2347 226 226 Name="VCLinkerTool" 227 227 AdditionalDependencies="xerces-c_2.lib glew32.lib zdll.lib zziplib.lib devil.lib glut32.lib OpenGL32.Lib glu32.lib Preprocessor.lib RTScene.lib RTWorld.lib" 228 OutputFile="../bin/release/Preprocessor .exe"228 OutputFile="../bin/release/Preprocessor2.exe" 229 229 LinkIncremental="1" 230 230 AdditionalLibraryDirectories="..\src\GL;..\lib\release;..\..\Preprocessing\lib\release;..\..\..\..\..\..\NonGTP\Boost\lib;..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\..\..\..\NonGTP\Zlib\lib;..\..\..\..\..\..\NonGTP\Devil\lib;..\MultiLevelRayTracing\RTScene\Release;..\MultiLevelRayTracing\RTWorld\Release" -
GTP/trunk/Lib/Vis/Preprocessing/src/Trackball.cpp
r2332 r2347 60 60 * Programmer. 61 61 */ 62 #define TRACKBALLSIZE (0.8 )62 #define TRACKBALLSIZE (0.8f) 63 63 64 64 /* -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r2342 r2347 1708 1708 1709 1709 1710 1711 1710 float ViewCellsManager::ComputeRenderCost(const int tri, const int obj) //const 1712 1711 { 1712 return (float)tri; 1713 1713 return max((float)tri * mTriangleWeight, (float)obj * mObjectWeight); 1714 1714 } … … 2087 2087 sum += ComputeSampleContribution(*(*it), addContributions, storeViewCells, useHitObjects); 2088 2088 } 2089 2090 2089 } 2091 2090 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
r2283 r2347 1066 1066 1067 1067 // max cost threshold violated? 1068 splitCandidate.mMaxCostMisses = costRatioViolated ? 1069 splitCandidate.mParentData.mMaxCostMisses : 1070 splitCandidate.mParentData.mMaxCostMisses + 1; 1068 splitCandidate.mMaxCostMisses = costRatioViolated ? splitCandidate.mParentData.mMaxCostMisses : 1069 splitCandidate.mParentData.mMaxCostMisses + 1; 1071 1070 1072 1071 float oldRenderCost; -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
r2342 r2347 31 31 #define HACK_PERFORMANCE 1 32 32 33 #define HAS_TO_BE_REDONE 0 33 34 34 35 ///////////// … … 258 259 { 259 260 VssRayContainer::const_iterator vit, vit_end = mVssRays.end(); 261 260 262 for (vit = mVssRays.begin(); vit != vit_end; ++ vit) 261 263 { … … 266 268 delete ray; 267 269 } 268 //CLEAR_CONTAINER(mVssRays);269 270 } 270 271 … … 312 313 mRoot(NULL), 313 314 mOutOfBoundsCell(NULL), 314 mStoreRays(false), 315 //mStoreRays(false), 316 mStoreRays(true), 315 317 mTimeStamp(1), 316 318 mHierarchyManager(NULL) … … 554 556 if (updatePvs) 555 557 { 556 // update pvs of view cell558 // store pvs of view cell 557 559 AddSamplesToPvs(leaf, *tData.mRays, sampCon, conSamp); 558 560 … … 579 581 //-- store sampling rays 580 582 581 RayInfoContainer::const_iterator it, it_end = tData.mRays->end(); 582 583 for (it = tData.mRays->begin(); it != it_end; ++ it) 584 { 585 (*it).mRay->Ref(); 583 RayInfoContainer::const_iterator rit, rit_end = tData.mRays->end(); 584 585 for (rit = tData.mRays->begin(); rit != rit_end; ++ rit) 586 { 587 VssRay *ray = new VssRay(*(*rit).mRay); 588 ray->Ref(); 589 586 590 // note: should rather store rays with view cell 587 leaf->mVssRays.push_back( (*it).mRay);591 leaf->mVssRays.push_back(ray); 588 592 } 589 593 } … … 668 672 { 669 673 VspLeaf *leaf = static_cast<VspLeaf *>(newNode); 670 671 #if 0 672 ///////////// 673 //-- store pvs optained from rays 674 675 // view cell is created during subdivision 676 ViewCell *viewCell = leaf->GetViewCell(); 677 678 int conSamp = 0; 679 float sampCon = 0.0f; 680 681 AddSamplesToPvs(leaf, *tData.mRays, sampCon, conSamp); 682 683 // update scalar pvs size value 684 ObjectPvs &pvs = viewCell->GetPvs(); 685 mViewCellsManager->UpdateScalarPvsSize(viewCell, pvs.EvalPvsCost(), pvs.GetSize()); 686 687 mVspStats.contributingSamples += conSamp; 688 mVspStats.sampleContributions += (int)sampCon; 689 #endif 690 if (mStoreRays) 674 675 if (0 && mStoreRays) 691 676 { 692 677 ////////// 693 678 //-- store rays piercing this view cell 679 694 680 RayInfoContainer::const_iterator it, it_end = tData.mRays->end(); 695 681 for (it = tData.mRays->begin(); it != it_end; ++ it) … … 697 683 (*it).mRay->Ref(); 698 684 leaf->mVssRays.push_back((*it).mRay); 699 //leaf->mVssRays.push_back(new VssRay(*(*it).mRay));700 685 } 701 686 } … … 753 738 RayInfoContainer::const_iterator rit, rit_end = splitCandidate.mParentData.mRays->end(); 754 739 755 float frontTriangles = 0, backTriangles = 0, totalTriangles = 0; 756 int frontObjects = 0, backObjects = 0, totalObjects = 0; 740 SplitData sData; 757 741 758 742 Intersectable::NewMail(3); … … 779 763 // evaluate contribution of ray endpoint to front 780 764 // and back pvs with respect to the classification 781 UpdateContributionsToPvs(leaf, cf, 782 frontTriangles, backTriangles, totalTriangles, 783 frontObjects, backObjects, totalObjects); 765 UpdateContributionsToPvs(leaf, cf, sData); 784 766 785 767 #if COUNT_ORIGIN_OBJECTS … … 791 773 leaf = mBvHierarchy->GetLeaf(obj); 792 774 793 UpdateContributionsToPvs(leaf, cf, 794 frontTriangles, backTriangles, totalTriangles, 795 frontObjects, backObjects, totalObjects); 775 UpdateContributionsToPvs(leaf, cf, sData); 796 776 } 797 777 #endif … … 802 782 } 803 783 804 const float totalRenderCost = mViewCellsManager->ComputeRenderCost((int)totalTriangles, totalObjects);805 const float backRenderCost = mViewCellsManager->ComputeRenderCost((int)backTriangles, backObjects);806 const float frontRenderCost = mViewCellsManager->ComputeRenderCost((int)frontTriangles, frontObjects);784 sData.mTotalRenderCost = mViewCellsManager->ComputeRenderCost(sData.mTotalTriangles, sData.mTotalObjects); 785 sData.mBackRenderCost = mViewCellsManager->ComputeRenderCost(sData.mBackTriangles, sData.mBackObjects); 786 sData.mFrontRenderCost = mViewCellsManager->ComputeRenderCost(sData.mFrontTriangles, sData.mFrontObjects); 807 787 808 788 … … 810 790 // avg ray contri 811 791 812 const float avgRayContri = (float) totalObjects /792 const float avgRayContri = (float)sData.mTotalObjects / 813 793 ((float)splitCandidate.mParentData.mRays->size() + Limits::Small); 814 794 815 splitCandidate.SetAvgRayContribution(avgRayContri);816 817 const float avgRaysPerObject = 818 (float)splitCandidate.mParentData.mRays->size() / ((float)totalTriangles + Limits::Small);795 const float avgRaysPerObject = (float)splitCandidate.mParentData.mRays->size() / 796 ((float)sData.mTotalObjects + Limits::Small); 797 798 //cout << "avg rays per obj: " << avgRaysPerObject << endl; 819 799 820 800 splitCandidate.SetAvgRayContribution(avgRayContri); 821 801 splitCandidate.SetAvgRaysPerObject(avgRaysPerObject); 822 823 802 824 803 // todo: compute old render cost in the function 825 804 // using michi's render cost evaluation 826 805 float oldRenderCost; 827 const float renderCostDecr = EvalRenderCostDecrease(splitCandidate, 828 oldRenderCost, 829 totalRenderCost, 830 frontRenderCost, 831 backRenderCost); 832 806 const float renderCostDecr = EvalRenderCostDecrease(splitCandidate, oldRenderCost, sData); 833 807 splitCandidate.SetRenderCostDecrease(renderCostDecr); 834 808 835 809 // the increase in pvs entries num induced by this split 836 const int pvsEntriesIncr = EvalPvsEntriesIncr(splitCandidate, totalObjects, frontObjects, backObjects);810 const int pvsEntriesIncr = EvalPvsEntriesIncr(splitCandidate, sData); 837 811 splitCandidate.SetPvsEntriesIncr(pvsEntriesIncr); 838 812 839 splitCandidate.mFrontTriangles = frontTriangles;840 splitCandidate.mBackTriangles = backTriangles;813 splitCandidate.mFrontTriangles = (float)sData.mFrontTriangles; 814 splitCandidate.mBackTriangles = (float)sData.mBackTriangles; 841 815 842 816 // take render cost of node into account … … 857 831 858 832 int VspTree::EvalPvsEntriesIncr(VspSubdivisionCandidate &splitCandidate, 859 const int oldPvsSize, 860 const int fPvsSize, 861 const int bPvsSize) const 862 { 863 864 RayInfoContainer::const_iterator rit, rit_end = splitCandidate.mParentData.mRays->end(); 865 833 const SplitData &sData) const 834 { 866 835 const float oldPvsRatio = (splitCandidate.mParentData.mPvs > 0) ? 867 oldPvsSize/ splitCandidate.mParentData.mPvs : 1;836 sData.mTotalObjects / splitCandidate.mParentData.mPvs : 1; 868 837 const float correctedOldPvs = splitCandidate.mParentData.mCorrectedPvs * oldPvsRatio; 869 838 870 839 splitCandidate.mCorrectedFrontPvs = 871 mHierarchyManager->EvalCorrectedPvs((float) fPvsSize,840 mHierarchyManager->EvalCorrectedPvs((float)sData.mFrontObjects, 872 841 (float)correctedOldPvs, 873 842 splitCandidate.GetAvgRaysPerObject()); 874 843 splitCandidate.mCorrectedBackPvs = 875 mHierarchyManager->EvalCorrectedPvs((float) bPvsSize,844 mHierarchyManager->EvalCorrectedPvs((float)sData.mBackObjects, 876 845 (float)correctedOldPvs, 877 846 splitCandidate.GetAvgRaysPerObject()); 878 847 879 splitCandidate.mFrontPvs = (float) fPvsSize;880 splitCandidate.mBackPvs = (float) bPvsSize;881 882 #if TODO848 splitCandidate.mFrontPvs = (float)sData.mFrontObjects; 849 splitCandidate.mBackPvs = (float)sData.mBackObjects; 850 851 #if HAS_TO_BE_REDONE 883 852 return (int)(splitCandidate.mCorrectedFrontPvs + splitCandidate.mCorrectedBackPvs - correctedOldPvs); 884 853 #else 885 return fPvsSize + bPvsSize - oldPvsSize;854 return sData.mFrontObjects + sData.mBackObjects - sData.mTotalObjects; 886 855 #endif 887 856 } … … 1038 1007 ++ contributingSamples; 1039 1008 } 1040 1041 // store rays for visualization1042 if (0) leaf->mVssRays.push_back(new VssRay(*ray));1043 1009 } 1044 1010 } … … 1475 1441 1476 1442 exporter->SetForcedMaterial(m); 1477 1478 1443 exporter->ExportIntersectable(leaf); 1479 1444 … … 1505 1470 1506 1471 #ifdef GTP_DEBUG 1507 cout << "\n((((( eval localcost )))))" << endl1472 Debug << "\n((((( eval local vsp cost )))))" << endl 1508 1473 << "back pvs: " << penaltyBack << " front pvs: " << penaltyFront << " total pvs: " << penaltyOld << endl 1509 1474 << "back p: " << pBack * volRatio << " front p " << pFront * volRatio << " p: " << pOverall * volRatio << endl … … 1626 1591 float VspTree::EvalRenderCostDecrease(VspSubdivisionCandidate &sc, 1627 1592 float &normalizedOldRenderCost, 1628 const float totalRenderCost, 1629 const float frontRenderCost, 1630 const float backRenderCost) const 1593 const SplitData &sData) const 1631 1594 { 1632 1595 const float viewSpaceVol = mBoundingBox.GetVolume(); … … 1655 1618 1656 1619 // ratio of how render cost changed since last evaluation 1657 const float oldRenderCostRatio = (tData.mRenderCost > 0)? ( totalRenderCost / tData.mRenderCost) : 1;1620 const float oldRenderCostRatio = (tData.mRenderCost > 0)? (sData.mTotalRenderCost / tData.mRenderCost) : 1; 1658 1621 const float penaltyOld = tData.mCorrectedRenderCost * oldRenderCostRatio; 1659 1622 1660 sc.mCorrectedFrontRenderCost = mHierarchyManager->EvalCorrectedPvs( frontRenderCost, penaltyOld, avgRaysPerObject);1661 sc.mCorrectedBackRenderCost = mHierarchyManager->EvalCorrectedPvs( backRenderCost, penaltyOld, avgRaysPerObject);1662 1663 sc.mFrontRenderCost = frontRenderCost;1664 sc.mBackRenderCost = backRenderCost;1665 1666 #if TODO// undersampling evalution does not work yet1623 sc.mCorrectedFrontRenderCost = mHierarchyManager->EvalCorrectedPvs(sData.mFrontRenderCost, penaltyOld, avgRaysPerObject); 1624 sc.mCorrectedBackRenderCost = mHierarchyManager->EvalCorrectedPvs(sData.mBackRenderCost, penaltyOld, avgRaysPerObject); 1625 1626 sc.mFrontRenderCost = sData.mFrontRenderCost; 1627 sc.mBackRenderCost = sData.mBackRenderCost; 1628 1629 #if HAS_TO_BE_REDONE // undersampling evalution does not work yet 1667 1630 1668 1631 const float oldRenderCost = penaltyOld * pOverall; … … 1672 1635 #else 1673 1636 1674 const float oldRenderCost = totalRenderCost * pOverall;1675 const float newRenderCost = frontRenderCost * pFront + backRenderCost * pBack;1637 const float oldRenderCost = sData.mTotalRenderCost * pOverall; 1638 const float newRenderCost = sData.mFrontRenderCost * pFront + sData.mBackRenderCost * pBack; 1676 1639 1677 1640 #endif … … 1682 1645 // the render cost decrase for this split 1683 1646 const float renderCostDecrease = (oldRenderCost - newRenderCost) / viewSpaceVol; 1647 1648 //cout << "old: " << normalizedOldRenderCost << " new: " << newRenderCost / viewSpaceVol << " corr: " << tData.mCorrectedRenderCost << " ratio: " << oldRenderCostRatio << endl; 1684 1649 1685 1650 return renderCostDecrease; … … 1834 1799 void VspTree::UpdateContributionsToPvs(BvhLeaf *leaf, 1835 1800 const int cf, 1836 float &frontPvs, 1837 float &backPvs, 1838 float &totalPvs, 1839 int &frontSize, 1840 int &backSize, 1841 int &totalSize) const 1842 { 1843 const float triSize = (float)leaf->mObjects.size(); 1801 SplitData &sData) const 1802 { 1803 const int triSize = (int)leaf->mObjects.size(); 1844 1804 1845 1805 // object in no pvs => count as new 1846 1806 if (!leaf->Mailed() && !leaf->Mailed(1) && !leaf->Mailed(2)) 1847 1807 { 1848 totalPvs +=triSize;1849 ++ totalSize;1808 sData.mTotalTriangles += (int)triSize; 1809 ++ sData.mTotalObjects; 1850 1810 } 1851 1811 … … 1854 1814 if (!leaf->Mailed() && !leaf->Mailed(2)) 1855 1815 { 1856 frontPvs += triSize;1857 ++ frontSize;1816 sData.mFrontTriangles += triSize; 1817 ++ sData.mFrontObjects; 1858 1818 1859 1819 // already in back pvs => in both pvss … … 1869 1829 if (!leaf->Mailed(1) && !leaf->Mailed(2)) 1870 1830 { 1871 backPvs += triSize;1872 ++ backSize;1831 sData.mBackTriangles += triSize; 1832 ++ sData.mBackObjects; 1873 1833 1874 1834 // already in front pvs => in both pvss … … 2044 2004 2045 2005 2046 void VspTree::CollapseViewCells() 2047 { 2048 // TODO matt 2049 #if HAS_TO_BE_REDONE 2050 stack<VspNode *> nodeStack; 2051 2006 void VspTree::CollectRays(VssRayContainer &rays) 2007 { 2008 vector<VspLeaf *> leaves; 2009 CollectLeaves(leaves); 2010 2011 vector<VspLeaf *>::const_iterator lit, lit_end = leaves.end(); 2012 2013 for (lit = leaves.begin(); lit != lit_end; ++ lit) 2014 { 2015 VspLeaf *leaf = *lit; 2016 VssRayContainer::const_iterator rit, rit_end = leaf->mVssRays.end(); 2017 2018 for (rit = leaf->mVssRays.begin(); rit != rit_end; ++ rit) 2019 rays.push_back(*rit); 2020 } 2021 } 2022 2023 2024 void VspTree::SetViewCellsManager(ViewCellsManager *vcm) 2025 { 2026 mViewCellsManager = vcm; 2027 } 2028 2029 2030 void VspTree::ValidateTree() 2031 { 2052 2032 if (!mRoot) 2053 2033 return; 2054 2034 2035 mVspStats.invalidLeaves = 0; 2036 stack<VspNode *> nodeStack; 2037 2055 2038 nodeStack.push(mRoot); 2056 2039 2057 2040 while (!nodeStack.empty()) 2058 2041 { … … 2061 2044 2062 2045 if (node->IsLeaf()) 2063 { 2064 BspViewCell *viewCell = static_cast<VspLeaf *>(node)->GetViewCell(); 2065 2066 if (!viewCell->GetValid()) 2067 { 2068 BspViewCell *viewCell = static_cast<VspLeaf *>(node)->GetViewCell(); 2069 2070 ViewCellContainer leaves; 2071 mViewCellsTree->CollectLeaves(viewCell, leaves); 2072 2073 ViewCellContainer::const_iterator it, it_end = leaves.end(); 2074 2075 for (it = leaves.begin(); it != it_end; ++ it) 2076 { 2077 VspLeaf *l = static_cast<BspViewCell *>(*it)->mLeaf; 2078 l->SetViewCell(GetOrCreateOutOfBoundsCell()); 2079 ++ mVspStats.invalidLeaves; 2080 } 2081 2082 // add to unbounded view cell 2083 ViewCell *outOfBounds = GetOrCreateOutOfBoundsCell(); 2084 outOfBounds->GetPvs().AddPvs(viewCell->GetPvs()); 2085 DEL_PTR(viewCell); 2046 { 2047 VspLeaf *leaf = static_cast<VspLeaf *>(node); 2048 2049 if (!leaf->GetViewCell()->GetValid()) 2050 ++ mVspStats.invalidLeaves; 2051 2052 // validity flags don't match => repair 2053 if (leaf->GetViewCell()->GetValid() != leaf->TreeValid()) 2054 { 2055 leaf->SetTreeValid(leaf->GetViewCell()->GetValid()); 2056 PropagateUpValidity(leaf); 2086 2057 } 2087 2058 } … … 2096 2067 2097 2068 Debug << "invalid leaves: " << mVspStats.invalidLeaves << endl; 2098 #endif2099 }2100 2101 2102 void VspTree::CollectRays(VssRayContainer &rays)2103 {2104 vector<VspLeaf *> leaves;2105 CollectLeaves(leaves);2106 2107 vector<VspLeaf *>::const_iterator lit, lit_end = leaves.end();2108 2109 for (lit = leaves.begin(); lit != lit_end; ++ lit)2110 {2111 VspLeaf *leaf = *lit;2112 VssRayContainer::const_iterator rit, rit_end = leaf->mVssRays.end();2113 2114 for (rit = leaf->mVssRays.begin(); rit != rit_end; ++ rit)2115 rays.push_back(*rit);2116 }2117 }2118 2119 2120 void VspTree::SetViewCellsManager(ViewCellsManager *vcm)2121 {2122 mViewCellsManager = vcm;2123 }2124 2125 2126 void VspTree::ValidateTree()2127 {2128 if (!mRoot)2129 return;2130 2131 mVspStats.invalidLeaves = 0;2132 stack<VspNode *> nodeStack;2133 2134 nodeStack.push(mRoot);2135 2136 while (!nodeStack.empty())2137 {2138 VspNode *node = nodeStack.top();2139 nodeStack.pop();2140 2141 if (node->IsLeaf())2142 {2143 VspLeaf *leaf = static_cast<VspLeaf *>(node);2144 2145 if (!leaf->GetViewCell()->GetValid())2146 ++ mVspStats.invalidLeaves;2147 2148 // validity flags don't match => repair2149 if (leaf->GetViewCell()->GetValid() != leaf->TreeValid())2150 {2151 leaf->SetTreeValid(leaf->GetViewCell()->GetValid());2152 PropagateUpValidity(leaf);2153 }2154 }2155 else2156 {2157 VspInterior *interior = static_cast<VspInterior *>(node);2158 2159 nodeStack.push(interior->GetFront());2160 nodeStack.push(interior->GetBack());2161 }2162 }2163 2164 Debug << "invalid leaves: " << mVspStats.invalidLeaves << endl;2165 2069 } 2166 2070 … … 2168 2072 2169 2073 void VspTree::CollectViewCells(VspNode *root, 2170 2171 2172 2074 bool onlyValid, 2075 ViewCellContainer &viewCells, 2076 bool onlyUnmailed) const 2173 2077 { 2174 2078 if (!root) -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h
r2342 r2347 500 500 }; 501 501 502 struct SplitData 503 { 504 SplitData(): 505 mFrontRenderCost(0), 506 mBackRenderCost(0), 507 mTotalRenderCost(0), 508 mFrontObjects(0), 509 mBackObjects(0), 510 mTotalObjects(0), 511 mFrontTriangles(0), 512 mBackTriangles(0), 513 mTotalTriangles(0) {} 514 515 516 float mFrontRenderCost; 517 float mBackRenderCost; 518 float mTotalRenderCost; 519 520 int mFrontObjects; 521 int mBackObjects; 522 int mTotalObjects; 523 524 int mFrontTriangles; 525 int mBackTriangles; 526 int mTotalTriangles; 527 }; 528 529 502 530 /** Candidate for a view space split. 503 531 */ … … 707 735 */ 708 736 void ValidateTree(); 709 710 /** Invalid view cells are added to the unbounded space711 */712 void CollapseViewCells();713 737 714 738 /** Collects rays stored in the leaves. … … 797 821 float EvalRenderCostDecrease(VspSubdivisionCandidate &splitData, 798 822 float &normalizedOldRenderCost, 799 const float totalRenderCost, 800 const float frontRenderCost, 801 const float backRenderCost) const; 823 const SplitData &data) const; 802 824 803 825 /** Collects view cells in the subtree under root. … … 889 911 890 912 int EvalPvsEntriesIncr(VspSubdivisionCandidate &splitCandidate, 891 const int oldPvsSize, 892 const int fPvsSize, 893 const int bPvsSize) const; 913 const SplitData &sData) const; 894 914 895 915 /** Returns number of effective entries in the pvs. … … 1013 1033 inline void UpdateContributionsToPvs(BvhLeaf *leaf, 1014 1034 const int cf, 1015 float &frontPvs, 1016 float &backPvs, 1017 float &totalPvs, 1018 int &frontSize, 1019 int &backSize, 1020 int &totalSize) const; 1035 SplitData &sdata) const; 1021 1036 1022 1037 /** Evaluates the contribution for kd leaves.
Note: See TracChangeset
for help on using the changeset viewer.