Changeset 2609


Ignore:
Timestamp:
01/17/08 21:46:32 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/include/Mesh.h

    r68 r2609  
    1616  }; 
    1717 
    18   /** Mesh containing polygonal patches */ 
     18  /** Mesh containing polygonal patches  
     19  */ 
    1920  class Mesh { 
    2021  public: 
  • GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp

    r2582 r2609  
    22382238void AxisAlignedBox3::EnlargeToMinSize() 
    22392239{ 
    2240   const float epsMin = 1e-7; 
    2241   const float epsAdd = 1e-6; 
    2242   const float epsMul = 1.000005; 
     2240  const float epsMin = 1e-7f; 
     2241  const float epsAdd = 1e-6f; 
     2242  const float epsMul = 1.000005f; 
    22432243  float dir = mMax.x - mMin.x; 
     2244 
    22442245  assert(dir >= 0.f); 
    22452246  if (dir < epsMin) { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h

    r2588 r2609  
    215215         
    216216        int CastRay(Ray &ray) { return 0; } 
    217         int CastSimpleRay(const SimpleRay &ray) { return 0;} 
    218         int CastSimpleRay(const SimpleRay &ray, int IndexRay) { return 0;} 
     217        int CastSimpleRay(const SimpleRay &ray) { return 0;} 
     218        int CastSimpleRay(const SimpleRay &ray, int IndexRay) { return 0;} 
    219219         
    220220        bool IsConvex() const { return true; } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Containers.h

    r2176 r2609  
    1010namespace GtpVisibilityPreprocessor { 
    1111 
     12class TransformedMeshInstance; 
    1213class ViewCell; 
    1314class HierarchyNode; 
     
    7172typedef std::vector<int> VertexIndexContainer; 
    7273 
     74/// a container for dynamic objects 
     75typedef std::vector<TransformedMeshInstance *> DynamicObjectsContainer; 
     76 
     77 
    7378} 
    7479 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp

    r2604 r2609  
    133133void GlRenderer::RenderTriangle(TriangleIntersectable *object) 
    134134{ 
    135   Triangle3 *t = &(object->GetItem()); 
     135        Triangle3 *t = &(object->GetItem()); 
    136136 
    137137        glBegin(GL_TRIANGLES); 
     
    317317 
    318318        glPushMatrix(); 
    319  
    320319        glMultMatrixf((float *)m.x); 
    321320 
     
    494493        Intersectable::NewMail(); 
    495494 
     495        Preprocessor *p = mViewCellsManager->GetPreprocessor(); 
     496        // handle dynamic objects 
     497        DynamicObjectsContainer::const_iterator dit, dit_end = p->mDynamicObjects.end(); 
     498 
     499        for (dit = p->mDynamicObjects.begin(); dit != dit_end; ++ dit) 
     500        { 
     501                RenderIntersectable(*dit); 
     502        } 
     503 
    496504#if 1 
    497  
    498505        _RenderSceneTrianglesWithDrawArrays(); 
    499506 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp

    r2176 r2609  
    5656 
    5757}; 
     58 
     59 
     60Mesh::Mesh(const int vertices, const int faces): 
     61mFaces(), 
     62mMaterial(NULL), 
     63mKdTree(NULL), 
     64mVertices(), 
     65mIsConvex(false), 
     66mIsWatertight(false), 
     67mId(0) 
     68{ 
     69        mVertices.reserve(vertices); 
     70        mFaces.reserve(faces); 
     71} 
    5872 
    5973 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h

    r2575 r2609  
    6262 
    6363/** Mesh containing polygonal patches */ 
    64 class Mesh { 
     64class Mesh  
     65{ 
    6566 
    6667public: 
    6768 
    6869  /// Default constructor 
    69   Mesh():mVertices(), mFaces(), mMaterial(NULL), mKdTree(NULL), mId(0) {} 
     70  Mesh(): mVertices(), mFaces(), mMaterial(NULL), mKdTree(NULL), mId(0) {} 
    7071 
    7172  /// Constructor with container preallocation 
    72   Mesh(const int vertices, const int faces): 
    73     mFaces(), 
    74     mMaterial(NULL), 
    75     mKdTree(NULL), 
    76     mVertices(), 
    77     mIsConvex(false), 
    78     mIsWatertight(false), 
    79         mId(0) 
    80   { 
    81     mVertices.reserve(vertices); 
    82     mFaces.reserve(faces); 
    83   } 
    84  
     73  Mesh(const int vertices, const int faces); 
    8574  /** Constructor setting a unqiue mesh id. 
    8675  */ 
    8776  Mesh(const int id); 
    88  
    8977  /** Setting unique mesh id and using preallocation. 
    9078  */ 
    9179  Mesh(const int id, const int vertices, const int faces); 
    92  
    9380  /** Copy constructor making a deep copy of the faces. 
    9481  */ 
    9582  Mesh(const Mesh &rhs); 
    96  
    9783  /** Assignement operator. 
    9884        @note does not copy id 
     
    116102  void AddFace(Face *face)  
    117103  { 
    118     mFaces.push_back(face); 
     104          mFaces.push_back(face); 
    119105  } 
    120106 
    121107  void ComputeBoundingBox(); 
    122  
    123108  /** This function must be called after creating the mesh 
    124109        because it creates the local kd tree and the bounding box. 
     
    132117  void ApplyTransformation(const Matrix4x4 &m); 
    133118 
    134   /** Axis aligned bounding box of the mesh in local mesh coordinates. 
    135   */ 
    136   AxisAlignedBox3 mBox; 
    137    
    138   /** Vertices forming the mesh. 
    139   */ 
     119  /// Axis aligned bounding box of the mesh in local mesh coordinates. 
     120  AxisAlignedBox3 mBox;  
     121  /// Vertices forming the mesh. 
    140122  VertexContainer mVertices; 
    141    
    142   /** Patches forming the mesh. 
    143   */ 
     123  /// Patches forming the mesh. 
    144124  FaceContainer mFaces; 
    145    
    146   /** Global mesh material. 
    147   */ 
     125  /// Global mesh material. 
    148126  Material *mMaterial; 
    149    
    150   /** true if the mesh is a convex mesh. 
    151   */ 
     127  /// true if the mesh is a convex mesh. 
    152128  bool mIsConvex; 
    153  
    154   /** true if the mesh is a convex mesh. 
    155   */ 
     129  /// true if the mesh is a convex mesh. 
    156130  bool mIsWatertight; 
    157131 
     
    202176  /** Returns unique mesh id. 
    203177  */ 
    204   int GetId() const 
    205   { 
    206           return mId; 
    207   } 
     178  int GetId() const { return mId; } 
    208179 
    209180 
     
    245216 
    246217public: 
    247         MeshInstance(Mesh *mesh):Intersectable(), mMesh(mesh), mMaterial(NULL) 
     218        MeshInstance(Mesh *mesh): Intersectable(), mMesh(mesh), mMaterial(NULL) 
    248219        { 
    249220        } 
     
    315286{ 
    316287public: 
    317   TransformedMeshInstance(Mesh *mesh); 
    318    
    319   virtual AxisAlignedBox3 GetBox() const; 
    320     
    321    
    322   virtual int CastRay(Ray &ray); 
    323  
    324   virtual int CastRay(Ray &ray, const std::vector<int> &faces); 
    325  
    326   virtual int Type() const { return TRANSFORMED_MESH_INSTANCE; } 
    327  
    328   int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); 
    329  
    330   /** Transforms this mesh instance by m. 
    331   */ 
    332   void ApplyWorldTransform(const Matrix4x4 &m); 
    333  
    334   /** Loads the transformation matrix into this mesh instance. 
    335   */ 
    336   void LoadWorldTransform(const Matrix4x4 &m); 
    337  
    338   /** The transformation is returned in m. 
    339   */ 
    340   void GetWorldTransform(Matrix4x4 &m) const; 
    341  
    342   /** Transforms a mesh according to the stored world transform. 
    343           @param transformedMesh returns the tranformed mesh. 
    344   */ 
    345   void GetTransformedMesh(Mesh &transformedMesh) const; 
    346  
    347   Vector3 GetNormal(const int idx) const; 
     288        TransformedMeshInstance(Mesh *mesh); 
     289 
     290        virtual AxisAlignedBox3 GetBox() const; 
     291 
     292        virtual int CastRay(Ray &ray); 
     293 
     294        virtual int CastRay(Ray &ray, const std::vector<int> &faces); 
     295 
     296        virtual int Type() const { return TRANSFORMED_MESH_INSTANCE; } 
     297 
     298        int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); 
     299 
     300        /** Transforms this mesh instance by m. 
     301        */ 
     302        void ApplyWorldTransform(const Matrix4x4 &m); 
     303        /** Loads the transformation matrix into this mesh instance. 
     304        */ 
     305        void LoadWorldTransform(const Matrix4x4 &m); 
     306        /** The transformation is returned in m. 
     307        */ 
     308        void GetWorldTransform(Matrix4x4 &m) const; 
     309        /** Transforms a mesh according to the stored world transform. 
     310                @param transformedMesh returns the tranformed mesh. 
     311        */ 
     312        void GetTransformedMesh(Mesh &transformedMesh) const; 
     313 
     314        Vector3 GetNormal(const int idx) const; 
    348315 
    349316protected: 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r2606 r2609  
    115115        DEL_PTR(mViewCellsManager); 
    116116        cout << "done.\n"; 
    117  
    118117         
    119118        cout << "Deleting bsp tree ... \n"; 
     
    136135        DEL_PTR(mRenderSimulator); 
    137136        mRenderSimulator = NULL; 
     137 
    138138        cout << "deleting renderer ... \n"; 
    139139        DEL_PTR(renderer); 
    140140        renderer = NULL; 
     141 
    141142        cout << "deleting ray caster ... \n"; 
    142143        DEL_PTR(mRayCaster); 
     
    10931094                               const string &internKdTree) 
    10941095{ 
    1095         // always try to load the kd tree 
    1096 /*      cout << "loading kd tree file " << internKdTree << " ... " << endl; 
    1097  
    1098         if (!LoadKdTree(internKdTree)) 
    1099         { 
    1100                 cout << "error loading kd tree with filename "  
    1101                          << internKdTree << ", rebuilding it instead ... " << endl; 
    1102                 // build new kd tree from scene geometry 
    1103                 BuildKdTree(); 
    1104  
    1105                 // export kd tree? 
    1106                 const long startTime = GetTime(); 
    1107                 cout << "exporting kd tree ... "; 
    1108  
    1109                 if (!ExportKdTree(internKdTree)) 
    1110                 { 
    1111                         cout << " error exporting kd tree with filename "  
    1112                                  << internKdTree << endl; 
    1113                 } 
    1114                 else 
    1115                 { 
    1116                         cout << "finished in "  
    1117                                  << TimeDiff(startTime, GetTime()) * 1e-3  
    1118                                  << " secs" << endl; 
    1119                 } 
    1120         } 
    1121          
    1122         KdTreeStatistics(cout); 
    1123         cout << mKdTree->GetBox() << endl; 
    1124 */ 
    11251096        int rayCastMethod; 
    11261097        Environment::GetSingleton()-> 
     
    12041175                                           ) 
    12051176{ 
    1206  
    12071177        const long t1 = GetTime(); 
    12081178 
     
    12341204                        castDoubleRays, 
    12351205                        pruneInvalidRays); 
     1206 
     1207#if DYNAMIC_OBJECTS_HACK 
     1208 
     1209                static Ray hRay; 
     1210 
     1211                VssRayContainer::iterator vit, vit_end = vssRays.end(); 
     1212 
     1213                for (vit = vssRays.begin(); vit != vit_end; ++ vit) 
     1214                { 
     1215                        VssRay *vssRay = *vit; 
     1216                        hRay.Init(*vssRay); 
     1217 
     1218                        DynamicObjectsContainer::const_iterator tit, tit_end = mDynamicObjects.end(); 
     1219 
     1220                        bool foundIntersect = false; 
     1221                        for (tit = mDynamicObjects.begin(); tit != tit_end; ++ tit) 
     1222                        { 
     1223                                TransformedMeshInstance *tmi = *tit; 
     1224                                if (tmi->CastRay(hRay)) //cout << "z"; else cout<< "r"; 
     1225                                { 
     1226                                        cout << "i: " << Intersectable::GetTypeName(hRay.intersections[0].mObject); 
     1227                                        foundIntersect = true; 
     1228                                } 
     1229                        } 
     1230 
     1231                        if (foundIntersect) 
     1232                                cout << "x: " << Intersectable::GetTypeName(hRay.intersections[0].mObject); 
     1233 
     1234                        if (foundIntersect) 
     1235                                // write new results back into vssRay 
     1236                                vssRay->Init(hRay); 
     1237 
     1238                        if (foundIntersect) 
     1239                                cout << "y : " << Intersectable::GetTypeName(vssRay->mTerminationObject); 
     1240 
     1241                        hRay.intersections.clear(); 
     1242                } 
     1243#endif 
    12361244        } 
    12371245 
     
    15951603 
    15961604 
    1597 bool Preprocessor::AddGeometry(const string &filename, 
    1598                                                            ObjectContainer &pvsObjects,  
    1599                                                            const ObjectContainer &preprocessorObjects) 
    1600 { 
    1601 //      bool success = LoadBinaryObj(filename, mSceneGraph->GetRoot(), &mFaceParents); 
    1602         SceneGraphLeaf *leaf = new SceneGraphLeaf(); 
    1603         if (LoadBinaryObj(filename, leaf, NULL)) 
    1604         { 
     1605Mesh *Preprocessor::LoadBinaryObjIntoMesh(const string &filename) 
     1606{ 
     1607        igzstream inStream(filename.c_str()); 
     1608         
     1609        if (!inStream.is_open()) 
     1610                return NULL; 
     1611 
     1612        cout << "binary obj dump available, loading " << filename.c_str() << endl; 
     1613         
     1614        // read in triangle size 
     1615        int numTriangles; 
     1616 
     1617        inStream.read(reinterpret_cast<char *>(&numTriangles), sizeof(int)); 
     1618         
     1619        cout << "loading " << numTriangles << " triangles into mesh" << endl; 
     1620 
     1621        int i = 0, j = 0; 
     1622 
     1623        Mesh *mesh = new Mesh(numTriangles * 3, numTriangles); 
     1624 
     1625        const int t = 500000; 
     1626        while (1) 
     1627        { 
     1628                Triangle3 tri; 
     1629                 
     1630                inStream.read(reinterpret_cast<char *>(&mesh->mVertices[i]), sizeof(Vector3)); 
     1631                inStream.read(reinterpret_cast<char *>(&mesh->mVertices[i + 1]), sizeof(Vector3)); 
     1632                inStream.read(reinterpret_cast<char *>(&mesh->mVertices[i + 2]), sizeof(Vector3)); 
     1633 
     1634                 
     1635                mesh->mVertices[i].x += 20; 
     1636                mesh->mVertices[i + 1].x += 20; 
     1637                mesh->mVertices[i + 2].x += 20; 
     1638 
     1639                mesh->mVertices[i].z -= 10; 
     1640                mesh->mVertices[i + 1].z -= 10; 
     1641                mesh->mVertices[i + 2].z -= 10; 
     1642 
     1643                mesh->mVertices[i] *= 50; 
     1644                mesh->mVertices[i + 1] *= 50; 
     1645                mesh->mVertices[i + 2] *= 50; 
     1646 
     1647                mesh->AddFace(new Face(i + 0, i + 1, i + 2)); 
     1648 
     1649                // end of file reached 
     1650                if (inStream.eof()) 
     1651                        break; 
     1652 
     1653                i += 3; 
     1654                if (((j ++) % t) == (t - 1)) 
     1655                         cout<<"\r"<<i<<"/"<<numTriangles<<"\r"; 
     1656        } 
     1657         
     1658        if (j != numTriangles) 
     1659        { 
     1660                cout << "warning: triangle size does not match with loaded triangle size" << endl; 
     1661                return false; 
     1662        } 
     1663 
     1664        mesh->Preprocess(); 
     1665        cout << "loaded " << numTriangles << " triangles" << endl; 
     1666 
     1667        return mesh; 
     1668} 
     1669 
     1670 
     1671bool Preprocessor::LoadDynamicGeometry(const string &filename) 
     1672{ 
     1673        const bool dynamic = true; 
     1674 
     1675        Mesh *mesh = LoadBinaryObjIntoMesh(filename); 
     1676     
     1677        if (mesh) 
     1678        { 
     1679                SceneGraphLeaf *leaf = new SceneGraphLeaf(dynamic); 
     1680 
     1681                TransformedMeshInstance *tmi = new TransformedMeshInstance(mesh); 
     1682                leaf->mGeometry.push_back(tmi); 
     1683 
    16051684                mSceneGraph->GetRoot()->mChildren.push_back(leaf); 
     1685                //mDynamicObjects.push_back(leaf); 
     1686                mDynamicObjects.push_back(tmi); 
     1687 
    16061688                return true; 
    16071689        } 
    16081690 
     1691 
    16091692        return false; 
    16101693} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h

    r2600 r2609  
    5858 
    5959        virtual ~Preprocessor(); 
    60  
    6160        /** Load the input scene.  
    6261                @param filename file to load 
     
    6463        */ 
    6564        virtual bool LoadScene(const string &filename); 
    66  
    6765        /** Export all preprocessed data in a XML format understandable by the 
    6866                PreprocessingInterface of the GtpVisibilityPreprocessor Module.  
     
    7169        */ 
    7270        virtual bool ExportPreprocessedData(const string &filename); 
    73  
    7471        /** Build the KdTree of currently loaded occluders/occludees/viewcells. The construction 
    7572                is driven by the environment settings, which also sais which of the three types of 
     
    7774        */ 
    7875        virtual bool BuildKdTree(); 
    79  
    8076        /** Compute visibility method. This method has to be reimplemented by the actual 
    8177                Preprocessor implementation (e.g. SamplingPreprocessor, ExactPreprocessor, 
     
    8379        */ 
    8480        virtual bool ComputeVisibility() = 0; 
    85  
    8681        /** Post Process the computed visibility. By default applys the visibility filter 
    8782                (if specified in the environment and export the preprocessed data  
    88                 */ 
     83        */ 
    8984        virtual bool PostProcessVisibility(); 
    90  
    9185        /** View cells are either loaded or prepared for generation, according to the chosen environment 
    9286                object. Important evironment options are, e.g, the view cell type. 
     
    9488        */ 
    9589        bool PrepareViewCells(); 
    96  
    9790        /** Construct viewcells from the scratch  
    9891        */ 
    9992        bool ConstructViewCells(); 
    100  
    10193        /** Returns the specified sample strategy, NULL if no valid strategy. 
    10294        */ 
    10395        SamplingStrategy *GenerateSamplingStrategy(const int strategyId); 
    104  
    10596        /** Export preprocessor data. 
    10697        */ 
     
    198189                                                        const ObjectContainer &preprocessorObject); 
    199190 
    200         /** Adds new geometry to the existing one. 
    201         */ 
    202         bool AddGeometry(const string &filename, ObjectContainer &pvsObjects, const ObjectContainer &prepObjects); 
     191        /** Adds dynamic geometry 
     192        */ 
     193        bool LoadDynamicGeometry(const string &filename); 
     194 
     195        Mesh *Preprocessor::LoadBinaryObjIntoMesh(const string &filename); 
     196 
    203197 
    204198        ///////////////////////// 
     
    212206        /// kD-tree organizing the scene graph (occluders + occludees) + viewcells 
    213207        KdTree *mKdTree; 
    214   AxisAlignedBox3 sceneBox; 
     208        AxisAlignedBox3 sceneBox; 
     209 
    215210        /// View space partition bsp tree 
    216211        VspBspTree *mVspBspTree; 
     
    222217        /// list of all loaded occludees 
    223218        ObjectContainer mOccludees; 
    224  
    225  
     219        /// the view cells manager 
    226220        ViewCellsManager *mViewCellsManager; 
     221 
     222        //SceneGraphNodeContainer mDynamicObjects; 
     223        DynamicObjectsContainer mDynamicObjects; 
    227224 
    228225        /// greedy optimized hierarchy for both objects and view cells 
  • GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp

    r2604 r2609  
    369369        glNormalPointer(GL_FLOAT, 0, (char *)arrayPtr + offset * sizeof(Vector3)); 
    370370        glDrawElements(GL_TRIANGLES, mIndexBufferSize, GL_UNSIGNED_INT, mIndices); 
    371 } 
    372  
    373  
    374 void QtGlRendererWidget::_UpdatePvsIndices() 
     371 
     372        // handle dynamic objects 
     373        DynamicObjectsContainer::const_iterator dit, dit_end = mDynamicObjects.end(); 
     374 
     375        for (dit = mDynamicObjects.begin(); dit != dit_end; ++ dit) 
     376        { 
     377                RenderIntersectable(*dit); 
     378        } 
     379} 
     380 
     381 
     382void QtGlRendererWidget::PreparePvs() 
    375383{ 
    376384        int indexBufferSize = 0; 
     
    381389        mPvsSize = mPvsCache.mPvs.GetSize(); 
    382390 
     391        mDynamicObjects.clear(); 
     392 
    383393        ObjectPvsIterator it = mPvsCache.mPvs.GetIterator(); 
    384394 
     
    386396        { 
    387397                Intersectable *obj = it.Next(); 
    388                 KdNode *node = static_cast<KdIntersectable *>(obj)->GetItem(); 
    389  
    390                 _UpdatePvsIndices(node, indexBufferSize); 
     398                switch (obj->Type()) 
     399                { 
     400                case Intersectable::KD_INTERSECTABLE: 
     401                        { 
     402                                KdNode *node = static_cast<KdIntersectable *>(obj)->GetItem(); 
     403                                _UpdatePvsIndices(node, indexBufferSize); 
     404                        } 
     405                        break; 
     406                case Intersectable::TRANSFORMED_MESH_INSTANCE: 
     407                        mDynamicObjects.push_back(static_cast<TransformedMeshInstance *>(obj)); 
     408                        break; 
     409                default: 
     410                        cerr << "PreparePvs: type " << Intersectable::GetTypeName(obj) << " not handled yet" << endl; 
     411                } 
    391412        } 
    392413 
     
    421442                                static_cast<TriangleIntersectable *>(leaf->mObjects[i]); 
    422443 
    423                         // check if already rendered 
    424                         /*if (!obj->Mailed()) 
    425                         { 
    426                                 obj->Mail(); 
    427  
    428                                 mIndices[indexBufferSize + 0] = (obj->GetId() - 1) * 3 + 0; 
    429                                 mIndices[indexBufferSize + 1] = (obj->GetId() - 1) * 3 + 1; 
    430                                 mIndices[indexBufferSize + 2] = (obj->GetId() - 1) * 3 + 2; 
    431  
    432                                 indexBufferSize += 3; 
    433                         }*/ 
    434444                        if (obj->mRenderedFrame != mCurrentFrame) 
    435445                        { 
     
    481491                        if (mUseSpatialFilter)  
    482492                        { 
    483                                 //ObjectPvs pvs; 
    484  
    485493                                //mMutex.lock(); 
    486494                                // mSpatialFilter size is in range 0.001 - 0.1 
     
    500508 
    501509                        /// update the indices for rendering 
    502                         _UpdatePvsIndices(); 
     510                        PreparePvs(); 
    503511 
    504512                        emit PvsUpdated(); 
    505513                } 
    506514 
    507                 //Intersectable::NewMail(); 
    508                 PvsData pvsData; 
    509515 
    510516                // Render PVS 
     
    519525                { 
    520526                        if (!mRenderVisibilityEstimates && !mUseRandomColorPerPvsObject) 
    521                         { 
    522527                                _RenderPvs(); 
    523                         } 
    524528                        else 
    525                         { 
    526                                 mPvsSize = mPvsCache.mPvs.GetSize(); 
    527  
    528                                 ObjectPvsIterator it = mPvsCache.mPvs.GetIterator(); 
    529  
    530                                 while (it.HasMoreEntries()) 
    531                                 { 
    532                                         Intersectable *object = it.Next(pvsData); 
    533  
    534                                         RgbColor color; 
    535  
    536                                         //float visibility = mTransferFunction*log10(entry.mData.mSumPdf + 1); // /5.0f 
    537                                         // glColor3f(visibility, 0.0f, 0.0f); 
    538                                         //cerr << "sumpdf: " << pvsData.mSumPdf << endl; 
    539                                         if (mUseRandomColorPerPvsObject) 
    540                                         { 
    541                                                 KdIntersectable *kdint = static_cast<KdIntersectable *>(object); 
    542  
    543                                                 if (kdint->mGenericIdx == -1) 
    544                                                 { 
    545                                                         kdint->mGenericIdx = (int)mColors.size(); 
    546                                                         mColors.push_back(RandomColor()); 
    547                                                 } 
    548                                                 color = mColors[kdint->mGenericIdx]; 
    549                                         }  
    550                                         else 
    551                                         { 
    552                                                 color = RainbowColorMapping(mTransferFunction * log10(pvsData.mSumPdf + 1)); 
    553                                         } 
    554  
    555                                         glColor3f(color.r, color.g, color.b); 
    556  
    557                                         mUseForcedColors = true; 
    558                                         RenderIntersectable(object); 
    559                                         mUseForcedColors = false; 
    560                                 } 
    561                         } 
     529                                _RenderColoredPvs(); 
    562530                } 
    563531 
     
    587555                RenderScene(); 
    588556        } 
    589  
    590         //DisableDrawArrays(); 
    591         //glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); 
    592557} 
    593558 
     
    673638{ 
    674639        float MOVE_SENSITIVITY = Magnitude(mSceneGraph->GetBox().Diagonal())*1e-3; 
    675         float TURN_SENSITIVITY=0.1f; 
    676         float TILT_SENSITIVITY=32.0 ; 
    677         float TURN_ANGLE= M_PI/36.0 ; 
     640        float TURN_SENSITIVITY = 0.1f; 
     641        float TILT_SENSITIVITY = 32.0 ; 
     642        float TURN_ANGLE= M_PI  /36.0 ; 
    678643 
    679644        int x = e->pos().x(); 
     
    685650        if (e->modifiers() & Qt::ControlModifier)  
    686651        { 
    687                 mViewPoint.y += (y-mousePoint.y)*MOVE_SENSITIVITY/2.0; 
    688                 mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY/2.0; 
     652                mViewPoint.y += (y-mousePoint.y)*MOVE_SENSITIVITY / 2.0; 
     653                mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY / 2.0; 
    689654        }  
    690655        else  
     
    930895        connect(mControlWidget, SIGNAL(SetRandomViewPoint()), this,     SLOT(SetRandomViewPoint())); 
    931896        connect(mControlWidget, SIGNAL(StoreStatistics(void)), this, SLOT(StoreStatistics(void))); 
     897        connect(mControlWidget, SIGNAL(LoadObject(void)), this, SLOT(LoadObject(void))); 
    932898 
    933899        connect(mControlWidget, SIGNAL(SetSceneCut(int)), this, SLOT(SetSceneCut(int))); 
     
    1029995} 
    1030996 
     997 
     998void QtGlRendererWidget::LoadObject() 
     999{ 
     1000        string filename("../data/bunny.bn"); 
     1001         
     1002        cout << "Loading model << " << filename << endl; 
     1003 
     1004        if (mViewCellsManager->GetPreprocessor()->LoadDynamicGeometry(filename)) 
     1005                cout << "Loading finished" << endl; 
     1006        else 
     1007                cerr << "Loading failed" << endl; 
     1008 
     1009    updateGL(); 
     1010} 
     1011 
    10311012void 
    10321013QtGlRendererWidget::RenderRenderCost() 
     
    11761157         
    11771158        QFont font40; font40.setPointSize(30); 
    1178         s.sprintf("pvs:%04d", mPvsSize); 
     1159        s.sprintf("PVS: %04d", mPvsSize); 
    11791160        renderText(20, 40, s, font40); 
    11801161} 
     
    18621843        QGroupBox *groupBox2 = CreateRenderCostPanel(hbox); 
    18631844        vh->addWidget(groupBox2, 0, 0); 
    1864  
    18651845         
    18661846        QGroupBox *groupBox3 = CreateRayVisualizationPanel(hbox); 
     
    18771857 
    18781858        vbox->resize(800,150); 
    1879  
    18801859 
    18811860        vbox = new QGroupBox("Rendering", this); 
     
    20342013        connect(button, SIGNAL(clicked()), SIGNAL(StoreStatistics())); 
    20352014 
     2015        button = new QPushButton("Load object", vbox); 
     2016        vbox->layout()->addWidget(button); 
     2017        connect(button, SIGNAL(clicked()), SIGNAL(LoadObject())); 
     2018 
    20362019        /*cb = new QCheckBox("Stats", vbox); 
    20372020        vbox->layout()->addWidget(cb); 
    20382021        cb->setChecked(false); 
    2039         connect(cb, SIGNAL(toggled(bool)), SIGNAL(StoreStatistics())); 
    2040 */ 
     2022        connect(cb, SIGNAL(toggled(bool)), SIGNAL(StoreStatistics()));*/ 
    20412023        if (0)  
    20422024        { 
     
    22072189 
    22082190 
    2209 } 
     2191void QtGlRendererWidget::_RenderColoredPvs() 
     2192{ 
     2193        // note: could be done more efficiently using color buffers 
     2194        mPvsSize = mPvsCache.mPvs.GetSize(); 
     2195 
     2196        ObjectPvsIterator it = mPvsCache.mPvs.GetIterator(); 
     2197 
     2198        PvsData pvsData; 
     2199 
     2200        while (it.HasMoreEntries()) 
     2201        { 
     2202                Intersectable *object = it.Next(pvsData); 
     2203 
     2204                RgbColor color; 
     2205 
     2206                //float visibility = mTransferFunction*log10(entry.mData.mSumPdf + 1); // /5.0f 
     2207                // glColor3f(visibility, 0.0f, 0.0f); 
     2208                //cerr << "sumpdf: " << pvsData.mSumPdf << endl; 
     2209                if (mUseRandomColorPerPvsObject) 
     2210                { 
     2211                        KdIntersectable *kdint = static_cast<KdIntersectable *>(object); 
     2212 
     2213                        if (kdint->mGenericIdx == -1) 
     2214                        { 
     2215                                kdint->mGenericIdx = (int)mColors.size(); 
     2216                                mColors.push_back(RandomColor()); 
     2217                        } 
     2218                        color = mColors[kdint->mGenericIdx]; 
     2219                }  
     2220                else 
     2221                { 
     2222                        color = RainbowColorMapping(mTransferFunction * log10(pvsData.mSumPdf + 1)); 
     2223                } 
     2224 
     2225                glColor3f(color.r, color.g, color.b); 
     2226 
     2227                mUseForcedColors = true; 
     2228                RenderIntersectable(object); 
     2229                mUseForcedColors = false; 
     2230        } 
     2231} 
     2232 
     2233} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h

    r2604 r2609  
    109109  void SetRandomViewPoint(); 
    110110  void StoreStatistics(); 
     111  void LoadObject(); 
    111112  void UpdateAllPvs(); 
    112113  void SetViewCellGranularity(int); 
     
    224225        bool mUseRandomColorPerPvsObject; 
    225226 
     227        DynamicObjectsContainer mDynamicObjects; 
     228 
    226229        QtGlRendererWidget(SceneGraph *sceneGraph, 
    227230                               ViewCellsManager *viewcells, 
     
    270273                SetupCameraProjection(const int w, const int h, const float angle = 70.0f); 
    271274 
    272         void 
    273                 RenderViewCells(); 
    274  
    275  
    276         virtual void Show() { 
    277                 show(); 
    278         } 
     275        void RenderViewCells(); 
     276 
     277        virtual void Show() { show(); } 
    279278 
    280279        bool PvsChanged(ViewCell *viewcell) const; 
     
    300299 
    301300        ///////// 
    302  
    303301        //QMutex mMutex; 
    304302 
     
    311309        void SetRandomViewPoint(); 
    312310        void StoreStatistics(); 
     311        void LoadObject(); 
    313312 
    314313        void SetRenderErrors(bool b) { 
     
    517516        } 
    518517 
     518        void PreparePvs(); 
     519 
    519520        void _RenderPvs(); 
    520  
    521         void _UpdatePvsIndices(); 
     521        /** Render pvs using false colors. 
     522        */ 
     523        void _RenderColoredPvs(); 
    522524 
    523525        void _UpdatePvsIndices(KdNode *node, int &indexBufferSize); 
     
    569571 
    570572#endif 
    571  
  • GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp

    r2605 r2609  
    177177 
    178178        glLoadIdentity(); 
    179         gluLookAt(0.0f, 0.0f, 10.0f,  // eye is at (0,0,30)  
     179        gluLookAt(0.0f, 0.0f, 15.0f,  // eye is at (0,0,30)  
    180180                      0.0f, 0.0f, 0.0f,  // center is at (0,0,0)  
    181181                      0.0f, 1.0f, 0.0f); // up is in positive Y direction  
     
    191191        glTranslatef(t.x, t.y, t.z); 
    192192 
    193         /*mDummyViewPoint = -t; 
    194         mDummyViewPoint /= s; 
    195  
     193        //mDummyViewPoint = -t; 
     194        //mDummyViewPoint /= s; 
    196195        //glGetFloatv(GL_MODELVIEW_MATRIX, m1); 
    197 */ 
     196 
    198197        m.Invert(); 
    199198 
     
    243242QtGlViewer::mouseMoveEvent(QMouseEvent *event) 
    244243{ 
    245   int dx = event->x() + lastPos.x(); 
    246   int dy = event->y() + lastPos.y();   
     244  int dx = event->x() - lastPos.x(); 
     245  int dy = event->y() - lastPos.y();   
    247246   
    248247  if (event->modifiers() & Qt::CTRL) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Ray.cpp

    r2176 r2609  
    227227} 
    228228 
    229 void 
    230 Ray::Init(const VssRay &vssRay) 
    231 { 
    232   loc = vssRay.mOrigin; 
    233   sourceObject = Intersection(0, vssRay.GetDir(), vssRay.mOriginObject, 0); 
    234   mType = LOCAL_RAY; 
    235    
    236   float len = vssRay.Length(); 
    237    
    238   if (!len) 
    239         len = Limits::Small; 
    240    
    241   dir = vssRay.GetDir() / len; 
    242    
    243   intersections.clear(); 
    244   if (vssRay.mTerminationObject) 
    245         intersections.push_back(Intersection(len, -vssRay.GetDir(), vssRay.mTerminationObject, 0)); 
    246  
    247    
    248   Precompute(); 
    249 } 
    250  
    251 } 
     229 
     230void Ray::Init(const VssRay &vssRay) 
     231{ 
     232        loc = vssRay.mOrigin; 
     233        sourceObject = Intersection(0, vssRay.GetDir(), vssRay.mOriginObject, 0); 
     234        mType = LOCAL_RAY; 
     235 
     236        float len = vssRay.Length(); 
     237 
     238        if (!len) 
     239                len = Limits::Small; 
     240 
     241        dir = vssRay.GetDir() / len; 
     242 
     243        intersections.clear(); 
     244 
     245        if (vssRay.mTerminationObject) 
     246                intersections.push_back(Intersection(len, -vssRay.GetDir(), vssRay.mTerminationObject, 0)); 
     247 
     248        Precompute(); 
     249} 
     250 
     251} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Ray.h

    r2575 r2609  
    3838  struct Intersection  
    3939  { 
    40           /// the point of intersection 
    41           float mT; 
    42  
    43           /// the normal of the intersection 
    44           Vector3 mNormal; 
    45  
    46           /// can be either mesh or a viewcell 
    47           Intersectable *mObject; 
    48  
    49         /// the face of the intersectable 
    50           int mFace; 
    51  
    5240          Intersection(const float t, 
    5341                                                                 const Vector3 &normal, 
     
    5947          Intersection(): mT(0), mNormal(0,0,0), mObject(NULL), mFace(0)  
    6048          {} 
    61                  
     49 
     50 
     51          /// the point of intersection 
     52          float mT; 
     53          /// the normal of the intersection 
     54          Vector3 mNormal; 
     55          /// can be either mesh or a viewcell 
     56          Intersectable *mObject; 
     57          /// the face of the intersectable 
     58          int mFace; 
     59 
     60 
    6261          bool operator<(const Intersection &b) const  
    6362          { 
     
    6968  // I should have some abstract cell data type !!! here 
    7069  // corresponds to the spatial elementary cell 
    71   /** intersection with the source object if any */ 
     70   
     71  /// intersection with the source object if any 
    7272  Intersection sourceObject; 
    7373   
    7474  std::vector<Intersection> intersections; 
    75  // std::vector<BspIntersection> bspIntersections; 
    7675  std::vector<KdLeaf *> kdLeaves; 
    7776  std::vector<Intersectable *> testedObjects; 
     
    8483  // constructors 
    8584  Ray(const Vector3 &wherefrom, 
    86       const Vector3 &whichdir, 
    87       const int _type):mFlags(CULL_BACKFACES) { 
    88     loc = wherefrom; 
    89     if (_type == LINE_SEGMENT) 
    90       dir = whichdir; 
    91     else 
    92       dir = Normalize(whichdir); 
    93     mType = _type; 
    94     depth = 0; 
    95         Init(); 
    96   } 
     85          const Vector3 &whichdir, 
     86          const int _type): mFlags(CULL_BACKFACES)  
     87  { 
     88          loc = wherefrom; 
     89          if (_type == LINE_SEGMENT) 
     90                  dir = whichdir; 
     91          else 
     92                  dir = Normalize(whichdir); 
     93          mType = _type; 
     94          depth = 0; 
     95          Init(); 
     96  } 
     97 
    9798  // dummy constructor 
    9899  Ray() {} 
     
    100101  /** Construct ray from a vss ray. 
    101102  */ 
    102   Ray(const VssRay &vssRay) { 
    103         Init(vssRay); 
    104         mFlags |= CULL_BACKFACES; 
     103  Ray(const VssRay &vssRay)  
     104  { 
     105          Init(vssRay); 
     106          mFlags |= CULL_BACKFACES; 
    105107  } 
    106108 
     
    130132            const Vector3 &whichdir, 
    131133            const int _type,  
    132             bool dirNormalized = false) { 
    133     loc = wherefrom; 
    134     dir = (dirNormalized || _type == LINE_SEGMENT) ? whichdir: Normalize(whichdir) ; 
    135     mType = _type; 
    136     depth = 0; 
    137     Init(); 
    138         Precompute(); 
     134            bool dirNormalized = false)  
     135  { 
     136          loc = wherefrom; 
     137          dir = (dirNormalized || _type == LINE_SEGMENT) ? whichdir: Normalize(whichdir) ; 
     138          mType = _type; 
     139          depth = 0; 
     140          Init(); 
     141          Precompute(); 
    139142  } 
    140143 
     
    253256  int mType; 
    254257  
    255    
    256258  // unique ID of a ray for the use in the mailboxes 
    257259  int ID; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.cpp

    r2601 r2609  
    276276} 
    277277 
    278 } 
     278 
     279void SceneGraphLeaf::Transform(const Matrix4x4 &trafo) 
     280{ 
     281        mTrafo *= trafo; 
     282} 
     283 
     284} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.h

    r2606 r2609  
    55#include "Containers.h" 
    66#include "AxisAlignedBox3.h" 
    7  
     7#include "Matrix4x4.h" 
    88 
    99namespace GtpVisibilityPreprocessor { 
     
    3737        virtual void UpdateBox(); 
    3838 
    39         ~SceneGraphInterior(); 
    40  
    4139//protected: 
    4240 
     
    5149public: 
    5250 
     51        SceneGraphLeaf(bool isDynamic = false):  
     52          mIsDynamic(isDynamic){} 
     53        ~SceneGraphLeaf(); 
     54 
     55        virtual void Transform(const Matrix4x4 &trafo); 
     56        virtual bool IsDynamic() const { return mIsDynamic;} 
    5357        virtual bool IsLeaf() const { return true; } 
    5458        virtual void UpdateBox(); 
    5559 
    56         ~SceneGraphLeaf(); 
     60        ObjectContainer mGeometry; 
    5761 
    58 //protected: 
     62protected: 
    5963 
    60         //MeshContainer mGeometry; 
    61         ObjectContainer mGeometry; 
     64        bool mIsDynamic; 
     65        Matrix4x4 mTrafo; 
    6266}; 
    6367 
    6468 
    6569 
    66 /** Scene graph class */ 
    67 class SceneGraph { 
     70/** Scene graph class  
     71*/ 
     72class SceneGraph  
     73{ 
    6874 
    6975public: 
     
    8187 
    8288        AxisAlignedBox3 GetBox() const { return mRoot->mBox; } 
    83    
    8489        /** Exports binary version of the scene. 
    8590        */ 
    8691        void ExportScene(const std::string filename); 
    87  
    8892        /** Loads binary version of the scene. 
    8993        */ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp

    r2017 r2609  
    28222822        {   
    28232823                VssRay *ray = rays[i]; 
     2824#if VSS_STORE_VIEWCELLS 
    28242825         
    28252826                // traverse leaves stored in the rays and compare and  
     
    28752876                                candidates.push_back(mc); 
    28762877 
    2877                                 if (((int)candidates.size() % 1000) == 0) 
     2878                                if ((candidates.size() % 1000) == 0) 
    28782879                                { 
    28792880                                        cout << "collected " << (int)candidates.size() << " merge candidates" << endl; 
     
    28812882                        } 
    28822883        } 
     2884#endif 
    28832885        } 
    28842886 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r2606 r2609  
    368368                                                                                                  const bool isTermination) const 
    369369{ 
     370#if DYNAMIC_OBJECTS_HACK 
     371        if (ray.mTerminationObject->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE) 
     372                return ray.mTerminationObject; 
     373#endif 
    370374        if (mUseKdPvs) 
    371375        { 
     
    24832487                                                                          const bool useHitObjects) 
    24842488{ 
    2485   if (!useHitObjects)  
    2486         { 
    2487           // store higher order object (e.g., bvh node) instead of object itself 
    2488           VssRayContainer::const_iterator it, it_end = rays.end(); 
    2489            
    2490           for (it = rays.begin(); it != it_end; ++ it)  
    2491                 { 
    2492                   VssRay *vssRay = *it; 
    2493                    
    2494                   // set only the termination object 
    2495                   //              if (vssRay->mTerminationObject == NULL)  
    2496                   //                    cerr<<"Error NULL termination object!"<<endl; 
    2497                   vssRay->mTerminationObject = GetIntersectable(*vssRay, true); 
     2489        if (!useHitObjects)  
     2490        { 
     2491                // store higher order object (e.g., bvh node) instead of object itself 
     2492                VssRayContainer::const_iterator it, it_end = rays.end(); 
     2493 
     2494                for (it = rays.begin(); it != it_end; ++ it)  
     2495                { 
     2496                        VssRay *vssRay = *it; 
     2497 
     2498                        // set only the termination object 
     2499                        vssRay->mTerminationObject = GetIntersectable(*vssRay, true); 
    24982500#if 0 
    24992501                  if (vssRay->mTerminationObject == NULL) { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp

    r2575 r2609  
    38543854        {   
    38553855                VssRay *ray = rays[i]; 
    3856          
     3856 
     3857#if VSS_STORE_VIEWCELLS 
    38573858                // traverse leaves stored in the rays and compare and  
    38583859                // merge consecutive leaves (i.e., the neighbors in the tree) 
     
    39133914                        } 
    39143915        } 
     3916#endif 
    39153917        } 
    39163918 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.cpp

    r2593 r2609  
    4141 
    4242 
    43 VssRay::VssRay(const Ray &ray): 
    44         mRefCount(0), 
    45         mFlags(0), 
    46         mMailbox(-1), 
    47         mOriginObject(ray.sourceObject.mObject), 
    48         mPass(0), 
     43VssRay::VssRay(const Ray &ray) 
     44{ 
     45        Init(ray); 
     46} 
     47 
     48 
     49void VssRay::Init(const Ray &ray) 
     50{        
     51        mRefCount = 0; 
     52        mFlags = 0; 
     53        mMailbox = -1; 
     54        mOriginObject = ray.sourceObject.mObject; 
     55        mPass = 0; 
     56        mPdf = 1.0f; 
     57        mTerminationNode = NULL; 
     58        mOriginNode = NULL; 
     59        mPvsContribution = 0; 
     60 
    4961#if VSS_STORE_VIEWCELLS 
    50         mViewCells(0), 
    51 #endif 
    52         mPdf(1.0f), 
    53         mTerminationNode(NULL), 
    54         mOriginNode(NULL), 
    55         mPvsContribution(0) 
    56 { 
     62        mViewCells.clear(); 
     63#endif 
     64 
    5765        if (ray.sourceObject.mObject) 
    5866                mOrigin = ray.Extrap(ray.sourceObject.mT); 
     
    6876        else 
    6977        { 
    70                 mTermination = ray.Extrap(1e6); //TODO: should be Limits::Infinity 
     78                mTermination = ray.Extrap(1e6f); //TODO: should be Limits::Infinity 
    7179                mTerminationObject = NULL; 
    7280        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h

    r2593 r2609  
    2020 
    2121#define ABS_CONTRIBUTION_WEIGHT 0.0f 
    22 #define VSS_STORE_VIEWCELLS 1 
     22#define VSS_STORE_VIEWCELLS 0 
    2323 
    2424 
     
    6969  // sampling pass in which this ray was generated 
    7070  short mPass; 
    71  
    7271  /// Distribution used to generate this ray 
    7372  short mDistribution; 
    74    
    7573  /// number of cells where this ray made a contribution to the PVS 
    7674  int mPvsContribution; 
    77    
    7875  /// sum of relative ray contributions per object 
    7976  float mRelativePvsContribution; 
    80  
    81   /// weighted contribution to the pvs (based on the pass the ray was casted at) 
    82   /// computed by the prperocessor 
     77  /** weighted contribution to the pvs (based on the pass the ray was casted at) 
     78         ccomputed by the prperocessor 
     79  */ 
    8380  float mWeightedPvsContribution; 
    84  
    8581  /// probability of this ray 
    8682  float mPdf; 
     
    107103  VssRay(const Ray &ray); 
    108104         
    109    
     105  void Init(const Ray &ray); 
     106 
    110107  void Precompute(); 
    111108 
  • GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp

    r2600 r2609  
    234234        { 
    235235                /////////////////// 
    236                 //-- load data as single triangles instead of whole meshes 
     236                //-- load data as triangle soup instead of whole meshes 
    237237 
    238238                cout << "m";     
  • GTP/trunk/Lib/Vis/Preprocessing/src/common.h

    r2603 r2609  
    2323#include <vector> 
    2424 
    25  
     25#define DYNAMIC_OBJECTS_HACK 1 
    2626#define USE_HAVRAN_RAYCASTER 
    2727 
Note: See TracChangeset for help on using the changeset viewer.