- Timestamp:
- 11/11/05 21:28:02 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 3 added
- 11 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/Preprocessor.vcproj
r390 r406 243 243 </File> 244 244 <File 245 RelativePath="..\src\RenderSimulator.cpp"> 246 </File> 247 <File 248 RelativePath="..\src\RenderSimulator.h"> 249 </File> 250 <File 245 251 RelativePath="..\src\SamplingPreprocessor.cpp"> 246 252 </File> … … 283 289 <File 284 290 RelativePath="..\src\ViewCellBsp.h"> 291 </File> 292 <File 293 RelativePath="..\src\ViewCellKd.cpp"> 294 </File> 295 <File 296 RelativePath="..\src\ViewCellKd.h"> 285 297 </File> 286 298 <File … … 358 370 RelativePath="..\include\ViewCell.h"> 359 371 </File> 360 <File361 RelativePath="..\include\ViewCellBsp.h">362 </File>363 372 </Filter> 364 373 </Files> -
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r404 r406 56 56 57 57 Sampling { 58 totalSamples 30000058 totalSamples 1000000 59 59 samplesPerPass 3 60 60 } … … 126 126 #splitPlaneStrategy 130 127 127 128 splitPlaneStrategy 1 024128 splitPlaneStrategy 1 129 129 130 maxPolyCandidates 0131 maxRayCandidates 50130 maxPolyCandidates 50 131 maxRayCandidates 100 132 132 133 133 Termination { 134 134 # autopartition 135 maxRays 300135 maxRays 200 136 136 maxPolygons -1 137 137 maxDepth 40 … … 161 161 } 162 162 } 163 164 Simulation { 165 objRenderCost 1.0 166 vcOverhead 0.05 167 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
r403 r406 1177 1177 RegisterOption("ViewCells.PostProcessing.minPvsDif", 1178 1178 optInt, 1179 "-view_cells_ min_pvs_dif",1179 "-view_cells_post_processing_min_pvs_dif", 1180 1180 "10"); 1181 1181 1182 1182 RegisterOption("ViewCells.PostProcessing.maxPvs", 1183 1183 optInt, 1184 "-view_cells_ max_pvs",1184 "-view_cells_post_processing_max_pvs", 1185 1185 "300"); 1186 1186 1187 1187 RegisterOption("ViewCells.PostProcessing.minPvs", 1188 1188 optString, 1189 "-view_cells_ min_pvs",1189 "-view_cells_post_processing_min_pvs", 1190 1190 "10"); 1191 1191 … … 1199 1199 "-view_cells_height=", 1200 1200 "5.0"); 1201 1202 RegisterOption("Simulation.objRenderCost", 1203 optFloat, 1204 "-simulation_obj_render_cost", 1205 "1.0"); 1206 1207 RegisterOption("Simulation.vcOverhead", 1208 optFloat, 1209 "-simulation_vc_overhead", 1210 "0.05"); 1201 1211 1202 1212 RegisterOption("BspTree.Construction.input", -
trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.h
r390 r406 192 192 virtual float IntersectionComplexity() { return (float)mMesh->mFaces.size(); } 193 193 194 virtual int NumberOfFaces() const { return mMesh->mFaces.size(); }194 virtual int NumberOfFaces() const { return (int)mMesh->mFaces.size(); } 195 195 196 196 virtual int Type() const { return MESH_INSTANCE; } -
trunk/VUT/GtpVisibilityPreprocessor/src/Pvs.h
r385 r406 8 8 class Ray; 9 9 class Intersectable; 10 10 class ViewCellKdNode; 11 11 12 12 template<typename T> … … 142 142 143 143 typedef std::map<KdNode *, PvsData<KdNode *>, LtSample<KdNode *> > KdPvsMap; 144 typedef std::map<ViewCellKdNode *, PvsData<ViewCellKdNode *>, LtSample<ViewCellKdNode *> > ViewCellKdPvsMap; 144 145 typedef std::map<Intersectable *, PvsData<Intersectable *>, LtSample<Intersectable *> > ViewCellPvsMap; 145 146 typedef PvsData<Intersectable *> ViewCellPvsData; 146 147 typedef PvsData<KdNode *> KdPvsData; 147 //typedef Pvs<KdNode *>KdPvs;148 typedef Pvs<ViewCellKdNode *> ViewCellKdPvs; 148 149 typedef Pvs<Intersectable *> ViewCellPvs; 149 150 -
trunk/VUT/GtpVisibilityPreprocessor/src/Ray.cpp
r369 r406 172 172 int 173 173 Ray::ClassifyPlane(const Plane3 &plane, 174 const float minT, 175 const float maxT) const 176 { 177 const Vector3 entp = Extrap(minT); 178 const Vector3 extp = Extrap(maxT); 179 180 const int entSide = plane.Side(entp); 181 const int extSide = plane.Side(extp); 174 const float minT, 175 const float maxT, 176 Vector3 &entP, 177 Vector3 &extP) const 178 { 179 entP = Extrap(minT); 180 extP = Extrap(maxT); 181 182 const int entSide = plane.Side(entP); 183 const int extSide = plane.Side(extP); 182 184 183 185 if (entSide < 0) 186 { 187 if (extSide >= 0) 184 188 { 185 if (extSide >= 0) 186 { 187 return BACK_FRONT; 188 } 189 return BACK; 189 return BACK_FRONT; 190 190 } 191 return BACK; 192 } 191 193 else if (entSide > 0) 192 193 194 194 { 195 if (extSide <= 0) 196 return FRONT_BACK; 195 197 196 197 198 return FRONT; 199 } 198 200 else if (entSide == 0) 199 200 201 202 203 204 201 { 202 if (extSide > 0) 203 return BACK_FRONT; 204 else if (extSide < 0) 205 return FRONT_BACK; 206 } 205 207 206 208 return COINCIDENT; -
trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h
r401 r406 214 214 /** Classifies ray with respect to the plane. 215 215 */ 216 int ClassifyPlane(const Plane3 &plane, const float minT, const float maxT) const; 216 int ClassifyPlane(const Plane3 &plane, 217 const float minT, 218 const float maxT, 219 Vector3 &entP, 220 Vector3 &extP) const; 217 221 218 222 private: -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r404 r406 7 7 #include "Polygon3.h" 8 8 #include "ViewCell.h" 9 #include "RenderSimulator.h" 9 10 10 11 SamplingPreprocessor::SamplingPreprocessor(): mPass(0), mSampleRays(NULL) … … 16 17 environment->GetIntValue("ViewCells.PostProcessing.samples", mPostProcessSamples); 17 18 environment->GetIntValue("BspTree.Visualization.samples", mVisualizationSamples); 19 environment->GetFloatValue("Simulation.objRenderCost", mObjRenderCost); 20 environment->GetFloatValue("Simulation.vcOverhead", mVcOverhead); 18 21 19 22 mKdPvsDepth = 100; … … 540 543 //-- render simulation 541 544 cout << "\nevaluating render time before merge ... "; 542 Real rt = SimulateRendering();545 Real rt = BspTreeRenderSimulator(mObjRenderCost, mVcOverhead, mBspTree).SimulateRendering(); 543 546 544 547 cout << "avg render time: " << rt * 1e-3 << endl; … … 586 589 cout << "\nevaluating render time after merge ... "; 587 590 588 rt = SimulateRendering();591 rt = BspTreeRenderSimulator(mObjRenderCost, mVcOverhead, mBspTree).SimulateRendering(); 589 592 590 593 cout << "render time: " << rt * 1e-3 << endl; … … 1034 1037 } 1035 1038 } 1036 1037 1038 Real SamplingPreprocessor::RenderPvs(ViewCell &viewCell,1039 const float objRenderTime) const1040 {1041 return viewCell.GetPvs().GetSize() * objRenderTime;1042 }1043 1044 Real SamplingPreprocessor::SimulateRendering()1045 {1046 Real renderTime = 0;1047 1048 // render time for 1 object of PVS1049 const float objRt = 1.0f;1050 // const overhead for crossing a view cell border1051 const float vcOverhead = 0;//0.01f;1052 1053 // total area of view cells1054 float totalArea = 0;//= mKdTree->GetBox().SurfaceArea();1055 1056 ViewCellContainer viewCells;1057 1058 mBspTree->CollectViewCells(viewCells);1059 1060 ViewCellContainer::const_iterator it, it_end = viewCells.end();1061 1062 for (it = viewCells.begin(); it != it_end; ++ it)1063 {1064 // surface area substitute for probability1065 PolygonContainer cell;1066 float area = 0;1067 1068 mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), cell);1069 1070 area = Polygon3::GetArea(cell);1071 1072 renderTime += area * RenderPvs(*(*it), objRt) + vcOverhead;1073 totalArea += area;1074 CLEAR_CONTAINER(cell);1075 }1076 1077 renderTime /= totalArea;1078 1079 //Debug << "render time without overhead: " << renderTime * 1e-3 << endl;1080 //renderTime += (float)viewCells.size() * vcOverhead;1081 1082 return renderTime;1083 } -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h
r392 r406 99 99 int PostprocessViewCells(const RayContainer &rays); 100 100 101 /** Simulated rendering using a simple render heuristics. Used to evaluate the 102 quality of the view cell partition. 103 */ 104 Real SimulateRendering(); 105 /** Simulates rendering of the pvs of one view cell, with given rendering time for an object. 106 @param viewCell the view cell holding the Pvs 107 @param objRenderTime estimated render time for one object of the Pvs 108 */ 109 Real RenderPvs(ViewCell &viewCell, const float objRenderTime) const; 110 101 // rendering costs for a single object 102 float mObjRenderCost; 103 // rendering overhead when crossing a view cell border 104 float mVcOverhead; 111 105 }; 112 106 113 114 115 107 #endif -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r404 r406 67 67 */ 68 68 float BspTree::sBalancedRaysTable[] = {1, -1, 0, 0, 0}; 69 70 bool BspTree::sPvsUseArea = true; 69 71 70 72 /****************************************************************/ … … 1036 1038 } 1037 1039 1038 Plane3 BspTree::SelectPlane(BspLeaf *leaf, 1039 BspTraversalData &data) 1040 Plane3 BspTree::SelectPlane(BspLeaf *leaf, BspTraversalData &data) 1040 1041 { 1041 1042 if (data.mPolygons->empty() && data.mRays->empty()) … … 1071 1072 if (sSplitPlaneStrategy & RANDOM_POLYGON) 1072 1073 { 1073 1074 if (!data.mPolygons->empty()) 1074 1075 { 1075 1076 Polygon3 *nextPoly = (*data.mPolygons)[Random((int)data.mPolygons->size())]; 1076 1077 return nextPoly->GetSupportingPlane(); 1077 1078 } 1078 1079 else 1080 { 1081 const int candidateIdx = Random((int)data.mRays->size()); 1082 BoundedRay *bRay = (*data.mRays)[candidateIdx]; 1083 1084 Ray *ray = bRay->mRay; 1085 1086 const Vector3 minPt = ray->Extrap(bRay->mMinT); 1087 const Vector3 maxPt = ray->Extrap(bRay->mMaxT); 1088 1089 const Vector3 pt = (maxPt + minPt) * 0.5; 1090 1091 const Vector3 normal = ray->GetDir(); 1092 1093 return Plane3(normal, pt); 1094 } 1095 1079 1096 return Plane3(); 1080 1097 } … … 1084 1101 } 1085 1102 1086 Plane3 BspTree::SelectPlaneHeuristics(BspLeaf *leaf, 1087 BspTraversalData &data) 1103 Plane3 BspTree::SelectPlaneHeuristics(BspLeaf *leaf, BspTraversalData &data) 1088 1104 { 1089 1105 float lowestCost = MAX_FLOAT; 1090 1106 Plane3 bestPlane; 1091 1107 Plane3 plane; 1108 1092 1109 int limit = Min((int)data.mPolygons->size(), sMaxPolyCandidates); 1093 1110 … … 1096 1113 for (int i = 0; i < limit; ++ i) 1097 1114 { 1098 Debug << i << " ";1099 1115 candidateIdx = GetNextCandidateIdx(candidateIdx, *data.mPolygons); 1100 1116 … … 1116 1132 const BoundedRayContainer *rays = data.mRays; 1117 1133 1118 for (int i = 0; i < sMaxRayCandidates; ++ i) 1119 { 1120 Plane3 plane; 1121 1122 if (0) 1123 { 1124 Vector3 pt[3]; 1125 int idx[3]; 1126 int cmaxT = 0; 1127 int cminT = 0; 1128 bool chooseMin = false; 1129 1130 for (int j = 0; j < 3; j ++) 1131 { 1132 idx[j] = Random((int)rays->size() * 2); 1133 1134 if (idx[j] >= (int)rays->size()) 1135 { 1136 idx[j] -= (int)rays->size(); 1137 1138 chooseMin = (cminT < 2); 1139 } 1140 else 1141 chooseMin = (cmaxT < 2); 1142 1143 BoundedRay *bRay = (*rays)[idx[j]]; 1144 pt[j] = chooseMin ? bRay->mRay->Extrap(bRay->mMinT) : bRay->mRay->Extrap(bRay->mMaxT); 1145 } 1134 for (int i = 0; i < sMaxRayCandidates / 2; ++ i) 1135 { 1136 candidateIdx = Random((int)rays->size()); 1137 BoundedRay *bRay = (*rays)[candidateIdx]; 1138 1139 Ray *ray = bRay->mRay; 1140 1141 const Vector3 minPt = ray->Extrap(bRay->mMinT); 1142 const Vector3 maxPt = ray->Extrap(bRay->mMaxT); 1143 1144 const Vector3 pt = (maxPt + minPt) * 0.5; 1145 1146 const Vector3 normal = ray->GetDir(); 1146 1147 1147 plane = Plane3(pt[0], pt[1], pt[2]); 1148 } 1149 else 1150 { 1151 candidateIdx = Random((int)rays->size()); 1152 BoundedRay *bRay = (*rays)[candidateIdx]; 1153 1154 Ray *ray = bRay->mRay; 1155 1156 const Vector3 minPt = ray->Extrap(bRay->mMinT); 1157 const Vector3 maxPt = ray->Extrap(bRay->mMaxT); 1158 1159 const Vector3 pt = (maxPt + minPt) * 0.5; 1160 1161 const Vector3 normal = ray->GetDir(); 1162 1163 plane = Plane3(normal, pt); 1164 } 1165 1148 plane = Plane3(normal, pt); 1149 1166 1150 const float candidateCost = SplitPlaneCost(plane, data); 1167 1151 1168 1152 if (candidateCost < lowestCost) 1169 1153 { 1170 Debug << "choose ray plane: " << candidateCost << endl;1171 1154 bestPlane = plane; 1172 1155 … … 1175 1158 } 1176 1159 1177 Debug << "Plane lowest cost: " << lowestCost << endl; 1160 Debug << "lowest: " << lowestCost << endl; 1161 1162 for (int i = 0; i < sMaxRayCandidates / 2; ++ i) 1163 { 1164 Vector3 pt[3]; 1165 int idx[3]; 1166 int cmaxT = 0; 1167 int cminT = 0; 1168 bool chooseMin = false; 1169 1170 for (int j = 0; j < 3; j ++) 1171 { 1172 idx[j] = Random((int)rays->size() * 2); 1173 1174 if (idx[j] >= (int)rays->size()) 1175 { 1176 idx[j] -= (int)rays->size(); 1177 1178 chooseMin = (cminT < 2); 1179 } 1180 else 1181 chooseMin = (cmaxT < 2); 1182 1183 BoundedRay *bRay = (*rays)[idx[j]]; 1184 pt[j] = chooseMin ? bRay->mRay->Extrap(bRay->mMinT) : bRay->mRay->Extrap(bRay->mMaxT); 1185 } 1186 1187 plane = Plane3(pt[0], pt[1], pt[2]); 1188 1189 const float candidateCost = SplitPlaneCost(plane, data); 1190 1191 if (candidateCost < lowestCost) 1192 { 1193 Debug << "choose ray plane 2: " << candidateCost << endl; 1194 bestPlane = plane; 1195 1196 lowestCost = candidateCost; 1197 } 1198 } 1199 1200 Debug << "plane lowest cost: " << lowestCost << endl; 1178 1201 return bestPlane; 1179 1202 } … … 1358 1381 Intersectable::NewMail(); frontAndBackId = ViewCell::sMailId; 1359 1382 1360 if ( 1) // use front and back cell areas to approximate volume1383 if (sPvsUseArea) // use front and back cell areas to approximate volume 1361 1384 { 1362 1385 // construct child geometry with regard to the candidate split plane … … 1371 1394 pOverall = area; 1372 1395 } 1373 else1374 {1375 pOverall = (float)rays.size();1376 }1377 1396 } 1378 1397 … … 1385 1404 const float maxT = (*rit)->mMaxT; 1386 1405 1406 Vector3 entP, extP; 1407 1387 1408 const int cf = 1388 ray->ClassifyPlane(candidatePlane, minT, maxT );1409 ray->ClassifyPlane(candidatePlane, minT, maxT, entP, extP); 1389 1410 1390 1411 if (sSplitPlaneStrategy & LEAST_RAY_SPLITS) … … 1416 1437 } 1417 1438 1418 // use #rays to approximate volume 1419 if (0) 1439 if (!sPvsUseArea) // use front and back cell areas to approximate volume 1420 1440 { 1421 if ((cf == Ray::BACK) || (cf == Ray::FRONT_BACK) || (cf == Ray::BACK_FRONT)) 1422 ++ pFront; 1423 if ((cf == Ray::FRONT) || (cf == Ray::FRONT_BACK) || (cf == Ray::BACK_FRONT)) 1424 ++ pBack; 1441 float len = Distance(entP, extP); 1442 pOverall += len; 1443 1444 // use length of rays to approximate volume 1445 switch (cf) 1446 { 1447 case Ray::COINCIDENT: 1448 pBack += len; 1449 pFront += len; 1450 break; 1451 case Ray::BACK: 1452 pBack += len; 1453 break; 1454 case Ray::FRONT: 1455 pFront += len; 1456 break; 1457 case Ray::FRONT_BACK: 1458 { 1459 // find intersection of ray segment with plane 1460 const Vector3 extp = ray->Extrap(maxT); 1461 const float t = candidatePlane.FindT(ray->GetLoc(), extp); 1462 1463 const float newT = t * maxT; 1464 float newLen = Distance(ray->Extrap(newT), extp); 1465 1466 pFront += len - newLen; 1467 pBack += newLen; 1468 } 1469 break; 1470 case Ray::BACK_FRONT: 1471 { 1472 // find intersection of ray segment with plane 1473 const Vector3 extp = ray->Extrap(maxT); 1474 const float t = candidatePlane.FindT(ray->GetLoc(), extp); 1475 1476 const float newT = t * maxT; 1477 float newLen = Distance(ray->Extrap(newT), extp); 1478 1479 pFront += len; 1480 pBack += len - newLen; 1481 } 1482 break; 1483 default: 1484 Debug << "Should not come here" << endl; 1485 break; 1486 } 1425 1487 } 1426 1488 } … … 1443 1505 } 1444 1506 1445 if ((val < 0.00001) || (frontPvs + backPvs < pvs)) 1446 { 1447 // create three unique ids for pvs heuristics 1448 Intersectable::NewMail(); backId = ViewCell::sMailId; 1449 Intersectable::NewMail(); frontId = ViewCell::sMailId; 1450 Intersectable::NewMail(); frontAndBackId = ViewCell::sMailId; 1451 1452 1453 BoundedRayContainer::const_iterator rit, rit_end = rays.end(); 1454 1455 int fpvs = 0; int bpvs = 0; 1456 for (rit = rays.begin(); rit != rays.end(); ++ rit) 1457 { 1458 Ray *ray = (*rit)->mRay; 1459 const float minT = (*rit)->mMinT; 1460 const float maxT = (*rit)->mMaxT; 1461 1462 const int cf = 1463 ray->ClassifyPlane(candidatePlane, minT, maxT); 1464 1465 Debug << "classification: " << cf << endl; 1466 if (!ray->intersections.empty()) 1467 { 1468 // in case the ray intersects an objcrs 1469 // assure that we only count a object 1470 // once for the front and once for the back side of the plane 1471 IncPvs(*ray->intersections[0].mObject, fpvs, bpvs, 1472 cf, frontId, backId, frontAndBackId); 1473 } 1474 // the source object in the origin of the ray 1475 if (ray->sourceObject.mObject) 1476 { 1477 IncPvs(*ray->sourceObject.mObject, fpvs, bpvs, 1478 cf, frontId, backId, frontAndBackId); 1479 } 1480 1481 } 1482 1507 if (0) 1483 1508 Debug << "totalpvs: " << pvs << " ptotal: " << pOverall 1484 1509 << " frontpvs: " << frontPvs << " pFront: " << pFront 1485 1510 << " backpvs: " << backPvs << " pBack: " << pBack 1486 << " val " << val << " new size: " << ComputePvsSize(rays) 1487 << " fp " << fpvs << " bp " << bpvs << endl << endl; 1488 1489 } 1511 << " val " << val << " new size: " << ComputePvsSize(rays)<< endl << endl; 1512 1490 1513 return val; 1491 1514 } … … 2016 2039 BoundedRay *bRay = rays.back(); 2017 2040 Ray *ray = bRay->mRay; 2041 float minT = bRay->mMinT; 2042 float maxT = bRay->mMaxT; 2043 2018 2044 rays.pop_back(); 2045 2046 Vector3 entP, extP; 2047 2048 const int cf = 2049 ray->ClassifyPlane(plane, minT, maxT, entP, extP); 2019 2050 2020 const int cf = 2021 ray->ClassifyPlane(plane, bRay->mMinT, bRay->mMaxT); 2022 2051 // set id to ray classification 2023 2052 ray->SetId(cf); 2024 2053 2025 2054 switch (cf) 2026 2055 { 2027 case Ray::COINCIDENT: 2056 case Ray::COINCIDENT: // TODO: should really discard ray? 2028 2057 //frontRays.push_back(bRay); 2029 2058 DEL_PTR(bRay); … … 2038 2067 { 2039 2068 // find intersection of ray segment with plane 2040 const Vector3 extp = ray->Extrap(bRay->mMaxT); 2041 const float t = plane.FindT(ray->GetLoc(), extp); 2069 const float t = plane.FindT(ray->GetLoc(), extP); 2042 2070 2043 const float newT = t * bRay->mMaxT;2044 2045 frontRays.push_back(new BoundedRay(ray, bRay->mMinT, newT));2046 backRays.push_back(new BoundedRay(ray, newT, bRay->mMaxT));2071 const float newT = t * maxT; 2072 2073 frontRays.push_back(new BoundedRay(ray, minT, newT)); 2074 backRays.push_back(new BoundedRay(ray, newT, maxT)); 2047 2075 2048 2076 DEL_PTR(bRay); … … 2054 2082 { 2055 2083 // find intersection of ray segment with plane 2056 const Vector3 extp = ray->Extrap(bRay->mMaxT); 2057 const float t = plane.FindT(ray->GetLoc(), extp); 2084 const float t = plane.FindT(ray->GetLoc(), extP); 2058 2085 const float newT = t * bRay->mMaxT; 2059 2086 … … 2411 2438 for (int i = 0; i < (int)mPolys.size(); ++ i) 2412 2439 { 2413 const int cf = mPolys[i]->ClassifyPlane(splitPlane, 0.00001 );2440 const int cf = mPolys[i]->ClassifyPlane(splitPlane, 0.00001f); 2414 2441 2415 2442 // split new polygon with all previous planes … … 2473 2500 2474 2501 const int cf = 2475 planePoly->ClassifyPlane(plane, 0.00001 );2502 planePoly->ClassifyPlane(plane, 0.00001f); 2476 2503 2477 2504 // split new polygon with all previous planes -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r400 r406 814 814 static int sMinPvs; 815 815 static int sMaxPvs; 816 static bool sPvsUseArea; 816 817 817 818 private: -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellKd.h
r405 r406 1 #ifndef _ KdTree_H__2 #define _ KdTree_H__1 #ifndef _ViewCellKdTree_H__ 2 #define _ViewCellKdTree_H__ 3 3 4 4 #include <functional> … … 11 11 12 12 13 class KdNode;14 class KdLeaf;15 class KdInterior;13 class ViewCellKdNode; 14 class ViewCellKdLeaf; 15 class ViewCellKdInterior; 16 16 class Intersectable; 17 17 … … 20 20 // Static statistics for kd-tree search 21 21 // -------------------------------------------------------------- 22 class KdTreeStatistics22 class ViewCellKdTreeStatistics 23 23 { 24 24 public: … … 51 51 52 52 // Constructor 53 KdTreeStatistics() {53 ViewCellKdTreeStatistics() { 54 54 Reset(); 55 55 } … … 75 75 Print(ostream &app) const; 76 76 77 friend ostream &operator<<(ostream &s, const KdTreeStatistics &stat) {77 friend ostream &operator<<(ostream &s, const ViewCellKdTreeStatistics &stat) { 78 78 stat.Print(s); 79 79 return s; … … 83 83 84 84 85 class KdInterior;85 class ViewCellKdInterior; 86 86 /** Abstract class for kd-tree node */ 87 class KdNode {87 class ViewCellKdNode { 88 88 public: 89 89 static int mailID; … … 95 95 96 96 97 KdNode(KdInterior *parent);97 ViewCellKdNode(ViewCellKdInterior *parent); 98 98 99 99 /** Determines whether this node is a leaf or interior node … … 111 111 /** Parent of the node - the parent is a little overhead for maintanance of the tree, 112 112 but allows various optimizations of tree traversal algorithms */ 113 KdInterior *mParent;113 ViewCellKdInterior *mParent; 114 114 int mDepth; 115 115 }; 116 116 117 117 /** Implementation of the kd-tree interior node */ 118 class KdInterior : publicKdNode {118 class ViewCellKdInterior : public ViewCellKdNode { 119 119 120 120 public: 121 121 122 KdInterior(KdInterior *parent):KdNode(parent), mBack(NULL), mFront(NULL) {}123 124 /** \sa KdNode::IsLeaf() */122 ViewCellKdInterior(ViewCellKdInterior *parent):ViewCellKdNode(parent), mBack(NULL), mFront(NULL) {} 123 124 /** \sa ViewCellKdNode::IsLeaf() */ 125 125 virtual bool IsLeaf() const { return false; } 126 126 … … 133 133 134 134 /** back node */ 135 KdNode *mBack;135 ViewCellKdNode *mBack; 136 136 /** front node */ 137 KdNode *mFront;138 139 void SetupChildLinks( KdNode *b,KdNode *f) {137 ViewCellKdNode *mFront; 138 139 void SetupChildLinks(ViewCellKdNode *b, ViewCellKdNode *f) { 140 140 mBack = b; 141 141 mFront = f; … … 143 143 } 144 144 145 void ReplaceChildLink( KdNode *oldChild,KdNode *newChild) {145 void ReplaceChildLink(ViewCellKdNode *oldChild, ViewCellKdNode *newChild) { 146 146 if (mBack == oldChild) 147 147 mBack = newChild; … … 155 155 156 156 /** Implementation of the kd-tree leaf node */ 157 class KdLeaf : publicKdNode {157 class ViewCellKdLeaf : public ViewCellKdNode { 158 158 public: 159 KdLeaf(KdInterior *parent, const int objects):KdNode(parent) {159 ViewCellKdLeaf(ViewCellKdInterior *parent, const int objects):ViewCellKdNode(parent) { 160 160 mObjects.reserve(objects); 161 161 } … … 176 176 } 177 177 178 /** \sa KdNode::IsLeaf() */178 /** \sa ViewCellKdNode::IsLeaf() */ 179 179 virtual bool IsLeaf() const { return true; } 180 180 … … 191 191 PassingRaySet mPassingRays; 192 192 193 /** PVS consisting of visible KdTreenodes */194 KdPvs mKdPvs;193 /** PVS consisting of visible ViewCellKd nodes */ 194 ViewCellKdPvs mKdPvs; 195 195 196 196 /** PVS consisting of visible objects */ … … 200 200 201 201 202 /** KdTreefor indexing scene entities - occluders/occludees/viewcells */203 class KdTree{202 /** ViewCellKd for indexing scene entities - occluders/occludees/viewcells */ 203 class ViewCellKd { 204 204 205 205 protected: 206 206 struct TraversalData 207 207 { 208 KdNode *mNode;208 ViewCellKdNode *mNode; 209 209 AxisAlignedBox3 mBox; 210 210 int mDepth; … … 213 213 TraversalData() {} 214 214 215 TraversalData( KdNode *n, const float p):215 TraversalData(ViewCellKdNode *n, const float p): 216 216 mNode(n), mPriority(p) 217 217 {} 218 218 219 TraversalData( KdNode *n,219 TraversalData(ViewCellKdNode *n, 220 220 const AxisAlignedBox3 &b, 221 221 const int d): … … 225 225 bool operator<( 226 226 const TraversalData &b) const { 227 KdLeaf *leafa = (KdLeaf *) mNode;228 KdLeaf *leafb = (KdLeaf *) b.mNode;227 ViewCellKdLeaf *leafa = (ViewCellKdLeaf *) mNode; 228 ViewCellKdLeaf *leafb = (ViewCellKdLeaf *) b.mNode; 229 229 return 230 230 leafa->mObjects.size()*mBox.SurfaceArea() … … 254 254 SPLIT_SAH}; 255 255 256 KdTree();256 ViewCellKd(); 257 257 258 258 … … 274 274 were already met 275 275 */ 276 virtual KdNode *Subdivide(const TraversalData &tdata);276 virtual ViewCellKdNode *Subdivide(const TraversalData &tdata); 277 277 278 278 /** Get the root of the tree */ 279 KdNode *GetRoot() const {279 ViewCellKdNode *GetRoot() const { 280 280 return mRoot; 281 281 } … … 289 289 ); 290 290 291 const KdTreeStatistics &GetStatistics() const {291 const ViewCellKdTreeStatistics &GetStatistics() const { 292 292 return mStat; 293 293 } 294 294 295 295 void 296 CollectObjects( KdNode *n, ObjectContainer &objects);296 CollectObjects(ViewCellKdNode *n, ObjectContainer &objects); 297 297 298 298 void 299 CollectLeaves(vector< KdLeaf *> &leaves);300 301 AxisAlignedBox3 GetBox(const KdNode *node) const {302 KdInterior *parent = node->mParent;299 CollectLeaves(vector<ViewCellKdLeaf *> &leaves); 300 301 AxisAlignedBox3 GetBox(const ViewCellKdNode *node) const { 302 ViewCellKdInterior *parent = node->mParent; 303 303 if (parent == NULL) 304 304 return mBox; 305 305 306 306 if (!node->IsLeaf()) 307 return (( KdInterior *)node)->mBox;307 return ((ViewCellKdInterior *)node)->mBox; 308 308 309 309 AxisAlignedBox3 box(parent->mBox); … … 315 315 } 316 316 317 KdNode *318 FindRandomNeighbor( KdNode *n,317 ViewCellKdNode * 318 FindRandomNeighbor(ViewCellKdNode *n, 319 319 bool onlyUnmailed 320 320 ); 321 321 322 KdNode *323 KdTree::GetRandomLeaf(const Plane3 &halfspace);324 325 KdNode *322 ViewCellKdNode * 323 ViewCellKd::GetRandomLeaf(const Plane3 &halfspace); 324 325 ViewCellKdNode * 326 326 GetRandomLeaf(const bool onlyUnmailed = false); 327 327 328 328 int 329 FindNeighbors( KdNode *n,330 vector< KdNode *> &neighbors,329 FindNeighbors(ViewCellKdNode *n, 330 vector<ViewCellKdNode *> &neighbors, 331 331 bool onlyUnmailed 332 332 ); … … 419 419 420 420 struct RayTraversalData { 421 KdNode *mNode;421 ViewCellKdNode *mNode; 422 422 Vector3 mExitPoint; 423 423 float mMaxT; 424 424 425 425 RayTraversalData() {} 426 RayTraversalData( KdNode *n,426 RayTraversalData(ViewCellKdNode *n, 427 427 const Vector3 &p, 428 428 const float maxt): … … 460 460 float 461 461 BestCostRatio( 462 KdLeaf *node,462 ViewCellKdLeaf *node, 463 463 const AxisAlignedBox3 &box, 464 464 const int axis, … … 470 470 void 471 471 SortSplitCandidates( 472 KdLeaf *node,472 ViewCellKdLeaf *node, 473 473 const int axis 474 474 ); … … 477 477 EvaluateLeafStats(const TraversalData &data); 478 478 479 KdNode *479 ViewCellKdNode * 480 480 SubdivideNode( 481 KdLeaf *leaf,481 ViewCellKdLeaf *leaf, 482 482 const AxisAlignedBox3 &box, 483 483 AxisAlignedBox3 &backBBox, … … 486 486 487 487 bool 488 TerminationCriteriaMet(const KdLeaf *leaf);488 TerminationCriteriaMet(const ViewCellKdLeaf *leaf); 489 489 490 490 int 491 SelectPlane( KdLeaf *leaf,491 SelectPlane(ViewCellKdLeaf *leaf, 492 492 const AxisAlignedBox3 &box, 493 493 float &position … … 504 504 bool mSahUseFaces; 505 505 /// root of the tree 506 KdNode *mRoot;506 ViewCellKdNode *mRoot; 507 507 /// bounding box of the tree root 508 508 AxisAlignedBox3 mBox; 509 KdTreeStatistics mStat;509 ViewCellKdTreeStatistics mStat; 510 510 511 511 }; 512 513 514 515 516 517 512 518 513 #endif
Note: See TracChangeset
for help on using the changeset viewer.