Changeset 840 for GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
- Timestamp:
- 04/27/06 11:57:28 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r837 r840 93 93 environment->GetIntValue("ViewCells.renderCostEvaluationType", mRenderCostEvaluationType); 94 94 95 environment->Get IntValue("ViewCells.pvsExportMode", mPvsExportMode);95 environment->GetBoolValue("ViewCells.exportBboxesForPvs", mExportBboxesForPvs); 96 96 97 97 char buf[100]; … … 1677 1677 if (viewcell->GetValid()) 1678 1678 { 1679 // HACK1680 #if TEST_EMPTY_VIEW_CELLS1681 for (int i = 0; i < mEmptyViewCells.size(); ++i)1682 {1683 if (viewcell == mEmptyViewCells[i])1684 {1685 viewcell->mPiercingRays.push_back(new Ray(ray));1686 Debug << "empty view cell ray found: " << ray.mOriginObject << ", " << ray.mTerminationObject << endl;1687 }1688 }1689 #endif1690 1679 // if ray not outside of view space 1691 1680 float contribution; … … 1699 1688 } 1700 1689 1701 // for directional sampling it is important to count only contributions1690 // for directional sampling it is important to count only contributions 1702 1691 // made in one direction!!! 1703 1692 // the other contributions of this sample will be counted for the oposite ray! … … 1858 1847 } 1859 1848 1849 1850 int ViewCellsManager::GetMaxFilterSize() const 1851 { 1852 return mMaxFilterSize; 1853 } 1854 1855 static const bool USE_ASCII = true; 1856 1857 bool ViewCellsManager::ExportBoundingBoxes(const string filename, 1858 const ObjectContainer &objects) const 1859 { 1860 ObjectContainer::const_iterator it, it_end = objects.end(); 1861 1862 if (USE_ASCII) 1863 { 1864 ofstream boxesOut(filename.c_str()); 1865 if (!boxesOut.is_open()) 1866 return false; 1867 1868 for (it = objects.begin(); it != it_end; ++ it) 1869 { 1870 MeshInstance *mi = dynamic_cast<MeshInstance *>(*it); 1871 const AxisAlignedBox3 box = mi->GetBox(); 1872 1873 boxesOut << mi->GetId() << " " 1874 << box.Min().x << " " 1875 << box.Min().y << " " 1876 << box.Min().z << " " 1877 << box.Max().x << " " 1878 << box.Max().y << " " 1879 << box.Max().z << endl; 1880 } 1881 1882 boxesOut.close(); 1883 } 1884 else 1885 { 1886 ofstream boxesOut(filename.c_str(), ios::binary); 1887 1888 if (!boxesOut.is_open()) 1889 return false; 1890 1891 for (it = objects.begin(); it != it_end; ++ it) 1892 { 1893 MeshInstance *mi = dynamic_cast<MeshInstance *>(*it); 1894 const AxisAlignedBox3 box = mi->GetBox(); 1895 Vector3 bmin = box.Min(); 1896 Vector3 bmax = box.Max(); 1897 1898 boxesOut.write(reinterpret_cast<char *>(&bmin), sizeof(Vector3)); 1899 boxesOut.write(reinterpret_cast<char *>(&bmax), sizeof(Vector3)); 1900 } 1901 1902 boxesOut.close(); 1903 } 1904 1905 1906 return true; 1907 } 1908 1909 1910 // use ascii format to store rays 1911 #define USE_ASCII 0 1912 1913 1914 inline bool ilt(Intersectable *obj1, Intersectable *obj2) 1915 { 1916 return obj1->mId < obj2->mId; 1917 } 1918 1919 /* 1920 bool Preprocessor::LoadBoundingBoxes(const string filename, 1921 const ObjectContainer &objects) const 1922 { 1923 std::stable_sort(objects.begin(), objects.end(), ilt); 1924 char fileName[100]; 1925 environment->GetStringValue("Preprocessor.samplesFilename", fileName); 1926 1927 Vector3 origin, termination; 1928 // HACK: needed only for lower_bound algorithm to find the 1929 // intersected objects 1930 MeshInstance sObj(NULL); 1931 MeshInstance tObj(NULL); 1932 1933 #if USE_ASCII 1934 ifstream samplesIn(fileName); 1935 if (!samplesIn.is_open()) 1936 return false; 1937 1938 string buf; 1939 while (!(getline(samplesIn, buf)).eof()) 1940 { 1941 sscanf(buf.c_str(), "%f %f %f %f %f %f %d %d", 1942 &origin.x, &origin.y, &origin.z, 1943 &termination.x, &termination.y, &termination.z, 1944 &(sObj.mId), &(tObj.mId)); 1945 1946 Intersectable *sourceObj = NULL; 1947 Intersectable *termObj = NULL; 1948 1949 if (sObj.mId >= 0) 1950 { 1951 ObjectContainer::iterator oit = 1952 lower_bound(objects.begin(), objects.end(), &sObj, ilt); 1953 sourceObj = *oit; 1954 } 1955 1956 if (tObj.mId >= 0) 1957 { 1958 ObjectContainer::iterator oit = 1959 lower_bound(objects.begin(), objects.end(), &tObj, ilt); 1960 termObj = *oit; 1961 } 1962 1963 samples.push_back(new VssRay(origin, termination, sourceObj, termObj)); 1964 } 1965 #else 1966 ifstream samplesIn(fileName, ios::binary); 1967 if (!samplesIn.is_open()) 1968 return false; 1969 1970 while (1) 1971 { 1972 samplesIn.read(reinterpret_cast<char *>(&origin), sizeof(Vector3)); 1973 samplesIn.read(reinterpret_cast<char *>(&termination), sizeof(Vector3)); 1974 samplesIn.read(reinterpret_cast<char *>(&(sObj.mId)), sizeof(int)); 1975 samplesIn.read(reinterpret_cast<char *>(&(tObj.mId)), sizeof(int)); 1976 1977 if (samplesIn.eof()) 1978 break; 1979 1980 Intersectable *sourceObj = NULL; 1981 Intersectable *termObj = NULL; 1982 1983 if (sObj.mId >= 0) 1984 { 1985 ObjectContainer::iterator oit = 1986 lower_bound(objects.begin(), objects.end(), &sObj, ilt); 1987 sourceObj = *oit; 1988 } 1989 1990 if (tObj.mId >= 0) 1991 { 1992 ObjectContainer::iterator oit = 1993 lower_bound(objects.begin(), objects.end(), &tObj, ilt); 1994 termObj = *oit; 1995 } 1996 1997 samples.push_back(new VssRay(origin, termination, sourceObj, termObj)); 1998 } 1999 2000 #endif 2001 samplesIn.close(); 2002 2003 return true; 2004 }*/ 2005 1860 2006 /**********************************************************************/ 1861 2007 /* BspViewCellsManager implementation */ … … 2117 2263 if (mExportViewCells) 2118 2264 { 2119 char buff[100]; 2120 environment->GetStringValue("ViewCells.filename", buff); 2121 string vcFilename(buff); 2122 2123 ExportViewCells(buff); 2124 } 2265 char filename[100]; 2266 environment->GetStringValue("ViewCells.filename", filename); 2267 ExportViewCells(filename); 2268 } 2269 2270 // export bounding boxes 2271 if (mExportBboxesForPvs) 2272 { 2273 char filename[100]; 2274 environment->GetStringValue("ViewCells.boxesFilename", filename); 2275 ExportBoundingBoxes(filename, objects); 2276 } 2277 2125 2278 2126 2279 return 0; … … 2484 2637 Mesh *mesh = new Mesh(); 2485 2638 2486 geom.AddToMesh(*mesh);2639 IncludeNodeGeomInMesh(geom, *mesh); 2487 2640 vc->SetMesh(mesh); 2641 2488 2642 // put mesh into mesh container so we can savely delete it 2489 2643 mMeshContainer.push_back(mesh); … … 2578 2732 //-- the type of the view cells hierarchy 2579 2733 //stream << "<Hierarchy name=\"bspTree\" />" << endl; 2580 stream << "<Hierarchy name=\"vspBspTree\" />" << endl; // write vsp bsp here because can use same tree and is bug free 2734 // NOTE: load in vsp bsp here because bsp and vsp bsp can use same tree and vsp bsp is bug free 2735 stream << "<Hierarchy name=\"vspBspTree\" />" << endl; 2736 2581 2737 //-- load the view cells itself, i.e., the ids and the pvs 2582 2738 stream << "<ViewCells>" << endl; 2583 2739 2584 mViewCellsTree->Export(stream , mPvsExportMode);2740 mViewCellsTree->Export(stream); 2585 2741 2586 2742 stream << "</ViewCells>" << endl; … … 2597 2753 2598 2754 return true; 2599 }2600 2601 2602 void BspViewCellsManager::AddCurrentViewCellsToHierarchy()2603 {2604 ViewCellContainer::const_iterator it, it_end = mViewCells.end();2605 for (it = mViewCells.begin(); it != it_end; ++ it)2606 {2607 ViewCell *vc = *it;2608 ViewCellContainer leaves;2609 mViewCellsTree->CollectLeaves(vc, leaves);2610 2611 ViewCellContainer::const_iterator lit, lit_end = leaves.end();2612 2613 for (lit = leaves.begin(); lit != lit_end; ++ lit)2614 {2615 BspViewCell *bspVc = dynamic_cast<BspViewCell *>(*lit);2616 bspVc->mLeaf->SetViewCell(vc);2617 }2618 }2619 2755 } 2620 2756 … … 3723 3859 int VspBspViewCellsManager::PostProcess(const ObjectContainer &objects, 3724 3860 const VssRayContainer &rays) 3725 { Debug << "here8773" << endl;3861 { 3726 3862 if (!ViewCellsConstructed()) 3727 3863 { … … 3812 3948 3813 3949 // collapse sibling leaves that share the same view cell 3814 if (0) 3815 mVspBspTree->CollapseTree(); 3950 if (0) mVspBspTree->CollapseTree(); 3816 3951 3817 3952 // recompute view cell list and statistics … … 3821 3956 if (1) FinalizeViewCells(true); 3822 3957 3823 3824 Debug << "here3" << endl;3825 3958 // write view cells to disc 3826 3959 if (mExportViewCells) 3827 3960 { 3828 Debug << "here4" << endl; 3829 char buff[100]; 3830 environment->GetStringValue("ViewCells.filename", buff); 3831 string vcFilename(buff); 3832 3833 ExportViewCells(buff); 3961 char filename[100]; 3962 environment->GetStringValue("ViewCells.filename", filename); 3963 ExportViewCells(filename); 3964 } 3965 3966 3967 // export bounding boxes 3968 if (mExportBboxesForPvs) 3969 { 3970 char filename[100]; 3971 environment->GetStringValue("ViewCells.boxesFilename", filename); 3972 ExportBoundingBoxes(filename, objects); 3834 3973 } 3835 3974 … … 4506 4645 4507 4646 Mesh *mesh = new Mesh(); 4508 geom.AddToMesh(*mesh); 4647 IncludeNodeGeomInMesh(geom, *mesh); 4648 4509 4649 vc->SetMesh(mesh); 4510 4650 // put mesh into mesh container so we can savely delete it … … 4543 4683 } 4544 4684 4545 4546 inline bool ilt(Intersectable *obj1, Intersectable *obj2)4547 {4548 return obj1->mId < obj2->mId;4549 }4550 4685 4551 4686 … … 4567 4702 << " max=\"" << mViewSpaceBox.Max().x << " " << mViewSpaceBox.Max().y << " " << mViewSpaceBox.Max().z << "\" />" << endl; 4568 4703 4704 4705 4569 4706 //-- the type of the view cells hierarchy 4570 4707 stream << "<Hierarchy name=\"vspBspTree\" />" << endl; 4571 4708 4572 //-- export the view cells itself, i.e., the idsand the pvs4709 //-- export the view cells and the pvs 4573 4710 stream << "<ViewCells>" << endl; 4574 Debug << "**************************** mode: " << mPvsExportMode << endl;4575 mViewCellsTree->Export(stream , mPvsExportMode);4711 4712 mViewCellsTree->Export(stream); 4576 4713 4577 4714 stream << "</ViewCells>" << endl; 4715 4578 4716 4579 4717 //-- export the hierarchy … … 4581 4719 mVspBspTree->Export(stream); 4582 4720 stream << endl << "</Hierarchy>" << endl; 4721 4722 4583 4723 4584 4724 stream << "</Visibility_Solution>" << endl; … … 4734 4874 4735 4875 4736 void VspBspViewCellsManager::AddCurrentViewCellsToHierarchy()4737 {4738 ViewCellContainer::const_iterator it, it_end = mViewCells.end();4739 for (it = mViewCells.begin(); it != it_end; ++ it)4740 {4741 }4742 }4743 4744 4876 ////////////////////////////////// 4745 4877 ViewCellsManager *ViewCellsManagerFactory::Create(const string mName)
Note: See TracChangeset
for help on using the changeset viewer.