Ignore:
Timestamp:
02/04/06 12:46:14 (18 years ago)
Author:
mattausch
Message:

updated vspkdtree for regular sudbivision

File:
1 edited

Legend:

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

    r586 r587  
    920920{ 
    921921        environment->GetIntValue("BspTree.Construction.samples", mInitialSamples); 
     922        mBspTree->SetViewCellsManager(this); 
    922923} 
    923924 
     
    965966        { 
    966967                // no view cells loaded 
    967                 mBspTree->Construct(objects, constructionRays); 
     968                mBspTree->Construct(objects, constructionRays, &mViewSpaceBox); 
    968969                // collect final view cells 
    969970                mBspTree->CollectViewCells(mViewCells); 
     
    986987 
    987988 
     989        ResetViewCells(); 
     990     
     991        Debug << "\nView cells after " << (int)savedRays.size()  
     992                  << " samples:\n" << mViewCellsStats << endl; 
     993 
     994        if (1) // export initial view cells 
     995        { 
     996                cout << "exporting initial view cells (=leaves) ... "; 
     997                Exporter *exporter = Exporter::GetExporter("view_cells.x3d"); 
     998 
     999                if (exporter) 
     1000                { 
     1001                        //exporter->SetWireframe(); 
     1002                        exporter->SetFilled(); 
     1003                        ExportViewCellsForViz(exporter); 
     1004 
     1005                        if (0 && mExportRays) 
     1006                                exporter->ExportRays(rays, RgbColor(1, 1, 1)); 
     1007 
     1008                        if (mExportGeometry) 
     1009                                exporter->ExportGeometry(objects); 
     1010 
     1011                        delete exporter; 
     1012                } 
     1013                cout << "finished" << endl; 
     1014        } 
     1015 
     1016 
    9881017        return sampleContributions; 
    9891018} 
     
    9921021void BspViewCellsManager::CollectViewCells() 
    9931022{ 
    994         mBspTree->CollectViewCells(mViewCells); 
     1023        // view cells tree constructed 
     1024        if (!ViewCellsTreeConstructed()) 
     1025        { 
     1026                mBspTree->CollectViewCells(mViewCells); 
     1027        } 
     1028        else  
     1029        { 
     1030                // we can use the view cells tree hierarchy to get the right set 
     1031                mViewCellsTree->CollectBestViewCellSet(mViewCells, mNumMergedViewCells); 
     1032        } 
    9951033} 
    9961034 
     
    10071045 
    10081046 
    1009 float BspViewCellsManager::GetRendercost(ViewCell *viewCell, float objRendercost) const 
     1047float BspViewCellsManager::GetRendercost(ViewCell *viewCell,  
     1048                                                                                 float objRendercost) const 
    10101049{ 
    10111050        return viewCell->GetPvs().GetSize() * objRendercost; 
     
    10721111 
    10731112        long startTime = GetTime(); 
    1074  
     1113         
     1114        VssRayContainer postProcessRays; 
     1115        GetRaySets(rays, mPostProcessSamples, postProcessRays); 
    10751116 
    10761117        //-- merge or subdivide view cells 
    1077         int merged = 0; 
    1078  
    1079         // TODO 
    1080          
     1118        int merged = mViewCellsTree->ConstructMergeTree(rays, objects); 
     1119 
    10811120        //-- stats and visualizations 
    10821121        cout << "finished" << endl; 
     
    10881127                  << "using " << (int)rays.size() << " samples" << endl << endl; 
    10891128 
     1129 
    10901130        // reset view cells and stats 
    10911131        ResetViewCells(); 
     1132        FinalizeViewCells(true); 
     1133         
     1134        // for output we need unique ids for each view cell 
     1135        CreateUniqueViewCellIds(); 
     1136 
     1137        // write view cells to disc 
     1138        if (mExportViewCells) 
     1139        { 
     1140                char buff[100]; 
     1141                environment->GetStringValue("ViewCells.filename", buff); 
     1142                string vcFilename(buff); 
     1143 
     1144                ExportViewCells(buff); 
     1145        } 
    10921146 
    10931147        return merged; 
     
    11121166                return; 
    11131167         
    1114         if (1) // export view cells 
    1115         { 
     1168        //BspLeaf::NewMail(); 
     1169        if (1) // export merged view cells 
     1170        { 
     1171 
     1172                cout << "reseting view cells ... "; 
     1173                ResetViewCells(); 
     1174 
     1175                cout << "finished" << endl; 
     1176 
     1177                Exporter *exporter = Exporter::GetExporter("merged_view_cells.x3d"); 
     1178                Debug << "\nView cells after merge:\n" << mViewCellsStats << endl; 
     1179 
    11161180                cout << "exporting view cells after merge ... "; 
    1117                 Exporter *exporter = Exporter::GetExporter("merged_view_cells.x3d"); 
    1118  
    11191181 
    11201182                if (exporter) 
    11211183                { 
     1184                        if (0) 
     1185                                exporter->SetWireframe(); 
     1186                        else 
     1187                                exporter->SetFilled(); 
    11221188                        ExportViewCellsForViz(exporter); 
     1189 
     1190                        if (mExportGeometry) 
     1191                        { 
     1192                                Material m; 
     1193                                m.mDiffuseColor = RgbColor(0, 1, 0); 
     1194                                exporter->SetForcedMaterial(m); 
     1195                                exporter->SetFilled(); 
     1196 
     1197                                exporter->ExportGeometry(objects); 
     1198                        } 
     1199 
    11231200                        delete exporter; 
    11241201                } 
    1125  
    11261202                cout << "finished" << endl; 
    11271203        } 
     
    11891265 
    11901266        // sort view cells to get largest view cells 
    1191 #if 0 
    1192         stable_sort(mViewCells.begin(), mViewCells.end(), vc_gt); 
    1193 #endif 
     1267        if (0) 
     1268                stable_sort(mViewCells.begin(), mViewCells.end(), vc_gt); 
     1269 
    11941270        int limit = min(leafOut, (int)mViewCells.size()); 
    11951271 
     
    12081284                cout << "creating output for view cell " << i << " ... "; 
    12091285 
    1210 #if 0 
    1211                 // check whether we can add the current ray to the output rays 
    1212                 for (int k = 0; k < raysOut; ++ k) 
    1213                 { 
    1214                         BspRay *ray = mBspRays[k]; 
    1215                         for     (int j = 0; j < (int)ray->intersections.size(); ++ j) 
     1286                if(0) 
     1287                { 
     1288                        // check whether we can add the current ray to the output rays 
     1289                        for (int k = 0; k < raysOut; ++ k) 
    12161290                        { 
    1217                                 BspLeaf *leaf = ray->intersections[j].mLeaf; 
    1218                                 if (vc == leaf->GetViewCell()) 
    1219                                         vcRays.push_back(ray->vssRay); 
     1291                                BspRay *ray = mBspRays[k]; 
     1292                                for     (int j = 0; j < (int)ray->intersections.size(); ++ j) 
     1293                                { 
     1294                                        BspLeaf *leaf = ray->intersections[j].mLeaf; 
     1295                                        if (vc == leaf->GetViewCell()) 
     1296                                                vcRays.push_back(ray->vssRay); 
     1297                                } 
    12201298                        } 
    12211299                } 
    1222 #endif 
     1300 
    12231301                //bspLeaves[j]->Mail(); 
    12241302                char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i); 
     
    12321310                exporter->SetForcedMaterial(m); 
    12331311 
    1234                 if (vc->GetMesh()) 
    1235                         exporter->ExportViewCell(vc); 
    1236                 else 
    1237                 { 
    1238                         BspNodeGeometry vcGeom; 
    1239  
    1240                         //-- export view cell 
    1241 #if VC_HISTORY 
    1242                         mBspTree->ConstructGeometry(vc, vcGeom); 
    1243                         exporter->ExportPolygons(vcGeom.mPolys); 
    1244 #endif 
    1245                 } 
     1312                ExportViewCellGeometry(exporter, vc); 
     1313                 
    12461314 
    12471315                Debug << i << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc) 
     
    12841352 
    12851353 
    1286  
    1287 void BspViewCellsManager::ConstructBspRays(const VssRayContainer &rays, 
    1288                                                                                    const int numSamples) 
    1289 { 
    1290         VssRayContainer::const_iterator it, it_end = rays.end(); 
    1291  
    1292         for (it = rays.begin(); it != rays.end() && mBspRays.size() < numSamples; ++ it) 
    1293         { 
    1294                 VssRay *vssRay = *it; 
    1295                 BspRay *ray = new BspRay(vssRay); 
    1296  
    1297                 ViewCellContainer viewCells; 
    1298  
    1299                 // cast line segment to get intersections with bsp leaves 
    1300                 CastLineSegment(vssRay->mTermination, vssRay->mOrigin, viewCells); 
    1301 #if VC_HISTORY 
    1302                 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
    1303                 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
    1304                 { 
    1305                         ViewCell *vc = *vit; 
    1306                         ray->intersections.push_back(BspIntersection(0, vc->mLeaf)); 
    1307                 } 
    1308 #endif 
    1309                 mBspRays.push_back(ray); 
    1310         } 
    1311 } 
    1312  
    1313  
    13141354void BspViewCellsManager::ExportColor(Exporter *exporter, 
    13151355                                                                          ViewCell *vc) const 
     
    13541394} 
    13551395 
     1396 
    13561397void BspViewCellsManager::ExportViewCellGeometry(Exporter *exporter, 
    1357                                                                                 ViewCell *vc) const 
     1398                                                                                                ViewCell *vc) const 
    13581399{ 
    13591400        if (vc->GetMesh()) 
    1360                 exporter->ExportViewCell(vc); 
     1401        { 
     1402                exporter->ExportMesh(vc->GetMesh()); 
     1403                return; 
     1404        } 
     1405 
     1406        BspNodeGeometry geom; 
     1407        mBspTree->ConstructGeometry(vc, geom); 
     1408        exporter->ExportPolygons(geom.mPolys); 
     1409} 
     1410 
     1411 
     1412void BspViewCellsManager::CreateMesh(ViewCell *vc) 
     1413{ 
     1414        if (vc->GetMesh()) 
     1415                delete vc->GetMesh(); 
     1416 
     1417        BspNodeGeometry geom; 
     1418         
     1419        mBspTree->ConstructGeometry(vc, geom); 
     1420 
     1421        Mesh *mesh = new Mesh(); 
     1422        geom.AddToMesh(*mesh); 
     1423        vc->SetMesh(mesh); 
     1424        mMeshContainer.push_back(mesh); 
     1425} 
     1426 
     1427 
     1428void BspViewCellsManager::Finalize(ViewCell *viewCell,  
     1429                                                                   const bool createMesh) 
     1430{ 
     1431        CreateMesh(viewCell); 
     1432 
     1433        float area = 0; 
     1434        float volume = 0; 
     1435 
     1436        ViewCellContainer leaves; 
     1437        mViewCellsTree->CollectLeaves(viewCell, leaves); 
     1438 
     1439        ViewCellContainer::const_iterator it, it_end = leaves.end(); 
     1440 
     1441        for (it = leaves.begin(); it != it_end; ++ it) 
     1442        { 
     1443                BspNodeGeometry geom; 
     1444                BspLeaf *leaf = dynamic_cast<BspViewCell *>(*it)->mLeaf; 
     1445                mBspTree->ConstructGeometry(leaf, geom); 
     1446 
     1447                area += geom.GetArea(); 
     1448                volume += geom.GetVolume(); 
     1449        } 
     1450 
     1451        viewCell->SetVolume(volume); 
     1452        viewCell->SetArea(area); 
     1453} 
     1454 
     1455 
     1456ViewCell *BspViewCellsManager::GetViewCell(const Vector3 &point) const 
     1457{ 
     1458        if (!mBspTree) 
     1459                return NULL; 
     1460 
     1461        if (!mViewSpaceBox.IsInside(point)) 
     1462                return NULL; 
     1463         
     1464        return mBspTree->GetViewCell(point); 
     1465} 
     1466 
     1467 
     1468void BspViewCellsManager::CollectMergeCandidates(const VssRayContainer &rays,  
     1469                                                                                                 vector<MergeCandidate> &candidates) 
     1470{ 
     1471        cout << "collecting merge candidates ... " << endl; 
     1472 
     1473        if (mUseRaysForMerge) 
     1474        { 
     1475                mBspTree->CollectMergeCandidates(rays, candidates); 
     1476        } 
    13611477        else 
    13621478        { 
    1363                 BspNodeGeometry geom; 
    1364 #if VC_HISTORY 
    1365                 mBspTree->ConstructGeometry(vc, geom); 
    1366                 exporter->ExportPolygons(geom.mPolys); 
    1367 #endif 
    1368         } 
    1369 } 
    1370  
    1371  
    1372 void BspViewCellsManager::CreateMesh(ViewCell *vc) 
    1373 { 
    1374         // TODO 
    1375 } 
    1376  
    1377  
    1378 ViewCell *BspViewCellsManager::GetViewCell(const Vector3 &point) const 
    1379 { 
    1380   if (!mBspTree) 
    1381         return NULL; 
    1382  
    1383   if (!mViewSpaceBox.IsInside(point)) 
    1384         return NULL; 
    1385  
    1386   return mBspTree->GetViewCell(point); 
    1387 } 
    1388  
    1389  
    1390 void BspViewCellsManager::CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates) 
    1391 { 
    1392         // TODO 
     1479                vector<BspLeaf *> leaves; 
     1480                mBspTree->CollectLeaves(leaves); 
     1481                mBspTree->CollectMergeCandidates(leaves, candidates); 
     1482        } 
     1483 
     1484        cout << "fininshed collecting candidates" << endl; 
    13931485} 
    13941486 
     
    14531545        return 0; 
    14541546} 
     1547 
    14551548 
    14561549bool KdViewCellsManager::ViewCellsConstructed() const 
     
    21542247        VssRayContainer savedRays; 
    21552248 
    2156         Debug << "samples used for subdivision: " << mInitialSamples << " rays: " << (int)rays.size() << endl; 
     2249        Debug << "samples used for subdivision: " << mInitialSamples  
     2250                  << " rays: " << (int)rays.size() << endl; 
     2251 
    21572252        GetRaySets(rays, mInitialSamples, constructionRays, &savedRays); 
    21582253 
     
    21702265        long startTime = GetTime(); 
    21712266        int collapsedLeaves = mVspBspTree->CollapseTree(); 
    2172         Debug << "collapsed in " << TimeDiff(startTime, GetTime()) * 1e-3 << " seconds" << endl; 
     2267        Debug << "collapsed in " << TimeDiff(startTime, GetTime()) * 1e-3  
     2268                  << " seconds" << endl; 
     2269 
    21732270    cout << "finished" << endl; 
    21742271 
     
    22572354                cout << "reseting view cells ... "; 
    22582355                ResetViewCells(); 
     2356 
    22592357                cout << "finished" << endl; 
    22602358 
     
    26852783 
    26862784        // sort view cells to visualize the largest view cells 
    2687 #if 0 
    2688         stable_sort(mViewCells.begin(), mViewCells.end(), vc_gt); 
    2689 #endif 
     2785        if (0) 
     2786                stable_sort(mViewCells.begin(), mViewCells.end(), vc_gt); 
     2787 
    26902788        int limit = min(leafOut, (int)mViewCells.size()); 
    26912789 
    2692 #if 1 
     2790        int raysOut; 
     2791 
    26932792        //-- some rays for output 
    2694         const int raysOut = min((int)rays.size(), mVisualizationSamples); 
    2695  
    2696 #endif 
     2793        if (1) 
     2794                raysOut = min((int)rays.size(), mVisualizationSamples); 
    26972795 
    26982796        for (int i = 0; i < limit; ++ i) 
     
    27092807                        vc = mViewCells[Random((int)mViewCells.size())]; 
    27102808 
     2809                vector<ViewCell *> leaves; 
     2810                mViewCellsTree->CollectLeaves(vc, leaves); 
     2811 
    27112812        if (1) 
    27122813                { 
     
    27182819                                { 
    27192820                                        ViewCell *rayvc = ray->mViewCells[j]; 
    2720 #if VC_HISTORY 
    2721                                         BspLeaf *leaf = rayvc->mLeaf; 
    2722                                         if (vc == rayvc) 
     2821 
     2822                                        if (leaves[0] == rayvc) 
    27232823                                                vcRays.push_back(ray); 
    2724 #endif 
    27252824                                } 
    27262825                        } 
     
    30213120 
    30223121 
    3023 void VspBspViewCellsManager::Finalize(ViewCell *viewCell, const bool createMesh) 
     3122void VspBspViewCellsManager::Finalize(ViewCell *viewCell,  
     3123                                                                          const bool createMesh) 
    30243124{ 
    30253125        CreateMesh(viewCell); 
Note: See TracChangeset for help on using the changeset viewer.