Changeset 1379


Ignore:
Timestamp:
09/15/06 17:33:22 (18 years ago)
Author:
mattausch
Message:

fixed sah for objeect partition
loader for single triangles also for x3d

Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
20 edited

Legend:

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

    r1370 r1379  
    290290                                                                                BvhTraversalData &backData) 
    291291{ 
    292         mBvhStats.nodes += 2; // we have two new leaves 
    293  
    294292        const BvhTraversalData &tData = sc.mParentData; 
    295293        BvhLeaf *leaf = tData.mNode; 
    296294        AxisAlignedBox3 parentBox = leaf->GetBoundingBox(); 
     295 
     296        // update stats 
     297        mBvhStats.nodes += 2; // we have two new leaves 
     298 
     299        if (tData.mDepth > mBvhStats.maxDepth) 
     300        { 
     301                mBvhStats.maxDepth = tData.mDepth; 
     302        } 
    297303 
    298304        // add the new nodes to the tree 
     
    471477                splitCandidate.mParentData.mMaxCostMisses; 
    472478 
    473         const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 
    474479        const float oldProp = EvalViewCellsVolume(leaf->mObjects); 
    475  
    476         const float oldRenderCost = oldProp * (float)leaf->mObjects.size() / viewSpaceVol; 
    477  
     480        const float oldRenderCost = EvalRenderCost(leaf->mObjects); 
     481                 
    478482        // compute global decrease in render cost 
    479         float newRenderCost = EvalRenderCost(splitCandidate.mParentData, 
    480                                                                              splitCandidate.mFrontObjects, 
    481                                                                                  splitCandidate.mBackObjects); 
    482  
    483         newRenderCost /=  viewSpaceVol; 
     483        const float newRenderCost =  
     484                EvalRenderCost(splitCandidate.mFrontObjects) + 
     485                EvalRenderCost(splitCandidate.mBackObjects); 
     486 
    484487        const float renderCostDecr = oldRenderCost - newRenderCost; 
    485488 
    486         //Debug << "\nbvh render cost decr: " << renderCostDecr << endl; 
     489#ifdef _DEBUG 
     490        Debug << "old render cost: " << oldRenderCost << endl; 
     491        Debug << "new render cost: " << newRenderCost << endl; 
     492        Debug << "render cost decrease: " << renderCostDecr << endl; 
     493#endif 
    487494        splitCandidate.SetRenderCostDecrease(renderCostDecr); 
    488495 
    489 #if 0 
    490         const float priority = (float)-splitCandidate.mParentData.mDepth; 
    491 #else    
     496#if 1 
    492497        // take render cost of node into account  
    493498        // otherwise danger of being stuck in a local minimum!! 
    494499        const float factor = mRenderCostDecreaseWeight; 
    495500        const float priority = factor * renderCostDecr + (1.0f - factor) * oldRenderCost; 
     501#else 
     502        const float priority = (float)-splitCandidate.mParentData.mDepth; 
    496503#endif 
    497504 
     
    540547        // depth related stuff 
    541548 
    542         if (data.mDepth > mBvhStats.maxDepth) 
    543         { 
    544                 mBvhStats.maxDepth = data.mDepth; 
    545         } 
    546  
    547549        if (data.mDepth < mBvhStats.minDepth) 
    548550        { 
     
    640642        } 
    641643 
    642         const float oldProp = EvalViewCellsVolume(tData.mNode->mObjects); 
    643         //const float oldProp = tData.mProbability; 
    644  
    645         const float oldRenderCost = oldProb * (float)tData.mNode->mObjects.size(); 
     644        const float oldRenderCost = EvalRenderCost(tData.mNode->mObjects); 
    646645        const float newRenderCost =  
    647                 EvalRenderCost(tData, objectsFront, objectsBack); 
     646                EvalRenderCost(objectsFront) * EvalRenderCost(objectsBack); 
    648647 
    649648        const float ratio = newRenderCost / oldRenderCost; 
     
    672671                // object mailed => belongs to back objects 
    673672                if (i < border)  
     673                { 
    674674                        objectsBack.push_back(obj); 
     675                } 
    675676                else 
     677                { 
    676678                        objectsFront.push_back(obj); 
    677         } 
    678  
    679         const float oldProp = EvalViewCellsVolume(tData.mNode->mObjects); 
    680         //const float oldProp = tData.mProbability; 
    681  
    682         const float oldRenderCost = oldProp * (float)tData.mNode->mObjects.size(); 
    683         const float newRenderCost = EvalRenderCost(tData, objectsFront, objectsBack); 
     679                } 
     680        } 
     681 
     682        const float oldRenderCost = EvalRenderCost(tData.mNode->mObjects); 
     683        const float newRenderCost = EvalRenderCost(objectsFront) + EvalRenderCost(objectsBack); 
    684684 
    685685        const float ratio = newRenderCost / oldRenderCost; 
     
    694694                                                   ObjectContainer &objectsBack) 
    695695{ 
    696         PrepareLocalSubdivisionCandidates(tData, axis); 
    697    
    698696        // go through the lists, count the number of objects left and right 
    699697        // and evaluate the following cost funcion: 
    700698        // C = ct_div_ci  + (ol + or)/queries 
     699        PrepareLocalSubdivisionCandidates(tData, axis); 
     700 
    701701        int objectsLeft = 0, objectsRight = (int)tData.mNode->mObjects.size(); 
    702702   
     
    709709        float minSum = 1e20f; 
    710710   
     711        float minBorder = maxBox; 
     712        float maxBorder = minBox; 
     713        float areaLeft = 0, areaRight = 0; 
     714 
     715        SortableEntryContainer::const_iterator currentPos = 
     716                mSubdivisionCandidates->begin(); 
     717 
     718         
     719        // we keep track of both borders of the bounding boxes => 
     720        // store the events in descending order 
    711721        vector<float> bordersRight; 
    712722        bordersRight.resize(mSubdivisionCandidates->size()); 
    713723 
    714         float minBorder = maxBox; 
    715         float maxBorder = minBox; 
    716  
    717         SortableEntryContainer::const_iterator currentPos = 
    718                 mSubdivisionCandidates->begin(); 
    719  
    720724        SortableEntryContainer::reverse_iterator rcit =  
    721725                mSubdivisionCandidates->rbegin(), rcit_end = mSubdivisionCandidates->rend(); 
    722                  
     726         
    723727        vector<float>::reverse_iterator rbit = bordersRight.rbegin(); 
    724728         
     
    728732                const AxisAlignedBox3 box = obj->GetBox(); 
    729733 
    730                 if (box.Min() < minBorder) 
     734                if (box.Min(axis) < minBorder) 
     735                { 
    731736                        minBorder = box.Min(axis); 
    732                  
     737                } 
     738 
    733739                (*rbit) = minBorder; 
    734740        } 
    735741 
    736742        vector<float>::const_iterator bit = bordersRight.begin(); 
    737         cout << "here42" << endl; 
    738743        SortableEntryContainer::const_iterator cit, cit_end = mSubdivisionCandidates->end(); 
     744 
    739745        for (cit = mSubdivisionCandidates->begin(); cit != cit_end; ++ cit, ++ bit)  
    740746        { 
     
    749755                const AxisAlignedBox3 obox = obj->GetBox(); 
    750756 
     757                // the borders of the bounding boxes have changed 
    751758                if (obox.Max(axis) > maxBorder) 
     759                { 
    752760                        maxBorder = obox.Max(axis); 
    753  
     761                } 
     762 
     763                minBorder = (*bit); 
     764         
    754765        lbox.SetMax(axis, maxBorder); 
    755                 rbox.SetMin(axis, *bit); 
    756          
    757                 const float sum = objectsLeft * lbox.SurfaceArea() + objectsRight * rbox.SurfaceArea(); 
     766                rbox.SetMin(axis, minBorder); 
     767         
     768                const float al = lbox.SurfaceArea(); 
     769                const float ar = rbox.SurfaceArea(); 
     770 
     771                const float sum = objectsLeft * al + objectsRight * ar; 
    758772       
    759                 cout << "pos=" << (*cit).mPos << "\t q=(" << objectsLeft << "," << objectsRight <<")\t r=("  
     773                /*cout << "pos=" << (*cit).mPos << "\t q=(" << objectsLeft << "," << objectsRight <<")\t r=("  
    760774                         << lbox.SurfaceArea() << "," << rbox.SurfaceArea() << ")" << endl; 
     775                cout << "minborder: " << minBorder << " maxborder: " << maxBorder << endl; 
    761776            cout << "cost= " << sum << endl; 
    762        
     777*/ 
    763778                if (sum < minSum)  
    764779                { 
    765                         minSum = sum;    
     780                        minSum = sum; 
     781                        areaLeft = al; 
     782                        areaRight = ar; 
    766783                        // objects belong to left side now 
    767784                        for (; currentPos != (cit + 1); ++ currentPos); 
    768785                } 
    769786        } 
     787 
    770788 
    771789        //////////////////////////////////////////// 
     
    784802        float ratio = newCost / oldCost; 
    785803   
    786 #if 0 
    787   cout<<"===================="<<endl; 
    788   cout<<"costRatio="<<ratio<<" pos="<<position<<" t="<<(position - minBox)/(maxBox - minBox) 
    789       <<"\t o=("<<objectsBack<<","<<objectsFront<<")"<<endl; 
     804#ifdef _DEBUG 
     805        cout << "\n\nobjects=(" << objectsBack.size() << "," << objectsFront.size() << " of " << tData.mNode->mObjects.size() << ")\t area=("  
     806                 << areaLeft << "," << areaRight << ")" << endl; 
     807        cout << "cost= " << minSum << endl; 
    790808#endif 
    791809  return ratio; 
     
    855873        int nObjectsLeft = 0; 
    856874        const int nTotalObjects = (int)tData.mNode->mObjects.size(); 
    857         const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 
     875        const float viewSpaceVol = mHierarchyManager->GetViewSpaceBox().GetVolume(); 
    858876 
    859877        SortableEntryContainer::const_iterator backObjectsStart = mSubdivisionCandidates->begin(); 
     
    11281146                                        //-- use surface area heuristic because view cells not constructed yet                           
    11291147                                        nCostRatio[axis] = 
    1130                                                 EvalLocalCostHeuristics( 
    1131                                                                                                 tData, 
    1132                                                                                                 axis, 
    1133                                                                                                 nFrontObjects[axis], 
    1134                                                                                                 nBackObjects[axis]); 
     1148                                                EvalSah( 
     1149                                                                tData, 
     1150                                                                axis, 
     1151                                                                nFrontObjects[axis], 
     1152                                                                nBackObjects[axis]); 
    11351153                                } 
    11361154                        } 
     
    11381156                        { 
    11391157                                //-- split objects using some simple criteria 
    1140  
    11411158                                nCostRatio[axis] = 
    11421159                                        EvalLocalObjectPartition( 
     
    12451262 
    12461263 
    1247 float BvHierarchy::EvalRenderCost(const BvhTraversalData &tData, 
    1248                                                                   const ObjectContainer &objectsFront, 
    1249                                                                   const ObjectContainer &objectsBack) const 
    1250 { 
    1251         // probability that view point lies in a view cell which sees this node 
    1252         const float pFront = EvalViewCellsVolume(objectsFront); 
    1253         const float pBack = EvalViewCellsVolume(objectsBack); 
    1254                  
    1255         //-- pvs rendering heuristics 
    1256         const float newRenderCost = (int)objectsFront.size() * pFront + (int)objectsBack.size() * pBack; 
    1257  
    1258 #ifdef _DEBUG 
    1259         const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 
    1260         Debug << "\nbvh render cost\n"  
    1261                   << "back p: " << pBack / viewSpaceVol << " front p " << pFront / viewSpaceVol << endl 
    1262                   << "new rc: " << newRenderCost / viewSpaceVol << endl; 
    1263 #endif 
    1264         return newRenderCost; 
     1264float BvHierarchy::EvalRenderCost(const ObjectContainer &objects) const 
     1265{ 
     1266        if (mHierarchyManager->GetViewSpaceSubdivisionType() == HierarchyManager::NO_VIEWSPACE_SUBDIV) 
     1267        { 
     1268                if (objects.empty()) 
     1269                        return 0.0f; 
     1270 
     1271                ///////////////////////////// 
     1272                //-- surface area heuristics 
     1273 
     1274                const AxisAlignedBox3 box = ComputeBoundingBox(objects); 
     1275                const float area = box.SurfaceArea(); 
     1276 
     1277                return (float)objects.size() * area; 
     1278        } 
     1279        else 
     1280        {       ///////////////////////////// 
     1281                //-- render cost heuristics 
     1282 
     1283                const float viewSpaceVol = mHierarchyManager->GetViewSpaceBox().GetVolume(); 
     1284                // probability that view point lies in a view cell which sees this node 
     1285                const float p = EvalViewCellsVolume(objects) / viewSpaceVol;     
     1286 
     1287                return (float)objects.size() * p; 
     1288        } 
    12651289} 
    12661290 
    12671291 
    12681292AxisAlignedBox3 BvHierarchy::ComputeBoundingBox(const ObjectContainer &objects, 
    1269                                                                                                 const AxisAlignedBox3 *parentBox) 
     1293                                                                                                const AxisAlignedBox3 *parentBox) const 
    12701294{ 
    12711295        if (parentBox && objects.empty()) 
     
    13251349                                                                   const bool setCounter) const 
    13261350{ 
     1351        // no view cells yet 
     1352        if (mHierarchyManager->GetViewSpaceSubdivisionType() ==  
     1353                HierarchyManager::NO_VIEWSPACE_SUBDIV) 
     1354                return; 
     1355 
    13271356        ViewCell::NewMail(); 
    13281357        ObjectContainer::const_iterator oit, oit_end = objects.end(); 
     
    13481377                ViewCellContainer tmpViewCells; 
    13491378         
    1350                 mVspTree->GetViewCells(*ray, tmpViewCells); 
     1379                mHierarchyManager->mVspTree->GetViewCells(*ray, tmpViewCells); 
    13511380 
    13521381                ViewCellContainer::const_iterator vit, vit_end = tmpViewCells.end(); 
     
    16451674        bvhleaf->SetSubdivisionCandidate(oSubdivisionCandidate); 
    16461675 
    1647         const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 
     1676        const float viewSpaceVol = mHierarchyManager->GetViewSpaceBox().GetVolume(); 
    16481677        mTotalCost = (float)objects.size() * prop / viewSpaceVol; 
    16491678 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h

    r1370 r1379  
    312312        friend class HierarchyManager; 
    313313 
    314 public: 
    315          
     314protected: 
    316315        struct SortableEntry; 
    317316        typedef vector<SortableEntry> SortableEntryContainer; 
    318317 
     318public: 
     319         
    319320        /** Additional data which is passed down the BSP tree during traversal. 
    320321        */ 
     
    589590        void EvalPriority(BvhTraversalData &tData) const; 
    590591 
    591         /** Evaluates render cost of next split. 
    592         */ 
    593         float EvalRenderCost( 
    594                 const BvhTraversalData &tData, 
    595                 const ObjectContainer &objectsLeft, 
    596                 const ObjectContainer &objectsRight) const; 
     592        /** Evaluates render cost of the bv induced by these objects 
     593        */ 
     594        float EvalRenderCost(const ObjectContainer &objects) const; 
    597595 
    598596        /** Evaluates tree stats in the BSP tree leafs. 
     
    704702        AxisAlignedBox3 ComputeBoundingBox( 
    705703                const ObjectContainer &objects,  
    706                 const AxisAlignedBox3 *parentBox = NULL); 
     704                const AxisAlignedBox3 *parentBox = NULL) const; 
    707705 
    708706        /** Collects list of invalid candidates. Candidates 
     
    785783        /// pointer to the hierarchy of view cells 
    786784        ViewCellsTree *mViewCellsTree; 
    787         /// pointer to the view space partition tree 
    788         VspTree *mVspTree; 
    789785        /// The view cells manager 
    790786        ViewCellsManager *mViewCellsManager; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp

    r1370 r1379  
    16701670                                        "rays.out"); 
    16711671 
    1672         RegisterOption("Preprocessor.loadPolygonsAsMeshes", 
    1673                                         optBool, 
    1674                                         "loadPolygonsAsMeshes=", 
    1675                                         "false"); 
     1672        RegisterOption("Preprocessor.loadMeshes", 
     1673                                        optBool, 
     1674                                        "loadMeshes=", 
     1675                                        "true"); 
    16761676 
    16771677        RegisterOption("Preprocessor.pvsRenderErrorSamples", 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r1370 r1379  
    4646                mOspTree = new OspTree(); 
    4747                mOspTree->mVspTree = mVspTree; 
    48                  
    49                 Debug << "creating osp tree" << endl; 
     48                mOspTree->mHierarchyManager = this; 
    5049                break; 
    5150        case BV_BASED_OBJ_SUBDIV: 
    5251        mBvHierarchy = new BvHierarchy(); 
    53                 mBvHierarchy->mVspTree = mVspTree; 
    54                  
    55                 Debug << "creating bv hierachy" << endl; 
     52                mBvHierarchy->mHierarchyManager = this; 
    5653                break; 
    5754        default: 
     
    5956        } 
    6057 
    61         if (mVspTree) 
    62                 mVspTree->mHierarchyManager = this; 
    63  
     58        // hierarchy manager links view space partition and object space partition 
     59        mVspTree->mHierarchyManager = this; 
     60         
    6461        ParseEnvironment(); 
    6562} 
     
    7471        mOspTree->mVspTree = mVspTree; 
    7572 
    76         Debug << "creating osp tree" << endl; 
    77  
    78         if (mVspTree) 
    79                 mVspTree->mHierarchyManager = this; 
     73        mVspTree->mHierarchyManager = this; 
    8074 
    8175        ParseEnvironment(); 
     
    160154 
    161155 
     156VspTree *HierarchyManager::GetVspTree()  
     157{  
     158        return mVspTree;  
     159} 
     160 
     161 
     162AxisAlignedBox3 HierarchyManager::GetViewSpaceBox() const 
     163{ 
     164        return mVspTree->mBoundingBox; 
     165} 
     166 
     167 
    162168SubdivisionCandidate *HierarchyManager::NextSubdivisionCandidate() 
    163169{ 
     
    223229                                                                 AxisAlignedBox3 *forcedViewSpace) 
    224230{ 
    225          
    226231        mHierarchyStats.Reset(); 
    227232        mHierarchyStats.Start(); 
     
    233238        cout << "Constructing view space / object space tree ... \n"; 
    234239         
     240        // compute view space bounding box 
     241        mVspTree->ComputeBoundingBox(sampleRays, forcedViewSpace); 
     242 
    235243        // use objects for evaluating vsp tree construction in the first levels 
    236244        // of the subdivision 
     
    245253        { 
    246254                mViewSpaceSubdivisionType = mSavedViewSpaceSubdivisionType; 
    247                 PrepareViewSpaceSubdivision(sampleRays, objects, forcedViewSpace); 
     255                PrepareViewSpaceSubdivision(sampleRays, objects); 
    248256        } 
    249257         
     
    270278 
    271279void HierarchyManager::PrepareViewSpaceSubdivision(const VssRayContainer &sampleRays, 
    272                                                                                                    const ObjectContainer &objects, 
    273                                                                                                    AxisAlignedBox3 *forcedViewSpace) 
     280                                                                                                   const ObjectContainer &objects) 
    274281{ 
    275282        cout << "starting view space hierarchy construction ... " << endl; 
     
    277284        RayInfoContainer *viewSpaceRays = new RayInfoContainer(); 
    278285        SubdivisionCandidate *vsc =  
    279                 mVspTree->PrepareConstruction(sampleRays, forcedViewSpace, *viewSpaceRays); 
     286                mVspTree->PrepareConstruction(sampleRays, *viewSpaceRays); 
    280287 
    281288        mTQueue.Push(vsc); 
     
    491498                                 << mMinDepthForViewSpaceSubdivion << ") " << endl; 
    492499 
    493                         PrepareViewSpaceSubdivision(sampleRays, objects, forcedViewSpace); 
     500                        PrepareViewSpaceSubdivision(sampleRays, objects); 
    494501 
    495502                        cout << "reseting queue ... "; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h

    r1370 r1379  
    198198        void PrintHierarchyStatistics(ofstream &stream) const; 
    199199 
    200         VspTree *GetVspTree() { return mVspTree; } 
     200        VspTree *GetVspTree(); 
     201 
     202        AxisAlignedBox3 GetViewSpaceBox() const; 
    201203 
    202204        void ExportObjectSpaceHierarchy( 
     
    266268        void PrepareViewSpaceSubdivision( 
    267269                const VssRayContainer &sampleRays, 
    268                 const ObjectContainer &objects, 
    269                 AxisAlignedBox3 *forcedViewSpace = NULL); 
     270                const ObjectContainer &objects); 
    270271 
    271272        bool ObjectSpaceSubdivisionConstructed() const; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.cpp

    r1344 r1379  
    177177bool ObjParser::ParseFile(const string filename, 
    178178                                                  SceneGraphNode *root, 
    179                                                   const bool loadPolygonsAsMeshes, 
     179                                                  const bool loadMeshes, 
    180180                                                  vector<FaceParentInfo> *parents) 
    181181{ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.h

    r1344 r1379  
    1717  virtual bool ParseFile(const std::string filename,  
    1818                                                 SceneGraphNode *root, 
    19                                                  const bool loadPolygonsAsMeshes = false, 
     19                                                 const bool loadMeshes = true, 
    2020                                                 vector<FaceParentInfo> *parents = NULL); 
    2121   
  • GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.h

    r1287 r1379  
    3737class KdTreeStatistics; 
    3838class SubdivisionCandidate; 
     39class HierarchyManager; 
     40 
    3941 
    4042 
     
    738740        ViewCellsTree *mViewCellsTree; 
    739741 
     742        /// pointer to the view space partition 
     743        /// note: should be handled over the hierarchy manager 
    740744        VspTree *mVspTree; 
     745 
     746        /// pointer to the hierarchy manager 
     747        HierarchyManager *mHierarchyManager; 
    741748 
    742749        /// The view cells manager 
     
    756763 
    757764 
     765        ////////////////////////////// 
    758766        //-- local termination 
    759767 
     
    772780 
    773781 
     782        //////////////////////// 
    774783        //-- global criteria 
    775784 
     
    786795 
    787796 
     797        /////////////////////////////////////////// 
    788798        //-- split heuristics based parameters 
    789799         
     
    793803        /// if only driving axis should be used for split 
    794804        bool mOnlyDrivingAxis; 
    795          
     805        /// represents min and max band for sweep 
     806        float mSplitBorder; 
     807 
     808        //////////////////////////////////////////////// 
     809 
    796810        /// current time stamp (used for keeping split history) 
    797811        int mTimeStamp; 
    798812        // if rays should be stored in leaves 
    799813        bool mStoreRays; 
    800  
    801814        /// epsilon for geometric comparisons 
    802815        float mEpsilon; 
    803  
    804816        /// subdivision stats output file 
    805817        ofstream  mSubdivisionStats; 
     
    810822        /// number of currenly generated view cells 
    811823        int mCreatedLeaves; 
    812  
    813         /// represents min and max band for sweep 
    814         float mSplitBorder; 
    815  
     824         
    816825        /// weight between  render cost decrease and node render cost 
    817826        float mRenderCostDecreaseWeight; 
    818827 
    819         /// stores the kd node intersectables used for pvs 
     828    /// stores the kd node intersectables used for pvs 
    820829        KdIntersectableMap mKdIntersectables; 
    821  
    822  
     830         
    823831private: 
    824832 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Parser.h

    r1344 r1379  
    2020  virtual bool ParseFile(const std::string filename, 
    2121                                                 SceneGraphNode *root, 
    22                                                  const bool loadPolygonsAsMeshes = false, 
     22                                                 const bool loadMeshes = true, 
    2323                                                 std::vector<FaceParentInfo> *parents = NULL)  
    2424  {return false;}; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/PlyParser.cpp

    r1344 r1379  
    260260PlyParser::ParseFile(const string filename, 
    261261                                         SceneGraphNode *root, 
    262                                          const bool loadPolygonsAsMeshes, 
     262                                         const bool loadMeshes, 
    263263                                         vector<FaceParentInfo> *parents) 
    264264{ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/PlyParser.h

    r1344 r1379  
    1616  bool ParseFile(const string filename, 
    1717                                 SceneGraphNode *root, 
    18                                  const bool loadPolygonsAsMeshes = false, 
     18                                 const bool loadMeshes = true, 
    1919                                 vector<FaceParentInfo> *parents = NULL); 
    2020 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1359 r1379  
    145145   
    146146        Environment::GetSingleton()->GetBoolValue("Preprocessor.useGlDebugger", mUseGlDebugger); 
    147         Environment::GetSingleton()->GetBoolValue("Preprocessor.loadPolygonsAsMeshes", mLoadPolygonsAsMeshes); 
     147        Environment::GetSingleton()->GetBoolValue("Preprocessor.loadMeshes", mLoadMeshes); 
    148148        Environment::GetSingleton()->GetBoolValue("Preprocessor.quitOnFinish", mQuitOnFinish); 
    149149        Environment::GetSingleton()->GetBoolValue("Preprocessor.computeVisibility", mComputeVisibility); 
     
    161161 
    162162        Debug << "detect empty view space=" << mDetectEmptyViewSpace << endl; 
    163         Debug << "load polygons as meshes: " << mLoadPolygonsAsMeshes << endl; 
     163        Debug << "load meshes: " << mLoadMeshes << endl; 
    164164 
    165165        if (mRayCastMethod == 0) 
     
    259259                                filename,  
    260260                                mSceneGraph->GetRoot(), 
    261                                 mLoadPolygonsAsMeshes, 
     261                                mLoadMeshes, 
    262262                                &mFaceParents); 
    263263                } 
    264264                else 
    265265                {  
    266                         result = parser->ParseFile(filename, mSceneGraph->GetRoot(), mLoadPolygonsAsMeshes); 
     266                        result = parser->ParseFile(filename, mSceneGraph->GetRoot(), mLoadMeshes); 
    267267                } 
    268268                 
     
    285285                                  filename,  
    286286                                  node, 
    287                                   mLoadPolygonsAsMeshes, 
     287                                  mLoadMeshes, 
    288288                                  &mFaceParents); 
    289289                  } 
    290290                  else 
    291291                  { 
    292                           success = parser->ParseFile(filename, node, mLoadPolygonsAsMeshes); 
     292                          success = parser->ParseFile(filename, node, mLoadMeshes); 
    293293                  } 
    294294 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h

    r1292 r1379  
    218218 
    219219  bool mQuitOnFinish; 
    220   bool mLoadPolygonsAsMeshes; 
     220  bool mLoadMeshes; 
    221221  bool mComputeVisibility; 
    222222 
  • GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.cpp

    r1344 r1379  
    4444UnigraphicsParser::ParseFile(const string filename, 
    4545                                                         SceneGraphNode *root, 
    46                                                          const bool loadPolygonsAsMeshes, 
     46                                                         const bool loadMeshes, 
    4747                                                         vector<FaceParentInfo> *parents) 
    4848{ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.h

    r1344 r1379  
    1717  virtual bool ParseFile(const std::string filename,  
    1818                                                 SceneGraphNode *root,  
    19                                                  const bool loadPolygonsAsMeshes = false, 
     19                                                 const bool loadMeshes = false, 
    2020                                                 vector<FaceParentInfo> *parents = NULL); 
    2121   
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp

    r1370 r1379  
    479479        { 
    480480                mBoundingBox = *forcedBoundingBox; 
    481         } 
    482         else // compute vsp tree bounding box 
    483         { 
    484                 mBoundingBox.Initialize(); 
    485                 VssRayContainer::const_iterator rit, rit_end = rays.end(); 
    486  
    487                 //-- compute bounding box 
    488         for (rit = rays.begin(); rit != rit_end; ++ rit) 
    489                 { 
    490                         VssRay *ray = *rit; 
    491  
    492                         // compute bounding box of view space 
    493                         mBoundingBox.Include(ray->GetTermination()); 
    494                         mBoundingBox.Include(ray->GetOrigin()); 
    495                 } 
     481                return; 
     482        } 
     483         
     484        ////////////////////////////////////////////// 
     485        // bounding box of view space includes all visibility events 
     486        mBoundingBox.Initialize(); 
     487        VssRayContainer::const_iterator rit, rit_end = rays.end(); 
     488 
     489        for (rit = rays.begin(); rit != rit_end; ++ rit) 
     490        { 
     491                VssRay *ray = *rit; 
     492 
     493                mBoundingBox.Include(ray->GetTermination()); 
     494                mBoundingBox.Include(ray->GetOrigin()); 
    496495        } 
    497496} 
     
    769768        VspLeaf *leaf = dynamic_cast<VspLeaf *>(tData.mNode); 
    770769         
     770        /////////////////////////////////////////////////////////////////// 
    771771        //-- the front and back traversal data is filled with the new values 
    772772 
     
    784784 
    785785        //-- compute pvs 
    786  
    787786        frontData.mPvs = EvalPvsSize(*frontData.mRays); 
    788787        backData.mPvs = EvalPvsSize(*backData.mRays); 
    789  
    790         Debug << "f pvs: " << frontData.mPvs << " b pvs: " << backData.mPvs << " pvs " << tData.mPvs << endl; 
    791  
    792         // split front and back node geometry and compute area 
     788        //Debug << "f pvs: " << frontData.mPvs << " b pvs: " << backData.mPvs << " pvs " << tData.mPvs << endl; 
     789         
     790        //-- split front and back node geometry and compute area 
    793791        tData.mBoundingBox.Split(splitPlane.mAxis,  
    794792                                                         splitPlane.mPosition,  
     
    799797        backData.mProbability = tData.mProbability - frontData.mProbability; 
    800798 
    801  
    802     /////////////////////////////////////////// 
    803         // subdivide further 
    804  
    805         // store maximal and minimal depth 
     799        // update some stats 
     800        // store maximal depth 
    806801        if (tData.mDepth > mVspStats.maxDepth) 
    807802        { 
    808                 Debug << "max depth increases to " << tData.mDepth  
    809                           << " at " << mVspStats.Leaves() << " leaves" << endl; 
     803                //Debug << "max depth increases to " << tData.mDepth << " at " << mVspStats.Leaves() << " leaves" << endl; 
    810804                mVspStats.maxDepth = tData.mDepth; 
    811805        } 
     
    813807        // two more leaves 
    814808        mVspStats.nodes += 2; 
    815      
     809 
     810 
     811    /////////////////////////////////////////// 
     812        //-- create front and back and subdivide further 
     813 
    816814        VspInterior *interior = new VspInterior(splitPlane); 
    817  
    818  
    819         //-- create front and back leaf 
    820  
    821815        VspInterior *parent = leaf->GetParent(); 
    822816 
     
    862856#endif 
    863857 
     858        // set the time stamp so the order of traversal can be reconstructed 
    864859        interior->mTimeStamp = mTimeStamp ++; 
    865860         
     
    14141409        const float viewSpaceVol = mBoundingBox.GetVolume(); 
    14151410 
    1416         // create unique ids for pvs heuristics 
     1411        ////////////////////////////////////////////// 
     1412        // mark objects in the front / back / both using mailboxing 
     1413        // then count pvs sizes 
    14171414        Intersectable::NewMail(3); 
    14181415        KdLeaf::NewMail(3); 
     
    14501447 
    14511448 
    1452         //-- pvs rendering heuristics 
     1449        //////////////////////////////////// 
     1450        //-- evaluate render cost heuristics 
    14531451 
    14541452        const int lowerPvsLimit = mViewCellsManager->GetMinPvsSize(); 
    14551453        const int upperPvsLimit = mViewCellsManager->GetMaxPvsSize(); 
    14561454 
    1457         // only render cost heuristics or combined with standard deviation 
    1458         const float penaltyOld = EvalPvsPenalty((int)totalPvs, lowerPvsLimit, upperPvsLimit); 
     1455        const float penaltyOld = EvalPvsPenalty((int)totalPvs, lowerPvsLimit, upperPvsLimit); 
    14591456    const float penaltyFront = EvalPvsPenalty((int)pvsFront, lowerPvsLimit, upperPvsLimit); 
    14601457        const float penaltyBack = EvalPvsPenalty((int)pvsBack, lowerPvsLimit, upperPvsLimit); 
     
    14631460        const float newRenderCost = penaltyFront * pFront + penaltyBack * pBack; 
    14641461 
     1462        // we also return the old render cost 
    14651463        normalizedOldRenderCost = oldRenderCost / viewSpaceVol; 
    14661464 
     1465        // the render cost decrase for this split 
    14671466        const float renderCostDecrease = (oldRenderCost - newRenderCost) / viewSpaceVol; 
    1468          
     1467#ifdef _DEBUG 
    14691468        Debug << "\neval vsp render cost decrease" << endl 
    14701469                  << "back pvs: " << pvsBack << " front pvs " << pvsFront << " total pvs: " << totalPvs << endl  
     
    14721471                  << "old rc: " << normalizedOldRenderCost << " new rc: " << newRenderCost / viewSpaceVol << endl 
    14731472                  << "render cost decrease: " << renderCostDecrease << endl; 
    1474  
     1473#endif 
    14751474        return renderCostDecrease; 
    14761475} 
     
    26512650 
    26522651SubdivisionCandidate *VspTree::PrepareConstruction(const VssRayContainer &sampleRays, 
    2653                                                                                                    AxisAlignedBox3 *forcedViewSpace, 
    26542652                                                                                                   RayInfoContainer &rays) 
    26552653{        
     
    26612659        VspSubdivisionCandidate::sVspTree = this; 
    26622660         
    2663         // compute view space bounding box 
    2664         ComputeBoundingBox(sampleRays, forcedViewSpace); 
    2665  
    26662661        // initialise termination criteria 
    26672662        mTermMinProbability *= mBoundingBox.GetVolume(); 
     
    26722667 
    26732668        const int pvsSize = EvalPvsSize(rays); 
    2674          
    2675         Debug <<  "pvs size: " << (int)pvsSize << endl; 
    2676         Debug <<  "rays size: " << (int)rays.size() << endl; 
     2669        //Debug <<  "pvs size: " << (int)pvsSize << endl; 
     2670        //Debug <<  "rays size: " << (int)rays.size() << endl; 
    26772671 
    26782672        //-- prepare view space partition 
     
    28512845                                ++ pvsSize; 
    28522846                        } 
     2847 
    28532848                        ++ obj->mCounter;        
    28542849                        break; 
     
    28702865                                pvsSize += (int)leaf->mObjects.size(); 
    28712866                        } 
     2867 
    28722868                        ++ leaf->mCounter;       
    28732869                        break; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h

    r1357 r1379  
    945945        SubdivisionCandidate *PrepareConstruction( 
    946946                const VssRayContainer &sampleRays, 
    947                 AxisAlignedBox3 *forcedViewSpace, 
    948947                RayInfoContainer &rays); 
    949948 
  • GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp

    r1344 r1379  
    3030#include "ViewCellsManager.h" 
    3131#include "ResourceManager.h" 
     32#include "IntersectableWrapper.h" 
    3233#include <assert.h> 
     34 
    3335 
    3436namespace GtpVisibilityPreprocessor { 
     
    8284// --------------------------------------------------------------------------- 
    8385X3dParseHandlers::X3dParseHandlers(SceneGraphNode *root,  
    84                                                                    const bool loadPolygonsAsMeshes): 
     86                                                                   const bool loadMeshes): 
    8587  mElementCount(0) 
    8688  , mAttrCount(0) 
    8789  , mCharacterCount(0) 
    8890  , mSpaceCount(0) 
    89   , mLoadPolygonsAsMeshes(loadPolygonsAsMeshes) 
     91  , mLoadMeshes(loadMeshes) 
    9092  , mCurrentMesh(NULL) 
    9193{ 
     
    224226         } 
    225227 
    226           
    227          //-- each polygon is one single mesh 
    228          if (mLoadPolygonsAsMeshes) 
     228         //////////////////////////////////// 
     229         //-- each triangle is one single mesh 
     230 
     231         if (!mLoadMeshes) 
    229232         { 
    230233                 cout << "m";    
    231                  FaceContainer::const_iterator fit, fit_end = mCurrentMesh->mFaces.end(); 
     234                 Mesh tempMesh(*mCurrentMesh); 
     235                 ApplyTransformations(mTransformations, &tempMesh); 
     236 
     237                 FaceContainer::const_iterator fit, fit_end = tempMesh.mFaces.end(); 
    232238                 
    233                  for (fit = mCurrentMesh->mFaces.begin(); fit != fit_end; ++ fit) 
     239                 for (fit = tempMesh.mFaces.begin(); fit != fit_end; ++ fit) 
    234240                 { 
    235241                         cout << "f"; 
     242                         // triangulate the faces 
    236243                         Face *face = *fit; 
    237                  
     244                         vector<Triangle3> triangles; 
     245                         Polygon3 poly(face, &tempMesh); 
     246                         poly.Triangulate(triangles); 
     247 
     248                         vector<Triangle3>::const_iterator tit, tit_end = triangles.end(); 
     249 
     250                         for (tit = triangles.begin(); tit != tit_end; ++ tit) 
     251                         { 
     252                                 cout << "triangle: " << *tit << endl; 
     253                                 TriangleIntersectable *ti = new TriangleIntersectable(*tit); 
     254                                 mCurrentNode->mGeometry.push_back(ti); 
     255                         } 
     256#if 0 
    238257                         // we create a new mesh for each face from the current mesh 
    239258                         Mesh *mesh = MeshManager::GetSingleton()->CreateResource(); 
     
    249268                                 cout << "i"; 
    250269                                 const int index = (*vit); 
    251  
    252270                                 // add vertices 
    253271                                 mesh->mVertices.push_back(mCurrentMesh->mVertices[index]); 
    254  
    255                                  // indices don't make much sense if mesh == face,  
    256                                  // but we need them anyway ... 
     272                                 // indices don't make much sense if mesh == face, but we need them anyway ... 
    257273                                 vcIndices.push_back(i); 
    258274                         } 
     
    260276                         mesh->mFaces.push_back(new Face(vcIndices)); 
    261277 
    262                          // write transformations directly in mesh  
     278                         // write transformations directly into the mesh 
    263279                         // note: could be transformed in parent mesh, save some transformations 
    264280                         ApplyTransformations(mTransformations, mesh); 
     
    283299                                 } 
    284300                         } 
     301#endif 
    285302                 } 
    286303 
     
    656673X3dParser::ParseFile(const string filename, 
    657674                                         SceneGraphNode *root, 
    658                                          const bool loadPolygonsAsMeshes, 
     675                                         const bool loadMeshes, 
    659676                                         vector<FaceParentInfo> *parents) 
    660677{ 
     
    689706  //  to do. 
    690707  // 
    691   X3dParseHandlers handler(root, loadPolygonsAsMeshes); 
     708  X3dParseHandlers handler(root, loadMeshes); 
    692709  parser->setDocumentHandler(&handler); 
    693710  parser->setErrorHandler(&handler); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.h

    r1344 r1379  
    1818                                   const string filename,  
    1919                                   SceneGraphNode *root,  
    20                                    const bool loadPolygonsAsMeshes = false, 
     20                                   const bool loadMeshes = false, 
    2121                                   vector<FaceParentInfo> *parents = NULL); 
    2222 
  • GTP/trunk/Lib/Vis/Preprocessing/src/X3dParserXerces.h

    r1020 r1379  
    4141  //  Constructors and Destructor 
    4242  // ----------------------------------------------------------------------- 
    43   X3dParseHandlers(SceneGraphNode *root, const bool loadPolygonsAsMeshes = false); 
     43  X3dParseHandlers(SceneGraphNode *root, const bool loadMeshes = false); 
    4444  ~X3dParseHandlers(); 
    4545   
     
    8888  Material *mCurrentMaterial; 
    8989   
    90   bool mLoadPolygonsAsMeshes; 
     90  bool mLoadMeshes; 
    9191 
    9292  typedef stack<Matrix4x4> TrafoStack; 
Note: See TracChangeset for help on using the changeset viewer.