Changeset 1974 for GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
- Timestamp:
- 01/14/07 19:59:25 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1972 r1974 667 667 668 668 669 670 671 ViewCellsManager *ViewCellsManager::LoadViewCells(const string &filename, 672 ObjectContainer *objects, 673 bool finalizeViewCells, 674 BoundingBoxConverter *bconverter) 675 676 { 677 ViewCellsParser parser; 678 ViewCellsManager *vm = NULL; 679 680 const long startTime = GetTime(); 681 bool success = parser.ParseViewCellsFile(filename, &vm, objects, bconverter); 682 683 cout<<"viewcells parsed "<<endl<<flush; 684 685 if (success) 686 { 687 //vm->ResetViewCells(); 688 //hack 689 vm->mViewCells.clear(); 690 ViewCellContainer leaves; 691 vm->mViewCellsTree->CollectLeaves(vm->mViewCellsTree->GetRoot(), leaves); 692 693 ViewCellContainer::const_iterator it, it_end = leaves.end(); 694 695 for (it = leaves.begin(); it != it_end; ++ it) 696 { 697 vm->mViewCells.push_back(*it); 698 } 699 vm->mViewCellsFinished = true; 700 vm->mMaxPvsSize = (int)objects->size(); 701 702 if (finalizeViewCells) 703 { 704 // create the meshes and compute volumes 705 vm->FinalizeViewCells(true); 706 // vm->mViewCellsTree->AssignRandomColors(); 707 } 708 709 Debug << (int)vm->mViewCells.size() << " view cells loaded in " 710 << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 711 } 712 else 713 { 714 Debug << "Error: loading view cells failed!" << endl; 715 DEL_PTR(vm); 716 } 717 718 return vm; 719 } 720 721 722 bool VspBspViewCellsManager::ExportViewCells(const string filename, 723 const bool exportPvs, 724 const ObjectContainer &objects) 725 { 726 if (!ViewCellsConstructed() || !ViewCellsTreeConstructed()) 727 { 728 return false; 729 } 730 731 cout << "exporting view cells to xml ... "; 732 733 OUT_STREAM stream(filename.c_str()); 734 735 // for output we need unique ids for each view cell 736 CreateUniqueViewCellIds(); 737 738 stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"<<endl; 739 stream << "<VisibilitySolution>" << endl; 740 741 if (exportPvs) 742 { 743 //-- export bounding boxes 744 stream << "<BoundingBoxes>" << endl; 745 746 if (mUseKdPvs) 747 { 748 vector<KdIntersectable *>::iterator kit, kit_end = GetPreprocessor()->mKdTree->mKdIntersectables.end(); 749 750 int id = 0; 751 for (kit = GetPreprocessor()->mKdTree->mKdIntersectables.begin(); kit != kit_end; ++ kit, ++ id) 752 { 753 Intersectable *obj = *kit; 754 const AxisAlignedBox3 box = obj->GetBox(); 755 756 obj->SetId(id); 757 758 stream << "<BoundingBox" << " id=\"" << id << "\"" 759 << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 760 << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; 761 } 762 } 763 else 764 { 765 ObjectContainer::const_iterator oit, oit_end = objects.end(); 766 767 for (oit = objects.begin(); oit != oit_end; ++ oit) 768 { 769 const AxisAlignedBox3 box = (*oit)->GetBox(); 770 771 //////////// 772 //-- the bounding boxes 773 774 stream << "<BoundingBox" << " id=\"" << (*oit)->GetId() << "\"" 775 << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 776 << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; 777 } 778 } 779 780 stream << "</BoundingBoxes>" << endl; 781 } 782 783 784 ///////////// 785 //-- export the view cells and the pvs 786 787 const int numViewCells = mCurrentViewCellsStats.viewCells; 788 stream << "<ViewCells number=\"" << numViewCells << "\" >" << endl; 789 790 mViewCellsTree->Export(stream, exportPvs); 791 792 stream << "</ViewCells>" << endl; 793 794 795 ////////// 796 //-- export the view space hierarchy 797 798 stream << "<ViewSpaceHierarchy type=\"bsp\"" 799 << " min=\"" << mViewSpaceBox.Min().x << " " << mViewSpaceBox.Min().y << " " << mViewSpaceBox.Min().z << "\"" 800 << " max=\"" << mViewSpaceBox.Max().x << " " << mViewSpaceBox.Max().y << " " << mViewSpaceBox.Max().z << "\">" << endl; 801 802 mVspBspTree->Export(stream); 803 stream << "</ViewSpaceHierarchy>" << endl; 804 805 stream << "</VisibilitySolution>" << endl; 806 807 stream.close(); 808 cout << "finished" << endl; 809 810 return true; 811 } 812 669 813 void ViewCellsManager::EvalViewCellHistogram(const string filename, 670 814 const int nViewCells) … … 757 901 outstream.close(); 758 902 } 759 760 761 ViewCellsManager *ViewCellsManager::LoadViewCells(const string &filename,762 ObjectContainer *objects,763 bool finalizeViewCells,764 BoundingBoxConverter *bconverter)765 766 {767 ViewCellsParser parser;768 ViewCellsManager *vm = NULL;769 770 const long startTime = GetTime();771 bool success = parser.ParseViewCellsFile(filename, &vm, objects, bconverter);772 773 cout<<"viewcells parsed "<<endl<<flush;774 775 if (success)776 {777 //vm->ResetViewCells();778 //hack779 vm->mViewCells.clear();780 ViewCellContainer leaves;781 vm->mViewCellsTree->CollectLeaves(vm->mViewCellsTree->GetRoot(), leaves);782 783 ViewCellContainer::const_iterator it, it_end = leaves.end();784 785 for (it = leaves.begin(); it != it_end; ++ it)786 {787 vm->mViewCells.push_back(*it);788 }789 vm->mViewCellsFinished = true;790 vm->mMaxPvsSize = (int)objects->size();791 792 if (finalizeViewCells)793 {794 // create the meshes and compute volumes795 vm->FinalizeViewCells(true);796 // vm->mViewCellsTree->AssignRandomColors();797 }798 799 Debug << (int)vm->mViewCells.size() << " view cells loaded in "800 << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;801 }802 else803 {804 Debug << "Error: loading view cells failed!" << endl;805 DEL_PTR(vm);806 }807 808 return vm;809 }810 811 812 bool VspBspViewCellsManager::ExportViewCells(const string filename,813 const bool exportPvs,814 const ObjectContainer &objects)815 {816 if (!ViewCellsConstructed() || !ViewCellsTreeConstructed())817 {818 return false;819 }820 821 cout << "exporting view cells to xml ... ";822 823 OUT_STREAM stream(filename.c_str());824 825 // for output we need unique ids for each view cell826 CreateUniqueViewCellIds();827 828 stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"<<endl;829 stream << "<VisibilitySolution>" << endl;830 831 if (exportPvs)832 {833 //-- export bounding boxes834 stream << "<BoundingBoxes>" << endl;835 836 if (mUseKdPvs)837 {838 vector<KdIntersectable *>::iterator kit, kit_end = GetPreprocessor()->mKdTree->mKdIntersectables.end();839 840 int id = 0;841 for (kit = GetPreprocessor()->mKdTree->mKdIntersectables.begin(); kit != kit_end; ++ kit, ++ id)842 {843 Intersectable *obj = *kit;844 const AxisAlignedBox3 box = obj->GetBox();845 846 obj->SetId(id);847 848 stream << "<BoundingBox" << " id=\"" << id << "\""849 << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\""850 << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl;851 }852 }853 else854 {855 ObjectContainer::const_iterator oit, oit_end = objects.end();856 857 for (oit = objects.begin(); oit != oit_end; ++ oit)858 {859 const AxisAlignedBox3 box = (*oit)->GetBox();860 861 ////////////862 //-- the bounding boxes863 864 stream << "<BoundingBox" << " id=\"" << (*oit)->GetId() << "\""865 << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\""866 << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl;867 }868 }869 870 stream << "</BoundingBoxes>" << endl;871 }872 873 874 /////////////875 //-- export the view cells and the pvs876 877 const int numViewCells = mCurrentViewCellsStats.viewCells;878 stream << "<ViewCells number=\"" << numViewCells << "\" >" << endl;879 880 mViewCellsTree->Export(stream, exportPvs);881 882 stream << "</ViewCells>" << endl;883 884 885 //////////886 //-- export the view space hierarchy887 888 stream << "<ViewSpaceHierarchy type=\"bsp\""889 << " min=\"" << mViewSpaceBox.Min().x << " " << mViewSpaceBox.Min().y << " " << mViewSpaceBox.Min().z << "\""890 << " max=\"" << mViewSpaceBox.Max().x << " " << mViewSpaceBox.Max().y << " " << mViewSpaceBox.Max().z << "\">" << endl;891 892 mVspBspTree->Export(stream);893 stream << "</ViewSpaceHierarchy>" << endl;894 895 stream << "</VisibilitySolution>" << endl;896 897 stream.close();898 cout << "finished" << endl;899 900 return true;901 }902 903 903 904 904 void ViewCellsManager::EvalViewCellHistogramForPvsSize(const string filename, … … 1269 1269 filename = string(statsPrefix) + string(s); 1270 1270 1271 EvalViewCellHistogramForPvsSize(filename, pass); 1271 EvalViewCellHistogram(filename, pass); 1272 // EvalViewCellHistogramForPvsSize(filename, pass); 1272 1273 } 1273 1274 } … … 1992 1993 stat.maxPvs = 0; 1993 1994 stat.avgPvs = 0.0f; 1995 stat.avgPvsEntries = 0.0f; 1994 1996 stat.avgFilteredPvs = 0.0f; 1997 stat.avgFilteredPvsEntries = 0.0f; 1995 1998 stat.avgFilterContribution = 0.0f; 1996 1999 stat.avgFilterRadius = 0; … … 2016 2019 if (viewcell->GetValid()) { 2017 2020 const float pvsCost = mViewCellsTree->GetPvsCost(viewcell); 2018 2021 2019 2022 if (pvsCost < stat.minPvs) 2020 2023 stat.minPvs = pvsCost; … … 2024 2027 stat.avgPvs += pvsCost; 2025 2028 2029 const float pvsEntries = mViewCellsTree->GetPvsEntries(viewcell); 2030 stat.avgPvsEntries += pvsEntries; 2031 2026 2032 2027 2033 if (mPerViewCellStat[i].pvsSize > 0.0f) … … 2037 2043 if (evaluateFilter) { 2038 2044 ObjectPvs filteredPvs; 2045 2039 2046 PvsFilterStatistics fstat = ApplyFilter2(viewcell, 2040 2047 false, … … 2043 2050 2044 2051 float filteredCost = filteredPvs.EvalPvsCost(); 2052 2045 2053 stat.avgFilteredPvs += filteredCost; 2054 stat.avgFilteredPvsEntries += filteredPvs.GetSize(); 2055 2046 2056 stat.avgFilterContribution += filteredCost - pvsCost; 2047 2057 … … 2066 2076 if (stat.viewcells) { 2067 2077 stat.avgPvs/=stat.viewcells; 2078 stat.avgPvsEntries/=stat.viewcells; 2068 2079 stat.avgFilteredPvs/=stat.viewcells; 2069 2080 stat.avgFilterContribution/=stat.viewcells; … … 2089 2100 GetPvsStatistics(pvsStat); 2090 2101 s<<"#AVG_PVS\n"<<pvsStat.avgPvs<<endl; 2102 s<<"#AVG_ENTRIES_PVS\n"<<pvsStat.avgPvsEntries<<endl; 2091 2103 s<<"#AVG_FILTERED_PVS\n"<<pvsStat.avgFilteredPvs<<endl; 2104 s<<"#AVG_FILTERED_ENTRIES_PVS\n"<<pvsStat.avgFilteredPvsEntries<<endl; 2092 2105 s<<"#AVG_FILTER_CONTRIBUTION\n"<<pvsStat.avgFilterContribution<<endl; 2093 2106 s<<"#AVG_FILTER_RADIUS\n"<<pvsStat.avgFilterRadius<<endl; … … 2991 3004 objects.clear(); 2992 3005 // $$ warning collect objects takes only unmailed ones! 2993 CollectObjects(box, objects); 3006 if (mUseKdPvsAfterFiltering) { 3007 float area = GetPreprocessor()->mKdTree->GetBox().SurfaceArea()*KD_PVS_AREA; 3008 GetPreprocessor()->mKdTree->CollectKdObjects(box, objects, area); 3009 } else 3010 CollectObjects(box, objects); 3011 2994 3012 // cout<<"collected objects="<<objects.size()<<endl; 2995 3013 ObjectContainer::const_iterator noi = objects.begin();
Note: See TracChangeset
for help on using the changeset viewer.