Ignore:
Timestamp:
12/05/05 04:42:54 (19 years ago)
Author:
mattausch
Message:

fixed bug in VspBspTree?
view cells in VssPreprocessor?
bounding rays for vspkdtree

File:
1 edited

Legend:

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

    r444 r448  
    6868 
    6969void ViewCellsManager::ComputeSampleContributions(const RayContainer &rays,  
    70                                                                                                   const bool castRays, 
    7170                                                                                                  int &sampleContributions, 
    72                                                                                                   int &contributingSamples) 
     71                                                                                                  int &contributingSamples, 
     72                                                                                                  const bool castRays) 
    7373{ 
    7474        // view cells not yet constructed 
     
    168168SimulationStatistics ViewCellsManager::SimulateRendering() const 
    169169{ 
    170         if (!ViewCellsConstructed()) 
     170        if (!ViewCellsConstructed() || !mRenderSimulator) 
    171171                return SimulationStatistics(); 
    172172 
     
    240240                return 0; 
    241241 
    242         Debug << "Constructing bsp view cells" << endl; 
    243  
    244242        int sampleContributions = 0; 
    245243         
     
    247245 
    248246        int limit = min (mConstructionSamples, (int)rays.size()); 
     247 
     248        // construct view cells using the collected samples 
     249        Debug << "construcing bsp view cells from "  
     250                  << limit << " samples " << endl; 
    249251 
    250252    for (int i = 0; i < limit; ++ i) 
     
    332334        int pvsSize = 0; 
    333335 
    334         BspViewCellsStatistics stat; 
    335         mBspTree->EvaluateViewCellsStats(stat); 
    336         Debug << "original view cell partition:\n" << stat << endl; 
    337                  
    338         if (1) // export view cells 
     336        BspViewCellsStatistics vcStats; 
     337        mBspTree->EvaluateViewCellsStats(vcStats); 
     338        Debug << "original view cell partition:\n" << vcStats << endl; 
     339                 
     340        if (1) // export view cells before merge 
    339341        { 
    340342                cout << "exporting initial view cells (=leaves) ... "; 
     
    344346                { 
    345347                        exporter->SetWireframe(); 
    346                         exporter->ExportBspLeaves(*mBspTree, stat.maxPvs); 
     348                        exporter->ExportBspLeaves(*mBspTree, vcStats.maxPvs); 
    347349                        //exporter->ExportBspViewCellPartition(*mBspTree, 0); 
    348350                                 
     
    360362                } 
    361363                cout << "finished" << endl; 
    362         } 
     364 
     365                //-- render simulation 
     366                cout << "\nevaluating bsp view cells render time before merge ... "; 
     367                  
     368                const SimulationStatistics ss = SimulateRendering(); 
     369                          
     370                cout << " finished" << endl; 
     371                cout << ss << endl; 
     372                Debug << ss << endl; 
     373        } 
     374 
    363375 
    364376        cout << "starting post processing using " << mPostProcessSamples << " samples ... "; 
    365                  
     377 
    366378        long startTime = GetTime(); 
    367  
    368379 
    369380        //-- merge or subdivide view cells 
     
    408419        cout << "merged " << merged << " view cells in " 
    409420                 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl; 
     421 
     422        // statistics after post process 
     423        vcStats.Reset(); 
     424        mBspTree->EvaluateViewCellsStats(vcStats); 
     425        Debug << "post processed view cell partition:\n" << vcStats << endl; 
    410426 
    411427        return merged; 
     
    956972mVspKdTree(vspKdTree) 
    957973{ 
    958    mRenderSimulator = NULL; // TODO: new VspKdRenderSimulator(vspKdTree); 
     974   mRenderSimulator = NULL;//new VspKdRenderSimulator(vspKdTree); 
    959975   InitRenderSimulator(); 
    960976} 
     
    983999                return 0; 
    9841000 
    985         //if (castRay) // TODO 
     1001        //if (castRay) 
     1002                //mVspKdTree->CastRay(ray); 
    9861003 
    9871004        int sampleContributions = 0; 
    9881005 
    989 /* 
    990     for (int i = 0; i < (int)rays.size(); ++ i) 
    991         { 
    992                 Ray *ray = rays[i]; 
    993  
    994                 mBspTree->CastRay(*ray); 
    995                          
    996                 Intersectable *term =  
    997                         !ray->intersections.empty() ? ray->intersections[0].mObject : NULL 
    998                         ; 
    999                 sampleContributions +=  
    1000                         AddSampleContributions(*ray, ray->sourceObject.mObject, term); 
    1001                          
    1002         } 
    1003 */ 
    10041006        return sampleContributions; 
    10051007} 
     
    11211123mVspBspTree(vspBspTree) 
    11221124{ 
    1123    mRenderSimulator = NULL;// TODO new VspBspRenderSimulator(bspTree); 
    1124    //InitRenderSimulator(); 
     1125        mRenderSimulator = new VspBspRenderSimulator(vspBspTree); 
     1126        InitRenderSimulator(); 
    11251127} 
    11261128 
     
    11821184                for (int j = 0; j < (int)ray.bspIntersections.size(); ++ j) 
    11831185                {        
    1184                         VspBspLeaf *leaf = NULL;  //TODO ray.bspIntersections[j].mLeaf; 
     1186                        BspLeaf *leaf = ray.bspIntersections[j].mLeaf; 
    11851187                 
    11861188                        // if ray not in unbounded space 
     
    12061208                for (int j = 1; j < ((int)ray.bspIntersections.size() - 1); ++ j)  
    12071209                { 
    1208                         VspBspLeaf *leaf = NULL;// TODO = ray.bspIntersections[j].mLeaf; 
     1210                        BspLeaf *leaf = ray.bspIntersections[j].mLeaf; 
    12091211 
    12101212                        if (leaf->GetViewCell() != mVspBspTree->GetRootCell()) 
     
    12191221                                                                                const RayContainer &rays) 
    12201222{ 
    1221         return 0;// TODO 
    12221223        if (!ViewCellsConstructed()) 
    12231224        { 
     
    12311232        int pvsSize = 0; 
    12321233 
    1233         VspBspViewCellsStatistics vcStats; 
     1234        BspViewCellsStatistics vcStats; 
    12341235        mVspBspTree->EvaluateViewCellsStats(vcStats); 
    12351236        Debug << "original view cell partition:\n" << vcStats << endl; 
     
    12431244                { 
    12441245                        exporter->SetWireframe(); 
    1245                         //exporter->ExportBspLeaves(*mVspBspTree, stat.maxPvs); 
     1246                        exporter->ExportBspViewCellPartition(*mVspBspTree, vcStats.maxPvs); 
    12461247                                 
    12471248                        if (0) 
     
    12841285                iit = ray->bspIntersections.begin(); 
    12851286 
    1286                 VspBspLeaf *previousLeaf = NULL;//TODO(*iit).mLeaf; 
     1287                BspLeaf *previousLeaf = (*iit).mLeaf; 
    12871288                ++ iit; 
    12881289                 
    12891290                for (; iit != ray->bspIntersections.end(); ++ iit) 
    12901291                { 
    1291                         VspBspLeaf *leaf = NULL;//TODO(*iit).mLeaf; 
     1292                        BspLeaf *leaf = (*iit).mLeaf; 
    12921293 
    12931294                        if (ShouldMerge(leaf, previousLeaf)) 
     
    13071308                 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl; 
    13081309 
     1310        // statistics after post process 
     1311        vcStats.Reset(); 
     1312        mVspBspTree->EvaluateViewCellsStats(vcStats); 
     1313        Debug << "post processed view cell partition:\n" << vcStats << endl; 
     1314 
    13091315        return merged; 
    13101316} 
     
    13191325                                                                           const RayContainer &sampleRays) 
    13201326{ 
    1321         return; // TODO 
    13221327        if (!ViewCellsConstructed()) 
    13231328                return; 
    13241329 
    13251330        //-- recount pvs 
    1326         VspBspViewCellsStatistics vcStats; 
     1331        BspViewCellsStatistics vcStats; 
    13271332        mVspBspTree->EvaluateViewCellsStats(vcStats); 
    13281333 
     
    13301335        { 
    13311336                cout << "exporting view cells after merge ... "; 
    1332                 /*Exporter *exporter = Exporter::GetExporter("merged_view_cells.x3d"); 
     1337                Exporter *exporter = Exporter::GetExporter("merged_view_cells.x3d"); 
    13331338 
    13341339                if (exporter) 
     
    13371342                        delete exporter; 
    13381343                } 
    1339                 */ 
     1344                 
    13401345                cout << "finished" << endl; 
    13411346        }        
     
    13431348        //-- visualization of the BSP splits 
    13441349        bool exportSplits = false; 
    1345                 environment->GetBoolValue("BspTree.Visualization.exportSplits", exportSplits); 
     1350        environment->GetBoolValue("BspTree.Visualization.exportSplits", exportSplits); 
    13461351         
    13471352        if (exportSplits) 
     
    13521357        } 
    13531358 
    1354 //TODO  ExportVspBspPvs(objects, sampleRays); 
     1359        ExportBspPvs(objects, sampleRays); 
    13551360} 
    13561361 
     
    13671372                exporter->SetForcedMaterial(m); 
    13681373                exporter->SetWireframe(); 
    1369                 // TODO 
    1370                 //exporter->ExportBspSplits(*mVspBspTree, true); 
     1374                 
     1375                exporter->ExportBspSplits(*mVspBspTree, true); 
    13711376 
    13721377                // take forced material, else big scenes cannot be viewed 
     
    14121417        const int raysOut = min((int)sampleRays.size(), mVisualizationSamples); 
    14131418        cout << "visualization using " << mVisualizationSamples << " samples" << endl; 
    1414         vector<Ray *> vcRays[leafOut]; 
    1415  
    1416         if (0) 
     1419         
     1420        if (1) 
    14171421        { 
    14181422                //-- some random view cells and rays for output 
    1419                 vector<VspBspLeaf *> vspBspLeaves; 
     1423                vector<BspLeaf *> vspBspLeaves; 
    14201424 
    14211425                for (int i = 0; i < leafOut; ++ i) 
     
    14241428                for (int i = 0; i < (int)vspBspLeaves.size(); ++ i) 
    14251429                { 
     1430                        RayContainer vcRays; 
    14261431                        cout << "creating output for view cell " << i << " ... "; 
    14271432                        // check whether we can add the current ray to the output rays 
    1428                         for (int k = 0; k < raysOut; ++ k)  
     1433                        /*for (int k = 0; k < raysOut; ++ k)  
    14291434                        { 
    14301435                                Ray *ray = sampleRays[k]; 
     
    14361441                                        if (vspBspLeaves[i]->GetViewCell() == leaf->GetViewCell())  
    14371442                                        { 
    1438                                                 vcRays[i].push_back(ray); 
     1443                                                vcRays.push_back(ray); 
    14391444                                        } 
    14401445                                } 
    14411446                        } 
     1447                        */ 
    14421448 
    14431449                        Intersectable::NewMail(); 
     
    14741480 
    14751481                        Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize()  
    1476                                         << ", piercing rays=" << (int)vcRays[i].size() << endl; 
     1482                                        << ", piercing rays=" << (int)vcRays.size() << endl; 
    14771483 
    14781484                        // export rays piercing this view cell 
    1479                         exporter->ExportRays(vcRays[i], 1000, RgbColor(0, 1, 0)); 
    1480  
    1481                         m.mDiffuseColor = RgbColor(1, 0, 0); 
     1485                        exporter->ExportRays(vcRays, 1000, RgbColor(1, 0, 0)); 
     1486                        exporter->ExportRays(vspBspLeaves[i]->mVssRays, RgbColor(1, 1, 1)); 
     1487                         
     1488                        m.mDiffuseColor = RgbColor(0, 1, 1); 
    14821489                        exporter->SetForcedMaterial(m); 
    14831490 
    1484                         // exporter->SetWireframe(); 
    1485                         exporter->SetFilled(); 
     1491                        exporter->SetWireframe(); 
     1492                        //exporter->SetFilled(); 
    14861493 
    14871494                        // output PVS of view cell 
     
    15271534                { 
    15281535                        cout << "creating output for view cell " << i << " ... "; 
    1529                          
     1536                        RayContainer vcRays; 
    15301537            Intersectable::NewMail(); 
    15311538                        BspViewCell *vc = dynamic_cast<BspViewCell *>(viewCells[i]); 
     
    15391546                                for     (int j = 0; j < (int)ray->bspIntersections.size(); ++ j) 
    15401547                                { 
    1541                                         VspBspLeaf *leaf = NULL; // TODO = ray->bspIntersections[j].mLeaf; 
     1548                                        BspLeaf *leaf = ray->bspIntersections[j].mLeaf; 
    15421549 
    15431550                                        if (vc == leaf->GetViewCell())  
    15441551                                        { 
    1545                                                 vcRays[i].push_back(ray); 
     1552                                                vcRays.push_back(ray); 
    15461553                                        } 
    15471554                                } 
     
    15721579                         
    15731580                        Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize()  
    1574                                         << ", piercing rays=" << (int)vcRays[i].size() << endl; 
     1581                                        << ", piercing rays=" << (int)vcRays.size() << endl; 
    15751582 
    15761583                         
    15771584                        // export rays piercing this view cell 
    1578                         exporter->ExportRays(vcRays[i], 1000, RgbColor(0, 1, 0)); 
     1585                        exporter->ExportRays(vcRays, 1000, RgbColor(0, 1, 0)); 
    15791586         
    15801587                        m.mDiffuseColor = RgbColor(1, 0, 0); 
     
    16071614 
    16081615 
    1609 bool VspBspViewCellsManager::MergeVspBspLeafViewCells(VspBspLeaf *front,  
    1610                                                                                                           VspBspLeaf *back) const 
     1616bool VspBspViewCellsManager::MergeVspBspLeafViewCells(BspLeaf *front,  
     1617                                                                                                          BspLeaf *back) const 
    16111618{ 
    16121619        BspViewCell *viewCell =  
     
    16231630        BspViewCell *bVc = back->GetViewCell(); 
    16241631 
    1625         // TODO 
    1626         /*vector<VspBspLeaf *> fLeaves = fVc->mBspLeaves; 
    1627         vector<VspBspLeaf *> bLeaves = bVc->mBspLeaves; 
    1628  
    1629         vector<VspBspLeaf *>::const_iterator it; 
     1632        vector<BspLeaf *> fLeaves = fVc->mBspLeaves; 
     1633        vector<BspLeaf *> bLeaves = bVc->mBspLeaves; 
     1634 
     1635        vector<BspLeaf *>::const_iterator it; 
    16301636         
    16311637        for (it = fLeaves.begin(); it != fLeaves.end(); ++ it) 
     
    16421648        DEL_PTR(fVc); 
    16431649        DEL_PTR(bVc); 
    1644 */ 
     1650 
    16451651        return true; 
    16461652} 
    16471653 
    1648 bool VspBspViewCellsManager::ShouldMerge(VspBspLeaf *front, VspBspLeaf *back) const 
     1654bool VspBspViewCellsManager::ShouldMerge(BspLeaf *front, BspLeaf *back) const 
    16491655{ 
    16501656        ViewCell *fvc = front->GetViewCell(); 
Note: See TracChangeset for help on using the changeset viewer.