Changeset 2539


Ignore:
Timestamp:
08/08/07 15:50:33 (17 years ago)
Author:
mattausch
Message:

fixed obj loading error

Location:
GTP/trunk/Lib/Vis
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/src/RandomUpdateCullingManager.cpp

    r2538 r2539  
    106106                                        int nodesTested = 0; 
    107107 
    108                                         // use different algorithm to find random candidates 
    109108#if 1 
     109                                        // test a certain ratio of random candidates 
    110110                                        HierarchyNodeContainer mynodes; 
    111111                                        mHierarchyInterface->CollectLeaves(node, mynodes); 
     
    144144 
    145145#else 
    146                                          
     146                                        // always test one random candidate 
    147147                                        HierarchyNode *leaf = mHierarchyInterface->GetRandomLeaf(node); 
    148148                                         
  • GTP/trunk/Lib/Vis/Preprocessing/scripts/generate_viewcells.env

    r2537 r2539  
    77 
    88        filename ../data/vienna/vienna_cropped.obj 
    9 #       filename ../data/soda/soda.dat 
    10 #       filename ../data/soda/soda5.dat 
    11 #       filename ../data/artificial/cube_test.x3d 
    12 #       filename ../data/CityModel.obj 
    13 #       filename ../data/arena/arena-low-lods.obj 
    149} 
    1510 
     
    2116        loadMeshes false 
    2217         
    23         # internal raycaster 
     18        # internal raycaster: 0, intel: 1 
    2419        rayCastMethod 0   
    25         # intel raycaster 
    26         #rayCastMethod 1 
    2720         
    2821        exportVisibility false 
     
    3225 
    3326 
    34 RssPreprocessor { 
    35         distributions mutation+spatial+object_direction 
    36         #distributions spatial 
    37  
    38  
    39         useImportanceSampling true 
    40  
    41         Export { 
    42                 pvs false 
    43                 rssTree false 
    44         } 
    45  
    46         useViewcells true 
    47         updateSubdivision true 
    48         loadInitialSamples false 
    49         storeInitialSamples false 
    50  
    51         useRssTree true 
    52 } 
    53  
    54  
    55  
    5627VssTree { 
    57         useRss          false 
    58         epsilon         1e-6 
    59          
    6028        maxDepth        2 
    61         minPvs          30 
    62         minRays         800 
    63         minSize         0.001 
    64         maxCostRatio    1.5 
    65         maxRayContribution 0.5 
    66                  
     29         
    6730        maxTotalMemory  50 
    6831        maxStaticMemory 20 
    6932         
    7033        splitType regular 
    71         #       splitType heuristic 
    72         #       splitType hybrid 
    7334        splitUseOnlyDrivingAxis true 
    74          
    75         interleaveDirSplits     true 
    76         dirSplitDepth 0 
    77          
    78         numberOfEndPointDomains 10000 
    79         ct_div_ci       0.0 
    80         randomize       false 
    81          
    82         refDirBoxMaxSize        0.1 
    8335} 
    8436 
     
    8840       small            1e-6 
    8941       infinity         1e9 
    90 } 
    91  
    92  
    93 Unigraphics { 
    94         meshGrouping 1 
    9542} 
    9643 
     
    10754        } 
    10855 
    109 #       splitMethod spatialMedian 
    11056        splitMethod SAH 
    11157        splitBorder 0.01 
     
    12066        } 
    12167 
    122 #       splitMethod spatialMedian 
    12368        splitMethod SAH 
    12469        splitBorder 0.01 
     
    14691        type vspOspTree 
    14792         
    148         #percentage of total visible objects where pvs is considered invalid 
     93        #this ratio of the biggest pvs gives the threshold when a pvs is considered invalid 
    14994        maxPvsRatio 1.0 
    15095                 
     
    175120        } 
    176121 
    177         showVisualization true 
    178         #showVisualization false 
     122        #showVisualization true 
     123        showVisualization false 
    179124        evaluateViewCells false 
    180125         
    181          
     126 
    182127        Evaluation { 
    183128                samples         80000000 
     
    210155        Termination { 
    211156                minPvs 0 
    212                 maxViewCells 500000 
    213         } 
    214  
     157                maxViewCells 4000 
     158        } 
     159 
     160        # heuristics for computing local split planes 
    215161        useCostHeuristics false 
    216         splitUseOnlyDrivingAxis false 
    217162 
    218163        # maximum number of tests per node 
     
    230175        Construction {           
    231176                renderCostDecreaseWeight 0.999 
    232         } 
    233  
    234         Termination { 
    235                 maxLeaves 3000 
     177                #renderCostDecreaseWeight 1.0 
     178        } 
     179 
     180        Termination { 
     181                maxLeaves 4000 
    236182        } 
    237183 
    238184        minRaysForVisibility 3 
    239         #minRaysForVisibility 15 
    240  
    241         useCostHeuristics false 
     185 
     186        # heuristics for computing local split planes 
     187        useCostHeuristics true 
     188        # surface area or visibility based heuristics 
    242189        useSah false 
    243190 
     
    281228        Termination { 
    282229                # maximal number of leaves 
    283                 maxLeaves 30000 
     230                maxLeaves 300000 
    284231                # maximal memory in MB 
    285                 maxMemory 17 
     232                # maxMemory 4 
     233                maxMemory 200 
    286234                # minimum ratio of global cost decrease 
    287235                minGlobalCostRatio -1 
  • GTP/trunk/Lib/Vis/Preprocessing/scripts/generate_viewcells.sh

    r2535 r2539  
    88 
    99PROGRAM=../bin/$TARGET/Preprocessor.exe 
    10 #PROGRAM=../bin/$TARGET/Preprocessor_itl.exe 
     10 
    1111 
    1212EXT=obj 
     
    1515SCENE_PATH=../data/vienna 
    1616 
     17#SCENE=arena-high-lods 
     18#SCENE_PATH=../data/Arena 
     19 
     20 
    1721ENVIRONMENT=generate_viewcells.env 
    18 LOG_PREFIX=../scripts/$SCENE 
     22LOG_PREFIX=$SCENE 
    1923 
    2024echo "starting $TARGET mode for $SCENE scene ($PROGRAM)" 
     
    2226SCENE_FILENAME=$SCENE_PATH/$SCENE.$EXT 
    2327 
    24 OBJ_WEIGHT=20 
    2528 
    2629####################################################### 
     
    2831METHOD=seq 
    2932 
    30 # the # of bvh nodes 
    31 NODES=3000 
     33NODES=4000 
     34VIEWCELLS=4000 
     35#USE_HEUR=true 
     36USE_HEUR=false 
     37OBJ_WEIGHT=20 
    3238 
    3339  
     
    4248 -hierarchy_subdivision_stats=$LOG_PREFIX-$METHOD-hierarchy-subdivisionStats.log \ 
    4349 -hierarchy_construction_type=0 \ 
    44  -vsp_use_cost_heuristics=false \ 
    45  -bvh_term_max_leaves=$NODES 
     50 -view_cells_triangle_weight=1.0 \ 
     51 -view_cells_object_weight=$OBJ_WEIGHT \ 
     52 -vsp_use_cost_heuristics=$USE_HEUR \ 
     53 -bvh_term_max_leaves=$NODES \ 
     54 -vsp_term_max_view_cells=$VIEWCELLS 
    4655 
    4756sh movefiles.sh $LOG_PREFIX-$METHOD 
     57 
  • GTP/trunk/Lib/Vis/Preprocessing/scripts/gi_final.sh

    r2535 r2539  
    88 
    99PROGRAM=../bin/$TARGET/Preprocessor.exe 
    10 #PROGRAM=../bin/$TARGET/Preprocessor_itl.exe 
    1110 
    1211EXT=obj 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp

    r2538 r2539  
    407407                glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId); 
    408408 
    409         int offset = mObjects.size() * 3; 
     409        int offset = (int)mObjects.size() * 3; 
    410410        char *arrayPtr = mUseVbos ? NULL : (char *)mData; 
    411411         
     
    413413        glNormalPointer(GL_FLOAT, 0, (char *)arrayPtr + offset * sizeof(Vector3)); 
    414414         
    415         glDrawArrays(GL_TRIANGLES, 0, mObjects.size() * 3); 
     415        glDrawArrays(GL_TRIANGLES, 0, (int)mObjects.size() * 3); 
    416416        //DisableDrawArrays(); 
    417417} 
     
    16511651                return; 
    16521652 
    1653         unsigned int offset = mObjects.size() * 3; 
     1653        size_t offset = mObjects.size() * 3; 
    16541654        char *arrayPtr = mUseVbos ? NULL : (char *)mData; 
    16551655         
     
    16671667        mIndices = new unsigned int[mObjects.size() * 3]; 
    16681668 
    1669         const int offset = mObjects.size() * 3; 
     1669        size_t offset = mObjects.size() * 3; 
    16701670 
    16711671        for (size_t i = 0; i < mObjects.size(); ++ i) 
     
    17031703        } 
    17041704 
    1705         cout << "\n**************\ndraw arrays created\n" << endl;       
     1705        cout << "\n******** created vertex buffer objects **********" << endl;   
    17061706} 
    17071707 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r2353 r2539  
    17501750 
    17511751 
     1752/** Deletes the ray refs from the all the objects in the container. 
     1753*/ 
    17521754static void RemoveRayRefs(const ObjectContainer &objects) 
    17531755{ 
     
    18261828        else 
    18271829        { 
     1830                // just output boxes of objects 
    18281831                ObjectContainer::const_iterator oit, oit_end = objects.end(); 
    18291832 
     
    18421845 
    18431846 
     1847 
     1848 
     1849///////////////////////// 
     1850 
    18441851class HierarchyNodeWrapper; 
    18451852 
     
    18581865                                           myless<vector<HierarchyNodeWrapper *>::value_type> > HierarchyNodeQueue; 
    18591866 
     1867/** A wrapper for a hierarchy node. This class let's us treat vsp and bvh nodes 
     1868        as if they were inherited from the same class. 
     1869*/ 
    18601870class HierarchyNodeWrapper 
    18611871{ 
     
    18711881 
    18721882 
     1883/** Class wrapping a vsp node. 
     1884*/ 
    18731885class VspNodeWrapper: public HierarchyNodeWrapper 
    18741886{ 
     
    18931905        } 
    18941906 
     1907        ////////// 
     1908 
    18951909        VspNode *mNode; 
    18961910}; 
    18971911 
    18981912 
     1913/** Class wrapping a bvh node. 
     1914*/ 
    18991915class BvhNodeWrapper: public HierarchyNodeWrapper 
    19001916{ 
     
    19181934                } 
    19191935        } 
     1936 
     1937        //////////// 
    19201938 
    19211939        BvhNode *mNode; 
     
    19501968        } 
    19511969 
     1970        ////////// 
     1971 
    19521972        ViewCell *mViewCell; 
    19531973}; 
     1974 
     1975////////////////////////////// 
     1976 
    19541977 
    19551978 
     
    19601983{ 
    19611984        HierarchyNodeQueue tqueue; 
    1962         //tqueue.push(new VspNodeWrapper(mVspTree->GetRoot())); 
     1985 
    19631986        tqueue.push(new ViewCellWrapper(mVspTree->mViewCellsTree->GetRoot())); 
    19641987        tqueue.push(new BvhNodeWrapper(mBvHierarchy->GetRoot())); 
     
    19701993                HierarchyNodeWrapper *nodeWrapper = tqueue.top(); 
    19711994                tqueue.pop(); 
    1972                 //cout << "priority: " << nodeWrapper->GetMergeCost() << endl; 
    1973                 // save the view cells if it is a leaf or if enough view cells have already been traversed 
    1974                 // because of the priority queue, this will be the optimal set of view cells 
     1995 
     1996                // save the view cells if it is a leaf or if enough view cells  
     1997                // have already been traversed because of the priority queue,  
     1998                // this will be the optimal set of view cells 
     1999 
    19752000                if (nodeWrapper->IsLeaf() ||  
    19762001                        ((viewCells.size() + bvhNodes.size() + tqueue.size() + 1) >= maxSplits) || 
     
    25172542} 
    25182543 
    2519  
    2520 } 
     2544} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp

    r2524 r2539  
    1313using namespace std; 
    1414 
    15 // $$JB HACK 
    16 //#define KD_PVS_AREA (1e-4f) 
    1715 
    1816#define TYPE_INTERIOR -2 
     
    3230 
    3331 
    34 KdNode::KdNode(KdInterior *parent):mParent(parent), mMailbox(0), mIntersectable(NULL) 
    35  
    36 { 
    37   if (parent) 
    38     mDepth = parent->mDepth+1; 
    39   else 
    40     mDepth = 0; 
     32KdNode::KdNode(KdInterior *parent): 
     33mParent(parent), mMailbox(0), mIntersectable(NULL) 
     34{ 
     35        if (parent) 
     36                mDepth = parent->mDepth+1; 
     37        else 
     38                mDepth = 0; 
    4139} 
    4240 
     
    5755 
    5856KdTree::KdTree() 
    59 { 
    60  
    61    
     57{  
    6258  mRoot = new KdLeaf(NULL, 0); 
    6359  Environment::GetSingleton()->GetIntValue("KdTree.Termination.maxNodes", mTermMaxNodes); 
     
    194190                 (leaf->mDepth >= mTermMaxDepth); 
    195191  
    196         if (criteriaMet) 
     192        if (0 && criteriaMet) 
    197193                cerr<<"\n OBJECTS="<<(int)leaf->mObjects.size()<<endl; 
    198194 
     
    11321128 
    11331129 
    1134 int 
    1135 KdTree::CastBeam( 
    1136                                  Beam &beam 
    1137                                  ) 
     1130int KdTree::CastBeam(Beam &beam) 
    11381131{ 
    11391132  stack<KdNode *> nodeStack; 
     
    12211214         
    12221215        // read object ids 
    1223         // note: could also do this geometrically 
     1216        // note: this can also be done geometrically 
    12241217        for (int i = 0; i < size; ++ i) 
    12251218        {        
     
    12311224                                                                 
    12321225                if ((oit != objects.end()) && ((*oit)->GetId() == objId)) 
    1233                 { 
    1234                         if (1) leaf->mObjects.push_back(*oit); 
    1235                 } 
     1226                        leaf->mObjects.push_back(*oit); 
    12361227                else 
    1237                 { 
    12381228                        Debug << "error: object with id " << objId << " does not exist" << endl; 
    1239                 } 
    12401229        } 
    12411230 
     
    12611250        KdInterior *interior = new KdInterior(parent); 
    12621251 
    1263         int axis = interior->mAxis; 
    1264         float pos = interior->mPosition; 
     1252        int axis; 
     1253        float pos; 
    12651254 
    12661255        stream.read(reinterpret_cast<char *>(&axis), sizeof(int)); 
     
    13101299 
    13111300 
    1312 KdNode *KdTree::LoadNextNode(IN_STREAM &stream,  
    1313                                                          KdInterior *parent, 
    1314                                                          const ObjectContainer &objects) 
     1301KdNode *KdTree::ImportNextNode(IN_STREAM &stream,  
     1302                                                           KdInterior *parent, 
     1303                                                           const ObjectContainer &objects) 
    13151304{ 
    13161305        int nodeType; 
     
    13181307 
    13191308        if (nodeType == TYPE_LEAF) 
    1320         { 
    13211309                return ImportBinLeaf(stream, static_cast<KdInterior *>(parent), objects); 
    1322         } 
    13231310 
    13241311        if (nodeType == TYPE_INTERIOR) 
    1325         { 
    13261312                return ImportBinInterior(stream, static_cast<KdInterior *>(parent)); 
    1327         } 
    13281313 
    13291314        Debug << "error! loading failed!" << endl; 
    1330          
    13311315        return NULL; 
    13321316} 
    13331317 
    13341318 
    1335 bool KdTree::LoadBinTree(const string &filename, ObjectContainer &objects) 
     1319bool KdTree::ImportBinTree(const string &filename, ObjectContainer &objects) 
    13361320{ 
    13371321        // export binary version of mesh 
     
    13421326 
    13431327        // sort objects by their id 
    1344         sort(objects.begin(), objects.end(), ilt); 
     1328//      if (!is_sorted(objects.begin(), objects.end(), ilt)) 
     1329                sort(objects.begin(), objects.end(), ilt); 
    13451330 
    13461331        mBox.Initialize(); 
     
    13591344        DEL_PTR(mRoot); 
    13601345   
    1361         mRoot = LoadNextNode(stream, NULL, objects); 
     1346        mRoot = ImportNextNode(stream, NULL, objects); 
    13621347 
    13631348        tStack.push(TraversalData(mRoot, mBox, 0)); 
     
    13801365                        interior->mBox = tData.mBox; 
    13811366 
    1382             KdNode *front = LoadNextNode(stream, interior, objects); 
    1383                         KdNode *back = LoadNextNode(stream, interior, objects); 
     1367            KdNode *front = ImportNextNode(stream, interior, objects); 
     1368                        KdNode *back = ImportNextNode(stream, interior, objects); 
    13841369         
    13851370                        interior->SetupChildLinks(back, front); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h

    r2538 r2539  
    417417 
    418418  bool ExportBinTree(const std::string &filename); 
    419  
    420   /// loads kd tree from disk. note: sorts objects by id 
    421   bool LoadBinTree(const std::string &filename, ObjectContainer &object); 
     419  /** loads kd tree from disk. note: sorts objects by id 
     420  */ 
     421  bool ImportBinTree(const std::string &filename, ObjectContainer &object); 
    422422 
    423423protected: 
     
    589589        void ProcessMultipleRefs(KdLeaf *leaf) const; 
    590590 
     591 
     592        ////////// 
     593        // binary import / export 
     594 
    591595        void ExportBinLeaf(OUT_STREAM  &stream, KdLeaf *leaf); 
     596         
    592597        void ExportBinInterior(OUT_STREAM &stream, KdInterior *interior); 
     598 
    593599        KdLeaf *ImportBinLeaf(IN_STREAM &stream, KdInterior *parent, const ObjectContainer &objects); 
     600         
    594601        KdInterior *ImportBinInterior(IN_STREAM  &stream, KdInterior *parent); 
    595         KdNode *LoadNextNode(IN_STREAM  &stream, KdInterior *parent, const ObjectContainer &objects); 
     602         
     603        KdNode *ImportNextNode(IN_STREAM  &stream, KdInterior *parent, const ObjectContainer &objects); 
    596604         
    597605        /** Adds this objects to the kd leaf objects. 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.cpp

    r2307 r2539  
    7979                                                  const int line) 
    8080{ 
     81        vector<char *> substrings; 
     82 
     83        // extract the triples of the form v/t/n v/t/n ... 
    8184        char *pch = strtok(str + 1, " "); 
    82           
     85 
     86        while (pch != NULL) 
     87        { 
     88                substrings.push_back(pch); 
     89                pch = strtok(NULL, " ");           
     90        } 
     91 
     92        //for (int i = 0; i < substrings.size(); ++ i) 
     93        //      cout << "sub: " << substrings[i] << " "; 
     94 
    8395        VertexIndexContainer indices; 
    84         int i = 0; 
    85         while (pch != NULL) 
    86         {++ i; 
    87           const int index = (int)strtol(pch, NULL, 10) - 1; 
    88                                                  
    89           // store vertex in hash table 
    90           //hashTable[index] = vertices[index]; 
    91           if (index >= 0) 
    92                 indices.push_back(index); 
    93                  
    94           pch = strtok(NULL, " "); 
    95            
    96           // problem: don't know how intel ray tracer tesselates 
    97           if ((int)indices.size() > 2) 
     96 
     97        for (int i = 0; i < substrings.size(); ++ i) 
     98        { 
     99                // discard normal and texture indices 
     100                // and only keep first index 
     101         
     102                char *str = strtok(substrings[i], "/");    
     103                const int index = (int)strtol(str, NULL, 10) - 1; 
     104 
     105                // store indices 
     106                if (index >= 0) 
     107                        indices.push_back(index); 
     108 
     109                //cout << "i " << index << " "; 
     110 
     111                // new triangle found 
     112                // problem: don't know how intel ray tracer tesselates 
     113                if ((int)indices.size() > 2) 
    98114                { 
    99                         const int index_2 = (int)indices.size() - 2; 
    100                         const int index_3 = (int)indices.size() - 1; 
     115                        const int idx2 = (int)indices.size() - 2; 
     116                        const int idx3 = (int)indices.size() - 1; 
    101117 
    102118                        triangles.push_back(Triangle3(vertices[indices[0]],  
    103                                                                                   vertices[indices[index_2]],            
    104                                                                                   vertices[indices[index_3]])); 
     119                                                                                  vertices[indices[idx2]],               
     120                                                                                  vertices[indices[idx3]])); 
    105121                } 
    106122        } 
    107         //if (line == 451703) 
    108         //      cout << "t: " << triangles.size() << endl; 
    109123} 
    110124 
     
    230244        while (fgets(str, 100000, file) != NULL) 
    231245        { 
    232           switch (str[0])  
     246                switch (str[0])  
    233247                { 
    234248                case 'v': // vertex  or normal 
    235                   { 
    236                         switch (str[1])  
    237249                        { 
    238                         case 'n' : 
    239                                 // normal do nothing 
     250                                switch (str[1])  
     251                                { 
     252                                case 'n' : 
     253                                        // do nothing for normals 
     254                                        break; 
     255                                case 't': 
     256                                        // do nothing for textures 
     257                                        break; 
     258                                default: 
     259                                        float x, y, z; //cout << "v";    
     260                                        sscanf(str + 1, "%f %f %f", &x, &y, &z); 
     261                                        vertices.push_back(Vector3(x,y,z)); 
     262 
     263                                } 
    240264                                break; 
    241                         default: 
    242                                 float x, y, z; //cout << "v";    
    243                                 sscanf(str + 1, "%f %f %f", &x, &y, &z); 
    244                                 vertices.push_back(Vector3(x,y,z)); 
    245                           
    246265                        } 
    247                         break; 
    248                   } 
    249266                case 'f':  
    250267                        { 
     
    254271 
    255272                                        if (!face) break; 
    256          
     273 
    257274                                        faces.push_back(face); 
    258275 
     
    265282                                { 
    266283                                        ++ line; 
     284 
     285                                        ////////// 
     286                                        // construct the triangles given in the current line 
     287 
    267288                                        vector<Triangle3> triangles; 
    268                                          
    269289                                        LoadTriangles(str, vertices, triangles, line); 
    270290 
     
    273293                                        for (tit = triangles.begin(); tit != tit_end; ++ tit) 
    274294                                        { 
     295                                                // test if it is a valid triangle 
    275296                                                if (0 && !TriangleValid(*tit)) continue; 
    276297 
    277298                                                TriangleIntersectable *obj = new TriangleIntersectable(*tit);    
    278                         root->mGeometry.push_back(obj); 
     299                                                root->mGeometry.push_back(obj); 
    279300                                        } 
    280301                                } 
     
    285306                } 
    286307        } 
    287          
     308 
    288309        //cout << "\n**** " << root->mGeometry.size() << " " << " lines: " << line << endl; 
    289310        if (loadMeshes) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r2452 r2539  
    816816{ 
    817817        mKdTree = new KdTree(); 
    818  
    819         return mKdTree->LoadBinTree(filename.c_str(), mObjects); 
     818        return mKdTree->ImportBinTree(filename.c_str(), mObjects); 
    820819} 
    821820 
     
    11911190        if (rays.size() > 10000) 
    11921191        { 
    1193          
     1192 
    11941193                mRayCaster->SortRays(rays); 
    11951194                cout<<"Rays sorted in "<<TimeDiff(t1, GetTime())<<" ms."<<endl; 
     
    11991198        if (mUseHwGlobalLines)  
    12001199        { 
    1201           CastRaysWithHwGlobalLines( 
    1202                                                                 rays, 
    1203                                                                 vssRays, 
    1204                                                                 castDoubleRays, 
    1205                                                                 pruneInvalidRays 
    1206                                                                 ); 
     1200                CastRaysWithHwGlobalLines( 
     1201                        rays, 
     1202                        vssRays, 
     1203                        castDoubleRays, 
     1204                        pruneInvalidRays 
     1205                        ); 
    12071206        } 
    12081207        else 
    12091208        { 
    1210           mRayCaster->CastRays( 
    1211                                                  rays,                           
    1212                                                  vssRays, 
    1213                                                  mViewCellsManager->GetViewSpaceBox(), 
    1214                                                  castDoubleRays, 
    1215                                                  pruneInvalidRays); 
     1209                mRayCaster->CastRays( 
     1210                        rays,                            
     1211                        vssRays, 
     1212                        mViewCellsManager->GetViewSpaceBox(), 
     1213                        castDoubleRays, 
     1214                        pruneInvalidRays); 
    12161215        } 
    12171216 
     
    12191218        { 
    12201219                cout << endl; 
    1221         long t2 = GetTime(); 
     1220                long t2 = GetTime(); 
    12221221 
    12231222#if SHOW_RAYCAST_TIMING 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp

    r2198 r2539  
    400400 
    401401        for (rit = rays.begin(); rit != rit_end; ++ rit) { 
     402                 
    402403                CastRay( 
    403404                        *rit,                            
  • GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj

    r2530 r2539  
    131131                        ConfigurationType="1" 
    132132                        CharacterSet="2" 
    133                         WholeProgramOptimization="TRUE"> 
     133                        WholeProgramOptimization="FALSE"> 
    134134                        <Tool 
    135135                                Name="VCCLCompilerTool" 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Timer/merror.h

    r2066 r2539  
    249249#define CHKGL _BLBEGIN GLenum error; \ 
    250250        if ( (error = glGetError()) != GL_NO_ERROR) \ 
    251         EOUT("here4 " << gluErrorString(error)); _BLEND; 
     251        EOUT("gl error " << gluErrorString(error)); _BLEND; 
    252252 
    253253#ifdef WIN32 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r2342 r2539  
    1919namespace GtpVisibilityPreprocessor { 
    2020 
     21 
     22#define TYPE_INTERIOR -2 
     23#define TYPE_LEAF -3 
     24 
     25 
     26static inline bool ilt(Intersectable *obj1, Intersectable *obj2) 
     27{ 
     28        return obj1->mId < obj2->mId; 
     29} 
    2130 
    2231 
     
    121130} 
    122131 
     132 
    123133ViewCell::ViewCell(Mesh *mesh):  
    124134MeshInstance(mesh),  
     
    131141mPvsSizeValid(false), 
    132142mFilteredPvsSize(0) 
    133 //mMailbox(0) 
    134143{ 
    135144        mId = -100; 
     
    302311        // erase leaf from old view cell 
    303312        ViewCellContainer::iterator it = mChildren.begin(); 
    304  
    305313        for (; (*it) != prev; ++ it); 
     314 
    306315        if (it == mChildren.end()) 
    307         { 
    308316                Debug << "error: child link not found" << endl; 
    309         } 
    310317        else 
    311         { 
    312318                (*it) = cur; 
    313         } 
    314319} 
    315320 
     
    428433 
    429434        stack<ViewCell *> tstack; 
    430  
    431435        tstack.push(vc); 
    432436 
     
    443447                { 
    444448                        ViewCellInterior *interior = static_cast<ViewCellInterior *>(vc); 
    445  
    446449                        ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
    447450                         
     
    450453                                tstack.push(*it); 
    451454                        } 
    452                          
    453455                } 
    454456        } 
     
    20202022} 
    20212023 
    2022 //#if HAS_TO_BE_REDONE 
     2024 
    20232025int ViewCellsTree::CountStoredPvsEntries(ViewCell *root) const 
    20242026{ 
     
    20292031        { 
    20302032                ViewCellInterior *interior = static_cast<ViewCellInterior *>(root); 
    2031  
    20322033                ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
    20332034 
     
    20402041        return pvsSize;          
    20412042} 
    2042 //#endif 
     2043 
    20432044 
    20442045int ViewCellsTree::ViewCellsStorage() const 
     
    25872588 
    25882589 
    2589 } 
     2590/////////////////// 
     2591// Binary export 
     2592 
     2593void ViewCellsTree::ExportBinInterior(OUT_STREAM &stream, ViewCellInterior *interior) 
     2594{ 
     2595#if TODO 
     2596        int interiorid = TYPE_INTERIOR; 
     2597        stream.write(reinterpret_cast<char *>(&interiorid), sizeof(int)); 
     2598 
     2599        int axis = interior->GetAxis(); 
     2600        float pos = interior->GetPosition(); 
     2601 
     2602        stream.write(reinterpret_cast<char *>(&axis), sizeof(int)); 
     2603        stream.write(reinterpret_cast<char *>(&pos), sizeof(float)); 
     2604#endif 
     2605} 
     2606 
     2607 
     2608void ViewCellsTree::ExportBinLeaf(OUT_STREAM &stream, ViewCell *leaf) 
     2609{ 
     2610#if TODO 
     2611        int type = TYPE_LEAF; 
     2612 
     2613        int id = -1; 
     2614        if (viewCell != mOutOfBoundsCell) 
     2615                id = viewCell->GetId(); 
     2616 
     2617        stream.write(reinterpret_cast<char *>(&type), sizeof(int)); 
     2618        stream.write(reinterpret_cast<char *>(&id), sizeof(int)); 
     2619 
     2620        int pvsSize = viewCell->GetPvs().GetSize(); 
     2621        stream.write(reinterpret_cast<char *>(&pvsSize), sizeof(int)); 
     2622 
     2623        ObjectPvsIterator pit = viewCell->GetPvs().GetIterator(); 
     2624 
     2625        // write PVS of view cell 
     2626        while (pit.HasMoreEntries()) 
     2627        { 
     2628                Intersectable *intersect = pit.Next(); 
     2629                id = intersect->GetId(); 
     2630                stream.write(reinterpret_cast<char *>(&id), sizeof(int)); 
     2631        } 
     2632#endif 
     2633} 
     2634 
     2635 
     2636bool ViewCellsTree::ExportBinary(OUT_STREAM &stream) 
     2637{ 
     2638#if TODO 
     2639        // export binary version of mesh 
     2640        queue<ViewCell *> tStack; 
     2641        tStack.push(mRoot); 
     2642 
     2643        while(!tStack.empty()) 
     2644        { 
     2645                ViewCell *node = tStack.front(); 
     2646                tStack.pop(); 
     2647                 
     2648                if (node->IsLeaf()) 
     2649                { 
     2650                        ExportBinLeaf(stream, static_cast<ViewCellLeaf *>(node)); 
     2651                } 
     2652                else 
     2653                { 
     2654                        VspInterior *interior = static_cast<ViewCellInterior *>(node); 
     2655 
     2656                        ExportBinInterior(stream, interior); 
     2657                         
     2658                        tStack.push(interior->GetFront()); 
     2659                        tStack.push(interior->GetBack()); 
     2660                } 
     2661        } 
     2662#endif 
     2663        return true; 
     2664} 
     2665 
     2666 
     2667////////////////// 
     2668// import binary 
     2669 
     2670ViewCellInterior *ViewCellsTree::ImportBinInterior(IN_STREAM  &stream, ViewCellInterior *parent) 
     2671{ 
     2672        ViewCellInterior *interior = new ViewCellInterior(); 
     2673        return interior; 
     2674} 
     2675 
     2676 
     2677ViewCellLeaf *ViewCellsTree::ImportBinLeaf(IN_STREAM &stream,  
     2678                                                                                   ViewCellInterior *parent, 
     2679                                                                                   const ObjectContainer &pvsObjects) 
     2680{ 
     2681        int leafId = TYPE_LEAF; 
     2682        int objId = leafId; 
     2683        int size; 
     2684 
     2685        stream.read(reinterpret_cast<char *>(&size), sizeof(int)); 
     2686        VspViewCell *leaf = new VspViewCell(); 
     2687 
     2688        MeshInstance dummyInst(NULL); 
     2689         
     2690        // read object ids 
     2691        for (int i = 0; i < size; ++ i) 
     2692        {        
     2693                stream.read(reinterpret_cast<char *>(&objId), sizeof(int)); 
     2694                dummyInst.SetId(objId); 
     2695 
     2696                ObjectContainer::const_iterator oit = 
     2697                        lower_bound(pvsObjects.begin(), pvsObjects.end(), (Intersectable *)&dummyInst, ilt); 
     2698                                                                 
     2699                if ((oit != pvsObjects.end()) && ((*oit)->GetId() == objId)) 
     2700                        leaf->GetPvs().AddSample(*oit, 0); 
     2701                else 
     2702                        Debug << "error: object with id " << objId << " does not exist" << endl; 
     2703        } 
     2704 
     2705        return leaf; 
     2706} 
     2707 
     2708 
     2709ViewCell *ViewCellsTree::ImportNextNode(IN_STREAM &stream,  
     2710                                                                                ViewCellInterior *parent, 
     2711                                                                                const ObjectContainer &objects) 
     2712{ 
     2713        int nodeType; 
     2714        stream.read(reinterpret_cast<char *>(&nodeType), sizeof(int)); 
     2715 
     2716        if (nodeType == TYPE_LEAF) 
     2717                return ImportBinLeaf(stream, static_cast<ViewCellInterior *>(parent), objects); 
     2718 
     2719        if (nodeType == TYPE_INTERIOR) 
     2720                return ImportBinInterior(stream, static_cast<ViewCellInterior *>(parent)); 
     2721 
     2722        Debug << "error! loading failed!" << endl; 
     2723        return NULL; 
     2724} 
     2725 
     2726 
     2727/** Data used for tree traversal 
     2728*/ 
     2729struct MyTraversalData 
     2730 
     2731public: 
     2732 
     2733        MyTraversalData(ViewCell *node, const int depth, const AxisAlignedBox3 &box): 
     2734        mNode(node), mDepth(depth), mBox(box) 
     2735        {} 
     2736 
     2737 
     2738        ////////////////////// 
     2739 
     2740        /// the current node 
     2741        ViewCell *mNode; 
     2742        /// current depth 
     2743        int mDepth; 
     2744        /// the bounding box 
     2745        AxisAlignedBox3 mBox; 
     2746}; 
     2747 
     2748 
     2749bool ViewCellsTree::ImportBinary(IN_STREAM &stream, const ObjectContainer &pvsObjects) 
     2750{ 
     2751        // export binary version of mesh 
     2752        queue<ViewCell *> tStack; 
     2753 
     2754        // hack: we make a new root 
     2755        DEL_PTR(mRoot); 
     2756   
     2757        mRoot = ImportNextNode(stream, NULL, pvsObjects); 
     2758 
     2759        tStack.push(mRoot); 
     2760 
     2761        while(!tStack.empty()) 
     2762        { 
     2763                ViewCell *viewCell = tStack.front(); 
     2764                tStack.pop(); 
     2765 
     2766                if (!viewCell->IsLeaf()) 
     2767                { 
     2768                        ViewCellInterior *interior = static_cast<ViewCellInterior *>(viewCell); 
     2769 
     2770            ViewCell *front = ImportNextNode(stream, interior, pvsObjects); 
     2771                        ViewCell *back = ImportNextNode(stream, interior, pvsObjects); 
     2772         
     2773                        interior->mChildren.push_back(front); 
     2774                        interior->mChildren.push_back(back); 
     2775 
     2776                        tStack.push(front);                      
     2777                        tStack.push(back); 
     2778                } 
     2779                else 
     2780                { 
     2781                        //cout << "l"; 
     2782                } 
     2783        } 
     2784 
     2785        return true; 
     2786} 
     2787 
     2788 
     2789 
     2790} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h

    r2387 r2539  
    547547        */ 
    548548        ViewCell *GetActiveViewCell(ViewCellLeaf *vc) const; 
    549  
    550549        /** Sets the leaves to be the currently active view cells. 
    551550        */ 
    552551    void SetActiveSetToLeaves(); 
    553  
    554552        /** Propagates pvs up the tree to the root and downwards the tree. 
    555553        */ 
    556554        void PropagatePvs(ViewCell *vc); 
    557  
    558555        /** Exports view cells to file. 
    559556        */ 
    560557        bool Export(OUT_STREAM &stream, const bool exportPvs = false); 
    561  
    562558        /** Export statistics of this view cell tree. 
    563559        */ 
    564560        void ExportStats(const std::string &mergeStats); 
    565  
    566561        /** Sets root of hierarchy. 
    567562        */ 
    568563        void SetRoot(ViewCell *root); 
    569  
    570564        /** Assignes unique ids to view cells. 
    571565        */ 
    572566        void CreateUniqueViewCellsIds(); 
    573  
    574567        /** Resets pvs of whole tree. 
    575568        */ 
    576569        void ResetPvs(); 
    577  
    578570        /** Counts pvs of the view cell taking the kd cells into account. 
    579571        */ 
    580572        int CountKdPvs(const ViewCellLeaf *vc) const; 
    581  
    582573        /** Sets pointer to view cells manager. 
    583574        */ 
    584575        void SetViewCellsManager(ViewCellsManager *vcm); 
    585576 
    586         void Update(); 
     577        ViewCellInterior *ImportBinInterior(IN_STREAM  &stream, ViewCellInterior *parent); 
     578 
     579        ViewCellLeaf *ImportBinLeaf(IN_STREAM &stream,  
     580                                        ViewCellInterior *parent, 
     581                                                                const ObjectContainer &pvsObjects); 
     582 
     583        void ExportBinInterior(OUT_STREAM &stream, ViewCellInterior *interior); 
     584 
     585        void ExportBinLeaf(OUT_STREAM &stream, ViewCell *leaf); 
     586 
     587        bool ExportBinary(OUT_STREAM &stream); 
     588         
     589        bool ImportBinary(IN_STREAM &stream, const ObjectContainer &pvsObjects); 
     590 
     591        ViewCell *ImportNextNode(IN_STREAM &stream,  
     592                                                         ViewCellInterior *parent, 
     593                                                         const ObjectContainer &objects); 
    587594 
    588595protected: 
     
    601608        */ 
    602609        float ComputeMergedPvsCost(const ObjectPvs &pvs1, const ObjectPvs &pvs2) const; 
    603  
    604610        /** Returns cost of this leaf according to current heuristics. 
    605611        */ 
    606612        float GetCostHeuristics(ViewCell *vc) const; 
    607  
    608613        /** Returns cost of leaf. 
    609614        */ 
    610615        float GetRenderCost(ViewCell *vc) const; 
    611  
    612616        /** Evaluates the merge cost of this merge candidate pair. 
    613617        */ 
    614618        void EvalMergeCost(MergeCandidate &mc) const; 
    615  
    616619        /** Variance of leaf. 
    617620        */ 
    618621        float GetVariance(ViewCell *vc) const; 
    619  
    620622        /** Standard deviation of leaf. 
    621623        */ 
    622624        float GetDeviation(ViewCell *vc) const; 
    623  
    624625        /** Tries to set this merge candidate to valid.  
    625626                @returns false if both view cells are the same 
    626627        */ 
    627628        bool ValidateMergeCandidate(MergeCandidate &mc) const; 
    628  
    629629        /** Merge view cells of leaves l1 and l2. 
    630630                @returns difference in pvs size 
    631631        */ 
    632632        ViewCellInterior *MergeViewCells(ViewCell *l, ViewCell *r, float &pvsDiff); 
    633  
    634633        /** Shuffles, i.e. takes border leaf from view cell 1 and adds it  
    635634                to view cell 2. 
    636635        */ 
    637636        void ShuffleLeaf(ViewCell *leaf, ViewCellInterior *vc1, ViewCellInterior *vc2) const;    
    638                  
    639637        /** Shuffles the leaves, i.e., tests if exchanging 
    640638                the leaves helps in improving the view cells. 
    641639        */ 
    642640        bool ShuffleLeaves(MergeCandidate &mc) const; 
    643  
    644641        /** Calculates cost for merge of view cell 1 and 2. 
    645642        */ 
     
    647644                                                  ViewCellInterior *vc1,  
    648645                                                  ViewCellInterior *vc2) const; 
    649  
    650646        /** Exports a snapshot of the merged view cells to disc. 
    651647        */ 
     
    653649                                                           const ObjectContainer &objects, 
    654650                                                           const int numNewViewCells); 
    655  
    656651        /** Merge queue must be reset after some time because expected value 
    657652                may not be valid. 
    658653        */ 
    659654        void ResetMergeQueue(); 
    660  
    661655        /** Updates the current cut of view cells. 
    662656                @returns number of newly merged view cells 
    663657        */ 
    664658        int UpdateActiveViewCells(ViewCellContainer &viewCells); 
    665  
    666659        /** Helper function pullling pvs as high up in the tree as possible. 
    667660        */  
    668661        void PullUpVisibility(ViewCellInterior *interior); 
    669  
    670662        /** Compress pvs of view cell and children. 
    671663        */ 
    672664        void CompressViewCellsPvs(ViewCell *root); 
    673  
    674665        /** Returns memory usage of view cells. 
    675666        */ 
    676667        float GetMemUsage() const; 
    677  
    678668        /**     Exports single view cell. 
    679669                NOTE: should be in exporter!! 
    680670        */ 
    681671        void ExportViewCell(ViewCell *viewCell, OUT_STREAM &stream, const bool exportPvs);       
    682  
    683672        /** Exports pvs of a view cell. 
    684673        */ 
    685674        void ExportPvs(ViewCell *viewCell, OUT_STREAM &stream); 
    686  
    687675        /** Counts the logical number of entries in the pvs this view cell. 
    688676                The pvs is assumed to be stored using lossless compression. 
    689677        */ 
    690678        int GetEntriesInPvsForCompressedStorage(ViewCell *vc) const; 
    691  
    692679        /** Computes pvs size of this view cell. 
    693680                The pvs is assumed to be stored using lossless compression. 
    694681        */ 
    695682        float GetPvsCostForCompressedStorage(ViewCell *vc) const; 
    696          
    697683        /** Computes pvs size of this view cell. 
    698684                The pvs is assumed to be stored in the leaves. 
    699685        */ 
    700686        float GetPvsCostForLeafStorage(ViewCell *vc) const; 
    701  
    702687        /** Counts the logical number of entries in the pvs this view cell. 
    703688                The pvs is assumed to be stored using the leaves. 
    704689        */ 
    705690        int GetEntriesInPvsForLeafStorage(ViewCell *vc) const; 
    706  
    707691        /** Update stats for the log. 
    708692        */ 
    709693        void UpdateStats(std::ofstream &stats, 
    710694                                         const ViewCellsTreeStats &vcStats); 
    711  
    712695         
    713696 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r2538 r2539  
    10211021                                                                                                  
    10221022{ 
     1023        // give just an empty container as parameter: 
     1024        // this loading function is used in the engine, thus it 
     1025        // does not need to load the entities the preprocessor works on 
    10231026        ObjectContainer preprocessorObjects; 
    10241027 
     
    10581061        } 
    10591062         
    1060         if (0) 
     1063        if (0) //hack: should work with reset function, but something is wrong .. 
    10611064        { 
    10621065                vm->ResetViewCells(); 
     
    10641067        else 
    10651068        { 
    1066                 //hack: should work with reset function 
    10671069                ViewCellContainer leaves; 
    10681070 
     
    11111113        OUT_STREAM stream(filename.c_str()); 
    11121114 
    1113         // for output we need unique ids for each view cell 
     1115        // we need unique ids for each view cell 
    11141116        CreateUniqueViewCellIds(); 
    11151117 
     
    12871289 
    12881290        ViewCellContainer viewCells; 
     1291 
    12891292#ifdef USE_BIT_PVS 
    12901293        cout << "objects size: " << (int)ObjectPvsIterator::sObjects.size() << endl; 
    12911294        cout << "pvs size: " <<  ObjectPvs::sPvsSize << endl; 
    12921295#endif 
     1296 
    12931297        // $$ JB hack - the collect best viewcells does not work? 
    12941298#if 0 
     
    12971301        viewCells = mViewCells; 
    12981302#endif 
     1303 
    12991304        ViewCellContainer::iterator it = viewCells.begin(), it_end = viewCells.end();            
     1305         
    13001306        for (; it != it_end; ++it)  
    13011307        { 
    1302                 if (1) 
    1303                         (*it)->UpdatePvsCost(); 
    1304                 else 
    1305                         (*it)->SetTrianglesInPvs((float)(*it)->GetFilteredPvsSize()); 
     1308                (*it)->UpdatePvsCost(); 
    13061309        } 
    13071310 
     
    13641367                        ++ smallerSum; 
    13651368                } 
    1366                  
    1367                 //              if (0 && (i < (int)viewCells.size())) 
    1368                 //                Debug << "new pvs cost increase: " << mViewCellsTree->GetTrianglesInPvs(viewCells[i])  
    1369                 //                              << " " << currentPvs << endl; 
    13701369                 
    13711370                const float volRatioDif = volDif / totalVol; 
     
    18431842                                                           const float filterWidth) 
    18441843{ 
    1845   ViewCell *currentViewCell = GetViewCell(viewPoint); 
    1846  
    1847   if (mMaxFilterSize < 1) { 
    1848         prvs.mViewCell = currentViewCell; 
    1849         return; 
    1850   } 
    1851    
    1852   const AxisAlignedBox3 box = GetFilterBBox(viewPoint, filterWidth); 
    1853    
    1854   if (currentViewCell)  
    1855         { 
    1856           ViewCellContainer viewCells; 
    1857           ComputeBoxIntersections(box, viewCells); 
    1858            
    1859           ViewCell *root = ConstructLocalMergeTree2(currentViewCell, viewCells); 
    1860           prvs.mViewCell = root; 
    1861            
     1844        ViewCell *currentViewCell = GetViewCell(viewPoint); 
     1845 
     1846        if (mMaxFilterSize < 1) { 
     1847                prvs.mViewCell = currentViewCell; 
     1848                return; 
     1849        } 
     1850 
     1851        const AxisAlignedBox3 box = GetFilterBBox(viewPoint, filterWidth); 
     1852 
     1853        if (currentViewCell)  
     1854        { 
     1855                ViewCellContainer viewCells; 
     1856                ComputeBoxIntersections(box, viewCells); 
     1857 
     1858                ViewCell *root = ConstructLocalMergeTree2(currentViewCell, viewCells); 
     1859                prvs.mViewCell = root; 
     1860 
    18621861        }  
    1863   else 
    1864         { 
    1865           prvs.mViewCell = NULL; 
    1866           //prvs.mPvs = root->GetPvs(); 
     1862        else 
     1863        { 
     1864                prvs.mViewCell = NULL; 
     1865                //prvs.mPvs = root->GetPvs(); 
    18671866        } 
    18681867} 
     
    40774076 
    40784077        ////////// 
    4079         //-- some view cells for output 
     4078        //-- export visualizations of some view cells 
    40804079 
    40814080        ViewCell::NewMail(); 
     
    41164115                for (vit = leaves.begin(); vit != vit_end; ++ vit) 
    41174116                        {        
    4118                                 // prepare some rays for output 
     4117                                // prepare some rays for visualization 
    41194118                                VssRayContainer::const_iterator rit, rit_end = (*vit)->GetOrCreateRays()->end(); 
    41204119                                for (rit = (*vit)->GetOrCreateRays()->begin(); rit != rit_end; ++ rit) 
     
    41264125                        const int raysOut = min((int)collectRays.size(), maxRays); 
    41274126 
    4128                         // prepare some rays for output 
     4127                        // prepare some rays for visualization 
    41294128                        VssRayContainer::const_iterator rit, rit_end = collectRays.end(); 
    41304129                        for (rit = collectRays.begin(); rit != rit_end; ++ rit) 
     
    43814380        OUT_STREAM stream(filename.c_str()); 
    43824381 
    4383         // for output we need unique ids for each view cell 
     4382        // we need unique ids for each view cell 
    43844383        CreateUniqueViewCellIds(); 
    43854384 
     
    46114610                ViewCell::NewMail(); 
    46124611 
    4613                 //-- some rays for output 
     4612                //-- some rays for visualization 
    46144613                const int raysOut = min((int)sampleRays.size(), mVisualizationSamples); 
    46154614                Debug << "visualization using " << raysOut << " samples" << endl; 
    46164615 
    4617                 //-- some random view cells and rays for output 
     4616                //-- some random view cells and rays for visualization 
    46184617                vector<KdLeaf *> kdLeaves; 
    46194618 
     
    54005399 
    54015400        ////////// 
    5402         //-- some view cells for output 
     5401        //-- export some view cells for visualization 
    54035402 
    54045403        ViewCell::NewMail(); 
     
    54535452                        const int raysOut = min((int)collectRays.size(), maxRays); 
    54545453                 
    5455                         // prepare some rays for output 
     5454                        // prepare some rays for visualization 
    54565455                        VssRayContainer::const_iterator rit, rit_end = collectRays.end(); 
    54575456                        for (rit = collectRays.begin(); rit != rit_end; ++ rit) 
     
    54835482                { 
    54845483                        Intersectable::NewMail(); 
    5485  
    54865484                        ObjectPvsIterator pit = pvs.GetIterator(); 
    54875485 
     
    65856583        OUT_STREAM stream(filename.c_str()); 
    65866584 
    6587         // for output we need unique ids for each view cell 
     6585        // we need unique ids for each view cell 
    65886586        CreateUniqueViewCellIds(); 
    65896587 
     
    66006598                { 
    66016599                        stream << "<BoundingBoxes>" << endl; 
     6600 
     6601                        int id = 0; 
     6602 
    66026603                        vector<KdIntersectable *>::const_iterator kit, kit_end = mPreprocessor->mKdTree->mKdIntersectables.end(); 
    6603  
    6604                         int id = 0; 
    6605  
     6604                         
    66066605                        for (kit = mPreprocessor->mKdTree->mKdIntersectables.begin(); kit != kit_end; ++ kit, ++ id) 
    66076606                        { 
     
    66576656} 
    66586657 
     6658 
     6659bool VspOspViewCellsManager::ExportBinaryViewCells(const string filename,  
     6660                                                                                                   const bool exportPvs,  
     6661                                                                                                   const ObjectContainer &objects) 
     6662{ 
     6663        if (!ViewCellsConstructed() || !ViewCellsTreeConstructed()) 
     6664                return false; 
     6665 
     6666        const long starttime = GetTime(); 
     6667        cout << "exporting view cells to binary format ... "; 
     6668         
     6669        OUT_STREAM stream(filename.c_str()); 
     6670 
     6671        // we need unique ids for each view cell 
     6672        CreateUniqueViewCellIds(); 
     6673 
     6674        int numBoundingBoxes = mPreprocessor->mKdTree->mKdIntersectables.size(); 
     6675        stream.write(reinterpret_cast<char *>(&numBoundingBoxes), sizeof(int)); 
     6676 
     6677 
     6678    /////////////// 
     6679        //-- export bounding boxes 
     6680        //-- we need the boxes to identify objects in the target engine 
     6681 
     6682        vector<KdIntersectable *>::const_iterator kit, kit_end = mPreprocessor->mKdTree->mKdIntersectables.end(); 
     6683 
     6684        int id = 0; 
     6685 
     6686        for (kit = mPreprocessor->mKdTree->mKdIntersectables.begin(); kit != kit_end; ++ kit, ++ id) 
     6687        { 
     6688                Intersectable *obj = (*kit); 
     6689                const AxisAlignedBox3 &box = obj->GetBox(); 
     6690 
     6691                // set kd node id 
     6692                obj->SetId(id); 
     6693                Vector3 bmin = box.Min(); 
     6694                Vector3 bmax = box.Max(); 
     6695 
     6696                stream.write(reinterpret_cast<char *>(&bmin), sizeof(Vector3)); 
     6697                stream.write(reinterpret_cast<char *>(&bmax), sizeof(Vector3)); 
     6698                stream.write(reinterpret_cast<char *>(&id), sizeof(int)); 
     6699        } 
     6700 
     6701 
     6702        /////////////// 
     6703        //-- export the view cells and the pvs 
     6704 
     6705 
     6706        int numViewCells = mCurrentViewCellsStats.viewCells; 
     6707        stream.write(reinterpret_cast<char *>(&numViewCells), sizeof(int)); 
     6708 
     6709        Vector3 vmin = mViewSpaceBox.Min(); 
     6710        Vector3 vmax = mViewSpaceBox.Max(); 
     6711 
     6712        stream.write(reinterpret_cast<char *>(&vmin), sizeof(Vector3)); 
     6713        stream.write(reinterpret_cast<char *>(&vmax), sizeof(Vector3)); 
     6714 
     6715 
     6716        ////////////////////// 
     6717        //-- export the view space hierarchy 
     6718         
     6719        mHierarchyManager->GetVspTree()->ExportBinary(stream); 
     6720         
     6721        stream.close(); 
     6722         
     6723        cout << "finished in " << TimeDiff(starttime, GetTime()) * 1e-3 << " secs" << endl; 
     6724        return true; 
     6725} 
    66596726 
    66606727 
     
    69667033                                ////////// 
    69677034                                // compare results 
    6968  
    69697035                                cout << "ray " << i << ": " << (int)tmpRays[i]->mViewCells.size() << " " << (int)packet.mViewCells[i].size() << endl; 
    69707036                        } 
    6971  
    6972                          
    69737037                         
    69747038                        CLEAR_CONTAINER(tmpRays); 
    69757039                } 
    69767040        } 
    6977 cout << "=================\nhere6"<<endl; 
     7041         
    69787042        CLEAR_CONTAINER(tmpRays); 
    69797043 
     
    69907054 
    69917055 
    6992 } 
     7056 
     7057ViewCellsManager *LoadViewCellsBinary(const string &filename,  
     7058                                                                          ObjectContainer &pvsObjects, 
     7059                                                                          bool finalizeViewCells, 
     7060                                                                          BoundingBoxConverter *bconverter)                                                                                               
     7061{ 
     7062        ViewCellsParser parser; 
     7063        ViewCellsManager *vm = NULL; 
     7064 
     7065        const long startTime = GetTime(); 
     7066        const bool success = false; 
     7067 
     7068        if (!success) 
     7069        { 
     7070                Debug << "Error: loading view cells failed!" << endl; 
     7071                DEL_PTR(vm); 
     7072 
     7073                return NULL; 
     7074        } 
     7075         
     7076        ViewCellContainer leaves; 
     7077 
     7078        vm->mViewCells.clear(); 
     7079        vm->mViewCellsTree->CollectLeaves(vm->mViewCellsTree->GetRoot(), leaves); 
     7080 
     7081        ViewCellContainer::const_iterator it, it_end = leaves.end(); 
     7082 
     7083        for (it = leaves.begin(); it != it_end; ++ it) 
     7084        { 
     7085                vm->mViewCells.push_back(*it); 
     7086        } 
     7087 
     7088        vm->mViewCellsFinished = true; 
     7089        vm->mMaxPvsSize = (int)pvsObjects.size(); 
     7090 
     7091        if (finalizeViewCells) 
     7092        { 
     7093                // create the meshes and compute view cell volumes 
     7094                const bool createMeshes = true; 
     7095                vm->FinalizeViewCells(createMeshes); 
     7096        } 
     7097 
     7098        cout << (int)vm->mViewCells.size() << " view cells loaded in " 
     7099                 << TimeDiff(startTime, GetTime()) * 1e-3f << " secs" << endl; 
     7100 
     7101        Debug << (int)vm->mViewCells.size() << " view cells loaded in " 
     7102                  << TimeDiff(startTime, GetTime()) * 1e-3f << " secs" << endl; 
     7103         
     7104        return vm; 
     7105} 
     7106 
     7107} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r2538 r2539  
    6565        /// root of view cells tree 
    6666        ViewCell *mViewCell; 
    67  
    6867        // input parameter is the render budget for the PrVs 
    6968        float mRenderBudget; 
    70  
    71         // some characteristic values could be stored as well 
    7269}; 
    7370 
     
    142139        */ 
    143140        ViewCellsManager(ViewCellsTree *viewCellsTree); 
    144  
     141        /** Destructor. 
     142        */ 
    145143        virtual ~ViewCellsManager(); 
    146  
    147144        /** Constructs view cells container taking a preprocessor 
    148145                @returns the output rays (if not null) 
     
    178175                                                                                        const bool storeViewCells, 
    179176                                                                                        const bool useHitObject = false); 
    180  
    181177        /** Compute sample contribution only for current view cell. 
    182178        */ 
     
    185181                                                                                        ViewCell *currentViewCell, 
    186182                                                                                        const bool useHitObject = false); 
    187  
    188183        /** Prints out statistics of the view cells. 
    189184        */ 
    190185        virtual void PrintStatistics(std::ostream &s) const; 
    191  
    192186        /** Post processes view cells givemŽa number of rays. 
    193187        */ 
    194188        virtual int PostProcess(const ObjectContainer &objects,  
    195189                                                        const VssRayContainer &rays) = 0; 
    196  
    197190        /** Show visualization of the view cells. 
    198191        */ 
    199192        virtual void Visualize(const ObjectContainer &objects, 
    200193                                                   const VssRayContainer &sampleRays) = 0; 
    201  
    202194        /** collect objects intersecting a given spatial box. 
    203195        */ 
    204196        virtual void CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects); 
    205  
    206197        /** type of the view cell container. 
    207198        */ 
    208199        virtual int GetType() const = 0; 
    209  
    210200        /** Load the input viewcells. The input viewcells should be given as a collection 
    211201                of meshes. Each mesh is assume to form a bounded polyhedron  
     
    217207        */ 
    218208        virtual bool LoadViewCellsGeometry(const string filename, const bool extrudeBaseTriangle); 
    219          
    220209        /** Merges two view cells. 
    221210                @note the piercing rays of the front and back will be ordered    
     
    223212        */ 
    224213        ViewCellInterior *MergeViewCells(ViewCell *front, ViewCell *back) const; 
    225  
    226214        /** Merges a container of view cells. 
    227215                @returns new view cell based on the merging. 
    228216        */ 
    229217        ViewCellInterior *MergeViewCells(ViewCellContainer &children) const; 
    230          
    231218        /** Generates view cell of the type specified by this manager 
    232219        */ 
    233220        virtual ViewCell *GenerateViewCell(Mesh *mesh = NULL) const = 0; 
    234  
    235221        /** Constructs view cell from base triangle.  
    236222                The view cell is extruded along the normal vector. 
     
    239225        */ 
    240226        ViewCell *ExtrudeViewCell(const Triangle3 &baseTri, const float height) const; 
    241  
     227        /** Returns the intersectable that was hit by the ray. 
     228        */ 
    242229        virtual Intersectable *GetIntersectable(const VssRay &ray, const bool isTermination) const; 
    243  
    244230        /** Sets maximal number of samples used for the  
    245231                construction of the view cells. 
    246232        */ 
    247233        void SetVisualizationSamples(const int visSamples); 
    248  
    249234        /** Sets maximal number of samples used for the construction of the view cells. 
    250235        */ 
    251236        void SetConstructionSamples(const int constructionSamples); 
    252  
    253237        /** Sets maximal number of samples used for the visualization of the view cells. 
    254238        */ 
    255239        void SetInitialSamples(const int initialSamples); 
    256  
    257240        /** Sets maximal number of samples used for the post processing of the view cells. 
    258241        */ 
    259242        void SetPostProcessSamples(const int postProcessingSamples); 
    260  
    261243        /** See set. 
    262244        */ 
    263245        int GetVisualizationSamples() const; 
    264  
    265246        /** See set. 
    266247        */ 
    267248        int GetConstructionSamples() const; 
    268  
    269249        /** See set. 
    270250        */ 
    271251        int GetPostProcessSamples() const; 
    272  
    273252        /** Returns true if view cells are already constructed. 
    274253        */ 
    275254        virtual bool ViewCellsConstructed() const = 0; 
    276  
    277255        /** cast line segment to get a list of unique viewcells which are intersected 
    278256                by this line segment  
    279257        */ 
    280258        virtual int CastLineSegment(const Vector3 &origin, 
    281                                                           const Vector3 &termination, 
    282                                                           ViewCellContainer &viewcells 
    283                                                           ) = 0; 
    284  
     259                                                            const Vector3 &termination, 
     260                                                            ViewCellContainer &viewcells) = 0; 
    285261        /** Tests if this line segment intersects a particular view cell. 
    286262        */ 
     
    288264                                                                           const Vector3 &termination, 
    289265                                                                           ViewCell *viewCell) = 0; 
    290  
    291266        /** Returns a stats about the global pvs. 
    292267        */ 
    293268        virtual void GetPvsStatistics(PvsStatistics &stat); 
    294  
     269        /** Returns the probably visible set of the view space filtered pvs. 
     270        */ 
    295271        virtual void GetPrVS(const Vector3 &viewPoint, PrVs &prvs, const float filterWidth); 
    296    
    297272        /** Get a viewcell containing the specified view point. 
    298273                @param active if the active or elementary view cell should be returned. 
    299274        */ 
    300275        virtual ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const = 0; 
    301    
     276        /** Returns the view cell with the given index (different from the id). 
     277        */ 
    302278        ViewCell *GetViewCell(const int idx) const {return mViewCells[idx];} 
    303  
     279        /** Prints the statistics over the view cell pvss. 
     280        */ 
    304281        virtual void PrintPvsStatistics(std::ostream &s); 
    305  
    306282        /** Updates pvs of the view cell hierarchy if necessary. 
    307283        */ 
    308284        void UpdatePvs(); 
    309  
    310285        /** Returns probability that view point lies in one view cell. 
    311286        */ 
    312287        virtual float GetProbability(ViewCell *viewCell) = 0; 
    313  
    314288        /** Returns render cost of a single view cell given the render cost of an object. 
    315289        */ 
    316290        float GetRendercost(ViewCell *viewCell) const; 
    317  
    318291        /** Returns reference to container of loaded / generated view cells. 
    319292        */ 
    320293        ViewCellContainer &GetViewCells(); 
    321  
    322294        /** Helper function used to split ray sets uniformly  
    323295                into one that is currently used and the other that  
     
    332304                                        VssRayContainer &usedRays,  
    333305                                        VssRayContainer *savedRays = NULL) const; 
    334          
    335306        /** Returns accumulated area of all view cells. 
    336307        */ 
    337308        float GetAccVcArea(); 
    338  
    339309        /** Returns area of one view cell. 
    340310        */ 
    341311        virtual float GetArea(ViewCell *viewCell) const; 
    342  
    343312        /** Returns volume of view cell. 
    344313        */ 
    345314        virtual float GetVolume(ViewCell *viewCell) const; 
    346  
    347315        /** Sets the current renderer mainly for view cells statistics. 
    348316        */ 
    349317        void SetRenderer(Renderer *renderer); 
    350  
    351318        /** Computes a (random) view point in the valid view space. 
    352319                @returns true if valid view point was found 
    353320        */ 
    354321        virtual bool GetViewPoint(Vector3 &viewPoint) const; 
    355    
     322        /** Returns the current view point given a vector for activating the halton sequence. 
     323        */ 
    356324        virtual bool GetViewPoint(Vector3 &viewPoint, const Vector3 &params) const; 
    357  
    358325        /** Returns true if this view point is in the valid view space. 
    359326        */ 
    360327        virtual bool ViewPointValid(const Vector3 &viewPoint) const; 
    361  
    362328        /** Sets a view space boundary. 
    363329        */ 
    364330        void SetViewSpaceBox(const AxisAlignedBox3 &box); 
    365  
     331        /** Returns the boundaries of the view space. 
     332        */ 
    366333        AxisAlignedBox3 GetViewSpaceBox() const; 
    367  
    368334        /** Creates mesh for this view cell. 
    369335        */ 
    370336        virtual void CreateMesh(ViewCell *vc) = NULL; 
    371  
    372337        /** Writes view cells to disc. 
    373338        */ 
     
    375340                                                                 const bool exportPvs,  
    376341                                                                 const ObjectContainer &objects); 
    377  
    378342        /** Casts beam to collect view cells. 
    379343        */ 
    380344        virtual int CastBeam(Beam &beam); 
    381  
    382345        /** Checks if view cell is considered as valid. 
    383346        */ 
     
    385348                                                           int minPvsSize,  
    386349                                                           int maxPvsSize) const; 
    387  
    388  
    389         // resort pvss after a pass of the algorithm 
     350        /** Resort pvss after a pass of the algorithm. 
     351        */ 
    390352        void  SortViewCellPvs(); 
    391  
    392         // map the ray intersection objects from triangles to high level objects... 
     353        /** Map the ray intersection objects from triangles to high level objects. 
     354        */ 
    393355        void DeterminePvsObjects(VssRayContainer &rays, 
    394356                                                         const bool useHitObjects = false); 
    395          
    396357        /** Sets validity of view cell 
    397358        */ 
     
    399360                                                         int minPvsSize,  
    400361                                                         int maxPvsSize) const; 
    401  
    402362        /** sets validy of all viewcells  
    403363        */ 
    404         virtual void SetValidity(int minPvsSize,  
    405                                                          int maxPvsSize) const; 
    406  
    407  
     364        virtual void SetValidity(int minPvsSize, int maxPvsSize) const; 
    408365        /** Set valid viewcells in the range of pvs. sorts the viewcells 
    409366                according to the pvs and then pickups those in the ranges  
    410367        */ 
    411368        void SetValidityPercentage(const float minValid, const float maxValid); 
    412  
    413369        /** Returns number of valid view cells. 
    414370        */ 
    415371    int CountValidViewcells() const; 
    416  
    417372        /** Returns maximal allowed pvs size. 
    418373        */ 
    419374        int GetMaxPvsSize() const; 
    420  
    421375        /** Returns maximal allowed pvs size. 
    422376        */ 
    423377        int GetMinPvsSize() const; 
    424  
    425378        /** Returns maximal ratio. i.e., currentPVs / maxPvs, 
    426379                where pvs is still considered valid. 
    427380        */ 
    428381        float GetMaxPvsRatio() const; 
    429  
    430382        /** Exports view cell geometry. 
    431383        */ 
     
    435387                                                                                const AxisAlignedPlane *clipPlane = NULL 
    436388                                                                                ) const = 0; 
    437  
    438389        /** Brings the view cells into their final state, computes meshes and volume. 
    439390        */ 
    440391        virtual void FinalizeViewCells(const bool createMesh); 
    441  
    442392        /** Evaluates statistics values on view cells. 
    443393        */ 
     
    448398                                                                  float &totalPvs, 
    449399                                                                  float &avgRenderCost); 
    450  
    451400        /** Returns hierarchy of the view cells. 
    452401        */ 
    453402        ViewCellsTree *GetViewCellsTree(); 
    454  
    455403        /** Collect candidates for the view cell merge. 
    456404        */ 
    457405        virtual void CollectMergeCandidates(const VssRayContainer &rays,  
    458406                                                                                vector<MergeCandidate> &candidates); 
    459  
    460407        /** Collects n view cells and stores it as the active view cells. 
    461408        */ 
    462409        void CollectViewCells(const int n); 
    463  
    464410        /** Sets current view cells set to active,  
    465411                i.e., the sampling is done in this view cell set. 
    466412        */ 
    467413        void SetViewCellsActive(); 
    468  
    469414        /** Evaluates render cost statistics of current view cell hierarchy. 
    470415        */ 
    471416        virtual void EvalViewCellPartition(); 
    472  
    473417        /** Sets maximal size of a view cell filter. 
    474418        */ 
    475419        void SetMaxFilterSize(const int size); 
    476  
    477420        /** Returns maximal filter size. 
    478421        */ 
    479422        int GetMaxFilterSize() const; 
    480  
    481423        /** Deletes interior nodes from the tree which have negative  
    482424                merge cost set (local merge). 
    483425        */   
    484426        void DeleteLocalMergeTree(ViewCell *vc) const; 
    485    
    486427        /** Evaluautes histogram for a given number of view cells. 
    487428        */ 
    488429        void EvalViewCellHistogram(const string filename, const int nViewCells); 
    489  
    490430        /** Evaluautes histogram for a given number of view cells. 
    491431        */ 
    492432        void EvalViewCellHistogramForPvsSize(const string filename,  
    493433                                                                                 const int nViewCells); 
    494  
     434        /** Evaluautes histogram for a given vector of view cells. 
     435        */ 
    495436        void EvalViewCellHistogramForPvsSize(const string filename,  
    496437                                                                                 ViewCellContainer &viewCells); 
    497  
    498438        float ComputeRenderCost(const int tri, const int obj); //const 
    499  
    500439        /** Sets pvs size of view cell as a scalar. Used when storing pvs only in the leaves 
    501440                of the hierarchy. 
     
    504443                                                         const float pvsCost,  
    505444                                                         const int entriesInPvs) const; 
    506  
    507445        /** Returns bounding box of a view cell. 
    508446        */ 
    509447        AxisAlignedBox3 GetViewCellBox(ViewCell *vc); 
    510  
    511448        /** Exports bounding boxes of objects to file. 
    512449        */ 
    513450        bool ExportBoundingBoxes(const string filename,  
    514451                                                         const ObjectContainer &objects) const; 
    515      
    516452        /** Load the bounding boxes into the container. 
    517453        */ 
    518454        bool LoadBoundingBoxes(const string filename,  
    519455                                                  IndexedBoundingBoxContainer &boxes) const; 
    520  
    521456        /** Returns true if pvs should be exported together with the view cells. 
    522457        */ 
    523458        bool GetExportPvs() const; 
    524  
    525459        /** Efficiently merges the view cells in the container. 
    526460        */ 
    527461        void MergeViewCellsRecursivly(ObjectPvs &pvs,  
    528462                                                                  const ViewCellContainer &viewCells) const; 
    529  
    530         /** Compress the view cells. 
     463        /** Compresses the view cells. 
    531464        */ 
    532465        virtual void CompressViewCells(); 
    533  
     466        /** Returns view cell with the given id. 
     467        */ 
    534468        ViewCell *GetViewCellById(const int id); 
    535  
    536469        /** Returns number of view cells. 
    537470        */ 
     
    620553 
    621554        float GetAbsFilterWidth(); 
    622  
    623555        /** Returns the bounding box of filter width. 
    624556        */ 
     
    688620                                                                  const int leftIdx,  
    689621                                                                  const int rightIdx) const; 
    690  
    691622        /** Intersects box with the tree and returns the number of intersected boxes. 
    692         @returns number of view cells found 
     623                @returns number of view cells found 
    693624        */ 
    694625        virtual int ComputeBoxIntersections(const AxisAlignedBox3 &box,  
    695626                                                                                ViewCellContainer &viewCells) const; 
    696  
    697627        /** Tests the visibility filter functionality. 
    698628        */ 
    699629        virtual void TestFilter(const ObjectContainer &objects) {}; 
    700  
    701630        /** If the view cells tree was already constructed or not. 
    702631        */ 
    703632        bool ViewCellsTreeConstructed() const; 
    704  
    705633        /** Requests preprocessor to cast samplesPerPass samples of a specific type. 
    706634        */ 
     
    711639        int CastEvaluationSamples(const int samplesPerPass,  
    712640                                                          VssRayContainer &passSamples);// const; 
    713  
    714641        /** Parse the options from the environment file. 
    715642        */ 
    716643        void ParseEnvironment(); 
    717  
    718644        /** Creates unique view cell ids. 
    719645        */ 
    720646        void CreateUniqueViewCellIds(); 
    721  
    722647        /** Finalizes, i.e., creates mesh, volume, area etc. for the view cell. 
    723648        */ 
    724649        virtual void Finalize(ViewCell *viewCell, const bool createMesh); 
    725  
    726650        /** Recollects view cells and resets statistics. 
    727651        */ 
    728652        void ResetViewCells(); 
    729  
    730653        /** Sets this view cell to active. 
    731654        */ 
    732655        void SetViewCellActive(ViewCell *vc) const; 
    733  
    734656        /** Collects the view cells in the view cell container. 
    735657        */ 
    736658        virtual void CollectViewCells() = 0; 
    737  
    738         /** Evaluates view cells statistics and stores it in 
    739         mViewCellsStatistics. 
     659        /** Evaluates view cells statistics and stores it in mViewCellsStatistics. 
    740660        */ 
    741661        void EvaluateViewCellsStats(); 
     
    751671                                                           const bool colorCode, 
    752672                                                           const AxisAlignedPlane *clipPlane) const; 
    753  
    754673        /** Sets exporter color. 
    755674        */ 
     
    757676                                                         ViewCell *vc,  
    758677                                                         const int colorCode) const; 
    759  
    760678        /** Creates meshes from the view cells. 
    761679        */ 
    762680        void CreateViewCellMeshes(); 
    763  
    764681        /** Creates clip plane for visualization. 
    765682        */ 
     
    776693        */ 
    777694        virtual float GetViewSpaceVolume(); 
    778  
    779695        /** Prepares the view cells for sampling after loading them from disc. 
    780696        */ 
    781697        virtual void PrepareLoadedViewCells() {}; 
    782          
    783698        /** Constructs local view cell merge hierarchy. 
    784699        */ 
    785700        ViewCell *ConstructLocalMergeTree(ViewCell *currentViewCell,  
    786                 const ViewCellContainer &viewCells); 
    787  
     701                                          const ViewCellContainer &viewCells); 
    788702        /** Constructs local view cell merge hierarchy based solely on similarity with the 
    789703                current viewcell 
     
    791705        ViewCell *ConstructLocalMergeTree2(ViewCell *currentViewCell,  
    792706                                                                           const ViewCellContainer &viewCells); 
    793    
    794707        /** Updates pvs of all view cells for statistical evaluation after some more sampling 
    795708        */ 
     
    797710 
    798711        virtual void ExportStats(const string &mergeStats); 
     712 
     713        friend ViewCellsManager *LoadViewCellsBinary(const string &filename,  
     714                                                                                                 ObjectContainer &pvsObjects, 
     715                                                                                                 bool finalizeViewCells, 
     716                                                 BoundingBoxConverter *bconverter); 
    799717 
    800718 
     
    804722        ofstream mStats; 
    805723        Preprocessor *mPreprocessor; 
    806          
    807724        /// if bounding boxes should be exported together with the view cells 
    808725        bool mExportBboxesForPvs; 
    809          
    810726        /// the clip plane for visualization 
    811727        AxisAlignedPlane mClipPlaneForViz; 
    812          
    813728        /// if the visualization is using the clip plane 
    814729        bool mUseClipPlaneForViz; 
    815          
    816730        /// Renders the view cells. 
    817731        Renderer *mRenderer; 
    818          
    819732        /// Loaded view cells 
    820733        ViewCellContainer mViewCells; 
    821          
    822734        /// the view cell hierarchy (i.e., the logical description of view cells) 
    823735        ViewCellsTree *mViewCellsTree; 
     
    998910        */ 
    999911        ViewCell *ConstructDummyMergeTree(BspNode *root); 
    1000  
    1001912        /** Exports visualization of the BSP splits. 
    1002913        */ 
    1003914        void ExportSplits(const ObjectContainer &objects); 
    1004  
    1005915        /** test if subdivision is valid in terms of volume / area. 
    1006916        */ 
     
    12461156        ViewCell *GenerateViewCell(Mesh *mesh = NULL) const; 
    12471157 
    1248         virtual Intersectable *GetIntersectable( 
    1249                 const VssRay &ray, const bool isTermination) const; 
     1158        virtual Intersectable *GetIntersectable(const VssRay &ray,  
     1159                                                                                        const bool isTermination) const; 
    12501160 
    12511161        bool ViewCellsConstructed() const; 
    12521162 
    1253          
    12541163        int CastLineSegment(const Vector3 &origin, 
    12551164                                                const Vector3 &termination, 
     
    12881197                                                           VssRayContainer *visRays = NULL); 
    12891198         
    1290         float UpdateObjectCosts(); 
    1291  
     1199        ; 
     1200        /** See parent class. 
     1201        */ 
    12921202        virtual void FinalizeViewCells(const bool createMesh); 
     1203 
     1204        bool ExportBinaryViewCells(const string filename,  
     1205                                                           const bool exportPvs,  
     1206                                                           const ObjectContainer &objects); 
    12931207 
    12941208#if TEST_PACKETS 
     
    13001214#endif 
    13011215 
     1216 
    13021217protected: 
    13031218 
     1219        /** View cells manager taking a view cells tree and a hierarchy as input. 
     1220        */ 
    13041221        VspOspViewCellsManager(ViewCellsTree *vcTree, HierarchyManager *hm); 
    13051222         
    13061223        virtual void EvalViewCellPartition(); 
    1307  
    13081224        /** Exports view cell geometry. 
    13091225        */ 
     
    13341250        */ 
    13351251        virtual void CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects); 
    1336  
     1252        /** Update the cost of pvss for hierarchy objects. 
     1253        */ 
     1254        float UpdateObjectCosts(); 
     1255 
     1256 
     1257        //////////////// 
     1258 
     1259        /** Fast view cell loader in binary mode. 
     1260        */ 
     1261        friend ViewCellsManager *LoadViewCellsBinary(const string &filename,  
     1262                                                                                                 ObjectContainer &pvsObjects, 
     1263                                                                                                 bool finalizeViewCells, 
     1264                                                                                                 BoundingBoxConverter *bconverter); 
     1265 
     1266        /** Print statistics about the view cells compression. 
     1267        */ 
    13371268        static void PrintCompressionStats(HierarchyManager *hm, const int pvsEntries); 
    13381269 
     
    13401271        //////////////////// 
    13411272 
     1273        /// if we should compress the objects after view cell evaluation: this makes 
     1274        /// only sense for testing purpose 
    13421275        bool mCompressObjects; 
    1343  
     1276        /// pointer to the hierarchy manager responsible for view space / object space subdivision. 
    13441277        HierarchyManager *mHierarchyManager; 
    13451278}; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp

    r2332 r2539  
    122122        //Debug<<"\nhsize: " << mHashPvs.size() << endl; 
    123123} 
    124 /* 
    125 void ViewCellsParseHandlers::CreateHashVector2() 
    126 { 
    127         ObjectContainer::const_iterator oit, oit_end = mPvsObjects.end(); 
    128  
    129         for (oit = mPvsObjects.begin(); oit != oit_end; ++ oit) 
    130         { 
    131                 mHashPvs[(*oit)->GetId()] = (*oit); 
    132         } 
    133         Debug<<"\nhsize: " << mHashPvs.size() << endl; 
    134 } 
    135 */ 
     124 
     125 
    136126// --------------------------------------------------------------------------- 
    137127//  StdInParseHandlers: Implementation of the SAX DocumentHandler interface 
     
    324314        { 
    325315                sort(mPvsObjects.begin(), mPvsObjects.end(), ilt); 
    326  
    327                 /*ObjectContainer::const_iterator oit, oit_end = mPvsObjects.end(); 
    328          
    329                 int id = 0; 
    330                 for (oit = mPvsObjects.begin(); oit != oit_end; ++ oit, ++ id) 
    331                 { 
    332                         if ((*oit)->GetId() != id) 
    333                                 Debug << "error" << endl; 
    334                 }*/ 
    335316        } 
    336317 
     
    540521void ViewCellsParseHandlers::StartViewCellPvs(ObjectPvs &pvs, const char *ptr) 
    541522{ 
    542         // handle obect indices 
     523        // handle object indices 
    543524        vector<int> objIndices; 
    544525        char *endptr; 
    545526                         
    546527        while (1) 
    547         {       // read object ids 
     528        {        
     529                // read object ids 
    548530                const int index = strtol(ptr, &endptr, 10); 
     531                 
    549532                if (ptr == endptr)  
    550533                        break; 
     534                 
    551535                objIndices.push_back(index); 
    552536                ptr = endptr; 
    553537        } 
    554538 
     539        mPvsTimer.Entry(); 
     540 
    555541        Intersectable::NewMail(); 
    556  
    557         mPvsTimer.Entry(); 
    558542 
    559543        // TODO:  
     
    561545        // 2) get view cell with specified id 
    562546        MeshInstance dummyInst(NULL); 
     547        pair<ObjectContainer::const_iterator, ObjectContainer::const_iterator> result; 
    563548 
    564549        vector<int>::const_iterator it, it_end = objIndices.end(); 
    565550         
    566         pair<ObjectContainer::const_iterator, ObjectContainer::const_iterator> result; 
    567  
    568551        for (it = objIndices.begin(); it != it_end; ++ it) 
    569552        { 
     
    578561                } 
    579562#else 
    580 #if 0 
     563        #if 0 
    581564                dummyInst.SetId(objId); 
    582565 
     
    584567                                                        lower_bound(mPvsObjects.begin(),  
    585568                                                                                mPvsObjects.end(),  
    586                                                                                 (Intersectable *)&dummyInst, ilt);       
     569                                                                                (Intersectable *)&dummyInst,  
     570                                                                                ilt);    
    587571 
    588572                if ((oit != mPvsObjects.end()) && ((*oit)->GetId() == objId)) 
     
    590574                        pvs.AddSample(*oit, 1.0f); 
    591575                } 
    592 #else 
     576        #else 
    593577                pvs.AddSample(mPvsObjects[objId], 1.0f); 
    594 #endif 
     578        #endif 
    595579#endif 
    596580        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp

    r2529 r2539  
    3232 
    3333 
     34#define TYPE_INTERIOR -2 
     35#define TYPE_LEAF -3 
     36 
     37 
    3438///////////// 
    3539//-- static members 
     
    114118} 
    115119 
     120 
     121 
     122VspTree::VspTraversalData::VspTraversalData(): 
     123mNode(NULL), 
     124mDepth(0), 
     125mRays(NULL), 
     126mPvs(0), 
     127mProbability(0.0), 
     128mMaxCostMisses(0),  
     129mPriority(0), 
     130mCorrectedPvs(0) 
     131{} 
     132 
     133 
     134VspTree::VspTraversalData::VspTraversalData(VspLeaf *node,  
     135                                                                                        const int depth,  
     136                                                                                        RayInfoContainer *rays, 
     137                                                                                        const float pvs, 
     138                                                                                        const float p, 
     139                                                                                        const AxisAlignedBox3 &box): 
     140mNode(node),  
     141mDepth(depth),  
     142mRays(rays), 
     143mProbability(p), 
     144mBoundingBox(box), 
     145mMaxCostMisses(0), 
     146mPriority(0), 
     147mCorrectedPvs(0), 
     148mPvs(pvs), 
     149mRenderCost(0), 
     150mCorrectedRenderCost(0) 
     151{} 
     152 
     153 
     154float VspTree::VspTraversalData::GetAvgRayContribution() const 
     155{ 
     156        return (float)mPvs / ((float)mRays->size() + Limits::Small); 
     157} 
     158 
     159 
     160float VspTree::VspTraversalData::GetAvgRaysPerObject() const 
     161{ 
     162        return (float)mRays->size() / ((float)mPvs + Limits::Small); 
     163} 
     164 
     165         
     166float VspTree::VspTraversalData::GetCost() const  
     167{ 
     168        return mPriority;  
     169} 
     170         
     171 
     172void VspTree::VspTraversalData::Clear() 
     173{ 
     174        DEL_PTR(mRays); 
     175 
     176        if (mNode) 
     177        {       // delete old view cell 
     178                delete mNode->GetViewCell(); 
     179                delete mNode; 
     180                mNode = NULL; 
     181        } 
     182} 
    116183 
    117184 
     
    31593226 
    31603227 
    3161 void VspTree::CollectDirtyCandidate(const VssRay &ray,  
    3162                                                                         const bool isTermination, 
    3163                                                                         vector<SubdivisionCandidate *> &dirtyList, 
    3164                                                                         const bool onlyUnmailed) const 
    3165 { 
    3166          
     3228void VspTree::AddCandidateToDirtyList(const VssRay &ray,  
     3229                                                                const bool isTermination, 
     3230                                                                vector<SubdivisionCandidate *> &dirtyList, 
     3231                                                                const bool onlyUnmailed) const 
     3232 
     3233{ 
    31673234#if HACK_PERFORMANCE 
    31683235 
     
    31723239 
    31733240        BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj); 
    3174  
    31753241        SubdivisionCandidate *candidate; 
    31763242 
     
    32543320                VssRay *ray = (*rit).mRay; 
    32553321                 
    3256                 CollectDirtyCandidate(*ray, true, dirtyList, onlyUnmailed); 
     3322                AddCandidateToDirtyList(*ray, true, dirtyList, onlyUnmailed); 
    32573323 
    32583324#if COUNT_ORIGIN_OBJECTS 
    3259         CollectDirtyCandidate(*ray, false, dirtyList, onlyUnmailed); 
     3325        AddCandidateToDirtyList(*ray, false, dirtyList, onlyUnmailed); 
    32603326#endif 
    32613327        } 
     
    37883854 
    37893855 
    3790  
    3791  
    3792 } 
     3856////////// 
     3857// Binary export 
     3858 
     3859void VspTree::ExportBinInterior(OUT_STREAM &stream, VspInterior *interior) 
     3860{ 
     3861        int interiorid = TYPE_INTERIOR; 
     3862        stream.write(reinterpret_cast<char *>(&interiorid), sizeof(int)); 
     3863 
     3864        int axis = interior->GetAxis(); 
     3865        float pos = interior->GetPosition(); 
     3866 
     3867        stream.write(reinterpret_cast<char *>(&axis), sizeof(int)); 
     3868        stream.write(reinterpret_cast<char *>(&pos), sizeof(float)); 
     3869} 
     3870 
     3871 
     3872void VspTree::ExportBinLeaf(OUT_STREAM &stream, VspLeaf *leaf) 
     3873{ 
     3874        ViewCell *viewCell = mViewCellsTree->GetActiveViewCell(leaf->GetViewCell()); 
     3875 
     3876        int type = TYPE_LEAF; 
     3877 
     3878        int id = -1; 
     3879        if (viewCell != mOutOfBoundsCell) 
     3880                id = viewCell->GetId(); 
     3881 
     3882        stream.write(reinterpret_cast<char *>(&type), sizeof(int)); 
     3883        stream.write(reinterpret_cast<char *>(&id), sizeof(int)); 
     3884 
     3885        int pvsSize = viewCell->GetPvs().GetSize(); 
     3886        stream.write(reinterpret_cast<char *>(&pvsSize), sizeof(int)); 
     3887 
     3888        ObjectPvsIterator pit = viewCell->GetPvs().GetIterator(); 
     3889 
     3890        // write PVS of view cell 
     3891        while (pit.HasMoreEntries()) 
     3892        { 
     3893                Intersectable *intersect = pit.Next(); 
     3894                id = intersect->GetId(); 
     3895                stream.write(reinterpret_cast<char *>(&id), sizeof(int)); 
     3896        } 
     3897} 
     3898 
     3899 
     3900bool VspTree::ExportBinary(OUT_STREAM &stream) 
     3901{ 
     3902        // export binary version of mesh 
     3903        queue<VspNode *> tStack; 
     3904        tStack.push(mRoot); 
     3905 
     3906        while(!tStack.empty()) 
     3907        { 
     3908                VspNode *node = tStack.front(); 
     3909                tStack.pop(); 
     3910                 
     3911                if (node->IsLeaf()) 
     3912                { 
     3913                        ExportBinLeaf(stream, static_cast<VspLeaf *>(node)); 
     3914                } 
     3915                else 
     3916                { 
     3917                        VspInterior *interior = static_cast<VspInterior *>(node); 
     3918 
     3919                        ExportBinInterior(stream, interior); 
     3920                         
     3921                        tStack.push(interior->GetFront()); 
     3922                        tStack.push(interior->GetBack()); 
     3923                } 
     3924        } 
     3925 
     3926        return true; 
     3927} 
     3928 
     3929 
     3930////////////////// 
     3931// import binary 
     3932 
     3933VspInterior *VspTree::ImportBinInterior(IN_STREAM  &stream, VspInterior *parent) 
     3934{ 
     3935        AxisAlignedPlane plane; 
     3936 
     3937        stream.read(reinterpret_cast<char *>(&plane.mAxis), sizeof(int)); 
     3938        stream.read(reinterpret_cast<char *>(&plane.mPosition), sizeof(float)); 
     3939 
     3940        VspInterior *interior = new VspInterior(plane); 
     3941 
     3942        return interior; 
     3943} 
     3944 
     3945 
     3946VspLeaf *VspTree::ImportBinLeaf(IN_STREAM &stream,  
     3947                                                                VspInterior *parent, 
     3948                                                                const ObjectContainer &pvsObjects) 
     3949{ 
     3950#if TODO 
     3951        int leafId = TYPE_LEAF; 
     3952        int objId = leafId; 
     3953        int size; 
     3954 
     3955        stream.read(reinterpret_cast<char *>(&size), sizeof(int)); 
     3956        KdLeaf *leaf = new KdLeaf(parent, size); 
     3957 
     3958        MeshInstance dummyInst(NULL); 
     3959         
     3960        // read object ids 
     3961        // note: could also do this geometrically 
     3962        for (int i = 0; i < size; ++ i) 
     3963        {        
     3964                stream.read(reinterpret_cast<char *>(&objId), sizeof(int)); 
     3965                dummyInst.SetId(objId); 
     3966 
     3967                ObjectContainer::const_iterator oit = 
     3968                        lower_bound(objects.begin(), objects.end(), (Intersectable *)&dummyInst, ilt); 
     3969                                                                 
     3970                if ((oit != objects.end()) && ((*oit)->GetId() == objId)) 
     3971                        leaf->mObjects.push_back(*oit); 
     3972                else 
     3973                        Debug << "error: object with id " << objId << " does not exist" << endl; 
     3974        } 
     3975        return leaf; 
     3976#endif 
     3977return NULL; 
     3978} 
     3979 
     3980 
     3981VspNode *VspTree::ImportNextNode(IN_STREAM &stream,  
     3982                                                                 VspInterior *parent, 
     3983                                                                 const ObjectContainer &objects) 
     3984{ 
     3985        int nodeType; 
     3986        stream.read(reinterpret_cast<char *>(&nodeType), sizeof(int)); 
     3987 
     3988        if (nodeType == TYPE_LEAF) 
     3989                return ImportBinLeaf(stream, static_cast<VspInterior *>(parent), objects); 
     3990 
     3991        if (nodeType == TYPE_INTERIOR) 
     3992                return ImportBinInterior(stream, static_cast<VspInterior *>(parent)); 
     3993 
     3994        Debug << "error! loading failed!" << endl; 
     3995        return NULL; 
     3996} 
     3997 
     3998 
     3999/** Data used for tree traversal 
     4000*/ 
     4001struct MyTraversalData 
     4002 
     4003public: 
     4004 
     4005        MyTraversalData(VspNode *node, const int depth, const AxisAlignedBox3 &box): 
     4006        mNode(node), mDepth(depth), mBox(box) 
     4007        {} 
     4008 
     4009 
     4010        ////////////////////// 
     4011 
     4012        /// the current node 
     4013        VspNode *mNode; 
     4014        /// current depth 
     4015        int mDepth; 
     4016        /// the bounding box 
     4017        AxisAlignedBox3 mBox; 
     4018}; 
     4019 
     4020 
     4021bool VspTree::ImportBinary(IN_STREAM &stream, ObjectContainer &pvsObjects) 
     4022{ 
     4023        // export binary version of mesh 
     4024        queue<MyTraversalData> tStack; 
     4025 
     4026        // sort objects by their id 
     4027        //sort(objects.begin(), objects.end(), ilt); 
     4028 
     4029        // hack: we make a new root 
     4030        DEL_PTR(mRoot); 
     4031   
     4032        mRoot = ImportNextNode(stream, NULL, pvsObjects); 
     4033 
     4034        tStack.push(MyTraversalData(mRoot, 0, mBoundingBox)); 
     4035        mVspStats.Reset(); 
     4036        mVspStats.nodes = 1; 
     4037 
     4038        while(!tStack.empty()) 
     4039        { 
     4040                MyTraversalData tData = tStack.front(); 
     4041                tStack.pop(); 
     4042 
     4043                VspNode *node = tData.mNode; 
     4044 
     4045                if (!node->IsLeaf()) 
     4046                { 
     4047                        mVspStats.nodes += 2; 
     4048 
     4049                        //Debug << "i" ; 
     4050                        VspInterior *interior = static_cast<VspInterior *>(node); 
     4051                        interior->SetBoundingBox(tData.mBox); 
     4052 
     4053            VspNode *front = ImportNextNode(stream, interior, pvsObjects); 
     4054                        VspNode *back = ImportNextNode(stream, interior, pvsObjects); 
     4055         
     4056                        interior->SetupChildLinks(back, front); 
     4057 
     4058                        ++ mVspStats.splits[interior->GetAxis()]; 
     4059 
     4060                        // compute new bounding box 
     4061                        AxisAlignedBox3 frontBox, backBox; 
     4062                         
     4063                        tData.mBox.Split(interior->GetAxis(),  
     4064                                         interior->GetPosition(),  
     4065                                                         frontBox,  
     4066                                                         backBox); 
     4067 
     4068                        tStack.push(MyTraversalData(front, tData.mDepth + 1, frontBox));                         
     4069                        tStack.push(MyTraversalData(back, tData.mDepth + 1,  backBox)); 
     4070                } 
     4071                else 
     4072                { 
     4073                        //EvaluateLeafStats(tData); 
     4074                        //cout << "l"; 
     4075                } 
     4076        } 
     4077        return true; 
     4078} 
     4079 
     4080 
     4081} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h

    r2353 r2539  
    147147 
    148148 
    149 /** 
    150     VspNode abstract class serving for interior and leaf node implementation 
     149/** VspNode abstract class serving for interior and leaf node implementation 
    151150*/ 
    152151class VspNode 
    153152{ 
     153        friend class VspTree; 
     154 
    154155public: 
    155156         
     
    172173        */ 
    173174        virtual bool IsRoot() const; 
    174          
    175175        /** Returns parent node. 
    176176        */ 
    177177        VspInterior *GetParent(); 
    178          
    179178        /** Sets parent node. 
    180179        */ 
    181180        void SetParent(VspInterior *parent); 
    182  
    183181        /** Returns true if this node is a sibling of node n. 
    184182        */ 
    185183        bool IsSibling(VspNode *n) const; 
    186          
    187184        /** returns depth of the node. 
    188185        */ 
    189186        int GetDepth() const; 
    190          
    191         /** returns true if the whole subtree is valid 
     187        /** Returns true if this node (which represents the whole subtree) is valid 
    192188        */ 
    193189        bool TreeValid() const; 
    194  
     190        /** Sets this node to valid. 
     191        */ 
    195192        void SetTreeValid(const bool v); 
    196          
    197193        /** Cost of mergin this node. 
    198194        */ 
    199195        float GetMergeCost() {return (float)-mTimeStamp; } 
    200196 
     197        /// timestamp of this node 
    201198        int mTimeStamp; 
    202199 
     
    212209        int mMailbox; 
    213210 
    214         //int mPvsEntriesIncr; 
    215         //float mMemoryIncr; 
    216         //float mRenderCostDecr; 
    217  
     211         
    218212protected: 
    219213 
    220214        /// if this sub tree is a completely valid view space region 
    221215        bool mTreeValid; 
    222          
    223216        /// parent of this node 
    224217        VspInterior *mParent; 
     
    230223class VspInterior: public VspNode  
    231224{ 
     225        friend class VspTree; 
     226 
    232227public: 
    233228 
     
    237232 
    238233        ~VspInterior(); 
    239          
    240234        /** @return false since it is an interior node  
    241235        */ 
    242   bool IsLeaf() const { 
    243         return false;  
    244   } 
    245  
     236        bool IsLeaf() const { return false; } 
    246237 
    247238        int Type() const; 
    248  
    249   VspNode *GetBack() { 
    250         return mBack; 
    251   } 
    252  
    253  
    254   VspNode *GetFront() { 
    255         return mFront; 
    256   } 
    257  
     239        /** Returns back child. 
     240        */ 
     241        VspNode *GetBack() { return mBack; } 
     242        /** Returns front child. 
     243        */ 
     244        VspNode *GetFront() { return mFront; } 
    258245        /** Returns split plane. 
    259246        */ 
    260   AxisAlignedPlane GetPlane() const { 
    261         return mPlane; 
    262   } 
    263    
    264  
     247        AxisAlignedPlane GetPlane() const { return mPlane; } 
    265248        /** Returns position of split plane. 
    266249        */ 
    267   float GetPosition() const { 
    268         return mPlane.mPosition; 
    269   } 
    270  
     250        float GetPosition() const { return mPlane.mPosition; } 
    271251        /** Returns split axis. 
    272252        */ 
    273   int GetAxis() const { 
    274         return mPlane.mAxis; 
    275   } 
    276  
     253        int GetAxis() const { return mPlane.mAxis; } 
    277254        /** Replace front or back child with new child. 
    278255        */ 
    279256        void ReplaceChildLink(VspNode *oldChild, VspNode *newChild); 
    280  
    281257        /** Replace front and back child. 
    282258        */ 
    283259        void SetupChildLinks(VspNode *front, VspNode *back); 
     260        /** Returns boundiŽng box of this node. 
     261        */ 
     262        AxisAlignedBox3 GetBoundingBox() const; 
     263        /** Sets boundiong box of this node. 
     264        */ 
     265        void SetBoundingBox(const AxisAlignedBox3 &box); 
     266        /** Computes intersection of this plane with the ray segment. 
     267        */ 
     268        int ComputeRayIntersection(const RayInfo &rayData, float &t) const 
     269        { 
     270                return rayData.ComputeRayIntersection(mPlane.mAxis, mPlane.mPosition, t); 
     271        } 
    284272 
    285273        friend std::ostream &operator<<(std::ostream &s, const VspInterior &A) 
     
    288276        } 
    289277 
    290         AxisAlignedBox3 GetBoundingBox() const; 
    291         void SetBoundingBox(const AxisAlignedBox3 &box); 
    292  
    293         /** Computes intersection of this plane with the ray segment. 
    294         */ 
    295         int ComputeRayIntersection(const RayInfo &rayData, float &t) const 
    296         { 
    297                 return rayData.ComputeRayIntersection(mPlane.mAxis, mPlane.mPosition, t); 
    298         } 
    299  
    300278 
    301279protected: 
     280 
    302281        /// bounding box for this interior node: should we really store this? 
    303282        AxisAlignedBox3 mBoundingBox; 
    304  
    305283        /// Splitting plane corresponding to this node 
    306284        AxisAlignedPlane mPlane; 
    307  
    308285        /// back node 
    309286        VspNode *mBack; 
     
    329306        /** @return true since it is an interior node  
    330307        */ 
    331   bool IsLeaf() const { 
    332         return true; 
    333   } 
     308        bool IsLeaf() const { return true; } 
    334309         
    335310        int Type() const; 
     
    337312        /** Returns pointer of view cell. 
    338313        */ 
    339   ViewCellLeaf *GetViewCell() const { 
    340         return mViewCell; 
    341   } 
    342  
     314        ViewCellLeaf *GetViewCell() const { return mViewCell; } 
    343315        /** Sets pointer to view cell. 
    344316        */ 
     
    383355public: 
    384356         
     357        /////////// 
     358        //-- Helper structs / classes 
     359 
    385360        /** Additional data which is passed down the BSP tree during traversal. 
    386361        */ 
    387         class VspTraversalData 
     362        struct VspTraversalData 
    388363        {   
    389364        public: 
    390365                 
    391                 /** Returns average ray contribution. 
    392                 */ 
    393                 float GetAvgRayContribution() const 
    394                 { 
    395                         return (float)mPvs / ((float)mRays->size() + Limits::Small); 
    396                 } 
    397  
    398  
    399                 /** Returns average rays per object. 
    400                 */ 
    401                 float GetAvgRaysPerObject() const 
    402                 { 
    403                         return (float)mRays->size() / ((float)mPvs + Limits::Small); 
    404                 } 
    405  
    406                 VspTraversalData(): 
    407                         mNode(NULL), 
    408                         mDepth(0), 
    409                         mRays(NULL), 
    410                         mPvs(0), 
    411                         mProbability(0.0), 
    412                         mMaxCostMisses(0),  
    413                         mPriority(0), 
    414                         mCorrectedPvs(0) 
    415                 {} 
     366                VspTraversalData(); 
    416367                 
    417368                VspTraversalData(VspLeaf *node,  
     
    420371                                                 const float pvs, 
    421372                                                 const float p, 
    422                                                  const AxisAlignedBox3 &box): 
    423                         mNode(node),  
    424                         mDepth(depth),  
    425                         mRays(rays), 
    426                         mProbability(p), 
    427                         mBoundingBox(box), 
    428                         mMaxCostMisses(0), 
    429                         mPriority(0), 
    430                         mCorrectedPvs(0), 
    431                         mPvs(pvs), 
    432                         mRenderCost(0), 
    433                         mCorrectedRenderCost(0) 
    434                 {} 
    435  
    436                 VspTraversalData(const int depth,  
    437                                                  RayInfoContainer *rays, 
    438                                                  const AxisAlignedBox3 &box):  
    439                         mNode(NULL),  
    440                         mDepth(depth),  
    441                         mRays(rays), 
    442                         mProbability(0), 
    443                         mMaxCostMisses(0), 
    444                         mBoundingBox(box), 
    445                         mCorrectedPvs(0), 
    446                         mPvs(0) , 
    447                         mRenderCost(0), 
    448                         mCorrectedRenderCost(0)  
    449                 {} 
    450  
     373                                                 const AxisAlignedBox3 &box); 
     374 
     375         
    451376                /** Returns cost of the traversal data. 
    452377                */ 
    453                 float GetCost() const 
    454                 { 
    455                         return mPriority; 
    456                 } 
    457  
    458                 /// deletes contents and sets them to NULL 
    459                 void Clear() 
    460                 { 
    461                         DEL_PTR(mRays); 
    462  
    463                         if (mNode) 
    464                         { 
    465                                 // delete old view cell 
    466                                 delete mNode->GetViewCell(); 
    467  
    468                                 delete mNode; 
    469                                 mNode = NULL; 
    470                         } 
    471                 } 
     378                inline float GetCost() const; 
     379                /** Returns average ray contribution. 
     380                */ 
     381                inline float GetAvgRayContribution() const; 
     382                /** Returns average rays per object. 
     383                */ 
     384                inline float GetAvgRaysPerObject() const; 
     385                /** deletes contents and sets them to NULL. 
     386                */ 
     387                void Clear(); 
     388 
     389 
     390                ////////////////////// 
    472391 
    473392                /// the current node 
     
    500419    }; 
    501420 
     421        /** Helper struct for data that comes with a split of a node. 
     422        */ 
    502423        struct SplitData  
    503424        { 
     
    511432                mFrontTriangles(0), 
    512433                mBackTriangles(0), 
    513                 mTotalTriangles(0) {} 
    514  
     434                mTotalTriangles(0)  
     435                {} 
     436 
     437                ////////////// 
    515438 
    516439                float mFrontRenderCost; 
     
    580503                {} 
    581504 
    582                 float GetPriority() const 
    583                 { 
    584                         return mPriority; 
    585                 } 
     505                float GetPriority() const {     return mPriority; } 
     506 
    586507 
    587508                //////////////////// 
    588509 
    589510                static VspTree* sVspTree; 
    590  
    591511                /// the current split plane 
    592512                AxisAlignedPlane mSplitPlane; 
     
    623543        }; 
    624544 
     545 
     546        ////////////////////// 
     547 
     548 
    625549        /** Default constructor creating an empty tree. 
    626550        */  
     
    629553        */ 
    630554        ~VspTree(); 
    631  
    632555        /** Returns BSP Tree statistics. 
    633556        */ 
    634557        const VspTreeStatistics &GetStatistics() const;  
    635    
    636558        /** Returns bounding box of the specified node. 
    637559        */ 
    638560        AxisAlignedBox3 GetBoundingBox(VspNode *node) const; 
    639  
    640561        /** Returns list of BSP leaves with pvs smaller than 
    641562                a certain threshold. 
     
    646567                                           const bool onlyUnmailed = false, 
    647568                                           const int maxPvs = -1) const; 
    648  
    649569        /** Returns box which bounds the whole tree. 
    650570        */ 
    651571        AxisAlignedBox3 GetBoundingBox() const; 
    652  
    653572        /** Returns root of the view space partitioning tree. 
    654573        */ 
    655574        VspNode *GetRoot() const; 
    656  
    657575        /** Collects the leaf view cells of the tree 
    658576                @param viewCells returns the view cells  
    659577        */ 
    660578        void CollectViewCells(ViewCellContainer &viewCells, bool onlyValid) const; 
    661  
    662579        /** A ray is cast possible intersecting the tree. 
    663580                @param the ray that is cast. 
     
    665582        */ 
    666583        int CastRay(Ray &ray); 
    667  
    668  
    669584        /** finds neighbouring leaves of this tree node. 
    670585        */ 
     
    672587                                          vector<VspLeaf *> &neighbors,  
    673588                                          const bool onlyUnmailed) const; 
    674  
    675589        /** Returns random leaf of BSP tree. 
    676590                @param halfspace defines the halfspace from which the leaf is taken. 
     
    682596        */ 
    683597        VspLeaf *GetRandomLeaf(const bool onlyUnmailed = false); 
    684  
    685598        /** Returns epsilon of this tree. 
    686599        */ 
    687600        float GetEpsilon() const; 
    688  
    689601        /** Casts line segment into the tree. 
    690602                @param origin the origin of the line segment 
     
    696608                                                ViewCellContainer &viewcells, 
    697609                                                const bool useMailboxing = true); 
    698  
    699                  
    700610        /** Sets pointer to view cells manager. 
    701611        */ 
    702612        void SetViewCellsManager(ViewCellsManager *vcm); 
    703  
    704613        /** Returns view cell the current point is located in. 
    705614                @param point the current view point 
     
    708617        */ 
    709618        ViewCell *GetViewCell(const Vector3 &point, const bool active = false); 
    710  
    711  
    712619        /** Returns true if this view point is in a valid view space, 
    713620                false otherwise. 
    714621        */ 
    715622        bool ViewPointValid(const Vector3 &viewPoint) const; 
    716  
    717623        /** Returns view cell corresponding to  
    718624                the invalid view space. 
    719625        */ 
    720626        VspViewCell *GetOutOfBoundsCell(); 
    721  
    722         /** Writes tree to output stream 
    723         */ 
    724         bool Export(OUT_STREAM &stream); 
    725  
    726627        /** Casts beam, i.e. a 5D frustum of rays, into tree. 
    727628                Tests conservative using the bounding box of the nodes. 
     
    729630        */ 
    730631        int CastBeam(Beam &beam); 
    731  
    732632        /** Checks if tree validity-flags are right  
    733633                with respect to view cell valitiy. 
     
    735635        */ 
    736636        void ValidateTree(); 
    737  
    738637        /** Collects rays stored in the leaves. 
    739638        */ 
    740639        void CollectRays(VssRayContainer &rays); 
    741  
    742640        /** Intersects box with the tree and returns the number of intersected boxes. 
    743641                @returns number of view cells found 
     
    745643        int ComputeBoxIntersections(const AxisAlignedBox3 &box,  
    746644                                                                ViewCellContainer &viewCells) const; 
    747  
    748645        /** Returns view cells of this ray, either taking precomputed cells 
    749646                or by recomputation. 
    750647        */ 
    751648        void GetViewCells(const VssRay &ray, ViewCellContainer &viewCells); 
    752  
    753649        /** Returns view cells tree. 
    754650        */ 
    755651        ViewCellsTree *GetViewCellsTree() const { return mViewCellsTree; } 
    756  
    757652        /** Sets the view cells tree. 
    758653        */ 
    759654        void SetViewCellsTree(ViewCellsTree *vt) { mViewCellsTree = vt; } 
    760  
     655        /** Writes vsp tree to output stream 
     656        */ 
     657        bool Export(OUT_STREAM &stream); 
     658        /** Writes vsp tree to binary output stream. 
     659        */ 
     660        bool ExportBinary(OUT_STREAM &stream); 
     661        /** Imports tree from binary format. 
     662        */ 
     663        bool ImportBinary(IN_STREAM &stream, ObjectContainer &pvsObjects); 
     664 
     665 
     666        //////////// 
    761667 
    762668        PerfTimer mSortTimer; 
     
    808714                                                         float &pFront, 
    809715                                                         float &pBack) const; 
    810  
     716        /** If != NULL, sets the bounding box to the forced  bounding box. 
     717                Else computes the bounding box of the view space using the 
     718                hit points gathered from the ray-object intersections. 
     719        */ 
    811720        void ComputeBoundingBox(const VssRayContainer &rays, 
    812721                                                        AxisAlignedBox3 *forcedBoundingBox); 
    813  
    814722        /** Evaluates candidate for splitting. 
    815723        */ 
    816         void EvalSubdivisionCandidate(VspSubdivisionCandidate &splitData,  
     724        void EvalSubdivisionCandidate(VspSubdivisionCandidate &candidate,  
    817725                                                                  bool computeSplitPlane = true); 
    818  
    819726        /** Evaluates render cost decrease of next split. 
    820727        */ 
    821         float EvalRenderCostDecrease(VspSubdivisionCandidate &splitData,  
     728        float EvalRenderCostDecrease(VspSubdivisionCandidate &candidate,  
    822729                                                                 float &normalizedOldRenderCost, 
    823730                                                                 const SplitData &data) const; 
    824  
    825731        /** Collects view cells in the subtree under root. 
    826732        */ 
     
    829735                                                  ViewCellContainer &viewCells, 
    830736                                                  bool onlyUnmailed = false) const; 
    831  
    832737        /** Returns view cell corresponding to  
    833738                the invalid view space. If it does not exist, it is created. 
    834739        */ 
    835740        VspViewCell *GetOrCreateOutOfBoundsCell(); 
    836  
    837741        /** Collapses the tree with respect to the view cell partition, 
    838742                i.e. leaves having the same view cell are collapsed. 
     
    843747        */ 
    844748        VspNode *CollapseTree(VspNode *node, int &collapsed); 
    845  
    846749        /** Helper function revalidating the view cell leaf list after merge. 
    847750        */ 
    848751        void RepairViewCellsLeafLists(); 
    849  
    850752        /** Evaluates tree stats in the BSP tree leafs. 
    851753        */ 
     
    861763                                           SubdivisionCandidate *splitCandidate, 
    862764                                           const bool globalCriteriaMet); 
    863  
    864765        /** Adds stats to subdivision log file. 
    865766        */ 
     
    868769                                                         const float totalRenderCost, 
    869770                                                         const float avgRenderCost); 
    870          
    871771        /** Subdivides leaf. 
    872                          
    873772                @param tData data object holding, e.g., a pointer to the leaf 
    874773                @param frontData returns the data (e.g., pointer to the leaf) in front of the split plane 
    875774                @param backData returns the data (e.g., pointer to the leaf) in the back of the split plane 
    876                  
    877                 @param rays the polygons to be filtered 
    878                 @param frontRays returns the polygons in front of the split plane 
    879775         
    880776                @returns the root of the subdivision 
     
    891787                                                   float &pFront, 
    892788                                                   float &pBack); 
    893  
    894789        /** Sorts split candidates along the specified axis. 
    895790                The split candidates are generated on possible visibility 
     
    905800                                                                   float minBand,  
    906801                                                                   float maxBand); 
    907  
    908802        /** Evaluate render cost of this pvs. 
    909803        */ 
     
    912806        int EvalPvsEntriesIncr(VspSubdivisionCandidate &splitCandidate, 
    913807                                                   const SplitData &sData) const; 
    914  
    915808        /** Returns number of effective entries in the pvs. 
    916809        */ 
     
    918811 
    919812        int EvalPvsEntriesContribution(const VssRay &ray, const bool isTermination) const; 
    920  
    921813        /** Computes best cost for axis aligned planes. 
    922814        */ 
     
    928820 
    929821 
    930         ////////////////////////////////////////// 
    931         // Helper function for computing heuristics 
     822        /////////////////////// 
     823        //-- Helper function for computing heuristics 
    932824 
    933825        /** Evaluates the contribution to left and right pvs at a visibility event ve. 
     
    937829        */ 
    938830        inline void EvalHeuristics(const SortableEntry &ve, float &pvsLeft, float &pvsRight) const; 
    939  
    940831        /** Evaluates contribution of min event to pvs 
    941832        */ 
    942833        inline float EvalMinEventContribution(const VssRay &ray, const bool isTermination) const; 
    943  
    944834        /** Evaluates contribution of max event to pvs 
    945835        */ 
    946836        inline float EvalMaxEventContribution(const VssRay &ray, const bool isTermination) const; 
    947  
    948837        /** Evaluates contribution of kd leaf when encountering a min event 
    949838        */ 
    950839        inline float EvalMinEventContribution(KdLeaf *leaf) const; 
    951  
    952840        /**  Evaluates contribution of kd leaf when encountering a max event 
    953841        */ 
    954842        inline float EvalMaxEventContribution(KdLeaf *leaf) const; 
    955  
    956843        /** Prepares objects for the heuristics. 
    957844                @returns pvs size as seen by the rays. 
    958845        */ 
    959846        float PrepareHeuristics(const RayInfoContainer &rays); 
    960          
    961847        /** Prepare a single ray for heuristics. 
    962848        */ 
    963849        float PrepareHeuristics(const VssRay &ray, const bool isTermination); 
    964  
    965850        /** Prepare a single kd leaf for heuristics. 
    966851        */ 
    967852        float PrepareHeuristics(KdLeaf *leaf); 
    968  
     853        /** Evaluates minimal and maximal depth in the tree. 
     854        */ 
    969855        void EvalMinMaxDepth(int &minDepth, int &maxDepth); 
    970  
    971  
    972  
    973         ///////////////////////////////////////////////////////////// 
    974  
     856        /** Writes the node to disk 
     857                @note: should be implemented as visitor. 
     858        */ 
     859        void ExportNode(VspNode *node, OUT_STREAM &stream); 
     860         
     861 
     862        //////////////// 
     863 
     864        void ExportBinInterior(OUT_STREAM &stream, VspInterior *interior); 
     865        void ExportBinLeaf(OUT_STREAM &stream, VspLeaf *leaf); 
     866 
     867        VspInterior *ImportBinInterior(IN_STREAM  &stream, VspInterior *parent); 
     868        VspLeaf *ImportBinLeaf(IN_STREAM &stream, VspInterior *parent, const ObjectContainer &pvsObjects); 
     869 
     870        VspNode *ImportNextNode(IN_STREAM &stream,  
     871                                                        VspInterior *parent, 
     872                                                        const ObjectContainer &pvsObjects); 
     873 
     874 
     875        ////////////////////////////////////////////////// 
    975876 
    976877        /** Subdivides the rays into front and back rays according to the split plane. 
    977                  
    978878                @param plane the split plane 
    979879                @param rays contains the rays to be split. The rays are  
     
    988888                              RayInfoContainer &frontRays,  
    989889                                  RayInfoContainer &backRays) const; 
    990  
    991  
     890        /** Add contributions of this ray to fron, back, and overall pvs of the parent. 
     891        */ 
    992892        inline void UpdatePvsEntriesContribution(const VssRay &ray, 
    993893                                                                                         const bool isTermination, 
     
    996896                                                                                         float &backPvs, 
    997897                                                                                         float &totalPvs) const; 
    998  
    999898        /** Classfifies the object with respect to the  
    1000899                pvs of the front and back leaf and updates pvs size 
     
    1013912                                                                                 float &backPvs, 
    1014913                                                                                 float &totalPvs) const; 
    1015  
    1016914        /** Evaluates the contribution for objects. 
    1017915        */ 
     
    1021919                                                                                 float &backPvs,  
    1022920                                                                                 float &totalPvs) const; 
    1023  
    1024921        /** Evaluates the contribution for bounding volume leaves. 
    1025922        */ 
     
    1030927                                                                                 float &totalPvs, 
    1031928                                                                                 const bool countEntries) const; 
    1032  
     929        /** Updates contribution to pvs caused by this bvh leaf. 
     930        */ 
    1033931        inline void UpdateContributionsToPvs(BvhLeaf *leaf, 
    1034932                                                                                 const int cf, 
    1035933                                                                                 SplitData &sdata) const; 
    1036  
    1037934        /** Evaluates the contribution for kd leaves. 
    1038935        */ 
     
    1042939                                                                                 float &backPvs, 
    1043940                                                                                 float &totalPvs) const; 
    1044  
    1045941        /** Returns true if tree can be terminated. 
    1046942        */ 
    1047943        inline bool LocalTerminationCriteriaMet(const VspTraversalData &data) const; 
    1048  
    1049944        /** Returns true if global tree can be terminated. 
    1050945        */ 
    1051946        bool GlobalTerminationCriteriaMet(const VspTraversalData &data) const; 
    1052  
    1053947        /** Adds ray sample contributions to the PVS. 
    1054948                @param sampleContributions the number contributions of the samples 
     
    1060954                                                 float &sampleContributions, 
    1061955                                                 int &contributingSamples); 
    1062  
    1063956        /** Propagates valid flag up the tree. 
    1064957        */ 
    1065958        void PropagateUpValidity(VspNode *node); 
    1066  
    1067         /** Writes the node to disk 
    1068                 @note: should be implemented as visitor. 
    1069         */ 
    1070         void ExportNode(VspNode *node, OUT_STREAM &stream); 
    1071  
    1072959        /** Returns estimated memory usage of tree. 
    1073960        */ 
    1074961        float GetMemUsage() const; 
    1075  
    1076962        /** Updates view cell pvs of objects. 
    1077963        */ 
     
    1079965                                                                ViewCell *front,  
    1080966                                                                ViewCell *back) const; 
    1081  
     967        /** Creates a new view cell from the traversal data. 
     968        */ 
    1082969        void CreateViewCell(VspTraversalData &tData,  
    1083970                                                const bool updatePvs, 
    1084971                                                const float renderCost, 
    1085972                                                const int pvs); 
    1086  
    1087973        /** Collect split candidates which are affected by the last split 
    1088974                and must be reevaluated. 
     
    1091977                                                                vector<SubdivisionCandidate *> &dirtyList, 
    1092978                                                                const bool onlyUnmailed); 
    1093  
    1094         void CollectDirtyCandidate(const VssRay &ray,  
     979        /** Adds the split candidate associated with this ray to the dirty list. 
     980        */ 
     981        void AddCandidateToDirtyList(const VssRay &ray,  
    1095982                                                           const bool isTermination, 
    1096983                                                           vector<SubdivisionCandidate *> &dirtyList, 
    1097984                                                           const bool onlyUnmailed) const; 
    1098  
    1099985        /** Rays will be clipped to the bounding box. 
    1100986        */ 
    1101987        void PreprocessRays(const VssRayContainer &sampleRays, RayInfoContainer &rays); 
    1102  
    1103988        /** Evaluate subdivision statistics. 
    1104989        */ 
    1105990        void EvalSubdivisionStats(const SubdivisionCandidate &tData); 
    1106  
     991        /** Prepares the construction of the vsp tree. 
     992        */ 
    1107993        void PrepareConstruction(SplitQueue &tQueue, 
    1108994                                                         const VssRayContainer &sampleRays, 
    1109995                                                         RayInfoContainer &rays); 
    1110  
    1111996        /** Evaluates pvs contribution of this ray. 
    1112997        */ 
    1113998        float EvalContributionToPvs(const VssRay &ray, const bool isTermination) const; 
    1114  
    1115999        /** Evaluates pvs contribution of a kd node. 
    11161000        */ 
    11171001        float EvalContributionToPvs(KdLeaf *leaf) const; 
    1118  
    11191002        /** Creates new root of hierarchy and computes bounding box. 
    11201003                Has to be called before the preparation of the subdivision. 
     
    11971080                int mStackPtr; 
    11981081                int mDepth; 
    1199  
    12001082        }; 
    12011083 
     
    12071089        /// pointer to the hierarchy of view cells 
    12081090        ViewCellsTree *mViewCellsTree; 
    1209  
     1091        /// Pointer to the hierarchy manager which is responsible for both  
     1092        /// view and object space 
    12101093        HierarchyManager *mHierarchyManager; 
     1094        /// Pointer to the bv hierarchy 
    12111095        BvHierarchy *mBvHierarchy; 
    1212          
     1096        /// Pointer to the view cells manager 
    12131097        ViewCellsManager *mViewCellsManager; 
    1214          
     1098        /// Buffer for subdivision candidates used for split heuristics evaluation 
    12151099        vector<SortableEntry> *mLocalSubdivisionCandidates; 
    1216  
    12171100        /// Pointer to the root of the tree 
    12181101        VspNode *mRoot; 
    1219                  
     1102        /// The statistics 
    12201103        VspTreeStatistics mVspStats; 
    1221          
    12221104        /// View cell corresponding to the space outside the valid view space 
    12231105        VspViewCell *mOutOfBoundsCell; 
    1224  
    12251106        /// box around the whole view domain 
    12261107        AxisAlignedBox3 mBoundingBox; 
     
    12811162        // if rays should be stored in leaves 
    12821163        bool mStoreRays; 
    1283  
    12841164        /// epsilon for geometric comparisons 
    12851165        float mEpsilon; 
    1286  
    12871166        /// subdivision stats output file 
    12881167        std::ofstream mSubdivisionStats; 
    12891168        /// keeps track of cost during subdivision 
    12901169        float mTotalCost; 
     1170        /// keeps track of #pvs entries during subdivison 
    12911171        int mPvsEntries; 
    12921172        /// keeps track of overall pvs size during subdivision 
     
    12971177        /// weight between render cost decrease and node render cost 
    12981178        float mRenderCostDecreaseWeight; 
    1299  
     1179        /// maximal #of rays used for heuristics evalution 
    13001180        int mMaxTests; 
    1301  
    13021181        /// constant value for driving the heuristics 
    13031182        float mMemoryConst; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp

    r2176 r2539  
    357357                                MeshManager::GetSingleton()->FindEntry(meshIdx); 
    358358 
    359                         //Debug << "retrieving mesh definition: " << mCurrentMeshName << endl; 
    360359                        cout << "u"; 
    361360                } 
    362                 else if (attrName == "DEF") //-- a definition of a mesh 
     361                else if (attrName == "DEF") // a definition of a mesh 
    363362                { 
    364363                        const StrX attrValue(attributes.getValue(i)); 
Note: See TracChangeset for help on using the changeset viewer.