Changeset 448 for trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
- Timestamp:
- 12/05/05 04:42:54 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r445 r448 98 98 } 99 99 100 Plane3 *BspInterior::GetPlane()101 { 102 return &mPlane;100 Plane3 BspInterior::GetPlane() const 101 { 102 return mPlane; 103 103 } 104 104 … … 117 117 } 118 118 119 int BspInterior::SplitPolygons(PolygonContainer &polys,120 PolygonContainer &frontPolys,121 PolygonContainer &backPolys,122 PolygonContainer &coincident)123 {124 int splits = 0;125 126 #ifdef _Debug127 Debug << "splitting polygons of node " << this << " with plane " << mPlane << endl;128 #endif129 while (!polys.empty())130 {131 Polygon3 *poly = polys.back();132 polys.pop_back();133 134 //Debug << "New polygon with plane: " << poly->GetSupportingPlane() << "\n";135 136 // classify polygon137 const int cf = poly->ClassifyPlane(mPlane);138 139 switch (cf)140 {141 case Polygon3::COINCIDENT:142 coincident.push_back(poly);143 break;144 case Polygon3::FRONT_SIDE:145 frontPolys.push_back(poly);146 break;147 case Polygon3::BACK_SIDE:148 backPolys.push_back(poly);149 break;150 case Polygon3::SPLIT:151 {152 Polygon3 *front_piece = new Polygon3(poly->mParent);153 Polygon3 *back_piece = new Polygon3(poly->mParent);154 155 //-- split polygon into front and back part156 poly->Split(mPlane, *front_piece, *back_piece);157 158 ++ splits; // increase number of splits159 160 //-- inherit rays from parent polygon for blocked ray criterium161 poly->InheritRays(*front_piece, *back_piece);162 //Debug << "p: " << poly->mPiercingRays.size() << " f: " << front_piece->mPiercingRays.size() << " b: " << back_piece->mPiercingRays.size() << endl;163 164 // check if polygons still valid165 if (front_piece->Valid())166 frontPolys.push_back(front_piece);167 else168 DEL_PTR(front_piece);169 170 if (back_piece->Valid())171 backPolys.push_back(back_piece);172 else173 DEL_PTR(back_piece);174 175 #ifdef _DEBUG176 Debug << "split " << *poly << endl << *front_piece << endl << *back_piece << endl;177 #endif178 DEL_PTR(poly);179 }180 break;181 default:182 Debug << "SHOULD NEVER COME HERE\n";183 break;184 }185 }186 187 return splits;188 }189 190 119 /****************************************************************/ 191 120 /* class BspLeaf implementation */ 192 121 /****************************************************************/ 122 123 193 124 BspLeaf::BspLeaf(): mViewCell(NULL) 194 125 { 195 126 } 127 196 128 197 129 BspLeaf::BspLeaf(BspViewCell *viewCell): … … 199 131 { 200 132 } 133 201 134 202 135 BspLeaf::BspLeaf(BspInterior *parent): … … 204 137 {} 205 138 139 140 206 141 BspLeaf::BspLeaf(BspInterior *parent, BspViewCell *viewCell): 207 142 BspNode(parent), mViewCell(viewCell) … … 222 157 { 223 158 return true; 224 }225 226 void BspLeaf::AddToPvs(const BoundedRayContainer &rays,227 int &sampleContributions,228 int &contributingSamples)229 {230 sampleContributions = 0;231 contributingSamples = 0;232 233 BoundedRayContainer::const_iterator it, it_end = rays.end();234 235 // add contributions from samples to the PVS236 for (it = rays.begin(); it != it_end; ++ it)237 {238 int contribution = 0;239 Ray *ray = (*it)->mRay;240 241 if (!ray->intersections.empty())242 contribution += mViewCell->GetPvs().AddSample(ray->intersections[0].mObject);243 244 if (ray->sourceObject.mObject)245 contribution += mViewCell->GetPvs().AddSample(ray->sourceObject.mObject);246 247 if (contribution)248 {249 sampleContributions += contribution;250 ++ contributingSamples;251 }252 253 //if (ray->mFlags & Ray::STORE_BSP_INTERSECTIONS)254 ray->bspIntersections.push_back(Ray::BspIntersection((*it)->mMinT, this));255 }256 159 } 257 160 … … 308 211 environment->GetIntValue("BspTree.maxTests", mMaxTests); 309 212 310 environment->GetFloatValue("BspTree.Construction.sideTolerance", Vector3::sDistTolerance); 311 Vector3::sDistToleranceSqrt = Vector3::sDistTolerance * Vector3::sDistTolerance; 312 313 213 environment->GetFloatValue("BspTree.Construction.epsilon", mEpsilon); 214 314 215 Debug << "BSP max depth: " << mTermMaxDepth << endl; 315 216 Debug << "BSP min PVS: " << mTermMinPvs << endl; … … 347 248 } 348 249 250 349 251 const BspTreeStatistics &BspTree::GetStatistics() const 350 252 { 351 253 return mStat; 352 254 } 255 256 257 int BspTree::SplitPolygons(const Plane3 &plane, 258 PolygonContainer &polys, 259 PolygonContainer &frontPolys, 260 PolygonContainer &backPolys, 261 PolygonContainer &coincident) const 262 { 263 int splits = 0; 264 265 #ifdef _Debug 266 Debug << "splitting polygons of node " << this << " with plane " << mPlane << endl; 267 #endif 268 while (!polys.empty()) 269 { 270 Polygon3 *poly = polys.back(); 271 polys.pop_back(); 272 273 //Debug << "New polygon with plane: " << poly->GetSupportingPlane() << "\n"; 274 275 // classify polygon 276 const int cf = poly->ClassifyPlane(plane, mEpsilon); 277 278 switch (cf) 279 { 280 case Polygon3::COINCIDENT: 281 coincident.push_back(poly); 282 break; 283 case Polygon3::FRONT_SIDE: 284 frontPolys.push_back(poly); 285 break; 286 case Polygon3::BACK_SIDE: 287 backPolys.push_back(poly); 288 break; 289 case Polygon3::SPLIT: 290 { 291 Polygon3 *front_piece = new Polygon3(poly->mParent); 292 Polygon3 *back_piece = new Polygon3(poly->mParent); 293 294 //-- split polygon into front and back part 295 poly->Split(plane, 296 *front_piece, 297 *back_piece, 298 mEpsilon); 299 300 ++ splits; // increase number of splits 301 302 //-- inherit rays from parent polygon for blocked ray criterium 303 poly->InheritRays(*front_piece, *back_piece); 304 305 // check if polygons still valid 306 if (front_piece->Valid(mEpsilon)) 307 frontPolys.push_back(front_piece); 308 else 309 DEL_PTR(front_piece); 310 311 if (back_piece->Valid(mEpsilon)) 312 backPolys.push_back(back_piece); 313 else 314 DEL_PTR(back_piece); 315 316 #ifdef _DEBUG 317 Debug << "split " << *poly << endl << *front_piece << endl << *back_piece << endl; 318 #endif 319 DEL_PTR(poly); 320 } 321 break; 322 default: 323 Debug << "SHOULD NEVER COME HERE\n"; 324 break; 325 } 326 } 327 328 return splits; 329 } 330 353 331 354 332 void BspTreeStatistics::Print(ostream &app) const … … 458 436 459 437 // split viewcell polygons with respect to split plane 460 splits += interior->SplitPolygons(*tData.mPolygons, 461 *frontPolys, 462 *backPolys, 463 coincident); 438 splits += SplitPolygons(interior->GetPlane(), 439 *tData.mPolygons, 440 *frontPolys, 441 *backPolys, 442 coincident); 464 443 465 444 // extract view cells associated with the split polygons … … 505 484 // cleanup 506 485 DEL_PTR(tData.mPolygons); 486 DEL_PTR(tData.mRays); 507 487 } 508 488 else … … 514 494 } 515 495 516 int BspTree::AddMeshToPolygons(Mesh *mesh, PolygonContainer &polys, MeshInstance *parent) 496 int BspTree::AddMeshToPolygons(Mesh *mesh, 497 PolygonContainer &polys, 498 MeshInstance *parent) 517 499 { 518 500 FaceContainer::const_iterator fi; … … 523 505 Polygon3 *poly = new Polygon3((*fi), mesh); 524 506 525 if (poly->Valid( ))507 if (poly->Valid(mEpsilon)) 526 508 { 527 509 poly->mParent = parent; // set parent intersectable … … 684 666 685 667 float minT, maxT; 686 if ( BoundRay(*ray, minT, maxT))668 if (mBox.GetRaySegment(*ray, minT, maxT)) 687 669 rays->push_back(new BoundedRay(ray, minT, maxT)); 688 670 } … … 719 701 720 702 float minT, maxT; 721 if ( BoundRay(*ray, minT, maxT))703 if (mBox.GetRaySegment(*ray, minT, maxT)) 722 704 rays->push_back(new BoundedRay(ray, minT, maxT)); 723 705 } … … 801 783 { 802 784 int conSamp = 0, sampCon = 0; 803 leaf->AddToPvs(*tData.mRays, conSamp, sampCon);785 AddToPvs(leaf, *tData.mRays, conSamp, sampCon); 804 786 805 787 mStat.contributingSamples += conSamp; … … 818 800 DEL_PTR(tData.mPolygons); 819 801 DEL_PTR(tData.mRays); 820 802 DEL_PTR(tData.mGeometry); 803 821 804 return leaf; 822 805 } … … 860 843 // cleanup 861 844 DEL_PTR(tData.mNode); 845 862 846 DEL_PTR(tData.mPolygons); 863 847 DEL_PTR(tData.mRays); … … 916 900 917 901 918 Debug << "number of rays: " << tData.mRays->size() << endl;919 Debug << "number of polys: " << tData.mPolygons->size() << endl;902 Debug << "number of rays: " << (int)tData.mRays->size() << endl; 903 Debug << "number of polys: " << (int)tData.mPolygons->size() << endl; 920 904 921 905 startTime = GetTime(); … … 928 912 startTime = GetTime(); 929 913 // subdivide polygons with plane 930 mStat.splits += interior->SplitPolygons(*tData.mPolygons, 931 *frontData.mPolygons, 932 *backData.mPolygons, 933 coincident); 914 mStat.splits += SplitPolygons(interior->GetPlane(), 915 *tData.mPolygons, 916 *frontData.mPolygons, 917 *backData.mPolygons, 918 coincident); 934 919 935 920 Debug << "time used for polygon splitting: " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; … … 944 929 tData.mGeometry->SplitGeometry(*frontData.mGeometry, 945 930 *backData.mGeometry, 946 *this, 947 interior->mPlane); 931 interior->mPlane, 932 mBox, 933 mEpsilon); 948 934 949 935 … … 974 960 interior->SetupChildLinks(new BspLeaf(interior), new BspLeaf(interior)); 975 961 976 frontData.mNode = interior-> mFront;977 backData.mNode = interior-> mBack;962 frontData.mNode = interior->GetFront(); 963 backData.mNode = interior->GetBack(); 978 964 979 965 //DEL_PTR(leaf); … … 1269 1255 1270 1256 BoundedRay *bRay = (*rays)[idx[j]]; 1271 pt[j] = chooseMin ? bRay->mRay->Extrap(bRay->mMinT) : bRay->mRay->Extrap(bRay->mMaxT); 1257 pt[j] = chooseMin ? bRay->mRay->Extrap(bRay->mMinT) : 1258 bRay->mRay->Extrap(bRay->mMaxT); 1272 1259 } 1273 1260 … … 1347 1334 Polygon3 *poly = polys[testIdx]; 1348 1335 1349 const int classification = poly->ClassifyPlane(candidatePlane); 1336 const int classification = 1337 poly->ClassifyPlane(candidatePlane, mEpsilon); 1350 1338 1351 1339 if (mSplitPlaneStrategy & BALANCED_POLYS) … … 1437 1425 } 1438 1426 1439 bool BspTree::BoundRay(const Ray &ray, float &minT, float &maxT) const1440 {1441 maxT = 1e6;1442 minT = 0;1443 1444 // test with tree bounding box1445 if (!mBox.GetMinMaxT(ray, &minT, &maxT))1446 return false;1447 1448 if (minT < 0) // start ray from origin1449 minT = 0;1450 1451 // bound ray or line segment1452 if (//(ray.GetType() == Ray::LOCAL_RAY) &&1453 !ray.intersections.empty() &&1454 (ray.intersections[0].mT <= maxT))1455 {1456 maxT = ray.intersections[0].mT;1457 }1458 1459 return true;1460 }1461 1427 1462 1428 inline void BspTree::GenerateUniqueIdsForPvs() … … 1499 1465 BspNodeGeometry backCell; 1500 1466 1501 cell.SplitGeometry(frontCell, backCell, *this, candidatePlane); 1467 cell.SplitGeometry(frontCell, 1468 backCell, 1469 candidatePlane, 1470 mBox, 1471 mEpsilon); 1502 1472 1503 1473 pFront = frontCell.GetArea(); … … 1803 1773 float maxt, mint; 1804 1774 1805 if (! BoundRay(ray, mint, maxt))1775 if (!mBox.GetRaySegment(ray, mint, maxt)) 1806 1776 return 0; 1807 1777 … … 1818 1788 if (!node->IsLeaf()) 1819 1789 { 1820 BspInterior *in = (BspInterior *) node;1790 BspInterior *in = dynamic_cast<BspInterior *>(node); 1821 1791 1822 Plane3 *splitPlane = in->GetPlane(); 1823 1824 int entSide = splitPlane->Side(entp); 1825 int extSide = splitPlane->Side(extp); 1826 1827 Vector3 intersection; 1792 Plane3 splitPlane = in->GetPlane(); 1793 const int entSide = splitPlane.Side(entp); 1794 const int extSide = splitPlane.Side(extp); 1828 1795 1829 1796 if (entSide < 0) … … 1858 1825 // find intersection of ray segment with plane 1859 1826 float t; 1860 extp = splitPlane ->FindIntersection(ray.GetLoc(), extp, &t);1827 extp = splitPlane.FindIntersection(ray.GetLoc(), extp, &t); 1861 1828 maxt *= t; 1862 1829 … … 1934 1901 BspInterior *interior = dynamic_cast<BspInterior *>(node); 1935 1902 1936 nodeStack.push(interior-> mFront);1937 nodeStack.push(interior-> mBack);1903 nodeStack.push(interior->GetFront()); 1904 nodeStack.push(interior->GetBack()); 1938 1905 } 1939 1906 } … … 1989 1956 BspInterior *interior = dynamic_cast<BspInterior *>(node); 1990 1957 1991 nodeStack.push(interior-> mFront);1992 nodeStack.push(interior-> mBack);1958 nodeStack.push(interior->GetFront()); 1959 nodeStack.push(interior->GetBack()); 1993 1960 } 1994 1961 } … … 2101 2068 { 2102 2069 BspInterior *interior = dynamic_cast<BspInterior *>(n); 2103 Plane3 halfSpace = *dynamic_cast<BspInterior *>(interior)->GetPlane();2104 2105 if (interior-> mFront!= lastNode)2070 Plane3 halfSpace = dynamic_cast<BspInterior *>(interior)->GetPlane(); 2071 2072 if (interior->GetFront() != lastNode) 2106 2073 halfSpace.ReverseOrientation(); 2107 2074 … … 2135 2102 ExtractHalfSpaces(n, halfSpaces); 2136 2103 2137 PolygonContainer candidate Polys;2104 PolygonContainer candidates; 2138 2105 2139 2106 // bounded planes are added to the polygons (reverse polygons … … 2143 2110 Polygon3 *p = GetBoundingBox().CrossSection(halfSpaces[i]); 2144 2111 2145 if (p->Valid( ))2146 { 2147 candidate Polys.push_back(p->CreateReversePolygon());2112 if (p->Valid(mEpsilon)) 2113 { 2114 candidates.push_back(p->CreateReversePolygon()); 2148 2115 DEL_PTR(p); 2149 2116 } … … 2158 2125 vertices.push_back(mBox.GetFace(i).mVertices[j]); 2159 2126 2160 candidate Polys.push_back(new Polygon3(vertices));2161 } 2162 2163 for (int i = 0; i < (int)candidate Polys.size(); ++ i)2127 candidates.push_back(new Polygon3(vertices)); 2128 } 2129 2130 for (int i = 0; i < (int)candidates.size(); ++ i) 2164 2131 { 2165 2132 // polygon is split by all other planes 2166 for (int j = 0; (j < (int)halfSpaces.size()) && candidate Polys[i]; ++ j)2133 for (int j = 0; (j < (int)halfSpaces.size()) && candidates[i]; ++ j) 2167 2134 { 2168 2135 if (i == j) // polygon and plane are coincident … … 2172 2139 Polygon3 *frontPoly, *backPoly; 2173 2140 2174 const int cf = candidatePolys[i]->ClassifyPlane(halfSpaces[j]); 2141 const int cf = candidates[i]-> 2142 ClassifyPlane(halfSpaces[j], mEpsilon); 2175 2143 2176 2144 switch (cf) … … 2180 2148 backPoly = new Polygon3(); 2181 2149 2182 candidatePolys[i]->Split(halfSpaces[j], 2183 *frontPoly, 2184 *backPoly); 2185 2186 DEL_PTR(candidatePolys[i]); 2187 2188 if (frontPoly->Valid()) 2189 candidatePolys[i] = frontPoly; 2150 candidates[i]->Split(halfSpaces[j], 2151 *frontPoly, 2152 *backPoly, 2153 mEpsilon); 2154 2155 DEL_PTR(candidates[i]); 2156 2157 if (frontPoly->Valid(mEpsilon)) 2158 candidates[i] = frontPoly; 2190 2159 else 2191 2160 DEL_PTR(frontPoly); … … 2194 2163 break; 2195 2164 case Polygon3::BACK_SIDE: 2196 DEL_PTR(candidate Polys[i]);2165 DEL_PTR(candidates[i]); 2197 2166 break; 2198 2167 // just take polygon as it is … … 2204 2173 } 2205 2174 2206 if (candidate Polys[i])2207 cell.push_back(candidate Polys[i]);2175 if (candidates[i]) 2176 cell.push_back(candidates[i]); 2208 2177 } 2209 2178 } … … 2242 2211 { 2243 2212 const int cf = 2244 Polygon3::ClassifyPlane(neighborCandidate, halfSpaces[i]); 2213 Polygon3::ClassifyPlane(neighborCandidate, 2214 halfSpaces[i], 2215 mEpsilon); 2245 2216 2246 2217 if (cf == Polygon3::BACK_SIDE) … … 2258 2229 BspInterior *interior = dynamic_cast<BspInterior *>(node); 2259 2230 2260 const int cf = Polygon3::ClassifyPlane(cell, interior->mPlane); 2231 const int cf = Polygon3::ClassifyPlane(cell, 2232 interior->mPlane, 2233 mEpsilon); 2261 2234 2262 2235 if (cf == Polygon3::FRONT_SIDE) 2263 nodeStack.push(interior-> mFront);2236 nodeStack.push(interior->GetFront()); 2264 2237 else 2265 2238 if (cf == Polygon3::BACK_SIDE) 2266 nodeStack.push(interior-> mBack);2239 nodeStack.push(interior->GetBack()); 2267 2240 else 2268 2241 { 2269 2242 // random decision 2270 nodeStack.push(interior-> mBack);2271 nodeStack.push(interior-> mFront);2243 nodeStack.push(interior->GetBack()); 2244 nodeStack.push(interior->GetFront()); 2272 2245 } 2273 2246 } … … 2305 2278 ConstructGeometry(interior, cell); 2306 2279 2307 const int cf = Polygon3::ClassifyPlane(cell, halfspace); 2280 const int cf = Polygon3::ClassifyPlane(cell, 2281 halfspace, 2282 mEpsilon); 2308 2283 2309 2284 if (cf == Polygon3::BACK_SIDE) 2310 next = interior-> mFront;2285 next = interior->GetFront(); 2311 2286 else 2312 2287 if (cf == Polygon3::FRONT_SIDE) 2313 next = interior-> mFront;2288 next = interior->GetFront(); 2314 2289 else 2315 2290 { 2316 2291 // random decision 2317 2292 if (mask & 1) 2318 next = interior-> mBack;2293 next = interior->GetBack(); 2319 2294 else 2320 next = interior-> mFront;2295 next = interior->GetFront(); 2321 2296 mask = mask >> 1; 2322 2297 } … … 2353 2328 // random decision 2354 2329 if (mask & 1) 2355 nodeStack.push(interior-> mBack);2330 nodeStack.push(interior->GetBack()); 2356 2331 else 2357 nodeStack.push(interior-> mFront);2332 nodeStack.push(interior->GetFront()); 2358 2333 2359 2334 mask = mask >> 1; … … 2362 2337 2363 2338 return NULL; 2339 } 2340 2341 void BspTree::AddToPvs(BspLeaf *leaf, 2342 const BoundedRayContainer &rays, 2343 int &sampleContributions, 2344 int &contributingSamples) 2345 { 2346 sampleContributions = 0; 2347 contributingSamples = 0; 2348 2349 BoundedRayContainer::const_iterator it, it_end = rays.end(); 2350 2351 ViewCell *vc = leaf->GetViewCell(); 2352 2353 // add contributions from samples to the PVS 2354 for (it = rays.begin(); it != it_end; ++ it) 2355 { 2356 int contribution = 0; 2357 Ray *ray = (*it)->mRay; 2358 2359 if (!ray->intersections.empty()) 2360 contribution += vc->GetPvs().AddSample(ray->intersections[0].mObject); 2361 2362 if (ray->sourceObject.mObject) 2363 contribution += vc->GetPvs().AddSample(ray->sourceObject.mObject); 2364 2365 if (contribution) 2366 { 2367 sampleContributions += contribution; 2368 ++ contributingSamples; 2369 } 2370 2371 //if (ray->mFlags & Ray::STORE_BSP_INTERSECTIONS) 2372 // ray->bspIntersections.push_back(Ray::BspIntersection((*it)->mMinT, this)); 2373 } 2364 2374 } 2365 2375 … … 2397 2407 } 2398 2408 2399 /************************************************************* 2400 * BspNodeGeometry Implementation * 2401 *************************************************************/ 2409 float BspTree::GetEpsilon() const 2410 { 2411 return mEpsilon; 2412 } 2413 2414 void BspViewCellsStatistics::Print(ostream &app) const 2415 { 2416 app << "===== BspViewCells statistics ===============\n"; 2417 2418 app << setprecision(4); 2419 2420 //app << "#N_CTIME ( Construction time [s] )\n" << Time() << " \n"; 2421 2422 app << "#N_OVERALLPVS ( objects in PVS )\n" << pvs << endl; 2423 2424 app << "#N_PMAXPVS ( largest PVS )\n" << maxPvs << endl; 2425 2426 app << "#N_PMINPVS ( smallest PVS )\n" << minPvs << endl; 2427 2428 app << "#N_PAVGPVS ( average PVS )\n" << AvgPvs() << endl; 2429 2430 app << "#N_PEMPTYPVS ( view cells with PVS smaller 2 )\n" << emptyPvs << endl; 2431 2432 app << "#N_VIEWCELLS ( number of view cells)\n" << viewCells << endl; 2433 2434 app << "#N_AVGBSPLEAVES (average number of BSP leaves per view cell )\n" << AvgBspLeaves() << endl; 2435 2436 app << "#N_MAXBSPLEAVES ( maximal number of BSP leaves per view cell )\n" << maxBspLeaves << endl; 2437 2438 app << "===== END OF BspViewCells statistics ==========\n"; 2439 } 2440 2441 /*************************************************************/ 2442 /* BspNodeGeometry Implementation */ 2443 /*************************************************************/ 2402 2444 2403 2445 BspNodeGeometry::~BspNodeGeometry() … … 2413 2455 void BspNodeGeometry::SplitGeometry(BspNodeGeometry &front, 2414 2456 BspNodeGeometry &back, 2415 const BspTree &tree, 2416 const Plane3 &splitPlane) const 2457 const Plane3 &splitPlane, 2458 const AxisAlignedBox3 &box, 2459 const float epsilon) const 2417 2460 { 2418 2461 // get cross section of new polygon 2419 Polygon3 *planePoly = tree.GetBoundingBox().CrossSection(splitPlane); 2420 2421 planePoly = SplitPolygon(planePoly, tree); 2422 2423 //-- plane poly splits all other cell polygons 2462 Polygon3 *planePoly = box.CrossSection(splitPlane); 2463 2464 // split polygon with all other polygons 2465 planePoly = SplitPolygon(planePoly, epsilon); 2466 2467 //-- new polygon splits all other polygons 2424 2468 for (int i = 0; i < (int)mPolys.size(); ++ i) 2425 2469 { 2426 const int cf = mPolys[i]->ClassifyPlane(splitPlane, 0.00001f); 2470 /// don't use epsilon here to get exact split planes 2471 const int cf = 2472 mPolys[i]->ClassifyPlane(splitPlane, Limits::Small); 2427 2473 2428 // split new polygon with all previous planes2429 2474 switch (cf) 2430 2475 { … … 2436 2481 Polygon3 *backPoly = new Polygon3(); 2437 2482 2438 poly->Split(splitPlane, *frontPoly, *backPoly); 2483 poly->Split(splitPlane, 2484 *frontPoly, 2485 *backPoly, 2486 epsilon); 2439 2487 2440 2488 DEL_PTR(poly); 2441 2489 2442 if (frontPoly->Valid( ))2490 if (frontPoly->Valid(epsilon)) 2443 2491 front.mPolys.push_back(frontPoly); 2444 2492 else 2445 2493 DEL_PTR(frontPoly); 2446 2494 2447 if (backPoly->Valid( ))2495 if (backPoly->Valid(epsilon)) 2448 2496 back.mPolys.push_back(backPoly); 2449 2497 else … … 2467 2515 } 2468 2516 2469 //-- finally add the new polygon to the child cells2517 //-- finally add the new polygon to the child node geometries 2470 2518 if (planePoly) 2471 2519 { … … 2481 2529 2482 2530 Polygon3 *BspNodeGeometry::SplitPolygon(Polygon3 *planePoly, 2483 const BspTree &tree) const 2484 { 2531 const float epsilon) const 2532 { 2533 if (!planePoly->Valid(epsilon)) 2534 DEL_PTR(planePoly); 2535 2485 2536 // polygon is split by all other planes 2486 2537 for (int i = 0; (i < (int)mPolys.size()) && planePoly; ++ i) … … 2488 2539 Plane3 plane = mPolys[i]->GetSupportingPlane(); 2489 2540 2541 /// don't use epsilon here to get exact split planes 2490 2542 const int cf = 2491 planePoly->ClassifyPlane(plane, 0.00001f);2543 planePoly->ClassifyPlane(plane, Limits::Small); 2492 2544 2493 2545 // split new polygon with all previous planes … … 2499 2551 Polygon3 *backPoly = new Polygon3(); 2500 2552 2501 planePoly->Split(plane, *frontPoly, *backPoly); 2553 planePoly->Split(plane, 2554 *frontPoly, 2555 *backPoly, 2556 epsilon); 2502 2557 2503 2558 // don't need anymore … … 2506 2561 2507 2562 // back polygon is belonging to geometry 2508 if (backPoly->Valid( ))2563 if (backPoly->Valid(epsilon)) 2509 2564 planePoly = backPoly; 2510 2565 else … … 2525 2580 return planePoly; 2526 2581 } 2527 2528 void BspViewCellsStatistics::Print(ostream &app) const2529 {2530 app << "===== BspViewCells statistics ===============\n";2531 2532 app << setprecision(4);2533 2534 //app << "#N_CTIME ( Construction time [s] )\n" << Time() << " \n";2535 2536 app << "#N_OVERALLPVS ( objects in PVS )\n" << pvs << endl;2537 2538 app << "#N_PMAXPVS ( largest PVS )\n" << maxPvs << endl;2539 2540 app << "#N_PMINPVS ( smallest PVS )\n" << minPvs << endl;2541 2542 app << "#N_PAVGPVS ( average PVS )\n" << AvgPvs() << endl;2543 2544 app << "#N_PEMPTYPVS ( view cells with PVS smaller 2 )\n" << emptyPvs << endl;2545 2546 app << "#N_VIEWCELLS ( number of view cells)\n" << viewCells << endl;2547 2548 app << "#N_AVGBSPLEAVES (average number of BSP leaves per view cell )\n" << AvgBspLeaves() << endl;2549 2550 app << "#N_MAXBSPLEAVES ( maximal number of BSP leaves per view cell )\n" << maxBspLeaves << endl;2551 2552 app << "===== END OF BspViewCells statistics ==========\n";2553 }
Note: See TracChangeset
for help on using the changeset viewer.