Ignore:
Timestamp:
01/16/06 03:23:29 (18 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r540 r542  
    2727mViewCellsFinished(false) 
    2828{ 
    29         mSceneBox.Initialize(); 
     29        mViewSpaceBox.Initialize(); 
    3030        ParseEnvironment(); 
    3131} 
     
    3939mViewCellsFinished(false) 
    4040{ 
    41         mSceneBox.Initialize(); 
     41        mViewSpaceBox.Initialize(); 
    4242        ParseEnvironment(); 
    4343} 
     
    7777int ViewCellsManager::Construct(VssRayContainer &rays) 
    7878{ 
    79         VssPreprocessor preprocessor; 
    80  
    81  
    82  
    83         return 0; 
     79/*      VssPreprocessor preprocessor; 
     80 
     81        VssRayContainer vssRays; 
     82        preprocessor->GenerateVssRays(mConstructionSamples, vssRays); 
     83        Construct(preprocessor->mObjects, vssRays); 
     84         
     85        // add rays to output rays 
     86        while (!vssRays.empty) 
     87        { 
     88                rays.push_back(vssRays.back()); 
     89                vssRays.pop_back(); 
     90        } 
     91 
     92        const int importanceRays = 1000000; 
     93        preprocessor->GenerateVssRays(max(importanceRays, mPostProcessSamples); 
     94 
     95        PostProcess(preprocesor->mObjects, importanceRays); 
     96        Visualize(preprocessor->mObjects, importanceRays); 
     97 
     98        // add rays to output rays 
     99        while (!importanceRays.empty) 
     100        { 
     101                rays.push_back(importanceRays.back()); 
     102                importanceRays.pop_back(); 
     103        } 
     104*/ 
     105        return (int)rays.size(); 
    84106} 
    85107 
     
    99121bool ViewCellsManager::GetViewPoint(Vector3 &viewPoint) const 
    100122{ 
    101         viewPoint = mSceneBox.GetRandomPoint(); 
     123        viewPoint = mViewSpaceBox.GetRandomPoint(); 
    102124 
    103125        return true; 
     
    107129bool ViewCellsManager::ViewPointValid(const Vector3 &viewPoint) const 
    108130{ 
    109         return mSceneBox.IsInside(viewPoint); 
     131        return mViewSpaceBox.IsInside(viewPoint); 
    110132} 
    111133 
     
    333355void ViewCellsManager::SetViewSpaceBox(const AxisAlignedBox3 &box) 
    334356{ 
    335         mSceneBox = box; 
     357        mViewSpaceBox = box; 
    336358} 
    337359 
     
    339361AxisAlignedBox3 ViewCellsManager::GetViewSpaceBox() const 
    340362{ 
    341         return mSceneBox; 
     363        return mViewSpaceBox; 
    342364} 
    343365 
     
    358380void ViewCellsManager::ComputeSampleContributions(VssRay &ray) 
    359381{ 
    360   ViewCellContainer viewcells; 
    361  
    362   ray.mPvsContribution = 0; 
    363   ray.mRelativePvsContribution = 0.0f; 
    364  
    365   // matt TODO: remove this!! 
    366   Ray hray(ray); 
    367   float tmin = 0, tmax = 1.0; 
    368  
    369   //hray.Init(ray.GetOrigin(), ray.GetDir(), Ray::LINE_SEGMENT); 
    370   if (!GetViewSpaceBox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) 
     382        ViewCellContainer viewcells; 
     383 
     384        ray.mPvsContribution = 0; 
     385        ray.mRelativePvsContribution = 0.0f; 
     386 
     387        // matt TODO: remove this!! 
     388        Ray hray(ray); 
     389        float tmin = 0, tmax = 1.0; 
     390 
     391        //hray.Init(ray.GetOrigin(), ray.GetDir(), Ray::LINE_SEGMENT); 
     392        if (!GetViewSpaceBox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) 
    371393        return; 
    372394 
    373   Vector3 origin = hray.Extrap(tmin); 
    374   Vector3 termination = hray.Extrap(tmax); 
    375  
    376   CastLineSegment(origin, 
    377                                   termination, 
    378                                   viewcells); 
    379   //Debug << "constribution: " << (int)viewcells.size() << endl; 
    380   // copy viewcells memory efficiently 
    381   const bool storeViewcells = false; 
    382   if (storeViewcells) { 
    383         ray.mViewCells.reserve(viewcells.size()); 
    384         ray.mViewCells = viewcells; 
    385   } 
    386  
    387   ViewCellContainer::const_iterator it = viewcells.begin(); 
    388  
    389   bool addInPlace = false; 
    390  
    391   if (addInPlace) { 
    392         for (; it != viewcells.end(); ++it) { 
    393           ViewCell *viewcell = *it; 
    394  
    395           // if ray not outside of view space 
    396           float contribution; 
    397           bool added = 
    398                 viewcell->GetPvs().AddSample(ray.mTerminationObject, 
    399                                                                          contribution 
    400                                                                          ); 
    401           if (added) 
    402                 ray.mPvsContribution++; 
    403  
    404           ray.mRelativePvsContribution += contribution; 
    405         } 
    406   } else { 
    407     for (; it != viewcells.end(); ++it) { 
    408           ViewCell *viewcell = *it; 
    409           // if ray not outside of view space 
    410           float contribution; 
    411           if (viewcell->GetPvs().GetSampleContribution(ray.mTerminationObject, 
    412                                                                                                    contribution 
    413                                                                                                    )) 
    414                 ray.mPvsContribution++; 
    415  
    416           ray.mRelativePvsContribution += contribution; 
    417         } 
    418  
    419         for (it = viewcells.begin(); it != viewcells.end(); ++it) { 
    420           ViewCell *viewcell = *it; 
    421           // if ray not outside of view space 
    422           viewcell->GetPvs().AddSample(ray.mTerminationObject); 
    423         } 
    424   } 
     395        Vector3 origin = hray.Extrap(tmin); 
     396        Vector3 termination = hray.Extrap(tmax); 
     397 
     398        CastLineSegment(origin, 
     399                                        termination, 
     400                                        viewcells); 
     401        //Debug << "constribution: " << (int)viewcells.size() << endl; 
     402        // copy viewcells memory efficiently 
     403        const bool storeViewcells = false; 
     404        if (storeViewcells) 
     405        { 
     406                ray.mViewCells.reserve(viewcells.size()); 
     407                ray.mViewCells = viewcells; 
     408        } 
     409 
     410        ViewCellContainer::const_iterator it = viewcells.begin(); 
     411 
     412        bool addInPlace = false; 
     413 
     414        if (addInPlace)  
     415        { 
     416                for (; it != viewcells.end(); ++it) { 
     417                        ViewCell *viewcell = *it; 
     418 
     419                        // if ray not outside of view space 
     420                        float contribution; 
     421                        bool added = 
     422                        viewcell->GetPvs().AddSample(ray.mTerminationObject, 
     423                                                                                        contribution 
     424                                                                                        ); 
     425                        if (added) 
     426                        ray.mPvsContribution++; 
     427 
     428                        ray.mRelativePvsContribution += contribution; 
     429                } 
     430        }  
     431        else  
     432        { 
     433                for (; it != viewcells.end(); ++it) { 
     434                        ViewCell *viewcell = *it; 
     435                        // if ray not outside of view space 
     436                        float contribution; 
     437                        if (viewcell->GetPvs().GetSampleContribution(ray.mTerminationObject, 
     438                                                                                                                contribution 
     439                                                                                                                )) 
     440                        ray.mPvsContribution++; 
     441                        ray.mRelativePvsContribution += contribution; 
     442                } 
     443 
     444                for (it = viewcells.begin(); it != viewcells.end(); ++it) { 
     445                        ViewCell *viewcell = *it; 
     446                        // if ray not outside of view space 
     447                        viewcell->GetPvs().AddSample(ray.mTerminationObject); 
     448                } 
     449        } 
    425450} 
    426451 
     
    14561481                  << (int)constructionRays.size() << " samples" << endl; 
    14571482 
    1458         mVspKdTree->Construct(constructionRays, &mSceneBox); 
     1483        mVspKdTree->Construct(constructionRays, &mViewSpaceBox); 
    14591484        Debug << mVspKdTree->GetStatistics() << endl; 
    14601485 
     
    14681493        mVspKdTree->RefineViewCells(rays); 
    14691494 
    1470                 // collapse siblings belonging to the same view cell 
     1495        // collapse siblings belonging to the same view cell 
    14711496        mVspKdTree->CollapseTree(); 
    14721497 
     
    18271852        Debug << "saved rays: " << (int)savedRays.size() << endl; 
    18281853 
    1829         mVspBspTree->Construct(constructionRays, &mSceneBox); 
     1854        mVspBspTree->Construct(constructionRays, &mViewSpaceBox); 
    18301855 
    18311856        Debug << mVspBspTree->GetStatistics() << endl; 
     
    19822007        } 
    19832008 
    1984         EvaluateViewCellsStats(); 
    1985  
    1986         // view cells already finished post processing step 
     2009         
     2010        // view cells already finished before post processing step (i.e. because they were loaded) 
    19872011        if (mViewCellsFinished) 
     2012        { 
     2013                EvaluateViewCellsStats(); 
    19882014                return 0; 
     2015        } 
     2016         
     2017 
     2018        // check if new view cells turned invalid 
     2019        mVspBspTree->CheckValidy(); 
     2020        ResetViewCells(); 
     2021 
    19892022 
    19902023        VssRayContainer postProcessRays; 
     
    20382071        for (int i = 0; i < limit; ++ i) 
    20392072        { 
    2040                 viewPoint = mSceneBox.GetRandomPoint(); 
     2073                viewPoint = mViewSpaceBox.GetRandomPoint(); 
    20412074                if (mVspBspTree->ViewPointValid(viewPoint)) 
    20422075                { 
     
    20512084bool VspBspViewCellsManager::ViewPointValid(const Vector3 &viewPoint) const 
    20522085{ 
    2053         return mSceneBox.IsInside(viewPoint) && 
     2086        return mViewSpaceBox.IsInside(viewPoint) && 
    20542087                   mVspBspTree->ViewPointValid(viewPoint); 
    20552088} 
     
    20722105                if (exporter) 
    20732106                { 
     2107                        if (1) 
     2108                        { 
     2109                                exporter->SetWireframe(); 
     2110                                exporter->ExportBox(mViewSpaceBox); 
     2111                                exporter->SetFilled(); 
     2112                        } 
     2113 
    20742114                        if (mExportGeometry) 
     2115                        { 
    20752116                                exporter->ExportGeometry(objects); 
     2117                        } 
    20762118 
    20772119                        // export rays 
     
    20992141        } 
    21002142 
    2101         // export single view cells 
     2143        //-- export single view cells 
    21022144        ExportBspPvs(objects, visRays); 
    21032145} 
     
    21672209                VssRayContainer vcRays; 
    21682210                Intersectable::NewMail(); 
    2169 #if 0 
     2211#if 0 // largest view cell pvs first 
    21702212                BspViewCell *vc = dynamic_cast<BspViewCell *>(mViewCells[i]); 
    21712213#else 
     
    23012343                                                                                          ViewCell *vc) const 
    23022344{ 
    2303 #if 1 
    2304     if (vc->GetMesh()) 
     2345        if (vc->GetMesh()) 
    23052346        { 
    23062347                exporter->ExportMesh(vc->GetMesh()); 
     
    23122353                ConstructGeometry(dynamic_cast<BspViewCell *>(vc), geom); 
    23132354        exporter->ExportPolygons(geom.mPolys); 
    2314 #else 
    2315  
    2316         Material m2; 
    2317         m2.mDiffuseColor.b = 0.3f + Random(0.7f); 
    2318         m2.mDiffuseColor.r = 0.0f;//0.3f + Random(0.7f); 
    2319         m2.mDiffuseColor.g = 0.3f + Random(0.7f); 
    2320         Material m; 
    2321         m.mDiffuseColor.b = 0.0f; 
    2322         m.mDiffuseColor.r = 1.0f; 
    2323         m.mDiffuseColor.g = 0.0f; 
    2324  
    2325         BspViewCell *bspVc = dynamic_cast<BspViewCell *>(vc); 
    2326         vector<BspLeaf *>::const_iterator it, it_end = bspVc->mLeaves.end(); 
    2327  
    2328         for (it = bspVc->mLeaves.begin(); it != it_end; ++ it) 
    2329         { 
    2330                 if ((*it)->Mailed()) 
    2331                         exporter->SetForcedMaterial(m); 
    2332                 else 
    2333                         exporter->SetForcedMaterial(m2); 
    2334                         //exporter->ResetForcedMaterial(); 
    2335                 BspNodeGeometry geom; 
    2336                 mVspBspTree->ConstructGeometry(*it, geom); 
    2337                 exporter->ExportPolygons(geom.mPolys); 
    2338         } 
    2339 #endif 
    23402355} 
    23412356 
Note: See TracChangeset for help on using the changeset viewer.