Changeset 2678


Ignore:
Timestamp:
05/15/08 13:02:00 (16 years ago)
Author:
mattausch
Message:

started working on dynamic objects

Location:
GTP/trunk/Lib/Vis/Preprocessing
Files:
1 added
12 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/Camera.cpp

    r2635 r2678  
    2121 
    2222#ifdef USE_HAVRAN_RAYCASTER 
    23 //#include "timer.h" 
    2423#include "raypack.h" 
    2524#endif 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Containers.h

    r2615 r2678  
    7676/// a container for dynamic objects 
    7777 
    78 #if USE_TRANSFORMED_MESH_INSTANCE_HACK 
    79 typedef std::vector<TransformedMeshInstance *> DynamicObjectsContainer; 
    80 #else 
    8178typedef vector<SceneGraphLeaf *> DynamicObjectsContainer; 
    82 #endif 
     79 
    8380 
    8481} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp

    r2677 r2678  
    522522        glPopMatrix(); 
    523523 
    524 #if 1 
    525         // test the box of the object 
    526         AxisAlignedBox3 box = leaf->GetBox(); 
    527         RenderBox(box); 
    528 #endif 
     524        if (1) 
     525        { 
     526                // test the box of the object 
     527                AxisAlignedBox3 box = leaf->GetBox(); 
     528                RenderBox(box); 
     529        } 
    529530} 
    530531 
     
    567568        for (dit = p->mDynamicObjects.begin(); dit != dit_end; ++ dit) 
    568569        { 
    569 #if USE_TRANSFORMED_MESH_INSTANCE_HACK 
    570                 RenderIntersectable(*dit); 
    571 #else 
    572570                _RenderDynamicObject(*dit); 
     571        } 
    573572#endif 
    574         } 
    575 #endif 
    576  
    577 #if 1 
    578573        _RenderSceneTrianglesWithDrawArrays(); 
    579574 
    580 #else 
    581         static int glList = -1; 
    582         if (mUseGlLists) { 
    583                 if (glList == -1) { 
    584                         glList = glGenLists(1); 
    585                         glNewList(glList, GL_COMPILE); 
    586                         _RenderSceneTriangles(); 
    587                         glEndList(); 
    588                 } 
    589  
    590                 glCallList(glList); 
    591         } else 
    592                 _RenderSceneTriangles(); 
    593  
    594 #endif 
    595575        return true; 
    596576} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.h

    r2623 r2678  
    8383                                                  const bool pruneInvalidRays = true); 
    8484 
    85   virtual void AddDynamicObjecs(const ObjectContainer &objects, const Matrix4x4 &m) {}; 
    86   virtual void UpdateDynamicObjects(const Matrix4x4 &m) {}; 
    87   virtual void DeleteDynamicObjects() {}; 
     85        virtual void AddDynamicObjecs(const ObjectContainer &objects, const Matrix4x4 &m) {DYN_ERROR_STRING;} 
     86        virtual void UpdateDynamicObjects(const Matrix4x4 &m) {DYN_ERROR_STRING;} 
     87        virtual void DeleteDynamicObjects() {DYN_ERROR_STRING;} 
    8888 
    8989protected: 
  • GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.h

    r2623 r2678  
    5858                ); 
    5959 
    60   virtual void AddDynamicObjecs(const ObjectContainer &objects, const Matrix4x4 &m) {}; 
    61   virtual void UpdateDynamicObjects(const Matrix4x4 &m) {}; 
    62   virtual void DeleteDynamicObjects() {}; 
     60  virtual void AddDynamicObjecs(const ObjectContainer &objects, const Matrix4x4 &m) { DYN_ERROR_STRING; }; 
     61  virtual void UpdateDynamicObjects(const Matrix4x4 &m) { DYN_ERROR_STRING;}; 
     62  virtual void DeleteDynamicObjects() {DYN_ERROR_STRING;}; 
    6363 
    6464protected: 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Matrix4x4.cpp

    r1980 r2678  
    137137    indxr[i] = irow; 
    138138    indxc[i] = icol; 
    139     if (x[icol][icol] == 0.0) 
     139    if (x[icol][icol] == 0.0f) 
    140140      return 1; /* singular matrix */ 
    141141 
    142     pivinv = 1.0 / x[icol][icol]; 
    143     x[icol][icol] = 1.0 ; 
     142    pivinv = 1.0f / x[icol][icol]; 
     143    x[icol][icol] = 1.0f ; 
    144144    for ( l = 0 ; l<n ; l++) 
    145145      x[l][icol] = x[l][icol] * pivinv ; 
     
    149149      { 
    150150        dum = x[icol][ll]; 
    151         x[icol][ll] = 0.0; 
     151        x[icol][ll] = 0.0f; 
    152152        for ( l = 0 ; l<n ; l++) 
    153153          x[l][ll] = x[l][ll] - x[l][icol] * dum ; 
     
    208208  for (int i = 0; i < 4; i++) 
    209209    for (int j = 0; j < 4; j++) 
    210       M.x[i][j] = (i == j) ? 1.0 : 0.0; 
     210      M.x[i][j] = (i == j) ? 1.0f : 0.0f; 
    211211  return M; 
    212212} 
     
    321321  double one_minus_cosine = 1 - cosine; 
    322322 
    323   M.x[0][0] = axis.x * axis.x + (1.0 - axis.x * axis.x) * cosine; 
     323  M.x[0][0] = axis.x * axis.x + (1.0f - axis.x * axis.x) * cosine; 
    324324  M.x[0][1] = axis.x * axis.y * one_minus_cosine + axis.z * sine; 
    325325  M.x[0][2] = axis.x * axis.z * one_minus_cosine - axis.y * sine; 
     
    327327 
    328328  M.x[1][0] = axis.x * axis.y * one_minus_cosine - axis.z * sine; 
    329   M.x[1][1] = axis.y * axis.y + (1.0 - axis.y * axis.y) * cosine; 
     329  M.x[1][1] = axis.y * axis.y + (1.0f - axis.y * axis.y) * cosine; 
    330330  M.x[1][2] = axis.y * axis.z * one_minus_cosine + axis.x * sine; 
    331331  M.x[1][3] = 0; 
     
    333333  M.x[2][0] = axis.x * axis.z * one_minus_cosine + axis.y * sine; 
    334334  M.x[2][1] = axis.y * axis.z * one_minus_cosine - axis.x * sine; 
    335   M.x[2][2] = axis.z * axis.z + (1.0 - axis.z * axis.z) * cosine; 
     335  M.x[2][2] = axis.z * axis.z + (1.0f - axis.z * axis.z) * cosine; 
    336336  M.x[2][3] = 0; 
    337337 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r2660 r2678  
    12441244                        pruneInvalidRays); 
    12451245 
    1246                 //#if DYNAMIC_OBJECTS_HACK 
    12471246                // disabled not neccessary 
    12481247                UpdateDynamicObjects(); 
    1249 #if 0 
    1250                 static Ray hRay; 
    1251                 VssRayContainer::iterator vit, vit_end = vssRays.end(); 
    1252  
    1253                 for (vit = vssRays.begin(); vit != vit_end; ++ vit) 
    1254                 { 
    1255                         VssRay *vssRay = *vit; 
    1256  
    1257                         DynamicObjectsContainer::const_iterator tit, tit_end = mDynamicObjects.end(); 
    1258                         bool foundIntersect = false; 
    1259  
    1260 #if USE_TRANSFORMED_MESH_INSTANCE_HACK 
    1261                         hRay.Init(*vssRay); 
    1262  
    1263                         for (tit = mDynamicObjects.begin(); tit != tit_end; ++ tit) 
    1264                         { 
    1265                                 TransformedMeshInstance *tmi = *tit; 
    1266  
    1267                                 float maxT, minT; 
    1268                                  
    1269                                 // test with bounding box 
    1270                                 if (tmi->GetBox().GetMinMaxT(hRay, &minT, &maxT)) 
    1271                                 { 
    1272                                         if (tmi->CastRay(hRay)) //cout << "z"; else cout<< "r"; 
    1273                                         { 
    1274                                                 //cout << "i: " << Intersectable::GetTypeName(hRay.intersections[0].mObject); 
    1275                                                 foundIntersect = true; 
    1276                                         } 
    1277                                 } 
    1278                         } 
    1279  
    1280                         if (foundIntersect) 
    1281                         { 
    1282                                 ++ numTransformed; 
    1283                                 // write new results back into vssRay 
    1284                                 vssRay->Init(hRay); 
    1285                         } 
    1286  
    1287                         hRay.intersections.clear(); 
    1288 #else 
    1289  
    1290                         //////////// 
    1291                         // TODO Vlastimil 
    1292                          
    1293                         for (tit = mDynamicObjects.begin(); tit != tit_end; ++ tit)      
    1294                         { 
    1295                                 // remove vss ray termination triangle with container object 
    1296                                 if (foundIntersect) 
    1297                                 { 
    1298                                         vssRay->mTerminationObject = (*tit)->GetIntersectable(); 
    1299                                 } 
    1300                         } 
    1301  
    1302          
    1303 #endif 
    1304  
    1305  
    1306                 } 
    1307 #endif 
    13081248        } 
    13091249 
     
    17461686        bool parsed = false; 
    17471687 
    1748         if (strstr(filename.c_str(), ".obj")) { 
    1749           cout<<"parsing obj file.."<<endl; 
    1750           ObjParser *p = new ObjParser; 
    1751           parsed = p->ParseFile(filename,  
    1752                                                         leaf, 
    1753                                                         false); 
    1754           leaf->UpdateBox(); 
    1755           cout<<leaf->GetBox(); 
    1756  
    1757           float s = 10.0f; 
    1758           leaf->ApplyTransform(ScaleMatrix(s, s, s)); 
    1759           leaf->ApplyTransform(TranslationMatrix(Vector3(0, 10, 0))); 
    1760  
    1761            
    1762         } else { 
    1763           cout<<"parsing binary obj file.."<<endl; 
    1764  
    1765           parsed = LoadBinaryObj(filename, leaf, NULL, 100); 
    1766         } 
    1767          
     1688        if (strstr(filename.c_str(), ".obj")) 
     1689        { 
     1690                cout<<"parsing obj file.."<<endl; 
     1691                ObjParser *p = new ObjParser; 
     1692                parsed = p->ParseFile(filename,  
     1693                        leaf, 
     1694                        false); 
     1695                leaf->UpdateBox(); 
     1696                cout<<leaf->GetBox(); 
     1697 
     1698                float s = 10.0f; 
     1699                leaf->ApplyTransform(ScaleMatrix(s, s, s)); 
     1700                leaf->ApplyTransform(TranslationMatrix(Vector3(0, 10, 0))); 
     1701 
     1702 
     1703        }  
     1704        else  
     1705        { 
     1706                cout<<"parsing binary obj file ... " << endl; 
     1707 
     1708                parsed = LoadBinaryObj(filename, leaf, NULL, 100); 
     1709        } 
     1710 
    17681711        if (parsed) 
    1769           { 
     1712        { 
    17701713                cout<<"success."<<endl; 
    17711714                leaf->UpdateBox(); 
     
    17741717                //leaf->RebuildKtbTree(); 
    17751718                mSceneGraph->GetRoot()->mChildren.push_back(leaf); 
    1776                  
     1719 
    17771720                if (mRayCaster) 
    1778                   mRayCaster->AddDynamicObjecs(leaf->mGeometry, leaf->GetTransformation()); 
    1779                  
    1780            
     1721                        mRayCaster->AddDynamicObjecs(leaf->mGeometry, leaf->GetTransformation()); 
     1722 
     1723 
    17811724                return true; 
    1782           } else 
    1783                 { 
    1784                   cout<<"failed."<<endl; 
    1785  
    1786                 } 
     1725        }  
     1726        else 
     1727        { 
     1728                cout<<"failed."<<endl; 
     1729 
     1730        } 
    17871731 
    17881732#endif 
     
    17921736 
    17931737 
    1794 void 
    1795 Preprocessor::ObjectMoved(SceneGraphLeaf *object) 
    1796 { 
    1797   // first invalidate all PVS from which this object is visible 
    1798   ViewCellContainer::const_iterator vit, vit_end = mViewCellsManager->GetViewCells().end(); 
    1799    
    1800   AxisAlignedBox3 box = object->GetBox(); 
    1801  
    1802   ObjectContainer objects; 
    1803  
    1804   if (0) { 
    1805         // simplified computation taking only the objects intersecting the box 
    1806         KdNode::NewMail(); 
    1807          
    1808         // first mail all kDObjects which are intersected by the object 
    1809         preprocessor->mKdTree->CollectKdObjects(box, 
    1810                                                                                         objects); 
    1811          
    1812   } else { 
    1813         ViewCellContainer viewCells; 
    1814         mViewCellsManager->ComputeBoxIntersections(box, viewCells); 
    1815          
    1816         ViewCellContainer::const_iterator it = viewCells.begin(), it_end = viewCells.end(); 
    1817          
    1818         ObjectPvs pvs; 
    1819          
    1820         for (int i=0; it != it_end; ++ it, ++ i) { 
    1821           //cout<<"v"<<i<<" pvs="<<(*it)->GetPvs().mEntries.size()<<endl; 
    1822           pvs.MergeInPlace((*it)->GetPvs()); 
    1823         } 
    1824  
    1825         ObjectPvsIterator pit = pvs.GetIterator(); 
    1826         while (pit.HasMoreEntries())  {          
    1827           PvsData pvsData; 
    1828           Intersectable *object = pit.Next(pvsData); 
    1829           objects.push_back(object); 
    1830         } 
    1831   } 
    1832    
    1833   int pvsCounter = 0; 
    1834   // now search for pvss which contained any mailed node 
    1835   for (vit = mViewCellsManager->GetViewCells().begin(); vit != vit_end; ++ vit) { 
    1836         ObjectPvs &pvs = (*vit)->GetPvs(); 
    1837         for (int i=0; i < objects.size(); i++) { 
    1838           vector<PvsEntry<Intersectable *,PvsData> >::iterator v; 
    1839           //      ObjectPvsIterator it; 
    1840           if (pvs.Find(objects[i], v)) { 
    1841                 // clear the pvs 
    1842                 pvs.Clear(); 
    1843                 pvsCounter++; 
    1844                 break; 
    1845           } 
    1846         } 
    1847   } 
    1848  
    1849   cout<<"Number of affected objects "<<objects.size()<<endl; 
    1850   cout<<"Cleared "<<pvsCounter<<" PVSs ("<<mViewCellsManager->GetViewCells().size()/ 
    1851         (float)pvsCounter*100.0f<<"%) "<<endl; 
    1852    
     1738void Preprocessor::ObjectMoved(SceneGraphLeaf *object) 
     1739{ 
     1740        // first invalidate all PVS from which this object is visible 
     1741        ViewCellContainer::const_iterator vit, vit_end = mViewCellsManager->GetViewCells().end(); 
     1742 
     1743        AxisAlignedBox3 box = object->GetBox(); 
     1744 
     1745        ObjectContainer objects; 
     1746 
     1747        if (0)  
     1748        { 
     1749                // simplified computation taking only the objects intersecting the box 
     1750                KdNode::NewMail(); 
     1751 
     1752                // first mail all kDObjects which are intersected by the object 
     1753                preprocessor->mKdTree->CollectKdObjects(box, objects); 
     1754 
     1755        }  
     1756        else  
     1757        { 
     1758                ViewCellContainer viewCells; 
     1759                mViewCellsManager->ComputeBoxIntersections(box, viewCells); 
     1760 
     1761                // add object to all viewcells that intersect the bounding box 
     1762                ObjectPvs pvs; 
     1763 
     1764                ViewCellContainer::const_iterator it = viewCells.begin(), it_end = viewCells.end(); 
     1765 
     1766                for (int i = 0; it != it_end; ++ it, ++ i)  
     1767                { 
     1768                        //cout<<"v"<<i<<" pvs="<<(*it)->GetPvs().mEntries.size()<<endl; 
     1769                        pvs.MergeInPlace((*it)->GetPvs()); 
     1770                } 
     1771 
     1772                ObjectPvsIterator pit = pvs.GetIterator(); 
     1773                while (pit.HasMoreEntries())   
     1774                {                
     1775                        PvsData pvsData; 
     1776                        Intersectable *object = pit.Next(pvsData); 
     1777                        objects.push_back(object); 
     1778                } 
     1779        } 
     1780 
     1781        int pvsCounter = 0; 
     1782 
     1783        // now search for pvss which contained any mailed node 
     1784        for (vit = mViewCellsManager->GetViewCells().begin(); vit != vit_end; ++ vit)  
     1785        { 
     1786                ObjectPvs &pvs = (*vit)->GetPvs(); 
     1787 
     1788                for (int i=0; i < objects.size(); i++)  
     1789                { 
     1790                        vector<PvsEntry<Intersectable *,PvsData> >::iterator v; 
     1791                 
     1792                        if (pvs.Find(objects[i], v)) { 
     1793                                // clear the pvs 
     1794                                pvs.Clear(); 
     1795                                pvsCounter++; 
     1796                                break; 
     1797                        } 
     1798                } 
     1799        } 
     1800 
     1801        cout<<"Number of affected objects "<<objects.size()<<endl; 
     1802        cout<<"Cleared "<<pvsCounter<<" PVSs ("<<mViewCellsManager->GetViewCells().size()/ 
     1803                (float)pvsCounter*100.0f<<"%) "<<endl; 
     1804 
    18531805} 
    18541806 
     
    18581810        if (mUpdateDynamicObjects)  
    18591811        { 
    1860            
     1812                // delete ALL dynamic stuff and rebuild using the new trafos 
    18611813                preprocessor->mRayCaster->DeleteDynamicObjects(); 
    18621814         
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h

    r2645 r2678  
    220220        /// the view cells manager 
    221221        ViewCellsManager *mViewCellsManager; 
     222 
    222223#if DYNAMIC_OBJECTS_HACK 
    223224        DynamicObjectsContainer mDynamicObjects; 
     
    295296        virtual void EvalViewCellHistogram(); 
    296297 
     298        /** Notify the preprocessor that an object has moved and must be reevaluated. 
     299        */ 
    297300        virtual void ObjectMoved(SceneGraphLeaf *object); 
    298301 
  • GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp

    r2677 r2678  
    497497        for (dit = mDynamicObjects.begin(); dit != dit_end; ++ dit) 
    498498        { 
    499 #if USE_TRANSFORMED_MESH_INSTANCE_HACK 
    500                 RenderIntersectable(*dit); 
    501 #else 
    502499                _RenderDynamicObject(*dit); 
    503 #endif 
    504500        } 
    505501#endif 
  • GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h

    r2677 r2678  
    236236 
    237237        bool mUseRandomColorPerPvsObject; 
     238 
    238239#if DYNAMIC_OBJECTS_HACK 
    239240        DynamicObjectsContainer mDynamicObjects; 
    240241#endif 
     242 
    241243        QtGlRendererWidget(SceneGraph *sceneGraph, 
    242244                               ViewCellsManager *viewcells, 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r2660 r2678  
    368368                                                                                                  const bool isTermination) const 
    369369{ 
     370        // dynamic objects are scene graph leaves 
    370371#if DYNAMIC_OBJECTS_HACK 
    371  
    372 #if USE_TRANSFORMED_MESH_INSTANCE_HACK 
    373         if (ray.mTerminationObject->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE) 
    374                 return ray.mTerminationObject; 
    375 #else 
    376372        if (ray.mTerminationObject->Type() == Intersectable::SCENEGRAPHLEAF_INTERSECTABLE) 
    377373                return ray.mTerminationObject; 
    378374#endif 
    379375 
    380 #endif 
    381376        if (mUseKdPvs) 
    382377        { 
  • GTP/trunk/Lib/Vis/Preprocessing/src/common.h

    r2655 r2678  
    2424 
    2525#define DYNAMIC_OBJECTS_HACK 1 
    26 #define USE_TRANSFORMED_MESH_INSTANCE_HACK 0 
    27 //#define USE_HAVRAN_RAYCASTER 0 
     26#define USE_HAVRAN_RAYCASTER 0 
     27 
    2828 
    2929namespace GtpVisibilityPreprocessor { 
     
    532532#endif 
    533533 
     534#define DYN_ERROR_STRING do {std::cout << "error: dynamic objects not supported" << endl;} while (0) 
     535 
    534536/** view cell id belonging to empty view space. 
    535537*/ 
     
    545547 
    546548 
    547  
    548  
Note: See TracChangeset for help on using the changeset viewer.