Changeset 1138


Ignore:
Timestamp:
07/18/06 05:07:05 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing
Files:
2 added
4 edited

Legend:

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

    r1137 r1138  
    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/ViewCellsManager.cpp

    r1135 r1138  
    54655465 
    54665466                if (1) 
    5467                 {       //-- export pvs 
    5468  
     5467                {        
     5468                        //-- export pvs 
    54695469                        ObjectPvsMap::const_iterator oit, 
    54705470                                oit_end = pvs.mEntries.end(); 
     
    54825482                        for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit) 
    54835483                        {        
    5484                                 // exportŽ"original" pvs 
     5484                                // export "original" pvs 
    54855485                                Intersectable *obj = (*oit).first; 
    54865486 
     
    54905490                                        obj->Mail(); 
    54915491                                }                                        
    5492         // TODO matt§§ 
    5493 #if TODO 
    5494                                 // collect kd leaves 
    5495                                 //KdLeaf = 
    5496                                 set<KdLeaf *>::const_iterator kdit, kdit_end = obj->mKdLeaves.end(); 
    5497  
    5498                                 for (kdit = obj->mKdLeaves.begin(); kdit != kdit_end; ++ kdit) 
     5492                                 
     5493                                // TODO matt§§ 
     5494                                // export kd pvs 
     5495                                KdLeaf *kdleaf = 0; 
     5496 
     5497                                if (!kdleaf->Mailed()) 
    54995498                                { 
    5500                                         KdLeaf *kdleaf = *kdit; 
    5501  
    5502                                         if (!kdleaf->Mailed()) 
    5503                                         { 
    5504                                                 kdleaf->Mail(); 
    5505                                                 kdLeaves.push_back(kdleaf); 
    5506                                         } 
     5499                                        kdleaf->Mail(); 
     5500                                        kdLeaves.push_back(kdleaf); 
    55075501                                } 
    5508 #endif 
    55095502                        } 
    55105503 
     
    55225515 
    55235516                                //-- export kd node 
    5524                                 /*exporter->SetWireframe(); 
    5525                                 exporter->ExportBox(mKdTree->GetBox(kdleaf)); 
    5526                                 exporter->SetFilled();*/ 
    5527  
     5517                                 
    55285518                                ObjectContainer::const_iterator oit, oit_end = kdleaf->mObjects.end(); 
    55295519 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp

    r1137 r1138  
    982982 
    983983 
    984 int VspTree::PrepareHeuristics(Intersectable *object) 
     984int VspTree::PrepareHeuristics(KdLeaf *leaf) 
    985985{        
    986986        int pvsSize = 0; 
    987         // TODO matt§§ 
    988 #if TODO 
    989         set<KdLeaf *>::const_iterator kit, kit_end = object->mKdLeaves.end(); 
    990  
    991         for (kit = object->mKdLeaves.begin(); kit != kit_end; ++ kit) 
    992         { 
    993                 KdLeaf *node = dynamic_cast<KdLeaf *>(*kit); 
    994  
    995                 if (!node->Mailed()) 
    996                 { 
    997                         node->Mail(); 
    998                         node->mCounter = 1; 
    999  
    1000                         // add objects without the objects which are in several kd leaves 
    1001                         pvsSize += (int)(node->mObjects.size() - node->mMultipleObjects.size()); 
     987         
     988        if (!leaf->Mailed()) 
     989        { 
     990                leaf->Mail(); 
     991                leaf->mCounter = 1; 
     992 
     993                // add objects without the objects which are in several kd leaves 
     994                pvsSize += (int)(leaf->mObjects.size() - leaf->mMultipleObjects.size()); 
     995        } 
     996        else 
     997        { 
     998                ++ leaf->mCounter; 
     999        } 
     1000 
     1001        //-- the objects belonging to several leaves must be handled seperately 
     1002 
     1003        ObjectContainer::const_iterator oit, oit_end = leaf->mMultipleObjects.end(); 
     1004 
     1005        for (oit = leaf->mMultipleObjects.begin(); oit != oit_end; ++ oit) 
     1006        { 
     1007                Intersectable *object = *oit; 
     1008                                                 
     1009                if (!object->Mailed()) 
     1010                { 
     1011                        object->Mail(); 
     1012                        object->mCounter = 1; 
     1013 
     1014                        ++ pvsSize; 
    10021015                } 
    10031016                else 
    10041017                { 
    1005                         ++ node->mCounter; 
    1006                 } 
    1007  
    1008                 //-- the objects belonging to several leaves must be handled seperately 
    1009  
    1010                 ObjectContainer::const_iterator oit, oit_end = node->mMultipleObjects.end(); 
    1011  
    1012                 for (oit = node->mMultipleObjects.begin(); oit != oit_end; ++ oit) 
    1013                 { 
    1014                         Intersectable *object = *oit; 
    1015                                                  
    1016                         if (!object->Mailed()) 
    1017                         { 
    1018                                 object->Mail(); 
    1019                                 object->mCounter = 1; 
    1020  
    1021                                 ++ pvsSize; 
    1022                         } 
    1023                         else 
    1024                         { 
    1025                                 ++ object->mCounter; 
    1026                         } 
    1027                 } 
    1028         } 
    1029 #endif 
     1018                        ++ object->mCounter; 
     1019                } 
     1020        } 
     1021         
    10301022        return pvsSize; 
    10311023} 
     
    10451037        for (ri = rays.begin(); ri != ri_end; ++ ri) 
    10461038        { 
    1047                 Intersectable *oObject = (*ri).mRay->mOriginObject; 
     1039                VssRay *ray = (*ri).mRay; 
     1040                Intersectable *oObject = ray->mOriginObject; 
    10481041 
    10491042                if (oObject) 
     
    10641057                        else 
    10651058                        { 
    1066                                 pvsSize += PrepareHeuristics(oObject);   
     1059                                KdLeaf *leaf = mOspTree->GetLeaf(ray->mOrigin, ray->mOriginNode); 
     1060                                pvsSize += PrepareHeuristics(leaf);      
    10671061                        }        
    10681062                } 
     
    10871081                        else 
    10881082                        { 
    1089                                 pvsSize += PrepareHeuristics(tObject);   
     1083                                KdLeaf *leaf = mOspTree->GetLeaf(ray->mTermination, ray->mTerminationNode); 
     1084                                pvsSize += PrepareHeuristics(leaf);      
    10901085                        }        
    10911086                } 
     
    11751170                else // per kd node 
    11761171                { 
    1177         // TODO matt§§ 
    1178 #if TODO 
    1179                         set<KdLeaf *>::const_iterator kit, kit_end = oObject->mKdLeaves.end(); 
    1180  
    1181                         for (kit = oObject->mKdLeaves.begin(); kit != kit_end; ++ kit) 
    1182                         { 
    1183                                 KdLeaf *node = dynamic_cast<KdLeaf *>(*kit); 
    1184  
    1185                                 // add contributions of the kd nodes 
    1186                                 if (ci.type == SortableEntry::ERayMin) 
    1187                                 { 
    1188                                         AddContriToPvs(node, pvsLeft); 
    1189                                 } 
    1190                                 else if (ci.type == SortableEntry::ERayMax) 
    1191                                 { 
    1192                                         RemoveContriFromPvs(node, pvsRight); 
    1193                                 } 
    1194                         } 
    1195 #endif 
     1172                        KdLeaf *node = mOspTree->GetLeaf(ray->mOrigin, ray->mOriginNode); 
     1173 
     1174                        // add contributions of the kd nodes 
     1175                        if (ci.type == SortableEntry::ERayMin) 
     1176                        { 
     1177                                AddContriToPvs(node, pvsLeft); 
     1178                        } 
     1179                        else if (ci.type == SortableEntry::ERayMax) 
     1180                        { 
     1181                                RemoveContriFromPvs(node, pvsRight); 
     1182                        } 
    11961183                } 
    11971184                         
     
    12191206                else // per kd node 
    12201207                { 
    1221                         // TODO matt§§ 
    1222 #if TODO 
    1223                         set<KdLeaf *>::const_iterator kit, kit_end = tObject->mKdLeaves.end(); 
    1224                          
    1225                         for (kit = tObject->mKdLeaves.begin(); kit != kit_end; ++ kit) 
    1226                         { 
    1227                                 KdLeaf *node = dynamic_cast<KdLeaf *>(*kit); 
    1228  
    1229                                 if (ci.type == SortableEntry::ERayMin) 
    1230                                 { 
    1231                                         AddContriToPvs(node, pvsLeft); 
    1232                                 } 
    1233                                 else if (ci.type == SortableEntry::ERayMax) 
    1234                                 { 
    1235                                         RemoveContriFromPvs(node, pvsRight); 
    1236                                 } 
    1237                         } 
    1238 #endif 
     1208                        KdLeaf *node = mOspTree->GetLeaf(ray->mTermination, ray->mTerminationNode); 
     1209 
     1210                        if (ci.type == SortableEntry::ERayMin) 
     1211                        { 
     1212                                AddContriToPvs(node, pvsLeft); 
     1213                        } 
     1214                        else if (ci.type == SortableEntry::ERayMax) 
     1215                        { 
     1216                                RemoveContriFromPvs(node, pvsRight); 
     1217                        } 
    12391218                } 
    12401219        } 
     
    25622541                                                                         vector<SplitCandidate *> &dirtyList) 
    25632542{ 
    2564         VspLeaf *node = sc->mParentData.mNode; 
    2565          
    2566     ViewCellLeaf *vc = node->GetViewCell(); 
     2543        VspTraversalData &tData = sc->mParentData; 
     2544        VspLeaf *node = tData.mNode; 
     2545         
     2546        KdLeaf::NewMail(); 
     2547 
     2548        RayInfoContainer::const_iterator rit, rit_end = tData.mRays->end(); 
     2549 
     2550        // add all kd nodes seen by the rays 
     2551        for (rit = tData.mRays->begin(); rit != rit_end; ++ rit) 
     2552        { 
     2553                VssRay *ray = (*rit).mRay; 
     2554         
     2555                KdLeaf *leaf = mOspTree->GetLeaf(ray->mOrigin, ray->mOriginNode); 
     2556         
     2557                if (!leaf->Mailed()) 
     2558                { 
     2559                        leaf->Mail(); 
     2560                        dirtyList.push_back(leaf->mSplitCandidate); 
     2561                } 
    25672562                 
    2568         ObjectPvsMap::const_iterator oit, oit_end = vc->GetPvs().mEntries.end(); 
    2569  
    2570         KdLeaf::NewMail(); 
    2571  
    2572         for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
    2573         { 
    2574                 Intersectable *obj = (*oit).first; 
    2575         // TODO matt§§ 
    2576 #if TODO 
    2577                 set<KdLeaf *>::const_iterator kit, kit_end = obj->mKdLeaves.end(); 
    2578          
    2579                 for (kit = obj->mKdLeaves.begin(); kit != kit_end; ++ kit) 
    2580                 { 
    2581                         KdLeaf *leaf = *kit; 
    2582  
    2583                         if (!leaf->Mailed()) 
    2584                         { 
    2585                                 leaf->Mail(); 
    2586                                 dirtyList.push_back(leaf->mSplitCandidate); 
    2587                         } 
    2588                 } 
    2589 #endif 
     2563                leaf = mOspTree->GetLeaf(ray->mTermination, ray->mTerminationNode); 
     2564         
     2565                if (!leaf->Mailed()) 
     2566                { 
     2567                        leaf->Mail(); 
     2568                        dirtyList.push_back(leaf->mSplitCandidate); 
     2569                } 
    25902570        } 
    25912571} 
     
    30142994        SortSplitCandidates(tData, axis, minBand, maxBand); 
    30152995 
    3016         float totalVol = PrepareHeuristics(tData.mNode->mObjects); 
     2996        float totalVol = PrepareHeuristics(tData); 
    30172997        float voll = 0; 
    30182998        float volr = totalVol; 
     
    32273207        ViewCellContainer viewCells; 
    32283208 
    3229         mVspTree->GetViewCells(ray); 
     3209        mVspTree->GetViewCells(ray, viewCells); 
    32303210     
    32313211        ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
     
    32673247                        (GetLeaf(ray->mTermination, ray->mTerminationNode) == leaf)) 
    32683248                { 
    3269             vol += PrepareHeuristics(ray); 
     3249            vol += PrepareHeuristics(tData); 
    32703250                } 
    32713251        } 
     
    34283408 
    34293409float OspTree::EvalRenderCostDecrease(const AxisAlignedPlane &candidatePlane, 
    3430                                                                           const OspTraversalData &data) const 
     3410                                                                          const OspTraversalData &tData) const 
    34313411{ 
    34323412#if 0 
    3433         return (float)-data.mDepth; 
     3413        return (float)-tData.mDepth; 
    34343414#endif 
    34353415 
     
    34393419 
    34403420        // probability that view point lies in back / front node 
    3441         float pOverall = data.mBoundingBox.GetVolume();//data.mProbability; 
     3421        float pOverall = 0;//data.mProbability; // todo matt§: value ok? 
    34423422        float pFront = 0; 
    34433423        float pBack = 0; 
     
    34473427        ViewCell::NewMail(); 
    34483428 
    3449         KdLeaf *leaf = data.mNode; 
     3429        KdLeaf *leaf = tData.mNode; 
    34503430        ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 
    34513431 
     
    34823462                if (GetLeaf(ray->mOrigin, ray->mOriginNode) == leaf) 
    34833463                { 
    3484                         if (ray->mOrigin[candidatePlane.mAxis] > candidatePlane.mPosition) 
    3485                         { 
    3486                                 // add view cells volume to front        
    3487                                 mVspTree->GetViewCells(ray, viewCells); 
    3488  
    3489                                 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
    3490  
    3491                                 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
     3464                        ViewCellContainer viewCells;             
     3465                        mVspTree->GetViewCells(*ray, viewCells); 
     3466                         
     3467                        ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
     3468 
     3469                        // add view cells volume to front        
     3470                        for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
     3471                        { 
     3472                                ViewCell *vc = *vit; 
     3473 
     3474                                if (!vc->Mailed()) 
    34923475                                { 
    3493                                         ViewCell *vc = *vit; 
    3494  
    3495                                         if (!vit->Mailed()) 
    3496                                         { 
    3497                                                 vit->Mail(); 
    3498                                                 volBack += vc->GetVolume(); 
    3499                                         } 
     3476                                        vc->Mail(); 
     3477 
     3478                                        const float vol = vc->GetVolume(); 
     3479                                        pOverall += vol; 
     3480 
     3481                                        if (ray->mOrigin[candidatePlane.mAxis] > candidatePlane.mPosition) 
     3482                                                pFront += vol; 
     3483                                        else 
     3484                                                pBack += vol; 
    35003485                                } 
    35013486                        } 
    3502                         else 
    3503                         {// TODO matt§§ 
    3504                                 // add view cells volume to back 
    3505                                 if (ray->mOrigin[candidatePlane.mAxis] < candidatePlane.mPosition) 
    3506                                 { 
    3507                                         // add view cells volume to front        
    3508                                         mVspTree->GetViewCells(ray, viewCells); 
    3509  
    3510                                         ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
    3511  
    3512                                         for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
    3513                                         { 
    3514                                                 ViewCell *vc = *vit; 
    3515          
    3516                                                 if (!vit->Mailed()) 
    3517                                                 { 
    3518                                                         vit->Mail(); 
    3519                                                         volBack += vc->GetVolume(); 
    3520                                                 } 
    3521                                         } 
    3522                                 } 
    3523                         } 
    3524                 } 
    3525         } 
    3526  
    3527  
    3528  
    3529         AxisAlignedBox3 frontBox; 
    3530         AxisAlignedBox3 backBox; 
    3531  
    3532         data.mBoundingBox.Split(candidatePlane.mAxis, candidatePlane.mPosition, frontBox, backBox); 
    3533  
    3534         pFront = frontBox.GetVolume(); 
    3535         pBack = pOverall - pFront; 
    3536                  
     3487                } 
     3488        } 
     3489 
    35373490 
    35383491        //-- pvs rendering heuristics 
    3539         const int lowerPvsLimit = mViewCellsManager->GetMinPvsSize(); 
    3540         const int upperPvsLimit = mViewCellsManager->GetMaxPvsSize(); 
    3541  
    3542         //-- only render cost heuristics or combined with standard deviation 
    3543         const float penaltyOld = totalPvs;//EvalPvsPenalty((int)totalPvs, lowerPvsLimit, upperPvsLimit); 
    3544     const float penaltyFront = pvsFront;//EvalPvsPenalty((int)pvsFront, lowerPvsLimit, upperPvsLimit); 
    3545         const float penaltyBack = pvsBack;//EvalPvsPenalty((int)pvsBack, lowerPvsLimit, upperPvsLimit); 
    3546                          
    3547         Debug << "total pvs: " << totalPvs << " p " << pOverall << endl; 
    3548         const float oldRenderCost = pOverall * penaltyOld; 
    3549         const float newRenderCost = penaltyFront * pFront + penaltyBack * pBack; 
    3550  
    3551         Debug << "old: " << oldRenderCost << " new: " << newRenderCost << " decrease: "  
    3552                 << oldRenderCost - newRenderCost << endl; 
    3553         const float renderCostDecrease = (oldRenderCost - newRenderCost) / mBoundingBox.GetVolume(); 
     3492        const float oldRenderCost = pOverall * totalPvs; 
     3493        const float newRenderCost = pvsFront * pFront + pvsBack * pBack; 
     3494 
     3495        Debug << "total pvs: " << totalPvs << " p " << pOverall << endl 
     3496                  << "old: " << oldRenderCost << " new: " << newRenderCost << " decrease: "  
     3497                  << oldRenderCost - newRenderCost << endl; 
     3498 
     3499        // todo matt§§: how to normalize volume?? 
     3500        const float renderCostDecrease = (oldRenderCost - newRenderCost);// / mBoundingBox.GetVolume(); 
    35543501         
    35553502        // take render cost of node into account  
     
    35573504        const float factor = mRenderCostDecreaseWeight; 
    35583505 
    3559         const float normalizedOldRenderCost = oldRenderCost / mBoundingBox.GetVolume(); 
     3506        const float normalizedOldRenderCost = oldRenderCost;// / mBoundingBox.GetVolume(); 
    35603507        return factor * renderCostDecrease + (1.0f - factor) * normalizedOldRenderCost; 
    35613508} 
     
    37453692                                                                         vector<SplitCandidate *> &dirtyList) 
    37463693{ 
    3747         KdLeaf *node = sc->mParentData.mNode; 
    3748  
    3749         ObjectContainer::const_iterator oit, oit_end = node->mObjects.end(); 
    3750  
     3694        OspTraversalData &tData = sc->mParentData; 
     3695        KdLeaf *node = tData.mNode; 
     3696         
     3697        ViewCell::NewMail(); 
    37513698        ViewCellContainer viewCells; 
    3752  
    3753         CollectViewCells(node, viewCells); 
    3754  
     3699        ViewCellContainer tmpViewCells; 
     3700 
     3701        RayInfoContainer::const_iterator rit, rit_end = tData.mRays->end(); 
     3702 
     3703        // find all view cells associated with the rays, add them to view cells 
     3704        for (rit = tData.mRays->begin(); rit != rit_end; ++ rit) 
     3705        { 
     3706                VssRay *ray = (*rit).mRay; 
     3707                mVspTree->GetViewCells(*ray, tmpViewCells); 
     3708 
     3709                ViewCellContainer::const_iterator vit, vit_end = tmpViewCells.end(); 
     3710 
     3711                for (vit = tmpViewCells.begin(); vit != vit_end; ++ vit) 
     3712                { 
     3713                        VspViewCell *vc = dynamic_cast<VspViewCell *>(*vit); 
     3714 
     3715                        if (!vc->Mailed()) 
     3716                        { 
     3717                                vc->Mail(); 
     3718                                viewCells.push_back(vc); 
     3719                        } 
     3720                } 
     3721        } 
     3722 
     3723 
     3724        // split candidates holding this view cells  
     3725        // are thrown into dirty list 
    37553726        ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
    37563727 
    3757         // through split candidates corresponding to view cell pvs of this 
    3758         // node into dirty list 
    37593728        for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
    37603729        { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h

    r1137 r1138  
    927927        int PrepareHeuristics(const RayInfoContainer &rays); 
    928928 
    929         int PrepareHeuristics(Intersectable *object); 
     929        int PrepareHeuristics(KdLeaf *leaf); 
    930930 
    931931        /** Subdivides the rays into front and back rays according to the split plane. 
Note: See TracChangeset for help on using the changeset viewer.