- Timestamp:
- 11/07/05 01:27:32 (19 years ago)
- Location:
- trunk/VUT
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r383 r384 126 126 #splitPlaneStrategy 130 127 127 128 splitPlaneStrategy 10 24128 splitPlaneStrategy 1032 129 129 130 130 maxPolyCandidates 50 … … 133 133 Termination { 134 134 # autopartition 135 maxRays 1000136 maxPolygons 1135 maxRays 300 136 maxPolygons 0 137 137 maxDepth 80 138 138 -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp
r375 r384 432 432 return count; 433 433 } 434 435 float Polygon3::GetArea(const PolygonContainer &cell) 436 { 437 float area = 0; 438 PolygonContainer::const_iterator pit; 439 440 for (pit = cell.begin(); pit != cell.end(); ++ pit) 441 area += (*pit)->GetArea(); 442 443 return area; 444 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h
r375 r384 87 87 Vector3 GetNormal() const; 88 88 89 /** Includes polygons to axis aligned box.90 */91 static void IncludeInBox(const PolygonContainer &polys, AxisAlignedBox3 &box);92 93 89 /** Casts ray to polygon. 94 90 */ 95 91 int CastRay(const Ray &ray, float &t, const float nearestT); 96 92 97 /** Classify polygons with respect to the plane. 98 @returns one of BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT 93 94 /** The piercing rays of the polygon are inherited by the child fragments 95 @parm front_piece the front fragment inheriting the front rays 96 @param back_piece the back fragment inheriting the back rays 99 97 */ 100 static int ClassifyPlane(const PolygonContainer &polys, const Plane3 &plane); 98 void InheritRays(Polygon3 &front_piece, 99 Polygon3 &back_piece) const; 100 101 101 102 102 /// vertices are connected in counterclockwise order. … … 112 112 RayContainer mPiercingRays; 113 113 114 /** The piercing rays of the polygon are inherited by the child fragments 115 @parm front_piece the front fragment inheriting the front rays 116 @param back_piece the back fragment inheriting the back rays114 115 116 /** Includes polygons to axis aligned box. 117 117 */ 118 void InheritRays(Polygon3 &front_piece, 119 Polygon3 &back_piece) const; 118 static void IncludeInBox(const PolygonContainer &polys, AxisAlignedBox3 &box); 119 120 /** Classify polygons with respect to the plane. 121 @returns one of BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT 122 */ 123 static int ClassifyPlane(const PolygonContainer &polys, const Plane3 &plane); 120 124 121 125 … … 123 127 */ 124 128 static int ParentObjectsSize(const PolygonContainer &polys); 129 130 static float GetArea(const PolygonContainer &cell); 125 131 }; 126 132 -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r383 r384 945 945 const float objRt = 1.0f; 946 946 // const overhead for crossing a view cell border 947 const float vcOverhead = 0 .01f;947 const float vcOverhead = 0;//0.01f; 948 948 949 949 // total area of view cells … … 955 955 956 956 ViewCellContainer::const_iterator it, it_end = viewCells.end(); 957 PolygonContainer::const_iterator pit; 958 957 959 958 for (it = viewCells.begin(); it != it_end; ++ it) 960 959 { … … 965 964 mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), cell); 966 965 967 for (pit = cell.begin(); pit != cell.end(); ++ pit) 968 area += (*pit)->GetArea(); 969 970 renderTime += area * RenderPvs(*(*it), objRt); 966 area = Polygon3::GetArea(cell); 967 968 renderTime += area * RenderPvs(*(*it), objRt) + vcOverhead; 971 969 totalArea += area; 972 970 } … … 974 972 renderTime /= totalArea; 975 973 976 Debug << "render time without overhead: " << renderTime * 1e-3 << endl; 977 978 renderTime += (float)viewCells.size() * vcOverhead; 974 //Debug << "render time without overhead: " << renderTime * 1e-3 << endl; 975 //renderTime += (float)viewCells.size() * vcOverhead; 979 976 980 977 return renderTime; -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp
r372 r384 65 65 ViewCell *ViewCell::ExtrudeViewCell(const Triangle3 &baseTri, const float height) 66 66 { 67 int i; 68 // one mesh per view cell 67 // one mesh per view cell 69 68 Mesh *mesh = new Mesh(); 70 69 … … 86 85 87 86 // add base vertices and calculate top vertices 88 for (i = 0; i < 3; ++ i)89 87 for (int i = 0; i < 3; ++ i) 88 mesh->mVertices.push_back(baseTri.mVertices[i]); 90 89 91 90 // add top vertices 92 for (i = 0; i < 3; ++ i)91 for (int i = 0; i < 3; ++ i) 93 92 mesh->mVertices.push_back(baseTri.mVertices[i] + height * triNorm); 94 93 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r383 r384 1088 1088 1089 1089 // use heuristics to find appropriate plane 1090 return SelectPlaneHeuristics(leaf, 1091 polys, 1092 rays, 1093 sMaxPolyCandidates, 1090 return SelectPlaneHeuristics(leaf, polys, rays, sMaxPolyCandidates, 1094 1091 sMaxRayCandidates); 1095 1092 } … … 1109 1106 int candidateIdx = limit; 1110 1107 1108 // only for pvs criterium 1109 PolygonContainer cell; 1110 vector<Plane3 *> planes; 1111 vector<bool> sides; 1112 float pvsSize = 0; 1113 1114 if (sSplitPlaneStrategy & PVS) 1115 { 1116 ConstructGeometry(leaf, cell); 1117 ExtractSplitPlanes(leaf, planes, sides); 1118 pvsSize = ComputePvsSize(rays); 1119 } 1120 1111 1121 for (int i = 0; i < limit; ++ i) 1112 1122 { … … 1115 1125 // evaluate current candidate 1116 1126 const float candidateCost = 1117 SplitPlaneCost(leaf, 1118 polys[candidateIdx]->GetSupportingPlane(), 1119 polys, rays); 1127 SplitPlaneCost(polys[candidateIdx]->GetSupportingPlane(), 1128 polys, rays, cell, planes, sides, pvsSize); 1120 1129 1121 1130 //Debug << polys[candidateIdx] << endl; … … 1151 1160 1152 1161 const float candidateCost = 1153 SplitPlaneCost( leaf,Plane3(pt[0], pt[1], pt[2]),1154 polys, rays );1162 SplitPlaneCost(Plane3(pt[0], pt[1], pt[2]), 1163 polys, rays, cell, planes, sides, pvsSize); 1155 1164 1156 1165 if (candidateCost < lowestCost) … … 1163 1172 } 1164 1173 1174 CLEAR_CONTAINER(cell); 1175 1165 1176 if (chooseFromRays) 1166 1177 { … … 1186 1197 } 1187 1198 1188 float BspTree::SplitPlaneCost(BspLeaf *leaf, 1189 const Plane3 &candidatePlane, 1199 float BspTree::SplitPlaneCost(const Plane3 &candidatePlane, 1190 1200 const PolygonContainer &polys) const 1191 1201 { … … 1283 1293 if (sSplitPlaneStrategy & BALANCED_POLYS) 1284 1294 val += sBalancedPolysFactor * fabs(sumBalancedPolys) / (float)polys.size(); 1285 1295 1286 1296 if (sSplitPlaneStrategy & LEAST_SPLITS) 1287 1297 val += sLeastSplitsFactor * sumSplits / (float)polys.size(); … … 1297 1307 if (sSplitPlaneStrategy & BALANCED_VIEW_CELLS) 1298 1308 if (totalViewCells != 0) 1299 val += sBalancedViewCellsFactor * fabs(sumBalancedViewCells) / 1300 (float)totalViewCells; 1309 val += sBalancedViewCellsFactor * fabs(sumBalancedViewCells) / (float)totalViewCells; 1301 1310 1302 1311 return val; … … 1326 1335 } 1327 1336 1328 float BspTree::SplitPlaneCost(BspLeaf *leaf, 1329 const Plane3 &candidatePlane, 1330 const BoundedRayContainer &rays) const 1337 float BspTree::SplitPlaneCost(const Plane3 &candidatePlane, 1338 const BoundedRayContainer &rays, 1339 const float frontArea, 1340 const float backArea, 1341 const int pvsSize) const 1331 1342 { 1332 1343 float val = 0; … … 1344 1355 Intersectable::NewMail(); const int frontAndBackId = ViewCell::sMailId; 1345 1356 1346 PolygonContainer cell;1347 PolygonContainer front;1348 PolygonContainer back;1349 1350 vector<Plane3 *> planes;1351 vector<bool> sides;1352 1353 ExtractSplitPlanes(leaf, planes, sides);1354 1355 ConstructGeometry(leaf, cell);1356 ConstructChildGeometry(front, cell, planes, sides, candidatePlane, true);1357 ConstructChildGeometry(back, cell, planes, sides, candidatePlane, false);1358 1359 CLEAR_CONTAINER(cell);1360 CLEAR_CONTAINER(front);1361 CLEAR_CONTAINER(back);1362 1363 1357 int frontRays = 0; 1364 1358 int backRays = 0; 1365 1366 // todo create geometry of left and right leaves 1367 1359 1368 1360 BoundedRayContainer::const_iterator rit, rit_end = rays.end(); 1369 1361 … … 1394 1386 // assure that we only count a object 1395 1387 // once for the front and once for the back side of the plane 1396 ComputePvs(*ray->intersections[0].mObject, 1397 frontPvs, 1398 backPvs, 1399 cf, 1400 frontId, 1401 backId, 1402 frontAndBackId); 1388 AddToPvs(*ray->intersections[0].mObject, 1389 frontPvs, backPvs, 1390 cf, frontId, backId, frontAndBackId); 1403 1391 } 1404 1392 1405 1393 // the source object in the origin of the ray 1406 ComputePvs(*ray->sourceObject.mObject, 1407 frontPvs, 1408 backPvs, 1409 cf, 1410 frontId, 1411 backId, 1412 frontAndBackId); 1413 1414 if ((cf == Ray::BACK) || (cf == Ray::FRONT_BACK) || (cf == Ray::BACK_FRONT)) 1415 ++ backRays; 1416 if ((cf == Ray::FRONT) || (cf == Ray::FRONT_BACK) || (cf == Ray::BACK_FRONT)) 1417 ++ frontRays; 1394 AddToPvs(*ray->sourceObject.mObject, 1395 frontPvs, backPvs, 1396 cf, frontId, backId, frontAndBackId); 1397 1398 if (0) 1399 { 1400 if ((cf == Ray::BACK) || (cf == Ray::FRONT_BACK) || (cf == Ray::BACK_FRONT)) 1401 ++ backRays; 1402 if ((cf == Ray::FRONT) || (cf == Ray::FRONT_BACK) || (cf == Ray::BACK_FRONT)) 1403 ++ frontRays; 1404 } 1418 1405 } 1419 1406 } … … 1428 1415 1429 1416 if (sSplitPlaneStrategy & PVS) 1430 if (!rays.empty()) // HACK (should divide by maximal possible pvs) 1431 val += sPvsFactor * (frontPvs * (float)frontRays + (backPvs * (float)backRays)) / 1432 (float)rays.size(); 1417 if (0 && !rays.empty()) // HACK (should divide by maximal possible pvs) 1418 val += sPvsFactor * (frontPvs * (float)frontRays + (backPvs * (float)backRays)) / (float)rays.size(); 1419 else 1420 val += sPvsFactor * (frontPvs * frontArea + (backPvs * backArea)) / 1421 ((frontArea + backArea) * (float)pvsSize); 1433 1422 1434 1423 //Debug << "pvs: " << pvsSize << " val " << val << endl; … … 1436 1425 } 1437 1426 1438 1439 /*void BspTree::CreateChildrenGeometry(PolygonContainer &cell, 1440 PolygonContainer &front, 1441 PolygonContainer &back, 1442 Plane3 &splitPlane) 1443 { 1444 }*/ 1445 1446 void BspTree::ComputePvs(Intersectable &obj, 1447 float &frontPvs, 1448 float &backPvs, 1449 const int cf, 1450 const int frontId, 1451 const int backId, 1452 const int frontAndBackId) const 1453 { 1454 if (cf == Ray::COINCIDENT) 1427 void BspTree::AddToPvs(Intersectable &obj, 1428 float &frontPvs, 1429 float &backPvs, 1430 const int cf, 1431 const int frontId, 1432 const int backId, 1433 const int frontAndBackId) const 1434 { 1435 if (cf == Ray::COINCIDENT) //TODO: really belongs to no pvs? 1455 1436 return; 1456 1437 … … 1459 1440 if ((obj.mMailbox != frontId) && 1460 1441 (obj.mMailbox != frontAndBackId)) 1442 { 1461 1443 frontPvs += 1.0; 1462 1444 1463 if (obj.mMailbox != backId) 1464 obj.mMailbox = frontId; 1465 else 1466 obj.mMailbox = frontAndBackId; 1445 if (obj.mMailbox != backId) 1446 obj.mMailbox = frontId; 1447 else 1448 obj.mMailbox = frontAndBackId; 1449 } 1467 1450 } 1468 1451 else if (cf == Ray::BACK) … … 1479 1462 } 1480 1463 } 1464 // object belongs to both pvs 1481 1465 else if ((cf == Ray::FRONT_BACK) || (cf == Ray::BACK_FRONT)) 1482 1466 { 1483 if (obj.mMailbox == backId) 1484 frontPvs += 1.0; 1485 else if (obj.mMailbox == frontId) 1486 backPvs += 1.0; 1487 else if (obj.mMailbox != frontAndBackId) // can add to both PVS 1488 { 1489 frontPvs += 1.0; 1490 backPvs += 1.0; 1491 } 1492 obj.mMailbox = frontAndBackId; 1493 } 1494 } 1495 1496 float BspTree::SplitPlaneCost(BspLeaf *leaf, 1497 const Plane3 &candidatePlane, 1467 if (obj.mMailbox != frontAndBackId) 1468 { 1469 if (obj.mMailbox != frontId) 1470 frontPvs += 1.0; 1471 if (obj.mMailbox != backId) 1472 backPvs += 1.0; 1473 1474 obj.mMailbox = frontAndBackId; 1475 } 1476 } 1477 } 1478 1479 float BspTree::SplitPlaneCost(const Plane3 &candidatePlane, 1498 1480 const PolygonContainer &polys, 1499 const BoundedRayContainer &rays) const 1481 const BoundedRayContainer &rays, 1482 const PolygonContainer &cell, 1483 const vector<Plane3 *> &planes, 1484 const vector<bool> &sides, 1485 const int pvsSize) const 1500 1486 { 1501 1487 float val = 0; … … 1517 1503 (sSplitPlaneStrategy & BLOCKED_RAYS)) 1518 1504 { 1519 val += SplitPlaneCost( leaf,candidatePlane, polys);1505 val += SplitPlaneCost(candidatePlane, polys); 1520 1506 } 1521 1507 … … 1525 1511 (sSplitPlaneStrategy & PVS)) 1526 1512 { 1527 val += SplitPlaneCost(leaf, candidatePlane, rays); 1513 float frontArea = 0; 1514 float backArea = 0; 1515 1516 if (sSplitPlaneStrategy & PVS) 1517 { 1518 PolygonContainer frontCell; 1519 PolygonContainer backCell; 1520 1521 // construct child geometry with regard to the candidate split plane 1522 ConstructChildGeometry(frontCell, cell, planes, sides, candidatePlane, true); 1523 ConstructChildGeometry(backCell, cell, planes, sides, candidatePlane, false); 1524 1525 frontArea = Polygon3::GetArea(frontCell); 1526 backArea = Polygon3::GetArea(backCell); 1527 1528 CLEAR_CONTAINER(frontCell); 1529 CLEAR_CONTAINER(backCell); 1530 } 1531 1532 val += SplitPlaneCost(candidatePlane, rays, frontArea, backArea, pvsSize); 1528 1533 } 1529 1534 … … 2039 2044 } 2040 2045 2041 bool BspTree::ConstructChildGeometry(PolygonContainer & newCell,2046 bool BspTree::ConstructChildGeometry(PolygonContainer &childCell, 2042 2047 const PolygonContainer &cell, 2043 2048 const vector<Plane3 *> &planes, … … 2049 2054 Polygon3 *planePoly = GetBoundingBox().CrossSection(splitPlane); 2050 2055 2051 bool inside = true;2052 2053 2056 // polygon is split by all other planes 2054 for (int i = 0; (i < planes.size()) && inside; ++ i)2057 for (int i = 0; (i < (int)planes.size()) && planePoly; ++ i) 2055 2058 { 2056 2059 const int cf = planePoly->ClassifyPlane(*planes[i]); … … 2080 2083 } 2081 2084 2082 inside = true; 2085 if (!planePoly->Valid()) 2086 DEL_PTR(planePoly); 2083 2087 } 2084 2088 break; 2085 2089 case Polygon3::BACK_SIDE: 2086 2090 if (sides[i]) 2087 inside = false;2091 DEL_PTR(planePoly); 2088 2092 break; 2089 2093 case Polygon3::FRONT_SIDE: 2090 2094 if (!sides[i]) 2091 inside = false; 2095 DEL_PTR(planePoly); 2096 break; 2097 case Polygon3::COINCIDENT: 2092 2098 break; 2093 2099 default: … … 2096 2102 } 2097 2103 2098 //-- finally add polygon 2099 if (inside) 2100 newCell.push_back(planePoly); 2101 else 2102 { 2103 //just copy polygons 2104 DEL_PTR(planePoly); 2104 if (!planePoly) 2105 { 2106 //geometry is not changed at all, hence just copy polygons 2105 2107 PolygonContainer::const_iterator it, it_end = cell.end(); 2106 2108 2107 2109 for (it = cell.begin(); it != it_end; ++ it) 2108 newCell.push_back(*it);2110 childCell.push_back(new Polygon3((*it)->mVertices)); 2109 2111 2110 2112 return false; 2111 2113 } 2112 2114 2113 //-- plane poly splits all other c andidates2115 //-- plane poly splits all other cell polygons 2114 2116 for (int i = 0; i < (int)cell.size(); ++ i) 2115 2117 { 2116 inside = true;2117 2118 2118 const int cf = cell[i]->ClassifyPlane(splitPlane); 2119 2119 … … 2123 2123 case Polygon3::SPLIT: 2124 2124 { 2125 Polygon3 *poly = new Polygon3( *cell[i]);2125 Polygon3 *poly = new Polygon3(cell[i]->mVertices); 2126 2126 2127 2127 Polygon3 *frontPoly = new Polygon3(); … … 2133 2133 DEL_PTR(poly); 2134 2134 2135 if (side s[i]== true)2135 if (side == true) 2136 2136 { 2137 newCell.push_back(frontPoly);2137 poly = frontPoly; 2138 2138 DEL_PTR(backPoly); 2139 2139 } 2140 2140 else 2141 2141 { 2142 newCell.push_back(backPoly);2142 poly = backPoly; 2143 2143 DEL_PTR(frontPoly); 2144 2144 } 2145 if (!poly->Valid()) 2146 DEL_PTR(poly); 2147 else 2148 childCell.push_back(poly); 2145 2149 } 2150 2146 2151 break; 2147 2152 case Polygon3::BACK_SIDE: 2148 if (!sides[i]) 2149 newCell.push_back(new Polygon3(*cell[i])); 2150 2153 if (!side) 2154 childCell.push_back(new Polygon3(cell[i]->mVertices)); 2151 2155 break; 2152 2156 case Polygon3::FRONT_SIDE: 2153 if (sides[i]) 2154 newCell.push_back(new Polygon3(*cell[i])); 2155 inside = false; 2157 if (side) 2158 childCell.push_back(new Polygon3(cell[i]->mVertices)); 2159 break; 2160 case Polygon3::COINCIDENT: 2161 childCell.push_back(new Polygon3(cell[i]->mVertices)); 2156 2162 break; 2157 2163 default: 2164 2158 2165 break; 2159 2166 } 2160 2167 } 2161 2168 2169 //-- finally add the new polygon 2170 childCell.push_back(planePoly); 2171 2162 2172 return true; 2163 2173 } … … 2229 2239 DEL_PTR(frontPoly); 2230 2240 } 2231 inside = true;2241 2232 2242 break; 2233 2243 … … 2239 2249 if (!sides[j]) 2240 2250 inside = false; 2251 break; 2252 case Polygon3::COINCIDENT: 2241 2253 break; 2242 2254 default: … … 2418 2430 return NULL; 2419 2431 } 2432 2433 int BspTree::ComputePvsSize(const BoundedRayContainer &rays) const 2434 { 2435 int pvsSize = 0; 2436 2437 BoundedRayContainer::const_iterator rit, rit_end = rays.end(); 2438 2439 Intersectable::NewMail(); 2440 2441 for (rit = rays.begin(); rit != rays.end(); ++ rit) 2442 { 2443 Ray *ray = (*rit)->mRay; 2444 2445 if (!ray->intersections.empty()) 2446 { 2447 if (!ray->intersections[0].mObject->Mailed()) 2448 { 2449 ray->intersections[0].mObject->Mail(); 2450 ++ pvsSize; 2451 } 2452 } 2453 if (!ray->sourceObject.mObject->Mailed()) 2454 { 2455 ray->sourceObject.mObject->Mail(); 2456 ++ pvsSize; 2457 } 2458 } 2459 2460 return pvsSize; 2461 } -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r383 r384 459 459 @returns true if plane contributes to the cell. 460 460 */ 461 bool ConstructChildGeometry(PolygonContainer & newCell,461 bool ConstructChildGeometry(PolygonContainer &childCell, 462 462 const PolygonContainer &cell, 463 463 const vector<Plane3 *> &planes, … … 535 535 /** Evaluates the contribution of the candidate split plane. 536 536 537 @param candi tatePlane the candidate split plane537 @param candidatePlane the candidate split plane 538 538 @param polys the polygons the split can be based on 539 539 @param rays the rays the split can be based on 540 540 541 @returns the cost of the candidate split plane 541 542 */ 542 float SplitPlaneCost(BspLeaf *leaf, 543 const Plane3 &candidatePlane, 543 float SplitPlaneCost(const Plane3 &candidatePlane, 544 544 const PolygonContainer &polys, 545 const BoundedRayContainer &rays) const; 545 const BoundedRayContainer &rays, 546 const PolygonContainer &cell, 547 const vector<Plane3 *> &plane, 548 const vector<bool> &sides, 549 const int pvsSize) const; 546 550 547 551 /** Strategies where the effect of the split plane is tested … … 549 553 @returns the cost of the candidate split plane 550 554 */ 551 float SplitPlaneCost(BspLeaf *leaf, 552 const Plane3 &candidatePlane, 555 float SplitPlaneCost(const Plane3 &candidatePlane, 553 556 const PolygonContainer &polys) const; 554 557 555 558 /** Strategies where the effect of the split plane is tested 556 559 on all input polygons. 560 557 561 @returns the cost of the candidate split plane 558 562 */ 559 float SplitPlaneCost(BspLeaf *leaf, 560 const Plane3 &candidatePlane, 561 const BoundedRayContainer &polys) const; 563 float SplitPlaneCost(const Plane3 &candidatePlane, 564 const BoundedRayContainer &rays, 565 const float frontArea, 566 const float backArea, 567 const int pvsSize) const; 562 568 563 569 /** Filters next view cell down the tree and inserts it into the appropriate leaves … … 721 727 /** Computes the pvs of the front and back leaf with a given classification. 722 728 */ 723 void ComputePvs(Intersectable &obj,729 void AddToPvs(Intersectable &obj, 724 730 float &frontPvs, 725 731 float &backPvs, … … 729 735 const int frontAndBackId) const; 730 736 737 int ComputePvsSize(const BoundedRayContainer &rays) const; 738 731 739 /// Pointer to the root of the tree 732 740 BspNode *mRoot;
Note: See TracChangeset
for help on using the changeset viewer.