Ignore:
Timestamp:
10/17/06 12:06:36 (18 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r1603 r1632  
    241241 
    242242int VspBspTree::AddMeshToPolygons(Mesh *mesh, 
    243                                                                   PolygonContainer &polys, 
    244                                                                   MeshInstance *parent) 
    245 { 
    246         if (!mesh) 
    247                 return 0; 
     243                                                                  PolygonContainer &polys) const 
     244{ 
     245        if (!mesh) return 0; 
    248246 
    249247        FaceContainer::const_iterator fi; 
     
    256254                if (poly->Valid(mEpsilon)) 
    257255                { 
    258                         poly->mParent = parent; // set parent intersectable 
    259256                        polys.push_back(poly); 
    260257                } 
     
    269266 
    270267 
    271 int VspBspTree::AddToPolygonSoup(const ViewCellContainer &viewCells, 
    272                                                                  PolygonContainer &polys, 
    273                                                                  int maxObjects) 
    274 { 
    275         const int limit = (maxObjects > 0) ? 
    276                 Min((int)viewCells.size(), maxObjects) : (int)viewCells.size(); 
    277  
    278         int polysSize = 0; 
    279          
    280         for (int i = 0; i < limit; ++ i) 
    281         { 
    282                 Mesh *mesh = viewCells[i]->GetMesh(); 
    283                 if (mesh)  
    284                 {       // copy the mesh into polygons and add to BSP tree aabb 
    285                         mBoundingBox.Include(viewCells[i]->GetBox());  
    286                         polysSize += AddMeshToPolygons(mesh, 
    287                                                                                    polys, 
    288                                                                                    viewCells[i]); 
    289                 } 
    290         } 
    291          
    292         return polysSize; 
     268void VspBspTree::ExtractPolygons(Intersectable *object, PolygonContainer &polys) const 
     269{ 
     270        // extract the polygons from the intersectables 
     271        switch (object->Type()) 
     272        { 
     273                case Intersectable::MESH_INSTANCE: 
     274                        { 
     275                                Mesh *mesh = dynamic_cast<MeshInstance *>(object)->GetMesh(); 
     276                                AddMeshToPolygons(mesh, polys); 
     277                        } 
     278                        break; 
     279                case Intersectable::VIEW_CELL: 
     280                        { 
     281                                Mesh *mesh = dynamic_cast<ViewCell *>(object)->GetMesh(); 
     282                                AddMeshToPolygons(mesh, polys); 
     283                                break; 
     284                        } 
     285                case Intersectable::TRANSFORMED_MESH_INSTANCE: 
     286                        { 
     287                                TransformedMeshInstance *mi =  
     288                                        dynamic_cast<TransformedMeshInstance *>(object); 
     289 
     290                                Mesh mesh; 
     291                                mi->GetTransformedMesh(mesh); 
     292                                AddMeshToPolygons(&mesh, polys); 
     293                        } 
     294                        break; 
     295                case Intersectable::TRIANGLE_INTERSECTABLE: 
     296                        { 
     297                                TriangleIntersectable *intersect =  
     298                                        dynamic_cast<TriangleIntersectable *>(object); 
     299 
     300                                Polygon3 *poly = new Polygon3(intersect->GetItem()); 
     301 
     302                                if (poly->Valid(mEpsilon))       
     303                                { 
     304                                        polys.push_back(poly); 
     305                                } 
     306                                else 
     307                                { 
     308                                        delete poly; 
     309                                } 
     310                        } 
     311                        break; 
     312                default: 
     313                        Debug << "intersectable type not supported" << endl; 
     314                        break; 
     315        } 
    293316} 
    294317 
     
    304327        { 
    305328                Intersectable *object = objects[i];//*it; 
    306                 Mesh *mesh = NULL; 
    307  
    308                 switch (object->Type()) // extract the meshes 
    309                 { 
    310                 case Intersectable::MESH_INSTANCE: 
    311                         mesh = dynamic_cast<MeshInstance *>(object)->GetMesh(); 
    312                         AddMeshToPolygons(mesh, polys, NULL); 
    313                         break; 
    314                 case Intersectable::VIEW_CELL: 
    315                         mesh = dynamic_cast<ViewCell *>(object)->GetMesh(); 
    316                         AddMeshToPolygons(mesh, polys, NULL); 
    317                         break; 
    318                 case Intersectable::TRANSFORMED_MESH_INSTANCE: 
    319                         { 
    320                                 TransformedMeshInstance *mi =  
    321                                         dynamic_cast<TransformedMeshInstance *>(object); 
    322  
    323                                 Mesh mesh; 
    324                                 mi->GetTransformedMesh(mesh); 
    325                                 AddMeshToPolygons(&mesh, polys, NULL); 
    326                 break; 
    327                         } 
    328                 case Intersectable::TRIANGLE_INTERSECTABLE: 
    329                         { 
    330                                 TriangleIntersectable *intersect =  
    331                                         dynamic_cast<TriangleIntersectable *>(object); 
    332  
    333                                 Polygon3 *poly = new Polygon3(intersect->GetItem()); 
    334  
    335                                 if (poly->Valid(mEpsilon))       
    336                                         polys.push_back(poly); 
    337                                 else 
    338                                         delete poly; 
    339                         } 
    340                 default: 
    341                                 Debug << "intersectable type not supported" << endl; 
    342                         break; 
    343                 } 
     329                ExtractPolygons(object, polys); 
    344330 
    345331                mBoundingBox.Include(object->GetBox()); // add to BSP tree aabb 
     
    404390                        Intersectable *obj = ray->mTerminationObject; 
    405391 
    406                         if ((mBoundingBox.IsInside(ray->mTermination) || !forcedBoundingBox) && 
    407                                 obj && !obj->Mailed()) 
    408                         { 
    409                                 obj->Mail(); 
    410  
    411                                 // handle intersectable 
    412                                 switch (obj->Type()) 
    413                                 { 
    414                                         case Intersectable::TRANSFORMED_MESH_INSTANCE: 
    415                                                 { 
    416                                                         Mesh mesh; 
    417                                  
    418                                                         TransformedMeshInstance *tmobj =  
    419                                                                 dynamic_cast<TransformedMeshInstance *>(obj); 
    420                                  
    421                                                         tmobj->GetTransformedMesh(mesh); 
    422                                                         AddMeshToPolygons(&mesh, polys, tmobj); 
    423                                                 } 
    424                                                 break; 
    425  
    426                                         case Intersectable::MESH_INSTANCE: 
    427                                                 { 
    428                                                         MeshInstance *mobj = dynamic_cast<MeshInstance *>(obj); 
    429                                                         AddMeshToPolygons(mobj->GetMesh(), polys, mobj); 
    430                                                 } 
    431                                                 break; 
    432  
    433                                         case Intersectable::TRIANGLE_INTERSECTABLE: 
    434                                                 { 
    435                                                         TriangleIntersectable *intersect =  
    436                                                                         dynamic_cast<TriangleIntersectable *>(obj); 
    437  
    438                                                         Polygon3 *poly = new Polygon3(intersect->GetItem()); 
    439  
    440                                                         if (poly->Valid(mEpsilon))       
    441                                                                 polys.push_back(poly); 
    442                                                         else 
    443                                                                 delete poly; 
    444                                                 } 
    445                                                 break; 
    446  
    447                                         default: 
    448                                                 cout << "not implemented yet" << endl; 
    449                                                 break; 
    450                                 } 
    451  
    452                                 ++ numObj; 
    453  
    454                                 ///////// 
    455                                 //-- compute bounding box 
    456  
    457                                 if (!forcedBoundingBox) 
    458                                 { 
    459                                         mBoundingBox.Include(ray->mTermination); 
    460                                 } 
     392                        ++ numObj; 
     393 
     394                        ///////// 
     395                        //-- compute bounding box 
     396 
     397                        if (!forcedBoundingBox) 
     398                        { 
     399                                mBoundingBox.Include(ray->mTermination); 
    461400                        } 
    462401 
     
    466405                        {                
    467406                                ray->mOriginObject->Mail(); 
    468                                 MeshInstance *obj = dynamic_cast<MeshInstance *>(ray->mOriginObject); 
    469                                 AddMeshToPolygons(obj->GetMesh(), polys, obj); 
    470                                  
     407                                ExtractPolygons(ray->mOriginObject, polys); 
     408                                                                 
    471409                                ++ numObj; 
    472410                        } 
     
    475413                // throw out unnecessary polygons 
    476414                PreprocessPolygons(polys); 
    477  
    478415                cout << "finished" << endl; 
    479416 
     
    1021958        ////////////////// 
    1022959        //-- terminate traversal and create new view cell 
     960 
    1023961        if (newNode->IsLeaf()) 
    1024962        { 
     
    1035973                // update scalar pvs size value 
    1036974                ObjectPvs &pvs = viewCell->GetPvs(); 
    1037                 mViewCellsManager->UpdateScalarPvsSize(viewCell, pvs.CountObjectsInPvs(), pvs.GetSize()); 
     975                mViewCellsManager->UpdateScalarPvsSize(viewCell,  
     976                                                                                           pvs.CountObjectsInPvs(),  
     977                                                                                           pvs.GetSize()); 
    1038978 
    1039979                mBspStats.contributingSamples += conSamp; 
    1040                 mBspStats.sampleContributions +=(int) sampCon; 
     980                mBspStats.sampleContributions += (int)sampCon; 
    1041981 
    1042982                viewCell->mLeaves.push_back(leaf); 
     
    1044984                /////////// 
    1045985                //-- store additional info 
     986 
    1046987                if (mStoreRays) 
    1047988                { 
Note: See TracChangeset for help on using the changeset viewer.