Changeset 495 for trunk/VUT/GtpVisibilityPreprocessor/src
- Timestamp:
- 01/04/06 10:02:28 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r492 r495 1340 1340 } 1341 1341 1342 // choose candidate planes extracted from rays1342 //-- choose candidate planes extracted from rays 1343 1343 for (int i = 0; i < mMaxRayCandidates; ++ i) 1344 1344 { -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
r492 r495 1387 1387 1388 1388 // collapse siblings belonging to the same view cell 1389 mVspKdTree->CollapseTree( mVspKdTree->GetRoot());1390 1389 mVspKdTree->CollapseTree(); 1390 1391 1391 // collapse siblings belonging to the same view cell 1392 1392 mVspKdTree->RefineViewCells(rays); … … 1763 1763 // collapse invalid regions 1764 1764 cout << "collapsing invalid tree regions ... "; 1765 mVspBspTree->CollapseTree(mVspBspTree->GetRoot()); 1766 cout << "finished" << endl; 1765 long startTime = GetTime(); 1766 mVspBspTree->CollapseTree(); 1767 Debug << "tree collapsed in " << TimeDiff(startTime, GetTime()) * 1e-3 << " seconds" << endl; 1768 cout << "finished" << endl; 1769 1767 1770 cout << "reseting view cell stats ... "; 1768 1771 ResetViewCells(); … … 1782 1785 ExportViewCells(exporter); 1783 1786 1784 //if (mExportRays)1785 // exporter->ExportRays(postProcessRays, RgbColor(1, 1, 0));1787 if (0 && mExportRays) 1788 exporter->ExportRays(rays, RgbColor(1, 1, 1)); 1786 1789 1787 1790 if (mExportGeometry) … … 1793 1796 } 1794 1797 1795 longstartTime = GetTime();1798 startTime = GetTime(); 1796 1799 cout << "Computing remaining ray contributions ... "; 1797 1800 // recast rest of rays … … 1942 1945 1943 1946 // collapse sibling leaves that share the same view cell 1944 mVspBspTree->CollapseTree(mVspBspTree->GetRoot()); 1947 mVspBspTree->CollapseTree(); 1948 1945 1949 // reset view cells and stats 1946 1950 ResetViewCells(); … … 2132 2136 //-- export rays piercing this view cell 2133 2137 #if 1 2134 exporter->ExportRays(vcRays, RgbColor( 0, 1, 0));2138 exporter->ExportRays(vcRays, RgbColor(1, 1, 1)); 2135 2139 #endif 2136 2140 #if 0 -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
r492 r495 35 35 float BspMergeCandidate::sOverallCost = 0; 36 36 37 38 /// Adds object to the pvs of the front and back node39 inline void AddObject2Pvs(Intersectable *object,40 const int side,41 int &pvsBack,42 int &pvsFront)43 {44 if (!object)45 return;46 47 if (side <= 0)48 {49 if (!object->Mailed() && !object->Mailed(2))50 {51 ++ pvsBack;52 53 if (object->Mailed(1))54 object->Mail(2);55 else56 object->Mail();57 }58 }59 60 if (side >= 0)61 {62 if (!object->Mailed(1) && !object->Mailed(2))63 {64 ++ pvsFront;65 66 if (object->Mailed())67 object->Mail(2);68 else69 object->Mail(1);70 }71 }72 }73 74 75 37 /****************************************************************/ 76 38 /* class VspBspTree implementation */ … … 83 45 mViewCellsManager(NULL), 84 46 mStoreRays(false), 85 mOnlyDrivingAxis(false),86 47 mOutOfBoundsCell(NULL) 87 48 { … … 794 755 float VspBspTree::SelectAxisAlignedPlane(Plane3 &plane, 795 756 const VspBspTraversalData &tData, 796 int &bestAxis) 757 int &axis, 758 float &position, 759 int &raysBack, 760 int &raysFront, 761 int &pvsBack, 762 int &pvsFront) 797 763 { 798 764 AxisAlignedBox3 box; … … 810 776 float nPosition[3]; 811 777 float nCostRatio[3]; 812 bestAxis = -1;778 int bestAxis = -1; 813 779 814 780 const int sAxis = box.Size().DrivingAxis(); 815 781 816 for ( intaxis = 0; axis < 3; ++ axis)782 for (axis = 0; axis < 3; ++ axis) 817 783 { 818 784 if (!mOnlyDrivingAxis || axis == sAxis) … … 851 817 } 852 818 853 //-- assign best axis 819 //-- assign values 820 axis = bestAxis; 821 position = nPosition[bestAxis]; 822 823 raysBack = 0;//nRaysBack[bestAxis]; 824 raysFront = 0;//nRaysFront[bestAxis]; 825 826 pvsBack = 0;//nPvsBack[bestAxis]; 827 pvsFront = 0;//nPvsFront[bestAxis]; 828 854 829 Vector3 normal(0,0,0); normal[bestAxis] = 1; 855 830 plane = Plane3(normal, nPosition[bestAxis]); … … 1070 1045 } 1071 1046 1047 1072 1048 bool VspBspTree::SelectPlaneHeuristics(Plane3 &bestPlane, 1073 1049 BspLeaf *leaf, … … 1086 1062 for (int i = 0; i < limit; ++ i) 1087 1063 { 1088 // assure that no index is taken twice1064 //-- assure that no index is taken twice 1089 1065 const int candidateIdx = (int)RandomValue(0, (Real)(-- maxIdx)); 1090 //Debug << "current Idx: " << maxIdx << " cand idx " << candidateIdx << endl;1091 1092 1066 Polygon3 *poly = (*data.mPolygons)[candidateIdx]; 1093 1067 … … 1109 1083 //-- axis aligned splits 1110 1084 int axis; 1111 candidateCost = SelectAxisAlignedPlane(plane, data, axis); 1085 float position; 1086 int raysBack; 1087 int raysFront; 1088 int pvsFront; 1089 int pvsBack; 1090 1091 candidateCost = SelectAxisAlignedPlane(plane, 1092 data, 1093 axis, 1094 position, 1095 raysBack, 1096 raysFront, 1097 pvsFront, 1098 pvsBack); 1112 1099 1113 1100 if (candidateCost < lowestCost) … … 1116 1103 { 1117 1104 useAxisAlignedPlane = true; 1105 //if (data.mPolygons->size() > 0) 1106 // Debug << "haha" << endl; 1118 1107 //! error also computed if cost ratio is missed 1119 1108 ++ mStat.splits[axis]; … … 1142 1131 Intersectable::NewMail(); sFrontAndBackId = ViewCell::sMailId; 1143 1132 } 1133 1144 1134 1145 1135 float VspBspTree::SplitPlaneCost(const Plane3 &candidatePlane, … … 1159 1149 float pBack = 0; 1160 1150 1161 const bool pvsUseLen = false;1162 1163 1151 if (mSplitPlaneStrategy & PVS) 1164 1152 { 1165 // matt: change back!!1166 Intersectable::NewMail(3);1167 1153 // create unique ids for pvs heuristics 1168 //GenerateUniqueIdsForPvs();1154 GenerateUniqueIdsForPvs(); 1169 1155 1170 1156 if (mPvsUseArea) // use front and back cell areas to approximate volume … … 1227 1213 // assure that we only count the object 1228 1214 // once for the front and once for the back side of the plane 1229 1230 // add the termination object 1231 //AddObjToPvs(ray->mTerminationObject, cf, frontPvs, backPvs); 1232 AddObject2Pvs(ray->mTerminationObject, cf, frontPvs, backPvs); 1233 // add the source object 1234 //AddObjToPvs(ray->mOriginObject, cf, frontPvs, backPvs); 1215 AddObjToPvs(ray->mTerminationObject, cf, frontPvs, backPvs); 1216 AddObjToPvs(ray->mOriginObject, cf, frontPvs, backPvs); 1235 1217 1236 1218 // use number of rays to approximate volume 1237 1219 if (!mPvsUseArea) 1238 1220 { 1239 ++ pOverall;1221 pOverall = (float)data.mRays->size(); 1240 1222 1241 1223 if (cf >= 0) … … 1253 1235 1254 1236 if (mSplitPlaneStrategy & BALANCED_RAYS) 1255 cost += mBalancedRaysFactor * fabs(sumBalancedRays) / 1237 cost += mBalancedRaysFactor * fabs(sumBalancedRays) / raysSize; 1256 1238 1257 1239 // pvs criterium … … 2125 2107 BspNode *VspBspTree::CollapseTree(BspNode *node) 2126 2108 { 2127 2109 if (node->IsLeaf()) 2128 2110 return node; 2129 2111 … … 2156 2138 } 2157 2139 2140 return node; 2141 } 2142 2143 2144 void VspBspTree::CollapseTree() 2145 { 2146 CollapseTree(mRoot); 2158 2147 // revalidate leaves 2159 2148 RepairVcLeafLists(); 2160 2161 return node;2162 2149 } 2163 2150 -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h
r492 r495 257 257 int RefineViewCells(const VssRayContainer &rays); 258 258 259 /** Collapses the tree with respect to the view cell partition, 260 i.e. leaves having the same view cell are collapsed. 261 @returns node of type leaf if the node could be collapsed, 262 this node otherwise 263 */ 264 BspNode *CollapseTree(BspNode *node); 259 /** Collapses the tree with respect to the view cell partition. 260 */ 261 void CollapseTree(); 265 262 266 263 ViewCell * … … 315 312 }; 316 313 314 /** Collapses the tree with respect to the view cell partition, 315 i.e. leaves having the same view cell are collapsed. 316 @returns node of type leaf if the node could be collapsed, 317 this node otherwise 318 */ 319 BspNode *CollapseTree(BspNode *node); 317 320 /** Shuffles the leaves, i.e., tests if exchanging 318 321 the leaves helps in improving the view cells. … … 421 424 int AddMeshToPolygons(Mesh *mesh, PolygonContainer &polys, MeshInstance *parent); 422 425 423 /** Selects a plane axis aligned. 426 /** Selects an axis aligned for the next split. 427 @returns cost for this split 424 428 */ 425 429 float SelectAxisAlignedPlane(Plane3 &plane, 426 430 const VspBspTraversalData &tData, 427 int &bestAxis); 431 int &axis, 432 float &position, 433 int &raysBack, 434 int &raysFront, 435 int &pvsBack, 436 int &pvsFront); 428 437 429 438 /** Sorts split candidates for surface area heuristics for axis aligned splits. -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp
r491 r495 188 188 const int maxCostMisses): 189 189 VspKdNode(p), mRays(), mPvsSize(0), mValidPvs(false), mViewCell(NULL), 190 mMaxCostMisses(maxCostMisses) 190 mMaxCostMisses(maxCostMisses), mPvs(NULL), mVolume(0) 191 191 { 192 192 mRays.reserve(nRays); … … 195 195 VspKdLeaf::~VspKdLeaf() 196 196 { 197 DEL_PTR(mPvs); 197 198 } 198 199 … … 785 786 if (1) //-- area substitute for probability 786 787 { 787 788 pOverall = box.SurfaceArea(); 789 788 790 const bool useMidSplit = true; 789 //const bool useMidSplit = false; 790 791 pOverall = box.SurfaceArea(); 792 791 //const bool useMidSplit = false; 792 793 793 if (!useMidSplit) 794 794 { … … 892 892 pvsFront = nPvsFront[bestAxis]; 893 893 894 if (bestAxis == 1) 895 Debug << "y axis!" << endl; 894 896 return nCostRatio[bestAxis]; 895 897 } … … 1887 1889 RayInfoContainer::const_iterator it, it_end = globalRays.end(); 1888 1890 1889 // TODO1891 Intersectable::NewMail(); 1890 1892 1891 1893 // warning: implicit conversion from VssRay to Ray 1892 1894 for (it = globalRays.begin(); it != globalRays.end(); ++ it) 1893 pvsSize += box.GetMinMaxT(*(*it).mRay, NULL, NULL); 1894 1895 { 1896 VssRay *ray = (*it).mRay; 1897 1898 // ray intersects node bounding box 1899 if (box.GetMinMaxT(*ray, NULL, NULL)) 1900 { 1901 if (ray->mTerminationObject && !ray->mTerminationObject->Mailed()) 1902 { 1903 ray->mTerminationObject->Mail(); 1904 ++ pvsSize; 1905 } 1906 } 1907 } 1895 1908 return pvsSize; 1896 1909 } … … 2345 2358 } 2346 2359 2360 return node; 2361 } 2362 2363 2364 void VspKdTree::CollapseTree() 2365 { 2366 CollapseTree(mRoot); 2347 2367 // revalidate leaves 2348 2368 RepairVcLeafLists(); 2349 2350 return node; 2351 } 2352 2369 } 2353 2370 2354 2371 int VspKdTree::RefineViewCells(const VssRayContainer &rays) … … 2379 2396 const bool wasShuffled = false; 2380 2397 //ShuffleLeaves(mc.GetLeaf1(), mc.GetLeaf2()); 2381 2398 // matt: restore 2382 2399 //-- stats 2383 2400 if (wasShuffled) … … 2403 2420 float GetShuffledVcCost(VspKdLeaf *leaf, VspKdViewCell *vc1, VspKdViewCell *vc2) 2404 2421 { 2405 #if 0 // TODO2406 2422 const int pvs1 = SubtractedPvsSize(vc1->GetPvs(), *leaf->mPvs); 2407 2423 const int pvs2 = AddedPvsSize(vc2->GetPvs(), *leaf->mPvs); 2408 2424 2409 const float area1 = vc1->GetArea() - leaf->mArea;2410 const float area2 = vc2->GetArea() + leaf->mArea;2411 2412 const float cost1 = pvs1 * area1;2413 const float cost2 = pvs2 * area2;2425 const float vol1 = vc1->GetVolume() - leaf->mVolume; 2426 const float vol2 = vc2->GetVolume() + leaf->mVolume; 2427 2428 const float cost1 = pvs1 * vol1; 2429 const float cost2 = pvs2 * vol2; 2414 2430 2415 2431 return cost1 + cost2; 2416 #else2417 return -1;2418 #endif2419 2432 } 2420 2433 … … 2424 2437 VspKdViewCell *vc2) const 2425 2438 { 2426 #if 0 // TODO2427 2439 // compute new pvs and area 2428 2440 vc1->GetPvs().SubtractPvs(*leaf->mPvs); 2429 2441 vc2->GetPvs().AddPvs(*leaf->mPvs); 2430 2442 2431 vc1->SetArea(vc1->Get Area() - leaf->mArea);2432 vc2->SetArea(vc2->Get Area() + leaf->mArea);2443 vc1->SetArea(vc1->GetVolume() - leaf->mVolume); 2444 vc2->SetArea(vc2->GetVolume() + leaf->mVolume); 2433 2445 2434 2446 /// add to second view cell … … 2442 2454 2443 2455 leaf->SetViewCell(vc2); // finally change view cell 2444 #endif2445 2456 } 2446 2457 -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h
r486 r495 390 390 391 391 static void NewMail(); 392 393 392 static int sMailId; 394 393 395 394 ObjectPvs *mPvs; 395 float mVolume; 396 396 397 protected: 397 398 … … 616 617 617 618 /** Collapses the tree with respect to the view cell partition. 618 @returns node of type leaf if the node could be collapsed, this node otherwise 619 */ 620 void CollapseTree(); 621 622 protected: 623 624 /** Collapses the tree with respect to the view cell partition. 625 @returns node of type leaf if the node could be collapsed, 626 this node otherwise 619 627 */ 620 628 VspKdNode *CollapseTree(VspKdNode *node); 621 622 protected:623 624 629 // incremental construction 625 630 virtual void UpdateRays(VssRayContainer &remove, VssRayContainer &add);
Note: See TracChangeset
for help on using the changeset viewer.