Changeset 1135


Ignore:
Timestamp:
07/17/06 09:59:26 (18 years ago)
Author:
mattausch
Message:

uaing rays for osp

Location:
GTP/trunk/Lib/Vis/Preprocessing
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/scripts/Preprocessor.vcproj

    r1106 r1135  
    206206                        </File> 
    207207                        <File 
     208                                RelativePath="..\src\KdIntersectable.cpp"> 
     209                        </File> 
     210                        <File 
     211                                RelativePath="..\src\KdIntersectable.h"> 
     212                        </File> 
     213                        <File 
    208214                                RelativePath="..\src\KdTree.cpp"> 
    209215                        </File> 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h

    r1133 r1135  
    3333  //set<KdLeaf *> mKdLeaves; 
    3434 
    35   enum { MESH_INSTANCE, TRANSFORMED_MESH_INSTANCE, SPHERE, VIEW_CELL, OGRE_MESH_INSTANCE }; 
     35  /// # of object references 
     36  int mObjectRefs; 
     37 
     38  enum { MESH_INSTANCE,  
     39                 TRANSFORMED_MESH_INSTANCE,  
     40                 SPHERE,  
     41                 VIEW_CELL,  
     42                 OGRE_MESH_INSTANCE, 
     43                 KD_INTERSECTABLE 
     44                }; 
    3645   
    37   Intersectable():mMailbox(0) {} 
     46  Intersectable():mMailbox(0), mObjectRefs(0) {} 
    3847 
    3948        void SetId(const int id) { mId = id; } 
     
    8897}; 
    8998 
     99 
    90100} 
    91101 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1112 r1135  
    3939                for (int j = 0; j < n; ++ j) 
    4040                { 
    41                         const Vector3 scale2((float)j * 0.8 / n + 0.1,  0.05, (float)i * 0.8  / (float)n + 0.1); 
     41                        const Vector3 scale2((float)j * 0.8f / n + 0.1f,  0.05f, (float)i * 0.8f  / (float)n + 0.1f); 
    4242                 
    4343                        const Vector3 pt2 = sceneBox.Min() + scale2 * (sceneBox.Max() - sceneBox.Min()); 
     
    5858                for (int j = 0; j < n; ++ j) 
    5959                { 
    60                         const Vector3 scale2(0.15, (float)j * 0.8 / n + 0.1, (float)i * 0.8  / (float)n + 0.1); 
     60                        const Vector3 scale2(0.15f, (float)j * 0.8f / n + 0.1f, (float)i * 0.8f  / (float)n + 0.1f); 
    6161                 
    6262                        Vector3 pt2 = sceneBox.Min() + scale2 * (sceneBox.Max() - sceneBox.Min()); 
    6363                 
    64                         Vector3 boxSize = sceneBox.Size() * Vector3(0.0025, 0.01, 0.0025); 
     64                        Vector3 boxSize = sceneBox.Size() * Vector3(0.0025f, 0.01f, 0.0025f); 
    6565                        AxisAlignedBox3 box(pt2, pt2 + boxSize); 
    6666                        Mesh *mesh = CreateMeshFromBox(box); 
     
    7575        for (int i = 0; i < n; ++ i) 
    7676        { 
    77                 const Vector3 scale2(2, 0.2, (float)i * 0.8  / (float)n + 0.1); 
     77                const Vector3 scale2(2, 0.2f, (float)i * 0.8f  / (float)n + 0.1f); 
    7878                 
    7979                Vector3 pt2 = sceneBox.Min() + scale2 * (sceneBox.Max() - sceneBox.Min()); 
    8080                 
    8181                //Vector3 boxSize = sceneBox.Size() * Vector3(0.0025, 0.01, 0.0025); 
    82                 Vector3 boxSize = sceneBox.Size() * Vector3(0.005, 0.02, 0.005); 
    83  
    84                 AxisAlignedBox3 box(pt2 + 0.1, pt2 + boxSize); 
     82                Vector3 boxSize = sceneBox.Size() * Vector3(0.005f, 0.02f, 0.005f); 
     83 
     84                AxisAlignedBox3 box(pt2 + 0.1f, pt2 + boxSize); 
    8585                Mesh *mesh = CreateMeshFromBox(box); 
    8686 
     
    9797        if (1) 
    9898        { 
    99                 const Vector3 scale(1.0, 0.0, 0); 
     99                const Vector3 scale(1.0f, 0.0, 0); 
    100100 
    101101                Vector3 pt = sceneBox.Min() + scale * (sceneBox.Max() - sceneBox.Min()); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r1133 r1135  
    265265{ 
    266266        const bool result = mKdPvs.AddSample(sample, pdf, contribution); 
    267  
    268267        return result; 
    269268} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1133 r1135  
    54905490                                        obj->Mail(); 
    54915491                                }                                        
    5492  
     5492        // TODO matt§§ 
     5493#if TODO 
    54935494                                // collect kd leaves 
    54945495                                //KdLeaf = 
     
    55055506                                        } 
    55065507                                } 
     5508#endif 
    55075509                        } 
    55085510 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp

    r1133 r1135  
    4747 
    4848 
    49  
    5049void VspTreeStatistics::Print(ostream &app) const 
    5150{ 
     
    443442 
    444443 
    445 void VspTree::PrepareConstruction(const VssRayContainer &sampleRays, 
    446                                                                   AxisAlignedBox3 *forcedBoundingBox)  
    447 { 
    448         // store pointer to this tree 
    449         VspSplitCandidate::sVspTree = this; 
    450  
    451         mVspStats.nodes = 1; 
    452          
     444void VspTree::ComputeBoundingBox(const RayInfoContainer &rays, 
     445                                                                 AxisAlignedBox3 *forcedBoundingBox)  
     446{        
    453447        if (forcedBoundingBox) 
    454448        { 
     
    459453                mBoundingBox.Initialize(); 
    460454 
    461                 VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); 
     455                RayInfoContainer::const_iterator rit, rit_end = rays.end(); 
    462456 
    463457                //-- compute bounding box 
    464         for (rit = sampleRays.begin(); rit != rit_end; ++ rit) 
    465                 { 
    466                         VssRay *ray = *rit; 
     458        for (rit = rays.begin(); rit != rit_end; ++ rit) 
     459                { 
     460                        VssRay *ray = (*rit).mRay; 
    467461 
    468462                        // compute bounding box of view space 
     
    471465                } 
    472466        } 
    473  
    474         mTermMinProbability *= mBoundingBox.GetVolume(); 
    475         mGlobalCostMisses = 0; 
    476467} 
    477468 
     
    697688 
    698689        frontData.mDepth = tData.mDepth + 1; 
     690        backData.mDepth = tData.mDepth + 1; 
     691 
    699692        frontData.mRays = new RayInfoContainer(); 
    700          
    701         backData.mDepth = tData.mDepth + 1; 
    702693        backData.mRays = new RayInfoContainer(); 
    703          
     694 
    704695        //-- subdivide rays 
    705696        SplitRays(splitPlane, 
     
    707698                          *frontData.mRays, 
    708699                          *backData.mRays); 
    709  
    710700         
    711701        //Debug << "f: " << frontData.mRays->size() << " b: " << backData.mRays->size() << "d: " << tData.mRays->size() << endl; 
     
    889879 
    890880                        // potentially visible kd cells 
    891                         const bool termination = true; 
    892                         vc->AddKdPvsSample(GetKdLeaf(ray, termination)); 
     881                        KdLeaf *leaf =  
     882                                mOspTree->GetLeaf(ray->mTermination, ray->mTerminationNode); 
     883                        float kdcontri; 
     884                        vc->AddKdPvsSample(leaf, 1, kdcontri); 
    893885                } 
    894886 
     
    903895 
    904896                        sc += contribution; 
    905  
     897         
    906898                        // potentially visible kd cells 
    907                         const bool termination = false; 
    908                         vc->AddKdPvsSample(GetKdLeaf(ray, termination)); 
    909                 } 
    910  
     899                        const bool origin = true; 
     900                        KdLeaf *leaf = 
     901                                mOspTree->GetLeaf(ray->mOrigin, ray->mOriginNode); 
     902                        float kdcontri; 
     903                        vc->AddKdPvsSample(leaf, 1, kdcontri); 
     904                } 
    911905 
    912906                if (madeContrib) 
     
    987981 
    988982int VspTree::PrepareHeuristics(Intersectable *object) 
    989 { 
     983{        
     984        int pvsSize = 0; 
     985        // TODO matt§§ 
     986#if TODO 
    990987        set<KdLeaf *>::const_iterator kit, kit_end = object->mKdLeaves.end(); 
    991          
    992         int pvsSize = 0; 
    993988 
    994989        for (kit = object->mKdLeaves.begin(); kit != kit_end; ++ kit) 
     
    10291024                } 
    10301025        } 
    1031  
     1026#endif 
    10321027        return pvsSize; 
    10331028} 
     
    11771172                else // per kd node 
    11781173                { 
     1174        // TODO matt§§ 
     1175#if TODO 
    11791176                        set<KdLeaf *>::const_iterator kit, kit_end = oObject->mKdLeaves.end(); 
    11801177 
     
    11931190                                } 
    11941191                        } 
     1192#endif 
    11951193                } 
    11961194                         
     
    12181216                else // per kd node 
    12191217                { 
     1218                        // TODO matt§§ 
     1219#if TODO 
    12201220                        set<KdLeaf *>::const_iterator kit, kit_end = tObject->mKdLeaves.end(); 
    12211221                         
     
    12331233                                } 
    12341234                        } 
    1235                 } 
    1236         } 
    1237 } 
    1238  
    1239  
    1240 float VspTree::EvalLocalCostHeuristics(const RayInfoContainer &rays, 
     1235#endif 
     1236                } 
     1237        } 
     1238} 
     1239 
     1240 
     1241float VspTree::EvalLocalCostHeuristics(const VspTraversalData &tData, 
    12411242                                                                           const AxisAlignedBox3 &box, 
    1242                                                                            int pvsSize, 
    12431243                                                                           const int axis, 
    12441244                                                                           float &position) 
    12451245{ 
     1246        RayInfoContainer *rays = tData.mRays; 
     1247        int pvsSize = tData.mPvs; 
     1248 
    12461249        const float minBox = box.Min(axis); 
    12471250        const float maxBox = box.Max(axis); 
     
    12521255        const float maxBand = minBox + mMaxBand * sizeBox; 
    12531256 
    1254         SortSplitCandidates(rays, axis, minBand, maxBand); 
     1257        SortSplitCandidates(*rays, axis, minBand, maxBand); 
    12551258 
    12561259        // prepare the sweep 
    12571260        // (note: returns pvs size, so there would be no need  
    12581261        // to give pvs size as argument) 
    1259         pvsSize = PrepareHeuristics(rays); 
     1262        pvsSize = PrepareHeuristics(*rays); 
    12601263 
    12611264        // go through the lists, count the number of objects left and right 
     
    13851388                                //-- place split plane using heuristics 
    13861389                                nCostRatio[axis] = 
    1387                                         EvalLocalCostHeuristics(*tData.mRays, 
     1390                                        EvalLocalCostHeuristics(tData, 
    13881391                                                                                        box, 
    1389                                                                                         tData.mPvs, 
    13901392                                                                                        axis, 
    13911393                                                                                        nPosition[axis]);                        
     
    24532455                const int side = bRay.ComputeRayIntersection(plane.mAxis, plane.mPosition, t); 
    24542456                         
    2455  
    2456 #if 1 
    24572457                if (side == 0) 
    24582458                { 
     
    24782478                        backRays.push_back(bRay); 
    24792479                } 
    2480 #else 
    2481                 if (side == 0) 
    2482                 { 
    2483                         ++ splits; 
    2484  
    2485                         if (ray->HasPosDir(plane.mAxis)) 
    2486                         { 
    2487                                 backRays.push_back(RayInfo(ray, bRay.GetMaxT(), t)); 
    2488                                 frontRays.push_back(RayInfo(ray, t, bRay.GetMinT())); 
    2489                         } 
    2490                         else 
    2491                         { 
    2492                                 frontRays.push_back(RayInfo(ray, bRay.GetMaxT(), t)); 
    2493                                 backRays.push_back(RayInfo(ray, t, bRay.GetMinT())); 
    2494                         } 
    2495                 } 
    2496                 else if (side == 1) 
    2497                 { 
    2498                         backRays.push_back(bRay); 
    2499                 } 
    2500                 else 
    2501                 { 
    2502                         frontRays.push_back(bRay); 
    2503                          
    2504                 } 
    2505 #endif 
    25062480        } 
    25072481 
     
    25822556 
    25832557 
    2584  
    2585  
    25862558void VspTree::CollectDirtyCandidates(VspSplitCandidate *sc,  
    25872559                                                                         vector<SplitCandidate *> &dirtyList) 
     
    25982570        { 
    25992571                Intersectable *obj = (*oit).first; 
    2600  
     2572        // TODO matt§§ 
     2573#if TODO 
    26012574                set<KdLeaf *>::const_iterator kit, kit_end = obj->mKdLeaves.end(); 
    2602  
     2575         
    26032576                for (kit = obj->mKdLeaves.begin(); kit != kit_end; ++ kit) 
    26042577                { 
     
    26112584                        } 
    26122585                } 
    2613         } 
     2586#endif 
     2587        } 
     2588} 
     2589 
     2590 
     2591void VspTree::ProcessRays(const VssRayContainer &sampleRays, 
     2592                                                  RayInfoContainer &rays) 
     2593{ 
     2594        VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); 
     2595 
     2596        long startTime = GetTime(); 
     2597 
     2598        cout << "storing rays ... "; 
     2599 
     2600        Intersectable::NewMail(); 
     2601 
     2602        //-- store rays and objects 
     2603        for (rit = sampleRays.begin(); rit != rit_end; ++ rit) 
     2604        { 
     2605                VssRay *ray = *rit; 
     2606                float minT, maxT; 
     2607                static Ray hray; 
     2608 
     2609                hray.Init(*ray); 
     2610                 
     2611                // TODO: not very efficient to implictly cast between rays types 
     2612                if (GetBoundingBox().GetRaySegment(hray, minT, maxT)) 
     2613                { 
     2614                        float len = ray->Length(); 
     2615 
     2616                        if (!len) 
     2617                                len = Limits::Small; 
     2618 
     2619                        rays.push_back(RayInfo(ray, minT / len, maxT / len)); 
     2620                } 
     2621        } 
     2622 
     2623        cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    26142624} 
    26152625 
     
    27072717    for (oit = objects.begin(); oit != oit_end; ++ oit)  
    27082718        { 
     2719                Intersectable *object = *oit; 
     2720 
    27092721                // determine the side of this ray with respect to the plane 
    2710                 const AxisAlignedBox3 box = (*oit)->GetBox(); 
     2722                const AxisAlignedBox3 box = object->GetBox(); 
    27112723 
    27122724                if (box.Max(splitPlane.mAxis) >= splitPlane.mPosition) 
    2713             front.push_back(*oit); 
    2714      
     2725                { 
     2726            front.push_back(object); 
     2727                        ++ object->mObjectRefs; 
     2728                } 
     2729 
    27152730                if (box.Min(splitPlane.mAxis) < splitPlane.mPosition) 
    2716                         back.push_back(*oit); 
     2731                { 
     2732                        back.push_back(object); 
     2733                        ++ object->mObjectRefs; 
     2734                } 
     2735 
     2736                // remove parent reference 
     2737                -- object->mObjectRefs; 
    27172738        } 
    27182739 
     
    27552776        // TODO matt: compute pvs 
    27562777        frontData.mPvs = 999; // ComputePvsSize(*frontData.mRays); 
    2757         backData.mPvs = -999; //ComputePvsSize(*backData.mRays); 
     2778        backData.mPvs = 999; //ComputePvsSize(*backData.mRays); 
    27582779 
    27592780        frontData.mProbability = frontData.mBoundingBox.GetVolume(); 
    27602781 
    2761  
    2762         // classify objects 
     2782         
     2783        //-- subdivide rays 
     2784        frontData.mRays = new RayInfoContainer(); 
     2785        backData.mRays = new RayInfoContainer(); 
     2786 
     2787        SplitRays(splitPlane, 
     2788                          *tData.mRays, 
     2789                          *frontData.mRays, 
     2790                          *backData.mRays); 
     2791 
     2792 
     2793        //-- classify objects 
    27632794        int objectsBack = 0; 
    27642795        int objectsFront = 0; 
     
    29512982 
    29522983 
    2953 float OspTree::EvalLocalCostHeuristics(KdLeaf *node, 
     2984float OspTree::EvalLocalCostHeuristics(const OspTraversalData &tData, 
    29542985                                                                           const AxisAlignedBox3 &box, 
    29552986                                                                           const int axis, 
     
    29582989                                                                           int &objectsBack) 
    29592990{ 
    2960         // sort so we can use a sweep 
    2961         SortSplitCandidates(node, axis); 
    2962    
    29632991        // go through the lists, count the number of objects left and right 
    29642992        // and evaluate the following cost funcion: 
    29652993        // C = ct_div_ci  + (ol + or)/queries 
    29662994         
    2967         float totalVol = PrepareHeuristics(node->mObjects); 
     2995        const float minBox = box.Min(axis); 
     2996        const float maxBox = box.Max(axis); 
     2997 
     2998        const float sizeBox = maxBox - minBox; 
     2999 
     3000        float minBand = minBox + mSplitBorder * (maxBox - minBox); 
     3001        float maxBand = minBox + (1.0f - mSplitBorder) * (maxBox - minBox); 
     3002 
     3003        //-- sort so we can use a sweep 
     3004        SortSplitCandidates(tData, axis, minBand, maxBand); 
     3005 
     3006        float totalVol = PrepareHeuristics(tData.mNode->mObjects); 
    29683007        float voll = 0; 
    29693008        float volr = totalVol; 
    29703009   
    2971         const int totalPvs = (int)node->mObjects.size(); 
    2972  
    2973         const float minBox = box.Min(axis); 
    2974         const float maxBox = box.Max(axis); 
    2975  
    2976         const float sizeBox = maxBox - minBox; 
     3010        const int totalPvs = tData.mNode->mObjects.size(); 
     3011 
    29773012                                 
    29783013        // if no good split can be found, take mid split 
     
    29823017        float ratio = 99999999.0f; 
    29833018        bool splitPlaneFound = false; 
    2984    
    2985         float minBand = minBox + mSplitBorder * (maxBox - minBox); 
    2986         float maxBand = minBox + (1.0f - mSplitBorder) * (maxBox - minBox); 
    2987  
     3019    
    29883020    float minSum = 1e20f; 
    29893021 
     
    29933025        float sum = (float)totalVol * sizeBox; 
    29943026 
     3027        int currentPvs = 0; 
     3028 
     3029        Intersectable::NewMail(); 
     3030 
     3031        //-- traverse through visibility events 
     3032 
    29953033        vector<SortableEntry>::const_iterator ci, ci_end = mSplitCandidates->end(); 
    29963034 
    2997  
    2998         //-- traverse through visibility events 
    2999         for (ci = mSplitCandidates->begin(); ci != ci_end; ++ ci) 
    3000         { 
     3035        for (ci = mSplitCandidates->begin(); ci != ci_end; ++ ci, ++ currentPvs) 
     3036        { 
     3037                Intersectable *object = (*ci).mObject; 
     3038 
     3039                // new object in this node -> add to the pvs 
     3040                if (!object->Mailed()) 
     3041                { 
     3042                        object->Mail(); 
     3043                        ++ currentPvs; 
     3044                } 
     3045 
    30013046                EvalViewCellVolumeIncr(*ci, voll, volr); 
    30023047 
     
    30053050 
    30063051                // Note: sufficient to compare size of bounding boxes of front and back side? 
    3007                 if (((*ci).value >= minBand) && ((*ci).value <= maxBand)) 
     3052                if (((*ci).mPos >= minBand) && ((*ci).mPos <= maxBand)) 
    30083053                { 
    30093054                        //sum = costl * ((*ci).value - minBox) + costr * (maxBox - (*ci).value); 
    3010                         sum = voll * (*ci).value +volr * (totalPvs - (*ci).value); 
    3011  
    3012                         cout << "pos=" << (*ci).value << "\t volt=(" <<  voll << ","  
     3055                        sum = voll * currentPvs + volr * (totalPvs - currentPvs); 
     3056 
     3057                        cout << "pos=" << currentPvs << "\t volt=(" <<  voll << ","  
    30133058                                 << volr << ")" << "\t volt= " << sum << endl; 
    30143059 
     
    30183063 
    30193064                                minSum = sum; 
    3020                                 pvsBack = (*ci).value; 
     3065                                pvsBack = currentPvs; 
    30213066                                 
    30223067                                volBack = voll; 
     
    30573102 
    30583103 
    3059 void OspTree::SortSplitCandidates(KdLeaf *node, const int axis) 
     3104void OspTree::SortSplitCandidates(const OspTraversalData &tData, 
     3105                                                                  const int axis,  
     3106                                                                  float minBand,  
     3107                                                                  float maxBand) 
     3108 
    30603109{ 
    30613110        mSplitCandidates->clear(); 
    30623111 
    3063         int requestedSize = 2 * (int)node->mObjects.size(); 
    3064          
     3112        RayInfoContainer *rays = tData.mRays; 
     3113        KdLeaf *leaf = tData.mNode; 
     3114 
     3115        int requestedSize = 2 * (int)rays->size(); 
     3116 
    30653117        // creates a sorted split candidates array 
    30663118        if (mSplitCandidates->capacity() > 500000 && 
    3067                 requestedSize < (int)(mSplitCandidates->capacity()/10))  
    3068         { 
    3069                 delete mSplitCandidates; 
    3070                 mSplitCandidates = new vector<SortableEntry>; 
     3119                requestedSize < (int)(mSplitCandidates->capacity() / 10) ) 
     3120        { 
     3121        delete mSplitCandidates; 
     3122                mSplitCandidates = new vector<SortableEntry>; 
    30713123        } 
    30723124 
    30733125        mSplitCandidates->reserve(requestedSize); 
    3074          
    3075         ObjectContainer::const_iterator mi, mi_end = node->mObjects.end(); 
    3076  
    3077         // insert all queries  
    3078         int pvs = 0; 
    3079         for(mi = node->mObjects.begin(); mi != mi_end; ++ mi, ++ pvs)  
    3080         { 
    3081                 AxisAlignedBox3 box = (*mi)->GetBox(); 
    3082  
    3083                 // only first event should be sufficient 
    3084                 // but maybe introduces problems with symmetry ... 
    3085                 mSplitCandidates->push_back(SortableEntry(SortableEntry::BOX_MIN, 
    3086                                         pvs, *mi)); 
    3087  
    3088                 //mSplitCandidates->push_back(SortableEntry(SortableEntry::BOX_MAX, 
    3089                 //                      pvs, *mi)); 
     3126 
     3127        float pos; 
     3128 
     3129        //-- insert all queries 
     3130        for (RayInfoContainer::const_iterator ri = rays->begin(); ri < rays->end(); ++ ri) 
     3131        { 
     3132                const bool positive = (*ri).mRay->HasPosDir(axis); 
     3133                                 
     3134                pos = (*ri).ExtrapOrigin(axis); 
     3135         
     3136 
     3137                //if (mOspTree->GetLeaf() == leaf) 
     3138 
     3139        /*      mSplitCandidates->push_back(SortableEntry(positive ? SortableEntry::ERayMin : SortableEntry::ERayMax,  
     3140                                                                        pos, (*ri).mRay)); 
     3141 
     3142                pos = (*ri).ExtrapTermination(axis); 
     3143 
     3144                mSplitCandidates->push_back(SortableEntry(positive ? SortableEntry::ERayMax : SortableEntry::ERayMin,  
     3145                                                                        pos, (*ri).mRay));*/ 
    30903146        } 
    30913147 
     
    31443200        Intersectable *obj = ci.mObject; 
    31453201 
    3146         switch (ci.type)  
     3202        switch (ci.mType)  
    31473203        { 
    31483204                case SortableEntry::BOX_MIN: 
     
    33563412 
    33573413 
    3358 void OspTree::PrepareConstruction(const ObjectContainer &objects, 
    3359                                                                   AxisAlignedBox3 *forcedBoundingBox)  
    3360 { 
    3361         // store pointer to this tree 
    3362         OspSplitCandidate::sOspTree = this; 
    3363  
    3364         mOspStats.nodes = 1; 
    3365          
     3414void OspTree::ComputeBoundingBox(const ObjectContainer &objects, 
     3415                                                                 AxisAlignedBox3 *forcedBoundingBox)  
     3416{ 
    33663417        if (forcedBoundingBox) 
    33673418        { 
     
    33843435                } 
    33853436        } 
    3386  
    3387         mTermMinProbability *= mBoundingBox.GetVolume(); 
    3388         mGlobalCostMisses = 0; 
    3389 } 
     3437} 
     3438 
    33903439 
    33913440#if DEPRECATED 
     
    35833632 
    35843633 
     3634KdNode *OspTree::GetRoot() const 
     3635{ 
     3636        return mRoot; 
     3637} 
     3638 
     3639 
    35853640KdLeaf *OspTree::GetLeaf(const Vector3 &pt, KdNode *node) const 
    35863641{ 
    35873642        if (node == NULL) 
     3643        { 
    35883644                node = mRoot; 
     3645        } 
    35893646 
    35903647        stack<KdNode *> nodeStack; 
     
    36083665                        // random decision 
    36093666                        if (interior->mPosition < pt[interior->mAxis]) 
     3667                        { 
    36103668                                nodeStack.push(interior->mBack); 
     3669                        } 
    36113670                        else 
     3671                        { 
    36123672                                nodeStack.push(interior->mFront); 
     3673                        } 
    36133674                } 
    36143675        } 
     
    36183679 
    36193680 
    3620 KdNode *OspTree::GetRoot() const 
    3621 { 
    3622         return mRoot; 
    3623 } 
     3681void OspTree::ProcessRays(const VssRayContainer &sampleRays, 
     3682                                                  RayInfoContainer &rays) 
     3683{ 
     3684        VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); 
     3685 
     3686        long startTime = GetTime(); 
     3687 
     3688        cout << "storing rays ... "; 
     3689 
     3690        Intersectable::NewMail(); 
     3691 
     3692        //-- store rays and objects 
     3693        for (rit = sampleRays.begin(); rit != rit_end; ++ rit) 
     3694        { 
     3695                VssRay *ray = *rit; 
     3696                float minT, maxT; 
     3697                static Ray hray; 
     3698 
     3699                hray.Init(*ray); 
     3700                 
     3701                // TODO: not very efficient to implictly cast between rays types 
     3702                if (GetBoundingBox().GetRaySegment(hray, minT, maxT)) 
     3703                { 
     3704                        float len = ray->Length(); 
     3705 
     3706                        if (!len) 
     3707                                len = Limits::Small; 
     3708 
     3709                        rays.push_back(RayInfo(ray, minT / len, maxT / len)); 
     3710                } 
     3711        } 
     3712 
     3713        cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     3714} 
     3715 
     3716 
     3717 
     3718int OspTree::SplitRays(const AxisAlignedPlane &plane, 
     3719                                           RayInfoContainer &rays, 
     3720                                           RayInfoContainer &frontRays, 
     3721                                           RayInfoContainer &backRays) const 
     3722{ 
     3723        int splits = 0; 
     3724 
     3725        RayInfoContainer::const_iterator rit, rit_end = rays.end(); 
     3726 
     3727        for (rit = rays.begin(); rit != rit_end; ++ rit) 
     3728        { 
     3729                RayInfo bRay = *rit; 
     3730                 
     3731                VssRay *ray = bRay.mRay; 
     3732                float t; 
     3733 
     3734                // get classification and receive new t 
     3735                //-- test if start point behind or in front of plane 
     3736                const int side = bRay.ComputeRayIntersection(plane.mAxis, plane.mPosition, t); 
     3737                         
     3738                if (side == 0) 
     3739                { 
     3740                        ++ splits; 
     3741 
     3742                        if (ray->HasPosDir(plane.mAxis)) 
     3743                        { 
     3744                                backRays.push_back(RayInfo(ray, bRay.GetMinT(), t)); 
     3745                                frontRays.push_back(RayInfo(ray, t, bRay.GetMaxT())); 
     3746                        } 
     3747                        else 
     3748                        { 
     3749                                frontRays.push_back(RayInfo(ray, bRay.GetMinT(), t)); 
     3750                                backRays.push_back(RayInfo(ray, t, bRay.GetMaxT())); 
     3751                        } 
     3752                } 
     3753                else if (side == 1) 
     3754                { 
     3755                        frontRays.push_back(bRay); 
     3756                } 
     3757                else 
     3758                { 
     3759                        backRays.push_back(bRay); 
     3760                } 
     3761        } 
     3762 
     3763        return splits; 
     3764} 
     3765 
     3766 
    36243767 
    36253768 
     
    36503793 
    36513794 
    3652 void HierarchyManager::ProcessRays(const VssRayContainer &sampleRays, 
    3653                                                                    RayInfoContainer &rays) 
    3654 { 
    3655         VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); 
    3656  
    3657         long startTime = GetTime(); 
    3658  
    3659         cout << "storing rays ... "; 
    3660  
    3661         Intersectable::NewMail(); 
    3662  
    3663         //-- store rays and objects 
    3664         for (rit = sampleRays.begin(); rit != rit_end; ++ rit) 
    3665         { 
    3666                 VssRay *ray = *rit; 
    3667                 float minT, maxT; 
    3668                 static Ray hray; 
    3669  
    3670                 hray.Init(*ray); 
    3671                  
    3672                 // TODO: not very efficient to implictly cast between rays types 
    3673                 if (mVspTree.GetBoundingBox().GetRaySegment(hray, minT, maxT)) 
    3674                 { 
    3675                         float len = ray->Length(); 
    3676  
    3677                         if (!len) 
    3678                                 len = Limits::Small; 
    3679  
    3680                         rays.push_back(RayInfo(ray, minT / len, maxT / len)); 
    3681                 } 
    3682         } 
    3683  
    3684         cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    3685 } 
    3686  
    3687  
    36883795SplitCandidate *HierarchyManager::PrepareVsp(const VssRayContainer &sampleRays, 
    36893796                                                                                         AxisAlignedBox3 *forcedViewSpace, 
    3690                                                                                          RayInfoContainer &rays 
    3691                                                                                          ) 
    3692 { 
     3797                                                                                         RayInfoContainer &rays) 
     3798{ 
     3799        // get clipped rays 
     3800        mVspTree.ProcessRays(sampleRays, rays); 
     3801 
     3802        // store pointer to this tree 
     3803        VspTree::VspSplitCandidate::sVspTree = &mVspTree; 
     3804        mVspTree.mVspStats.nodes = 1; 
     3805 
    36933806        // prepare bounding box 
    3694         mVspTree.PrepareConstruction(sampleRays, forcedViewSpace); 
    3695  
    3696         // get clipped rays 
    3697         ProcessRays(sampleRays, rays); 
     3807        mVspTree.ComputeBoundingBox(rays, forcedViewSpace); 
     3808 
     3809        mVspTree.mTermMinProbability *= mBoundingBox.GetVolume(); 
     3810        mVspTree.mGlobalCostMisses = 0; 
     3811 
    36983812 
    36993813        const int pvsSize = mVspTree.ComputePvsSize(rays); 
     
    37403854 
    37413855 
    3742 SplitCandidate * HierarchyManager::PrepareOsp(const ObjectContainer &objects, 
    3743                                                                                           AxisAlignedBox3 *forcedViewSpace) 
    3744 { 
    3745         mOspTree.PrepareConstruction(objects, forcedViewSpace); 
     3856SplitCandidate * HierarchyManager::PrepareOsp(const VssRayContainer &sampleRays, 
     3857                                                                                          const ObjectContainer &objects, 
     3858                                                                                          AxisAlignedBox3 *forcedObjectSpace, 
     3859                                                                                          RayInfoContainer &rays) 
     3860{ 
     3861        // get clipped rays 
     3862        mOspTree.ProcessRays(sampleRays, rays); 
     3863 
     3864        // store pointer to this tree 
     3865        OspTree::OspSplitCandidate::sOspTree = &mOspTree; 
     3866        mOspTree.mOspStats.nodes = 1; 
     3867         
     3868        mOspTree.ComputeBoundingBox(objects, forcedObjectSpace); 
     3869 
     3870        mOspTree.mTermMinProbability *= mBoundingBox.GetVolume(); 
     3871        mGlobalCostMisses = 0; 
     3872 
    37463873 
    37473874        // add first candidate for view space partition 
     
    37593886        OspTree::OspTraversalData oData(kdleaf, 
    37603887                                                                        0, 
     3888                                                                        &rays, 
    37613889                                                                        pvsSize, 
    37623890                                                                        prop, 
     
    37783906                                                                                   const ObjectContainer &objects, 
    37793907                                                                                   AxisAlignedBox3 *forcedViewSpace, 
    3780                                                                                    RayInfoContainer &rays) 
    3781 { 
    3782         mTQueue.Push(PrepareVsp(sampleRays, forcedViewSpace, rays)); 
    3783         mTQueue.Push(PrepareOsp(objects, forcedViewSpace)); 
     3908                                                                                   RayInfoContainer &viewSpaceRays, 
     3909                                                                                   RayInfoContainer &objectSpaceRays) 
     3910{ 
     3911        SplitCandidate *vsc =  
     3912                PrepareVsp(sampleRays, forcedViewSpace, viewSpaceRays); 
     3913        mTQueue.Push(vsc); 
     3914 
     3915        SplitCandidate *osc =  
     3916                PrepareOsp(sampleRays, objects, forcedViewSpace, objectSpaceRays); 
     3917 
     3918        mTQueue.Push(osc); 
    37843919} 
    37853920 
     
    37963931                                                                  AxisAlignedBox3 *forcedViewSpace) 
    37973932{ 
    3798         RayInfoContainer *rays = new RayInfoContainer(); 
     3933        RayInfoContainer *viewSpaceRays = new RayInfoContainer(); 
     3934        RayInfoContainer *objectSpaceRays = new RayInfoContainer(); 
    37993935 
    38003936        // makes no sense otherwise because only one kd cell available 
     
    38033939        mVspTree.mPvsCountMethod = VspTree::PER_OBJECT; 
    38043940 
    3805         mTQueue.Push(PrepareVsp(sampleRays, forcedViewSpace, *rays)); 
     3941        mTQueue.Push(PrepareVsp(sampleRays, forcedViewSpace, *viewSpaceRays)); 
    38063942 
    38073943        long startTime = GetTime(); 
     
    38443980 
    38453981        //-- object space partition 
    3846     mTQueue.Push(PrepareOsp(objects, forcedViewSpace)); 
     3982        SplitCandidate *osc = 
     3983                PrepareOsp(sampleRays, objects, forcedViewSpace, *objectSpaceRays); 
     3984 
     3985    mTQueue.Push(osc); 
     3986 
    38473987 
    38483988        i = 0; 
     
    38844024                                                                 AxisAlignedBox3 *forcedViewSpace) 
    38854025{ 
    3886         RayInfoContainer *rays = new RayInfoContainer(); 
    3887          
     4026        RayInfoContainer *objectSpaceRays = new RayInfoContainer(); 
     4027        RayInfoContainer *viewSpaceRays = new RayInfoContainer(); 
     4028 
    38884029        // prepare vsp and osp trees for traversal 
    3889         PrepareConstruction(sampleRays, objects, forcedViewSpace, *rays); 
     4030        PrepareConstruction(sampleRays, objects, forcedViewSpace, *viewSpaceRays, *objectSpaceRays); 
    38904031 
    38914032        mVspTree.mVspStats.Reset(); 
     
    39304071                } 
    39314072 
    3932                 // reevaluate affected candidates 
     4073                // reevaluate candidates affected by the split 
     4074                // for view space splits, this would be object space splits 
     4075                // and other way round 
    39334076                RepairQueue(); 
    39344077 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h

    r1133 r1135  
    549549                } 
    550550 
    551                 // deletes contents and sets them to NULL 
     551                /// deletes contents and sets them to NULL 
    552552                void Clear() 
    553553                { 
     
    748748        */ 
    749749        void AddViewCellReferences(ViewCell *vc) const; 
    750  
    751750 
    752751 
     
    794793                                                         float &pBack) const; 
    795794 
    796         void PrepareConstruction(const VssRayContainer &sampleRays, 
    797                                                          AxisAlignedBox3 *forcedBoundingBox); 
     795        void ComputeBoundingBox(const RayInfoContainer &rays, 
     796                AxisAlignedBox3 *forcedBoundingBox); 
    798797 
    799798        /** Evaluates candidate for splitting. 
     
    901900        /** Computes best cost for axis aligned planes. 
    902901        */ 
    903         float EvalLocalCostHeuristics(const RayInfoContainer &rays, 
     902        float EvalLocalCostHeuristics(const VspTraversalData &data, 
    904903                                                                  const AxisAlignedBox3 &box, 
    905                                                                   int pvsSize, 
    906904                                                                  const int axis, 
    907905                                                                  float &position); 
     
    10101008        KdNode *GetKdNode(VssRay &ray, const bool termination) const; 
    10111009 
     1010        void ProcessRays(const VssRayContainer &sampleRays, 
     1011                RayInfoContainer &rays); 
    10121012 
    10131013protected: 
    10141014 
    10151015        int mPvsCountMethod; 
     1016 
    10161017        enum {PER_OBJECT, PER_KDLEAF}; 
    10171018 
     
    10301031        /// box around the whole view domain 
    10311032        AxisAlignedBox3 mBoundingBox; 
     1033 
    10321034 
    10331035 
     
    11231125                int mDepth; 
    11241126                /// rays piercing this node 
    1125                 //RayInfoContainer *mRays; 
     1127                RayInfoContainer *mRays; 
    11261128                /// the probability that this node contains view point 
    11271129                float mProbability; 
     
    11401142                OspTraversalData(): 
    11411143                mNode(NULL), 
     1144                mRays(NULL), 
    11421145                mDepth(0), 
    11431146                mPvs(0), 
     
    11491152                 
    11501153                OspTraversalData(KdLeaf *node,  
    1151                                                  const int depth,  
     1154                                                 const int depth, 
     1155                         RayInfoContainer *rays, 
    11521156                                                 const int pvs, 
    11531157                                                 const float p, 
    11541158                                                 const AxisAlignedBox3 &box): 
    11551159                mNode(node),  
    1156                 mDepth(depth),  
     1160                mDepth(depth), 
     1161                mRays(rays), 
    11571162                mPvs(pvs), 
    11581163                mProbability(p), 
     
    11641169 
    11651170                OspTraversalData(const int depth,  
    1166                                                  const AxisAlignedBox3 &box):  
     1171                        RayInfoContainer *rays, 
     1172                        const AxisAlignedBox3 &box):  
    11671173                mNode(NULL),  
    1168                 mDepth(depth),  
     1174                mDepth(depth), 
     1175                mRays(rays), 
    11691176                mPvs(0), 
    11701177                mProbability(0), 
     
    11821189                } 
    11831190 
    1184                 // deletes contents and sets them to NULL 
     1191                /// deletes contents and sets them to NULL 
    11851192                void Clear() 
    11861193                { 
     1194                        DEL_PTR(mRays); 
    11871195                } 
     1196 
    11881197 
    11891198                friend bool operator<(const OspTraversalData &a, const OspTraversalData &b) 
     
    13421351        int ComputePvsSize(const ObjectContainer &objects) const; 
    13431352 
    1344  
    13451353        KdLeaf *GetLeaf(const Vector3 &pt, KdNode *node) const; 
    13461354 
     
    13551363        // For sorting objects 
    13561364        // -------------------------------------------------------------- 
    1357         struct  SortableEntry 
     1365        struct SortableEntry 
    13581366        { 
    1359                 enum 
     1367                enum EType  
    13601368                { 
    1361                         BOX_MIN, 
    1362                         BOX_MAX 
     1369                        ERayMin, 
     1370                        ERayMax 
    13631371                }; 
    13641372 
    1365                 int type; 
    1366                 float value; 
     1373                int mType; 
     1374                //int mPvs; 
     1375                float mPos; 
     1376 
    13671377                Intersectable *mObject; 
    13681378 
    13691379                SortableEntry() {} 
    13701380 
    1371                 SortableEntry(const int t, const float v, Intersectable *obj): 
    1372                 type(t), value(v), mObject(obj)  
     1381                SortableEntry(const int type,  
     1382                        //const float pvs,  
     1383                        const float pos, 
     1384                        Intersectable *obj): 
     1385                mType(type),  
     1386                //mPvs(pvs),  
     1387                mPos(pos),  
     1388                mObject(obj)  
    13731389                {} 
    13741390 
    13751391                bool operator<(const SortableEntry &b) const  
    13761392                { 
    1377                         return value < b.value; 
     1393                        return mPos < b.mPos; 
    13781394                } 
    13791395        }; 
     
    14671483                @param axis the current split axis 
    14681484        */ 
    1469         void SortSplitCandidates(KdLeaf *node, const int axis); 
     1485        void SortSplitCandidates(const OspTraversalData &data, 
     1486                                                         const int axis,  
     1487                                                         float minBand,  
     1488                                                         float maxBand); 
    14701489 
    14711490        /** Computes best cost for axis aligned planes. 
    14721491        */ 
    1473         float EvalLocalCostHeuristics(KdLeaf *node, 
     1492        float EvalLocalCostHeuristics(const OspTraversalData &data, 
    14741493                const AxisAlignedBox3 &box, 
    14751494                const int axis, 
     
    15701589        /** Prepares construction for vsp and osp trees. 
    15711590        */ 
    1572         void PrepareConstruction(const ObjectContainer &objects, 
     1591        void ComputeBoundingBox(const ObjectContainer &objects, 
    15731592                AxisAlignedBox3 *forcedBoundingBox); 
    15741593 
     
    15801599        void CollectViewCells(KdLeaf *leaf,  
    15811600                ViewCellContainer &viewCells); 
     1601 
     1602        void ProcessRays(const VssRayContainer &sampleRays, 
     1603                RayInfoContainer &rays); 
    15821604 
    15831605 
     
    17211743 
    17221744        void PrepareConstruction(const VssRayContainer &sampleRays, 
    1723                                                          const ObjectContainer &objects, 
    1724                                                          AxisAlignedBox3 *forcedViewSpace, 
    1725                                                          RayInfoContainer &rays); 
     1745                const ObjectContainer &objects, 
     1746                AxisAlignedBox3 *forcedViewSpace, 
     1747                RayInfoContainer &viewSpaceRays, 
     1748                RayInfoContainer &objectSpaceRays); 
    17261749 
    17271750        bool FinishedConstruction(); 
     
    17331756        void CollectDirtyCandidates(vector<SplitCandidate *> &dirtyList); 
    17341757 
    1735         SplitCandidate * PrepareVsp(const VssRayContainer &sampleRays, 
    1736                 AxisAlignedBox3 *forcedViewSpace, 
    1737                 RayInfoContainer &rays); 
    1738  
    1739         SplitCandidate * PrepareOsp(const ObjectContainer &objects,  
    1740                 AxisAlignedBox3 *forcedViewSpace); 
    1741  
    1742         void ProcessRays(const VssRayContainer &sampleRays, 
     1758        SplitCandidate *PrepareVsp(const VssRayContainer &sampleRays, 
     1759                                                           AxisAlignedBox3 *forcedViewSpace, 
     1760                                                           RayInfoContainer &rays); 
     1761 
     1762        SplitCandidate *PrepareOsp(const VssRayContainer &sampleRays, 
     1763                const ObjectContainer &objects, 
     1764                AxisAlignedBox3 *forcedObjectSpace, 
    17431765                RayInfoContainer &rays); 
    17441766 
Note: See TracChangeset for help on using the changeset viewer.