Changeset 570


Ignore:
Timestamp:
01/23/06 18:34:47 (18 years ago)
Author:
mattausch
Message:

construction method for view cells

Location:
trunk/VUT/GtpVisibilityPreprocessor/src
Files:
4 edited

Legend:

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

    r569 r570  
    8888 
    8989 
    90 int ViewCellsManager::Construct(VssRayContainer &rays) 
    91 { 
    92 /*      VssPreprocessor preprocessor; 
    93  
    94         VssRayContainer vssRays; 
    95         preprocessor->GenerateVssRays(mConstructionSamples, vssRays); 
    96         Construct(preprocessor->mObjects, vssRays); 
    97  
    98         // add rays to output rays 
    99         while (!vssRays.empty) 
    100         { 
    101                 rays.push_back(vssRays.back()); 
    102                 vssRays.pop_back(); 
    103         } 
    104  
    105         const int importanceRays = 1000000; 
    106         preprocessor->GenerateVssRays(max(importanceRays, mPostProcessSamples); 
    107  
    108         PostProcess(preprocesor->mObjects, importanceRays); 
     90int ViewCellsManager::Construct(Preprocessor *preprocessor, VssRayContainer *outRays) 
     91{ 
     92        SimpleRayContainer simpleRays; 
     93        VssRayContainer constructionRays; 
     94 
     95        preprocessor->GenerateRays(mConstructionSamples, 
     96                                                           Preprocessor::SPATIAL_BOX_BASED_DISTRIBUTION, 
     97                                                           simpleRays); 
     98 
     99        Construct(preprocessor->mObjects, constructionRays); 
     100 
     101        int numRays = (int)simpleRays.size(); 
     102 
     103        static Ray traversalRay; 
     104 
     105        // shoot simple ray and add it to construction rays 
     106        while (!simpleRays.empty()) 
     107        { 
     108                SimpleRay sray = simpleRays.back(); 
     109 
     110                // TODO: shoot into kdtree 
     111                constructionRays.push_back(new VssRay(traversalRay)); 
     112 
     113                if (outRays) 
     114                        outRays->push_back(constructionRays.back()); 
     115 
     116                simpleRays.pop_back(); 
     117        } 
     118 
     119        if (!outRays) 
     120                CLEAR_CONTAINER(constructionRays); 
     121 
     122        // guided rays 
     123        VssRayContainer importanceRays; 
     124        const int desiredImportanceRays = max(1000000, mPostProcessSamples); 
     125        preprocessor->GenerateRays(desiredImportanceRays, 
     126                                                           Preprocessor::RSS_BASED_DISTRIBUTION, 
     127                                                           simpleRays); 
     128 
     129        numRays += (int)simpleRays.size(); 
     130 
     131        // shoot simple ray and add it to construction rays 
     132        while (!simpleRays.empty()) 
     133        { 
     134                SimpleRay sray = simpleRays.back(); 
     135 
     136                // TODO: shoot into kdtree 
     137                importanceRays.push_back(new VssRay(traversalRay)); 
     138 
     139                if (outRays) 
     140                        outRays->push_back(importanceRays.back()); 
     141 
     142                simpleRays.pop_back(); 
     143        } 
     144 
     145        if (!outRays) 
     146                CLEAR_CONTAINER(importanceRays); 
     147 
     148        // merge the view cells 
     149        PostProcess(preprocessor->mObjects, importanceRays); 
     150 
    109151        Visualize(preprocessor->mObjects, importanceRays); 
    110152 
    111         // add rays to output rays 
    112         while (!importanceRays.empty) 
    113         { 
    114                 rays.push_back(importanceRays.back()); 
    115                 importanceRays.pop_back(); 
    116         } 
    117 */ 
    118         return (int)rays.size(); 
     153 
     154        return numRays; 
    119155} 
    120156 
     
    130166          return false; 
    131167        } 
    132    
     168 
    133169  return true; 
    134170} 
     
    144180void 
    145181ViewCellsManager::SetValidity( 
    146                                                           int minPvsSize,  
     182                                                          int minPvsSize, 
    147183                                                          int maxPvsSize) const 
    148184{ 
    149185  ViewCellContainer::const_iterator it, it_end = mViewCells.end(); 
    150    
     186 
    151187  for (it = mViewCells.begin(); it != it_end; ++ it) { 
    152188        SetValidity(*it, minPvsSize, maxPvsSize); 
     
    161197{ 
    162198  sort(mViewCells.begin(), mViewCells.end(), ViewCell::SmallerPvs); 
    163    
     199 
    164200  int start = mViewCells.size()*minValid; 
    165201  int end = mViewCells.size()*maxValid; 
    166    
     202 
    167203  for (int i=0; i < mViewCells.size(); i++) 
    168204        mViewCells[i]->SetValid(i >= start && i <= end); 
     
    542578} 
    543579 
    544 float 
    545 ViewCellsManager::ComputeSampleContributions(VssRay &ray, 
    546                                                                                          const bool addRays 
    547                                                                                          ) 
    548 { 
    549   ViewCellContainer viewcells; 
    550  
    551   ray.mPvsContribution = 0; 
    552   ray.mRelativePvsContribution = 0.0f; 
    553  
    554  static Ray hray; 
     580float ViewCellsManager::ComputeSampleContributions(VssRay &ray, 
     581                                                                                                   const bool addRays) 
     582{ 
     583        ViewCellContainer viewcells; 
     584 
     585        ray.mPvsContribution = 0; 
     586        ray.mRelativePvsContribution = 0.0f; 
     587 
     588        static Ray hray; 
    555589        hray.Init(ray); 
    556590        //hray.mFlags |= Ray::CULL_BACKFACES; 
     
    567601        CastLineSegment(origin, termination, viewcells); 
    568602        //Debug << "constribution: " << (int)viewcells.size() << endl; 
    569         CastLineSegment(origin, termination, viewcells); 
    570  
    571   //Debug << "constribution: " << (int)viewcells.size() << endl; 
    572  
    573   // copy viewcells memory efficiently 
    574   const bool storeViewcells = !addRays; 
    575  
    576   if (storeViewcells) 
    577   { 
    578         ray.mViewCells.reserve(viewcells.size()); 
    579         ray.mViewCells = viewcells; 
    580   } 
    581  
    582   ViewCellContainer::const_iterator it = viewcells.begin(); 
     603 
     604        // copy viewcells memory efficiently 
     605        const bool storeViewcells = !addRays; 
     606 
     607        if (storeViewcells) 
     608        { 
     609                ray.mViewCells.reserve(viewcells.size()); 
     610                ray.mViewCells = viewcells; 
     611        } 
     612 
     613        ViewCellContainer::const_iterator it = viewcells.begin(); 
    583614 
    584615 
     
    605636          } 
    606637        } 
    607    
    608   return ray.mRelativePvsContribution; 
     638 
     639        return ray.mRelativePvsContribution; 
    609640} 
    610641 
     
    15681599} 
    15691600 
     1601 
    15701602int VspKdViewCellsManager::Construct(const ObjectContainer &objects, 
    15711603                                                                         const VssRayContainer &rays) 
     
    19341966} 
    19351967 
    1936  
    1937  
     1968<<<<<<< .mine 
     1969 
     1970======= 
     1971 
     1972 
     1973>>>>>>> .r569 
    19381974int VspBspViewCellsManager::Construct(const ObjectContainer &objects, 
    19391975                                                                          const VssRayContainer &rays) 
     
    22682304  // validy update in preprocessor for all managers) 
    22692305  return ViewCellsManager::ViewPointValid(viewPoint); 
    2270    
     2306 
    22712307  //    return mViewSpaceBox.IsInside(viewPoint) && 
    22722308  //               mVspBspTree->ViewPointValid(viewPoint); 
     
    25082544                        importance = (float)vc->GetPvs().GetSize() / 
    25092545                                (float)mViewCellsStats.maxPvs; 
     2546 
    25102547                } 
    25112548                break; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h

    r569 r570  
    2626class Exporter; 
    2727class Beam; 
     28class Preprocessor; 
    2829 
    2930struct BspRay; 
     
    5556 
    5657        /** Constructs view cells container taking a preprocessor 
    57                 @returns construction rays. 
    58         */ 
    59         int Construct(VssRayContainer &rays); 
     58                @returns the output rays (if not null) 
     59        */  
     60        int Construct(Preprocessor *preprocessor, VssRayContainer *outRays = NULL); 
    6061 
    6162        /** Constructs view cell container with a given number of samples. 
     
    411412                                  const VssRayContainer &rays); 
    412413 
    413  
    414414        int PostProcess(const ObjectContainer &objects,  
    415415                                        const VssRayContainer &rays); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp

    r568 r570  
    19801980                                bool isAdjacent = true; 
    19811981 
    1982                         /*      if (1) 
     1982                                if (1) 
    19831983                                { 
    19841984                                        // test all planes of current node if still adjacent 
     
    20142014                                                } 
    20152015                                        } 
    2016                                 }*/ 
     2016                                } 
    20172017                                // neighbor was found 
    20182018                                if (isAdjacent) 
     
    31153115        queue<BspMergeCandidate> *backQueue = &queue2; 
    31163116 
    3117 #if 1 
    3118     Exporter *exporter = Exporter::GetExporter("neighors.x3d"); 
    3119  
    3120         if (exporter) 
    3121         { 
    3122                 cout << "exporting neighbors ... "; 
    3123                 exporter->ExportGeometry(objects); 
    3124         } 
    3125  
    3126         // HACK for visualization 
    3127         //ViewCellContainer viewCells; 
    3128         //ViewCell::NewMail(); 
    3129         //CollectViewCells(mRoot, true, viewCells, true); 
    3130         //for (int i = 0; i < viewCells.size(); ++i) 
    3131         //      viewCells[i]->SetId((int)RandomValue(0, Real(256*256*256))); 
    3132          
    3133          
    31343117        while (!mMergeQueue.empty()) 
    31353118        { 
     
    31373120                shuffleQueue->push(mc); 
    31383121                mMergeQueue.pop(); 
    3139  
    3140                 // visualize neighbors 
    3141                 Material m = RandomMaterial(); 
    3142                 exporter->SetForcedMaterial(m); 
    3143          
    3144  
    3145                 if (!mc.GetLeaf1()->Mailed()) 
    3146                 { 
    3147                         BspNodeGeometry geom1; 
    3148                         ConstructGeometry(mc.GetLeaf1(), geom1); 
    3149                         //m.mDiffuseColor.r = (mc.GetLeaf1()->GetViewCell()->GetId() & 256)/ 255.0f; 
    3150                         //m.mDiffuseColor.g = ((mc.GetLeaf1()->GetViewCell()->GetId()>>8) & 256)/ 255.0f; 
    3151                         //m.mDiffuseColor.b = ((mc.GetLeaf1()->GetViewCell()->GetId()>>16) & 256)/ 255.0f; 
    3152                         //exporter->SetForcedMaterial(m); 
    3153                         exporter->ExportPolygons(geom1.mPolys); 
    3154                         mc.GetLeaf1()->Mail(); 
    3155                 } 
    3156  
    3157                 if (!mc.GetLeaf2()->Mailed()) 
    3158                 { 
    3159                         BspNodeGeometry geom2; 
    3160                         ConstructGeometry(mc.GetLeaf2(), geom2); 
    3161                         //m.mDiffuseColor.r = (mc.GetLeaf2()->GetViewCell()->GetId() & 256)/ 255.0f; 
    3162                         //m.mDiffuseColor.g = ((mc.GetLeaf2()->GetViewCell()->GetId()>>8) & 256)/ 255.0f; 
    3163                         //m.mDiffuseColor.b = ((mc.GetLeaf2()->GetViewCell()->GetId()>>16) & 256)/ 255.0f; 
    3164                         //exporter->SetForcedMaterial(m); 
    3165                         exporter->ExportPolygons(geom2.mPolys); 
    3166                         mc.GetLeaf2()->Mail(); 
    3167                 }                
    3168         } 
    3169  
    3170         if (exporter) 
    3171         { 
    3172                 cout << "finished" << endl; 
    3173                 delete exporter; 
    3174         } 
    3175 #else 
    3176         while (!mMergeQueue.empty()) 
    3177         { 
    3178                 BspMergeCandidate mc = mMergeQueue.top(); 
    3179                 shuffleQueue->push(mc); 
    3180                 mMergeQueue.pop(); 
    3181         } 
    3182 #endif 
     3122        } 
     3123 
    31833124        const int numPasses = 5; 
    31843125        int pass = 0; 
     
    32573198        //const int pvs1 = SubtractedPvsSize(vc1, leaf, *leaf->mPvs); 
    32583199        const int pvs1 = SubtractedPvsSize(vc1->GetPvs(), *leaf->mPvs); 
    3259          
    32603200        const int pvs2 = AddedPvsSize(vc2->GetPvs(), *leaf->mPvs); 
    32613201 
     
    32773217        } 
    32783218 
    3279         const float cost1 = (float)pvs1 * p1; 
    3280         const float cost2 = (float)pvs2 * p2; 
     3219        const float cost1 = (float)pvs1;// * p1; 
     3220        const float cost2 = (float)pvs2;// * p2; 
    32813221 
    32823222        return cost1 + cost2; 
     
    33303270        BspViewCell *vc2 = leaf2->GetViewCell(); 
    33313271 
    3332         float cost1;  
    3333         float cost2;  
    3334  
    3335         if (mUseAreaForPvs) 
     3272        float cost1 = vc1->GetPvs().GetSize();  
     3273        float cost2 = vc2->GetPvs().GetSize();  
     3274 
     3275        /*if (mUseAreaForPvs) 
    33363276        { 
    33373277                cost1 = vc1->GetPvs().GetSize() * vc1->GetArea(); 
     
    33423282                cost1 = vc1->GetPvs().GetSize() * vc1->GetVolume(); 
    33433283                cost2 = vc2->GetPvs().GetSize() * vc2->GetVolume(); 
    3344         } 
     3284        }*/ 
    33453285 
    33463286        const float oldCost = cost1 + cost2; 
     
    34503390} 
    34513391 
     3392 
    34523393/************************************************************************/ 
    34533394/*                BspMergeCandidate implementation                      */ 
  • trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp

    r556 r570  
    2121#define USE_EXE_PATH false 
    2222 
    23  
     23#include <crtdbg.h> 
    2424 
    2525 
     
    2828main(int argc, char **argv) 
    2929{ 
     30         
     31//Now just call this function at the start of your program and if you're 
     32//compiling in debug mode (F5), any leaks will be displayed in the Output 
     33//window when the program shuts down. If you're not in debug mode this will 
     34//be ignored. Use it as you will! 
     35//note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() { 
     36    _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF); 
     37    _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE); 
     38    _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR);  
     39 
    3040  Debug.open("debug.log"); 
    3141  environment = new Environment; 
Note: See TracChangeset for help on using the changeset viewer.