Changeset 1763


Ignore:
Timestamp:
11/16/06 19:41:44 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
14 edited

Legend:

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

    r1761 r1763  
    8484} 
    8585 
     86 
     87int BvhNode::GetRandomEdgePoint(Vector3 &point, 
     88                                                                Vector3 &normal) 
     89{ 
     90        // get random edge 
     91        const int idx = Random(12);  
     92        Vector3 a, b; 
     93        mBoundingBox.GetEdge(idx, &a, &b); 
     94         
     95        const float factor = RandomValue(0.0f, 1.0f); 
     96 
     97        point = a * factor + b * (1 - factor); 
     98        //normal = mBoundingBox.GetNormal(); 
     99 
     100        return idx; 
     101} 
    86102 
    87103 
     
    415431         
    416432        // set the time stamp so the order of traversal can be reconstructed 
    417         node->mTimeStamp = mHierarchyManager->mTimeStamp ++; 
     433        node->SetTimeStamp(mHierarchyManager->mTimeStamp ++); 
    418434                 
    419435        // assign the objects in sorted order 
     
    16991715                numRays += CollectViewCells(*oit, viewCells, true, setCounter, onlyMailedRays); 
    17001716        } 
    1701         //cout << "here4 " << numRays << " boj: " << objects.size() << " " << onlyMailedRays << endl; 
    17021717 
    17031718        return numRays; 
     
    18181833        int numRays = CollectViewCells(node->mObjects, viewCells, false, false); 
    18191834 
    1820         //cout << "here6 " << numRays << endl; 
    18211835        if (0) cout << "collected " << (int)viewCells.size() << " dirty candidates" << endl; 
    18221836         
     
    23532367                BvhSubdivisionCandidate *backCandidate = new BvhSubdivisionCandidate(tBackData); 
    23542368 
    2355                 frontCandidate->SetPriority((float)-oldInterior->GetFront()->mTimeStamp); 
    2356                 backCandidate->SetPriority((float)-oldInterior->GetBack()->mTimeStamp); 
     2369                frontCandidate->SetPriority((float)-oldInterior->GetFront()->GetTimeStamp()); 
     2370                backCandidate->SetPriority((float)-oldInterior->GetBack()->GetTimeStamp()); 
    23572371 
    23582372                frontCandidate->mEvaluationHack = oldInterior->GetFront(); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h

    r1761 r1763  
    6363        { return rayRefs / (double)Leaves(); }  
    6464 
    65  
     65         
    6666        void Reset()  
    6767        { 
     
    201201        float GetMergeCost() {return (float)-mTimeStamp; } 
    202202 
    203         int mTimeStamp; 
     203        virtual int GetRandomEdgePoint(Vector3 &point, 
     204                                                                 Vector3 &normal); 
     205 
     206        inline int GetTimeStamp() const { return mTimeStamp; } 
     207        inline void SetTimeStamp(const int timeStamp) { mTimeStamp = timeStamp; }; 
    204208 
    205209        ///////////////////////////////////// 
     
    269273        /// parent of this node 
    270274        BvhInterior *mParent; 
     275        int mTimeStamp; 
    271276}; 
    272277 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r1760 r1763  
    741741        if (!success) // split was not taken 
    742742        { 
     743                cout << "x"; 
    743744                return false; 
    744745        } 
     
    17311732        int Type()  const { return BVH_NODE; } 
    17321733 
    1733         float GetMergeCost() const { return (float)-mNode->mTimeStamp; }; 
     1734        float GetMergeCost() const { return (float)-mNode->GetTimeStamp(); }; 
    17341735 
    17351736        bool IsLeaf() const { return mNode->IsLeaf(); } 
     
    18561857                        ++ pvsEntries; 
    18571858                        rc += mBvHierarchy->EvalAbsCost(objects); 
    1858                         //cout << " pvs: " << mBvHierarchy->EvalAbsCost(leaf->mObjects); 
    18591859                } 
    18601860        } 
     
    19101910        // collect best set of view cells for this #splits 
    19111911    CollectBestSet(maxSplits, maxMemoryCost, viewCells, bvhNodes); 
    1912         //cout << "here5 " << bvhNodes.size() << endl; 
    19131912        vector<BvhNode *>::const_iterator bit, bit_end = bvhNodes.end(); 
    19141913         
     
    21112110 
    21122111        firstVsp->SetPriority((float)-oldVspRoot->mTimeStamp); 
    2113         firstBvh->SetPriority((float)-oldBvhRoot->mTimeStamp); 
     2112        firstBvh->SetPriority((float)-oldBvhRoot->GetTimeStamp()); 
    21142113 
    21152114        tQueue.Push(firstVsp); 
     
    22142213        mOldViewCells.clear(); 
    22152214 
     2215        // reset active nodes 
     2216        vector<BvhLeaf *> bvhLeaves; 
     2217 
     2218        mBvHierarchy->CollectLeaves(mBvHierarchy->GetRoot(), bvhLeaves); 
     2219 
     2220        vector<BvhLeaf *>::const_iterator bit, bit_end = bvhLeaves.end(); 
     2221 
     2222        for (bit = bvhLeaves.begin(); bit != bit_end; ++ bit) 
     2223        { 
     2224                (*bit)->SetActiveNode(*bit); 
     2225        } 
     2226 
    22162227        cout << endl; 
    22172228} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h

    r1743 r1763  
    113113  virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0; 
    114114 
     115  virtual int GetRandomEdgePoint(Vector3 &point, 
     116                                                                 Vector3 &normal) = 0; 
     117 
    115118  virtual int GetRandomVisibleSurfacePoint(Vector3 &point, 
    116119                                                                                   Vector3 &normal, 
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.cpp

    r1758 r1763  
    9292 
    9393 
     94int TriangleIntersectable::GetRandomEdgePoint(Vector3 &point, 
     95                                                                                          Vector3 &normal) 
     96{ 
     97        int edge = Random(3); 
     98 
     99        Vector3 a = mItem.mVertices[edge]; 
     100        Vector3 b = mItem.mVertices[(edge + 1) % 3]; 
     101 
     102        const float factor = RandomValue(0.0f, 1.0f); 
     103 
     104        point = a * factor + b * factor; 
     105        normal = mItem.GetNormal(); 
     106 
     107        return edge; 
     108} 
     109 
     110 
    94111KdIntersectable::KdIntersectable(KdNode *item, const AxisAlignedBox3 &box)  : 
    95112  IntersectableWrapper<KdNode *>(item) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.h

    r1758 r1763  
    6262        ostream &Describe(ostream &s); 
    6363         
    64  
     64        int GetRandomEdgePoint(Vector3 &point, Vector3 &normal); 
    6565protected: 
    6666         
     
    111111} 
    112112 
     113 
    113114template<typename T> 
    114115float IntersectableWrapper<T>::IntersectionComplexity() 
     
    117118} 
    118119 
     120 
    119121template<typename T> 
    120122int IntersectableWrapper<T>::NumberOfFaces() const 
     
    122124        return 0; 
    123125} 
     126 
    124127 
    125128template<typename T> 
     
    129132        return 0; 
    130133} 
     134 
     135 
     136template<typename T> 
     137int IntersectableWrapper<T>::GetRandomEdgePoint(Vector3 &point, 
     138                                                                                                Vector3 &normal) 
     139{ 
     140        return 0; 
     141} 
     142 
    131143 
    132144template<typename T> 
     
    193205                                                                         const Vector3 &viewpoint, 
    194206                                                                         const int maxTries); 
     207 
     208        int GetRandomEdgePoint(Vector3 &point, Vector3 &normal); 
     209 
    195210}; 
    196211 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp

    r1587 r1763  
    795795 
    796796 
     797int MeshInstance::GetRandomEdgePoint(Vector3 &point, Vector3 &normal) 
     798{ 
     799        // TODO 
     800        return mMesh->GetRandomSurfacePoint(point, normal); 
     801} 
     802 
    797803 
    798804/*************************************************************/ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h

    r1419 r1763  
    245245 
    246246public: 
    247   MeshInstance(Mesh *mesh):Intersectable(), mMesh(mesh), mMaterial(NULL) 
    248   { 
    249   } 
    250  
    251   int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); 
    252  
    253         int 
    254         GetRandomVisibleSurfacePoint(Vector3 &point, 
    255                                                                                                                          Vector3 &normal, 
    256                                                                                                                          const Vector3 &viewpoint, 
    257                                                                                                                          const int maxTries 
    258                                                                                                                          ); 
    259  
    260  
    261   Mesh *GetMesh() { return mMesh; } 
    262  
    263   virtual AxisAlignedBox3 GetBox() const { 
    264     return mMesh->mBox; 
    265   } 
    266  
    267   virtual int CastRay(Ray &ray); 
    268  
    269   virtual bool IsConvex() const { return mMesh->mIsConvex; } 
    270   virtual bool IsWatertight() const { return mMesh->mIsWatertight; } 
    271   virtual float IntersectionComplexity() {  return (float)mMesh->mFaces.size(); } 
    272  
    273   virtual int NumberOfFaces() const {  return (int)mMesh->mFaces.size(); } 
    274  
    275   virtual int Type() const { return MESH_INSTANCE; } 
    276  
    277   virtual int 
    278   CastRay( 
    279           Ray &ray, 
    280           const vector<int> &faces 
    281           ); 
     247        MeshInstance(Mesh *mesh):Intersectable(), mMesh(mesh), mMaterial(NULL) 
     248        { 
     249        } 
     250 
     251        int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); 
     252 
     253        int     GetRandomVisibleSurfacePoint(Vector3 &point, 
     254                Vector3 &normal, 
     255                const Vector3 &viewpoint, 
     256                const int maxTries 
     257                ); 
     258 
     259 
     260        virtual int GetRandomEdgePoint(Vector3 &point, 
     261                                                                 Vector3 &normal); 
     262 
     263        Mesh *GetMesh() { return mMesh; } 
     264 
     265        virtual AxisAlignedBox3 GetBox() const { 
     266                return mMesh->mBox; 
     267        } 
     268 
     269        virtual int CastRay(Ray &ray); 
     270 
     271        virtual bool IsConvex() const { return mMesh->mIsConvex; } 
     272        virtual bool IsWatertight() const { return mMesh->mIsWatertight; } 
     273        virtual float IntersectionComplexity() {  return (float)mMesh->mFaces.size(); } 
     274 
     275        virtual int NumberOfFaces() const {  return (int)mMesh->mFaces.size(); } 
     276 
     277        virtual int Type() const { return MESH_INSTANCE; } 
     278 
     279        virtual int 
     280                CastRay( 
     281                Ray &ray, 
     282                const vector<int> &faces 
     283                ); 
    282284 
    283285 
     
    286288                return mMesh->Describe(s); 
    287289        } 
    288          
     290 
    289291        /** Sets the material. this overrides the material from  
    290                 the mesh itself. 
     292        the mesh itself. 
    291293        */ 
    292294        void SetMaterial(Material *mat); 
    293295 
    294296        /** Returns the material of this mesh instance. 
    295                 if not defined, returns the material of the mesh itself. 
     297        if not defined, returns the material of the mesh itself. 
    296298        */ 
    297299        Material *GetMaterial() const; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.cpp

    r1758 r1763  
    143143        Intersectable::NewMail(); 
    144144        KdLeaf::NewMail(); 
    145         BvhLeaf::NewMail(); 
     145        BvhNode::NewMail(); 
    146146 
    147147        ObjectPvsEntries::const_iterator it, it_end = mEntries.end(); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp

    r1695 r1763  
    183183} 
    184184 
     185 
     186bool ViewCellBorderBasedDistribution::GenerateSample(SimpleRay &ray) const 
     187{ 
     188        Vector3 origin, direction;  
     189 
     190        ViewCellContainer &viewCells = mPreprocessor.mViewCellsManager->GetViewCells(); 
     191 
     192        Vector3 point; 
     193        Vector3 normal, normal2; 
     194         
     195        //cout << "y"; 
     196        const int vcIdx = (int)RandomValue(0, (float)viewCells.size() - 0.5f); 
     197        const int objIdx = (int)RandomValue(0, (float)mPreprocessor.mObjects.size() - 0.5f); 
     198 
     199        Intersectable *object = mPreprocessor.mObjects[objIdx]; 
     200        ViewCell *viewCell = viewCells[vcIdx]; 
     201 
     202        object->GetRandomSurfacePoint(point, normal); 
     203        viewCell->GetRandomEdgePoint(origin, normal2); 
     204 
     205        direction = point - origin; 
     206 
     207        // $$ jb the pdf is yet not correct for all sampling methods! 
     208        const float c = Magnitude(direction); 
     209 
     210        if (c <= Limits::Small)  
     211                return false; 
     212 
     213        // $$ jb the pdf is yet not correct for all sampling methods! 
     214        const float pdf = 1.0f; 
     215        //cout << "p: " << point << " "; 
     216        direction *= 1.0f / c; 
     217        ray = SimpleRay(origin, direction, pdf); 
     218         
     219        return true; 
     220} 
     221 
    185222#if 0 
    186223bool ObjectsInteriorDistribution::GenerateSample(SimpleRay &ray) const 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h

    r1695 r1763  
    109109 
    110110 
     111class ViewCellBorderBasedDistribution: public SamplingStrategy 
     112{ 
     113 public: 
     114         ViewCellBorderBasedDistribution(const Preprocessor &preprocessor): 
     115         SamplingStrategy(preprocessor) {} 
     116          
     117         virtual bool GenerateSample(SimpleRay &ray) const; 
     118}; 
     119 
     120 
    111121/** This strategy generates samples inside of the objects, e.g., 
    112122        for sampling the inside of a colon. 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r1758 r1763  
    17851785        ViewCellContainer::const_iterator it, it_end = leaves.end(); 
    17861786 
    1787         Intersectable::NewMail(); 
    17881787        ObjectPvs newPvs; 
    17891788 
     
    17911790        for (it = leaves.begin(); it != it_end; ++ it) 
    17921791        { 
    1793                 ObjectPvsIterator oit = (*it)->GetPvs().GetIterator(); 
    1794  
    1795                 while (oit.HasMoreEntries()) 
    1796                 { 
    1797                         ObjectPvsEntry entry = oit.Next(); 
    1798                         Intersectable *intersect = entry.mObject; 
    1799  
    1800                         if (!intersect->Mailed()) 
    1801                         { 
    1802                                 intersect->Mail(); 
    1803                                 newPvs.AddSample(intersect, entry.mData.mSumPdf); 
    1804                         } 
    1805                 } 
     1792                newPvs.MergeInPlace((*it)->GetPvs()); 
    18061793        } 
    18071794 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1761 r1763  
    15791579                mViewCellsTree->UpdateViewCellsStats(*it, mCurrentViewCellsStats); 
    15801580        } 
    1581         cout << "here44 " << mCurrentViewCellsStats.maxPvs << endl; 
    15821581} 
    15831582 
     
    22142213{ 
    22152214        ViewCellContainer::const_iterator it, it_end = mViewCells.end(); 
    2216 cout << "here2" << endl; 
     2215 
    22172216        for (it = mViewCells.begin(); it != it_end; ++ it) 
    2218         {cout << "here4 " << mOnlyValidViewCells << " " << (*it)->GetValid() <<  endl; 
     2217        { 
    22192218                if (!mOnlyValidViewCells || (*it)->GetValid()) 
    2220                 {cout << "here5 " << mColorCode << endl; 
     2219                { 
    22212220                        ExportColor(exporter, *it, colorCode);   
    22222221                        ExportViewCellGeometry(exporter, *it, sceneBox, clipPlane); 
     
    27892788                 
    27902789        case 1: // pvs 
    2791                 { //cout << "here22 " << mCurrentViewCellsStats.maxPvs << endl; 
     2790                { 
    27922791                        if (mCurrentViewCellsStats.maxPvs) 
    27932792                        { 
    2794                                 //cout << "pvscost : " << (float)mViewCellsTree->GetPvsCost(vc) << endl; 
    2795                                 //cout << "maxPvs : " << (float)mCurrentViewCellsStats.maxPvs << endl; 
    2796  
    2797                                 importance =  
    2798                                         (float)mViewCellsTree->GetPvsCost(vc) /  
    2799                                         (float)mCurrentViewCellsStats.maxPvs; 
     2793                                importance = (float)mViewCellsTree->GetPvsCost(vc) /  
     2794                                                         (float)mCurrentViewCellsStats.maxPvs; 
    28002795                        } 
    28012796                } 
     
    28172812#endif 
    28182813        default: 
    2819                 cout << "here10" << endl; 
    28202814                break; 
    28212815        } 
     
    30573051        const int savedColorCode = mColorCode; 
    30583052 
     3053        Exporter *exporter; 
     3054 
     3055#if 0 
    30593056        // export merged view cells 
    30603057        mColorCode = 0; // use random colors 
    30613058 
    3062         Exporter *exporter = Exporter::GetExporter("merged_view_cells.wrl"); 
     3059        exporter = Exporter::GetExporter("merged_view_cells.wrl"); 
    30633060 
    30643061        cout << "exporting view cells after merge ... "; 
     
    30773074        } 
    30783075        cout << "finished" << endl; 
     3076#endif 
    30793077 
    30803078        // export merged view cells using pvs color coding 
    3081          
    30823079        exporter = Exporter::GetExporter("merged_view_cells_pvs.wrl"); 
    30833080        cout << "exporting view cells after merge (pvs size) ... ";      
     
    30923089                exporter->SetFilled(); 
    30933090                mColorCode = 1; 
    3094 cout << "here49 " << mColorCode << endl; 
     3091 
    30953092                ExportViewCellsForViz(exporter, NULL,  mColorCode, GetClipPlane()); 
    30963093 
     
    31833180 
    31843181        //  visualization of the view cells 
    3185         if (0) ExportMergedViewCells(objects); 
     3182        if (1) ExportMergedViewCells(objects); 
    31863183 
    31873184        // compute final meshes and volume / area 
     
    55045501        Exporter *exporter = Exporter::GetExporter("final_view_cells.wrl"); 
    55055502 
     5503        Vector3 scale(1.0f, 0.9f, 1.0f); 
    55065504        if (exporter) 
    55075505        { 
     5506                EvaluateViewCellsStats(); 
     5507 
    55085508                // hack color code (show pvs size) 
    55095509                const int savedColorCode = mColorCode; 
    5510                 mColorCode = 0; 
     5510                mColorCode = 1; // export pvs 
    55115511 
    55125512                const long starttime = GetTime(); 
     
    55155515                // matt: hack for clamping scene 
    55165516                AxisAlignedBox3 bbox = mViewSpaceBox; 
    5517                 bbox.Scale(Vector3(0.5, 1, 0.5)); 
     5517                bbox.Scale(scale); 
    55185518 
    55195519                if (CLAMP_TO_BOX) 
     
    55365536                mHierarchyManager->ExportObjectSpaceHierarchy(exporter, objects,  
    55375537                                                                                                          CLAMP_TO_BOX ? &bbox : NULL, false); 
    5538                 ExportViewCellsForViz(exporter, CLAMP_TO_BOX ? &bbox : NULL, mColorCode, GetClipPlane()); 
     5538                 
     5539                //ExportViewCellsForViz(exporter, CLAMP_TO_BOX ? &bbox : NULL, mColorCode, GetClipPlane()); 
     5540                ExportViewCellsForViz(exporter, NULL, mColorCode, GetClipPlane()); 
    55395541 
    55405542                delete exporter; 
     
    55535555                // matt: hack for making visualization smaller in size 
    55545556                AxisAlignedBox3 bbox = mHierarchyManager->GetObjectSpaceBox(); 
    5555                 bbox.Scale(Vector3(0.5, 1, 0.5)); 
     5557                bbox.Scale(scale); 
    55565558 
    55575559                cout << "exporting object space hierarchy ... "; 
     
    55625564        } 
    55635565         
    5564         cout << "here92 " << mHierarchyManager->GetVspTree()->GetStatistics().maxPvs << endl; 
    5565  
    55665566        // visualization of the view cells 
    5567     if (1)  
     5567    if (0)  
    55685568        {        
    5569                 EvaluateViewCellsStats(); 
    55705569                ExportMergedViewCells(objects); 
    55715570        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp

    r1760 r1763  
    505505        Debug << "vsp mem const: " << mMemoryConst << endl; 
    506506 
     507        cout << "use cost heuristics: " << mUseCostHeuristics << endl; 
     508 
    507509        Debug << endl; 
    508510} 
Note: See TracChangeset for help on using the changeset viewer.