Ignore:
Timestamp:
10/03/06 22:03:58 (18 years ago)
Author:
mattausch
Message:

fixed bug with view space box

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1557 r1563  
    233233  Mesh *m = vc->GetMesh(); 
    234234   
    235   if (m) { 
    236         m->ComputeBoundingBox(); 
    237         return m->mBox; 
     235  if (m)  
     236  { 
     237          m->ComputeBoundingBox(); 
     238          return m->mBox; 
    238239  } 
    239240 
    240241  AxisAlignedBox3 box; 
    241    
    242242  box.Initialize(); 
    243243   
     
    289289        { 
    290290                VssRayContainer::const_iterator it, it_end = rays.end(); 
    291  
    292291                for (it = rays.begin(); it != it_end; ++ it) 
    293292                { 
     
    298297        { 
    299298                VssRayContainer::const_iterator it, it_end = rays.end(); 
    300  
    301299                for (it = rays.begin(); it != it_end; ++ it) 
    302300                { 
    303                         //(*it)->Unref(); 
    304301                        if (!(*it)->IsActive()) 
    305302                                delete (*it); 
     
    322319        mPreprocessor = preprocessor; 
    323320         
    324          
     321 
    325322        /////////////////////////////////////////////////////// 
    326323        //-- Initial sampling for the construction of the view cell hierarchy.  
     
    361358        { 
    362359                //-- export initial view cell partition 
    363                 Debug << "\nView cells after initial sampling:\n"  
    364                           << mCurrentViewCellsStats << endl; 
     360                Debug << "\nView cells after initial sampling:\n" << mCurrentViewCellsStats << endl; 
    365361 
    366362                const string filename("viewcells.wrl"); 
     
    428424 
    429425         
    430 #if 0 
    431         /////////////// 
    432         //-- Get stats after the additional sampling step 
    433         //-- and before the bottom-up merge step 
    434  
    435         EvaluateViewCellsStats(); 
    436         Debug << "\noriginal view cell partition before post process:\n"  
    437                   << mCurrentViewCellsStats << endl; 
    438  
    439         mRenderer->RenderScene(); 
    440         SimulationStatistics ss; 
    441         dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss); 
    442  
    443     Debug << ss << endl; 
    444 #endif 
    445  
     426        if (0) 
     427        { 
     428                /////////////// 
     429                //-- Get stats after the additional sampling step 
     430                //-- and before the bottom-up merge step 
     431 
     432                EvaluateViewCellsStats(); 
     433                Debug << "\noriginal view cell partition before post process:\n"  
     434                          << mCurrentViewCellsStats << endl; 
     435         
     436                mRenderer->RenderScene(); 
     437                SimulationStatistics ss; 
     438                dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss); 
     439 
     440                Debug << ss << endl; 
     441        } 
    446442 
    447443        //////////////////// 
     
    612608{ 
    613609        ViewCellsParser parser; 
    614  
    615610        ViewCellsManager *vm = NULL; 
    616611 
    617612        if (parser.ParseViewCellsFile(filename, &vm, objects, bconverter)) 
    618613        { 
    619                 long startTime = GetTime(); 
     614                const long startTime = GetTime(); 
    620615 
    621616                vm->ResetViewCells(); 
     
    671666                for (oit = objects.begin(); oit != oit_end; ++ oit) 
    672667                { 
    673                         MeshInstance *mi = dynamic_cast<MeshInstance *>(*oit); 
    674                         const AxisAlignedBox3 box = mi->GetBox(); 
     668                        const AxisAlignedBox3 box = (*oit)->GetBox(); 
    675669 
    676670                        //////////// 
    677671                        //-- the bounding boxes 
    678                         stream << "<BoundingBox" << " id=\"" << mi->GetId() << "\"" 
     672                        stream << "<BoundingBox" << " id=\"" << (*oit)->GetId() << "\"" 
    679673                                   << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 
    680674                                   << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; 
     
    12621256                                                                                         const bool extrudeBaseTriangles) 
    12631257{ 
    1264         bool success; 
    1265  
    12661258        /// we use predefined view cells from now on 
    12671259        mUsePredefinedViewCells = true; 
     
    12711263        { 
    12721264                Environment::GetSingleton()->GetFloatValue("ViewCells.height", parser.mViewCellHeight); 
    1273                 success = parser.ParseFile(filename, *this); 
     1265                const bool success = parser.ParseFile(filename, *this); 
     1266 
     1267                if (!success) 
     1268                        return false; 
    12741269        } 
    12751270        else 
     
    12771272                // hack: use standard mesh loading 
    12781273                // create temporary scene graph for loading the view cells geometry 
     1274                // note: delete the meshes as they are created two times for transformed mesh instances. 
    12791275                SceneGraphNode *root = new SceneGraphNode(); 
    1280                 success = parser.ParseFile(filename, root, true); 
    1281                                  
    1282                 if (success) 
    1283                 { 
    1284                         ObjectContainer::const_iterator oit, oit_end = root->mGeometry.end(); 
    1285                         for (oit = root->mGeometry.begin(); oit != oit_end; ++ oit) 
     1276                const bool success = parser.ParseFile(filename, root, true); 
     1277                 
     1278                if (!success) 
     1279                { 
     1280                        DEL_PTR(root); 
     1281                        return false; 
     1282                } 
     1283 
     1284                ObjectContainer::const_iterator oit, oit_end = root->mGeometry.end(); 
     1285                 
     1286                for (oit = root->mGeometry.begin(); oit != oit_end; ++ oit) 
     1287                { 
     1288                        Mesh *mesh; 
     1289                        if ((*oit)->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE) 
    12861290                        { 
    1287                                 if ((*oit)->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE) 
    1288                                 { 
    1289                                         TransformedMeshInstance *mit = dynamic_cast<TransformedMeshInstance *>(*oit); 
    1290                                         Mesh *mesh = MeshManager::GetSingleton()->CreateResource(); 
    1291                                         mit->GetTransformedMesh(*mesh); 
    1292                                         mesh->ComputeBoundingBox(); 
    1293                                         mViewCells.push_back(GenerateViewCell(mesh)); 
    1294                                 } 
    1295                                 else if ((*oit)->Type() == Intersectable::MESH_INSTANCE) 
    1296                                 { 
    1297                                         MeshInstance *mit = dynamic_cast<MeshInstance *>(*oit); 
    1298                                         mViewCells.push_back(GenerateViewCell(mit->GetMesh())); 
    1299                                 }                        
     1291                                TransformedMeshInstance *mit = dynamic_cast<TransformedMeshInstance *>(*oit); 
     1292                                mesh = MeshManager::GetSingleton()->CreateResource(); 
     1293                                mit->GetTransformedMesh(*mesh); 
    13001294                        } 
    1301                 } 
     1295                        else if ((*oit)->Type() == Intersectable::MESH_INSTANCE) 
     1296                        { 
     1297                                MeshInstance *mit = dynamic_cast<MeshInstance *>(*oit); 
     1298                                mesh = mit->GetMesh(); 
     1299                        } 
     1300                        mesh->ComputeBoundingBox(); 
     1301                        mViewCells.push_back(GenerateViewCell(mesh)); 
     1302                } 
     1303 
    13021304                DEL_PTR(root); 
    13031305        } 
    13041306 
    1305         if (success) 
    1306         { 
    1307                 // set view space box to bounding box of the view cells 
    1308                 AxisAlignedBox3 bbox; 
    1309                 bbox.Initialize(); 
    1310                 ViewCellContainer::iterator it = mViewCells.begin(), it_end = mViewCells.end(); 
    1311                 for (; it != it_end; ++ it)  
    1312                 { 
    1313                         bbox.Include(GetViewCellBox(*it)); 
    1314                 } 
    1315                 SetViewSpaceBox(bbox); 
    1316          
    1317                 cout << "generated " << (int)mViewCells.size() << " view cells using the geometry from file " << filename << endl; 
    1318         } 
    1319  
    1320         return success; 
     1307        // set view space box to bounding box of the view cells 
     1308        AxisAlignedBox3 bbox; 
     1309        bbox.Initialize(); 
     1310        ViewCellContainer::iterator it = mViewCells.begin(), it_end = mViewCells.end(); 
     1311 
     1312        for (; it != it_end; ++ it)  
     1313        { 
     1314                bbox.Include((*it)->GetMesh()->mBox); 
     1315        } 
     1316 
     1317        SetViewSpaceBox(bbox); 
     1318        cout << "view space box: " << bbox << endl; 
     1319        cout << "generated " << (int)mViewCells.size() << " view cells using the geometry " << filename << endl; 
     1320 
     1321        return true; 
    13211322} 
    13221323 
     
    25392540        VssRayContainer savedRays; 
    25402541 
     2542        // choose a a number of rays based on the ratio of cast rays / requested rays 
    25412543        const int limit = min(mInitialSamples, (int)rays.size()); 
    2542  
    25432544        VssRayContainer::const_iterator it, it_end = rays.end(); 
    25442545 
    25452546        const float prop = (float)limit / ((float)rays.size() + Limits::Small); 
    2546  
    25472547        for (it = rays.begin(); it != it_end; ++ it) 
    25482548        { 
     
    27852785                return; 
    27862786         
    2787         int savedColorCode = mColorCode; 
     2787        const int savedColorCode = mColorCode; 
    27882788         
    27892789        if (1) // export final view cells 
     
    29892989                                                                                                 const AxisAlignedBox3 *sceneBox, 
    29902990                                                                                                 const AxisAlignedPlane *clipPlane 
    2991                                                                                                  ) const 
    2992 { 
    2993         // out of bounds cell 
    2994         //if (vc->GetId() == OUT_OF_BOUNDS_ID) return; 
    2995  
    2996         // export mesh if available 
    2997         if (vc->GetMesh()) 
    2998         { 
    2999                 exporter->ExportMesh(vc->GetMesh()); 
    3000                 return; 
    3001         } 
    3002  
    3003         // otherwise construct from leaves 
     2991                                                                                                        ) const 
     2992{ 
    30042993        if (clipPlane) 
    30052994        { 
     
    30183007                        mBspTree->ConstructGeometry(*it, geom); 
    30193008 
    3020                         const float eps = 0.00000001f; 
     3009                        const float eps = 0.0001f; 
    30213010                        const int cf = geom.Side(plane, eps); 
    30223011 
     
    30323021                                                                   mViewSpaceBox,  
    30333022                                                                   eps); 
    3034          
     3023 
    30353024                                if (back.Valid()) 
    3036                                 {        
     3025                                { 
    30373026                                        exporter->ExportPolygons(back.GetPolys()); 
    30383027                                }                        
     
    30423031        else 
    30433032        { 
    3044                 BspNodeGeometry geom; 
    3045                 mBspTree->ConstructGeometry(vc, geom); 
    3046                 exporter->ExportPolygons(geom.GetPolys()); 
     3033                // export mesh if available 
     3034                // TODO: some bug here? 
     3035                if (1 && vc->GetMesh()) 
     3036                { 
     3037                        exporter->ExportMesh(vc->GetMesh()); 
     3038                } 
     3039                else 
     3040                { 
     3041                        BspNodeGeometry geom; 
     3042                        mBspTree->ConstructGeometry(vc, geom); 
     3043                        exporter->ExportPolygons(geom.GetPolys()); 
     3044                } 
    30473045        } 
    30483046} 
     
    31583156                for (oit = objects.begin(); oit != oit_end; ++ oit) 
    31593157                { 
    3160                         MeshInstance *mi = dynamic_cast<MeshInstance *>(*oit); 
    3161                         const AxisAlignedBox3 box = mi->GetBox(); 
     3158                        const AxisAlignedBox3 box = (*oit)->GetBox(); 
    31623159                         
    3163                         stream << "<BoundingBox" << " id=\"" << mi->GetId() << "\"" 
     3160                        stream << "<BoundingBox" << " id=\"" << (*oit)->GetId() << "\"" 
    31643161                                   << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 
    31653162                                   << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; 
     
    41234120                { 
    41244121                        cout << "exporting view cells after post process ... "; 
    4125  
    41264122                        if (0) 
    4127                         { 
    4128                                 // export view space box 
     4123                        {       // export view space box 
    41294124                                exporter->SetWireframe(); 
    41304125                                exporter->ExportBox(mViewSpaceBox); 
     
    41334128 
    41344129                        Material m;  
    4135  
    41364130                        m.mDiffuseColor.r = 0.0f; 
    41374131                        m.mDiffuseColor.g = 0.5f; 
     
    41404134            exporter->SetForcedMaterial(m); 
    41414135 
    4142                         if (0 && mExportGeometry) 
     4136                        if (1 && mExportGeometry) 
    41434137                        { 
    41444138                                exporter->ExportGeometry(objects); 
    41454139                        } 
    41464140 
    4147                         // export rays 
    41484141                        if (0 && mExportRays) 
    41494142                        { 
    41504143                                exporter->ExportRays(visRays, RgbColor(1, 0, 0)); 
    41514144                        } 
    4152  
    41534145                        ExportViewCellsForViz(exporter, NULL, GetClipPlane()); 
    41544146 
     
    45004492                                                                                                        ) const 
    45014493{ 
    4502         // out of bounds cell 
    4503         //if (vc->GetId() == OUT_OF_BOUNDS_ID)  return; 
    45044494        if (clipPlane) 
    45054495        { 
     
    45134503                { 
    45144504                        BspNodeGeometry geom; 
    4515  
    45164505                        BspNodeGeometry front; 
    45174506                        BspNodeGeometry back; 
     
    45454534                // export mesh if available 
    45464535                // TODO: some bug here? 
    4547                 if (0 && vc->GetMesh()) 
     4536                if (1 && vc->GetMesh()) 
    45484537                { 
    45494538                        exporter->ExportMesh(vc->GetMesh()); 
     
    50705059 
    50715060                        // matt: hack for clamping scene 
    5072                         AxisAlignedBox3 bbox = mHierarchyManager->GetViewSpaceBox(); 
     5061                        AxisAlignedBox3 bbox = mViewSpaceBox; 
    50735062                        bbox.Scale(Vector3(0.5, 1, 0.5)); 
    50745063                        if (CLAMP_TO_BOX) 
Note: See TracChangeset for help on using the changeset viewer.