Changeset 1632


Ignore:
Timestamp:
10/17/06 12:06:36 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h

    r1614 r1632  
    408408                } 
    409409 
     410                /*bool Apply(SplitQueue *queue, bool terminationCriteriaMet) 
     411                { 
     412                        BvhNode *n = sBvHierarchy->Subdivide(splitQueue, this, terminationCriteriaMet); 
     413                        // local or global termination criteria failed 
     414                        return !n->IsLeaf();             
     415                }*/ 
     416 
    410417                bool GlobalTerminationCriteriaMet() const 
    411418                { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r1627 r1632  
    119119        Debug << "min global cost ratio: " << mTermMinGlobalCostRatio << endl; 
    120120        Debug << "global cost miss tolerance: " << mTermGlobalCostMissTolerance << endl; 
    121         Debug << "construction type: " << mConstructionType << endl; 
    122121        Debug << "min depth for object space subdivision: " << mMinDepthForObjectSpaceSubdivion << endl; 
    123122        Debug << "repair queue: " << mRepairQueue << endl; 
    124123        Debug << "number of multilevels: " << mNumMultiLevels << endl; 
     124 
     125        switch (mConstructionType) 
     126        { 
     127        case 0: 
     128                Debug << "construction type: sequential" << endl; 
     129                break; 
     130        case 1: 
     131                Debug << "construction type: interleaved" << endl; 
     132                break; 
     133        case 2: 
     134                Debug << "construction type: gradient" << endl; 
     135                break; 
     136        case 3: 
     137                Debug << "construction type: multilevel" << endl; 
     138                break; 
     139        default: 
     140                Debug << "construction type " << mConstructionType << " unknown" << endl; 
     141                break; 
     142        } 
     143 
    125144        //Debug << "min render cost " << mMinRenderCostDecrease << endl; 
    126145        Debug << endl; 
     
    308327        SplitQueue viewSpaceQueue; 
    309328 
    310         int maxSteps = 200; // number of initial splits; 
     329        // number of initial splits 
     330        int maxSteps = 200; 
    311331        float renderCostDecr = 0; 
    312332 
     
    322342                // for first round, use sah splits. Once view space partition 
    323343                // has started, use render cost heuristics instead 
    324                 SubdivisionCandidate *osc = ResetObjectSpaceSubdivision(sampleRays, objects); 
     344                SubdivisionCandidate *osc =  
     345                        ResetObjectSpaceSubdivision(sampleRays, objects); 
    325346                objectSpaceQueue.Push(osc); 
    326347 
    327                 // process object space candidates using  
    328                 // render queue for objects until slope of previous subdivision  
    329                 // is reached 
     348                // process object space candidates using render queue for  
     349                // objects until slope of previous subdivision is reached 
    330350                SubdivisionCandidateContainer ospContainer; 
    331351 
    332                 const int ospSteps = RunConstruction(objectSpaceQueue, ospContainer, renderCostDecr, maxSteps); 
     352                const int ospSteps =  
     353                        RunConstruction(objectSpaceQueue, ospContainer, renderCostDecr, maxSteps); 
    333354            cout << ospSteps << " object space partition steps taken" << endl; 
    334355 
     
    345366 
    346367                CollectDirtyCandidates(ospContainer, dirtyList); 
    347                 RepairQueue(dirtyList, viewSpaceQueue); 
     368                //RepairQueue(dirtyList, viewSpaceQueue); 
    348369 
    349370                cout << "finished repairing queue ... " << endl; 
     
    354375                // subdivide view space with respect to the objects 
    355376 
    356                 SubdivisionCandidate *vsc = ResetViewSpaceSubdivision(sampleRays, objects); 
     377                SubdivisionCandidate *vsc =  
     378                        ResetViewSpaceSubdivision(sampleRays, objects); 
    357379                viewSpaceQueue.Push(vsc); 
    358380 
    359381                SubdivisionCandidateContainer vspContainer; 
    360382                // process view space candidates 
    361                 const int vspSteps = RunConstruction(viewSpaceQueue, vspContainer, renderCostDecr, maxSteps); 
    362  
    363                 cout << vspSteps << " object space partition steps taken" << endl; 
     383                const int vspSteps =  
     384                        RunConstruction(viewSpaceQueue, vspContainer, renderCostDecr, maxSteps); 
     385 
     386                cout << vspSteps << " view space partition steps taken" << endl; 
    364387 
    365388                // view space subdivision constructed 
     
    373396                 
    374397                CollectDirtyCandidates(vspContainer, dirtyList); 
    375                 RepairQueue(dirtyList, objectSpaceQueue); 
     398                //RepairQueue(dirtyList, objectSpaceQueue); 
    376399 
    377400                cout << "finished repairing queue ... " << endl; 
     
    417440        mViewSpaceSubdivisionType = NO_VIEWSPACE_SUBDIV; 
    418441 
    419         // start with view space subdivison immediately? 
     442        // start view space subdivison immediately? 
    420443        if (StartViewSpaceSubdivision()) 
    421444        { 
    422445                // prepare vsp tree for traversal 
    423446                mViewSpaceSubdivisionType = mSavedViewSpaceSubdivisionType; 
    424                 PrepareViewSpaceSubdivision(sampleRays, objects); 
     447                SubdivisionCandidate *vspSc =  
     448                        PrepareViewSpaceSubdivision(sampleRays, objects); 
     449                mTQueue.Push(vspSc); 
    425450        } 
    426451         
     
    429454        { 
    430455                mObjectSpaceSubdivisionType = mSavedObjectSpaceSubdivisionType; 
    431                 PrepareObjectSpaceSubdivision(sampleRays, objects); 
    432         } 
    433 cout << "****************555555555555555555555555" << endl; 
     456                SubdivisionCandidate *ospSc = 
     457                        PrepareObjectSpaceSubdivision(sampleRays, objects); 
     458                mTQueue.Push(ospSc); 
     459        } 
     460 
    434461        // begin subdivision 
    435462        RunConstruction(mRepairQueue, sampleRays, objects, forcedViewSpace); 
     
    449476                                                                                                                                        const ObjectContainer &objects) 
    450477{ 
    451         cout << "\nstarting view space hierarchy construction ... " << endl; 
     478        cout << "\npreparing view space hierarchy construction ... " << endl; 
    452479 
    453480        // hack: reset global cost misses 
     
    541568                { 
    542569                        VspNode *n = mVspTree->Subdivide(splitQueue, sc, terminationCriteriaMet); 
    543                         // check if termination criteria failed 
     570 
     571                        // check if terminated 
    544572                        success = !n->IsLeaf(); 
    545573                } 
     
    564592                break; 
    565593        default: 
     594                cerr << "unknown subdivision type" << endl; 
    566595                break; 
    567596        } 
     
    682711        { 
    683712                SubdivisionCandidate *sc = NextSubdivisionCandidate(mTQueue);     
    684                          
     713         
    685714                /////////////////// 
    686715                //-- subdivide leaf node 
     
    698727                                 << mMinDepthForObjectSpaceSubdivion << ") " << endl; 
    699728 
    700                         PrepareObjectSpaceSubdivision(sampleRays, objects); 
     729                        SubdivisionCandidate *ospSc = PrepareObjectSpaceSubdivision(sampleRays, objects); 
     730                        mTQueue.Push(ospSc); 
    701731 
    702732                        cout << "reseting queue ... "; 
     
    713743                                 << mMinDepthForViewSpaceSubdivion << ") " << endl; 
    714744 
    715                         PrepareViewSpaceSubdivision(sampleRays, objects); 
     745                        SubdivisionCandidate *vspSc = PrepareViewSpaceSubdivision(sampleRays, objects); 
     746                        mTQueue.Push(vspSc); 
    716747 
    717748                        cout << "reseting queue ... "; 
     
    763794 
    764795                const bool repairQueue = false; 
    765                 ApplySubdivisionCandidate(sc, splitQueue, repairQueue); 
    766  
    767                 chosenCandidates.push_back(sc); 
     796                bool success = ApplySubdivisionCandidate(sc, splitQueue, repairQueue); 
     797 
     798                if (success) 
     799                { 
     800                        chosenCandidates.push_back(sc); 
     801                } 
    768802        } 
    769803 
     
    781815        } 
    782816 
    783         SubdivisionCandidate *firstCandidate = NULL; 
     817        SubdivisionCandidate *firstCandidate; 
    784818 
    785819        // object space partition constructed => reconstruct 
     
    791825                        Debug << "old bv hierarchy:\n " << mBvHierarchy->mBvhStats << endl; 
    792826         
    793                         SubdivisionCandidate *firstCandidate =  
    794                                 mBvHierarchy->Reset(sampleRays, objects); 
    795  
     827                        firstCandidate = mBvHierarchy->Reset(sampleRays, objects); 
     828                        cout << "here4" << endl; 
    796829                        mHierarchyStats.mTotalCost = mBvHierarchy->mTotalCost; 
    797830 
     
    802835                        // evaluate stats before first subdivision 
    803836                        EvalSubdivisionStats(); 
     837                        cout << "here5" << endl; 
    804838                } 
    805839                break; 
     
    807841        case KD_BASED_OBJ_SUBDIV: 
    808842                // TODO 
    809                 break; 
    810843        default: 
    811                 break; 
    812         } 
    813  
     844                firstCandidate = NULL; 
     845                break; 
     846        } 
     847cout << "here6" << endl; 
    814848        return firstCandidate; 
    815849} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp

    r1581 r1632  
    21782178   
    21792179   
    2180   int nrays = leaf->rays.size(); 
    2181   int startIndex = rays.size(); 
     2180  int nrays = (int)leaf->rays.size(); 
     2181  int startIndex = (int)rays.size(); 
    21822182   
    21832183  AxisAlignedBox3 box = GetBBox(leaf); 
     
    24512451        if (leaf->rays[i].mRay->RefCount() != 0) { 
    24522452          cerr<<"Error: refcount!=0, but"<<leaf->rays[i].mRay->RefCount()<<endl; 
    2453           cerr<<"desired="<<desired<<"i="<<i<<" size="<<leaf->rays.size()<<endl; 
     2453          cerr<<"desired="<<desired<<"i="<<i<<" size="<<(int)leaf->rays.size()<<endl; 
    24542454          exit(1); 
    24552455        } 
     
    25772577  int fixedPerLeaf = 0; 
    25782578  // int fixedPerLeaf = 0; 
    2579   int fixed = fixedPerLeaf*leaves.size(); 
     2579  int fixed = fixedPerLeaf*(int)leaves.size(); 
    25802580  int iGenerated = numberOfRays; 
    25812581  float ratioPerLeaf = iGenerated /(avgContrib*numberOfLeaves); 
     
    25922592        } 
    25932593 
    2594   return rays.size(); 
     2594  return (int)rays.size(); 
    25952595} 
    25962596 
     
    29332933        int id = object->GetId()-1; 
    29342934        if (id < 0 || id >= mRoots.size()) { 
    2935           Debug<<"Error: object Id out of range, Id="<<id<<" roots.size()="<<mRoots.size()<< 
     2935          Debug<<"Error: object Id out of range, Id="<<id<<" roots.size()="<<(int)mRoots.size()<< 
    29362936                endl<<flush; 
    29372937          id = (int)mRoots.size()-1; // $$ last tree is used by all unsigned objects 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SubdivisionCandidate.h

    r1576 r1632  
    2222        virtual void EvalPriority() = 0; 
    2323        virtual int Type() const = 0; 
     24        //virtual bool Apply() = 0; 
    2425        virtual bool GlobalTerminationCriteriaMet() const = 0; 
    2526 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp

    r1564 r1632  
    724724 
    725725        // extract planes of box 
    726         // TODO: can be done more elegantly than first extracting polygons 
    727         // and take their planes 
     726        // TODO: can be done more elegantly than here  
     727        // where we first extract polygons, then compute their planes 
    728728        for (pit = boxPolys.begin(); pit != pit_end; ++ pit) 
    729729        { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1627 r1632  
    3838// HACK 
    3939const static bool SAMPLE_AFTER_SUBDIVISION = true; 
    40 const static bool CLAMP_TO_BOX = true; 
     40const static bool CLAMP_TO_BOX = false; 
    4141 
    4242template <typename T> class myless 
  • 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                { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h

    r1563 r1632  
    538538                                                 int maxObjects = 0); 
    539539 
    540         /** Extracts the meshes of the view cells and and adds them to polygons. 
    541                 Adds view cell aabb to the aabb of the tree. 
    542                 @param maxPolys the maximal number of objects to be stored as polygons 
    543                 @returns the number of polygons 
    544         */ 
    545         int AddToPolygonSoup(const ViewCellContainer &viewCells,  
    546                                                  PolygonContainer &polys,  
    547                                                  int maxObjects = 0); 
    548  
    549         /** Extract polygons of this mesh and add to polygon container. 
     540        void ExtractPolygons(Intersectable *obj, PolygonContainer &polys) const; 
     541 
     542        /** Extract polygons of this mesh and adds them to container. 
    550543                @param mesh the mesh that drives the polygon construction 
    551                 @param parent the parent intersectable this polygon is constructed from 
    552544                @returns number of polygons 
    553545        */ 
    554         int AddMeshToPolygons(Mesh *mesh, PolygonContainer &polys, MeshInstance *parent); 
     546        int AddMeshToPolygons(Mesh *mesh, PolygonContainer &polys) const; 
    555547 
    556548        /** Selects an axis aligned for the next split. 
Note: See TracChangeset for help on using the changeset viewer.