Changeset 1074 for GTP/trunk/Lib/Vis/Preprocessing/src
- Timestamp:
- 07/05/06 08:43:09 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
r1027 r1074 1990 1990 optFloat, 1991 1991 "vsp_bsp_construction_min_band=", 1992 "0. 1");1992 "0.01"); 1993 1993 1994 1994 RegisterOption("VspBspTree.Construction.maxBand", 1995 1995 optFloat, 1996 1996 "vsp_bsp_construction_min_band=", 1997 "0.9 ");1997 "0.99"); 1998 1998 1999 1999 RegisterOption("VspBspTree.Construction.useDrivingAxisForMaxCost", … … 2120 2120 "0.001"); 2121 2121 2122 2123 2122 RegisterOption("VspTree.Termination.maxRayContribution", 2124 2123 optFloat, … … 2147 2146 "0.0001"); 2148 2147 2149 RegisterOption("VspTree.useSplitCostQueue",2150 optBool,2151 "vsp_use_split_cost_queue=",2152 "true");2153 2154 2148 RegisterOption("VspTree.Termination.globalCostMissTolerance", 2155 2149 optInt, … … 2200 2194 optFloat, 2201 2195 "vsp_construction_min_band=", 2202 "0. 1");2196 "0.01"); 2203 2197 2204 2198 RegisterOption("VspTree.Construction.maxBand", 2205 2199 optFloat, 2206 "vsp_construction_min_band=", 2207 "0.9"); 2200 "vsp_construction_max_band=", 2201 "0.99"); 2202 2203 RegisterOption("VspTree.pvsCountMethod", 2204 optInt, 2205 "vsp_pvs_count_method=", 2206 "1"); 2207 2208 2208 2209 2209 ////////////////////////////////////////////////////////////////////////////////// -
GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h
r1072 r1074 4 4 #include "AxisAlignedBox3.h" 5 5 #include "Pvs.h" 6 #include <set> 6 7 7 8 namespace GtpVisibilityPreprocessor { … … 28 29 29 30 /// kd leaves that this intersectable belongs to 30 s td::vector<KdLeaf *> mKdLeaves;31 set<KdLeaf *> mKdLeaves; 31 32 32 33 enum { MESH_INSTANCE, TRANSFORMED_MESH_INSTANCE, SPHERE, VIEW_CELL, OGRE_MESH_INSTANCE }; -
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
r1004 r1074 90 90 mBox.Include((*mi)->GetBox()); 91 91 } 92 93 ProcessLeafObjects(leaf, NULL); 92 94 93 95 cout <<"KdTree Root Box:"<<mBox<<endl; … … 281 283 KdLeaf *front = new KdLeaf(node, objectsFront); 282 284 285 283 286 // replace a link from node's parent 284 287 if ( leaf->mParent ) … … 304 307 } 305 308 309 ProcessLeafObjects(back, leaf); 310 ProcessLeafObjects(front, leaf); 311 306 312 delete leaf; 307 313 return node; … … 1087 1093 } 1088 1094 1089 } 1095 1096 void KdTree::ProcessLeafObjects(KdLeaf *leaf, KdLeaf *parent) const 1097 { 1098 ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 1099 1100 for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 1101 { 1102 Intersectable *object = *oit; 1103 1104 if (parent) 1105 { 1106 set<KdLeaf *>::iterator kdit = object->mKdLeaves.find(parent); 1107 1108 // remove parent leaf 1109 if (kdit != object->mKdLeaves.end()) 1110 object->mKdLeaves.erase(kdit); 1111 } 1112 1113 object->mKdLeaves.insert(leaf); 1114 1115 if (object->mKdLeaves.size() > 1) 1116 leaf->mMultipleObjects.push_back(object); 1117 } 1118 } 1119 1120 1121 } -
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h
r1073 r1074 191 191 /** Objects that are part of several leaves. 192 192 */ 193 Object MapmMultipleObjects;193 ObjectContainer mMultipleObjects; 194 194 195 195 /// universal counter … … 530 530 ); 531 531 532 533 /** does some post processing on the objects that are contained 534 in this leaf. 535 */ 536 void ProcessLeafObjects(KdLeaf *leaf, KdLeaf *parent) const; 532 537 533 538 int mTermMaxNodes; -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1072 r1074 454 454 bool dirSamples = (mSamplingType == Preprocessor::DIRECTION_BASED_DISTRIBUTION); 455 455 456 // -- the main loop456 //-- do some more sampling 457 457 while (numSamples < n) 458 458 { … … 490 490 } 491 491 492 493 492 //-- post processing 494 493 VssRayContainer postProcessSamples; 495 494 496 //-- construction rays 495 cout << "casting " << mPostProcessSamples << " post processing samples ... "; 496 497 // cast post processing samples rays (storing the view cells if wanted) 497 498 CastPassSamples(mPostProcessSamples, 498 499 mSamplingType, 499 500 postProcessSamples); 500 501 502 cout << "finished" << endl; 501 503 502 504 // stats before post processing (i.e., merge) … … 542 544 543 545 //-- visualization 546 544 547 if (mShowVisualization) 545 548 { … … 1727 1730 { 1728 1731 mViewSpaceBox = box; 1729 Debug << "here111 " << mViewSpaceBox << endl;1732 1730 1733 // hack: create clip plane relative to new view space box 1731 1734 CreateClipPlane(); … … 4853 4856 mMaxPvsSize = (int)(mMaxPvsRatio * (float)objects.size()); 4854 4857 4855 Debug << "here125 view space box " << mViewSpaceBox << endl; 4856 4857 // if view cells were already constructed 4858 // skip rest if view cells were already constructed 4858 4859 if (ViewCellsConstructed()) 4859 4860 return 0; … … 5277 5278 5278 5279 //-- export single view cells 5279 Export BspPvs(objects, visRays);5280 } 5281 5282 5283 void VspOspViewCellsManager::Export BspPvs(const ObjectContainer &objects,5284 5280 ExportPvs(objects, visRays); 5281 } 5282 5283 5284 void VspOspViewCellsManager::ExportPvs(const ObjectContainer &objects, 5285 const VssRayContainer &rays) 5285 5286 { 5286 5287 int leafOut; … … 5315 5316 if (sortViewCells) // largest view cell pvs first 5316 5317 vc = mViewCells[i]; 5317 else 5318 else // random view cell 5318 5319 vc = mViewCells[(int)RandomValue(0, (float)mViewCells.size() - 1)]; 5319 5320 … … 5328 5329 5329 5330 //-- export the sample rays 5330 if ( mExportRays)5331 if (1 || mExportRays) 5331 5332 { 5332 5333 // output rays stored with the view cells during subdivision … … 5408 5409 5409 5410 5410 //-- export pvs5411 5411 if (1) 5412 { 5412 { //-- export pvs 5413 5413 ObjectPvsMap::const_iterator oit, 5414 5414 oit_end = pvs.mEntries.end(); … … 5416 5416 Intersectable::NewMail(); 5417 5417 5418 // output PVS of view cell 5418 vector<KdLeaf *> kdLeaves; 5419 5420 KdLeaf::NewMail(); 5421 5422 m.mDiffuseColor = RgbColor(1, 0, 0); 5423 exporter->SetForcedMaterial(m); 5424 5425 // find kd nodes 5419 5426 for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit) 5420 { 5421 Intersectable *intersect = (*oit).first; 5422 5423 if (!intersect->Mailed()) 5427 { 5428 // "original" pvs 5429 Intersectable *obj = (*oit).first; 5430 5431 if (1 && !obj->Mailed()) 5424 5432 { 5425 m = RandomMaterial(); 5426 exporter->SetForcedMaterial(m); 5427 5428 exporter->ExportIntersectable(intersect); 5429 intersect->Mail(); 5433 exporter->ExportIntersectable(obj); 5434 obj->Mail(); 5435 } 5436 5437 // collect kd leaves 5438 set<KdLeaf *>::const_iterator kdit, kdit_end = obj->mKdLeaves.end(); 5439 5440 for (kdit = obj->mKdLeaves.begin(); kdit != kdit_end; ++ kdit) 5441 { 5442 KdLeaf *kdleaf = *kdit; 5443 5444 if (!kdleaf->Mailed()) 5445 { 5446 kdleaf->Mail(); 5447 kdLeaves.push_back(kdleaf); 5448 } 5430 5449 } 5431 5450 } 5432 } 5433 5434 if (0) 5435 { // export scene geometry 5436 m.mDiffuseColor = RgbColor(1, 0, 0); 5451 5452 m.mDiffuseColor = RgbColor(0, 0, 1); 5437 5453 exporter->SetForcedMaterial(m); 5438 5454 5439 exporter->ExportGeometry(objects); 5440 } 5441 5455 // export kd node pvs 5456 Intersectable::NewMail(); 5457 5458 vector<KdLeaf *>::const_iterator kdit, kdit_end = kdLeaves.end(); 5459 5460 for (kdit = kdLeaves.begin(); kdit != kdit_end; ++ kdit) 5461 { 5462 KdLeaf *kdleaf = *kdit; 5463 5464 //-- export kd node 5465 /*exporter->SetWireframe(); 5466 exporter->ExportBox(mKdTree->GetBox(kdleaf)); 5467 exporter->SetFilled();*/ 5468 5469 ObjectContainer::const_iterator oit, oit_end = kdleaf->mObjects.end(); 5470 5471 for (oit = kdleaf->mObjects.begin(); oit != oit_end; ++ oit) 5472 { 5473 Intersectable *obj = *oit; 5474 5475 if (!obj->Mailed()) 5476 { 5477 exporter->ExportIntersectable(obj); 5478 obj->Mail(); 5479 } 5480 } 5481 } 5482 } 5483 5442 5484 DEL_PTR(exporter); 5443 5485 cout << "finished" << endl; -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r1047 r1074 1001 1001 */ 1002 1002 void ExportViewCellGeometry(Exporter *exporter, 1003 ViewCell *vc, 1004 const AxisAlignedPlane *clipPlane = NULL) const; 1005 1006 int ComputeBoxIntersections(const AxisAlignedBox3 &box, ViewCellContainer &viewCells) const; 1003 ViewCell *vc, 1004 const AxisAlignedPlane *clipPlane = NULL) const; 1005 1006 int ComputeBoxIntersections(const AxisAlignedBox3 &box, 1007 ViewCellContainer &viewCells) const; 1007 1008 1008 1009 void CollectViewCells(); … … 1019 1020 void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs); 1020 1021 1021 /** Exports visualization of the BSPPVS.1022 */ 1023 void Export BspPvs(const ObjectContainer &objects,1024 1022 /** Exports visualization of the PVS. 1023 */ 1024 void ExportPvs(const ObjectContainer &objects, 1025 const VssRayContainer &rays); 1025 1026 1026 1027 -
GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.cpp
r1052 r1074 101 101 stream << "}" << endl; // end material 102 102 stream << "}" << endl; // end appearance 103 Debug << "here8" << endl;103 104 104 stream << "geometry IndexedLineSet { coordIndex [" << endl; 105 105 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
r1072 r1074 1321 1321 1322 1322 // the relative cost ratio 1323 float ratio = /*Limits::Infinity;*/99999999.0f;1323 float ratio = 99999999.0f; 1324 1324 bool splitPlaneFound = false; 1325 1325 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp
r1073 r1074 274 274 { 275 275 DEL_PTR(mPvs); 276 CLEAR_CONTAINER(mVssRays); 276 277 } 277 278 … … 349 350 Environment::GetSingleton()->GetIntValue("VspTree.Termination.globalCostMissTolerance", mTermGlobalCostMissTolerance); 350 351 351 // HACK//mTermMinPolygons = 25;352 353 352 //-- factors for bsp tree split plane heuristics 354 353 Environment::GetSingleton()->GetFloatValue("VspTree.Termination.ct_div_ci", mCtDivCi); … … 366 365 Environment::GetSingleton()->GetBoolValue("VspTree.simulateOctree", mCirculatingAxis); 367 366 367 Environment::GetSingleton()->GetIntValue("VspTree.pvsCountMethod", mPvsCountMethod); 368 368 369 369 char subdivisionStatsLog[100]; … … 398 398 Debug << "minband: " << mMinBand << endl; 399 399 Debug << "maxband: " << mMaxBand << endl; 400 Debug << "pvs count method: " << mPvsCountMethod << endl; 400 401 401 402 … … 650 651 splitCandidate.mMaxCostMisses = success ? tData.mMaxCostMisses : tData.mMaxCostMisses + 1; 651 652 652 Debug << "p: " << tData.mNode << " depth: " << tData.mDepth << endl;653 //Debug << "p: " << tData.mNode << " depth: " << tData.mDepth << endl; 653 654 } 654 655 … … 674 675 *backData.mRays); 675 676 676 Debug << "f: " << frontData.mRays->size() << " b: " << backData.mRays->size() << "d: " << tData.mRays->size() << endl;677 //Debug << "f: " << frontData.mRays->size() << " b: " << backData.mRays->size() << "d: " << tData.mRays->size() << endl; 677 678 //-- compute pvs 678 679 frontData.mPvs = ComputePvsSize(*frontData.mRays); … … 778 779 779 780 // warning: rays get never deleted! 780 if ( 0) leaf->mVssRays.push_back(new VssRay(*ray));781 if (1) leaf->mVssRays.push_back(new VssRay(*ray)); 781 782 } 782 783 } … … 804 805 float pos; 805 806 806 if (0)807 {808 // float values => don't compare with exact values809 minBand += Limits::Small;810 maxBand -= Limits::Small;811 }812 813 807 // insert all queries 814 808 for (RayInfoContainer::const_iterator ri = rays.begin(); ri < rays.end(); ++ ri) … … 818 812 pos = (*ri).ExtrapOrigin(axis); 819 813 820 if (0) ClipValue(pos, minBand, maxBand); // clamp to min / max band821 814 mSplitCandidates->push_back(SortableEntry(positive ? SortableEntry::ERayMin : SortableEntry::ERayMax, 822 815 pos, (*ri).mRay)); 823 816 824 817 pos = (*ri).ExtrapTermination(axis); 825 826 if (0) ClipValue(pos, minBand, maxBand); // clamp to min / max band827 818 828 819 mSplitCandidates->push_back(SortableEntry(positive ? SortableEntry::ERayMax : SortableEntry::ERayMin, … … 860 851 861 852 862 void VspTree::PrepareHeuristics(const RayInfoContainer &rays) 853 int VspTree::PrepareHeuristics(Intersectable *object) 854 { 855 set<KdLeaf *>::const_iterator kit, kit_end = object->mKdLeaves.end(); 856 857 int pvsSize = 0; 858 859 for (kit = object->mKdLeaves.begin(); kit != kit_end; ++ kit) 860 { 861 KdLeaf *node = dynamic_cast<KdLeaf *>(*kit); 862 863 if (!node->Mailed()) 864 { 865 node->Mail(); 866 node->mCounter = 1; 867 868 //Debug << "here5 "<<(int)node->mObjects.size() <<" "<< node->mMultipleObjects.size()<< " " <<(int)node->mObjects.size() - node->mMultipleObjects.size()<<endl; 869 // add objects without the objects which are in several kd leaves 870 pvsSize += (int)(node->mObjects.size() - node->mMultipleObjects.size()); 871 } 872 else 873 { 874 ++ node->mCounter; 875 } 876 877 //-- the objects belonging to several leaves must be handled seperately 878 ObjectContainer::const_iterator oit, oit_end = node->mMultipleObjects.end(); 879 880 for (oit = node->mMultipleObjects.begin(); oit != oit_end; ++ oit) 881 { 882 Intersectable *object = *oit; 883 884 if (!object->Mailed()) 885 { 886 //Debug << "here233: " << object->mKdLeaves.size() << endl; 887 object->Mail(); 888 object->mCounter = 1; 889 890 ++ pvsSize; 891 } 892 else 893 { 894 ++ object->mCounter; 895 } 896 } 897 } 898 899 return pvsSize; 900 } 901 902 903 int VspTree::PrepareHeuristics(const RayInfoContainer &rays) 863 904 { 864 ObjectContainer objects; 865 866 // Collect all pvs that can be seen from the view cell 867 CollectPvs(rays, objects); 868 869 // adjust kd node info table 870 // for each object the entry must be updated 871 // which belongs to the same kd nodes 872 ObjectContainer::const_iterator oit, oit_end = objects.end(); 873 874 for (oit = objects.begin(); oit != oit_end; ++ oit) 875 { 876 Intersectable *obj = *oit; 877 // TODO 878 //UpdateKdNodeInfo(obj); 879 } 905 Intersectable::NewMail(); 906 KdNode::NewMail(); 907 908 int pvsSize = 0; 909 910 RayInfoContainer::const_iterator ri, ri_end = rays.end(); 911 912 //-- set all kd nodes as belonging to the front pvs 913 914 for (ri = rays.begin(); ri != ri_end; ++ ri) 915 { 916 Intersectable *oObject = (*ri).mRay->mOriginObject; 917 918 if (oObject) 919 { 920 if (mPvsCountMethod == PER_OBJECT) 921 { 922 if (!oObject->Mailed()) 923 { 924 oObject->Mail(); 925 oObject->mCounter = 1; 926 ++ pvsSize; 927 } 928 else 929 { 930 ++ oObject->mCounter; 931 } 932 } 933 else 934 { 935 pvsSize += PrepareHeuristics(oObject); 936 } 937 } 938 939 Intersectable *tObject = (*ri).mRay->mTerminationObject; 940 941 if (tObject) 942 { 943 if (mPvsCountMethod == PER_OBJECT) 944 { 945 if (!tObject->Mailed()) 946 { 947 tObject->Mail(); 948 tObject->mCounter = 1; 949 ++ pvsSize; 950 } 951 else 952 { 953 ++ tObject->mCounter; 954 } 955 } 956 else 957 { 958 pvsSize += PrepareHeuristics(tObject); 959 } 960 } 961 } 962 963 return pvsSize; 880 964 } 881 965 … … 910 994 float VspTree::EvalLocalCostHeuristics(const RayInfoContainer &rays, 911 995 const AxisAlignedBox3 &box, 912 constint pvsSize,996 int pvsSize, 913 997 const int axis, 914 998 float &position) … … 942 1026 943 1027 // the relative cost ratio 944 float ratio = /*Limits::Infinity;*/99999999.0f;1028 float ratio = 99999999.0f; 945 1029 bool splitPlaneFound = false; 946 1030 … … 1061 1145 const float pFront = maxBox - position; 1062 1146 1063 /*const float pOverall = box.GetVolume(); 1064 1065 AxisAlignedBox3 bbox; 1066 AxisAlignedBox3 fbox; 1067 1068 box.Split(axis, position, bbox, fbox); 1069 1070 const float pBack = fbox.GetVolume(); 1071 const float pFront = bbox.GetVolume();*/ 1072 1147 1073 1148 const float penaltyOld = EvalPvsPenalty(pvsSize, lowerPvsLimit, upperPvsLimit); 1074 1149 const float penaltyFront = EvalPvsPenalty(pvsFront, lowerPvsLimit, upperPvsLimit); … … 1090 1165 1091 1166 1092 void VspTree::EvalPvsIncr(ObjectMap &multipleObjects, 1093 KdLeaf *leaf, 1094 const SortableEntry &ci, 1167 void VspTree::RemoveContriFromPvs(KdLeaf *leaf, int &pvs) const 1168 { 1169 // leaf falls out of right pvs 1170 if (-- leaf->mCounter == 0) 1171 { 1172 pvs -= ((int)leaf->mObjects.size() - (int)leaf->mMultipleObjects.size()); 1173 } 1174 1175 //-- handle objects which are in several kd leaves separately 1176 ObjectContainer::const_iterator oit, oit_end = leaf->mMultipleObjects.end(); 1177 1178 for (oit = leaf->mMultipleObjects.begin(); oit != oit_end; ++ oit) 1179 { 1180 Intersectable *object = *oit; 1181 1182 if (-- object->mCounter == 0) 1183 { 1184 -- pvs; 1185 } 1186 } 1187 } 1188 1189 1190 void VspTree::AddContriToPvs(KdLeaf *leaf, int &pvs) const 1191 { 1192 if (!leaf->Mailed()) 1193 { 1194 leaf->Mail(); 1195 1196 // add objects without objects which are part of several kd leaves 1197 pvs += ((int)leaf->mObjects.size() - (int)leaf->mMultipleObjects.size()); 1198 1199 //-- handle objects of several kd leaves separately 1200 ObjectContainer::const_iterator oit, oit_end = leaf->mMultipleObjects.end(); 1201 1202 for (oit = leaf->mMultipleObjects.begin(); oit != oit_end; ++ oit) 1203 { 1204 Intersectable *object = *oit; 1205 1206 // object not previously in left pvs 1207 if (!object->Mailed()) 1208 { 1209 object->Mail(); 1210 ++ pvs; 1211 } 1212 } 1213 } 1214 } 1215 1216 1217 void VspTree::EvalPvsIncr(const SortableEntry &ci, 1095 1218 int &pvsLeft, 1096 1219 int &pvsRight) const 1097 1220 { 1098 int pvsSize = 0; 1099 1100 if (ci.type == SortableEntry::ERayMin) 1101 { 1102 if (!leaf->Mailed()) 1103 { 1104 leaf->Mail(); 1105 pvsLeft += (int)leaf->mObjects.size() - (int)leaf->mMultipleObjects.size(); 1106 1107 // add duplicates 1108 ObjectMap::const_iterator oit, oit_end = leaf->mMultipleObjects.end(); 1109 1110 for (oit = leaf->mMultipleObjects.begin(); oit != oit_end; ++ oit) 1111 { 1112 const int id = (*oit).first; 1113 Intersectable *object = (*oit).second; 1114 1115 if (multipleObjects[id] != object) // object not previously in pvs 1221 VssRay *ray = ci.ray; 1222 1223 Intersectable *oObject = ray->mOriginObject; 1224 Intersectable *tObject = ray->mTerminationObject; 1225 1226 if (oObject) 1227 { 1228 if (mPvsCountMethod == PER_OBJECT) 1229 { 1230 if (ci.type == SortableEntry::ERayMin) 1231 { 1232 if (!oObject->Mailed()) 1116 1233 { 1117 multipleObjects[id] = object;1234 oObject->Mail(); 1118 1235 ++ pvsLeft; 1119 1236 } 1120 1121 } 1122 } 1123 } 1124 else if (ci.type == SortableEntry::ERayMax) 1125 { 1126 if (-- leaf->mCounter == 0) 1127 pvsRight += (int)leaf->mObjects.size() - (int)leaf->mMultipleObjects.size(); 1128 } 1129 } 1130 1131 1132 float VspTree::EvalKdCostHeuristics(const RayInfoContainer &rays, 1133 const AxisAlignedBox3 &box, 1134 const int pvsSize, 1135 const int axis, 1136 float &position) 1237 } 1238 else if (ci.type == SortableEntry::ERayMax) 1239 { 1240 if (-- oObject->mCounter == 0) 1241 -- pvsRight; 1242 } 1243 } 1244 else // per kd node 1245 { 1246 set<KdLeaf *>::const_iterator kit, kit_end = oObject->mKdLeaves.end(); 1247 1248 for (kit = oObject->mKdLeaves.begin(); kit != kit_end; ++ kit) 1249 { 1250 KdLeaf *node = dynamic_cast<KdLeaf *>(*kit); 1251 1252 // add contributions of the kd nodes 1253 if (ci.type == SortableEntry::ERayMin) 1254 { 1255 AddContriToPvs(node, pvsLeft); 1256 } 1257 else if (ci.type == SortableEntry::ERayMax) 1258 { 1259 RemoveContriFromPvs(node, pvsRight); 1260 } 1261 } 1262 } 1263 1264 1265 } 1266 1267 if (tObject) 1268 { 1269 if (mPvsCountMethod == PER_OBJECT) 1270 { 1271 if (ci.type == SortableEntry::ERayMin) 1272 { 1273 if (!tObject->Mailed()) 1274 { 1275 tObject->Mail(); 1276 ++ pvsLeft; 1277 } 1278 } 1279 else if (ci.type == SortableEntry::ERayMax) 1280 { 1281 if (-- tObject->mCounter == 0) 1282 -- pvsRight; 1283 } 1284 } 1285 else // per kd node 1286 { 1287 set<KdLeaf *>::const_iterator kit, kit_end = tObject->mKdLeaves.end(); 1288 1289 for (kit = tObject->mKdLeaves.begin(); kit != kit_end; ++ kit) 1290 { 1291 KdLeaf *node = dynamic_cast<KdLeaf *>(*kit); 1292 1293 if (ci.type == SortableEntry::ERayMin) 1294 { 1295 AddContriToPvs(node, pvsLeft); 1296 } 1297 else if (ci.type == SortableEntry::ERayMax) 1298 { 1299 RemoveContriFromPvs(node, pvsRight); 1300 } 1301 } 1302 } 1303 } 1304 } 1305 1306 1307 /* 1308 float VspTree::EvalLocalCostHeuristics(const RayInfoContainer &rays, 1309 const AxisAlignedBox3 &box, 1310 int pvsSize, 1311 const int axis, 1312 float &position) 1137 1313 { 1138 1314 const float minBox = box.Min(axis); … … 1145 1321 1146 1322 SortSplitCandidates(rays, axis, minBand, maxBand); 1323 1324 // prepare the heuristics sweep 1325 // (note: returns pvs size, so there would be no need 1326 // to give pvs size as argument) 1327 pvsSize = PrepareHeuristics(rays); 1328 1329 Debug << "here45 pvs: " << pvsSize << endl; 1147 1330 1148 1331 // go through the lists, count the number of objects left and right … … 1164 1347 1165 1348 // the relative cost ratio 1166 float ratio = /*Limits::Infinity;*/99999999.0f;1349 float ratio = 99999999.0f; 1167 1350 bool splitPlaneFound = false; 1168 1351 1169 1352 Intersectable::NewMail(); 1170 KdNode::NewMail(); 1171 1172 RayInfoContainer::const_iterator ri, ri_end = rays.end(); 1173 1174 //-- set all kd nodes as belonging to the front pvs 1175 1176 for (ri = rays.begin(); ri != ri_end; ++ ri) 1177 { 1178 Intersectable *oObject = (*ri).mRay->mOriginObject; 1179 1180 if (oObject) 1181 { 1182 KdPvsMap::const_iterator kit, kit_end = oObject->mKdPvs.mEntries.end(); 1183 1184 for (kit = oObject->mKdPvs.mEntries.begin(); kit != kit_end; ++ kit) 1185 { 1186 KdNode *node = (*kit).first; 1187 1188 if (!node->Mailed()) 1189 { 1190 node->Mail(); 1191 //node->mCounter = 1; 1192 } 1193 else 1194 { 1195 //++ node->mCounter; 1196 } 1197 } 1198 } 1199 1200 Intersectable *tObject = (*ri).mRay->mTerminationObject; 1201 1202 if (tObject) 1203 { 1204 KdPvsMap::const_iterator kit, kit_end = oObject->mKdPvs.mEntries.end(); 1205 1206 for (kit = tObject->mKdPvs.mEntries.begin(); kit != kit_end; ++ kit) 1207 { 1208 KdNode *node = (*kit).first; 1209 1210 if (!node->Mailed()) 1211 { 1212 node->Mail(); 1213 //node->mCounter = 1; 1214 } 1215 else 1216 { 1217 //++ node->mCounter; 1218 } 1219 } 1220 } 1221 } 1222 1223 Intersectable::NewMail(); 1353 KdLeaf::NewMail(); 1354 1224 1355 1225 1356 vector<SortableEntry>::const_iterator ci, ci_end = mSplitCandidates->end(); 1226 1357 1227 ObjectMap multipleObjectsLeft, multipleObjectsRight; 1228 1229 1230 // -- traverse through visibility events 1358 Debug << "****************" << endl; 1359 //-- traverse through visibility events 1231 1360 1232 1361 for (ci = mSplitCandidates->begin(); ci != ci_end; ++ ci) 1233 1362 { 1234 VssRay *ray; 1235 ray = (*ci).ray; 1236 1237 Intersectable *oObject = ray->mOriginObject; 1238 1239 KdPvsMap::const_iterator kit, kit_end = oObject->mKdPvs.mEntries.end(); 1240 1241 if (oObject) 1242 { 1243 for (kit = oObject->mKdPvs.mEntries.begin(); kit != kit_end; ++ kit) 1244 { 1245 KdLeaf *node = dynamic_cast<KdLeaf *>((*kit).first); 1246 1247 EvalPvsIncr(multipleObjectsLeft, node, *ci, pvsl, pvsr); 1248 } 1249 } 1250 1251 Intersectable *tObject = ray->mOriginObject; 1252 1253 if (tObject) 1254 { 1255 for (kit = tObject->mKdPvs.mEntries.begin(); kit != kit_end; ++ kit) 1256 { 1257 KdLeaf *node = dynamic_cast<KdLeaf *>((*kit).first); 1258 1259 EvalPvsIncr(multipleObjectsRight, node, *ci, pvsl, pvsr); 1260 } 1261 } 1262 1363 EvalPvsIncr(*ci, pvsl, pvsr); 1263 1364 1264 1365 // Note: sufficient to compare size of bounding boxes of front and back side? … … 1267 1368 sum = pvsl * ((*ci).value - minBox) + pvsr * (maxBox - (*ci).value); 1268 1369 1269 //Debug << "pos=" << (*ci).value << "\t pvs=(" << pvsl << "," << pvsr << ")" << endl; 1270 //Debug << "cost= " << sum << endl; 1370 //Debug << "pos=" << (*ci).value << "\t pvs=(" << pvsl << "," << pvsr << ")" << "\t cost= " << sum << endl; 1271 1371 1272 1372 if (sum < minSum) … … 1304 1404 ratio = newRenderCost / oldRenderCost; 1305 1405 } 1406 1306 1407 //if (axis != 1) 1307 //Debug << "axis=" << axis << " costRatio=" << ratio << " pos=" << position << " t=" << (position - minBox) / (maxBox - minBox)1308 //<<"\t pb=(" << pvsBack << ")\t pf=(" << pvsFront << ")" << endl;1408 Debug << "axis=" << axis << " costRatio=" << ratio << " pos=" << position << " t=" << (position - minBox) / (maxBox - minBox) 1409 <<"\t pb=(" << pvsBack << ")\t pf=(" << pvsFront << ")" << endl; 1309 1410 1310 1411 return ratio; 1311 } 1312 1313 1314 #if TODO 1315 1316 float VspTree::EvalLocalCostHeuristicsNonIncremential(const RayInfoContainer &rays, 1317 const AxisAlignedBox3 &box, 1318 const int pvsSize, 1319 const int axis, 1320 float &position) 1321 { 1322 const float minBox = box.Min(axis); 1323 const float maxBox = box.Max(axis); 1324 1325 const float sizeBox = maxBox - minBox; 1326 1327 const float minBand = minBox + mMinBand * sizeBox; 1328 const float maxBand = minBox + mMaxBand * sizeBox; 1329 1330 SortSplitCandidates(rays, axis, minBand, maxBand); 1331 1332 // go through the lists, count the number of objects left and right 1333 // and evaluate the following cost funcion: 1334 // C = ct_div_ci + (ql*rl + qr*rr)/queries 1335 1336 int pvsl = 0; 1337 int pvsr = pvsSize; 1338 1339 int pvsBack = pvsl; 1340 int pvsFront = pvsr; 1341 1342 float sum = (float)pvsSize * sizeBox; 1343 float minSum = 1e20f; 1344 1345 1346 // if no good split can be found, take mid split 1347 position = minBox + 0.5f * sizeBox; 1348 1349 // the relative cost ratio 1350 float ratio = /*Limits::Infinity;*/99999999.0f; 1351 bool splitPlaneFound = false; 1352 1353 Intersectable::NewMail(); 1354 1355 RayInfoContainer::const_iterator ri, ri_end = rays.end(); 1356 1357 //-- set all object as belonging to the front pvs 1358 1359 for(ri = rays.begin(); ri != ri_end; ++ ri) 1360 { 1361 // Note: sufficient to compare size of bounding boxes of front and back side? 1362 if (((*ci).value >= minBand) && ((*ci).value <= maxBand)) 1363 { 1364 sum = pvsl * ((*ci).value - minBox) + pvsr * (maxBox - (*ci).value); 1365 1366 //Debug << "pos=" << (*ci).value << "\t pvs=(" << pvsl << "," << pvsr << ")" << endl; 1367 //Debug << "cost= " << sum << endl; 1368 1369 if (sum < minSum) 1370 { 1371 splitPlaneFound = true; 1372 1373 minSum = sum; 1374 position = (*ci).value; 1375 1376 pvsBack = pvsl; 1377 pvsFront = pvsr; 1378 } 1379 } 1380 } 1381 1382 1383 // -- compute cost 1384 1385 const int lowerPvsLimit = mViewCellsManager->GetMinPvsSize(); 1386 const int upperPvsLimit = mViewCellsManager->GetMaxPvsSize(); 1387 1388 const float pOverall = sizeBox; 1389 const float pBack = position - minBox; 1390 const float pFront = maxBox - position; 1391 1392 1393 const float penaltyOld = EvalPvsPenalty(pvsSize, lowerPvsLimit, upperPvsLimit); 1394 const float penaltyFront = EvalPvsPenalty(pvsFront, lowerPvsLimit, upperPvsLimit); 1395 const float penaltyBack = EvalPvsPenalty(pvsBack, lowerPvsLimit, upperPvsLimit); 1396 1397 const float oldRenderCost = penaltyOld * pOverall + Limits::Small; 1398 const float newRenderCost = penaltyFront * pFront + penaltyBack * pBack; 1399 1400 if (splitPlaneFound) 1401 { 1402 ratio = newRenderCost / oldRenderCost; 1403 } 1404 //if (axis != 1) 1405 //Debug << "axis=" << axis << " costRatio=" << ratio << " pos=" << position << " t=" << (position - minBox) / (maxBox - minBox) 1406 // <<"\t pb=(" << pvsBack << ")\t pf=(" << pvsFront << ")" << endl; 1407 1408 return ratio; 1409 } 1410 #endif 1412 }*/ 1411 1413 1412 1414 … … 1427 1429 int bestAxis = -1; 1428 1430 1429 //mOnlyDrivingAxis = true;1430 1431 1431 // if we use some kind of specialised fixed axis 1432 1432 const bool useSpecialAxis = 1433 1433 mOnlyDrivingAxis || mCirculatingAxis; 1434 Debug << "data: " << tData.mBoundingBox << " pvs " << tData.mPvs << endl;1434 //Debug << "data: " << tData.mBoundingBox << " pvs " << tData.mPvs << endl; 1435 1435 if (mCirculatingAxis) 1436 1436 { … … 1481 1481 else if (nCostRatio[axis] < nCostRatio[bestAxis]) 1482 1482 { 1483 Debug << "old: " << nCostRatio[bestAxis] << " axis: " << bestAxis << endl;1484 1483 bestAxis = axis; 1485 1486 Debug << "new: " << nCostRatio[bestAxis] << " axis: " << bestAxis << endl;1487 1484 } 1488 1485 } … … 1499 1496 pBack = nProbBack[bestAxis]; 1500 1497 1501 1502 Debug << "val: " << nCostRatio[bestAxis] << " axis: " << bestAxis << endl; 1498 //Debug << "val: " << nCostRatio[bestAxis] << " axis: " << bestAxis << endl; 1503 1499 return nCostRatio[bestAxis]; 1504 1500 } … … 1779 1775 ++ mCreatedViewCells; 1780 1776 1781 //#ifdef _DEBUG1777 #ifdef _DEBUG 1782 1778 Debug << "BSP stats: " 1783 1779 << "Depth: " << data.mDepth << " (max: " << mTermMaxDepth << "), " … … 1786 1782 << "#pvs: " << leaf->GetViewCell()->GetPvs().GetSize() << "), " 1787 1783 << "#avg ray contrib (pvs): " << (float)data.mPvs / (float)data.mRays->size() << endl; 1788 //#endif1784 #endif 1789 1785 } 1790 1786 … … 3035 3031 { 3036 3032 SplitCandidate *splitCandidate = mTQueue.top(); 3037 Debug << "priority: " << splitCandidate->GetPriority() << endl;3033 //Debug << "priority: " << splitCandidate->GetPriority() << endl; 3038 3034 mTQueue.pop(); 3039 3035 … … 3089 3085 0, 3090 3086 &rays, 3091 (int)objects.size(),3092 //mVspTree.ComputePvsSize(rays),3087 //(int)objects.size(), 3088 mVspTree.ComputePvsSize(rays), 3093 3089 prop, 3094 3090 mVspTree.mBoundingBox); … … 3132 3128 cout << "Constructing view space / object space tree ... \n"; 3133 3129 const long startTime = GetTime(); 3134 3130 3131 int i = 0; 3135 3132 while (!FinishedConstruction()) 3136 3133 { … … 3140 3137 GlobalTerminationCriteriaMet(splitCandidate); 3141 3138 3142 Debug << "cost: " << splitCandidate->GetPriority();3139 cout << "view cells: " << i ++ << endl; 3143 3140 3144 3141 // cost ratio of cost decrease / totalCost … … 3168 3165 } 3169 3166 3170 cout << "finished in " << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl;3167 cout << "finished in " << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl; 3171 3168 3172 3169 mVspTree.mVspStats.Stop(); -
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h
r1072 r1074 883 883 884 884 /** Prepares objects for SAH. 885 */ 886 void PrepareHeuristics(const RayInfoContainer &rays); 885 @returns pvs size of the ray container 886 */ 887 int PrepareHeuristics(const RayInfoContainer &rays); 888 889 int PrepareHeuristics(Intersectable *object); 887 890 888 891 /** Computes pvs increase with respect to the previous pvs for SAH. … … 898 901 float EvalLocalCostHeuristics(const RayInfoContainer &rays, 899 902 const AxisAlignedBox3 &box, 900 constint pvsSize,903 int pvsSize, 901 904 const int axis, 902 905 float &position); 903 906 904 float EvalKdCostHeuristics(const RayInfoContainer &rays, 905 const AxisAlignedBox3 &box, 906 const int pvsSize, 907 const int axis, 908 float &position); 909 void EvalPvsIncr(ObjectMap &multipleObjects, 910 KdLeaf *leaf, 911 const SortableEntry &ci, 907 /** Evaluates the influence on the pvs of the visibility event ve. 908 @param ve the visibility event 909 @param pvsLeft updates the left pvs 910 @param rightPvs updates the right pvs 911 */ 912 void EvalPvsIncr(const SortableEntry &ve, 912 913 int &pvsLeft, 913 914 int &pvsRight) const; 914 915 916 void RemoveContriFromPvs(KdLeaf *leaf, int &pvs) const; 917 void AddContriToPvs(KdLeaf *leaf, int &pvs) const; 915 918 916 919 /** Subdivides the rays into front and back rays according to the split plane. … … 989 992 990 993 protected: 994 995 int mPvsCountMethod; 996 enum {PER_OBJECT, PER_KDLEAF}; 991 997 992 998 ViewCellsManager *mViewCellsManager; -
GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp
r1052 r1074 314 314 Exporter *exporter = NULL; 315 315 exporter = Exporter::GetExporter(filename); 316 //exporter->SetWireframe();317 //exporter->ExportKdTree(*mKdTree);316 exporter->SetWireframe(); 317 exporter->ExportKdTree(*mKdTree); 318 318 exporter->SetFilled(); 319 319 exporter->ExportScene(mSceneGraph->mRoot); … … 623 623 if (!mLoadViewCells) 624 624 { 625 Debug << "here923 " << vbox << endl;626 625 mViewCellsManager->SetViewSpaceBox(vbox); 627 626 // construct view cells using it's own set of samples … … 746 745 vssTree->Construct(mVssRays, mViewSpaceBox); 747 746 cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl; 747 748 ExportRays("kdtree.x3d", mVssRays, 10); 748 749 749 750 if (0)
Note: See TracChangeset
for help on using the changeset viewer.