Changeset 384 for trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
- Timestamp:
- 11/07/05 01:27:32 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.