Changeset 704 for GTP/trunk/Lib/Vis/Preprocessing
- Timestamp:
- 03/16/06 15:04:03 (19 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp
r697 r704 1790 1790 float &maxT) const 1791 1791 { 1792 maxT = 1e15 ;1792 maxT = 1e15f; 1793 1793 minT = 0; 1794 1794 -
GTP/trunk/Lib/Vis/Preprocessing/src/Beam.cpp
r542 r704 119 119 left = -right; 120 120 121 top = yDirRange * 0.5 ;121 top = yDirRange * 0.5f; 122 122 bottom = -top; 123 123 } … … 165 165 166 166 // box should not never remove part of beam polygons 167 Vector3 bmin = mBox.Min() - Vector3(zfar * 2.0 );168 Vector3 bmax = mBox.Max() + Vector3(zfar * 2.0 );167 Vector3 bmin = mBox.Min() - Vector3(zfar * 2.0f); 168 Vector3 bmax = mBox.Max() + Vector3(zfar * 2.0f); 169 169 170 170 AxisAlignedBox3 bbox(bmin, bmax); -
GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h
r695 r704 109 109 110 110 /** Compute continuous PVS difference */ 111 void ComputeContinuousPvsDifference( constPvs<T> &pvs,111 void ComputeContinuousPvsDifference(Pvs<T> &pvs, 112 112 float &pvsReduction, 113 113 float &pvsEnlargement); … … 115 115 116 116 /** Compute continuous PVS difference */ 117 float GetPvsHomogenity( constPvs<T> &pvs) {117 float GetPvsHomogenity(Pvs<T> &pvs) { 118 118 float 119 119 pvsReduction, … … 142 142 template <typename T> 143 143 void 144 Pvs<T>::ComputeContinuousPvsDifference( constPvs<T> &b,144 Pvs<T>::ComputeContinuousPvsDifference(Pvs<T> &b, 145 145 float &pvsReduction, 146 146 float &pvsEnlargement) 147 147 { 148 148 // Uses sum of log differences, which corresponds to entropy 149 std::map<T, PvsData<T>, LtSample<T> >::const_iterator it; 150 151 for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it) { 149 std::map<T, PvsData<T>, LtSample<T> >::iterator it; 150 151 for (it = b.mEntries.begin(); 152 it != b.mEntries.end(); ++ it) { 152 153 float bSumPdf = (*it).second.mSumPdf; 153 154 float aSumPdf = 0.0f; 154 155 PvsData<T> *data = Find((*it).first); 155 156 if (data) { 156 aSumPdf = data-> second.mSumPdf;157 aSumPdf = data->mSumPdf; 157 158 // mark this entry as processed to avoid double counting 158 data-> second.mSumPdf = -aSumPdf;159 data->mSumPdf = -aSumPdf; 159 160 } 160 161 float diff = bSumPdf - aSumPdf; … … 177 178 PvsData<T> *data = b.Find((*it).first); 178 179 if (data) { 179 bSumPdf = data-> second.mSumPdf;180 bSumPdf = data->mSumPdf; 180 181 } 181 182 float diff = bSumPdf - aSumPdf; -
GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.cpp
r697 r704 14 14 15 15 16 #define ROTATE_SCENE 116 #define ROTATE_SCENE 0 17 17 // HACK 18 18 static void RotateMesh(Mesh *mesh) -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp
r697 r704 2951 2951 int BspNodeGeometry::ComputeIntersection(const AxisAlignedBox3 &box) const 2952 2952 { 2953 AxisAlignedBox3 boundingBox;2954 GetBoundingBox(boundingBox);2955 2956 const bool overlap = Overlap(boundingBox, box);2957 2958 // no intersections with bounding box2959 if (!overlap)2960 {2961 return 1;2962 }2963 int result = -1;2964 2965 2953 // 1: box does not intersect geometry 2966 2954 // 0: box intersects geometry 2967 2955 // -1: box contains geometry 2968 for (int i = 0; i < 6; ++ i) 2956 2957 AxisAlignedBox3 boundingBox; 2958 GetBoundingBox(boundingBox); 2959 2960 // no intersections with bounding box 2961 if (!Overlap(box, boundingBox)) 2962 { 2963 return 1; 2964 } 2965 2966 // box cotains bounding box of geometry >=> contains geometry 2967 if (box.Includes(boundingBox)) 2968 return -1; 2969 2970 int result = 0; 2971 2972 // test geometry planes for intersections 2973 vector<Plane3>::const_iterator it, it_end = mPlanes.end(); 2974 2975 for (it = mPlanes.begin(); it != it_end; ++ it) 2969 2976 { 2970 const int side = Side(box.GetPlane(i));2977 const int side = box.Side(*it); 2971 2978 2972 2979 // box does not intersects geometry 2973 2980 if (side == 1) 2981 { 2974 2982 return 1; 2975 2976 if (side == 0) 2977 result = 0; 2983 } 2984 //if (side == 0) result = 0; 2978 2985 } 2979 2986 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r703 r704 544 544 } 545 545 546 /* 547 int ViewCellsManager::ConstructLocalMergeTree(vector<LocalMergeCandidate> candidates) 548 549 { 550 while(!candidates.empty()) 551 { 552 MergeCandidate mc = candidates.back(); 553 candidates.pop_back(); 554 EvalMergeCost(mc); 555 mergeQueue.push(mc); 556 } 557 558 ViewCell::NewMail(); 559 560 561 long startTime = GetTime(); 562 563 mergeStats.candidates = (int)mMergeQueue.size(); 564 565 // passes are needed for statistics, because we don't want to record 566 // every merge 567 int pass = 0; 568 int mergedPerPass = 0; 569 float realExpectedCost = mExpectedCost; 570 float realAvgRenderCost = mAvgRenderCost; 571 int realNumActiveViewCells = mNumActiveViewCells; 572 573 reset. 574 575 int numMergedViewCells = 0; 576 577 environment->GetIntValue("ViewCells.PostProcess.maxMergesPerPass", maxMergesPerPass); 578 environment->GetFloatValue("ViewCells.PostProcess.avgCostMaxDeviation", avgCostMaxDeviation); 579 580 cout << "actual merge starts now ... " << endl; 581 546 547 inline float EvalMergeCost(ViewCell *root, ViewCell *candidate) 548 { 549 return root->GetPvs().GetPvsHomogenity(candidate->GetPvs()); 550 } 551 552 553 int GetBestViewCellIdx(ViewCell *root, const ViewCellContainer &neighborhood) 554 { 555 int bestViewCellIdx = -1;; 556 557 float mergeCost = Limits::Infinity; 558 int i = 0; 559 560 ViewCellContainer::const_iterator it, it_end = neighborhood.end(); 561 562 for (it = neighborhood.begin(); it != it_end; ++ it, ++ i) 563 { 564 const float mc = EvalMergeCost(root, *it); 565 566 if (mc > mergeCost) 567 { 568 mergeCost = mc; 569 bestViewCellIdx = i; 570 } 571 } 572 573 return bestViewCellIdx; 574 } 575 576 577 ViewCell *ViewCellsManager::ConstructLocalMergeTree(ViewCell *currentViewCell, 578 const ViewCellContainer &viewCells) 579 { 580 ViewCell *root = currentViewCell; 581 ViewCellContainer neighborhood = viewCells; 582 583 ViewCellContainer::const_iterator it, it_end = neighborhood.end(); 584 585 const int n = min(mMaxFilterSize, (int)neighborhood.size()); 582 586 //-- use priority queue to merge leaf pairs 583 587 588 584 589 //const float maxAvgCost = 350; 585 while (!mMergeQueue.empty())//NumActiveViewCells > mMergeMinViewCells)) 586 { 587 //-- reset merge queue if the ratio of current expected cost / real expected cost 588 // too small or after a given number of merges 589 if ((mergedPerPass > maxMergesPerPass) || 590 (avgCostMaxDeviation > mAvgRenderCost / realAvgRenderCost)) 591 { 592 // adjust render cost 593 ++ pass; 594 595 mergedPerPass = 0; 596 mExpectedCost = realExpectedCost; 597 598 590 for (int nMergedViewCells = 0; nMergedViewCells < n; ++ nMergedViewCells) 591 { 592 const int bestViewCellIdx = GetBestViewCellIdx(root, neighborhood); 599 593 600 // refines the view cells 601 // then priorities are recomputed 602 // and the candidates are put back into merge queue 603 if (mRefineViewCells) 604 RefineViewCells(rays, objects); 605 else 606 ResetMergeQueue(); 607 608 Debug << "Values after reset: " 609 << " erc: " << mExpectedCost 610 << " avg: " << mAvgRenderCost 611 << " dev: " << mDeviation << endl; 612 613 if (mExportMergedViewCells) 614 { 615 ExportMergedViewCells(activeViewCells, objects, numMergedViewCells); 616 } 617 } 618 619 620 MergeCandidate mc = mMergeQueue.top(); 621 mMergeQueue.pop(); 622 623 // both view cells equal 624 // NOTE: do I really still need this? probably cannot happen!! 625 if (mc.mLeftViewCell == mc.mRightViewCell) 626 continue; 627 628 if (mc.IsValid()) 629 { 630 ViewCell::NewMail(); 631 632 //-- update statistical values 633 -- realNumActiveViewCells; 634 ++ mergeStats.merged; 635 ++ mergedPerPass; 636 637 const float renderCostIncr = mc.GetRenderCost(); 638 const float mergeCostIncr = mc.GetMergeCost(); 639 640 totalRenderCost += renderCostIncr; 641 mDeviation += mc.GetDeviationIncr(); 642 643 644 // merge the view cells of leaf1 and leaf2 645 int pvsDiff; 646 ViewCellInterior *mergedVc = 647 MergeViewCells(mc.mLeftViewCell, mc.mRightViewCell, pvsDiff); 648 649 650 // total render cost and deviation has changed 651 // real expected cost will be larger than expected cost used for the 652 // cost heuristics, but cannot recompute costs on each increase of the 653 // expected cost 654 totalPvs += pvsDiff; 655 realExpectedCost = totalRenderCost / (float)realNumActiveViewCells; 656 realAvgRenderCost = (float)totalPvs / (float)realNumActiveViewCells; 657 658 // set merge cost to this node 659 mergedVc->SetMergeCost(totalRenderCost); 660 661 //if (mViewCellsManager->EqualToSpatialNode(mergedVc)) 662 // ++ mergeStats.siblings; 663 mergedVc->SetCost(realExpectedCost); 664 665 if ((mergeStats.merged % statsOut) == 0) 666 cout << "merged " << mergeStats.merged << " view cells" << endl; 667 668 } 669 else 670 { 671 // merge candidate not valid, because one of the leaves was already 672 // merged with another one => validate and reinsert into queue 673 if (ValidateMergeCandidate(mc)) 674 { 675 EvalMergeCost(mc); 676 mMergeQueue.push(mc); 677 } 678 } 594 ViewCell *bestViewCell = neighborhood[bestViewCellIdx]; 679 595 680 } 681 682 683 // adjust stats and reset queue one final time 684 mExpectedCost = realExpectedCost; 685 mAvgRenderCost = realAvgRenderCost; 686 mNumActiveViewCells = realNumActiveViewCells; 687 688 UpdateActiveViewCells(activeViewCells); 689 690 691 // refine view cells and reset costs 692 if (mRefineViewCells) 693 RefineViewCells(rays, objects); 694 else 695 ResetMergeQueue(); 696 697 // create a root node if the merge was not done till root level, 698 // else take the single node as new root 699 if ((int)activeViewCells.size() > 1) 700 { 701 Debug << "creating root of view cell hierarchy for " 702 << (int)activeViewCells.size() << " view cells" << endl; 596 // remove from vector 597 swap(neighborhood[bestViewCellIdx], neighborhood.back()); 598 neighborhood.pop_back(); 703 599 704 ViewCellInterior *root = mViewCellsManager->MergeViewCells(activeViewCells); 705 root->SetMergeCost(totalRenderCost); 706 // $$JB keep this 0 temporarilly 707 root->SetCost(0.0f); 708 709 mRoot = root; 710 } 711 else if ((int)activeViewCells.size() == 1) 712 { 713 Debug << "setting root of the merge history" << endl; 714 mRoot = activeViewCells[0]; 715 } 716 717 //-- empty merge queue just in case 718 while (!mMergeQueue.empty()) 719 { 720 mMergeQueue.pop(); 721 } 722 723 // TODO delete because makes no sense here 724 mergeStats.expectedRenderCost = realExpectedCost; 725 mergeStats.deviation = mDeviation; 726 727 // we want to optimize this heuristics 728 mergeStats.heuristics = 729 mDeviation * (1.0f - mRenderCostWeight) + 730 mExpectedCost * mRenderCostWeight; 731 732 mergeStats.mergeTime = TimeDiff(startTime, GetTime()); 733 mergeStats.Stop(); 734 Debug << mergeStats << endl << endl; 735 736 // assign colors for the view cells so that at least one is always consistent 737 AssignRandomColors(); 738 739 //TODO: should return sample contributions? 740 return mergeStats.merged; 741 } 742 */ 600 if (!bestViewCell || !root) 601 cout << "warning!!" << endl; 602 // create new root of the hierarchy 603 root = MergeViewCells(root, bestViewCell); 604 } 605 606 return root; 607 } 608 743 609 744 610 bool ViewCellsManager::CheckValidity(ViewCell *vc, … … 771 637 const AxisAlignedBox3 box = GetFilterBBox(viewPoint, mFilterWidth); 772 638 639 ViewCell *currentViewCell = GetViewCell(viewPoint); 640 773 641 ViewCellContainer viewCells; 774 642 ComputeBoxIntersections(box, viewCells); 775 643 776 644 ViewCell *root = ConstructLocalMergeTree(currentViewCell, viewCells); 645 646 prvs.mViewCell = root; 647 //prvs.mPvs = root->GetPvs(); 777 648 } 778 649 … … 2050 1921 subdivVol += (*it)->GetVolume(); 2051 1922 2052 float thres = 0.9 ;1923 float thres = 0.9f; 2053 1924 if ((lVol < ((*it)->GetVolume() * thres)) || 2054 1925 (lVol * thres > ((*it)->GetVolume()))) … … 4106 3977 subdivVol += (*it)->GetVolume(); 4107 3978 4108 float thres = 0.9 ;3979 float thres = 0.9f; 4109 3980 if ((lVol < ((*it)->GetVolume() * thres)) || (lVol * thres > ((*it)->GetVolume()))) 4110 3981 Debug << "warning: " << lVol << " " << (*it)->GetVolume() << endl; … … 4129 4000 Exporter *exporter = Exporter::GetExporter("filter.x3d"); 4130 4001 4002 Vector3 bsize = mViewSpaceBox.Size(); 4003 const Vector3 viewPoint(mViewSpaceBox.Center()); 4004 const Vector3 width = Vector3(mFilterWidth); 4005 4006 PrVs testPrVs; 4007 4131 4008 if (exporter) 4132 4009 { 4133 AxisAlignedBox3 testBox = mViewSpaceBox;4134 Vector3 bsize = mViewSpaceBox.Size();4135 4136 testBox.Enlarge(Vector3(-bsize[0] * 0.3, 0, -bsize[2] * 0.4));4137 4138 4010 ViewCellContainer viewCells; 4139 4140 mVspBspTree->ComputeBoxIntersections(testBox, viewCells); 4141 cout << "view cells: " << viewCells.size() << endl; 4142 4011 4012 const AxisAlignedBox3 tbox = GetFilterBBox(viewPoint, mFilterWidth); 4013 4014 GetPrVS(viewPoint, testPrVs); 4015 4143 4016 exporter->SetWireframe(); 4144 4017 4145 4018 exporter->SetForcedMaterial(RgbColor(1,1,1)); 4146 exporter->ExportBox(t estBox);4019 exporter->ExportBox(tbox); 4147 4020 4148 4021 exporter->SetFilled(); 4149 4022 exporter->ResetForcedMaterial(); 4150 for (int i = 0; i < viewCells.size(); ++ i) 4151 { 4152 BspNodeGeometry geom; 4153 4154 mVspBspTree->ConstructGeometry(viewCells[i], geom); 4155 exporter->ExportPolygons(geom.GetPolys()); 4156 } 4157 4158 exporter->SetForcedMaterial(RgbColor(1,0,0)); 4023 4024 ExportViewCellGeometry(exporter, testPrVs.mViewCell); 4025 4026 exporter->SetForcedMaterial(RgbColor(1,0,0)); 4159 4027 exporter->ExportGeometry(objects); 4160 4028 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r703 r704 38 38 { 39 39 public: 40 /// viewcells 41 ViewCellContainer mViewCells; 40 /// root of view cells tree 41 ViewCell *mViewCell; 42 43 //ViewCellContainer mViewCells; 42 44 /// aggregated pvs 43 ObjectPvs mPvs;45 //ObjectPvs mPvs; 44 46 45 47 // input parameter is the render budget for the PrVS … … 488 490 virtual void PrepareLoadedViewCells() {}; 489 491 492 /** Constructs local view cell merge hierarchy. 493 */ 494 ViewCell *ConstructLocalMergeTree(ViewCell *currentViewCell, 495 const ViewCellContainer &viewCells); 496 490 497 /** Creates clip plane for visualization. 491 498 */
Note: See TracChangeset
for help on using the changeset viewer.