Changeset 1186


Ignore:
Timestamp:
08/07/06 18:35:51 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
2 edited

Legend:

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

    r1184 r1186  
    27372737 
    27382738                // get classification and receive new t 
    2739                 //-- test if start point behind or in front of plane 
     2739                // test if start point behind or in front of plane 
    27402740                const int side = bRay.ComputeRayIntersection(plane.mAxis, plane.mPosition, t); 
    27412741                         
     
    29112911 
    29122912 
    2913 void VspTree::GetViewCells(const VssRay &ray, ViewCellContainer &viewCells) 
    2914 { 
     2913void VspTree::GetViewCells(VssRay &ray, ViewCellContainer &viewCells) 
     2914{ 
     2915        mViewCellsManager->ComputeSampleContribution(ray, false, true); 
     2916        viewCells = ray.mViewCells; 
     2917        ray.mViewCells.clear(); 
     2918        /* 
    29152919        static Ray hray; 
    29162920        hray.Init(ray); 
     
    29272931 
    29282932        // if no precomputation of view cells 
    2929         CastLineSegment(origin, termination, viewCells); 
    2930 } 
     2933        CastLineSegment(origin, termination, viewCells);*/ 
     2934} 
     2935 
    29312936 
    29322937 
     
    31233128        backData.mRays = new RayInfoContainer(); 
    31243129 
    3125         SplitRays(splitPlane, 
     3130/*      SplitRays(splitPlane, 
    31263131                          *tData.mRays, 
    31273132                          *frontData.mRays, 
    31283133                          *backData.mRays); 
    3129  
     3134*/ 
    31303135 
    31313136        //-- classify objects 
     
    31503155 
    31513156        // TODO matt: compute pvs 
    3152         frontData.mPvs = objectsFront; 
    3153         backData.mPvs = objectsBack; 
     3157        //frontData.mPvs = objectsFront; 
     3158        //backData.mPvs = objectsBack; 
    31543159 
    31553160        //CheckViewCellsPvs(leaf, *tData.mRays); 
     
    31813186 
    31823187        SplitObjects(leaf, splitPlane, leaf->mObjects, front->mObjects, back->mObjects); 
     3188         
     3189        FilterRays(front, *tData.mRays, *frontData.mRays); 
     3190        FilterRays(back, *tData.mRays, *backData.mRays); 
    31833191 
    31843192 
     
    32733281        if (newNode->IsLeaf()) 
    32743282        { 
    3275                 EvaluateLeafStats(tData);                
    3276 const bool mStoreRays= true; 
     3283                EvaluateLeafStats(tData); 
     3284         
     3285                const bool mStoreRays= true; 
     3286 
    32773287                //-- store additional info 
    32783288                if (mStoreRays) 
     
    33663376        ++ mCreatedLeaves; 
    33673377 
    3368         if (data.mPvs > mOspStats.maxPvs) 
     3378        /*if (data.mPvs > mOspStats.maxPvs) 
    33693379        { 
    33703380                mOspStats.maxPvs = data.mPvs; 
     
    33763386        { 
    33773387                mOspStats.minDepth = data.mDepth; 
    3378         } 
     3388        }*/ 
    33793389         
    33803390        if (data.mDepth >= mTermMaxDepth) 
     
    36863696        ViewCellContainer viewCells; 
    36873697 
    3688         mVspTree->GetViewCells(ray, viewCells); 
     3698        mVspTree->GetViewCells(VssRay(ray), viewCells); 
    36893699         
    36903700        ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
     
    37983808        ViewCellContainer viewCells; 
    37993809 
    3800         mVspTree->GetViewCells(ray, viewCells); 
     3810        mVspTree->GetViewCells(VssRay(ray), viewCells); 
    38013811 
    38023812        /// classify view cells and compute volume contri accordingly 
     
    40284038 
    40294039 
     4040int OspTree::ClassifyRays(const RayInfoContainer &rays,  
     4041                                                  KdLeaf *leaf,  
     4042                                                  const AxisAlignedPlane &plane, 
     4043                                                  RayInfoContainer &frontRays, 
     4044                                                  RayInfoContainer &backRays) const 
     4045{ 
     4046        RayInfoContainer::const_iterator rit, rit_end = rays.end(); 
     4047 
     4048        for (rit = rays.begin(); rit < rit_end; ++ rit) 
     4049        { 
     4050                VssRay *ray = (*rit).mRay; 
     4051 
     4052                bool originGt = false; 
     4053                bool terminationGt = false; 
     4054                 
     4055                Intersectable *obj = ray->mOriginObject; 
     4056 
     4057                if (obj) 
     4058                { 
     4059                        originGt = ray->mOrigin[plane.mAxis] > plane.mPosition; 
     4060                } 
     4061 
     4062                obj = ray->mTerminationObject; 
     4063                 
     4064                if (obj) 
     4065                { 
     4066                        terminationGt = ray->mTermination[plane.mAxis] > plane.mPosition; 
     4067                } 
     4068 
     4069                // either begin or end point on front side 
     4070                const bool addToFront = originGt || terminationGt; 
     4071 
     4072                // add view cell volume to back volume 
     4073                const bool addToBack = !originGt || !terminationGt; 
     4074         
     4075                // classify ray with respect to the child nodes the view cells contribute 
     4076                if (addToFront) 
     4077                        frontRays.push_back(*rit); 
     4078                if (addToBack) 
     4079                        backRays.push_back(*rit); 
     4080        } 
     4081 
     4082        return 0; 
     4083} 
     4084 
     4085 
     4086#if 1 
     4087 
    40304088float OspTree::EvalRenderCostDecrease(const AxisAlignedPlane &candidatePlane, 
    40314089                                                                          const OspTraversalData &tData, 
     
    40484106        const int totalPvs = (int)leaf->mObjects.size(); 
    40494107         
    4050         ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
    4051  
    4052         // evaluate reverse pvs and view cell volume on left and right cell 
    4053         // note: should I take all leaf objects or rather the objects hit by rays? 
    4054         for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 
    4055         { 
    4056                 int pvsContri = 0; 
    4057  
    4058                 Intersectable *obj = *oit; 
    4059                 const AxisAlignedBox3 box = obj->GetBox(); 
    4060  
    4061                 // test if box falls in left / right child node 
    4062                 if (box.Max(candidatePlane.mAxis) >= candidatePlane.mPosition) 
    4063                 { 
    4064                         ++ pvsFront; 
    4065                         obj->Mail();             
    4066                 } 
    4067  
    4068                 if (box.Min(candidatePlane.mAxis) < candidatePlane.mPosition) 
    4069                 { 
    4070                         ++ pvsBack; 
    4071  
    4072                         if (obj->Mailed()) 
    4073                                 obj->Mail(2); 
    4074                         else  
    4075                                 obj->Mail(1); 
    4076                 } 
    4077  
    4078                 //Debug << "here3 pt: " << obj << " mail: " << obj->mMailbox - Intersectable::sMailId << endl; 
    4079         } 
    4080  
    4081          
     4108        RayInfoContainer frontRays, backRays; 
     4109        ClassifyRays(*tData.mRays, leaf, candidatePlane, frontRays, backRays); 
     4110 
    40824111        ViewCellContainer touchedViewCells; 
    4083         RayInfoContainer touchedRays; 
    4084  
     4112         
    40854113        // sum up volume seen from the objects of left and right children 
    40864114        // => the volume is the weight for the render cost equation 
     
    40884116 
    40894117        RayInfoContainer::const_iterator rit, rit_end = tData.mRays->end(); 
    4090         //map<Intersectable *, ViewCellContainer> objectsMap; 
    40914118 
    40924119        for (rit = tData.mRays->begin(); rit < rit_end; ++ rit) 
     
    41004127                if (originInside || terminationInside) 
    41014128                { 
    4102                         touchedRays.push_back(*rit); 
    41034129                        // add volume to volumes of left and / or right children 
    41044130                        // if one of the ray end points is inside 
     
    41244150                // classify / mail the view cell 
    41254151                                MailViewCell(vc, classification);        
    4126  
    4127                                 /*if (terminationInside) 
    4128                                         objectsMap[ray->mTerminationObject].push_back(vc); 
    4129                                 if (originInside) 
    4130                                         objectsMap[ray->mOriginObject].push_back(vc);*/ 
    41314152                        } 
    41324153                } 
     
    41544175        ViewCellPvsData::NewMail(); 
    41554176 
    4156         for (rit = touchedRays.begin(); rit != touchedRays.end(); ++ rit) 
     4177        for (rit = tData.mRays->begin(); rit != tData.mRays->end(); ++ rit) 
    41574178        { 
    41584179                VssRay *ray = (*rit).mRay; 
     
    41734194                        // => the render cost was falsly reduced, add them again 
    41744195 
    4175                         if (EndPointInsideNode(leaf, *ray, true)) 
     4196                        if (ray->mTerminationObject) 
    41764197                        {        
    41774198                                Intersectable *obj = ray->mTerminationObject; 
     
    41794200                                const bool renderCostWrong =  
    41804201                                        ViewCellHasMultipleReferences(obj, viewCell, true); 
    4181                         //      if(!obj->Mailed()){ 
    4182                         //      Debug << "pt: " << obj << endl; 
    4183                         //      Debug << "vc mail: " << viewCell->mMailbox - ViewCell::sMailId << " obj mail: " << obj->mMailbox << " "<< Intersectable::sMailId << " " <<obj->mMailbox - Intersectable::sMailId << endl; 
    4184                         //      obj->Mail(); 
    4185                         //      } 
     4202                         
    41864203                                // if there is already an entry of this object in the view cell pvs  
    41874204                                if (renderCostWrong) 
     
    41894206                                        // view cell was counted only for front or back => correct tjos 
    41904207                                        if (viewCell->Mailed(1) && obj->Mailed()) 
     4208                                        { 
    41914209                                                additionalFrontRenderCost += viewCell->GetVolume(); 
     4210                                        } 
    41924211                                        else if (viewCell->Mailed() && obj->Mailed(1)) 
     4212                                        { 
    41934213                                                additionalBackRenderCost += viewCell->GetVolume(); 
     4214                                        } 
    41944215                                } 
    41954216                        } 
    41964217         
    4197                         if (EndPointInsideNode(leaf, *ray, false)) 
     4218                        if (ray->mOriginObject) 
    41984219                        { 
    41994220                                Intersectable *obj = ray->mOriginObject; 
     
    42054226                                { 
    42064227                                        if (viewCell->Mailed(1) && obj->Mailed()) 
     4228                                        { 
    42074229                                                additionalFrontRenderCost += viewCell->GetVolume(); 
     4230                                        } 
    42084231                                        else if (viewCell->Mailed() && obj->Mailed(1)) 
     4232                                        { 
    42094233                                                additionalBackRenderCost += viewCell->GetVolume(); 
     4234                                        } 
    42104235                                } 
    42114236                        } 
     
    42564281} 
    42574282 
     4283#else 
     4284 
     4285float OspTree::EvalRenderCostDecrease(const AxisAlignedPlane &candidatePlane, 
     4286                                                                          const OspTraversalData &tData, 
     4287                                                                          float &normalizedOldRenderCost) const 
     4288{ 
     4289        float pvsFront = 0; 
     4290        float pvsBack = 0; 
     4291 
     4292        // probability that view point lies in back / front node 
     4293        float pOverall = 0;//data.mProbability; // todo matt§: value ok? 
     4294        float pFront = 0; 
     4295        float pBack = 0; 
     4296        float pFrontAndBack = 0; 
     4297 
     4298        const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 
     4299 
     4300        Intersectable::NewMail(3); 
     4301         
     4302        KdLeaf *leaf = tData.mNode; 
     4303        const int totalPvs = (int)leaf->mObjects.size(); 
     4304         
     4305        ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
     4306 
     4307        // evaluate reverse pvs and view cell volume on left and right cell 
     4308        // note: should I take all leaf objects or rather the objects hit by rays? 
     4309        for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 
     4310        { 
     4311                int pvsContri = 0; 
     4312 
     4313                Intersectable *obj = *oit; 
     4314                const AxisAlignedBox3 box = obj->GetBox(); 
     4315 
     4316                // test if box falls in left / right child node 
     4317                if (box.Max(candidatePlane.mAxis) >= candidatePlane.mPosition) 
     4318                { 
     4319                        ++ pvsFront; 
     4320                        obj->Mail();             
     4321                } 
     4322 
     4323                if (box.Min(candidatePlane.mAxis) < candidatePlane.mPosition) 
     4324                { 
     4325                        ++ pvsBack; 
     4326 
     4327                        if (obj->Mailed()) 
     4328                                obj->Mail(2); 
     4329                        else  
     4330                                obj->Mail(1); 
     4331                } 
     4332                //Debug << "here3 pt: " << obj << " mail: " << obj->mMailbox - Intersectable::sMailId << endl; 
     4333        } 
     4334 
     4335         
     4336        ViewCellContainer touchedViewCells; 
     4337 
     4338        // sum up volume seen from the objects of left and right children 
     4339        // => the volume is the weight for the render cost equation 
     4340        ViewCell::NewMail(3); 
     4341 
     4342        RayInfoContainer::const_iterator rit, rit_end = tData.mRays->end(); 
     4343        //map<Intersectable *, ViewCellContainer> objectsMap; 
     4344 
     4345        for (rit = tData.mRays->begin(); rit < rit_end; ++ rit) 
     4346        { 
     4347                VssRay *ray = (*rit).mRay; 
     4348 
     4349                // add volume to volumes of left and / or right children 
     4350                // if one of the ray end points is inside 
     4351                const int classification = ClassifyRay(ray, leaf, candidatePlane); 
     4352 
     4353                ViewCellContainer viewCells; 
     4354                mVspTree->GetViewCells(*ray, viewCells); 
     4355                         
     4356                ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
     4357 
     4358                // traverse through view cells and classify them according 
     4359                // to them being seen from to back / front / front and back node 
     4360                for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
     4361                { 
     4362                        ViewCell *vc = *vit; 
     4363 
     4364                        // if not previously mailed 
     4365                        if (!vc->Mailed() && !vc->Mailed(1) && !vc->Mailed(2)) 
     4366                        { 
     4367                                touchedViewCells.push_back(vc); 
     4368                        } 
     4369 
     4370                        // classify / mail the view cell 
     4371                        MailViewCell(vc, classification);        
     4372 
     4373                        /*if (terminationInside) 
     4374                                objectsMap[ray->mTerminationObject].push_back(vc); 
     4375                        if (originInside) 
     4376                                objectsMap[ray->mOriginObject].push_back(vc);*/ 
     4377                } 
     4378        } 
     4379 
     4380        // evaluate view cells volume contribution  
     4381        // with respect to the mail box classification 
     4382        ViewCellContainer::const_iterator vit, vit_end = touchedViewCells.end(); 
     4383 
     4384        for (vit = touchedViewCells.begin(); vit != vit_end; ++ vit) 
     4385        { 
     4386                AddViewCellVolumeContri(*vit, pFront, pBack, pFrontAndBack); 
     4387        } 
     4388 
     4389        ////////////////////////////////////////////// 
     4390        // 
     4391        // evaluate contribution of objects which are part of other kd nodes 
     4392        // which are seen by the same view cell 
     4393        // These contributions cannot be reduced by splitting, because 
     4394        // the object would still be part of the pvs 
     4395 
     4396        float frontRc = 0; 
     4397        float backRc = 0; 
     4398        float rc = 0; 
     4399 
     4400        ViewCellPvsData::NewMail(); 
     4401        ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
     4402 
     4403        //Debug << "here53 " << touchedViewCells.size() << endl; 
     4404        for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 
     4405        { 
     4406                Intersectable *obj = *oit; 
     4407                ViewCellContainer::const_iterator vit, vit_end = touchedViewCells.end(); 
     4408 
     4409                for (vit = touchedViewCells.begin(); vit != vit_end; ++ vit) 
     4410                { 
     4411                        ViewCell *vc = *vit; 
     4412                        /*ObjectPvsData *vdata = vc->GetPvs().Find(obj); 
     4413 
     4414                        if (!vdata) 
     4415                        { 
     4416                                vc->GetPvs().AddSample(obj, 1); 
     4417                                newCost += vc->GetVolume(); 
     4418                                //prop += vc->GetVolume(); 
     4419                        }*/ 
     4420 
     4421                        ViewCellPvsData *vdata = obj->mViewCellPvs.Find(vc); 
     4422 
     4423                        if (!vdata || !vdata->Mailed()) 
     4424                        { 
     4425                                newCost += vc->GetVolume(); 
     4426                                if (!vdata) 
     4427                                        vdata = obj->mViewCellPvs.AddSample2(vc, 1); 
     4428                                vdata->Mail(); 
     4429                        } 
     4430                } 
     4431        } 
     4432 
     4433 
     4434        } 
     4435 
     4436        ///////////////////////////// 
     4437 
     4438 
     4439        // these are non-overlapping sets 
     4440        pOverall = pFront + pBack + pFrontAndBack; 
     4441 
     4442 
     4443        //-- pvs rendering heuristics 
     4444 
     4445        const float oldRenderCost = pOverall * totalPvs; 
     4446         
     4447        // sum up the terms:  
     4448        // the view cells seeing 
     4449        // a) the left node are weighted by the #left node objects 
     4450        // b) the right node are weighted by the #right node objects 
     4451        // c) both nodes are weighted by the #parent node objects 
     4452        const float newRenderCost = pvsFront * pFront + pvsBack * pBack + totalPvs * pFrontAndBack 
     4453                + additionalFrontRenderCost + additionalBackRenderCost; 
     4454 
     4455        // normalize volume with view space volume 
     4456        const float renderCostDecrease = (oldRenderCost - newRenderCost) / viewSpaceVol; 
     4457 
     4458        Debug << "\n(((( eval render cost decrease ))))" << endl 
     4459                  << "back pvs: " << pvsBack << " front pvs " << pvsFront << " total pvs: " << totalPvs << endl  
     4460                  << "back p: " << pBack / viewSpaceVol << " front p " << pFront / viewSpaceVol  
     4461                  << " front and back p " << pFrontAndBack / viewSpaceVol << " p: " << tData.mProbability / viewSpaceVol << endl 
     4462                  << "old rc: " << oldRenderCost / viewSpaceVol << " new rc: " << newRenderCost / viewSpaceVol << endl 
     4463                  << "render cost decrease: " << renderCostDecrease << endl 
     4464                  << "additional front " << additionalFrontRenderCost / viewSpaceVol  
     4465                  << " additional back " << additionalBackRenderCost  / viewSpaceVol << endl; 
     4466 
     4467        if (oldRenderCost < newRenderCost * 0.99) 
     4468                Debug <<"error!!"<<endl; 
     4469 
     4470        //if ((((pOverall - tData.mProbability) / viewSpaceVol) > 0.00001)) 
     4471        //      Debug << "ERROR!!"<<endl; 
     4472 
     4473        normalizedOldRenderCost = oldRenderCost / viewSpaceVol; 
     4474 
     4475                 
     4476        return renderCostDecrease; 
     4477} 
     4478#endif 
    42584479 
    42594480void OspTree::ComputeBoundingBox(const ObjectContainer &objects, 
     
    44694690 
    44704691 
    4471 void OspTree::PreprocessRays(const VssRayContainer &sampleRays, 
     4692void OspTree::PreprocessRays(KdLeaf *root, 
     4693                                                         const VssRayContainer &sampleRays, 
    44724694                                                         RayInfoContainer &rays) 
    44734695{ 
    44744696        VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); 
     4697        RayInfoContainer clippedRays; 
    44754698 
    44764699        long startTime = GetTime(); 
     
    44944717                { 
    44954718                        float len = ray->Length(); 
    4496  
    4497                         if (!len) 
     4719                        if (!len)  
    44984720                                len = Limits::Small; 
    44994721 
    4500                         rays.push_back(RayInfo(ray, minT / len, maxT / len)); 
     4722                        clippedRays.push_back(RayInfo(ray, minT / len, maxT / len)); 
    45014723 
    45024724                        // HACK: reset nodes for the case we have used object kd tree for 
     
    45064728                } 
    45074729        } 
     4730 
     4731        FilterRays(root, clippedRays, rays); 
    45084732 
    45094733        cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     
    45604784} 
    45614785 
     4786 
     4787int OspTree::FilterRays(KdLeaf *leaf,  
     4788                                                const RayInfoContainer &rays, 
     4789                                                RayInfoContainer &filteredRays) 
     4790{ 
     4791        RayInfoContainer::const_iterator rit, rit_end = rays.end(); 
     4792 
     4793        for (rit = rays.begin(); rit != rit_end; ++ rit) 
     4794        { 
     4795                VssRay *ray = (*rit).mRay; 
     4796 
     4797                // test if intersection point with one of the objects is inside this node 
     4798                const bool originInside = EndPointInsideNode(leaf, *ray, false); 
     4799        const bool terminationInside = EndPointInsideNode(leaf, *ray, true); 
     4800 
     4801                if (originInside || terminationInside) 
     4802                { 
     4803                        filteredRays.push_back(ray); 
     4804                } 
     4805        } 
     4806 
     4807        return 0; 
     4808} 
     4809                                          
    45624810 
    45634811int OspTree::SplitViewCells(const AxisAlignedPlane &candidatePlane, 
     
    49905238 
    49915239 
    4992 float OspTree::EvalRenderCost() 
     5240float OspTree::EvalRenderCost(const VssRayContainer &myrays) 
    49935241{ 
    49945242        float rc = 0; 
    4995 float prop = mVspTree->GetBoundingBox().GetVolume();     
     5243        float prop = mVspTree->GetBoundingBox().GetVolume();     
     5244 
    49965245        KdLeafContainer leaves; 
    49975246        CollectLeaves(leaves); 
    49985247 
     5248        ViewCellContainer vcleaves; 
     5249        mVspTree->CollectViewCells(vcleaves, false); 
     5250         
     5251 
     5252        ViewCellContainer::const_iterator vit, vit_end = vcleaves.end(); 
     5253 
     5254        for (vit = vcleaves.begin(); vit != vit_end; ++ vit) 
     5255        { 
     5256                ViewCell *vc = *vit; 
     5257                vc->GetPvs().Clear(); 
     5258        } 
     5259 
    49995260        KdLeafContainer::const_iterator kit, kit_end = leaves.end(); 
     5261 
     5262        ViewCellPvsData::NewMail(); 
     5263 
    50005264        for (kit = leaves.begin(); kit != kit_end; ++ kit) 
    50015265        { 
     
    50135277                         
    50145278                        // test if intersection point with one of the objects is inside this node 
     5279 
    50155280                        const bool originInside = EndPointInsideNode(leaf, *ray, false); 
    50165281                        const bool terminationInside = EndPointInsideNode(leaf, *ray, true); 
     
    50315296                                        { 
    50325297                                                vc->Mail(); 
    5033                                                 vc->GetPvs().Clear(); 
    50345298                                                touchedViewCells.push_back(vc); 
    50355299                                        } 
     
    50395303                } 
    50405304                 
    5041                 //ViewCellPvsData::NewMail(); 
    50425305                ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
    50435306 
     5307                //Debug << "here53 " << touchedViewCells.size() << endl; 
    50445308                for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 
    50455309                { 
     
    50505314                        { 
    50515315                                ViewCell *vc = *vit; 
    5052                                 ObjectPvsData *vdata = vc->GetPvs().Find(obj); 
     5316                                /*ObjectPvsData *vdata = vc->GetPvs().Find(obj); 
    50535317 
    50545318                                if (!vdata) 
     
    50575321                                        newCost += vc->GetVolume(); 
    50585322                                        //prop += vc->GetVolume(); 
     5323                                }*/ 
     5324 
     5325                                ViewCellPvsData *vdata = obj->mViewCellPvs.Find(vc); 
     5326 
     5327                                if (!vdata || !vdata->Mailed()) 
     5328                                { 
     5329                                        newCost += vc->GetVolume(); 
     5330                                        if (!vdata) 
     5331                                                vdata = obj->mViewCellPvs.AddSample2(vc, 1); 
     5332                                        vdata->Mail(); 
    50595333                                } 
    50605334                        } 
     
    50685342 
    50695343 
    5070 /********************************************************************/ 
    5071 /*               class HierarchyManager implementation              */ 
    5072 /********************************************************************/ 
     5344float OspTree::EvalLeafCost(const OspTraversalData &tData) 
     5345{ 
     5346        KdLeaf *leaf = tData.mNode; 
     5347 
     5348        float rc = 0; 
     5349        //float prop = mVspTree->GetBoundingBox().GetVolume();   
     5350        //float vol = 0; 
     5351        //ViewCell::NewMail(); 
     5352         
     5353        RayInfoContainer::const_iterator rit, rit_end = tData.mRays->end(); 
     5354        ViewCellContainer touchedViewCells; 
     5355 
     5356        for (rit = tData.mRays->begin(); rit != rit_end; ++ rit) 
     5357        { 
     5358                VssRay *ray = (*rit).mRay; 
     5359                         
     5360                // test if intersection point with one of the objects is inside this node 
     5361 
     5362                ViewCellContainer viewCells; 
     5363                mVspTree->GetViewCells(*ray, viewCells); 
     5364                         
     5365                ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
     5366 
     5367                for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
     5368                { 
     5369                        ViewCell *vc = *vit; 
     5370 
     5371                        // if not previously mailed 
     5372                        if (!vc->Mailed()) 
     5373                        { 
     5374                                vc->Mail(); 
     5375                                touchedViewCells.push_back(vc); 
     5376                        } 
     5377                } 
     5378        } 
     5379 
     5380        // clear pvs of involved view cells 
     5381        ViewCellContainer::const_iterator vit, vit_end = touchedViewCells.end(); 
     5382 
     5383        for (vit = touchedViewCells.begin(); vit != vit_end; ++ vit) 
     5384        { 
     5385                ViewCell *vc = *vit; 
     5386                vc->GetPvs().Clear(); 
     5387        } 
     5388         
     5389        ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
     5390 
     5391        //Debug << "here53 " << touchedViewCells.size() << endl; 
     5392        for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 
     5393        { 
     5394                Intersectable *obj = *oit; 
     5395 
     5396                for (vit = touchedViewCells.begin(); vit != vit_end; ++ vit) 
     5397                { 
     5398                        ViewCell *vc = *vit; 
     5399                        ObjectPvsData *vdata = vc->GetPvs().Find(obj); 
     5400 
     5401                        if (!vdata) 
     5402                        { 
     5403                                vc->GetPvs().AddSample(obj, 1); 
     5404                                rc += vc->GetVolume(); 
     5405                                //prop += vc->GetVolume(); 
     5406                        } 
     5407                } 
     5408        } 
     5409         
     5410        return rc; 
     5411} 
     5412 
     5413 
     5414 
     5415/*******************************************************************/ 
     5416/*              class HierarchyManager implementation              */ 
     5417/*******************************************************************/ 
    50735418 
    50745419 
     
    51785523        mGlobalCostMisses = 0; 
    51795524 
    5180         // get clipped rays 
    5181         mOspTree.PreprocessRays(sampleRays, rays); 
    5182  
    51835525        // create new root 
    51845526        KdLeaf *kdleaf = new KdLeaf(NULL, 0); 
     
    51865528        mOspTree.mRoot = kdleaf; 
    51875529         
     5530        // get clipped rays 
     5531        mOspTree.PreprocessRays(kdleaf, sampleRays, rays); 
     5532 
     5533 
    51885534        // probabilty is voume of all "seen" view cells 
    5189 #if 1 
     5535#if 0 
    51905536        const float prop = mOspTree.EvalViewCellsVolume(kdleaf, rays); 
    51915537#else 
     
    54365782        mOspTree.mOspStats.Stop(); 
    54375783 
    5438         float rc = mOspTree.EvalRenderCost(); 
     5784        float rc = mOspTree.EvalRenderCost(sampleRays); 
    54395785 
    54405786        Debug << "My render cost evalulation: " << rc << endl; 
    54415787 
    5442          
    5443  
    5444  
    5445 ViewCellContainer leaves; 
    5446  
    5447 mVspTree.CollectViewCells(leaves, false); 
    5448 float rc2 = 0; 
    5449         ViewCellContainer::const_iterator vit, vit_end = leaves.end(); 
    5450         for (vit = leaves.begin(); vit != vit_end; ++ vit) 
    5451         { 
    5452                 ViewCell *vc = *vit; 
    5453  
    5454                 int pvs = vc->GetPvs().CountObjectsInPvs(); 
    5455                 float vol = vc->GetVolume(); 
    5456                 rc2 += (float)pvs * vol; 
    5457  
    5458         } 
    5459          
    5460         Debug << "here225 " << rc2 / mVspTree.GetBoundingBox().GetVolume()<<endl; 
    54615788#if 0 
    54625789        // reset parameters 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h

    r1184 r1186  
    778778                or by recomputation. 
    779779        */ 
    780         void GetViewCells(const VssRay &ray, ViewCellContainer &viewCells); 
     780        void GetViewCells(VssRay &ray, ViewCellContainer &viewCells); 
    781781 
    782782 
     
    11241124 
    11251125 
    1126  
    11271126        //-- split heuristics based parameters 
    11281127         
     
    11921191                AxisAlignedBox3 mBoundingBox; 
    11931192                /// pvs size 
    1194                 int mPvs; 
     1193                float mRenderCost; 
    11951194                /// how often this branch has missed the max-cost ratio 
    11961195                int mMaxCostMisses; 
     
    12051204                mRays(NULL), 
    12061205                mDepth(0), 
    1207                 mPvs(0), 
     1206                mRenderCost(0), 
    12081207                mProbability(0.0), 
    12091208                mMaxCostMisses(0),  
     
    12151214                                                 const int depth, 
    12161215                         RayInfoContainer *rays, 
    1217                                                  const int pvs, 
     1216                                                 const float rc, 
    12181217                                                 const float p, 
    12191218                                                 const AxisAlignedBox3 &box): 
     
    12211220                mDepth(depth), 
    12221221                mRays(rays), 
    1223                 mPvs(pvs), 
     1222                mRenderCost(rc), 
    12241223                mProbability(p), 
    12251224                mBoundingBox(box), 
     
    12351234                mDepth(depth), 
    12361235                mRays(rays), 
    1237                 mPvs(0), 
     1236                mRenderCost(0), 
    12381237                mProbability(0), 
    12391238                mMaxCostMisses(0), 
     
    14221421        void SetViewCellsTree(ViewCellsTree *vt) { mViewCellsTree = vt; } 
    14231422 
    1424         float EvalRenderCost(); 
     1423        float EvalRenderCost(const VssRayContainer &myrays); 
     1424        float EvalLeafCost(const OspTraversalData &tData); 
    14251425 
    14261426protected: 
     
    15851585                RayInfoContainer &backRays) const; 
    15861586 
     1587        int FilterRays(KdLeaf *leaf, const RayInfoContainer &rays, RayInfoContainer &filteredRays); 
     1588 
    15871589        int SplitViewCells( 
    15881590                const AxisAlignedPlane &candidatePlane, 
     
    16791681        /** Rays will be clipped to the bounding box. 
    16801682        */ 
    1681         void PreprocessRays(const VssRayContainer &sampleRays, 
     1683        void PreprocessRays( 
     1684                KdLeaf *root,  
     1685                const VssRayContainer &sampleRays, 
    16821686                RayInfoContainer &rays); 
    16831687 
     
    17291733                float &contribution, 
    17301734                bool onlyMailed) const; 
     1735 
     1736        int ClassifyRays( 
     1737                const RayInfoContainer &rays,  
     1738                KdLeaf *leaf,  
     1739                const AxisAlignedPlane &plane, 
     1740                RayInfoContainer &frontRays, 
     1741                RayInfoContainer &backRays) const; 
    17311742 
    17321743protected: 
Note: See TracChangeset for help on using the changeset viewer.