Ignore:
Timestamp:
04/27/06 11:57:28 (18 years ago)
Author:
mattausch
Message:

implementing bounding box hack

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r837 r840  
    9393        environment->GetIntValue("ViewCells.renderCostEvaluationType", mRenderCostEvaluationType); 
    9494 
    95         environment->GetIntValue("ViewCells.pvsExportMode", mPvsExportMode); 
     95        environment->GetBoolValue("ViewCells.exportBboxesForPvs", mExportBboxesForPvs); 
    9696 
    9797        char buf[100]; 
     
    16771677                if (viewcell->GetValid()) 
    16781678                { 
    1679                         // HACK 
    1680 #if TEST_EMPTY_VIEW_CELLS 
    1681                                 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 #endif 
    16901679                        // if ray not outside of view space 
    16911680                        float contribution; 
     
    16991688                        } 
    17001689 
    1701                         //for directional sampling it is important to count only contributions 
     1690                        // for directional sampling it is important to count only contributions 
    17021691                        // made in one direction!!! 
    17031692                        // the other contributions of this sample will be counted for the oposite ray! 
     
    18581847} 
    18591848 
     1849 
     1850int ViewCellsManager::GetMaxFilterSize() const 
     1851{ 
     1852        return mMaxFilterSize;   
     1853} 
     1854 
     1855static const bool USE_ASCII = true; 
     1856 
     1857bool 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 
     1914inline bool ilt(Intersectable *obj1, Intersectable *obj2) 
     1915{ 
     1916        return obj1->mId < obj2->mId; 
     1917} 
     1918 
     1919/* 
     1920bool 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 
    18602006/**********************************************************************/ 
    18612007/*                   BspViewCellsManager implementation               */ 
     
    21172263        if (mExportViewCells) 
    21182264        { 
    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 
    21252278 
    21262279        return 0; 
     
    24842637        Mesh *mesh = new Mesh(); 
    24852638 
    2486         geom.AddToMesh(*mesh); 
     2639        IncludeNodeGeomInMesh(geom, *mesh); 
    24872640        vc->SetMesh(mesh); 
     2641 
    24882642        // put mesh into mesh container so we can savely delete it 
    24892643        mMeshContainer.push_back(mesh); 
     
    25782732        //-- the type of the view cells hierarchy 
    25792733        //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         
    25812737        //-- load the view cells itself, i.e., the ids and the pvs 
    25822738        stream << "<ViewCells>" << endl; 
    25832739 
    2584         mViewCellsTree->Export(stream, mPvsExportMode); 
     2740        mViewCellsTree->Export(stream); 
    25852741 
    25862742        stream << "</ViewCells>" << endl; 
     
    25972753 
    25982754        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         } 
    26192755} 
    26202756 
     
    37233859int VspBspViewCellsManager::PostProcess(const ObjectContainer &objects, 
    37243860                                                                                const VssRayContainer &rays) 
    3725 {Debug << "here8773" << endl; 
     3861{ 
    37263862        if (!ViewCellsConstructed()) 
    37273863        { 
     
    38123948 
    38133949        // collapse sibling leaves that share the same view cell 
    3814         if (0) 
    3815                 mVspBspTree->CollapseTree(); 
     3950        if (0) mVspBspTree->CollapseTree(); 
    38163951 
    38173952        // recompute view cell list and statistics 
     
    38213956        if (1) FinalizeViewCells(true); 
    38223957 
    3823  
    3824         Debug << "here3" << endl; 
    38253958        // write view cells to disc 
    38263959        if (mExportViewCells) 
    38273960        { 
    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); 
    38343973        } 
    38353974 
     
    45064645         
    45074646        Mesh *mesh = new Mesh(); 
    4508         geom.AddToMesh(*mesh); 
     4647        IncludeNodeGeomInMesh(geom, *mesh); 
     4648 
    45094649        vc->SetMesh(mesh); 
    45104650        // put mesh into mesh container so we can savely delete it 
     
    45434683} 
    45444684 
    4545  
    4546 inline bool ilt(Intersectable *obj1, Intersectable *obj2) 
    4547 { 
    4548         return obj1->mId < obj2->mId; 
    4549 } 
    45504685 
    45514686 
     
    45674702                   << " max=\"" << mViewSpaceBox.Max().x << " " << mViewSpaceBox.Max().y << " " << mViewSpaceBox.Max().z << "\" />" << endl; 
    45684703 
     4704 
     4705 
    45694706        //-- the type of the view cells hierarchy 
    45704707        stream << "<Hierarchy name=\"vspBspTree\" />" << endl; 
    45714708 
    4572         //-- export the view cells itself, i.e., the ids and the pvs 
     4709        //-- export the view cells and the pvs 
    45734710        stream << "<ViewCells>" << endl; 
    4574         Debug << "**************************** mode: " << mPvsExportMode << endl; 
    4575         mViewCellsTree->Export(stream, mPvsExportMode); 
     4711         
     4712        mViewCellsTree->Export(stream); 
    45764713 
    45774714        stream << "</ViewCells>" << endl; 
     4715 
    45784716 
    45794717        //-- export the hierarchy 
     
    45814719        mVspBspTree->Export(stream); 
    45824720        stream << endl << "</Hierarchy>" << endl; 
     4721 
     4722 
    45834723 
    45844724        stream << "</Visibility_Solution>" << endl; 
     
    47344874 
    47354875 
    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  
    47444876////////////////////////////////// 
    47454877ViewCellsManager *ViewCellsManagerFactory::Create(const string mName) 
Note: See TracChangeset for help on using the changeset viewer.