Changeset 1545 for GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
- Timestamp:
- 09/29/06 22:42:25 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
r1449 r1545 265 265 266 266 int polysSize = 0; 267 267 268 268 for (int i = 0; i < limit; ++ i) 269 269 { 270 if (viewCells[i]->GetMesh()) // copy the mesh data to polygons271 {272 mBox.Include(viewCells[i]->GetBox()); //add to BSP tree aabb273 polysSize +=274 AddMeshToPolygons(viewCells[i]->GetMesh(),275 polys,276 viewCells[i]);277 } 278 } 279 270 Mesh *mesh = viewCells[i]->GetMesh(); 271 if (mesh) 272 { // // copy the mesh into polygons and add to BSP tree aabb 273 mBox.Include(viewCells[i]->GetBox()); 274 polysSize += AddMeshToPolygons(mesh, 275 polys, 276 viewCells[i]); 277 } 278 } 279 280 280 return polysSize; 281 281 } … … 2588 2588 { 2589 2589 ViewCell::NewMail(); 2590 2591 2590 CollectViewCells(mRoot, onlyValid, viewCells, true); 2592 2591 } 2593 2594 2595 void VspBspTree::CollapseViewCells()2596 {2597 // TODO2598 #if HAS_TO_BE_REDONE2599 stack<BspNode *> nodeStack;2600 2601 if (!mRoot)2602 return;2603 2604 nodeStack.push(mRoot);2605 2606 while (!nodeStack.empty())2607 {2608 BspNode *node = nodeStack.top();2609 nodeStack.pop();2610 2611 if (node->IsLeaf())2612 {2613 BspViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell();2614 2615 if (!viewCell->GetValid())2616 {2617 BspViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell();2618 2619 ViewCellContainer leaves;2620 mViewCellsTree->CollectLeaves(viewCell, leaves);2621 2622 ViewCellContainer::const_iterator it, it_end = leaves.end();2623 2624 for (it = leaves.begin(); it != it_end; ++ it)2625 {2626 BspLeaf *l = dynamic_cast<BspViewCell *>(*it)->mLeaf;2627 l->SetViewCell(GetOrCreateOutOfBoundsCell());2628 ++ mBspStats.invalidLeaves;2629 }2630 2631 // add to unbounded view cell2632 GetOrCreateOutOfBoundsCell()->GetPvs().AddPvs(viewCell->GetPvs());2633 DEL_PTR(viewCell);2634 }2635 }2636 else2637 {2638 BspInterior *interior = dynamic_cast<BspInterior *>(node);2639 2640 nodeStack.push(interior->GetFront());2641 nodeStack.push(interior->GetBack());2642 }2643 }2644 2645 Debug << "invalid leaves: " << mBspStats.invalidLeaves << endl;2646 #endif2647 }2648 2649 2650 void VspBspTree::CollectRays(VssRayContainer &rays)2651 {2652 vector<BspLeaf *> leaves;2653 2654 vector<BspLeaf *>::const_iterator lit, lit_end = leaves.end();2655 2656 for (lit = leaves.begin(); lit != lit_end; ++ lit)2657 {2658 BspLeaf *leaf = *lit;2659 VssRayContainer::const_iterator rit, rit_end = leaf->mVssRays.end();2660 2661 for (rit = leaf->mVssRays.begin(); rit != rit_end; ++ rit)2662 rays.push_back(*rit);2663 }2664 }2665 2666 2667 void VspBspTree::ValidateTree()2668 {2669 stack<BspNode *> nodeStack;2670 2671 if (!mRoot)2672 return;2673 2674 nodeStack.push(mRoot);2675 2676 mBspStats.invalidLeaves = 0;2677 while (!nodeStack.empty())2678 {2679 BspNode *node = nodeStack.top();2680 nodeStack.pop();2681 2682 if (node->IsLeaf())2683 {2684 BspLeaf *leaf = dynamic_cast<BspLeaf *>(node);2685 2686 if (!leaf->GetViewCell()->GetValid())2687 ++ mBspStats.invalidLeaves;2688 2689 // validity flags don't match => repair2690 if (leaf->GetViewCell()->GetValid() != leaf->TreeValid())2691 {2692 leaf->SetTreeValid(leaf->GetViewCell()->GetValid());2693 PropagateUpValidity(leaf);2694 }2695 }2696 else2697 {2698 BspInterior *interior = dynamic_cast<BspInterior *>(node);2699 2700 nodeStack.push(interior->GetFront());2701 nodeStack.push(interior->GetBack());2702 }2703 }2704 2705 Debug << "invalid leaves: " << mBspStats.invalidLeaves << endl;2706 }2707 2708 2592 2709 2593 … … 2748 2632 } 2749 2633 } 2750 2634 } 2635 2636 2637 void VspBspTree::CollapseViewCells() 2638 { 2639 // TODO 2640 #if HAS_TO_BE_REDONE 2641 stack<BspNode *> nodeStack; 2642 2643 if (!mRoot) 2644 return; 2645 2646 nodeStack.push(mRoot); 2647 2648 while (!nodeStack.empty()) 2649 { 2650 BspNode *node = nodeStack.top(); 2651 nodeStack.pop(); 2652 2653 if (node->IsLeaf()) 2654 { 2655 BspViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 2656 2657 if (!viewCell->GetValid()) 2658 { 2659 BspViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 2660 2661 ViewCellContainer leaves; 2662 mViewCellsTree->CollectLeaves(viewCell, leaves); 2663 2664 ViewCellContainer::const_iterator it, it_end = leaves.end(); 2665 2666 for (it = leaves.begin(); it != it_end; ++ it) 2667 { 2668 BspLeaf *l = dynamic_cast<BspViewCell *>(*it)->mLeaf; 2669 l->SetViewCell(GetOrCreateOutOfBoundsCell()); 2670 ++ mBspStats.invalidLeaves; 2671 } 2672 2673 // add to unbounded view cell 2674 GetOrCreateOutOfBoundsCell()->GetPvs().AddPvs(viewCell->GetPvs()); 2675 DEL_PTR(viewCell); 2676 } 2677 } 2678 else 2679 { 2680 BspInterior *interior = dynamic_cast<BspInterior *>(node); 2681 2682 nodeStack.push(interior->GetFront()); 2683 nodeStack.push(interior->GetBack()); 2684 } 2685 } 2686 2687 Debug << "invalid leaves: " << mBspStats.invalidLeaves << endl; 2688 #endif 2689 } 2690 2691 2692 void VspBspTree::CollectRays(VssRayContainer &rays) 2693 { 2694 vector<BspLeaf *> leaves; 2695 2696 vector<BspLeaf *>::const_iterator lit, lit_end = leaves.end(); 2697 2698 for (lit = leaves.begin(); lit != lit_end; ++ lit) 2699 { 2700 BspLeaf *leaf = *lit; 2701 VssRayContainer::const_iterator rit, rit_end = leaf->mVssRays.end(); 2702 2703 for (rit = leaf->mVssRays.begin(); rit != rit_end; ++ rit) 2704 rays.push_back(*rit); 2705 } 2706 } 2707 2708 2709 void VspBspTree::ValidateTree() 2710 { 2711 stack<BspNode *> nodeStack; 2712 2713 if (!mRoot) 2714 return; 2715 2716 nodeStack.push(mRoot); 2717 2718 mBspStats.invalidLeaves = 0; 2719 while (!nodeStack.empty()) 2720 { 2721 BspNode *node = nodeStack.top(); 2722 nodeStack.pop(); 2723 2724 if (node->IsLeaf()) 2725 { 2726 BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 2727 2728 if (!leaf->GetViewCell()->GetValid()) 2729 ++ mBspStats.invalidLeaves; 2730 2731 // validity flags don't match => repair 2732 if (leaf->GetViewCell()->GetValid() != leaf->TreeValid()) 2733 { 2734 leaf->SetTreeValid(leaf->GetViewCell()->GetValid()); 2735 PropagateUpValidity(leaf); 2736 } 2737 } 2738 else 2739 { 2740 BspInterior *interior = dynamic_cast<BspInterior *>(node); 2741 2742 nodeStack.push(interior->GetFront()); 2743 nodeStack.push(interior->GetBack()); 2744 } 2745 } 2746 2747 Debug << "invalid leaves: " << mBspStats.invalidLeaves << endl; 2751 2748 } 2752 2749
Note: See TracChangeset
for help on using the changeset viewer.