Changeset 1418


Ignore:
Timestamp:
09/19/06 22:33:29 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/scripts/vienna.env

    r1404 r1418  
    88#       filename vienna.x3d 
    99#       filename ../data/vienna/vienna-simple.x3d 
    10         filename ../data/vienna/vienna-buildings.x3d 
     10#       filename ../data/vienna/vienna-buildings.x3d 
    1111#       filename ../data/vienna/city1500_flat_1.x3d 
    1212#       filename ../data/vienna/vienna-buildings.x3d;../data/vienna-roads.x3d;../data/vienna/vienna-roofs.x3d 
    13 #filename ../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-roads.x3d 
     13filename ../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-roads.x3d 
    1414#filename ../data/vienna/city1500_flat_1.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-roads.x3d 
    1515#filename ../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-roads.x3d;../data/vienna/vienna-plane.x3d 
     
    205205        maxPvsRatio 1.0 
    206206                 
    207         pruneEmptyViewCells false 
    208207        processOnlyValidViewCells false 
    209208 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp

    r1416 r1418  
    12741274                                        "view_cells_evaluation_stats_prefix=", 
    12751275                                        "viewCells"); 
     1276 
    12761277        RegisterOption("ViewCells.Evaluation.histogram", 
    12771278                                        optBool, 
     
    14901491 
    14911492         
    1492         /************************************************************************************/ 
    1493         /*                         Render simulation related options                        */ 
    1494         /************************************************************************************/ 
     1493        /****************************************************************************/ 
     1494        /*                     Render simulation related options                    */ 
     1495        /****************************************************************************/ 
    14951496 
    14961497 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp

    r1416 r1418  
    106106bool Exporter::ExportBvHierarchy(const BvHierarchy &bvHierarchy,  
    107107                                                                 const int maxPvs, 
    108                                                                  const AxisAlignedBox3 *box) 
     108                                                                 const AxisAlignedBox3 *box, 
     109                                                                 const bool exportBoundingBoxes) 
    109110{ 
    110111        vector<BvhLeaf *> leaves; 
     
    122123        { 
    123124                BvhLeaf *leaf = *it; 
    124                 if (leaf->mObjects.empty()) 
     125 
     126                if (leaf->mObjects.empty() ||  
     127                        (box && !Overlap(*box, leaf->GetBoundingBox()))) 
    125128                        continue; 
    126129 
    127                 if (box && !Overlap(*box, leaf->GetBoundingBox())) 
    128                         continue; 
    129  
    130                 SetWireframe(); 
    131                 SetForcedMaterial(white); 
    132                 ExportBox(leaf->GetBoundingBox()); 
    133                 SetFilled(); 
    134  
    135                 if (maxPvs) // color code pvs 
     130                if (exportBoundingBoxes) 
     131                { 
     132                        SetWireframe(); 
     133                        SetForcedMaterial(white); 
     134                        ExportBox(leaf->GetBoundingBox()); 
     135                } 
     136 
     137        if (maxPvs) // color code pvs 
    136138                { 
    137139                        mForcedMaterial.mDiffuseColor.b = 1.0f; 
     
    146148                } 
    147149 
    148                 if (1)  
    149                 { 
    150                         SetFilled(); 
    151                         ExportGeometry(leaf->mObjects, true); 
    152                 } 
    153         } 
     150                SetFilled(); 
     151                ExportGeometry(leaf->mObjects, true); 
     152        } 
     153 
     154        SetFilled(); 
    154155 
    155156        return true; 
     
    176177                { 
    177178                        const Triangle3 triangle = dynamic_cast<TriangleIntersectable *>(object)->GetItem(); 
    178  
    179                         VertexContainer vertices; 
    180                         vertices.push_back(triangle.mVertices[0]); 
    181                         vertices.push_back(triangle.mVertices[1]); 
    182                         vertices.push_back(triangle.mVertices[2]); 
    183  
    184                         Polygon3 poly(vertices); 
     179                        Polygon3 poly(triangle); 
    185180                        ExportPolygon(&poly); 
    186181                        break; 
    187182                } 
     183        case Intersectable::BVH_INTERSECTABLE: 
     184                { 
     185                        BvhNode *node = dynamic_cast<BvhIntersectable *>(object)->GetItem(); 
     186                        if (node->IsLeaf()) 
     187                                ExportGeometry(dynamic_cast<BvhLeaf *>(node)->mObjects, true); 
     188                        break; 
     189                } 
    188190        default: 
    189191                cerr << "Sorry the export for object type " << Intersectable::GetTypeName(object) << " is not available yet" << endl; 
     
    191193        } 
    192194} 
     195 
    193196 
    194197void Exporter::ExportMeshInstance(MeshInstance *object) 
     
    234237                for (oit = objects.begin(); oit != oit_end; ++ oit) 
    235238                { 
    236                         if (bbox && Overlap(*bbox, (*oit)->GetBox())) 
     239                        if (!bbox || Overlap(*bbox, (*oit)->GetBox())) 
    237240                        { 
    238241                                if (0) SetForcedMaterial(RandomMaterial()); 
     
    240243                        } 
    241244                } 
    242  
    243245                return; 
    244246        } 
    245  
    246247         
    247         /////////////////////////////////////////// 
     248 
     249        /////////////////////// 
    248250        //-- all objects exported as one mesh 
    249         //-- hack: currently works only for triangles 
     251        //-- warning: currently works only for triangles 
    250252 
    251253        PolygonContainer polys; 
     
    255257                Intersectable *obj = *oit; 
    256258 
    257                 if (bbox && !Overlap(*bbox, (*oit)->GetBox())) 
     259                if (bbox && !Overlap(*bbox, obj->GetBox())) 
     260                { 
     261                        //cout << *bbox << " " << obj->GetBox() << endl; 
    258262                        continue; 
     263                } 
    259264 
    260265                switch (obj->Type()) 
     
    266271                break; 
    267272                        } 
     273                case Intersectable::MESH_INSTANCE: 
     274                        { 
     275                                MeshInstance *mi = dynamic_cast<MeshInstance *>(obj); 
     276                                ExportMesh(mi->GetMesh()); 
     277                                //polys.push_back(new Polygon3(ti->GetItem())); 
     278                break; 
     279                        } 
    268280                default: 
    269281                        cout << "merging of object type " << obj->Type() << " not implemented yet" << endl; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.h

    r1416 r1418  
    154154          const BvHierarchy &bvHierarchy,  
    155155          const int maxPvs,  
    156           const AxisAlignedBox3 *box = NULL); 
     156          const AxisAlignedBox3 *box = NULL, 
     157          const bool exportBoundingBoxes = true); 
    157158 
    158159  virtual void ExportMeshInstance(MeshInstance *mi); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r1416 r1418  
    281281        RunConstruction(sampleRays, objects, forcedViewSpace); 
    282282         
    283         cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    284  
     283        cout << "\nfinished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     284 
     285        cout << "here5 " << GetViewSpaceBox() << endl; 
     286        cout << "here6 " << GetObjectSpaceBox() << endl; 
    285287        mHierarchyStats.Stop(); 
    286288        mVspTree->mVspStats.Stop(); 
    287         FinishObjectSpaceSubdivision(); 
     289        FinishObjectSpaceSubdivision(objects); 
    288290 
    289291        mObjectSpaceSubdivisionType = mSavedObjectSpaceSubdivisionType; 
     
    762764void HierarchyManager::ExportObjectSpaceHierarchy(Exporter *exporter, 
    763765                                                                                                  const ObjectContainer &objects, 
    764                                                                                                   const AxisAlignedBox3 *bbox) const 
     766                                                                                                  const AxisAlignedBox3 *bbox, 
     767                                                                                                  const bool exportBounds) const 
    765768{ 
    766769        switch (mObjectSpaceSubdivisionType) 
     
    773776        case BV_BASED_OBJ_SUBDIV: 
    774777                { 
    775                         ExportBvHierarchy(exporter, objects, bbox); 
     778                        exporter->ExportBvHierarchy(*mBvHierarchy, 0, bbox, exportBounds); 
    776779                        break; 
    777780                } 
     
    779782                break; 
    780783        } 
    781 } 
    782  
    783  
    784 void HierarchyManager::ExportBvHierarchy(Exporter *exporter,  
    785                                                                                  const ObjectContainer &objects, 
    786                                                                                  const AxisAlignedBox3 *bbox) const 
    787 { 
    788         exporter->SetWireframe(); 
    789         exporter->ExportBvHierarchy(*mBvHierarchy, 0, bbox); 
    790784} 
    791785 
     
    801795 
    802796 
     797Intersectable *HierarchyManager::GetIntersectable(const VssRay &ray,  
     798                                                                                                  const bool isTermination) const 
     799{ 
     800 
     801        Intersectable *obj; 
     802        Vector3 pt; 
     803        KdNode *node; 
     804 
     805        ray.GetSampleData(isTermination, pt, &obj, &node); 
     806         
     807        if (!obj) return NULL; 
     808 
     809        switch (mObjectSpaceSubdivisionType) 
     810        { 
     811        case HierarchyManager::KD_BASED_OBJ_SUBDIV: 
     812                { 
     813                        KdLeaf *leaf = mOspTree->GetLeaf(pt, node); 
     814                        return mOspTree->GetOrCreateKdIntersectable(leaf); 
     815                } 
     816        case HierarchyManager::BV_BASED_OBJ_SUBDIV: 
     817                { 
     818                        BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj); 
     819                        return mBvHierarchy->GetOrCreateBvhIntersectable(leaf); 
     820                } 
     821        default: 
     822                return obj; 
     823        } 
     824} 
     825 
     826 
    803827void HierarchyStatistics::Print(ostream &app) const 
    804828{ 
     
    823847 
    824848 
    825 void HierarchyManager::FinishObjectSpaceSubdivision() const 
     849static void RemoveRayRefs(const ObjectContainer &objects) 
     850{ 
     851        ObjectContainer::const_iterator oit, oit_end = objects.end(); 
     852        for (oit = objects.begin(); oit != oit_end; ++ oit) 
     853        { 
     854                (*oit)->mVssRays.clear(); 
     855        } 
     856} 
     857 
     858 
     859void HierarchyManager::FinishObjectSpaceSubdivision(const ObjectContainer &objects) const 
    826860{ 
    827861        switch (mObjectSpaceSubdivisionType) 
     
    835869                { 
    836870                        mBvHierarchy->mBvhStats.Stop(); 
     871                        RemoveRayRefs(objects); 
    837872                        break; 
    838873                } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h

    r1416 r1418  
    206206                Exporter *exporter,  
    207207                const ObjectContainer &objects, 
    208                 const AxisAlignedBox3 *bbox) const; 
    209  
     208                const AxisAlignedBox3 *bbox, 
     209                const bool exportBounds = true) const; 
     210 
     211 
     212        Intersectable *GetIntersectable( 
     213                const VssRay &ray,  
     214                const bool isTermination) const; 
    210215 
    211216protected: 
     
    254259        void ExportOspTree(Exporter *exporter, const ObjectContainer &objects) const; 
    255260 
    256         void ExportBvHierarchy( 
    257                 Exporter *exporter,  
    258                 const ObjectContainer &objects,  
    259                 const AxisAlignedBox3 *box) const; 
    260  
    261         void PrepareBvHierarchy( 
    262                 const VssRayContainer &sampleRays, 
    263                 const ObjectContainer &objects); 
    264  
    265         void PrepareOspTree( 
    266                 const VssRayContainer &sampleRays, 
    267                 const ObjectContainer &objects); 
    268  
    269261        void ParseEnvironment(); 
    270262 
     
    272264        bool StartViewSpaceSubdivision() const; 
    273265 
     266        void PrepareBvHierarchy( 
     267                const VssRayContainer &sampleRays, 
     268                const ObjectContainer &objects); 
     269 
     270        void PrepareOspTree( 
     271                const VssRayContainer &sampleRays, 
     272                const ObjectContainer &objects); 
     273 
    274274        void PrepareViewSpaceSubdivision( 
    275275                const VssRayContainer &sampleRays, 
     
    281281    void ResetQueue(); 
    282282 
    283         void FinishObjectSpaceSubdivision() const; 
     283        void FinishObjectSpaceSubdivision(const ObjectContainer &objects) const; 
    284284 
    285285        int GetObjectSpaceSubdivisionDepth() const; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp

    r1344 r1418  
    476476 
    477477Plane3 
    478 Mesh::GetFacePlane(const int faceIndex) 
     478Mesh::GetFacePlane(const int faceIndex) const 
    479479{ 
    480480  Face *face = mFaces[faceIndex]; 
     
    521521 
    522522 
     523Vector3 Mesh::GetNormal(const int idx) const 
     524{ 
     525        return GetFacePlane(idx).mNormal; 
     526} 
     527 
     528 
    523529void 
    524530Mesh::AddTriangle(const Triangle3 &triangle) 
     
    728734Vector3 MeshInstance::GetNormal(const int idx) const 
    729735{ 
    730         return mMesh->GetFacePlane(idx).mNormal; 
     736        return mMesh->GetNormal(idx); 
    731737} 
    732738 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h

    r1344 r1418  
    187187                                          ); 
    188188   
    189   Plane3 GetFacePlane(const int faceIndex); 
     189  Plane3 GetFacePlane(const int faceIndex) const; 
    190190 
    191191  AxisAlignedBox3 GetFaceBox(const int faceIndex); 
     
    207207  } 
    208208 
     209 
     210  Vector3 GetNormal(const int idx) const; 
     211 
    209212  virtual ostream &Describe(ostream &s) { 
    210213        return s<<"Mesh #vertices="<<(int)mVertices.size()<<" #faces="<<(int)mFaces.size(); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Plane3.h

    r1076 r1418  
    7777        AxisAlignedPlane(){} 
    7878        AxisAlignedPlane(const int axis, const float position): 
    79           mAxis(axis), mPosition(position) 
     79          mAxis(axis), mPosition(position), mOrientation(false) 
    8080          { 
    8181          } 
    8282        Plane3 GetPlane() const 
    8383        { 
    84                 Vector3 normal(0,0,0); normal[mAxis] = 1; 
     84                Vector3 normal(0,0,0); normal[mAxis] = mOrientation ? 1.0f : -1.0f; 
    8585                Vector3 point(0,0,0); point[mAxis] = mPosition; 
    8686 
     
    9292        /// the absolute position of the split axis 
    9393        float mPosition; 
     94        /// the plane orientation 
     95        bool mOrientation; 
     96 
     97        friend ostream &operator<<(ostream &s, const AxisAlignedPlane &p)  
     98        { 
     99                s << "a: " << p.mAxis << " p: " << p.mPosition; 
     100                return s; 
     101        } 
    94102}; 
    95  
    96  
    97103} 
    98  
    99104#endif 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Polygon3.cpp

    r1404 r1418  
    6666        mVertices.push_back(tri.mVertices[1]); 
    6767        mVertices.push_back(tri.mVertices[2]); 
     68 
     69        //cout << "poly n: " << GetNormal() << " t normal: " << tri.GetNormal() << endl; 
    6870} 
    6971 
     
    539541        while (i < k) 
    540542        { 
    541                 triangles.push_back(Triangle3(mVertices[i], mVertices[j], mVertices[k])); 
     543                if (0) // matt: I don't know why i made it like this because the normals are wrong!!  
     544                        triangles.push_back(Triangle3(mVertices[i], mVertices[j], mVertices[k])); 
     545                else 
     546                        triangles.push_back(Triangle3(mVertices[k], mVertices[j], mVertices[i])); 
    542547 
    543548                if ((count ++) % 2) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1416 r1418  
    788788 
    789789 
    790 bool Preprocessor::InitRayCast(const string externKdTree) 
    791 { 
    792         bool loadKdTree, exportKdTree; 
    793  
     790bool Preprocessor::InitRayCast(const string externKdTree, const string internkdtree) 
     791{ 
     792        bool loadKdTree; 
    794793        Environment::GetSingleton()->GetBoolValue("Preprocessor.loadKdTree", loadKdTree); 
    795         Environment::GetSingleton()->GetBoolValue("Preprocessor.exportKdTree", exportKdTree); 
    796  
    797         char kdtreename[100]; 
    798         Environment::GetSingleton()->GetStringValue("Preprocessor.kdTreeFilename", kdtreename); 
    799  
    800794         
    801795        if (!loadKdTree) 
    802         {       ////// 
     796        {        
    803797                //-- build new kd tree from scene geometry 
    804798                BuildKdTree(); 
     
    808802        { 
    809803                const long startTime = GetTime(); 
    810                 cout << "loading kd tree file " << kdtreename << " ... "; 
    811  
    812                 if (!LoadKdTree(kdtreename)) 
     804                cout << "loading kd tree file " << internkdtree << " ... "; 
     805 
     806                if (!LoadKdTree(internkdtree)) 
    813807                { 
    814                         cout << "error loading kd tree with filename " << kdtreename << endl; 
    815                         return false; 
     808                        cout << "error loading kd tree with filename " << internkdtree << ", rebuilding it instead ..." << endl; 
     809 
     810                        BuildKdTree(); 
     811                        KdTreeStatistics(cout); 
    816812                } 
    817813 
     
    827823                                delete exporter; 
    828824                        } 
    829                 } 
    830         } 
    831  
    832         if (exportKdTree) 
    833         { 
    834                 const long startTime = GetTime(); 
    835                 cout << "exporting kd tree ... "; 
    836                 if (!ExportKdTree(kdtreename)) 
    837                 { 
    838                         cout << " error exporting kd tree with filename " << kdtreename << endl; 
    839                 } 
    840                 else 
    841                 { 
    842                         cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    843825                } 
    844826        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h

    r1415 r1418  
    168168  GlRendererBuffer *GetRenderer() { return renderer;} 
    169169 
    170   bool InitRayCast(const string externKdTree); 
     170  bool InitRayCast(const string externKdTree, const string internKdTree); 
    171171 
    172172  int CastRay( 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp

    r1291 r1418  
    130130{ 
    131131        DEL_PTR(mPvs); 
     132 
     133        VssRayContainer::const_iterator vit, vit_end = mVssRays.end(); 
     134        for (vit = mVssRays.begin(); vit != vit_end; ++ vit) 
     135        { 
     136                VssRay *ray = *vit; 
     137                ray->Unref(); 
     138 
     139                if (!ray->IsActive()) 
     140                        delete ray; 
     141        } 
    132142} 
    133143 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1416 r1418  
    181181 
    182182 
    183  
    184         Debug << "************ View Cells options ***************" << endl; 
     183        Debug << "************ View Cells Manager options ***************" << endl; 
    185184        Debug << "color code: " << mColorCode << endl; 
    186185 
     
    211210        Debug << "export bounding boxes: " << mExportBboxesForPvs << endl; 
    212211        Debug << "export pvs for view cells: " << mExportPvs << endl; 
    213          
    214212        Debug << endl; 
    215213} 
     
    511509 
    512510 
    513 AxisAlignedPlane * ViewCellsManager::GetClipPlane() 
     511AxisAlignedPlane *ViewCellsManager::GetClipPlane() 
    514512{ 
    515513        return mUseClipPlaneForViz ? &mClipPlaneForViz : NULL; 
     
    16961694        int axis = 0; 
    16971695        float pos; 
     1696        bool orientation; 
     1697        Vector3 absPos; 
    16981698 
    16991699        Environment::GetSingleton()->GetFloatValue("ViewCells.Visualization.clipPlanePos", pos); 
    1700         Vector3 absPos = mViewSpaceBox.Min() +  mViewSpaceBox.Size() * pos; 
    1701          
    17021700        Environment::GetSingleton()->GetIntValue("ViewCells.Visualization.clipPlaneAxis", axis); 
    17031701 
     1702        if (axis < 0)  
     1703        { 
     1704                axis = -axis; 
     1705                orientation = false; 
     1706                absPos = mViewSpaceBox.Max() -  mViewSpaceBox.Size() * pos; 
     1707        } 
     1708        else 
     1709        { 
     1710                orientation = true; 
     1711                absPos = mViewSpaceBox.Min() +  mViewSpaceBox.Size() * pos; 
     1712        } 
     1713 
    17041714        mClipPlaneForViz = AxisAlignedPlane(axis, absPos[axis]); 
     1715        mClipPlaneForViz.mOrientation = orientation; 
    17051716} 
    17061717 
     
    26582669 
    26592670         
    2660         ///////////////////////////////////////// 
     2671        //////////////////////// 
    26612672        //-- visualization and statistics 
    26622673 
     
    27292740        if (1) FinalizeViewCells(true); 
    27302741 
    2731         // write view cells to disc 
    2732         if (mExportViewCells) 
     2742        // write view cells to disc (this moved to preprocessor) 
     2743        if (0 && mExportViewCells) 
    27332744        { 
    27342745                char filename[100]; 
     
    28432854 
    28442855        // sort view cells in order to find the largest view cells 
    2845         if (0) 
    2846                 stable_sort(mViewCells.begin(), mViewCells.end(), ViewCell::SmallerPvs); 
     2856        if (0) stable_sort(mViewCells.begin(), mViewCells.end(), ViewCell::SmallerPvs); 
    28472857 
    28482858        int limit = min(leafOut, (int)mViewCells.size()); 
     
    38403850        } 
    38413851 
    3842  
    38433852        // view cells already finished before post processing step  
    38443853        // (i.e. because they were loaded) 
     
    38853894        if (0) FinalizeViewCells(false); 
    38863895                 
    3887         ////////////////////////////////////// 
     3896        ////////////////// 
    38883897        //-- merge the individual view cells 
    38893898        MergeViewCells(postProcessRays, objects); 
     
    38933902        if (0) RefineViewCells(postProcessRays, objects); 
    38943903 
    3895         /////////////////////////////////////////// 
     3904        ////////////////// 
    38963905        //-- render simulation after merge + refine 
    38973906 
     
    39043913         
    39053914 
    3906         /////////////////// 
     3915        //////////// 
    39073916        //-- compression 
    39083917 
     
    39273936        // compute final meshes and volume / area 
    39283937        if (1) FinalizeViewCells(true); 
    3929  
     3938cout << "here09*******************" << endl; 
    39303939        // write view cells to disc 
    3931         if (mExportViewCells) 
    3932         { 
     3940        if (0 && mExportViewCells) 
     3941        {cout << "here77*******************" << endl; 
    39333942                char filename[100]; 
    39343943                Environment::GetSingleton()->GetStringValue("ViewCells.filename", filename); 
     
    48324841        } 
    48334842 
    4834  
    4835         // take this step only if  
    4836         // view cells already constructed before post processing step  
    4837         // (e.g., because they were loaded) 
     4843        // if view cells were already constructed before post processing step  
     4844        // (e.g., because they were loaded), we are finished 
    48384845        if (mViewCellsFinished) 
    48394846        { 
     
    48814888        mViewCellsTree->SetRoot(root); 
    48824889 
    4883         //////////////////////////////////// 
     4890 
     4891        ////////////////////////// 
    48844892        //-- update pvs in the whole hierarchy 
    48854893        ObjectPvs pvs; 
     
    48874895 
    48884896 
    4889         /////////////////////////////////////////// 
     4897        ////////////////////// 
    48904898        //-- render simulation after merge + refine 
    48914899 
     
    48964904        cout << ss << endl; 
    48974905         
    4898         /////////////////////// 
     4906        /////////////// 
    48994907        //-- compression 
    49004908 
     
    49104918        } 
    49114919 
    4912         ///////////////////////////////////// 
     4920        /////////////// 
    49134921        //-- compute final meshes and volume / area 
    49144922        if (1) FinalizeViewCells(true); 
    49154923 
    4916  
    4917         // write out view cells 
    4918         if (mExportViewCells) 
    4919         { 
     4924        // write out view cells (this moved to preprocessor) 
     4925        if (0 && mExportViewCells) 
     4926        { 
     4927                cout << "here5" << endl; 
    49204928                char filename[100]; 
    49214929                Environment::GetSingleton()->GetStringValue("ViewCells.filename", filename); 
     
    50055013{ 
    50065014        ViewCellContainer leaves; 
    5007  
    50085015        mViewCellsTree->CollectLeaves(vc, leaves); 
    50095016        ViewCellContainer::const_iterator it, it_end = leaves.end(); 
    50105017 
    50115018        Plane3 plane; 
    5012  
    50135019        if (clipPlane) 
     5020        { 
     5021                // arbitrary plane definition 
    50145022                plane = clipPlane->GetPlane(); 
     5023        } 
    50155024 
    50165025        for (it = leaves.begin(); it != it_end; ++ it) 
     
    50225031                        mHierarchyManager->GetVspTree()->GetBoundingBox(vspVc->mLeaf); 
    50235032                 
    5024                 if (!Overlap(*sceneBox, box)) 
     5033                if (sceneBox && !Overlap(*sceneBox, box)) 
    50255034                        continue; 
    50265035 
     
    50335042                        else if (box.Side(plane) == 0) 
    50345043                        { 
     5044                                // intersection 
    50355045                                AxisAlignedBox3 fbox, bbox; 
    5036                                 bbox.Split(clipPlane->mAxis, clipPlane->mPosition, fbox, bbox); 
    5037  
     5046                                box.Split(clipPlane->mAxis, clipPlane->mPosition, fbox, bbox); 
    50385047                                exporter->ExportBox(bbox); 
    50395048                        } 
     
    50835092                        cout << "exporting final view cells (after initial construction + post process) ... "; 
    50845093 
    5085                         // matt: hack 
     5094                        // matt: hack for clamping scene 
    50865095                        AxisAlignedBox3 bbox = mHierarchyManager->GetViewSpaceBox(); 
    50875096                        bbox.Scale(Vector3(0.5, 1, 0.5)); 
    5088  
    5089                         if (mExportGeometry) 
     5097                         
     5098                        exporter->SetWireframe();  
     5099                        exporter->ExportBox(bbox); 
     5100                        exporter->SetFilled();  
     5101 
     5102                                 
     5103                        if (0 && mExportGeometry) 
    50905104                        { 
    50915105                                exporter->ExportGeometry(objects, true, &bbox); 
     
    50975111                                exporter->ExportRays(visRays, RgbColor(0, 1, 0)); 
    50985112                        } 
    5099  
     5113                 
     5114                        mHierarchyManager->ExportObjectSpaceHierarchy(exporter, objects, &bbox, false); 
    51005115                        ExportViewCellsForViz(exporter, &bbox, GetClipPlane()); 
    5101                  
    51025116                        delete exporter; 
    51035117                        cout << "finished in " << TimeDiff(starttime, GetTime()) * 1e-3f << " secs" << endl; 
     
    51455159        Debug << "\nOutput view cells: " << endl; 
    51465160 
    5147         const bool sortViewCells = true; 
    5148  
    5149         if (sortViewCells) 
    5150         { 
    5151                 //stable_sort(mViewCells.begin(), mViewCells.end(), ViewCell::SmallerPvs); 
     5161        const bool sortedViewCells = false; 
     5162 
     5163        if (sortedViewCells) 
     5164        { 
    51525165                // sort view cells to visualize the view cells with highest render cost 
    51535166                stable_sort(mViewCells.begin(), mViewCells.end(), ViewCell::LargerRenderCost); 
     
    51575170        int raysOut = 0; 
    51585171 
    5159         /////////////////////////// 
     5172        /////////////// 
    51605173        //-- some rays for output 
    51615174         
     
    51635176        { 
    51645177                cout << "creating output for view cell " << i << " ... "; 
    5165  
    5166                 ViewCell *vc; 
    5167          
    5168                 if (sortViewCells) // largest view cell pvs first 
    5169                         vc = mViewCells[i]; 
    5170                 else // random view cell 
    5171                         vc = mViewCells[(int)RandomValue(0, (float)mViewCells.size() - 1)]; 
    5172  
     5178                 
     5179                // largest view cell pvs first of random view cell 
     5180                ViewCell *vc = sortedViewCells ?  
     5181                        mViewCells[i] : mViewCells[(int)RandomValue(0, (float)mViewCells.size() - 1)]; 
     5182                 
    51735183                ObjectPvs pvs; 
    51745184                mViewCellsTree->GetPvs(vc, pvs); 
     
    51795189                Debug << i << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc) << endl; 
    51805190 
     5191                //////////// 
    51815192                //-- export the sample rays 
     5193 
    51825194                if (1 || mExportRays) 
    51835195                { 
     
    51995211                                { 
    52005212                                        VspLeaf *vcLeaf = dynamic_cast<VspViewCell *>(*vit)->mLeaf; 
    5201                                  
    52025213                                        VssRayContainer::const_iterator rit, rit_end = vcLeaf->mVssRays.end(); 
    52035214 
     
    52125223                                for (rit = collectRays.begin(); rit != rit_end; ++ rit) 
    52135224                                { 
    5214                                         float p = RandomValue(0.0f, (float)collectRays.size()); 
     5225                                        const float p = RandomValue(0.0f, (float)collectRays.size()); 
    52155226                         
    52165227                                        if (p < raysOut) 
    52175228                                                vcRays.push_back(*rit); 
    52185229                                } 
    5219  
     5230                                 
    52205231                                //-- export rays piercing this view cell 
    52215232                                exporter->ExportRays(vcRays, RgbColor(1, 1, 1)); 
     5233 
     5234                                //-- export objects seen from the rays 
     5235                                Intersectable::NewMail(); 
     5236                VssRayContainer::const_iterator vcit, vcit_end = vcRays.end(); 
     5237                                for (vcit = vcRays.begin(); vcit != vcit_end; ++ vcit) 
     5238                                { 
     5239                                        VssRay *ray = *vcit; 
     5240                                        //Intersectable *obj = ray->mTerminationObject; 
     5241                                        Intersectable *obj = mHierarchyManager->GetIntersectable(*ray, true); 
     5242                                         
     5243                                        if (obj && !obj->Mailed()) 
     5244                                        { 
     5245                                                obj->Mail(); 
     5246                                        //      exporter->ExportIntersectable(obj); 
     5247                                        } 
     5248                                } 
    52225249                        } 
    5223                  
    5224                         // associate new rays with output view cell 
    5225                         if (0) 
    5226                         { 
    5227                                 VssRayContainer vcRays; 
    5228                                 raysOut = min((int)rays.size(), mVisualizationSamples); 
    5229  
    5230                                 // check whether we can add the current ray to the output rays 
    5231                                 for (int k = 0; k < raysOut; ++ k) 
    5232                                 { 
    5233                                         VssRay *ray = rays[k]; 
    5234                                         for     (int j = 0; j < (int)ray->mViewCells.size(); ++ j) 
    5235                                         { 
    5236                                                 ViewCell *rayvc = ray->mViewCells[j]; 
    5237          
    5238                                                 if (rayvc == vc) 
    5239                                                         vcRays.push_back(ray); 
    5240                                         } 
    5241                                 }        
    5242                                  
    5243                                 // export rays piercing this view cell 
    5244                                 exporter->ExportRays(vcRays, RgbColor(1, 1, 0)); 
    5245                         } 
    5246                 } 
    5247  
     5250                } 
    52485251 
    52495252                ///////////////// 
     
    52595262                exporter->SetFilled(); 
    52605263 
    5261 #if 0    
    5262                 ////////// 
    5263                 //-- export pvs 
    5264  
    5265                 Intersectable::NewMail(); 
    5266                 KdLeaf::NewMail(); 
    5267  
    5268                 vector<KdLeaf *> kdLeaves; 
    5269  
    5270                 ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end(); 
    5271  
    5272                 for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit) 
    5273                 {        
    5274                         Intersectable *obj = (*oit).first; 
    5275  
    5276                         if (obj->Type() == Intersectable::KD_INTERSECTABLE) 
    5277                         { 
    5278                                 m.mDiffuseColor = RgbColor(1, 1, 1); 
    5279                                 exporter->SetForcedMaterial(m); 
    5280  
    5281                                 // export bounding box of node 
    5282                                 KdIntersectable *kdObj  = dynamic_cast<KdIntersectable *>(obj); 
    5283                                 AxisAlignedBox3 box = mOspTree->GetBoundingBox(kdObj->GetItem()); 
    5284  
    5285                                 exporter->SetWireframe(); 
    5286                                 exporter->ExportBox(box); 
    5287                                 exporter->SetFilled(); 
    5288                         } 
    5289  
    5290                         m.mDiffuseColor = RgbColor(1, 0, 0); 
    5291                         exporter->SetForcedMaterial(m); 
    5292  
    5293                         // export pvs entry 
    5294                         if (!obj->Mailed()) 
    5295                         { 
    5296                                 exporter->ExportIntersectable(obj); 
    5297                                 obj->Mail(); 
    5298                         } 
    5299                 }                
    5300 #endif 
    5301          
    53025264                DEL_PTR(exporter); 
    53035265                cout << "finished" << endl; 
     
    53985360        if (!ViewCellsConstructed()) 
    53995361                return NULL; 
    5400  
    54015362        if (!mViewSpaceBox.IsInside(point)) 
    5402           return NULL; 
    5403  
     5363                return NULL; 
    54045364        return mHierarchyManager->GetVspTree()->GetViewCell(point, active); 
    54055365} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp

    r1302 r1418  
    12811281                if (madeContrib) 
    12821282                        ++ contributingSamples; 
    1283                  
    1284                 // note: vss rays are never deleted 
    1285                 if (0) leaf->mVssRays.push_back(new VssRay(*ray)); 
    12861283        } 
    12871284} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp

    r1415 r1418  
    305305{ 
    306306        DEL_PTR(mPvs); 
    307         CLEAR_CONTAINER(mVssRays); 
     307 
     308        VssRayContainer::const_iterator vit, vit_end = mVssRays.end(); 
     309        for (vit = mVssRays.begin(); vit != vit_end; ++ vit) 
     310        { 
     311                VssRay *ray = *vit; 
     312                ray->Unref(); 
     313 
     314                if (!ray->IsActive()) 
     315                        delete ray; 
     316        } 
     317        //CLEAR_CONTAINER(mVssRays); 
    308318} 
    309319 
     
    357367mRoot(NULL), 
    358368mOutOfBoundsCell(NULL), 
    359 mStoreRays(false), 
     369mStoreRays(true), 
    360370mTimeStamp(1), 
    361371mHierarchyManager(NULL) 
     
    588598        } 
    589599 
    590  
    591         //-- store additional info 
    592600        if (mStoreRays) 
    593601        { 
     602                /////////// 
     603                //-- store sampling rays 
    594604                RayInfoContainer::const_iterator it, it_end = tData.mRays->end(); 
    595605 
     
    684694 
    685695#if 0 
     696                ///////////// 
    686697                //-- store pvs optained from rays 
    687698                AddSamplesToPvs(leaf, *tData.mRays, sampCon, conSamp); 
     
    694705                mVspStats.sampleContributions += (int)sampCon; 
    695706#endif 
    696                 //-- store additional info 
    697707                if (mStoreRays) 
    698708                { 
     709                        ////////// 
     710                        //-- store rays piercing this view cell 
    699711                        RayInfoContainer::const_iterator it, it_end = tData.mRays->end(); 
    700712                        for (it = tData.mRays->begin(); it != it_end; ++ it) 
     
    702714                                (*it).mRay->Ref();                       
    703715                                leaf->mVssRays.push_back((*it).mRay); 
     716                                //leaf->mVssRays.push_back(new VssRay(*(*it).mRay)); 
    704717                        } 
    705718                } 
     
    767780        VspLeaf *leaf = dynamic_cast<VspLeaf *>(tData.mNode); 
    768781         
    769         //////////////////////////////////////////////////////// 
    770         //-- the front and back traversal data are filled with the new values 
     782        /////////////// 
     783        //-- new traversal values 
    771784 
    772785        frontData.mDepth = tData.mDepth + 1; 
     
    782795                          *backData.mRays); 
    783796 
     797        ///////////// 
    784798        //-- compute pvs 
    785799        frontData.mPvs = EvalPvsSize(*frontData.mRays); 
     
    27412755                        { 
    27422756                                leaf->Mail(); 
    2743                                 if (leaf->GetSubdivisionCandidate()) // a candidate still attached to this node 
     2757                                 // a candidate still attached to this node 
     2758                                if (leaf->GetSubdivisionCandidate()) 
    27442759                                { 
    27452760                                        dirtyList.push_back(leaf->GetSubdivisionCandidate()); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp

    r1414 r1418  
    331331 
    332332                bool exportViewCells = false; 
    333                  
    334333                if (exportViewCells) 
    335334                { 
     
    477476          mViewCellsManager->PrintStatistics(Debug); 
    478477  } 
    479 #if 1  
     478#if 0 
    480479  else  
    481480  {       
  • GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp

    r1415 r1418  
    238238                ApplyTransformations(mTransformations, &tempMesh); 
    239239 
    240                 FaceContainer::const_iterator fit, fit_end = tempMesh.mFaces.end(); 
    241  
    242                 for (fit = tempMesh.mFaces.begin(); fit != fit_end; ++ fit) 
     240                FaceContainer::const_iterator fit, fit_begin = tempMesh.mFaces.begin(),  
     241                        fit_end = tempMesh.mFaces.end(); 
     242                 
     243                for (fit = fit_begin; fit != fit_end; ++ fit) 
    243244                { 
    244245                        //cout << "f"; 
     
    253254                        for (tit = triangles.begin(); tit != tit_end; ++ tit) 
    254255                        { 
    255                                 //cout << "triangle: " << *tit << endl; 
    256256                                TriangleIntersectable *ti = new TriangleIntersectable(*tit); 
    257257                                mCurrentNode->mGeometry.push_back(ti); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp

    r1415 r1418  
    163163        } 
    164164 
    165         string rayCastFile = ReplaceSuffix(filename, ".obj", ".kdf"); 
     165 
     166        string externKdTree = ReplaceSuffix(filename, ".obj", ".kdf"); 
     167        char internKdTree[100]; 
     168        Environment::GetSingleton()->GetStringValue("Preprocessor.kdTreeFilename", internKdTree); 
    166169 
    167170        //-- initialize external ray casters 
    168         if (preprocessor->InitRayCast(rayCastFile)) 
     171        if (preprocessor->InitRayCast(externKdTree, internKdTree)) 
    169172        { 
    170173                cout << "ray casting initialized!" << endl; 
     
    175178                Cleanup(); 
    176179                exit(1); 
     180        } 
     181 
     182        // export kd tree? 
     183        bool exportKdTree; 
     184        Environment::GetSingleton()->GetBoolValue("Preprocessor.exportKdTree", exportKdTree); 
     185        if (exportKdTree) 
     186        { 
     187                const long startTime = GetTime(); 
     188                cout << "exporting kd tree ... "; 
     189 
     190                if (!preprocessor->ExportKdTree(internKdTree)) 
     191                { 
     192                        cout << " error exporting kd tree with filename " << internKdTree << endl; 
     193                } 
     194                else 
     195                { 
     196                        cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     197                } 
    177198        } 
    178199 
     
    198219#endif 
    199220 
    200          
    201221        bool guiSupported = false; 
    202222        if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger) 
Note: See TracChangeset for help on using the changeset viewer.