Changeset 308 for trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
- Timestamp:
- 10/05/05 02:19:15 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r307 r308 424 424 interior->ProcessPolygons(&coincident, mStoreSplitPolys); 425 425 426 //Debug << "split node on level " << tData.mDepth << " bk: " << backPolys->size() << " frnt: " << frontPolys->size() << endl;427 426 mStat.splits += splits; 428 427 … … 437 436 else // reached leaf => subdivide current viewcell 438 437 { 439 //if (tData.mPolygons->size() > 0) 440 // Debug << "Subdividing further: polygon size: " << (int)tData.mPolygons->size() << ", view cell: " << tData.mViewCell << endl; 441 442 BspNode *root = Subdivide(tStack, tData, viewCells); 443 438 //if (tData.mPolygons->size() > 0) Debug << "Subdividing further: polygon size: " << (int)tData.mPolygons->size() << ", view cell: " << tData.mViewCell << endl; 439 BspNode *root = Subdivide(tStack, tData); 440 441 if (viewCells && root->IsLeaf()) 442 { // generate new view cell for each leaf 443 ViewCell *viewCell = new ViewCell(); 444 viewCells->push_back(viewCell); 445 446 dynamic_cast<BspLeaf *>(root)->SetViewCell(viewCell); 447 } 444 448 if (!mRoot) // tree empty => new root 445 449 mRoot = root; … … 448 452 } 449 453 450 int BspTree::AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys, Intersectable *parent)454 int BspTree::AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys, MeshInstance *parent) 451 455 { 452 456 FaceContainer::const_iterator fi; … … 498 502 mesh = dynamic_cast<MeshInstance *>(object)->GetMesh(); 499 503 break; 500 case Intersectable::VIEW CELL:504 case Intersectable::VIEW_CELL: 501 505 mesh = dynamic_cast<ViewCell *>(object)->GetMesh(); 502 506 break; … … 586 590 587 591 // subdivide leaf node 588 BspNode *root = Subdivide(tStack, tData, viewCells); 592 BspNode *root = Subdivide(tStack, tData); 593 594 if (viewCells && root->IsLeaf()) 595 { // generate new view cell for each leaf 596 ViewCell *viewCell = new ViewCell(); 597 viewCells->push_back(viewCell); 598 599 dynamic_cast<BspLeaf *>(root)->SetViewCell(viewCell); 600 } 589 601 590 602 // empty tree => new root corresponding to unbounded space … … 598 610 599 611 600 BspNode *BspTree::Subdivide(BspTraversalStack &tStack, BspTraversalData &tData, 601 ViewCellContainer *viewCells) 612 BspNode *BspTree::Subdivide(BspTraversalStack &tStack, BspTraversalData &tData) 602 613 { 603 614 //-- terminate traversal … … 605 616 { 606 617 #ifdef _DEBUG 607 Debug << "subdivision terminated at depth " << tData.mDepth << ", #polys: " << (int)tData.mPolygons->size() << endl; 618 Debug << "subdivision terminated at depth " << tData.mDepth << ", #polys: " 619 << (int)tData.mPolygons->size() << endl; 608 620 #endif 609 621 … … 611 623 612 624 BspLeaf *leaf = dynamic_cast<BspLeaf *>(tData.mNode); 613 614 //-- new viewcells are generated and added to each leaf 615 if (viewCells) 616 { 617 ViewCell *viewCell = new ViewCell(); 618 leaf->SetViewCell(viewCell); 619 viewCells->push_back(viewCell); 620 // Debug << "creating new viewcell" << endl; 621 } 622 //-- add viewcell stored in split polygon 623 else if (!leaf->GetViewCell()) 625 626 // add view cell to leaf 627 if (!leaf->GetViewCell()) 624 628 leaf->SetViewCell(tData.mViewCell); 625 //else Debug << "Leaf already has view cell " << endl;626 629 627 630 // remaining polygons are discarded or added to node 628 tData.mNode->ProcessPolygons(tData.mPolygons, mStoreSplitPolys);631 leaf->ProcessPolygons(tData.mPolygons, mStoreSplitPolys); 629 632 DEL_PTR(tData.mPolygons); 630 633 631 return tData.mNode;634 return leaf; 632 635 } 633 636 … … 644 647 &coincident); 645 648 646 //-- extract view cells from coincident polygons according to plane normal647 649 ViewCell *frontViewCell = mViewCell; 648 650 ViewCell *backViewCell = mViewCell; 649 650 if (!viewCells) 651 { // extract the pointer to the view cells 652 ExtractViewCells(&backViewCell, 653 &frontViewCell, 654 coincident, 655 interior->mPlane, 656 frontPolys->empty(), 657 backPolys->empty()); 658 } 651 652 #ifdef _DEBUG 653 if (frontPolys->empty() && backPolys->empty() && (coincident.size() > 2)) 654 { for (PolygonContainer::iterator it = coincident.begin(); it != coincident.end(); ++it) 655 Debug << (*it) << " " << (*it)->GetArea() << " " << (*it)->mParent << endl ; 656 Debug << endl;} 657 #endif 658 659 //-- extract view cells from coincident polygons according to plane normal 660 ExtractViewCells(&backViewCell, &frontViewCell, coincident, interior->mPlane, 661 frontPolys->empty(), backPolys->empty()); 659 662 660 663 // don't need coincident polygons anymore … … 684 687 PolygonContainer::const_iterator it, it_end = coincident.end(); 685 688 689 //-- find first view cells in front and back leafs 686 690 for (it = coincident.begin(); !(foundFront && foundBack) && 687 (it < coincident.end()); ++it)691 (it != it_end); ++ it) 688 692 { 689 693 if (DotProd((*it)->GetSupportingPlane().mNormal, splitPlane.mNormal > 0)) … … 996 1000 if (sSplitPlaneStrategy & BALANCED_VIEW_CELLS) 997 1001 { 998 Intersectable *viewCell = (*it)->mParent;1002 MeshInstance *viewCell = (*it)->mParent; 999 1003 1000 1004 if (classification == Polygon3::FRONT_SIDE) … … 1011 1015 val += sLeastSplitsFactor * sumSplits / (float)polys.size(); 1012 1016 1013 if ( (sSplitPlaneStrategy & LARGEST_POLY_AREA) && sumPolyArea)1017 if (sSplitPlaneStrategy & LARGEST_POLY_AREA) 1014 1018 val += sLargestPolyAreaFactor * (float)polys.size() / sumPolyArea; // HACK 1015 1019 … … 1022 1026 ObjectContainer::const_iterator frontIt, frontIt_end = frontViewCells.end(); 1023 1027 1024 Intersectable * intersect= NULL;1028 Intersectable *vc = NULL; 1025 1029 // increase counter for view cells in front of plane 1026 1030 for (frontIt = frontViewCells.begin(); frontIt != frontIt_end; ++frontIt) 1027 1031 { 1028 if (*frontIt != intersect)1032 if (*frontIt != vc) 1029 1033 { 1030 intersect= *frontIt;1034 vc = *frontIt; 1031 1035 sumBalancedViewCells += 1.0f; 1032 1036 } … … 1034 1038 1035 1039 ObjectContainer::const_iterator backIt, backIt_end = backViewCells.end(); 1036 intersect= NULL;1040 vc = NULL; 1037 1041 // decrease counter for view cells on back side of plane 1038 1042 for (backIt = backViewCells.begin(); backIt != backIt_end; ++backIt) 1039 1043 { 1040 if (*backIt != intersect)1044 if (*backIt != vc) 1041 1045 { 1042 intersect= *backIt;1046 vc = *backIt; 1043 1047 sumBalancedViewCells -= 1.0f; 1044 1048 } … … 1136 1140 } 1137 1141 1138 int BspTree::CollectLeafPvs()1139 {1140 int totalPvsSize = 0;1141 1142 stack<BspNode *> nodeStack;1143 1144 nodeStack.push(mRoot);1145 1146 while (!nodeStack.empty())1147 {1148 BspNode *node = nodeStack.top();1149 1150 nodeStack.pop();1151 1152 if (node->IsLeaf())1153 {1154 BspLeaf *leaf = dynamic_cast<BspLeaf *>(node);1155 1156 ViewCell *viewcell = leaf->GetViewCell();1157 1158 if (!viewcell->Mailed())1159 {1160 viewcell->Mail(); // what does mail mean?1161 1162 // add this node to pvs of all nodes it can see1163 BspPvsMap::iterator ni;1164 1165 /* for (ni = object->mBspPvs.mEntries.begin(); ni != object->mKdPvs.mEntries.end(); ni++)1166 {1167 BspNode *node = (*ni).first;1168 1169 // $$ JB TEMPORARY solution -> should add object PVS or explictly computed1170 // BSP tree PVS1171 if (leaf->mBspPvs.AddNodeSample(node))1172 totalPvsSize++;1173 }*/1174 }1175 } else1176 {1177 // traverse tree1178 BspInterior *interior = (BspInterior *)node;1179 1180 nodeStack.push(interior->GetFront());1181 nodeStack.push(interior->GetBack());1182 }1183 }1184 1185 return totalPvsSize;1186 }1187 1188 1142 AxisAlignedBox3 BspTree::GetBoundingBox() const 1189 1143 { … … 1303 1257 extp = splitPlane->FindIntersection(ray.GetLoc(), extp, &maxt); 1304 1258 1305 } else // compute intersections with objects in leaf1259 } else // reached leaf => intersection with view cell 1306 1260 { 1307 1261 BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 1308 //ray.leaves.push_back(leaf);1309 // TODO 1310 /*ObjectContainer::const_iterator mi; 1311 for (mi = leaf->mObjects.begin(); mi != leaf->mObjects.end(); ++mi)1262 1263 //ray.mBspLeaves.push_back(leaf); 1264 1265 if (!leaf->mViewCell->Mailed()) 1312 1266 { 1313 Intersectable *object = *mi; 1314 if (!object->Mailed()) 1315 { 1316 object->Mail(); 1317 //ray.meshes.push_back(mesh); 1318 hits += object->CastRay(ray); 1319 } 1320 }*/ 1321 1322 if (hits && ray.GetType() == Ray::LOCAL_RAY) 1267 ray.viewCells.push_back(leaf->mViewCell); 1268 mViewCell->Mail(); 1269 ++ hits; 1270 } 1271 1272 if (hits && ray.GetType() == Ray::LOCAL_RAY) 1323 1273 if (ray.intersections[0].mT <= maxt) 1324 1274 break; … … 1355 1305 return false; 1356 1306 } 1307 1308 void BspTree::CollectViewCells(BspNode *n, ViewCellContainer &viewCells) 1309 { 1310 stack<BspNode *> nodeStack; 1311 1312 nodeStack.push(n); 1313 1314 while (!nodeStack.empty()) 1315 { 1316 BspNode *node = nodeStack.top(); 1317 nodeStack.pop(); 1318 1319 if (node->IsLeaf()) 1320 { 1321 ViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->mViewCell; 1322 1323 if (!viewCell->Mailed()) 1324 { 1325 viewCell->Mail(); 1326 viewCells.push_back(viewCell); 1327 } 1328 } 1329 else 1330 { 1331 BspInterior *interior = dynamic_cast<BspInterior *>(node); 1332 nodeStack.push(interior->mFront); 1333 nodeStack.push(interior->mBack); 1334 } 1335 } 1336 } 1357 1337 //} // GtpVisibilityPreprocessor
Note: See TracChangeset
for help on using the changeset viewer.