Changeset 406 for trunk


Ignore:
Timestamp:
11/11/05 21:28:02 (19 years ago)
Author:
mattausch
Message:

started kd based bottom-up view cells

Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
3 added
11 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/scripts/Preprocessor.vcproj

    r390 r406  
    243243                        </File> 
    244244                        <File 
     245                                RelativePath="..\src\RenderSimulator.cpp"> 
     246                        </File> 
     247                        <File 
     248                                RelativePath="..\src\RenderSimulator.h"> 
     249                        </File> 
     250                        <File 
    245251                                RelativePath="..\src\SamplingPreprocessor.cpp"> 
    246252                        </File> 
     
    283289                        <File 
    284290                                RelativePath="..\src\ViewCellBsp.h"> 
     291                        </File> 
     292                        <File 
     293                                RelativePath="..\src\ViewCellKd.cpp"> 
     294                        </File> 
     295                        <File 
     296                                RelativePath="..\src\ViewCellKd.h"> 
    285297                        </File> 
    286298                        <File 
     
    358370                                RelativePath="..\include\ViewCell.h"> 
    359371                        </File> 
    360                         <File 
    361                                 RelativePath="..\include\ViewCellBsp.h"> 
    362                         </File> 
    363372                </Filter> 
    364373        </Files> 
  • trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env

    r404 r406  
    5656 
    5757Sampling { 
    58         totalSamples    300000 
     58        totalSamples    1000000 
    5959        samplesPerPass  3 
    6060} 
     
    126126        #splitPlaneStrategy 130 
    127127         
    128         splitPlaneStrategy 1024 
     128        splitPlaneStrategy 1 
    129129         
    130         maxPolyCandidates 0 
    131         maxRayCandidates 50 
     130        maxPolyCandidates 50 
     131        maxRayCandidates 100 
    132132         
    133133        Termination { 
    134134                # autopartition 
    135                 maxRays 300 
     135                maxRays 200 
    136136                maxPolygons -1 
    137137                maxDepth 40 
     
    161161        } 
    162162} 
     163 
     164Simulation { 
     165        objRenderCost 1.0 
     166        vcOverhead 0.05 
     167} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp

    r403 r406  
    11771177  RegisterOption("ViewCells.PostProcessing.minPvsDif", 
    11781178                 optInt, 
    1179                  "-view_cells_min_pvs_dif", 
     1179                 "-view_cells_post_processing_min_pvs_dif", 
    11801180                 "10"); 
    1181    
     1181 
    11821182  RegisterOption("ViewCells.PostProcessing.maxPvs", 
    11831183                 optInt, 
    1184                  "-view_cells_max_pvs", 
     1184                 "-view_cells_post_processing_max_pvs", 
    11851185                 "300"); 
    11861186 
    11871187  RegisterOption("ViewCells.PostProcessing.minPvs", 
    11881188                 optString, 
    1189                  "-view_cells_min_pvs", 
     1189                 "-view_cells_post_processing_min_pvs", 
    11901190                 "10"); 
    11911191 
     
    11991199                 "-view_cells_height=", 
    12001200                 "5.0"); 
     1201    
     1202  RegisterOption("Simulation.objRenderCost", 
     1203                 optFloat, 
     1204                 "-simulation_obj_render_cost", 
     1205                 "1.0"); 
     1206 
     1207  RegisterOption("Simulation.vcOverhead", 
     1208                 optFloat, 
     1209                 "-simulation_vc_overhead", 
     1210                 "0.05"); 
    12011211 
    12021212  RegisterOption("BspTree.Construction.input", 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.h

    r390 r406  
    192192  virtual float IntersectionComplexity() {  return (float)mMesh->mFaces.size(); } 
    193193 
    194         virtual int NumberOfFaces() const {  return mMesh->mFaces.size(); } 
     194        virtual int NumberOfFaces() const {  return (int)mMesh->mFaces.size(); } 
    195195 
    196196  virtual int Type() const { return MESH_INSTANCE; } 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Pvs.h

    r385 r406  
    88class Ray; 
    99class Intersectable; 
    10  
     10class ViewCellKdNode; 
    1111 
    1212template<typename T> 
     
    142142 
    143143typedef std::map<KdNode *, PvsData<KdNode *>, LtSample<KdNode *> > KdPvsMap; 
     144typedef std::map<ViewCellKdNode *, PvsData<ViewCellKdNode *>, LtSample<ViewCellKdNode *> > ViewCellKdPvsMap; 
    144145typedef std::map<Intersectable *, PvsData<Intersectable *>, LtSample<Intersectable *> > ViewCellPvsMap; 
    145146typedef PvsData<Intersectable *> ViewCellPvsData; 
    146147typedef PvsData<KdNode *> KdPvsData; 
    147 //typedef Pvs<KdNode *> KdPvs; 
     148typedef Pvs<ViewCellKdNode *> ViewCellKdPvs; 
    148149typedef Pvs<Intersectable *> ViewCellPvs; 
    149150 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Ray.cpp

    r369 r406  
    172172int 
    173173Ray::ClassifyPlane(const Plane3 &plane,  
    174                                                                          const float minT,  
    175                                                                          const float maxT) const 
    176 { 
    177         const Vector3 entp = Extrap(minT); 
    178         const Vector3 extp = Extrap(maxT); 
    179    
    180         const int entSide = plane.Side(entp); 
    181         const int extSide = plane.Side(extp); 
     174                                   const float minT,  
     175                                   const float maxT, 
     176                                   Vector3 &entP, 
     177                                   Vector3 &extP) const 
     178{ 
     179        entP = Extrap(minT); 
     180        extP = Extrap(maxT); 
     181   
     182        const int entSide = plane.Side(entP); 
     183        const int extSide = plane.Side(extP); 
    182184 
    183185        if (entSide < 0) 
     186        { 
     187                if (extSide >= 0) 
    184188                { 
    185                         if (extSide >= 0) 
    186                                 { 
    187                                         return BACK_FRONT; 
    188                                 } 
    189                         return BACK; 
     189                        return BACK_FRONT; 
    190190                } 
     191                return BACK; 
     192        } 
    191193        else if (entSide > 0) 
    192                 { 
    193                         if (extSide <= 0) 
    194                                 return FRONT_BACK; 
     194        { 
     195                if (extSide <= 0) 
     196                        return FRONT_BACK; 
    195197                         
    196                         return FRONT; 
    197                 } 
     198                return FRONT; 
     199        } 
    198200        else if (entSide == 0) 
    199                 { 
    200                         if (extSide > 0) 
    201                                 return BACK_FRONT; 
    202                         else if (extSide < 0) 
    203                                 return FRONT_BACK; 
    204                 } 
     201        { 
     202                if (extSide > 0) 
     203                        return BACK_FRONT; 
     204                else if (extSide < 0) 
     205                        return FRONT_BACK; 
     206        } 
    205207         
    206208        return COINCIDENT; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h

    r401 r406  
    214214  /** Classifies ray with respect to the plane. 
    215215  */ 
    216   int ClassifyPlane(const Plane3 &plane, const float minT, const float maxT) const; 
     216  int ClassifyPlane(const Plane3 &plane,  
     217                                        const float minT,  
     218                                        const float maxT, 
     219                                        Vector3 &entP, 
     220                                        Vector3 &extP) const; 
    217221 
    218222private: 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r404 r406  
    77#include "Polygon3.h" 
    88#include "ViewCell.h" 
     9#include "RenderSimulator.h" 
    910 
    1011SamplingPreprocessor::SamplingPreprocessor(): mPass(0), mSampleRays(NULL) 
     
    1617  environment->GetIntValue("ViewCells.PostProcessing.samples", mPostProcessSamples); 
    1718  environment->GetIntValue("BspTree.Visualization.samples", mVisualizationSamples); 
     19  environment->GetFloatValue("Simulation.objRenderCost", mObjRenderCost); 
     20  environment->GetFloatValue("Simulation.vcOverhead", mVcOverhead); 
    1821 
    1922  mKdPvsDepth = 100; 
     
    540543                //-- render simulation 
    541544                cout << "\nevaluating render time before merge ... "; 
    542                 Real rt = SimulateRendering(); 
     545                Real rt = BspTreeRenderSimulator(mObjRenderCost, mVcOverhead, mBspTree).SimulateRendering(); 
    543546                 
    544547                cout << "avg render time: " << rt * 1e-3 << endl; 
     
    586589                cout << "\nevaluating render time after merge ... "; 
    587590                         
    588                 rt = SimulateRendering(); 
     591                rt = BspTreeRenderSimulator(mObjRenderCost, mVcOverhead, mBspTree).SimulateRendering(); 
    589592 
    590593                cout << "render time: " << rt * 1e-3 << endl; 
     
    10341037        } 
    10351038} 
    1036  
    1037  
    1038 Real SamplingPreprocessor::RenderPvs(ViewCell &viewCell,  
    1039                                                                          const float objRenderTime) const 
    1040 { 
    1041         return viewCell.GetPvs().GetSize() * objRenderTime; 
    1042 } 
    1043  
    1044 Real SamplingPreprocessor::SimulateRendering() 
    1045 { 
    1046         Real renderTime = 0; 
    1047  
    1048         // render time for 1 object of PVS 
    1049         const float objRt = 1.0f;  
    1050          // const overhead for crossing a view cell border 
    1051         const float vcOverhead = 0;//0.01f; 
    1052          
    1053         // total area of view cells 
    1054         float totalArea = 0;//= mKdTree->GetBox().SurfaceArea(); 
    1055  
    1056         ViewCellContainer viewCells; 
    1057  
    1058         mBspTree->CollectViewCells(viewCells); 
    1059  
    1060         ViewCellContainer::const_iterator it, it_end = viewCells.end(); 
    1061          
    1062         for (it = viewCells.begin(); it != it_end; ++ it) 
    1063         { 
    1064                 // surface area substitute for probability 
    1065                 PolygonContainer cell; 
    1066                 float area = 0; 
    1067  
    1068                 mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), cell); 
    1069  
    1070                 area = Polygon3::GetArea(cell); 
    1071                  
    1072                 renderTime += area * RenderPvs(*(*it), objRt) + vcOverhead; 
    1073                 totalArea += area; 
    1074                 CLEAR_CONTAINER(cell); 
    1075         } 
    1076  
    1077         renderTime /= totalArea; 
    1078  
    1079         //Debug << "render time without overhead: " << renderTime * 1e-3 << endl; 
    1080         //renderTime += (float)viewCells.size() * vcOverhead; 
    1081  
    1082         return renderTime; 
    1083 } 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h

    r392 r406  
    9999        int PostprocessViewCells(const RayContainer &rays); 
    100100 
    101         /** Simulated rendering using a simple render heuristics. Used to evaluate the  
    102                 quality of the view cell partition. 
    103         */ 
    104         Real SimulateRendering(); 
    105         /** Simulates rendering of the pvs of one view cell, with given rendering time for an object. 
    106                 @param viewCell the view cell holding the Pvs 
    107                 @param objRenderTime estimated render time for one object of the Pvs 
    108         */ 
    109         Real RenderPvs(ViewCell &viewCell, const float objRenderTime) const; 
    110  
     101        // rendering costs for a single object 
     102        float mObjRenderCost; 
     103        // rendering overhead when crossing a view cell border 
     104        float mVcOverhead; 
    111105}; 
    112106 
    113  
    114  
    115107#endif 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r404 r406  
    6767*/ 
    6868float BspTree::sBalancedRaysTable[] = {1, -1, 0, 0, 0}; 
     69 
     70bool BspTree::sPvsUseArea = true; 
    6971 
    7072/****************************************************************/ 
     
    10361038} 
    10371039 
    1038 Plane3 BspTree::SelectPlane(BspLeaf *leaf,  
    1039                                                         BspTraversalData &data) 
     1040Plane3 BspTree::SelectPlane(BspLeaf *leaf, BspTraversalData &data) 
    10401041{ 
    10411042        if (data.mPolygons->empty() && data.mRays->empty()) 
     
    10711072        if (sSplitPlaneStrategy & RANDOM_POLYGON) 
    10721073        { 
    1073                 if (!data.mPolygons->empty()) 
     1074        if (!data.mPolygons->empty()) 
    10741075                { 
    10751076                        Polygon3 *nextPoly = (*data.mPolygons)[Random((int)data.mPolygons->size())]; 
    10761077                        return nextPoly->GetSupportingPlane(); 
    10771078                } 
    1078                  
     1079                else 
     1080                { 
     1081                        const int candidateIdx = Random((int)data.mRays->size()); 
     1082                        BoundedRay *bRay = (*data.mRays)[candidateIdx]; 
     1083 
     1084                        Ray *ray = bRay->mRay; 
     1085                                                 
     1086                        const Vector3 minPt = ray->Extrap(bRay->mMinT); 
     1087                        const Vector3 maxPt = ray->Extrap(bRay->mMaxT); 
     1088 
     1089                        const Vector3 pt = (maxPt + minPt) * 0.5; 
     1090 
     1091                        const Vector3 normal = ray->GetDir(); 
     1092                         
     1093                        return Plane3(normal, pt); 
     1094                } 
     1095 
    10791096                return Plane3(); 
    10801097        } 
     
    10841101} 
    10851102 
    1086 Plane3 BspTree::SelectPlaneHeuristics(BspLeaf *leaf, 
    1087                                                                           BspTraversalData &data) 
     1103Plane3 BspTree::SelectPlaneHeuristics(BspLeaf *leaf, BspTraversalData &data) 
    10881104{ 
    10891105        float lowestCost = MAX_FLOAT; 
    10901106        Plane3 bestPlane; 
    1091          
     1107        Plane3 plane; 
     1108 
    10921109        int limit = Min((int)data.mPolygons->size(), sMaxPolyCandidates); 
    10931110         
     
    10961113        for (int i = 0; i < limit; ++ i) 
    10971114        { 
    1098                 Debug << i << " "; 
    10991115                candidateIdx = GetNextCandidateIdx(candidateIdx, *data.mPolygons); 
    11001116                 
     
    11161132        const BoundedRayContainer *rays = data.mRays; 
    11171133 
    1118         for (int i = 0; i < sMaxRayCandidates; ++ i) 
    1119         { 
    1120                 Plane3 plane; 
    1121  
    1122                 if (0) 
    1123                 { 
    1124                         Vector3 pt[3]; 
    1125                         int idx[3]; 
    1126                         int cmaxT = 0; 
    1127                         int cminT = 0; 
    1128                         bool chooseMin = false; 
    1129  
    1130                         for (int j = 0; j < 3; j ++) 
    1131                         { 
    1132                                 idx[j] = Random((int)rays->size() * 2); 
    1133                                  
    1134                                 if (idx[j] >= (int)rays->size()) 
    1135                                 { 
    1136                                         idx[j] -= (int)rays->size(); 
    1137                                          
    1138                                         chooseMin = (cminT < 2); 
    1139                                 } 
    1140                                 else 
    1141                                         chooseMin = (cmaxT < 2); 
    1142  
    1143                                 BoundedRay *bRay = (*rays)[idx[j]]; 
    1144                                 pt[j] = chooseMin ? bRay->mRay->Extrap(bRay->mMinT) : bRay->mRay->Extrap(bRay->mMaxT); 
    1145                         }        
     1134        for (int i = 0; i < sMaxRayCandidates / 2; ++ i) 
     1135        { 
     1136                candidateIdx = Random((int)rays->size()); 
     1137                BoundedRay *bRay = (*rays)[candidateIdx]; 
     1138 
     1139                Ray *ray = bRay->mRay; 
     1140                                                 
     1141                const Vector3 minPt = ray->Extrap(bRay->mMinT); 
     1142                const Vector3 maxPt = ray->Extrap(bRay->mMaxT); 
     1143 
     1144                const Vector3 pt = (maxPt + minPt) * 0.5; 
     1145 
     1146                const Vector3 normal = ray->GetDir(); 
    11461147                         
    1147                         plane = Plane3(pt[0], pt[1], pt[2]); 
    1148                 } 
    1149                 else 
    1150                 { 
    1151                         candidateIdx = Random((int)rays->size()); 
    1152                         BoundedRay *bRay = (*rays)[candidateIdx]; 
    1153  
    1154                         Ray *ray = bRay->mRay; 
    1155                                                  
    1156                         const Vector3 minPt = ray->Extrap(bRay->mMinT); 
    1157                         const Vector3 maxPt = ray->Extrap(bRay->mMaxT); 
    1158  
    1159                         const Vector3 pt = (maxPt + minPt) * 0.5; 
    1160  
    1161                         const Vector3 normal = ray->GetDir(); 
    1162                          
    1163                         plane = Plane3(normal, pt); 
    1164                 } 
    1165                  
     1148                plane = Plane3(normal, pt); 
     1149         
    11661150                const float candidateCost = SplitPlaneCost(plane, data); 
    11671151 
    11681152                if (candidateCost < lowestCost) 
    11691153                { 
    1170                         Debug << "choose ray plane: " << candidateCost << endl; 
    11711154                        bestPlane = plane; 
    11721155                         
     
    11751158        } 
    11761159 
    1177         Debug << "Plane lowest cost: " << lowestCost << endl; 
     1160        Debug << "lowest: " << lowestCost << endl; 
     1161                 
     1162        for (int i = 0; i < sMaxRayCandidates / 2; ++ i) 
     1163        { 
     1164                Vector3 pt[3]; 
     1165                int idx[3]; 
     1166                int cmaxT = 0; 
     1167                int cminT = 0; 
     1168                bool chooseMin = false; 
     1169 
     1170                for (int j = 0; j < 3; j ++) 
     1171                { 
     1172                        idx[j] = Random((int)rays->size() * 2); 
     1173                                 
     1174                        if (idx[j] >= (int)rays->size()) 
     1175                        { 
     1176                                idx[j] -= (int)rays->size(); 
     1177                                 
     1178                                chooseMin = (cminT < 2); 
     1179                        } 
     1180                        else 
     1181                                chooseMin = (cmaxT < 2); 
     1182 
     1183                        BoundedRay *bRay = (*rays)[idx[j]]; 
     1184                        pt[j] = chooseMin ? bRay->mRay->Extrap(bRay->mMinT) : bRay->mRay->Extrap(bRay->mMaxT); 
     1185                }        
     1186                         
     1187                plane = Plane3(pt[0], pt[1], pt[2]); 
     1188 
     1189                const float candidateCost = SplitPlaneCost(plane, data); 
     1190 
     1191                if (candidateCost < lowestCost) 
     1192                { 
     1193                        Debug << "choose ray plane 2: " << candidateCost << endl; 
     1194                        bestPlane = plane; 
     1195                         
     1196                        lowestCost = candidateCost; 
     1197                } 
     1198        }        
     1199 
     1200        Debug << "plane lowest cost: " << lowestCost << endl; 
    11781201        return bestPlane; 
    11791202} 
     
    13581381                Intersectable::NewMail(); frontAndBackId = ViewCell::sMailId; 
    13591382 
    1360                 if (1) // use front and back cell areas to approximate volume 
     1383                if (sPvsUseArea) // use front and back cell areas to approximate volume 
    13611384                {        
    13621385                        // construct child geometry with regard to the candidate split plane 
     
    13711394                        pOverall = area; 
    13721395                } 
    1373                 else 
    1374                 { 
    1375                         pOverall = (float)rays.size(); 
    1376                 } 
    13771396        } 
    13781397                         
     
    13851404                const float maxT = (*rit)->mMaxT; 
    13861405 
     1406                Vector3 entP, extP; 
     1407 
    13871408                const int cf =  
    1388                         ray->ClassifyPlane(candidatePlane, minT, maxT); 
     1409                        ray->ClassifyPlane(candidatePlane, minT, maxT, entP, extP); 
    13891410 
    13901411                if (sSplitPlaneStrategy & LEAST_RAY_SPLITS) 
     
    14161437                        } 
    14171438 
    1418                         // use #rays to approximate volume 
    1419                         if (0) 
     1439                        if (!sPvsUseArea) // use front and back cell areas to approximate volume 
    14201440                        { 
    1421                                 if ((cf == Ray::BACK) || (cf == Ray::FRONT_BACK) || (cf == Ray::BACK_FRONT)) 
    1422                                         ++ pFront; 
    1423                                 if ((cf == Ray::FRONT) || (cf == Ray::FRONT_BACK) || (cf == Ray::BACK_FRONT)) 
    1424                                         ++ pBack; 
     1441                                float len = Distance(entP, extP); 
     1442                                pOverall += len; 
     1443 
     1444                                // use length of rays to approximate volume 
     1445                                switch (cf) 
     1446                                { 
     1447                                        case Ray::COINCIDENT: 
     1448                                                pBack += len; 
     1449                                                pFront += len;                                           
     1450                                                break; 
     1451                                        case Ray::BACK: 
     1452                                                pBack += len; 
     1453                                                break; 
     1454                                        case Ray::FRONT: 
     1455                                                pFront += len; 
     1456                                                break; 
     1457                                        case Ray::FRONT_BACK: 
     1458                                                { 
     1459                                                        // find intersection of ray segment with plane 
     1460                                                        const Vector3 extp = ray->Extrap(maxT); 
     1461                                                        const float t = candidatePlane.FindT(ray->GetLoc(), extp); 
     1462                                         
     1463                                                        const float newT = t * maxT; 
     1464                                                        float newLen = Distance(ray->Extrap(newT), extp); 
     1465 
     1466                                                        pFront += len - newLen; 
     1467                                                        pBack += newLen; 
     1468                                                } 
     1469                                                break; 
     1470                                        case Ray::BACK_FRONT: 
     1471                                                { 
     1472                                                        // find intersection of ray segment with plane 
     1473                                                        const Vector3 extp = ray->Extrap(maxT); 
     1474                                                        const float t = candidatePlane.FindT(ray->GetLoc(), extp); 
     1475                                         
     1476                                                        const float newT = t * maxT; 
     1477                                                        float newLen = Distance(ray->Extrap(newT), extp); 
     1478 
     1479                                                        pFront += len; 
     1480                                                        pBack += len - newLen; 
     1481                                                } 
     1482                                                break; 
     1483                                        default: 
     1484                                                Debug << "Should not come here" << endl; 
     1485                                                break; 
     1486                                } 
    14251487                        } 
    14261488                } 
     
    14431505        } 
    14441506 
    1445 if ((val < 0.00001) || (frontPvs + backPvs < pvs)) 
    1446 { 
    1447         // create three unique ids for pvs heuristics 
    1448         Intersectable::NewMail(); backId = ViewCell::sMailId; 
    1449         Intersectable::NewMail(); frontId = ViewCell::sMailId; 
    1450         Intersectable::NewMail(); frontAndBackId = ViewCell::sMailId; 
    1451  
    1452  
    1453         BoundedRayContainer::const_iterator rit, rit_end = rays.end(); 
    1454  
    1455         int fpvs = 0; int bpvs = 0; 
    1456         for (rit = rays.begin(); rit != rays.end(); ++ rit) 
    1457         { 
    1458                 Ray *ray = (*rit)->mRay; 
    1459                 const float minT = (*rit)->mMinT; 
    1460                 const float maxT = (*rit)->mMaxT; 
    1461  
    1462                 const int cf =  
    1463                         ray->ClassifyPlane(candidatePlane, minT, maxT); 
    1464  
    1465                 Debug << "classification: " << cf << endl; 
    1466                 if (!ray->intersections.empty()) 
    1467                 { 
    1468                         // in case the ray intersects an objcrs 
    1469                         // assure that we only count a object  
    1470                         // once for the front and once for the back side of the plane 
    1471                         IncPvs(*ray->intersections[0].mObject, fpvs, bpvs,  
    1472                                    cf, frontId, backId, frontAndBackId); 
    1473                 } 
    1474                 // the source object in the origin of the ray 
    1475                 if (ray->sourceObject.mObject) 
    1476                 { 
    1477                         IncPvs(*ray->sourceObject.mObject, fpvs, bpvs,  
    1478                                    cf, frontId, backId, frontAndBackId); 
    1479                 } 
    1480  
    1481         } 
    1482  
     1507        if (0) 
    14831508        Debug << "totalpvs: " << pvs << " ptotal: " << pOverall 
    14841509                  << " frontpvs: " << frontPvs << " pFront: " << pFront  
    14851510                  << " backpvs: " << backPvs << " pBack: " << pBack  
    1486                   << " val " << val << " new size: " << ComputePvsSize(rays) 
    1487                   << " fp " << fpvs << " bp " << bpvs << endl << endl; 
    1488  
    1489 } 
     1511                  << " val " << val << " new size: " << ComputePvsSize(rays)<< endl << endl; 
     1512 
    14901513        return val; 
    14911514} 
     
    20162039                BoundedRay *bRay = rays.back(); 
    20172040                Ray *ray = bRay->mRay; 
     2041                float minT = bRay->mMinT; 
     2042                float maxT = bRay->mMaxT; 
     2043 
    20182044                rays.pop_back(); 
     2045         
     2046                Vector3 entP, extP; 
     2047 
     2048                const int cf =  
     2049                        ray->ClassifyPlane(plane, minT, maxT, entP, extP); 
    20192050                 
    2020                 const int cf =  
    2021                         ray->ClassifyPlane(plane, bRay->mMinT, bRay->mMaxT); 
    2022                  
     2051                // set id to ray classification 
    20232052                ray->SetId(cf); 
    20242053 
    20252054                switch (cf) 
    20262055                { 
    2027                 case Ray::COINCIDENT: 
     2056                case Ray::COINCIDENT: // TODO: should really discard ray? 
    20282057                        //frontRays.push_back(bRay); 
    20292058                        DEL_PTR(bRay); 
     
    20382067                        { 
    20392068                                // find intersection of ray segment with plane 
    2040                                 const Vector3 extp = ray->Extrap(bRay->mMaxT); 
    2041                                 const float t = plane.FindT(ray->GetLoc(), extp); 
     2069                                const float t = plane.FindT(ray->GetLoc(), extP); 
    20422070                                 
    2043                                 const float newT = t * bRay->mMaxT; 
    2044  
    2045                                 frontRays.push_back(new BoundedRay(ray, bRay->mMinT, newT)); 
    2046                                 backRays.push_back(new BoundedRay(ray, newT, bRay->mMaxT)); 
     2071                                const float newT = t * maxT; 
     2072 
     2073                                frontRays.push_back(new BoundedRay(ray, minT, newT)); 
     2074                                backRays.push_back(new BoundedRay(ray, newT, maxT)); 
    20472075 
    20482076                                DEL_PTR(bRay); 
     
    20542082                        { 
    20552083                                // find intersection of ray segment with plane 
    2056                                 const Vector3 extp = ray->Extrap(bRay->mMaxT); 
    2057                                 const float t = plane.FindT(ray->GetLoc(), extp); 
     2084                                const float t = plane.FindT(ray->GetLoc(), extP); 
    20582085                                const float newT = t * bRay->mMaxT; 
    20592086 
     
    24112438        for (int i = 0; i < (int)mPolys.size(); ++ i) 
    24122439        { 
    2413                 const int cf = mPolys[i]->ClassifyPlane(splitPlane, 0.00001); 
     2440                const int cf = mPolys[i]->ClassifyPlane(splitPlane, 0.00001f); 
    24142441                         
    24152442                // split new polygon with all previous planes 
     
    24732500 
    24742501                const int cf =  
    2475                         planePoly->ClassifyPlane(plane, 0.00001); 
     2502                        planePoly->ClassifyPlane(plane, 0.00001f); 
    24762503                         
    24772504                // split new polygon with all previous planes 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h

    r400 r406  
    814814        static int sMinPvs; 
    815815        static int sMaxPvs; 
     816        static bool sPvsUseArea; 
    816817 
    817818private: 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellKd.h

    r405 r406  
    1 #ifndef _KdTree_H__ 
    2 #define _KdTree_H__ 
     1#ifndef _ViewCellKdTree_H__ 
     2#define _ViewCellKdTree_H__ 
    33 
    44#include <functional> 
     
    1111 
    1212   
    13 class KdNode; 
    14 class KdLeaf; 
    15 class KdInterior; 
     13class ViewCellKdNode; 
     14class ViewCellKdLeaf; 
     15class ViewCellKdInterior; 
    1616class Intersectable; 
    1717 
     
    2020// Static statistics for kd-tree search 
    2121// -------------------------------------------------------------- 
    22 class KdTreeStatistics  
     22class ViewCellKdTreeStatistics  
    2323{ 
    2424public:   
     
    5151   
    5252  // Constructor 
    53   KdTreeStatistics() { 
     53  ViewCellKdTreeStatistics() { 
    5454    Reset(); 
    5555  } 
     
    7575  Print(ostream &app) const; 
    7676 
    77   friend ostream &operator<<(ostream &s, const KdTreeStatistics &stat) { 
     77  friend ostream &operator<<(ostream &s, const ViewCellKdTreeStatistics &stat) { 
    7878    stat.Print(s); 
    7979    return s; 
     
    8383 
    8484   
    85 class KdInterior; 
     85class ViewCellKdInterior; 
    8686/** Abstract class for kd-tree node */ 
    87 class KdNode { 
     87class ViewCellKdNode { 
    8888public: 
    8989  static int mailID; 
     
    9595 
    9696 
    97   KdNode(KdInterior *parent); 
     97  ViewCellKdNode(ViewCellKdInterior *parent); 
    9898 
    9999  /** Determines whether this node is a leaf or interior node 
     
    111111  /** Parent of the node - the parent is a little overhead for maintanance of the tree, 
    112112      but allows various optimizations of tree traversal algorithms */ 
    113   KdInterior *mParent; 
     113  ViewCellKdInterior *mParent; 
    114114  int mDepth; 
    115115}; 
    116116 
    117117/** Implementation of the kd-tree interior node */ 
    118 class KdInterior : public KdNode { 
     118class ViewCellKdInterior : public ViewCellKdNode { 
    119119 
    120120public: 
    121121     
    122   KdInterior(KdInterior *parent):KdNode(parent), mBack(NULL), mFront(NULL) {} 
    123  
    124   /** \sa KdNode::IsLeaf() */ 
     122  ViewCellKdInterior(ViewCellKdInterior *parent):ViewCellKdNode(parent), mBack(NULL), mFront(NULL) {} 
     123 
     124  /** \sa ViewCellKdNode::IsLeaf() */ 
    125125  virtual bool IsLeaf() const { return false; } 
    126126 
     
    133133 
    134134  /** back node */ 
    135   KdNode *mBack; 
     135  ViewCellKdNode *mBack; 
    136136  /** front node */ 
    137   KdNode *mFront; 
    138  
    139   void SetupChildLinks(KdNode *b, KdNode *f) { 
     137  ViewCellKdNode *mFront; 
     138 
     139  void SetupChildLinks(ViewCellKdNode *b, ViewCellKdNode *f) { 
    140140    mBack = b; 
    141141    mFront = f; 
     
    143143  } 
    144144   
    145   void ReplaceChildLink(KdNode *oldChild, KdNode *newChild) { 
     145  void ReplaceChildLink(ViewCellKdNode *oldChild, ViewCellKdNode *newChild) { 
    146146    if (mBack == oldChild) 
    147147      mBack = newChild; 
     
    155155   
    156156/** Implementation of the kd-tree leaf node */ 
    157 class KdLeaf : public KdNode { 
     157class ViewCellKdLeaf : public ViewCellKdNode { 
    158158public: 
    159   KdLeaf(KdInterior *parent, const int objects):KdNode(parent) { 
     159  ViewCellKdLeaf(ViewCellKdInterior *parent, const int objects):ViewCellKdNode(parent) { 
    160160    mObjects.reserve(objects); 
    161161  } 
     
    176176  } 
    177177 
    178   /** \sa KdNode::IsLeaf() */ 
     178  /** \sa ViewCellKdNode::IsLeaf() */ 
    179179  virtual bool IsLeaf() const { return true; } 
    180180   
     
    191191  PassingRaySet mPassingRays; 
    192192         
    193   /** PVS consisting of visible KdTree nodes */ 
    194   KdPvs mKdPvs; 
     193  /** PVS consisting of visible ViewCellKd nodes */ 
     194  ViewCellKdPvs mKdPvs; 
    195195         
    196196        /** PVS consisting of visible objects */ 
     
    200200   
    201201 
    202 /** KdTree for indexing scene entities - occluders/occludees/viewcells */ 
    203 class KdTree { 
     202/** ViewCellKd for indexing scene entities - occluders/occludees/viewcells */ 
     203class ViewCellKd { 
    204204 
    205205protected: 
    206206  struct TraversalData 
    207207  {   
    208     KdNode *mNode; 
     208    ViewCellKdNode *mNode; 
    209209    AxisAlignedBox3 mBox; 
    210210    int mDepth; 
     
    213213    TraversalData() {} 
    214214 
    215     TraversalData(KdNode *n, const float p): 
     215    TraversalData(ViewCellKdNode *n, const float p): 
    216216      mNode(n), mPriority(p) 
    217217    {} 
    218218     
    219     TraversalData(KdNode *n, 
     219    TraversalData(ViewCellKdNode *n, 
    220220                   const AxisAlignedBox3 &b, 
    221221                   const int d): 
     
    225225    bool operator<( 
    226226                   const TraversalData &b) const { 
    227       KdLeaf *leafa = (KdLeaf *) mNode; 
    228       KdLeaf *leafb = (KdLeaf *) b.mNode; 
     227      ViewCellKdLeaf *leafa = (ViewCellKdLeaf *) mNode; 
     228      ViewCellKdLeaf *leafb = (ViewCellKdLeaf *) b.mNode; 
    229229      return  
    230230        leafa->mObjects.size()*mBox.SurfaceArea() 
     
    254254        SPLIT_SAH}; 
    255255   
    256   KdTree(); 
     256  ViewCellKd(); 
    257257   
    258258     
     
    274274      were already met 
    275275  */ 
    276   virtual KdNode *Subdivide(const TraversalData &tdata); 
     276  virtual ViewCellKdNode *Subdivide(const TraversalData &tdata); 
    277277 
    278278  /** Get the root of the tree */ 
    279   KdNode *GetRoot() const { 
     279  ViewCellKdNode *GetRoot() const { 
    280280    return mRoot; 
    281281  } 
     
    289289          ); 
    290290 
    291   const KdTreeStatistics &GetStatistics() const { 
     291  const ViewCellKdTreeStatistics &GetStatistics() const { 
    292292    return mStat; 
    293293  } 
    294294 
    295295  void 
    296   CollectObjects(KdNode *n, ObjectContainer &objects); 
     296  CollectObjects(ViewCellKdNode *n, ObjectContainer &objects); 
    297297         
    298298  void 
    299   CollectLeaves(vector<KdLeaf *> &leaves); 
    300          
    301   AxisAlignedBox3 GetBox(const KdNode *node) const { 
    302     KdInterior *parent = node->mParent; 
     299  CollectLeaves(vector<ViewCellKdLeaf *> &leaves); 
     300         
     301  AxisAlignedBox3 GetBox(const ViewCellKdNode *node) const { 
     302    ViewCellKdInterior *parent = node->mParent; 
    303303    if (parent == NULL) 
    304304      return mBox; 
    305305     
    306306    if (!node->IsLeaf()) 
    307       return ((KdInterior *)node)->mBox; 
     307      return ((ViewCellKdInterior *)node)->mBox; 
    308308     
    309309    AxisAlignedBox3 box(parent->mBox); 
     
    315315  } 
    316316         
    317   KdNode * 
    318   FindRandomNeighbor(KdNode *n, 
     317  ViewCellKdNode * 
     318  FindRandomNeighbor(ViewCellKdNode *n, 
    319319                                                                                 bool onlyUnmailed 
    320320                                                                                 ); 
    321321   
    322   KdNode * 
    323   KdTree::GetRandomLeaf(const Plane3 &halfspace); 
    324  
    325         KdNode * 
     322  ViewCellKdNode * 
     323  ViewCellKd::GetRandomLeaf(const Plane3 &halfspace); 
     324 
     325        ViewCellKdNode * 
    326326        GetRandomLeaf(const bool onlyUnmailed = false); 
    327327 
    328328  int 
    329   FindNeighbors(KdNode *n, 
    330                 vector<KdNode *> &neighbors, 
     329  FindNeighbors(ViewCellKdNode *n, 
     330                vector<ViewCellKdNode *> &neighbors, 
    331331                bool onlyUnmailed 
    332332                ); 
     
    419419 
    420420  struct RayTraversalData { 
    421     KdNode *mNode; 
     421    ViewCellKdNode *mNode; 
    422422    Vector3 mExitPoint; 
    423423    float mMaxT; 
    424424     
    425425    RayTraversalData() {} 
    426     RayTraversalData(KdNode *n, 
     426    RayTraversalData(ViewCellKdNode *n, 
    427427                     const Vector3 &p, 
    428428                     const float maxt): 
     
    460460  float 
    461461  BestCostRatio( 
    462                 KdLeaf *node, 
     462                ViewCellKdLeaf *node, 
    463463                const AxisAlignedBox3 &box, 
    464464                const int axis, 
     
    470470  void 
    471471  SortSplitCandidates( 
    472                       KdLeaf *node, 
     472                      ViewCellKdLeaf *node, 
    473473                      const int axis 
    474474                      ); 
     
    477477  EvaluateLeafStats(const TraversalData &data); 
    478478 
    479   KdNode * 
     479  ViewCellKdNode * 
    480480  SubdivideNode( 
    481                 KdLeaf *leaf, 
     481                ViewCellKdLeaf *leaf, 
    482482                const AxisAlignedBox3 &box, 
    483483                AxisAlignedBox3 &backBBox, 
     
    486486 
    487487  bool 
    488   TerminationCriteriaMet(const KdLeaf *leaf); 
     488  TerminationCriteriaMet(const ViewCellKdLeaf *leaf); 
    489489   
    490490  int 
    491   SelectPlane(KdLeaf *leaf, 
     491  SelectPlane(ViewCellKdLeaf *leaf, 
    492492              const AxisAlignedBox3 &box, 
    493493              float &position 
     
    504504  bool mSahUseFaces; 
    505505  /// root of the tree 
    506   KdNode *mRoot; 
     506  ViewCellKdNode *mRoot; 
    507507  /// bounding box of the tree root 
    508508  AxisAlignedBox3 mBox; 
    509   KdTreeStatistics mStat; 
     509  ViewCellKdTreeStatistics mStat; 
    510510   
    511511}; 
    512    
    513  
    514  
    515  
    516  
    517512 
    518513#endif 
Note: See TracChangeset for help on using the changeset viewer.