Changeset 1616 for GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include
- Timestamp:
- 10/13/06 03:28:42 (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
r1595 r1616 7 7 #include "BoundingBoxConverter.h" 8 8 #include "Containers.h" 9 #include "IntersectableWrapper.h" 10 //#include "KdTree.h" 11 9 12 10 13 namespace Ogre { 11 14 15 #define USE_KD_PVS 1 12 16 class Entity; 13 17 class OctreeSceneManager; … … 15 19 class BvHierarchySceneManager; 16 20 21 typedef vector<Entity *> EntityContainer; 22 23 class ObjectsIntersectable: public GtpVisibilityPreprocessor::IntersectableWrapper<EntityContainer *> 24 { 25 public: 26 ObjectsIntersectable(EntityContainer *item): 27 GtpVisibilityPreprocessor::IntersectableWrapper<EntityContainer *>(item) {} 28 29 // hack 30 ObjectsIntersectable::~ObjectsIntersectable() 31 { 32 //CLEAR_CONTAINER(*mItem); 33 delete mItem; 34 } 35 36 int Type() const 37 { 38 return Intersectable::OBJECTS_INTERSECTABLE; 39 } 40 }; 17 41 18 42 /** Class which converts preprocessor types to OGRE types … … 42 66 } 43 67 68 /** find object which fits best to this bounding box 69 */ 44 70 Entity *FindBestFittingObject(const AxisAlignedBox &box) const; 71 72 /** find objects which are intersected by this box 73 */ 74 void FindIntersectingObjects(const AxisAlignedBox &box, 75 vector<Entity *> &objects) const; 45 76 46 77 T *mSceneMgr; … … 74 105 list<SceneNode *>::const_iterator sit, sit_end = sceneNodeList.end(); 75 106 // find the bbox which is closest to the current bbox 107 for (sit = sceneNodeList.begin(); sit != sceneNodeList.end(); ++ sit) 108 { 109 SceneNode *sn = *sit; 110 SceneNode::ObjectIterator oit = sn->getAttachedObjectIterator(); 111 112 while (oit.hasMoreElements()) 113 { 114 MovableObject *mo = oit.getNext(); 115 116 // we are only interested in scene entities 117 if (mo->getMovableType() != "Entity") 118 { 119 continue; 120 } 121 mo-> 122 const AxisAlignedBox bbox = EnlargeBox(mo->getWorldBoundingBox()); 123 124 // compute measure how much aabbs overlap 125 overlap = RatioOfOverlap(OgreTypeConverter::ConvertFromOgre(mybox), 126 OgreTypeConverter::ConvertFromOgre(bbox)); 127 128 if (overlap > bestFit) 129 { 130 bestFit = overlap; 131 bestFittingObj = static_cast<Entity *>(mo); 132 133 // perfect fit => object found, early exit 134 if (overlap >= thresh) 135 { 136 return bestFittingObj; 137 } 138 } 139 } 140 } 141 142 if (0) 143 { 144 std::stringstream d; 145 if (bestFittingObj) 146 d << "best fit: " << bestFit; 147 else 148 d << "warning, no best fitting object\n" << box; 149 150 Ogre::LogManager::getSingleton().logMessage(d.str()); 151 } 152 153 return bestFittingObj; 154 } 155 //----------------------------------------------------------------------- 156 template<typename T> 157 void PlatFormBoundingBoxConverter<T>::FindIntersectingObjects(const AxisAlignedBox &box, 158 EntityContainer &objects) const 159 { 160 list<SceneNode *> sceneNodeList; 161 162 // get intersecting scene nodes (= candidates) 163 //AxisAlignedBox mybox = EnlargeBox(box); 164 //mSceneMgr->findNodesIn(mybox, sceneNodeList, NULL); 165 mSceneMgr->findNodesIn(box, sceneNodeList, NULL); 166 167 list<SceneNode *>::const_iterator sit, sit_end = sceneNodeList.end(); 168 169 //GtpVisibilityPreprocessor::AxisAlignedBox nodeBox = OgreTypeConverter::ConvertFromOgre(mybox); 170 GtpVisibilityPreprocessor::AxisAlignedBox3 nodeBox = OgreTypeConverter::ConvertFromOgre(box); 171 172 // find really intersecting objects 76 173 for (sit = sceneNodeList.begin(); sit != sceneNodeList.end(); ++ sit) 77 174 { … … 89 186 } 90 187 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) 188 //const AxisAlignedBox bbox = EnlargeBox(mo->getWorldBoundingBox()); 189 const AxisAlignedBox bbox = mo->getWorldBoundingBox(); 190 191 const bool overlaps = Overlap(nodeBox, 192 OgreTypeConverter::ConvertFromOgre(bbox) 193 ); 194 //,0.00001); 195 196 if (overlaps) 98 197 { 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 } 198 objects.push_back(static_cast<Entity *>(mo)); 107 199 } 108 200 } 109 201 } 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 } 202 } 203 204 #if USE_KD_PVS 205 //------------------------------------------------------------------------- 206 template<typename T> 207 bool PlatFormBoundingBoxConverter<T>::IdentifyObjects( 208 const GtpVisibilityPreprocessor::IndexedBoundingBoxContainer &iboxes, 209 GtpVisibilityPreprocessor::ObjectContainer &objects) const 210 { 211 Ogre::LogManager().logMessage("pvs: intersecting objects"); 212 const long startTime = GtpVisibilityPreprocessor::GetTime(); 213 214 GtpVisibilityPreprocessor::IndexedBoundingBoxContainer:: 215 const_iterator iit, iit_end = iboxes.end(); 216 217 int i = 0; 218 219 for (iit = iboxes.begin(); iit != iit_end; ++ iit, ++ i) 220 { 221 if ((i % 1000) == 0) 222 { 223 std::stringstream d; d << "found " << i << " objects"; 224 Ogre::LogManager().getSingleton().logMessage(d.str()); 225 } 226 227 const AxisAlignedBox box = OgreTypeConverter::ConvertToOgre((*iit).second); 228 229 //GtpVisibilityPreprocessor::ObjectContainer *entryObjects = new EntityContainer(); 230 EntityContainer *entryObjects = new EntityContainer(); 231 232 // find all objects that intersect the bounding box 233 FindIntersectingObjects(box, *entryObjects); 234 235 /*vector<Entity *>::const_iterator mit, mit_end = sceneObjects.end(); 236 237 for (mit = sceneObjects.begin(); mit != mit_end; ++ mit) 238 { 239 Entity *ent = *mit; 240 // create new mesh instance 241 OgreMeshInstance *omi = new OgreGetOrCreateOgreMeshInstance(ent); 242 //omi->SetId((*iit).first); 243 entryObjects->push_back(omi); 244 }*/ 245 246 ObjectsIntersectable *entry = 247 new ObjectsIntersectable(entryObjects); 248 entry->SetId((*iit).first); 249 //kdObj->mBbox = (*iit).second; 250 objects.push_back(entry); 251 } 252 253 std::stringstream d; d << "finished object intersection in " << GtpVisibilityPreprocessor::TimeDiff(startTime, GtpVisibilityPreprocessor::GetTime()) * 1e-3 << "secs"; 254 Ogre::LogManager().logMessage(d.str()); 255 256 return true; 257 } 258 #else 124 259 //------------------------------------------------------------------------- 125 260 template<typename T> … … 138 273 Entity *ent = FindBestFittingObject(currentBox); 139 274 140 // create new mesh instance141 275 if (ent) 142 276 { 277 // create new mesh instance 143 278 OgreMeshInstance *omi = new OgreMeshInstance(ent); 144 279 omi->SetId((*iit).first); … … 149 284 return true; 150 285 } 151 286 #endif 152 287 153 288 typedef PlatFormBoundingBoxConverter<OctreeSceneManager> OctreeBoundingBoxConverter; -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionCullingSceneManager.h
r1606 r1616 225 225 int mCurrentEntityId; 226 226 227 typedef map<int, MovableObject *> Movable ObjectsMap;227 typedef map<int, MovableObject *> MovableMap; 228 228 229 229 /// hash table for view cells geometry 230 MovableObjectsMap mViewCellsGeometry; 230 MovableMap mViewCellsGeometry; 231 232 bool mViewCellsGeometryLoaded; 231 233 }; 232 234
Note: See TracChangeset
for help on using the changeset viewer.