Changeset 1595 for GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include
- Timestamp:
- 10/10/06 01:27:11 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBoundingBoxConverter.h
r1296 r1595 1 #ifndef _ OgreBoundingBoxConverter_H__2 #define _ OgreBoundingBoxConverter_H__1 #ifndef _PlatFormBoundingBoxConverter_H__ 2 #define _PlatFormBoundingBoxConverter_H__ 3 3 4 4 #include "OgreAxisAlignedBox.h" … … 13 13 class OctreeSceneManager; 14 14 class KdTreeSceneManager; 15 class BvHierarchySceneManager; 16 15 17 16 18 /** Class which converts preprocessor types to OGRE types 17 19 */ 18 class __declspec(dllexport) OgreBoundingBoxConverter: public GtpVisibilityPreprocessor::BoundingBoxConverter 20 template<typename T> 21 class __declspec(dllexport) PlatFormBoundingBoxConverter: public GtpVisibilityPreprocessor::BoundingBoxConverter 19 22 { 20 23 public: 21 OgreBoundingBoxConverter(OctreeSceneManager *sm); 22 OgreBoundingBoxConverter(KdTreeSceneManager *sm); 23 24 PlatFormBoundingBoxConverter(T *sm); 25 24 26 bool IdentifyObjects(const GtpVisibilityPreprocessor::IndexedBoundingBoxContainer &iboxes, 25 27 GtpVisibilityPreprocessor::ObjectContainer &objects) const; … … 28 30 protected: 29 31 30 Entity *FindCorrespondingObject(const AxisAlignedBox &box) const; 32 //------------------------------------------------------------------------- 33 inline static AxisAlignedBox EnlargeBox(const AxisAlignedBox &box) 34 { 35 const float eps = 1e-3f; 36 const Vector3 veps(eps, eps, eps); 37 38 Vector3 max = box.getMaximum(); 39 Vector3 min = box.getMinimum(); 31 40 32 OctreeSceneManager *mOctSceneMgr; 33 KdTreeSceneManager *mKdSceneMgr; 41 return AxisAlignedBox(min - veps, max + veps); 42 } 43 44 Entity *FindBestFittingObject(const AxisAlignedBox &box) const; 45 46 T *mSceneMgr; 34 47 }; 48 49 //------------------------------------------------------------------------- 50 template<typename T> 51 PlatFormBoundingBoxConverter<T>::PlatFormBoundingBoxConverter(T *sm): 52 mSceneMgr(sm) 53 { 54 } 55 //----------------------------------------------------------------------- 56 template<typename T> 57 Entity *PlatFormBoundingBoxConverter<T>::FindBestFittingObject(const AxisAlignedBox &box) const 58 { 59 list<SceneNode *> sceneNodeList; 60 AxisAlignedBox mybox = EnlargeBox(box); 61 62 // get intersecting scene nodes 63 mSceneMgr->findNodesIn(mybox, sceneNodeList, NULL); 64 65 // minimal overlap 66 float overlap = 0;//1e-6; 67 68 Entity *bestFittingObj = NULL; 69 float bestFit = overlap; 70 71 // perfect fit threshold 72 const float thresh = 1.0 - GtpVisibilityPreprocessor::Limits::Small; 73 74 list<SceneNode *>::const_iterator sit, sit_end = sceneNodeList.end(); 75 // find the bbox which is closest to the current bbox 76 for (sit = sceneNodeList.begin(); sit != sceneNodeList.end(); ++ sit) 77 { 78 SceneNode *sn = *sit; 79 SceneNode::ObjectIterator oit = sn->getAttachedObjectIterator(); 80 81 while (oit.hasMoreElements()) 82 { 83 MovableObject *mo = oit.getNext(); 84 85 // we are only interested in scene entities 86 if (mo->getMovableType() != "Entity") 87 { 88 continue; 89 } 90 91 const AxisAlignedBox bbox = EnlargeBox(mo->getWorldBoundingBox()); 92 93 // compute measure how much aabbs overlap 94 overlap = RatioOfOverlap(OgreTypeConverter::ConvertFromOgre(mybox), 95 OgreTypeConverter::ConvertFromOgre(bbox)); 96 97 if (overlap > bestFit) 98 { 99 bestFit = overlap; 100 bestFittingObj = static_cast<Entity *>(mo); 101 102 // perfect fit => object found, early exit 103 if (overlap >= thresh) 104 { 105 return bestFittingObj; 106 } 107 } 108 } 109 } 110 111 if (0) 112 { 113 std::stringstream d; 114 if (bestFittingObj) 115 d << "best fit: " << bestFit; 116 else 117 d << "warning, no best fitting object\n" << box; 118 119 Ogre::LogManager::getSingleton().logMessage(d.str()); 120 } 121 122 return bestFittingObj; 123 } 124 //------------------------------------------------------------------------- 125 template<typename T> 126 bool PlatFormBoundingBoxConverter<T>::IdentifyObjects( 127 const GtpVisibilityPreprocessor::IndexedBoundingBoxContainer &iboxes, 128 GtpVisibilityPreprocessor::ObjectContainer &objects) const 129 { 130 GtpVisibilityPreprocessor::IndexedBoundingBoxContainer:: 131 const_iterator iit, iit_end = iboxes.end(); 132 133 for (iit = iboxes.begin(); iit != iit_end; ++ iit) 134 { 135 const GtpVisibilityPreprocessor::AxisAlignedBox3 box = (*iit).second; 136 const AxisAlignedBox currentBox = OgreTypeConverter::ConvertToOgre(box); 137 138 Entity *ent = FindBestFittingObject(currentBox); 139 140 // create new mesh instance 141 if (ent) 142 { 143 OgreMeshInstance *omi = new OgreMeshInstance(ent); 144 omi->SetId((*iit).first); 145 objects.push_back(omi); 146 } 147 } 148 149 return true; 150 } 151 152 153 typedef PlatFormBoundingBoxConverter<OctreeSceneManager> OctreeBoundingBoxConverter; 154 typedef PlatFormBoundingBoxConverter<BvHierarchySceneManager> BvhBoundingBoxConverter; 155 typedef PlatFormBoundingBoxConverter<KdTreeSceneManager> KdTreeBoundingBoxConverter; 35 156 36 157 } // namespace Ogre 37 158 38 #endif // OgreBoundingBoxConverter159 #endif // PlatFormBoundingBoxConverter -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBvHierarchySceneManager.h
r1320 r1595 271 271 bool mDeleteQueueAfterRendering; 272 272 273 274 273 // remember visited scene nodes for viz 275 274 BvHierarchy::NodeList mVisibleNodes; 276 275 277 /************************************************************************/ 278 /* Kd-Tree specific options & members */ 279 /************************************************************************/ 276 277 /************************************************************************/ 278 /* Bvh specific options & members */ 279 /************************************************************************/ 280 281 280 282 // maximum depth of the BvHierarchy 281 283 int mMaxDepth;
Note: See TracChangeset
for help on using the changeset viewer.