Changeset 574


Ignore:
Timestamp:
01/25/06 01:44:46 (18 years ago)
Author:
mattausch
Message:

finished function for view cell construction
removed bsp rays from vspbspmanager

Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env

    r573 r574  
    3030VssPreprocessor { 
    3131        samplesPerPass  100000 
    32         initialSamples 6000000 
     32        initialSamples 0 
    3333        vssSamples 0 
    3434        vssSamplesPerPass 500000 
     
    7878RssPreprocessor { 
    7979        samplesPerPass  100000 
    80         initialSamples 500000 
    81         vssSamples 10000000 
     80        #initialSamples 500000 
     81        #vssSamples 10000000 
     82        #for view cell construction 
     83        initialSamples 0 
     84        vssSamples 0 
    8285        vssSamplesPerPass 500000 
    8386        useImportanceSampling true 
     
    171174 
    172175ViewCells { 
     176        # samples used for view cell construction 
     177        Construction { 
     178                samples 5000000 
     179                samplesPerPass 500000 
     180        } 
     181         
    173182        loadFromFile false 
    174183        exportToFile false 
     
    196205        Visualization { 
    197206                # how much samples we use for visualization 
    198                 samples 5000 
     207                samples 100000 
    199208                #colorCode PVS 
    200209                #colorCode MergedLeaves 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp

    r564 r574  
    12061206                        "bspTree"); 
    12071207 
     1208        RegisterOption("ViewCells.Construction.samples", 
     1209                                        optInt, 
     1210                                        "view_cells_construction_samples=", 
     1211                                        "5000000"); 
     1212 
     1213        RegisterOption("ViewCells.Construction.samplesPerPass", 
     1214                                        optInt, 
     1215                                        "view_cells_construction_samples_per_pass=", 
     1216                                        "500000"); 
     1217 
    12081218        RegisterOption("ViewCells.PostProcess.samples", 
    12091219                                        optInt, 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp

    r544 r574  
    77Polygon3::Polygon3():  
    88mMaterial(NULL), mParent(NULL), mPiercingRays(0) 
    9 {} 
     9{ 
     10        // mostly there will be triangles 
     11        //mVertices.reserve(3); 
     12} 
    1013 
    1114Polygon3::Polygon3(const VertexContainer &vertices):  
    12 mVertices(vertices), mMaterial(NULL), mParent(NULL), mPiercingRays(0) 
    13 {} 
     15mMaterial(NULL), mParent(NULL), mPiercingRays(0) 
     16{ 
     17        mVertices.reserve(vertices.size()); 
     18        mVertices = vertices; 
     19} 
     20 
    1421 
    1522Polygon3::Polygon3(MeshInstance *parent):  
     
    1724{} 
    1825 
     26 
    1927Polygon3::Polygon3(Face *face, Mesh *parentMesh): 
    2028mMaterial(NULL), mParent(NULL), mPiercingRays(0) 
    2129{        
     30        mVertices.reserve(face->mVertexIndices.size()); 
     31         
    2232        VertexIndexContainer::iterator it = face->mVertexIndices.begin(); 
    2333        for (; it != face->mVertexIndices.end();  ++it) 
    2434        { 
    2535                mVertices.push_back(parentMesh->mVertices[*it]); 
    26                 mMaterial = parentMesh->mMaterial; 
    27         } 
    28 } 
     36        } 
     37 
     38        mMaterial = parentMesh->mMaterial; 
     39} 
     40 
    2941 
    3042Plane3 Polygon3::GetSupportingPlane() const 
     
    3244        return Plane3(mVertices[0], mVertices[1], mVertices[2]); 
    3345} 
     46 
    3447 
    3548Vector3 Polygon3::GetNormal() const  
     
    113126} 
    114127 
     128 
    115129float Polygon3::GetArea() const 
    116130{ 
     
    123137} 
    124138 
     139 
    125140int Polygon3::Side(const Plane3 &plane,  
    126141                                   const float epsilon) const 
     
    136151} 
    137152 
     153 
    138154int Polygon3::ClassifyPlane(const Plane3 &plane,  
    139155                                                        const float epsilon) const 
    140156{ 
    141         VertexContainer::const_iterator it; 
     157        VertexContainer::const_iterator it, it_end = mVertices.end(); 
    142158 
    143159        bool onFrontSide = false; 
     
    146162        int count = 0; 
    147163        // find possible line-plane intersections 
    148         for (it = mVertices.begin(); it != mVertices.end(); ++ it) 
     164        for (it = mVertices.begin(); it != it_end; ++ it) 
    149165        { 
    150166                const int side = plane.Side(*it, epsilon); 
     
    179195} 
    180196 
    181 /*int Polygon3::ClassifyPlane(const Plane3 &plane) const 
    182 { 
    183         return ClassifyPlane(plane, Limits::Small); 
    184 }*/ 
    185  
    186197 
    187198Vector3 
     
    212223                return false; 
    213224 
    214 #if 1 
    215         // check if area exceeds certain size 
    216         if (AREA_LIMIT > GetArea()) 
    217         { 
    218                 //Debug << "area too small: " << GetArea() << endl; 
    219                 return false; 
    220         } 
    221 #else 
    222         Vector3 vtx = mVertices.back(); 
    223         VertexContainer::const_iterator it, it_end = mVertices.end(); 
    224  
    225         for (it = mVertices.begin(); it != it_end; ++it) 
    226         { 
    227                 if (!(EpsilonEqual(vtx, *it))) 
    228                 { 
    229                         //Debug << "Malformed vertices:\n" << *this << endl; 
     225        //TODO: remove for performance 
     226#if 0 
     227        if (1) 
     228        { 
     229                // check if area exceeds certain size 
     230                if (GetArea() < AREA_LIMIT) 
     231                { 
     232                        Debug << "area too small: " << GetArea() << endl; 
    230233                        return false; 
    231234                } 
    232                 vtx = *it; 
    233         } 
    234 #endif   
     235        } 
     236        else 
     237        { 
     238                Vector3 vtx = mVertices.back(); 
     239                VertexContainer::const_iterator it, it_end = mVertices.end(); 
     240 
     241                for (it = mVertices.begin(); it != it_end; ++it) 
     242                { 
     243                        if (!(EpsilonEqualV3(vtx, *it))) 
     244                        { 
     245                                //Debug << "Malformed vertices:\n" << *this << endl; 
     246                                return false; 
     247                        } 
     248                        vtx = *it; 
     249                } 
     250        } 
     251#endif 
     252 
    235253        return true; 
    236254} 
     255 
    237256 
    238257void Polygon3::IncludeInBox(const PolygonContainer &polys, AxisAlignedBox3 &box) 
     
    243262                box.Include(*(*it)); 
    244263} 
     264 
    245265 
    246266// int_lineseg returns 1 if the given line segment intersects a 2D 
     
    283303} 
    284304 
     305 
    285306int Polygon3::CastRay(const Ray &ray, float &t, const float nearestT) 
    286307{ 
     
    353374        return (count & 1) ? Ray::INTERSECTION : Ray::NO_INTERSECTION; 
    354375} 
     376 
    355377 
    356378void Polygon3::InheritRays(Polygon3 &front_piece,  
     
    385407} 
    386408 
     409 
    387410int Polygon3::ClassifyPlane(const PolygonContainer &polys,  
    388411                                                        const Plane3 &plane, 
     
    422445} 
    423446 
     447 
    424448int Polygon3::ParentObjectsSize(const PolygonContainer &polys) 
    425449{ 
     
    441465} 
    442466 
     467 
    443468float Polygon3::GetArea(const PolygonContainer &cell) 
    444469{ 
     
    448473        for (pit = cell.begin(); pit != cell.end(); ++ pit) 
    449474        { 
    450                 if ((*pit)->mVertices.size() < 3) 
    451                         Debug << "ERROR" << endl; 
    452  
    453475                area += (*pit)->GetArea(); 
    454476        } 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h

    r508 r574  
    150150        static int ParentObjectsSize(const PolygonContainer &polys); 
    151151 
     152        /** Area of the accumulated polygons. 
     153        */ 
    152154        static float GetArea(const PolygonContainer &cell); 
    153155}; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp

    r567 r574  
    194194        environment->GetStringValue("ViewCells.type", viewCellsStr); 
    195195 
    196         int constructionSamples = 0; 
     196        int initialSamples = 0; 
    197197         
    198198        if (strcmp(viewCellsStr, "kdTree") == 0) 
     
    206206                Debug << "view cell type: Bsp" << endl; 
    207207 
    208                 environment->GetIntValue("BspTree.Construction.samples", constructionSamples); 
    209                 mViewCellsManager = new BspViewCellsManager(mBspTree, constructionSamples); 
     208                mViewCellsManager = new BspViewCellsManager(mBspTree); 
    210209        } 
    211210        else if (strcmp(viewCellsStr, "vspBspTree") == 0) 
     
    215214                Debug << "view cell type: VspBsp" << endl; 
    216215 
    217                 environment->GetIntValue("VspBspTree.Construction.samples", constructionSamples); 
    218                 mViewCellsManager = new VspBspViewCellsManager(mVspBspTree, constructionSamples); 
     216                mViewCellsManager = new VspBspViewCellsManager(mVspBspTree); 
    219217        } 
    220218        else if (strcmp(viewCellsStr, "vspKdTree") == 0) 
     
    222220                mVspKdTree = new VspKdTree();            
    223221         
    224                 environment->GetIntValue("VspKdTree.Construction.samples", constructionSamples); 
    225         mViewCellsManager = new VspKdViewCellsManager(mVspKdTree, constructionSamples); 
     222                mViewCellsManager = new VspKdViewCellsManager(mVspKdTree); 
    226223        } 
    227224        else if (strcmp(viewCellsStr, "sceneDependent") == 0) 
     
    231228 
    232229                Debug << "view cell type: Bsp" << endl; 
    233                 environment->GetIntValue("BspTree.Construction.samples", constructionSamples); 
    234                 mViewCellsManager = new BspViewCellsManager(mBspTree, constructionSamples); 
     230                 
     231                mViewCellsManager = new BspViewCellsManager(mBspTree); 
    235232        } 
    236233        else 
     
    248245        mRenderSimulator =  
    249246                new RenderSimulator(mViewCellsManager, objRenderCost, vcOverhead, moveSpeed); 
    250          
    251         int postProcessSamples = 0; 
    252         int visSamples = 0; 
    253  
    254         environment->GetIntValue("ViewCells.PostProcess.samples", postProcessSamples); 
    255         environment->GetIntValue("ViewCells.Visualization.samples", visSamples); 
    256  
    257         mViewCellsManager->SetPostProcessSamples(postProcessSamples); 
    258         mViewCellsManager->SetVisualizationSamples(visSamples); 
     247 
    259248        mViewCellsManager->SetRenderer(mRenderSimulator); 
    260249 
    261          
    262250        //-- parse view cells construction method 
    263251        environment->GetBoolValue("ViewCells.loadFromFile", mLoadViewCells); 
    264252        char buf[100]; 
     253 
    265254        if (mLoadViewCells) 
    266255        { 
  • trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp

    r564 r574  
    2424                << avgRtWithoutOverhead << "\n"; 
    2525         
     26        app << "#VALID_MAX_COST ( maximal cost of a valid view cell )\n" << validMaxCost << "\n"; 
     27 
     28        app << "#VALID_MIN_COST ( minimal cost of a valid view cell )\n" << validMinCost << "\n"; 
     29 
     30        app << "#VALID_AVG_RENDER_TIME ( average render time )\n" << validAvgRenderTime << "\n"; 
     31 
     32        app << "#VALID_AVG_RENDER_TIME_NO_OVERHEAD ( valid average render time without overhead )\n"  
     33                << validAvgRtWithoutOverhead << "\n"; 
     34         
    2635        app << "===== END OF Render Simulation statistics ==========\n"; 
    2736} 
     
    3140mObjRenderCost(0.0f),  
    3241mVcOverhead(0.0f),  
    33 mMoveSpeed(0.0f), 
    34 mOnlyValid(false) 
     42mMoveSpeed(0.0f) 
    3543{} 
    3644 
     
    4351mObjRenderCost(objRenderCost),  
    4452mVcOverhead(vcOverhead),  
    45 mMoveSpeed(moveSpeed), 
    46 mOnlyValid(false) 
     53mMoveSpeed(moveSpeed) 
    4754{ 
    4855} 
     
    5562 
    5663 
    57 void RenderSimulator::SetRenderOnlyValid(const bool renderOnlyValid) 
    58 { 
    59         mOnlyValid = renderOnlyValid; 
    60 } 
    61  
    62  
    6364void RenderSimulator::SetVcOverhead(const float vcOverhead) 
    6465{ 
     
    6667} 
    6768 
     69 
    6870void RenderSimulator::SetMoveSpeed(const float moveSpeed) 
    6971{ 
    7072        mMoveSpeed = moveSpeed; 
    7173} 
     74 
    7275 
    7376bool RenderSimulator::RenderScene() 
     
    7780 
    7881        Real renderTime = 0; 
    79          
     82        Real validRenderTime = 0; 
     83 
    8084        // overhead for loading the PVS of the view cells 
    8185        float loadPvsOverhead = 0; 
    82          
     86        float validLoadPvsOverhead = 0; 
     87 
    8388        ViewCellContainer::const_iterator it,  
    8489                it_end = mViewCellsManager->GetViewCells().end(); 
     
    8994                ViewCell *vc = *it; 
    9095 
    91                 if (mOnlyValid && !vc->GetValid()) 
    92                         continue; 
     96                const bool valid = !vc->GetValid(); 
     97         
    9398 
    9499                // probability of view cell 
     
    103108                // speed and the probability that a view cell border is crossed 
    104109                loadPvsOverhead += GetCrossVcProbability() * mVcOverhead; 
    105  
    106                 //Debug << "vccost: " << vcCost << " p in vc " << pInVc 
    107                 //<< " cross vc " << GetCrossVcProbability() << endl; 
     110                renderTime += vcCost; 
    108111 
    109112                //-- update statistics 
    110                 renderTime += vcCost; 
    111          
     113 
    112114                if (vcCost > mSimulationStatistics.maxCost) 
    113115                        mSimulationStatistics.maxCost = vcCost; 
    114116                else if (vcCost < mSimulationStatistics.minCost) 
    115117                        mSimulationStatistics.minCost = vcCost; 
     118 
     119                //-- different statistics for only valid view cells 
     120                if (valid) 
     121                { 
     122                        validLoadPvsOverhead += GetCrossVcProbability() * mVcOverhead; 
     123                        validRenderTime += vcCost; 
     124                 
     125                        if (vcCost > mSimulationStatistics.validMaxCost) 
     126                                mSimulationStatistics.validMaxCost = vcCost; 
     127                        else if (vcCost < mSimulationStatistics.validMinCost) 
     128                                mSimulationStatistics.validMinCost = vcCost; 
     129                } 
    116130        } 
    117131         
    118132        mSimulationStatistics.avgRtWithoutOverhead = renderTime; 
    119133        mSimulationStatistics.avgRenderTime = renderTime + loadPvsOverhead; 
     134 
     135        mSimulationStatistics.validAvgRtWithoutOverhead = renderTime; 
     136        mSimulationStatistics.validAvgRenderTime = renderTime + loadPvsOverhead; 
    120137         
    121138        mSimulationStatistics.Stop(); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.h

    r564 r574  
    1919        float avgRtWithoutOverhead; 
    2020   
     21        //-- options counting only valid view cells 
     22 
     23        /// view cell with the biggest "cost" 
     24        float validMaxCost; 
     25        /// view cell with the minimal "cost" 
     26    float validMinCost; 
     27        /// average render time 
     28        float validAvgRenderTime; 
     29        /// average render time with the overhead when crossing view cells 
     30        float validAvgRtWithoutOverhead; 
     31 
    2132        void Reset()  
    2233        { 
     
    2536                avgRenderTime = 0; 
    2637                avgRtWithoutOverhead = 0; 
     38 
     39                validMaxCost = 0; 
     40                validMinCost = 999999; 
     41                validAvgRenderTime = 0; 
     42                validAvgRtWithoutOverhead = 0; 
    2743        } 
    2844 
     
    99115        /// Simulation statistics 
    100116        SimulationStatistics mSimulationStatistics; 
    101  
    102         /// if only valid view space should be rendered 
    103         bool mOnlyValid; 
    104117}; 
    105118 
  • trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp

    r572 r574  
    441441 
    442442  } 
     443  else 
     444  { 
     445          // construct view cells using it's own set of samples 
     446          mViewCellsManager->Construct(this); 
     447 
     448          //-- several visualizations and statistics 
     449          Debug << "view cells after construction: " << endl; 
     450          mViewCellsManager->PrintStatistics(Debug); 
     451  } 
    443452   
    444453  int rssPass = 0; 
     
    476485         
    477486  if (mUseViewcells) { 
    478         // construct view cells 
    479         if (!mLoadViewCells) 
    480           mViewCellsManager->Construct(mObjects, mVssRays); 
    481  
    482          
    483487 
    484488        // evaluate contributions of the intitial rays 
    485         mViewCellsManager->ComputeSampleContributions(mVssRays); 
     489        mViewCellsManager->ComputeSampleContributions(mVssRays, true, false); 
    486490         
    487491         
     
    502506        mViewCellsManager->PrintPvsStatistics(mStats); 
    503507           
    504         VssRayContainer selectedRays; 
    505         int desired = Max( 
    506                                           mViewCellsManager->GetPostProcessSamples(), 
    507                                           mViewCellsManager->GetVisualizationSamples()); 
    508          
    509         mVssRays.SelectRays(desired, selectedRays); 
    510            
    511         //-- post process view cells 
    512         mViewCellsManager->PostProcess(mObjects, selectedRays); 
    513            
    514         //-- several visualizations and statistics 
    515         Debug << "view cells after post processing: " << endl; 
    516         mViewCellsManager->PrintStatistics(Debug); 
    517          
    518         if (1)  
    519           mViewCellsManager->Visualize(mObjects, selectedRays); 
    520  
    521508        // viewcells->UpdatePVS(newVssRays); 
    522509        Debug<<"Valid viewcells before set validity: "<<mViewCellsManager->CountValidViewcells()<<endl; 
     
    534521   
    535522  /// compute view cell contribution of rays if view cells manager already constructed 
    536   mViewCellsManager->ComputeSampleContributions(mVssRays); 
     523  mViewCellsManager->ComputeSampleContributions(mVssRays, true, false); 
    537524 
    538525  if (mUseImportanceSampling) { 
     
    571558          CastRays(rays, tmpVssRays); 
    572559          castRays += rays.size(); 
    573           float c1 = mViewCellsManager->ComputeSampleContributions(tmpVssRays, false); 
     560          float c1 = mViewCellsManager->ComputeSampleContributions(tmpVssRays, false, true); 
    574561          mStats<<"#RssRelContrib"<<endl<<c1/rays.size()<<endl; 
    575562 
     
    582569                CastRays(rays, tmpVssRays); 
    583570                castRays += rays.size(); 
    584                 float c2 = mViewCellsManager->ComputeSampleContributions(tmpVssRays, false); 
     571                float c2 = mViewCellsManager->ComputeSampleContributions(tmpVssRays, false, true); 
    585572                mStats<<"#SpatialRelContrib"<<endl<<c2/rays.size()<<endl; 
    586573                 
     
    596583                CastRays(rays, tmpVssRays); 
    597584                castRays += rays.size(); 
    598                 float c3 = mViewCellsManager->ComputeSampleContributions(tmpVssRays, false); 
     585                float c3 = mViewCellsManager->ComputeSampleContributions(tmpVssRays, false, true); 
    599586                mStats<<"#DirectionalRelContrib"<<endl<<c3/rays.size()<<endl; 
    600587                 
     
    622609          if (mUseViewcells) { 
    623610                /// compute view cell contribution of rays 
    624                 mViewCellsManager->ComputeSampleContributions(vssRays); 
     611                mViewCellsManager->ComputeSampleContributions(vssRays, true, false); 
    625612          } 
    626613                 
     
    646633          mViewCellsManager->PrintPvsStatistics(mStats); 
    647634        } 
    648  
    649  
     635         
    650636        ComputeRenderError(); 
    651637         
     
    709695  if (mUseViewcells) { 
    710696 
    711          
    712         //-- render simulation after merge 
    713         cout << "\nevaluating bsp view cells render time after merge ... "; 
    714          
    715         mRenderSimulator->RenderScene(); 
    716         SimulationStatistics ss; 
    717         mRenderSimulator->GetStatistics(ss); 
    718          
    719         cout << " finished" << endl; 
    720         cout << ss << endl; 
    721         Debug << ss << endl; 
     697          if(0) 
     698          { 
     699                  VssRayContainer selectedRays; 
     700                  int desired = mViewCellsManager->GetVisualizationSamples(); 
     701 
     702                  mVssRays.SelectRays(desired, selectedRays); 
     703 
     704                  mViewCellsManager->Visualize(mObjects, selectedRays); 
     705          } 
     706           
     707          // view cells after sampling 
     708          mViewCellsManager->PrintStatistics(Debug); 
     709       
     710          //-- render simulation after merge 
     711          cout << "\nevaluating bsp view cells render time after sampling ... "; 
     712           
     713          mRenderSimulator->RenderScene(); 
     714          SimulationStatistics ss; 
     715          mRenderSimulator->GetStatistics(ss); 
     716           
     717          cout << " finished" << endl; 
     718          cout << ss << endl; 
     719          Debug << ss << endl; 
    722720         
    723721  } 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r563 r574  
    6767  } 
    6868   
    69   mViewCellsManager->ComputeSampleContributions(vssRays, true); 
     69  mViewCellsManager->ComputeSampleContributions(vssRays, true, false); 
    7070  CLEAR_CONTAINER(vssRays); 
    7171} 
     
    7878        VssRay vssRay(ray); 
    7979 
    80         mViewCellsManager->ComputeSampleContributions(vssRay); 
     80        mViewCellsManager->ComputeSampleContributions(vssRay, true, false); 
    8181         
    8282        return vssRay.mPvsContribution; 
     
    384384        // construct view cells if not already constructed 
    385385        if (!mViewCellsManager->ViewCellsConstructed()) 
    386           mViewCellsManager->Construct(mObjects, mVssSampleRays); 
     386          mViewCellsManager->ConstructSubdivision(mObjects, mVssSampleRays); 
    387387 
    388388        // $$JB temporary removed 
     
    394394 
    395395        //-- render simulation after merge 
    396         cout << "\nevaluating bsp view cells render time after merge ... "; 
    397                   
    398          //-- render simulation after merge 
    399396        cout << "\nevaluating bsp view cells render time after merge ... "; 
    400397         
     
    434431                { 
    435432                  // construct view cells 
    436                   mViewCellsManager->Construct(objects, mVssSampleRays); 
     433                  mViewCellsManager->ConstructSubdivision(objects, mVssSampleRays); 
    437434                   
    438435                  // throw away samples  
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r573 r574  
    314314        Debug << "splitting polygons of node " << this << " with plane " << mPlane << endl; 
    315315#endif 
    316         while (!polys.empty()) 
    317         { 
    318                 Polygon3 *poly = polys.back(); 
    319                 polys.pop_back(); 
    320  
     316        PolygonContainer::const_iterator it, it_end = polys.end(); 
     317 
     318        for (it = polys.begin(); it != polys.end(); ++ it)       
     319        { 
     320                Polygon3 *poly = *it; 
     321         
    321322                //-- classify polygon 
    322323                const int cf = poly->ClassifyPlane(plane, mEpsilon); 
     
    25382539BspNodeGeometry::BspNodeGeometry(const BspNodeGeometry &rhs) 
    25392540{ 
     2541        mPolys.reserve(rhs.mPolys.size()); 
     2542         
    25402543        PolygonContainer::const_iterator it, it_end = rhs.mPolys.end(); 
    25412544        for (it = rhs.mPolys.begin(); it != it_end; ++ it) 
     
    25452548        } 
    25462549} 
     2550 
    25472551 
    25482552BspNodeGeometry::~BspNodeGeometry() 
     
    27002704} 
    27012705 
     2706 
    27022707Polygon3 *BspNodeGeometry::SplitPolygon(Polygon3 *planePoly, 
    27032708                                                                                const float epsilon) const 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r547 r574  
    2929        BspNodeGeometry(const BspNodeGeometry &rhs); 
    3030 
     31        //BspNodeGeometry(const PolygonContainer &polys); 
     32 
    3133        ~BspNodeGeometry(); 
    3234 
     
    6769        PolygonContainer mPolys; 
    6870}; 
     71 
    6972 
    7073/** Data structure used for optimized ray casting. 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp

    r573 r574  
    2020ViewCellsManager::ViewCellsManager(): 
    2121mRenderer(NULL), 
     22mInitialSamples(0), 
    2223mConstructionSamples(0), 
    2324mPostProcessSamples(0), 
     
    3536 
    3637 
    37 ViewCellsManager::ViewCellsManager(int constructionSamples): 
    38 mConstructionSamples(constructionSamples), 
    39 mRenderer(NULL), 
    40 mPostProcessSamples(0), 
    41 mVisualizationSamples(0), 
    42 mTotalAreaValid(false), 
    43 mTotalArea(0.0f), 
    44 mViewCellsFinished(false), 
    45 mMaxPvsSize(9999999), 
    46 mMinPvsSize(0), // one means only empty view cells are invalid 
    47 mMaxPvsRatio(1.0) 
    48 { 
    49         mViewSpaceBox.Initialize(); 
    50         ParseEnvironment(); 
    51 } 
    52  
    53  
    5438void ViewCellsManager::ParseEnvironment() 
    5539{ 
     
    6145        environment->GetBoolValue("ViewCells.pruneEmptyViewCells", emptyViewCells); 
    6246        environment->GetBoolValue("ViewCells.processOnlyValidViewCells", mOnlyValidViewCells); 
     47 
     48        environment->GetIntValue("ViewCells.Construction.samples", mConstructionSamples); 
     49        environment->GetIntValue("ViewCells.PostProcess.samples", mPostProcessSamples); 
     50        environment->GetIntValue("ViewCells.Visualization.samples", mVisualizationSamples); 
     51 
     52        environment->GetIntValue("ViewCells.Construction.samplesPerPass", mSamplesPerPass); 
    6353 
    6454        mMinPvsSize = emptyViewCells ? 1 : 0; 
     
    8878 
    8979 
    90 int ViewCellsManager::CastPassSamples(int samplesPerPass,  
    91                                                                           int sampleType,  
    92                                                                           VssRayContainer *outRays) const 
    93 { 
    94         VssRayContainer passSamples; 
     80int ViewCellsManager::CastPassSamples(const int samplesPerPass,  
     81                                                                          const int sampleType,  
     82                                                                          VssRayContainer &passSamples) const 
     83{ 
    9584        SimpleRayContainer simpleRays; 
    9685 
     
    10291        preprocessor->CastRays(simpleRays, passSamples); 
    10392 
    104         const int numSamples = (int)passSamples.size(); 
    105  
     93        return (int)passSamples.size(); 
     94} 
     95 
     96 
     97/// helper function which destroys rays or copies them into the output ray container 
     98inline void addOutRays(VssRayContainer &rays, VssRayContainer *outRays) 
     99{ 
     100        cout << "disposing samples ... "; 
    106101        if (outRays) 
    107102        { 
    108                 while (!passSamples.empty()) 
    109                         outRays->push_back(passSamples.back()); 
     103                VssRayContainer::const_iterator it, it_end = rays.end(); 
     104 
     105                for (it = rays.begin(); it != it_end; ++ it) 
     106                { 
     107                        outRays->push_back(*it); 
     108                } 
    110109        } 
    111110        else 
    112111        { 
    113                 CLEAR_CONTAINER(passSamples); 
    114         } 
    115  
    116         return numSamples; 
     112                CLEAR_CONTAINER(rays); 
     113        } 
     114        cout << "finished" << endl; 
    117115} 
    118116 
     
    123121        SimpleRayContainer simpleRays; 
    124122         
    125         VssRayContainer constructionSamples; 
    126  
     123        VssRayContainer initialSamples; 
     124 
     125        cout << "view cell construction: casting " << mInitialSamples << " initial samples ... "; 
    127126        //-- construction rays => we use uniform samples for this 
    128         CastPassSamples(mConstructionSamples,  
    129                                         Preprocessor::SPATIAL_BOX_BASED_DISTRIBUTION,  
    130                                         &constructionSamples); 
     127        CastPassSamples(mInitialSamples,  
     128                                        Preprocessor::DIRECTION_BASED_DISTRIBUTION, 
     129                                        //Preprocessor::SPATIAL_BOX_BASED_DISTRIBUTION,  
     130                                        initialSamples); 
    131131         
     132        cout << "finished" << endl; 
     133 
    132134        // construct view cells 
    133         const int initialSamples = Construct(preprocessor->mObjects, constructionSamples); 
    134  
    135         numSamples += initialSamples; 
    136  
    137         if (outRays) 
    138         { 
    139                 while (!constructionSamples.empty()) 
    140                         outRays->push_back(constructionSamples.back()); 
    141         } 
    142         else 
    143         { 
    144                 CLEAR_CONTAINER(constructionSamples); 
    145         } 
    146  
     135        const int numInitialSamples =  
     136                ConstructSubdivision(preprocessor->mObjects, initialSamples); 
     137 
     138        numSamples += numInitialSamples; 
     139 
     140        // rays can be passed or deleted 
     141        addOutRays(initialSamples, outRays); 
     142         
    147143 
    148144        //-- guided rays are used for further sampling 
    149         const int desiredImportanceSamples = 5000000; 
    150         const int importanceRayPerPass = 1000000; 
    151  
    152         const int n = desiredImportanceSamples; //+initialSamples; 
     145        const int n = mConstructionSamples; //+initialSamples; 
     146 
     147        bool dirSamples = false; 
    153148 
    154149        while (numSamples < n) 
    155150        { 
    156                 numSamples += CastPassSamples(importanceRayPerPass,  
    157                                                                           Preprocessor::RSS_BASED_DISTRIBUTION,  
    158                                                                           //Preprocessor::SPATIAL_BOX_BASED_DISTRIBUTION, 
    159                                                                           outRays); 
     151                cout << "casting " << mSamplesPerPass << " samples ... "; 
     152                VssRayContainer constructionSamples; 
     153 
     154                const int samplingType =  
     155                        dirSamples ?  
     156                                                Preprocessor::DIRECTION_BASED_DISTRIBUTION : 
     157                                                Preprocessor::SPATIAL_BOX_BASED_DISTRIBUTION; 
     158 
     159                dirSamples = !dirSamples; // toggle sampling 
     160                numSamples += CastPassSamples(mSamplesPerPass,  
     161                                                                          samplingType, 
     162                                                                          constructionSamples); 
     163 
     164                cout << "finished" << endl; 
     165 
     166                cout << "computing sample contribution for " << (int)constructionSamples.size() << " samples ... "; 
     167 
     168                // TODO: leak? 
     169                ComputeSampleContributions(constructionSamples, true, false); 
     170                cout << "finished" << endl; 
     171 
     172 
     173                addOutRays(constructionSamples, outRays); 
     174 
     175                cout << "total samples: " << numSamples << endl; 
    160176        } 
    161177         
     
    165181 
    166182        //-- construction rays => we use uniform samples for this 
    167         CastPassSamples(max(mPostProcessSamples, mVisualizationSamples), 
    168                                     Preprocessor::SPATIAL_BOX_BASED_DISTRIBUTION,  
    169                                         &postProcessSamples); 
     183        CastPassSamples(mPostProcessSamples, 
     184                                    Preprocessor::DIRECTION_BASED_DISTRIBUTION,  
     185                                        postProcessSamples); 
    170186         
     187        cout << "starting post processing and visualization" << endl; 
     188 
     189        // store viewCells for postprocessing 
     190        const bool storeViewCells = true; 
     191        ComputeSampleContributions(postProcessSamples, true, storeViewCells); 
    171192        // merge the view cells 
    172193        PostProcess(preprocessor->mObjects, postProcessSamples); 
    173         // several visualizations 
    174         Visualize(preprocessor->mObjects, postProcessSamples); 
    175  
    176         if (outRays) 
    177         { 
    178                 while (!postProcessSamples.empty()) 
    179                         outRays->push_back(postProcessSamples.back()); 
    180         } 
    181         else 
    182         { 
    183                 CLEAR_CONTAINER(postProcessSamples); 
    184         } 
     194 
     195 
     196        //-- visualization 
     197        VssRayContainer visualizationSamples; 
     198 
     199        //-- construction rays => we use uniform samples for this 
     200        CastPassSamples(mVisualizationSamples, 
     201                                    Preprocessor::DIRECTION_BASED_DISTRIBUTION,  
     202                                        visualizationSamples); 
     203 
     204        ComputeSampleContributions(visualizationSamples, true, storeViewCells); 
     205 
     206        //Debug << "visualizationsamples: " << mVisualizationSamples << " " << visualizationSamples.size() << endl; 
     207        // different visualizations 
     208        Visualize(preprocessor->mObjects, visualizationSamples); 
     209 
     210        addOutRays(visualizationSamples, outRays); 
    185211 
    186212        return numSamples; 
     
    293319float 
    294320ViewCellsManager::ComputeSampleContributions(const VssRayContainer &rays, 
    295                                                                                          const bool addRays 
     321                                                                                         const bool addRays, 
     322                                                                                         const bool storeViewCells 
    296323                                                                                         ) 
    297324{ 
     
    304331  float sum = 0.0f; 
    305332  for (it = rays.begin(); it != it_end; ++ it) { 
    306         sum += ComputeSampleContributions(*(*it), addRays); 
     333        sum += ComputeSampleContributions(*(*it), addRays, storeViewCells); 
    307334        //ComputeSampleContributions(*(*it), addRays); 
    308335        //      sum += (*it)->mPvsContribution; 
     
    466493{ 
    467494        mConstructionSamples = constructionSamples; 
     495} 
     496 
     497 
     498void ViewCellsManager::SetInitialSamples(const int initialSamples) 
     499{ 
     500        mInitialSamples = initialSamples; 
    468501} 
    469502 
     
    554587{ 
    555588        mViewCells.clear(); 
    556  
    557589        CollectViewCells(); 
    558590 
     
    610642} 
    611643 
     644 
    612645float ViewCellsManager::ComputeSampleContributions(VssRay &ray, 
    613                                                                                                    const bool addRays) 
     646                                                                                                   const bool addRays, 
     647                                                                                                   const bool storeViewCells) 
    614648{ 
    615649        ViewCellContainer viewcells; 
     
    635669 
    636670        // copy viewcells memory efficiently 
    637         const bool storeViewcells = !addRays; 
    638  
    639         if (storeViewcells) 
     671        //const bool storeViewcells = !addRays; 
     672 
     673        if (storeViewCells) 
    640674        { 
    641675                ray.mViewCells.reserve(viewcells.size()); 
     
    732766        for (it = mViewCells.begin(); it != it_end; ++ it) 
    733767        { 
    734                 ExportColor(exporter, *it); 
    735                 ExportVcGeometry(exporter, *it); 
     768                if (!mOnlyValidViewCells || (*it)->GetValid()) 
     769                { 
     770                        ExportColor(exporter, *it); 
     771                        ExportVcGeometry(exporter, *it); 
     772                } 
    736773        } 
    737774} 
     
    778815 
    779816 
    780 BspViewCellsManager::BspViewCellsManager(BspTree *bspTree, 
    781                                                                                  int constructionSamples): 
    782 ViewCellsManager(constructionSamples), 
    783 mBspTree(bspTree) 
    784 { 
     817BspViewCellsManager::BspViewCellsManager(BspTree *bspTree): 
     818ViewCellsManager(), mBspTree(bspTree) 
     819{ 
     820        environment->GetIntValue("BspTree.Construction.samples", mInitialSamples); 
    785821} 
    786822 
     
    798834 
    799835 
    800 int BspViewCellsManager::Construct(const ObjectContainer &objects, 
    801                                                                    const VssRayContainer &rays) 
     836int BspViewCellsManager::ConstructSubdivision(const ObjectContainer &objects, 
     837                                                                                          const VssRayContainer &rays) 
    802838{ 
    803839        // if view cells were already constructed 
     
    811847        VssRayContainer savedRays; 
    812848 
    813         const int limit = min(mConstructionSamples, (int)rays.size()); 
     849        const int limit = min(mInitialSamples, (int)rays.size()); 
    814850 
    815851        VssRayContainer::const_iterator it, it_end = rays.end(); 
     
    846882 
    847883        // recast rest of the rays 
    848         ComputeSampleContributions(savedRays); 
     884        ComputeSampleContributions(savedRays, true, false); 
    849885 
    850886 
     
    937973 
    938974 
    939         // $$JB we do not have connectivity information from the ray in the moment 
    940         // perhaps we could recast the rays or remember the cells traversed inside the 
    941         // vssray (which would on other hand create some overhead) 
    942975        //-- merge or subdivide view cells 
    943976        int merged = 0; 
    944977 
    945         vector<BspIntersection>::const_iterator iit; 
    946         CLEAR_CONTAINER(mBspRays); 
    947         ConstructBspRays(rays, mPostProcessSamples); 
    948  
    949         for (int i = 0; i < (int)mBspRays.size(); ++ i) 
    950         { 
    951                 BspRay *ray = mBspRays[i]; 
    952  
    953                 // traverse leaves stored in the rays and compare and merge consecutive 
    954                 // leaves (i.e., the neighbors in the tree) 
    955                 if (ray->intersections.size() < 2) 
    956                         continue; 
    957 #if 0 
    958                 iit = ray->intersections.begin(); 
    959  
    960                 BspLeaf *previousLeaf = (*iit).mLeaf; 
    961                 ++ iit; 
    962  
    963                 for (; iit != ray->intersections.end(); ++ iit) 
    964                 { 
    965                         BspLeaf *leaf = (*iit).mLeaf; 
    966  
    967                         if (ShouldMerge(leaf, previousLeaf)) 
    968                         { 
    969                                 MergeBspLeafViewCells(leaf, previousLeaf); 
    970  
    971                                 ++ merged; 
    972                         } 
    973  
    974                         previousLeaf = leaf; 
    975                 } 
    976 #endif 
    977         } 
    978  
     978        // TODO 
     979         
    979980        //-- stats and visualizations 
    980981        cout << "finished" << endl; 
     
    984985        Debug << "Postprocessing: Merged " << merged << " view cells in " 
    985986                  << TimeDiff(startTime, GetTime()) *1e-3 << " secs" 
    986                   << "using " << (int)mBspRays.size() << " samples" << endl << endl; 
    987  
    988         CLEAR_CONTAINER(mBspRays); 
     987                  << "using " << (int)rays.size() << " samples" << endl << endl; 
    989988 
    990989        // reset view cells and stats 
     
    997996BspViewCellsManager::~BspViewCellsManager() 
    998997{ 
    999         CLEAR_CONTAINER(mBspRays); 
    1000998} 
    1001999 
     
    10121010        if (!ViewCellsConstructed()) 
    10131011                return; 
    1014         CLEAR_CONTAINER(mBspRays); 
    1015         ConstructBspRays(sampleRays, mVisualizationSamples); 
    1016  
     1012         
    10171013        if (1) // export view cells 
    10181014        { 
     
    10701066 
    10711067                exporter->SetFilled(); 
    1072  
    1073                 // export rays 
    1074                 if (0) 
    1075                 { 
    1076                         VssRayContainer outRays; 
    1077  
    1078                         int raysSize = min((int)mBspRays.size(), mVisualizationSamples); 
    1079  
    1080                         for (int i = 0; i < raysSize; ++ i) 
    1081                                 // only rays piercing geometry 
    1082                                 outRays.push_back(mBspRays[i]->vssRay); 
    1083  
    1084                         // export rays 
    1085                         exporter->ExportRays(outRays, RgbColor(1, 1, 0)); 
    1086                 } 
    10871068 
    10881069                if (mExportGeometry) 
     
    13451326 
    13461327 
    1347 int KdViewCellsManager::Construct(const ObjectContainer &objects, 
     1328int KdViewCellsManager::ConstructSubdivision(const ObjectContainer &objects, 
    13481329                                                                  const VssRayContainer &rays) 
    13491330{ 
     
    13591340 
    13601341        // cast rays 
    1361         ComputeSampleContributions(rays); 
     1342        ComputeSampleContributions(rays, true, false); 
    13621343 
    13631344        EvaluateViewCellsStats(); 
     
    16051586 
    16061587 
    1607 VspKdViewCellsManager::VspKdViewCellsManager(VspKdTree *vspKdTree, 
    1608                                                                                          int constructionSamples): 
    1609 ViewCellsManager(constructionSamples), 
    1610 mVspKdTree(vspKdTree) 
    1611 { 
     1588VspKdViewCellsManager::VspKdViewCellsManager(VspKdTree *vspKdTree): 
     1589ViewCellsManager(), mVspKdTree(vspKdTree) 
     1590{ 
     1591        environment->GetIntValue("VspKdTree.Construction.samples", mInitialSamples); 
    16121592        mVspKdTree->SetViewCellsManager(this); 
    16131593} 
     
    16361616 
    16371617 
    1638 int VspKdViewCellsManager::Construct(const ObjectContainer &objects, 
    1639                                                                          const VssRayContainer &rays) 
     1618int VspKdViewCellsManager::ConstructSubdivision(const ObjectContainer &objects, 
     1619                                                                                                const VssRayContainer &rays) 
    16401620{ 
    16411621        // if view cells already constructed 
     
    16471627 
    16481628        GetRaySets(rays, 
    1649                            mConstructionSamples, 
     1629                           mInitialSamples, 
    16501630                           constructionRays, 
    16511631                           &savedRays); 
     
    16761656        long startTime = GetTime(); 
    16771657        // recast rest of rays 
    1678         ComputeSampleContributions(savedRays); 
     1658        ComputeSampleContributions(savedRays, true, false); 
    16791659 
    16801660        Debug << "Computed remaining ray contribution in " << TimeDiff(startTime, GetTime()) * 1e-3 
     
    19501930} 
    19511931 
     1932 
     1933 
    19521934/**************************************************************************/ 
    19531935/*                   VspBspViewCellsManager implementation                */ 
     
    19551937 
    19561938 
    1957 VspBspViewCellsManager::VspBspViewCellsManager(VspBspTree *vspBspTree, 
    1958                                                                                            int constructionSamples): 
    1959 ViewCellsManager(constructionSamples), 
    1960 mVspBspTree(vspBspTree) 
    1961 { 
     1939VspBspViewCellsManager::VspBspViewCellsManager(VspBspTree *vspBspTree): 
     1940ViewCellsManager(), mVspBspTree(vspBspTree) 
     1941{ 
     1942        environment->GetIntValue("VspBspTree.Construction.samples", mInitialSamples); 
    19621943        mVspBspTree->SetViewCellsManager(this); 
    19631944} 
     
    19801961void VspBspViewCellsManager::CollectViewCells() 
    19811962{ 
    1982         mVspBspTree->CollectViewCells(mViewCells, mOnlyValidViewCells); 
     1963        mVspBspTree->CollectViewCells(mViewCells, true); 
    19831964} 
    19841965 
     
    20031984 
    20041985 
    2005 int VspBspViewCellsManager::Construct(const ObjectContainer &objects, 
     1986int VspBspViewCellsManager::ConstructSubdivision(const ObjectContainer &objects, 
    20061987                                                                          const VssRayContainer &rays) 
    20071988{ 
     
    20161997        VssRayContainer sampleRays; 
    20171998 
    2018         int limit = min (mConstructionSamples, (int)rays.size()); 
     1999        int limit = min (mInitialSamples, (int)rays.size()); 
    20192000 
    20202001        VssRayContainer constructionRays; 
    20212002        VssRayContainer savedRays; 
    20222003 
    2023         Debug << "construction samples: " << mConstructionSamples << " rays: " << (int)rays.size() << endl; 
    2024         GetRaySets(rays, mConstructionSamples, constructionRays, &savedRays); 
    2025  
    2026         Debug << "construction rays: " << (int)constructionRays.size() << endl; 
     2004        Debug << "samples used for subdivision: " << mInitialSamples << " rays: " << (int)rays.size() << endl; 
     2005        GetRaySets(rays, mInitialSamples, constructionRays, &savedRays); 
     2006 
     2007        Debug << "initial rays: " << (int)constructionRays.size() << endl; 
    20272008        Debug << "saved rays: " << (int)savedRays.size() << endl; 
    20282009 
     
    20752056        cout << "Computing remaining ray contributions ... "; 
    20762057        // recast rest of rays 
    2077         ComputeSampleContributions(savedRays); 
     2058        ComputeSampleContributions(savedRays, true, false); 
    20782059        cout << "finished" << endl; 
    20792060 
     
    21162097                  << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl << endl; 
    21172098 
    2118         cout << "reseting view cell stats ... "; 
    2119         ResetViewCells(); 
    2120         cout << "finished" << endl; 
    21212099 
    21222100        //BspLeaf::NewMail(); 
    21232101        if (1) // export merged view cells 
    21242102        { 
     2103 
     2104                cout << "reseting view cells ... "; 
     2105                ResetViewCells(); 
     2106                cout << "finished" << endl; 
     2107 
    21252108                Exporter *exporter = Exporter::GetExporter("merged_view_cells.x3d"); 
    21262109                Debug << "\nView cells after merge:\n" << mViewCellsStats << endl; 
     
    21982181 
    21992182        // check if new view cells turned invalid 
     2183        SetValidity(mMinPvsSize, mMaxPvsSize);  
     2184        // update valid view space according to valid view cells 
    22002185        mVspBspTree->ValidateTree(); 
    2201         ResetViewCells(); 
     2186 
     2187        // recompute view cell statistics 
     2188        mViewCellsStats.Reset(); 
     2189        EvaluateViewCellsStats(); 
     2190        // has to be recomputed 
     2191        mTotalAreaValid = false; 
    22022192 
    22032193 
     
    22832273        // collapse sibling leaves that share the same view cell 
    22842274        mVspBspTree->CollapseTree(); 
    2285  
     2275        // recompute view cell list and statistics 
    22862276        ResetViewCells(); 
    22872277 
     
    24472437#if 1 
    24482438        //-- some rays for output 
    2449         vector<BspRay *> bspRays; 
    2450         mVspBspTree->ConstructBspRays(bspRays, rays); 
    2451  
    2452         const int raysOut = min((int)bspRays.size(), mVisualizationSamples); 
     2439        const int raysOut = min((int)rays.size(), mVisualizationSamples); 
     2440 
    24532441#endif 
    24542442 
     
    24592447                VssRayContainer vcRays; 
    24602448                Intersectable::NewMail(); 
    2461 #if 0 // largest view cell pvs first 
    2462                 BspViewCell *vc = dynamic_cast<BspViewCell *>(mViewCells[i]); 
    2463 #else 
    2464                 BspViewCell *vc = dynamic_cast<BspViewCell *> 
    2465                         (mViewCells[Random((int)mViewCells.size())]); 
    2466 #endif 
    2467  
    2468 #if 1 
    2469                 // check whether we can add the current ray to the output rays 
    2470                 for (int k = 0; k < raysOut; ++ k) 
    2471                 { 
    2472                         BspRay *ray = bspRays[k]; 
    2473                         for     (int j = 0; j < (int)ray->intersections.size(); ++ j) 
     2449                BspViewCell *vc; 
     2450         
     2451                if (0) // largest view cell pvs first 
     2452                { 
     2453                        vc = dynamic_cast<BspViewCell *>(mViewCells[i]); 
     2454                } 
     2455                else 
     2456                { 
     2457                        vc = dynamic_cast<BspViewCell *> 
     2458                                (mViewCells[Random((int)mViewCells.size())]); 
     2459                } 
     2460 
     2461        if (1) 
     2462                { 
     2463                        // check whether we can add the current ray to the output rays 
     2464                        for (int k = 0; k < raysOut; ++ k) 
    24742465                        { 
    2475                                 BspLeaf *leaf = ray->intersections[j].mLeaf; 
    2476                                 if (vc == leaf->GetViewCell()) 
    2477                                         vcRays.push_back(ray->vssRay); 
     2466                                VssRay *ray = rays[k]; 
     2467                                for     (int j = 0; j < (int)ray->mViewCells.size(); ++ j) 
     2468                                { 
     2469                                        BspViewCell *bspVc = dynamic_cast<BspViewCell *>(ray->mViewCells[j]); 
     2470                                        BspLeaf *leaf = bspVc->mLeaves[0]; 
     2471                                        if (vc == bspVc) 
     2472                                                vcRays.push_back(ray); 
     2473                                } 
    24782474                        } 
    24792475                } 
    2480 #endif 
     2476 
    24812477                //bspLeaves[j]->Mail(); 
    24822478                char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 
     
    24952491                          << ", leaves=" << (int)vc->mLeaves.size() << endl; 
    24962492 
     2493                 
    24972494                //-- export rays piercing this view cell 
    2498 #if 1 
    2499                 exporter->ExportRays(vcRays, RgbColor(1, 1, 1)); 
    2500 #endif 
    2501 #if 0 
    2502                 vector<BspLeaf *>::const_iterator lit, lit_end = vc->mLeaves.end(); 
    2503  
    2504                 for (lit = vc->mLeaves.begin(); lit != lit_end; ++ lit) 
    2505                         exporter->ExportRays((*lit)->mVssRays); 
    2506 #endif 
     2495                if (1) 
     2496                { 
     2497                        exporter->ExportRays(vcRays, RgbColor(1, 1, 1)); 
     2498                } 
     2499                else 
     2500                { 
     2501                        vector<BspLeaf *>::const_iterator lit, lit_end = vc->mLeaves.end(); 
     2502 
     2503                        for (lit = vc->mLeaves.begin(); lit != lit_end; ++ lit) 
     2504                                exporter->ExportRays((*lit)->mVssRays); 
     2505                } 
     2506 
     2507         
    25072508                m.mDiffuseColor = RgbColor(1, 0, 0); 
    25082509                exporter->SetForcedMaterial(m); 
     
    25132514                exporter->SetFilled(); 
    25142515 
     2516         
    25152517                // output PVS of view cell 
    25162518                for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 
    25172519                { 
     2520                 
    25182521                        Intersectable *intersect = (*it).first; 
    25192522 
     
    25282531                } 
    25292532 
     2533                 
    25302534                DEL_PTR(exporter); 
    25312535                cout << "finished" << endl; 
    25322536        } 
    25332537 
    2534 #if 1 
    2535         CLEAR_CONTAINER(bspRays); 
    2536 #endif 
    25372538        Debug << endl; 
    25382539} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h

    r573 r574  
    4747  enum {BSP, KD, VSP_KD, VSP_BSP}; 
    4848   
    49         /** Constructor taking the maximal number of samples used for construction 
    50         */ 
    51         ViewCellsManager(const int constructionSamples); 
     49        /** Constructor taking the initial and construction samples. 
     50                @param initialSamples the maximal number of samples used for creating the hierarchy 
     51                of view cells 
     52                @param constructionSamples the maximal number of samples used for construction 
     53        */ 
     54        ViewCellsManager(const int initialSamples, const int constructionSamples); 
    5255 
    5356        ViewCellsManager(); 
     
    6265        /** Constructs view cell container with a given number of samples. 
    6366        */ 
    64         virtual int Construct(const ObjectContainer &objects,  
     67        virtual int ConstructSubdivision(const ObjectContainer &objects,  
    6568                                                  const VssRayContainer &rays) = 0; 
    6669 
     
    7073                adding the contribution 
    7174                @param addRays true if rays should be added to the PVSs of the viewcells they 
    72                 intersect */ 
     75                intersect  
     76                @param storeViewCells true if view cells should be stored in the ray 
     77        */ 
    7378  float ComputeSampleContributions(const VssRayContainer &rays, 
    74                                                                    const bool addContributions = true); 
     79                                                                   const bool addContributions, 
     80                                                                   const bool storeViewCells); 
    7581 
    7682  /** Add sample contributions to the viewcells they intersect */ 
     
    8591                @returns number of sample contributions 
    8692        */ 
    87         virtual float ComputeSampleContributions(VssRay &ray, const bool addRays = true); 
     93        virtual float ComputeSampleContributions(VssRay &ray, const bool addRays, const bool storeViewCells); 
    8894 
    8995  virtual void AddSampleContributions(VssRay &ray); 
     
    147153        void SetVisualizationSamples(const int visSamples); 
    148154 
     155        /** Sets maximal number of samples used for the construction of the view cells. 
     156        */ 
     157        void SetConstructionSamples(const int constructionSamples); 
     158 
    149159        /** Sets maximal number of samples used for the visualization of the view cells. 
    150160        */ 
    151         void SetConstructionSamples(const int constructionSamples); 
     161        void SetInitialSamples(const int initialSamples); 
    152162 
    153163        /** Sets maximal number of samples used for the post processing of the view cells. 
     
    306316protected: 
    307317 
    308         int CastPassSamples(int samplesPerPass,  
    309                                                 int sampleType,  
    310                                                 VssRayContainer *outRays) const; 
     318        int CastPassSamples(const int samplesPerPass,  
     319                                                const int sampleType,  
     320                                                VssRayContainer &vssRays) const; 
    311321 
    312322        void ParseEnvironment(); 
     
    367377        /// maximum number of samples taken for construction of the view cells 
    368378        int mConstructionSamples; 
     379        int mSamplesPerPass; 
     380        int mInitialSamples; 
    369381        int mPostProcessSamples; 
    370382        int mVisualizationSamples; 
     
    409421                used to construct the bsp tree. 
    410422        */ 
    411         BspViewCellsManager(BspTree *tree, int constructionSamples); 
     423        BspViewCellsManager(BspTree *tree); 
    412424 
    413425        ~BspViewCellsManager(); 
    414426 
    415         int Construct(const ObjectContainer &objects,  
     427        int ConstructSubdivision(const ObjectContainer &objects,  
    416428                                  const VssRayContainer &rays); 
    417429 
     
    482494        KdViewCellsManager(KdTree *tree); 
    483495 
    484         int Construct(const ObjectContainer &objects,  
     496        int ConstructSubdivision(const ObjectContainer &objects,  
    485497                                  const VssRayContainer &rays); 
    486498 
     
    536548public: 
    537549 
    538         VspKdViewCellsManager(VspKdTree *vspKdTree, int constructionSamples); 
    539  
    540         int Construct(const ObjectContainer &objects,  
     550        VspKdViewCellsManager(VspKdTree *vspKdTree); 
     551 
     552        int ConstructSubdivision(const ObjectContainer &objects,  
    541553                                  const VssRayContainer &rays); 
    542554 
     
    595607public: 
    596608 
    597         VspBspViewCellsManager(VspBspTree *tree, int constructionSamples); 
     609        VspBspViewCellsManager(VspBspTree *tree); 
    598610        ~VspBspViewCellsManager(); 
    599611 
    600         int Construct(const ObjectContainer &objects,  
     612        int ConstructSubdivision(const ObjectContainer &objects,  
    601613                                  const VssRayContainer &rays); 
    602614 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp

    r573 r574  
    178178const BspTreeStatistics &VspBspTree::GetStatistics() const 
    179179{ 
    180         return mStat; 
     180        return mBspStats; 
    181181} 
    182182 
     
    273273                                                   AxisAlignedBox3 *forcedBoundingBox) 
    274274{ 
    275         mStat.nodes = 1; 
     275        mBspStats.nodes = 1; 
    276276        mBox.Initialize();      // initialise BSP tree bounding box 
    277277 
     
    353353                mTermMinProbability *= mBox.GetVolume(); 
    354354 
    355         mStat.polys = (int)polys.size(); 
     355        mBspStats.polys = (int)polys.size(); 
    356356 
    357357        cout << "finished" << endl; 
     
    373373        return 
    374374                (sizeof(VspBspTree) + 
    375                  mStat.Leaves() * sizeof(BspLeaf) + 
    376                  mStat.Interior() * sizeof(BspInterior) + 
    377                  mStat.accumRays * sizeof(RayInfo)) / (1024.0f * 1024.0f); 
     375                 mBspStats.Leaves() * sizeof(BspLeaf) + 
     376                 mBspStats.Interior() * sizeof(BspInterior) + 
     377                 mBspStats.accumRays * sizeof(RayInfo)) / (1024.0f * 1024.0f); 
    378378} 
    379379 
     
    405405        tStack.push(tData); 
    406406 
    407         mStat.Start(); 
     407        mBspStats.Start(); 
    408408        cout << "Contructing vsp bsp tree ... \n"; 
    409409 
     
    439439                                  << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 
    440440 
    441                 if (mStat.Leaves() >= nleaves) 
     441                if (mBspStats.Leaves() >= nleaves) 
    442442                { 
    443443                        nleaves += 500; 
    444444                                 
    445                         cout << "leaves=" << mStat.Leaves() << endl; 
     445                        cout << "leaves=" << mBspStats.Leaves() << endl; 
    446446                        Debug << "needed " 
    447447                          << TimeDiff(interTime, GetTime())*1e-3 << " secs to create 500 leaves" << endl; 
     
    453453        cout << "finished\n"; 
    454454 
    455         mStat.Stop(); 
     455        mBspStats.Stop(); 
    456456} 
    457457 
     
    463463                 (data.mPvs <= mTermMinPvs)   || 
    464464                 (data.mProbability <= mTermMinProbability) || 
    465                  (mStat.Leaves() >= mMaxViewCells) || 
     465                 (mBspStats.Leaves() >= mMaxViewCells) || 
    466466                 (data.GetAvgRayContribution() > mTermMaxRayContribution) || 
    467467                 (data.mDepth >= mTermMaxDepth)); 
     
    509509                AddToPvs(leaf, *tData.mRays, sampCon, conSamp); 
    510510 
    511                 mStat.contributingSamples += conSamp; 
    512                 mStat.sampleContributions +=(int) sampCon; 
     511                mBspStats.contributingSamples += conSamp; 
     512                mBspStats.sampleContributions +=(int) sampCon; 
    513513 
    514514                //-- store additional info 
     
    526526                        PropagateUpValidity(leaf); 
    527527 
    528                         ++ mStat.invalidLeaves; 
     528                        ++ mBspStats.invalidLeaves; 
    529529                } 
    530530                 
     
    572572                { 
    573573                        // terminate branch because of max cost 
    574                         ++ mStat.maxCostNodes; 
     574                        ++ mBspStats.maxCostNodes; 
    575575            return leaf; 
    576576                } 
    577577        } 
    578578 
    579         mStat.nodes += 2; 
     579        mBspStats.nodes += 2; 
    580580 
    581581        //-- subdivide further 
     
    11601160                 
    11611161                //! error also computed if cost ratio is missed 
    1162                 ++ mStat.splits[axis]; 
     1162                ++ mBspStats.splits[axis]; 
    11631163                isAxisAlignedSplit = true; 
    11641164        } 
     
    15091509 
    15101510        // store maximal and minimal depth 
    1511         if (data.mDepth > mStat.maxDepth) 
    1512                 mStat.maxDepth = data.mDepth; 
    1513  
    1514         if (data.mPvs > mStat.maxPvs) 
    1515                 mStat.maxPvs = data.mPvs; 
    1516          
    1517         if (data.mDepth < mStat.minDepth) 
    1518                 mStat.minDepth = data.mDepth; 
     1511        if (data.mDepth > mBspStats.maxDepth) 
     1512                mBspStats.maxDepth = data.mDepth; 
     1513 
     1514        if (data.mPvs > mBspStats.maxPvs) 
     1515                mBspStats.maxPvs = data.mPvs; 
     1516         
     1517        if (data.mDepth < mBspStats.minDepth) 
     1518                mBspStats.minDepth = data.mDepth; 
    15191519 
    15201520        if (data.mDepth >= mTermMaxDepth) 
    1521                 ++ mStat.maxDepthNodes; 
     1521                ++ mBspStats.maxDepthNodes; 
    15221522        // accumulate rays to compute rays /  leaf 
    1523         mStat.accumRays += (int)data.mRays->size(); 
     1523        mBspStats.accumRays += (int)data.mRays->size(); 
    15241524 
    15251525        if (data.mPvs < mTermMinPvs) 
    1526                 ++ mStat.minPvsNodes; 
     1526                ++ mBspStats.minPvsNodes; 
    15271527 
    15281528        if ((int)data.mRays->size() < mTermMinRays) 
    1529                 ++ mStat.minRaysNodes; 
     1529                ++ mBspStats.minRaysNodes; 
    15301530 
    15311531        if (data.GetAvgRayContribution() > mTermMaxRayContribution) 
    1532                 ++ mStat.maxRayContribNodes; 
     1532                ++ mBspStats.maxRayContribNodes; 
    15331533 
    15341534        if (data.mProbability <= mTermMinProbability) 
    1535                 ++ mStat.minProbabilityNodes; 
     1535                ++ mBspStats.minProbabilityNodes; 
    15361536         
    15371537        // accumulate depth to compute average depth 
    1538         mStat.accumDepth += data.mDepth; 
     1538        mBspStats.accumDepth += data.mDepth; 
    15391539 
    15401540#ifdef _DEBUG 
     
    16551655 
    16561656 
    1657 void VspBspTree::ValidateTree() 
     1657void VspBspTree::CollapseViewCells() 
    16581658{ 
    16591659        stack<BspNode *> nodeStack; 
     
    16641664        nodeStack.push(mRoot); 
    16651665         
    1666         const bool addToUnbounded = false; 
    1667  
    16681666        while (!nodeStack.empty())  
    16691667        { 
     
    16721670                 
    16731671                if (node->IsLeaf()) 
    1674                 { 
    1675                         BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 
    1676  
    1677                         if (!addToUnbounded && node->TreeValid()) 
     1672        { 
     1673                        BspViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 
     1674 
     1675                        if (!viewCell->GetValid()) 
    16781676                        { 
    16791677                                BspViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell(); 
    16801678                         
    1681                                 if (!mViewCellsManager->CheckValidity(viewCell, 
    1682                                                                                                           mViewCellsManager->GetMinPvsSize(),  
    1683                                                                                                           mViewCellsManager->GetMaxPvsSize())) 
     1679                                vector<BspLeaf *>::const_iterator it, it_end = viewCell->mLeaves.end(); 
     1680                                for (it = viewCell->mLeaves.begin();it != it_end; ++ it) 
    16841681                                { 
    1685                                         vector<BspLeaf *>::const_iterator it, it_end = viewCell->mLeaves.end(); 
    1686                                         for (it = viewCell->mLeaves.begin();it != it_end; ++ it) 
    1687                                         { 
    1688                                                 BspLeaf *l = *it; 
    1689                                                  
    1690                                                 l->SetTreeValid(false); 
    1691                                                 PropagateUpValidity(l); 
    1692                                                  
    1693                                                 if (addToUnbounded) 
    1694                                                         l->SetViewCell(GetOrCreateOutOfBoundsCell()); 
    1695  
    1696                                                 ++ mStat.invalidLeaves; 
    1697                                         } 
    1698  
    1699                                         // add to unbounded view cell or set to invalid 
    1700                                         if (addToUnbounded) 
    1701                                         { 
    1702                                                 GetOrCreateOutOfBoundsCell()->GetPvs().AddPvs(viewCell->GetPvs()); 
    1703                                                 DEL_PTR(viewCell); 
    1704                                         } 
    1705                                         else 
    1706                                         { 
    1707                                                 viewCell->SetValid(false); 
    1708                                         } 
     1682                                        BspLeaf *l = *it; 
     1683                                        l->SetViewCell(GetOrCreateOutOfBoundsCell()); 
     1684                                        ++ mBspStats.invalidLeaves; 
    17091685                                } 
     1686 
     1687                                // add to unbounded view cell 
     1688                                GetOrCreateOutOfBoundsCell()->GetPvs().AddPvs(viewCell->GetPvs()); 
     1689                                DEL_PTR(viewCell); 
    17101690                        } 
    17111691                } 
     
    17191699        } 
    17201700 
    1721         Debug << "invalid leaves: " << mStat.invalidLeaves << endl; 
    1722 } 
     1701        Debug << "invalid leaves: " << mBspStats.invalidLeaves << endl; 
     1702} 
     1703 
     1704 
     1705void VspBspTree::ValidateTree() 
     1706{ 
     1707        stack<BspNode *> nodeStack; 
     1708 
     1709        if (!mRoot) 
     1710                return; 
     1711 
     1712        nodeStack.push(mRoot); 
     1713         
     1714        mBspStats.invalidLeaves = 0; 
     1715        while (!nodeStack.empty())  
     1716        { 
     1717                BspNode *node = nodeStack.top(); 
     1718                nodeStack.pop(); 
     1719                 
     1720                if (node->IsLeaf()) 
     1721                { 
     1722                        BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 
     1723 
     1724                        if (!leaf->GetViewCell()->GetValid()) 
     1725                                ++ mBspStats.invalidLeaves; 
     1726 
     1727                        // validity flags don't match => repair 
     1728                        if (leaf->GetViewCell()->GetValid() != leaf->TreeValid()) 
     1729                        { 
     1730                                leaf->SetTreeValid(leaf->GetViewCell()->GetValid()); 
     1731                                PropagateUpValidity(leaf); 
     1732                        } 
     1733                } 
     1734                else 
     1735                { 
     1736                        BspInterior *interior = dynamic_cast<BspInterior *>(node); 
     1737                 
     1738                        nodeStack.push(interior->GetFront()); 
     1739                        nodeStack.push(interior->GetBack()); 
     1740                } 
     1741        } 
     1742 
     1743        Debug << "invalid leaves: " << mBspStats.invalidLeaves << endl; 
     1744} 
     1745 
    17231746 
    17241747 
     
    17841807        int splits = 0; 
    17851808 
    1786         while (!rays.empty()) 
    1787         { 
    1788                 RayInfo bRay = rays.back(); 
    1789                 rays.pop_back(); 
    1790  
     1809        RayInfoContainer::const_iterator it, it_end = rays.end(); 
     1810 
     1811        for (it = rays.begin(); it != it_end; ++ it) 
     1812        { 
     1813                RayInfo bRay = *it; 
     1814                 
    17911815                VssRay *ray = bRay.mRay; 
    17921816                float t; 
     
    22132237        int splits = 0; 
    22142238 
    2215         while (!polys.empty()) 
    2216         { 
    2217                 Polygon3 *poly = polys.back(); 
    2218                 polys.pop_back(); 
     2239        PolygonContainer::const_iterator it, it_end = polys.end(); 
     2240 
     2241        for (it = polys.begin(); it != polys.end(); ++ it)       
     2242        { 
     2243                Polygon3 *poly = *it; 
    22192244 
    22202245                // classify polygon 
     
    26322657                BspLeaf *leaf = *it; 
    26332658                 
    2634                 /// create leaf pvs (needed for post processing 
     2659                /// create leaf pvs (needed for post processing) 
    26352660                leaf->mPvs = new ObjectPvs(leaf->GetViewCell()->GetPvs()); 
    26362661 
     
    26742699int VspBspTree::CollectMergeCandidates(const VssRayContainer &rays) 
    26752700{ 
    2676         vector<BspRay *> bspRays; 
    2677  
    26782701        ViewCell::NewMail(); 
    26792702        long startTime = GetTime(); 
    2680         ConstructBspRays(bspRays, rays); 
    2681         Debug << (int)bspRays.size() << " bsp rays constructed in "  
    2682                   << TimeDiff(startTime, GetTime()) * 1e-3f << " secs" << endl; 
    2683  
     2703         
    26842704        map<BspLeaf *, vector<BspLeaf*> > neighborMap; 
    2685         vector<BspIntersection>::const_iterator iit; 
     2705        ViewCellContainer::const_iterator iit; 
    26862706 
    26872707        int numLeaves = 0; 
     
    26892709        BspLeaf::NewMail(); 
    26902710 
    2691         for (int i = 0; i < (int)bspRays.size(); ++ i) 
     2711        for (int i = 0; i < (int)rays.size(); ++ i) 
    26922712        {   
    2693                 BspRay *ray = bspRays[i]; 
     2713                VssRay *ray = rays[i]; 
    26942714         
    26952715                // traverse leaves stored in the rays and compare and  
    26962716                // merge consecutive leaves (i.e., the neighbors in the tree) 
    2697                 if (ray->intersections.size() < 2) 
     2717                if (ray->mViewCells.size() < 2) 
    26982718                        continue; 
    26992719           
    2700                 iit = ray->intersections.begin(); 
    2701                 BspLeaf *leaf = (*(iit ++)).mLeaf; 
     2720                iit = ray->mViewCells.begin(); 
     2721                BspViewCell *bspVc = dynamic_cast<BspViewCell *>(*(iit ++)); 
     2722                BspLeaf *leaf = bspVc->mLeaves[0]; 
    27022723                 
    27032724                // create leaf pvs (needed for post processing) 
     
    27152736                // traverse intersections  
    27162737                // consecutive leaves are neighbors => add them to queue 
    2717                 for (; iit != ray->intersections.end(); ++ iit) 
     2738                for (; iit != ray->mViewCells.end(); ++ iit) 
    27182739                { 
    27192740                        // next pair 
    27202741                        BspLeaf *prevLeaf = leaf; 
    2721             leaf = (*iit).mLeaf; 
     2742                        bspVc = dynamic_cast<BspViewCell *>(*iit); 
     2743            leaf = bspVc->mLeaves[0]; 
    27222744 
    27232745                        // view space not valid or same view cell 
     
    27812803        Debug << "overall cost: " << BspMergeCandidate::sOverallCost << endl; 
    27822804 
    2783         CLEAR_CONTAINER(bspRays); 
    2784  
    27852805        //-- collect the leaves which haven't been found by ray casting 
    27862806        if (0) 
     
    28572877        mergeStats.Start(); 
    28582878         
    2859         //BspMergeCandidate::sOverallCost = mBox.SurfaceArea() * mStat.maxPvs; 
     2879        //BspMergeCandidate::sOverallCost = mBox.SurfaceArea() * mBspStats.maxPvs; 
    28602880        long startTime = GetTime(); 
    28612881 
    2862         cout << "collecting merge candidates ... "; 
     2882        cout << "collecting merge candidates ... " << endl; 
    28632883         
    28642884        if (mUseRaysForMerge) 
     
    28802900 
    28812901        // number of view cells withouth the invalid ones 
    2882         int nViewCells = mStat.Leaves() - mStat.invalidLeaves; 
     2902        int nViewCells = mBspStats.Leaves() - mBspStats.invalidLeaves; 
    28832903         
    28842904         
     
    33703390void VspBspTree::PropagateUpValidity(BspNode *node) 
    33713391{ 
    3372         while (!node->IsRoot() && node->GetParent()->TreeValid()) 
    3373         { 
    3374                 node = node->GetParent(); 
    3375                 node->SetTreeValid(false); 
     3392        const bool isValid = node->TreeValid(); 
     3393 
     3394        // propagative up invalid flag until only invalid nodes exist over this node 
     3395        if (!isValid) 
     3396        { 
     3397                while (!node->IsRoot() && node->GetParent()->TreeValid()) 
     3398                { 
     3399                        node = node->GetParent(); 
     3400                        node->SetTreeValid(false); 
     3401                } 
     3402        } 
     3403        else 
     3404        { 
     3405                // propagative up valid flag until one of the subtrees is invalid 
     3406                while (!node->IsRoot() && !node->TreeValid()) 
     3407                { 
     3408            node = node->GetParent(); 
     3409                        BspInterior *interior = dynamic_cast<BspInterior *>(node); 
     3410                         
     3411                        // the parent is valid iff both leaves are valid 
     3412                        node->SetTreeValid(interior->GetBack()->TreeValid() &&  
     3413                                                           interior->GetFront()->TreeValid()); 
     3414                } 
    33763415        } 
    33773416} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h

    r573 r574  
    307307 
    308308         
    309         /** Checks validy of view cells. 
    310                 if not valid, sets regions invalid and deletes view cell. 
     309        /** Checks if tree validity-flags are right  
     310                with respect to view cell valitiy. 
     311                If not, marks subtree as invalid. 
    311312        */ 
    312313        void ValidateTree(); 
     314 
     315        /** Invalid view cells are added to the unbounded space 
     316        */ 
     317        void CollapseViewCells(); 
    313318 
    314319protected: 
     
    626631        BspNode *mRoot; 
    627632                 
    628         BspTreeStatistics mStat; 
     633        BspTreeStatistics mBspStats; 
    629634 
    630635        /// Strategies for choosing next split plane. 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp

    r564 r574  
    2727  environment->GetIntValue("VssPreprocessor.vssSamplesPerPass", mVssSamplesPerPass); 
    2828  environment->GetBoolValue("VssPreprocessor.useImportanceSampling", mUseImportanceSampling); 
    29   environment->GetBoolValue("ViewCells.delayedConstruction", mDelayedViewCellsConstruction); 
    30  
     29  
    3130  environment->GetBoolValue("VssPreprocessor.loadInitialSamples", mLoadInitialSamples); 
    3231  environment->GetBoolValue("VssPreprocessor.storeInitialSamples", mStoreInitialSamples); 
     
    5453  ray.Init(point, direction, Ray::LOCAL_RAY); 
    5554} 
     55 
     56 
     57void 
     58VssPreprocessor::CastRays( 
     59                                                  SimpleRayContainer &rays, 
     60                                                  VssRayContainer &vssRays 
     61                                                  ) 
     62{ 
     63  for (int i=0; i < rays.size(); i++) 
     64        CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays); 
     65} 
     66 
    5667 
    5768int 
     
    529540          mViewCellsManager->LoadViewCells(mViewCellsFilename, &mObjects); 
    530541  } 
    531  
     542  else 
     543  { 
     544          // construct view cells using it's own set of samples 
     545          mViewCellsManager->Construct(this); 
     546 
     547          //-- several visualizations and statistics 
     548          Debug << "view cells after construction: " << endl; 
     549          mViewCellsManager->PrintStatistics(Debug); 
     550  } 
     551         
    532552 
    533553  VssTree *vssTree = NULL; 
     
    634654  } 
    635655 
    636   /// compute view cell contribution of rays if view cells manager already constructed 
    637   mViewCellsManager->ComputeSampleContributions(mVssRays); 
    638  
    639   // construct view cells 
    640   if (!mDelayedViewCellsConstruction) 
    641         mViewCellsManager->Construct(mObjects, mVssRays); 
    642   
    643656  vssTree = new VssTree; 
    644657  // viewcells = Construct(mVssRays); 
     
    712725        cout<<"Average PVS size = "<<avgPvs<<endl; 
    713726 
    714         // construct view cells after vss 
    715         if (!mViewCellsManager->ViewCellsConstructed() &&  
    716                 (samples + mInitialSamples >= mViewCellsManager->GetConstructionSamples())) 
    717         { 
    718                 Debug << "samples " << samples << " initial " << mInitialSamples << " " << samples + mInitialSamples << endl; 
    719                 VssRayContainer constructionRays; 
    720                 vssTree->CollectRays(constructionRays, mViewCellsManager->GetConstructionSamples()); 
    721  
    722                 Debug << "collected rays: " << constructionRays.size() << endl; 
    723  
    724                 // test if we really have enough rays 
    725                 //if (constructionRays.size() >= nSamples)  
    726                 mViewCellsManager->Construct(mObjects, constructionRays); 
    727         } 
    728  
    729727        /// compute view cell contribution of rays 
    730         mViewCellsManager->ComputeSampleContributions(vssRays); 
     728        mViewCellsManager->ComputeSampleContributions(vssRays, true, false); 
    731729         
    732730        if (numExportRays) { 
     
    750748  } 
    751749 
    752  
    753   // at the latest create view cells here 
    754   if (!mViewCellsManager->ViewCellsConstructed()) 
    755   { 
    756           VssRayContainer constructionRays; 
    757  
    758           vssTree->CollectRays(constructionRays,  
    759                                                    mViewCellsManager->GetConstructionSamples()); 
    760           Debug << "collected rays: " << constructionRays.size() << endl; 
    761  
    762           mViewCellsManager->Construct(mObjects, constructionRays); 
    763   } 
    764  
    765   Debug << vssTree->stat << endl; 
    766   VssRayContainer viewCellRays; 
    767    
    768   // compute rays used for view cells construction 
    769   int numRays = Max(mViewCellsManager->GetPostProcessSamples(), 
    770                                         mViewCellsManager->GetVisualizationSamples()); 
    771  
    772   vssTree->CollectRays(viewCellRays, numRays); 
    773    
    774   //-- post process view cells 
    775   mViewCellsManager->PostProcess(mObjects, viewCellRays); 
    776  
    777750  if (mTestBeamSampling && mUseGlRenderer) 
    778751  {      
     
    780753  } 
    781754 
    782   //-- several visualizations and statistics 
    783   Debug << "\nview cells after post processing: " << endl; 
    784   mViewCellsManager->PrintStatistics(Debug); 
    785  
    786   mViewCellsManager->Visualize(mObjects, viewCellRays); 
    787    
     755  Debug << vssTree->stat << endl; 
     756 
     757  if (0) 
     758  { 
     759        VssRayContainer viewCellRays; 
     760   
     761        // compute rays used for view cells construction 
     762        const int numRays = mViewCellsManager->GetVisualizationSamples(); 
     763 
     764        vssTree->CollectRays(viewCellRays, numRays); 
     765  } 
     766 
    788767  //-- render simulation after merge 
    789   cout << "\nevaluating bsp view cells render time after merge ... "; 
     768  cout << "\nevaluating bsp view cells render time after sampling ... "; 
    790769  mRenderSimulator->RenderScene(); 
    791770  SimulationStatistics ss; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h

    r535 r574  
    3737  VssRayContainer mVssRays; 
    3838         
    39   bool mDelayedViewCellsConstruction; 
    40  
    4139  VssPreprocessor(); 
    4240  ~VssPreprocessor(); 
     
    5250                           ); 
    5351         
     52  void CastRays(SimpleRayContainer &rays, VssRayContainer &vssRays); 
     53 
    5454  void 
    5555  SetupRay(Ray &ray,  
  • trunk/VUT/GtpVisibilityPreprocessor/src/common.h

    r434 r574  
    138138#endif 
    139139// Clears a container (i.e., a vector of pointers) and deletes the pointers 
     140#if 0 
    140141#ifndef CLEAR_CONTAINER 
    141142#define CLEAR_CONTAINER(co) do { while (!(co).empty()) {   \ 
     
    143144                                                                   (co).pop_back();}}      \ 
    144145                                                        while (0) 
     146#endif 
     147#endif 
     148 
     149#ifndef CLEAR_CONTAINER 
     150#define CLEAR_CONTAINER(co) do { for (int _i = 0; _i < (int)(co).size(); ++ _i) { \ 
     151        DEL_PTR((co)[_i]);} \ 
     152        (co).clear(); } \ 
     153while (0) 
    145154#endif 
    146155 
  • trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp

    r570 r574  
    6767 
    6868  QApplication *app = NULL; 
    69    
     69 
    7070  if (p->mUseGlRenderer) { 
    7171        // create a qt application first (must be created before any opengl widget... 
Note: See TracChangeset for help on using the changeset viewer.