Ignore:
Timestamp:
01/23/06 02:56:48 (18 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp

    r563 r564  
    2727mViewCellsFinished(false), 
    2828mMaxPvsSize(9999999), 
    29 mMinPvsSize(1), // only empty view cells are invalid 
     29mMinPvsSize(0), // one means only empty view cells are invalid 
    3030mMaxPvsRatio(1.0) 
    3131{ 
     
    4444mViewCellsFinished(false), 
    4545mMaxPvsSize(9999999), 
    46 mMinPvsSize(1), // only empty view cells are invalid 
     46mMinPvsSize(0), // one means only empty view cells are invalid 
    4747mMaxPvsRatio(1.0) 
    4848{ 
     
    5858        environment->GetBoolValue("ViewCells.Visualization.exportGeometry", mExportGeometry); 
    5959        environment->GetFloatValue("ViewCells.maxPvsRatio", mMaxPvsRatio); 
     60        bool emptyViewCells = false; 
     61        environment->GetBoolValue("ViewCells.pruneEmptyViewCells", emptyViewCells); 
     62        environment->GetBoolValue("ViewCells.processOnlyValidViewCells", mOnlyValidViewCells); 
     63 
     64        mMinPvsSize = emptyViewCells ? 1 : 0; 
    6065 
    6166        char buf[50]; 
    62  
    6367        environment->GetStringValue("ViewCells.Visualization.colorCode", buf); 
    6468 
     
    9195        preprocessor->GenerateVssRays(mConstructionSamples, vssRays); 
    9296        Construct(preprocessor->mObjects, vssRays); 
    93          
     97 
    9498        // add rays to output rays 
    9599        while (!vssRays.empty) 
     
    116120 
    117121 
    118 bool ViewCellsManager::CheckValidity(ViewCell *vc,  
    119                                                                          int minPvsSize,  
     122bool ViewCellsManager::CheckValidity(ViewCell *vc, 
     123                                                                         int minPvsSize, 
    120124                                                                         int maxPvsSize) const 
    121125{ 
    122126        if ((vc->GetPvs().GetSize() > mMaxPvsSize) || 
    123127                (vc->GetPvs().GetSize() < mMinPvsSize)) 
    124         {        
     128        { 
    125129                return false; 
    126130        } 
     
    130134 
    131135 
    132 void ViewCellsManager::SetValidity(ViewCell *vc,  
    133                                                                    int minPvs,  
     136void ViewCellsManager::SetValidity(ViewCell *vc, 
     137                                                                   int minPvs, 
    134138                                                                   int maxPvs) const 
    135139{ 
     
    179183  if (!ViewCellsConstructed()) 
    180184        return 0.0f; 
    181    
     185 
    182186  VssRayContainer::const_iterator it, it_end = rays.end(); 
    183187 
     
    309313 
    310314        //-- merge ray sets 
    311         stable_sort(front.mPiercingRays.begin(), front.mPiercingRays.end()); 
    312         stable_sort(back.mPiercingRays.begin(), back.mPiercingRays.end()); 
    313  
    314         std::merge(front.mPiercingRays.begin(), front.mPiercingRays.end(), 
    315                            back.mPiercingRays.begin(), back.mPiercingRays.end(), 
    316                            vc->mPiercingRays.begin()); 
     315        if (0) 
     316        { 
     317                stable_sort(front.mPiercingRays.begin(), front.mPiercingRays.end()); 
     318                stable_sort(back.mPiercingRays.begin(), back.mPiercingRays.end()); 
     319 
     320                std::merge(front.mPiercingRays.begin(), front.mPiercingRays.end(), 
     321                                   back.mPiercingRays.begin(), back.mPiercingRays.end(), 
     322                                   vc->mPiercingRays.begin()); 
     323        } 
    317324 
    318325        return vc; 
     
    429436{ 
    430437        mViewCells.clear(); 
    431          
     438 
    432439        CollectViewCells(); 
    433          
     440 
    434441        mViewCellsStats.Reset(); 
    435442        EvaluateViewCellsStats(); 
     
    449456  if (!ViewCellsConstructed()) 
    450457        return; 
    451    
     458 
    452459  VssRayContainer::const_iterator it, it_end = rays.end(); 
    453    
     460 
    454461  for (it = rays.begin(); it != it_end; ++ it) { 
    455462        AddSampleContributions(*(*it)); 
     
    489496{ 
    490497  ViewCellContainer viewcells; 
    491    
     498 
    492499  ray.mPvsContribution = 0; 
    493500  ray.mRelativePvsContribution = 0.0f; 
    494    
    495   // matt TODO: remove this!! 
    496   Ray hray(ray); 
    497   float tmin = 0, tmax = 1.0; 
    498    
    499   //hray.Init(ray.GetOrigin(), ray.GetDir(), Ray::LINE_SEGMENT); 
    500   if (!GetViewSpaceBox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) 
    501         return 0.0f; 
    502    
    503   Vector3 origin = hray.Extrap(tmin); 
    504   Vector3 termination = hray.Extrap(tmax); 
     501 
     502 static Ray hray; 
     503        hray.Init(ray); 
     504        //hray.mFlags |= Ray::CULL_BACKFACES; 
     505        //Ray hray(ray); 
     506 
     507        float tmin = 0, tmax = 1.0; 
     508 
     509        if (!GetViewSpaceBox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) 
     510                return; 
     511 
     512        Vector3 origin = hray.Extrap(tmin); 
     513        Vector3 termination = hray.Extrap(tmax); 
     514 
     515        CastLineSegment(origin, termination, viewcells); 
     516        //Debug << "constribution: " << (int)viewcells.size() << endl; 
     517        // copy viewcells memory efficiently 
     518        const bool storeViewcells = false; 
     519        if (storeViewcells) 
    505520 
    506521  CastLineSegment(origin, 
    507522                                  termination, 
    508523                                  viewcells); 
    509    
     524 
    510525  //Debug << "constribution: " << (int)viewcells.size() << endl; 
    511    
     526 
    512527  // copy viewcells memory efficiently 
    513528  const bool storeViewcells = !addRays; 
    514    
     529 
    515530  if (storeViewcells) 
    516         { 
     531  { 
    517532          ray.mViewCells.reserve(viewcells.size()); 
    518533          ray.mViewCells = viewcells; 
    519         } 
    520    
     534          } 
     535 
    521536  ViewCellContainer::const_iterator it = viewcells.begin(); 
    522    
    523    
     537 
     538 
    524539  for (; it != viewcells.end(); ++it) { 
    525540        ViewCell *viewcell = *it; 
     
    533548        ray.mRelativePvsContribution += contribution; 
    534549  } 
    535    
     550 
    536551  if (addRays) 
    537552        for (it = viewcells.begin(); it != viewcells.end(); ++it) { 
     
    623638 
    624639 
    625 bool ViewCellsManager::ExportViewCells(const string filename)  
    626 {  
     640bool ViewCellsManager::ExportViewCells(const string filename) 
     641{ 
    627642        return false; 
    628643} 
     
    18471862void VspBspViewCellsManager::CollectViewCells() 
    18481863{ 
    1849         mVspBspTree->CollectViewCells(mViewCells, false); 
     1864        mVspBspTree->CollectViewCells(mViewCells, mOnlyValidViewCells); 
    18501865} 
    18511866 
     
    18941909 
    18951910        mMaxPvsSize = (int)(mMaxPvsRatio * (float)objects.size()); 
    1896          
     1911 
    18971912        mVspBspTree->Construct(constructionRays, &mViewSpaceBox); 
    18981913 
     
    19962011                if (exporter) 
    19972012                { 
    1998                         if (1) 
     2013                        if (0) 
    19992014                                exporter->SetWireframe(); 
    20002015                        else 
     
    20192034 
    20202035 
    2021 void VspBspViewCellsManager::RefineViewCells(const VssRayContainer &rays) 
     2036void VspBspViewCellsManager::RefineViewCells(const VssRayContainer &rays, 
     2037                                                                                         const ObjectContainer &objects) 
    20222038{ 
    20232039        Debug << "render time before refine:" << endl; 
     
    20312047 
    20322048        // refining the merged view cells 
    2033         const int refined = mVspBspTree->RefineViewCells(rays); 
     2049        const int refined = mVspBspTree->RefineViewCells(rays, objects); 
    20342050 
    20352051        //-- stats and visualizations 
     
    20522068        } 
    20532069 
    2054          
     2070 
    20552071        // view cells already finished before post processing step (i.e. because they were loaded) 
    20562072        if (mViewCellsFinished) 
     
    20602076                return 0; 
    20612077        } 
    2062          
     2078 
    20632079 
    20642080        // check if new view cells turned invalid 
     
    20712087 
    20722088        Debug << "post processing using " << (int)postProcessRays.size() << " samples" << endl; 
    2073          
     2089 
    20742090        Debug << "\nview cell partition after sampling:\n" << mViewCellsStats << endl << endl; 
    20752091 
     
    20842100        MergeViewCells(postProcessRays, objects); 
    20852101        //-- refines the merged view cells 
    2086         RefineViewCells(postProcessRays); 
     2102        RefineViewCells(postProcessRays, objects); 
    20872103        // collapse sibling leaves that share the same view cell 
    20882104        mVspBspTree->CollapseTree(); 
     
    21742190                                exporter->ExportRays(visRays, RgbColor(0, 1, 0)); 
    21752191                        } 
    2176                          
     2192 
    21772193                        ExportViewCellsForViz(exporter); 
    21782194                        delete exporter; 
     
    22112227 
    22122228                                lm = vm; 
    2213                                          
     2229 
    22142230                                vm.mDiffuseColor.r -= 0.45f; 
    22152231                                vm.mDiffuseColor.g -= 0.45f; 
     
    22262242                                        else 
    22272243                                                exporter->SetForcedMaterial(vm); 
    2228                                          
     2244 
    22292245                                        BspNodeGeometry geom; 
    22302246                                        mVspBspTree->ConstructGeometry(leaf, geom); 
     
    22322248                                } 
    22332249                        } 
    2234                          
     2250 
    22352251                        delete exporter; 
    22362252                } 
     
    24102426                                                                                 ViewCell *vc) const 
    24112427{ 
    2412         if (CheckValidity(vc, mMinPvsSize, mMaxPvsSize) && (mColorCode == 0)) // Random color 
     2428        const bool vcValid = CheckValidity(vc, mMinPvsSize, mMaxPvsSize); 
     2429 
     2430        float importance = 0; 
     2431        static Material m; 
     2432 
     2433        switch (mColorCode) 
     2434        { 
     2435        case 0: // Random 
     2436                { 
     2437                        if (vcValid) 
     2438                        { 
     2439                                m = RandomMaterial(); 
     2440                        } 
     2441                        else 
     2442                        { 
     2443                                m.mDiffuseColor.r = 0.0f; 
     2444                                m.mDiffuseColor.g = 1.0f; 
     2445                                m.mDiffuseColor.b = 0.0f; 
     2446                        } 
     2447                } 
    24132448                return; 
    2414  
    2415         float importance = 0; 
    2416         Material m; 
    2417          
    2418         switch (mColorCode) 
    2419         { 
    24202449        case 1: // pvs 
    24212450                { 
     
    24432472        } 
    24442473 
    2445         m.mDiffuseColor.b = CheckValidity(vc, mMinPvsSize, mMaxPvsSize) ? 1.0f : 0.0f; 
     2474        // special color code for invalid view cells 
    24462475        m.mDiffuseColor.r = importance; 
    24472476        m.mDiffuseColor.g = 1.0f - m.mDiffuseColor.r; 
     2477        m.mDiffuseColor.b = vcValid ? 1.0f : 0.0f; 
    24482478 
    24492479        //Debug << "importance: " << importance << endl; 
     
    25152545{ 
    25162546        ViewCellsParser parser; 
    2517          
     2547 
    25182548        DEL_PTR(mVspBspTree); 
    25192549        mVspBspTree = new VspBspTree(); 
    2520          
     2550 
    25212551        bool success = parser.ParseFile(filename, mVspBspTree, this, objects); 
    25222552        mVspBspTree->RepairViewCellsLeafLists(); 
    25232553        mVspBspTree->mBox = GetViewSpaceBox(); 
    25242554        ResetViewCells(); 
    2525          
     2555 
    25262556        mViewCellsFinished = true; 
    25272557        mMaxPvsSize = (int)objects->size(); 
    25282558 
    25292559        FinalizeViewCells(true); 
    2530          
     2560 
    25312561        Debug << (int)mViewCells.size() << " view cells loaded" << endl; 
    25322562 
     
    25432573bool VspBspViewCellsManager::ExportViewCells(const string filename) 
    25442574{ 
    2545         cout << "exporting view cells to xml ... ";  
     2575        cout << "exporting view cells to xml ... "; 
    25462576        std::ofstream stream; 
    25472577 
     
    25522582        stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"<<endl; 
    25532583        stream << "<Visibility_Solution>" << endl; 
    2554          
     2584 
    25552585        //-- load the view cells itself, i.e., the ids and the pvs 
    25562586        stream << "<ViewCells>" << endl; 
     
    25582588        for (it = mViewCells.begin(); it != it_end; ++ it) 
    25592589                ExportViewCell(*it, stream); 
    2560      
     2590 
    25612591        stream << "</ViewCells>" << endl; 
    2562          
     2592 
    25632593        //-- load the hierarchy 
    25642594        stream << "<BspTree>" << endl; 
    25652595        mVspBspTree->Export(stream); 
    25662596        stream << endl << "</BspTree>" << endl; 
    2567          
     2597 
    25682598        stream << "</Visibility_Solution>" << endl; 
    25692599        stream.close(); 
Note: See TracChangeset for help on using the changeset viewer.