VR-Forces 4.1 Class Documentation
vantageTerrainEngine.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2010 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
8 
10 
11 #pragma once
12 
19 
20 //vrlink includes
21 #include <vlutil/vlPrint.h>
22 #include <vlutil/vlFilename.h>
23 
24 //vrvantage includes
26 
27 //osg includes
28 #include <osgDB/Registry>
29 #include <osgTerrain/TerrainTile>
30 
31 //threadingBuildingBlocks includes
32 #include <tbb/concurrent_queue.h>
33 #include <tbb/tbb_thread.h>
34 #include <tbb/mutex.h>
35 
36 #include <boost/scoped_ptr.hpp>
37 #include <boost/ptr_container/ptr_vector.hpp>
38 #include <features/feature.h>
39 #include <features/pathFeature.h>
41 
43 class DtCollsionWorld;
44 class btIDebugDraw;
45 class DtCollisionWorld;
46 class DtString;
48 class DtTerrainEngineCommand;
49 class DtPageInVisitor;
50 class DtReadFileCallback;
53 
54 namespace makVrv
55 {
56  class DtDe;
57  class DtCoordinateSystem;
58 }
59 
60 typedef std::list<DtTerrainSourcePager*> DtTerrainSourcePagerList;
61 
62 
69 {
70 public:
71  typedef std::map<std::string,std::string> TerrainSettings;
72 
73 private:
75 
79 
80 public:
83  virtual ~DtVantageTerrainEngine();
84 
85  virtual void tick();
86 
90 
91  virtual bool loadTerrain(const DtString& filename,
93  const TerrainSettings& settings = TerrainSettings());
94 
95  virtual bool loadOsgEarthFile(const DtString& filename, MAKVRinTerra::DtFeatureLoader&);
96 
97  virtual makArchives::DtSceneRecord processMtfFile(const DtString& filename, std::list<std::string>& osgEarthFilenames);
98 
99  virtual bool processMapNode(osgEarth::MapNode* mapNode);
100 
103  virtual void startTerrainEngineThread();
107 
111 
113  virtual void setDatabasePager(osgDB::DatabasePager* databasePager) { theDatabasePager = databasePager; };
114 
116  virtual osg::ref_ptr<osgDB::DatabasePager> databasePager() { return theDatabasePager; };
117 
120 
122 
123  virtual void setDebugDrawer(DtSharedMemoryBulletDebugDrawer* drawer);
124 
126 
128 
131  virtual makVrv::DtDe* de();
132 
133  virtual DtCollisionWorld* collisionWorld();
134 
135  virtual void setLastIntersectId(unsigned int intersectId);
136 
139  virtual void setLoadImages(const bool& shouldLoadImages);
140 
142  //virtual osg::ref_ptr<osg::Node> terrainRoot(int childIndex);
143 
144  virtual DtDrawMode drawMode() const;
145  virtual void setDrawMode(const DtDrawMode& drawMode);
146 
147  virtual const unsigned int numTriangles() const;
148  virtual void setNumTriangles(const unsigned int& numTriangles);
149 
150  virtual const unsigned int triangleThreshold() const;
151  virtual void setTriangleThreshold(const unsigned int& threshold);
152 
155 
156 public:
157 
160  virtual void updatePageTracker();
161 
162  virtual void updateDrawer();
163 
166  bool threadShouldExit() const;
167 
168  virtual void updateCollisionObjectsDrawState();
169 
170  virtual void decrementPendingPageOutOperations();
171 
172  virtual void pageOutTerrainNextTick();
173 
174  virtual void expireCommandsBeforeTime(const double& currentTime);
175 
177 
179 
180 protected:
182  virtual void reRegisterAgentCreators(makVrv::DtDe* de);
183 
185 
190  virtual std::list<std::string> vrvPluginsToLoad(const std::string& pluginDir);
191 
192 
193 protected:
197  static osg::ref_ptr<osgDB::DatabasePager> theDatabasePager;
198 
202  tbb::concurrent_queue<DtTerrainEngineCommand*> myCommandQueue;
203  tbb::tbb_thread* myTerrainEngineThread;
204  mutable tbb::mutex myShutdownMutex;
206 
207  mutable tbb::spin_rw_mutex myMutex;
208 
210 
212 
214 
216  bool myRedraw;
217 
218  unsigned int myLastIntersectId;
220  unsigned int myNumTriangles;
222 
225 
229 
231 
232  boost::scoped_ptr<DtTerrainAltitudeTable> myTerrainAltitudeTable;
233 
234  static bool theWorkLeft;
235 };
236 
237 class DtNodeUserData : public osg::Referenced
238 {
239 public:
240 
241  inline DtNodeUserData()
242  : osg::Referenced()
243  , myCollisionObject(0)
244  , myPendingRequestId(-1)
245  {
246  };
247 
249 
250  virtual btCollisionObject* collisionObject() const { return myCollisionObject; };
251  virtual void setCollisionObject(btCollisionObject* collisionObject) { myCollisionObject= collisionObject; };
253 
255 
256  virtual const int pendingRequestId() const { return myPendingRequestId; };
257  virtual void setPendingRequestId(int id) { myPendingRequestId = id; };
259 
260 protected:
261 
263  virtual ~DtNodeUserData() {};
264 
266  btCollisionObject* myCollisionObject;
267 
275 };
276 
277 class DtReadFileCallback : public osgDB::Registry::ReadFileCallback
278 {
279 public:
280 
281  DtReadFileCallback(osgDB::Registry::ReadFileCallback* current)
282  : osgDB::Registry::ReadFileCallback()
283  , myLoadImages(false)
284  , myCurrentReadFileCallback(current)
285  {
286 
287  }
288 
289  virtual osgDB::ReaderWriter::ReadResult readImage(const std::string& filename, const osgDB::ReaderWriter::Options* options)
290  {
291  if (loadImages())
292  {
293  DtVerbose << "Reading Image: " << filename << std::endl;
294 
296  {
297  return myCurrentReadFileCallback->readImage(filename, options);
298  }
299  else
300  {
301  return osgDB::Registry::instance()->readImageImplementation(filename, options);
302  }
303  }
304  else
305  {
306  //Ignore images. We don't need them. However, create an empty one and set the filename for later
308  std::map<std::string, osg::ref_ptr<osg::Image> >::iterator iter = myMappedImages.find(filename);
309  osg::ref_ptr<osg::Image> img;
310 
311  if (iter == myMappedImages.end())
312  {
313  img = new osg::Image;
314  myMappedImages[filename] = img;
315 
316  DtFilename stripDown(filename.c_str());
317 
318  stripDown.stripPath();
319 
320  img->setFileName(stripDown.c_str());
321  }
322  else
323  {
324  img = iter->second;
325  }
326 
327  //return img;
328  return osgDB::ReaderWriter::ReadResult(img.get(), osgDB::ReaderWriter::ReadResult::FILE_NOT_HANDLED);
329  }
330 
331  }
332 
333  virtual osgDB::ReaderWriter::ReadResult openArchive(
334  const std::string& filename,osgDB::ReaderWriter::ArchiveStatus status,
335  unsigned int indexBlockSizeHint,
336  const osgDB::ReaderWriter::Options* useObjectCache)
337  {
339  {
340  return myCurrentReadFileCallback->openArchive(filename,
341  status, indexBlockSizeHint, useObjectCache);
342  }
343  else
344  {
345  return osgDB::Registry::instance()->openArchiveImplementation(filename,
346  status, indexBlockSizeHint, useObjectCache);
347  }
348  }
349 
350  virtual osgDB::ReaderWriter::ReadResult readObject(
351  const std::string& filename, const osgDB::ReaderWriter::Options* options)
352  {
354  {
355  return myCurrentReadFileCallback->readObject(filename, options);
356  }
357  else
358  {
359  return osgDB::Registry::instance()->readObjectImplementation(filename,
360  options);
361  }
362  }
363 
364  virtual osgDB::ReaderWriter::ReadResult readHeightField(
365  const std::string& filename, const osgDB::ReaderWriter::Options* options)
366  {
368  {
369  return myCurrentReadFileCallback->readHeightField(filename, options);
370  }
371  else
372  {
373  return osgDB::Registry::instance()->readHeightFieldImplementation(filename,
374  options);
375  }
376  }
377 
378  virtual osgDB::ReaderWriter::ReadResult readShader(
379  const std::string& filename, const osgDB::ReaderWriter::Options* options)
380  {
382  {
383  return myCurrentReadFileCallback->readShader(filename, options);
384  }
385  else
386  {
387  return osgDB::Registry::instance()->readShaderImplementation(filename,
388  options);
389  }
390  }
391 
392  virtual osgDB::ReaderWriter::ReadResult readNode(const std::string& filename, const osgDB::ReaderWriter::Options* options)
393  {
394  osgDB::ReaderWriter::ReadResult readResult;
395 
397  {
398  readResult = myCurrentReadFileCallback->readNode(filename, options);
399  }
400  else
401  {
402  readResult = osgDB::Registry::instance()->readNodeImplementation(filename, options);
403  }
404 
405  std::string className;
406 
407  if (readResult.getNode())
408  {
409  className = readResult.getNode()->className();
410 
411  readResult.getNode()->setUserData(new DtNodeUserData());
412 
413  DtVerbose << " Reading " << className << ": " << filename << std::endl;
414  }
415  else if (readResult.status() == osgDB::ReaderWriter::ReadResult::FILE_NOT_FOUND)
416  {
417  //DtVantageTerrainEngine::terrainEngine()->addToFilesNotFound(filename);
418  //DtVantageTerrainEngine::terrainEngine()->updateDrawer();
419  }
420 
421  return readResult;
422  }
423 
424  virtual void setLoadImages(const bool& loadImages) { myLoadImages = loadImages; }
425 
426  virtual bool loadImages() const { return myLoadImages; }
427 
428 protected:
429 
431 
432  virtual ~DtReadFileCallback() {}
433 
434 protected:
435  std::map<std::string, osg::ref_ptr<osg::Image> > myMappedImages;
436  osg::ref_ptr<osgDB::Registry::ReadFileCallback> myCurrentReadFileCallback;
437 };
438 
440 {
441 public:
442  typedef DtPoint Point;
443 
446  const osgEarth::Map* map, unsigned lod,
447  double bias=30000, double factor=2);
448 
449  typedef std::vector<DtChord> ChordVector;
450 
451  void breakUpChord(const MAKVRinTerra::DtProj& proj, DtChord, ChordVector& chords);
452 
453  typedef std::pair<double,double> Segment;
454  typedef std::set<Segment> SegmentSet;
455 
456 protected:
459  const osgEarth::TileKey& tilekey, const osgEarth::Map* map, unsigned lod,
461  double bias, double factor);
462 
465  const osgEarth::TileKey& tilekey,
466  const osg::HeightField* field,
467  unsigned xmin, unsigned xmax, unsigned ymin, unsigned ymax,
469  double bias, double factor);
470 
476  void removeSegments(const DtChord& chord, SegmentSet& set);
477 
479  void createBoundaries();
480 
482  void setMaxHeight();
483 
484  typedef boost::ptr_vector<DtTerrainAltitudeTable> SubCellVector;
485  typedef std::vector<DtChord> BoundaryVector;
486 
487  osgEarth::TileKey myTileKey;
491  double myMaxHeight;
493  double myBias;
494  double myFactor;
495 };

Document ID: Generated on Tue Jan 29 18:21:16 EST 2013 from SVN revision 123193
Copyright © 2005-2013 VT MÄK Inc. All Rights Reserved (www.mak.com)