VR-Forces 4.1.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  struct ProcessedMtf
98  {
99  typedef std::list<std::string> FileList;
100 
103 
106  };
107 
108  virtual ProcessedMtf processMtfFile(const DtString& filename);
109 
110  virtual bool processMapNode(osgEarth::MapNode* mapNode);
111 
114  virtual void startTerrainEngineThread();
118 
122 
124  virtual void setDatabasePager(osgDB::DatabasePager* databasePager) { theDatabasePager = databasePager; };
125 
127  virtual osg::ref_ptr<osgDB::DatabasePager> databasePager() { return theDatabasePager; };
128 
131 
133 
134  virtual void setDebugDrawer(DtSharedMemoryBulletDebugDrawer* drawer);
135 
137 
139 
142  virtual makVrv::DtDe* de();
143 
144  virtual DtCollisionWorld* collisionWorld();
145 
146  virtual void setLastIntersectId(unsigned int intersectId);
147 
150  virtual void setLoadImages(const bool& shouldLoadImages);
151 
153  //virtual osg::ref_ptr<osg::Node> terrainRoot(int childIndex);
154 
155  virtual DtDrawMode drawMode() const;
156  virtual void setDrawMode(const DtDrawMode& drawMode);
157 
158  virtual const unsigned int numTriangles() const;
159  virtual void setNumTriangles(const unsigned int& numTriangles);
160 
161  virtual const unsigned int triangleThreshold() const;
162  virtual void setTriangleThreshold(const unsigned int& threshold);
163 
166 
167 public:
168 
171  virtual void updatePageTracker();
172 
173  virtual void updateDrawer();
174 
177  bool threadShouldExit() const;
178 
179  virtual void updateCollisionObjectsDrawState();
180 
181  virtual void decrementPendingPageOutOperations();
182 
183  virtual void pageOutTerrainNextTick();
184 
185  virtual void expireCommandsBeforeTime(const double& currentTime);
186 
188 
190 
191 protected:
193  virtual void reRegisterAgentCreators(makVrv::DtDe* de);
194 
196 
201  virtual std::list<std::string> vrvPluginsToLoad(const std::string& pluginDir);
202 
203 
204 protected:
208  static osg::ref_ptr<osgDB::DatabasePager> theDatabasePager;
209 
213  tbb::concurrent_queue<DtTerrainEngineCommand*> myCommandQueue;
214  tbb::tbb_thread* myTerrainEngineThread;
215  mutable tbb::mutex myShutdownMutex;
217 
218  mutable tbb::spin_rw_mutex myMutex;
219 
221 
223 
225 
227  bool myRedraw;
228 
229  unsigned int myLastIntersectId;
231  unsigned int myNumTriangles;
233 
236 
240 
242 
243  boost::scoped_ptr<DtTerrainAltitudeTable> myTerrainAltitudeTable;
244 
245  static bool theWorkLeft;
246 };
247 
248 class DtNodeUserData : public osg::Referenced
249 {
250 public:
251 
252  inline DtNodeUserData()
253  : osg::Referenced()
254  , myCollisionObject(0)
255  , myPendingRequestId(-1)
256  {
257  };
258 
260 
261  virtual btCollisionObject* collisionObject() const { return myCollisionObject; };
262  virtual void setCollisionObject(btCollisionObject* collisionObject) { myCollisionObject= collisionObject; };
264 
266 
267  virtual const int pendingRequestId() const { return myPendingRequestId; };
268  virtual void setPendingRequestId(int id) { myPendingRequestId = id; };
270 
271 protected:
272 
274  virtual ~DtNodeUserData() {};
275 
277  btCollisionObject* myCollisionObject;
278 
286 };
287 
288 class DtReadFileCallback : public osgDB::Registry::ReadFileCallback
289 {
290 public:
291 
292  DtReadFileCallback(osgDB::Registry::ReadFileCallback* current)
293  : osgDB::Registry::ReadFileCallback()
294  , myLoadImages(false)
295  , myCurrentReadFileCallback(current)
296  {
297 
298  }
299 
300  virtual osgDB::ReaderWriter::ReadResult readImage(const std::string& filename, const osgDB::ReaderWriter::Options* options)
301  {
302  if (loadImages())
303  {
304  DtVerbose << "Reading Image: " << filename << std::endl;
305 
307  {
308  return myCurrentReadFileCallback->readImage(filename, options);
309  }
310  else
311  {
312  return osgDB::Registry::instance()->readImageImplementation(filename, options);
313  }
314  }
315  else
316  {
317  //Ignore images. We don't need them. However, create an empty one and set the filename for later
319  boost::unordered_map<std::string, osg::ref_ptr<osg::Image> >::iterator iter = myMappedImages.find(filename);
320  osg::ref_ptr<osg::Image> img;
321 
322  if (iter == myMappedImages.end())
323  {
324  img = new osg::Image;
325  myMappedImages[filename] = img;
326 
327  DtFilename stripDown(filename.c_str());
328 
329  stripDown.stripPath();
330 
331  img->setFileName(stripDown.c_str());
332  }
333  else
334  {
335  img = iter->second;
336  }
337 
338  //return img;
339  return osgDB::ReaderWriter::ReadResult(img.get(), osgDB::ReaderWriter::ReadResult::FILE_NOT_HANDLED);
340  }
341 
342  }
343 
344  virtual osgDB::ReaderWriter::ReadResult openArchive(
345  const std::string& filename,osgDB::ReaderWriter::ArchiveStatus status,
346  unsigned int indexBlockSizeHint,
347  const osgDB::ReaderWriter::Options* useObjectCache)
348  {
350  {
351  return myCurrentReadFileCallback->openArchive(filename,
352  status, indexBlockSizeHint, useObjectCache);
353  }
354  else
355  {
356  return osgDB::Registry::instance()->openArchiveImplementation(filename,
357  status, indexBlockSizeHint, useObjectCache);
358  }
359  }
360 
361  virtual osgDB::ReaderWriter::ReadResult readObject(
362  const std::string& filename, const osgDB::ReaderWriter::Options* options)
363  {
365  {
366  return myCurrentReadFileCallback->readObject(filename, options);
367  }
368  else
369  {
370  return osgDB::Registry::instance()->readObjectImplementation(filename,
371  options);
372  }
373  }
374 
375  virtual osgDB::ReaderWriter::ReadResult readHeightField(
376  const std::string& filename, const osgDB::ReaderWriter::Options* options)
377  {
379  {
380  return myCurrentReadFileCallback->readHeightField(filename, options);
381  }
382  else
383  {
384  return osgDB::Registry::instance()->readHeightFieldImplementation(filename,
385  options);
386  }
387  }
388 
389  virtual osgDB::ReaderWriter::ReadResult readShader(
390  const std::string& filename, const osgDB::ReaderWriter::Options* options)
391  {
393  {
394  return myCurrentReadFileCallback->readShader(filename, options);
395  }
396  else
397  {
398  return osgDB::Registry::instance()->readShaderImplementation(filename,
399  options);
400  }
401  }
402 
403  virtual osgDB::ReaderWriter::ReadResult readNode(const std::string& filename, const osgDB::ReaderWriter::Options* options)
404  {
405  osgDB::ReaderWriter::ReadResult readResult;
406 
408  {
409  readResult = myCurrentReadFileCallback->readNode(filename, options);
410  }
411  else
412  {
413  readResult = osgDB::Registry::instance()->readNodeImplementation(filename, options);
414  }
415 
416  std::string className;
417 
418  if (readResult.getNode())
419  {
420  className = readResult.getNode()->className();
421 
422  readResult.getNode()->setUserData(new DtNodeUserData());
423 
424  DtVerbose << " Reading " << className << ": " << filename << std::endl;
425  }
426  else if (readResult.status() == osgDB::ReaderWriter::ReadResult::FILE_NOT_FOUND)
427  {
428  //DtVantageTerrainEngine::terrainEngine()->addToFilesNotFound(filename);
429  //DtVantageTerrainEngine::terrainEngine()->updateDrawer();
430  }
431 
432  return readResult;
433  }
434 
435  virtual void setLoadImages(const bool& loadImages) { myLoadImages = loadImages; }
436 
437  virtual bool loadImages() const { return myLoadImages; }
438 
439 protected:
440 
442 
443  virtual ~DtReadFileCallback() {}
444 
445 protected:
446  boost::unordered_map<std::string, osg::ref_ptr<osg::Image> > myMappedImages;
447  osg::ref_ptr<osgDB::Registry::ReadFileCallback> myCurrentReadFileCallback;
448 };
449 
451 {
452 public:
453  typedef DtPoint Point;
454 
457  const osgEarth::Map* map, unsigned lod,
458  double bias=30000, double factor=2);
459 
460  typedef std::vector<DtChord> ChordVector;
461 
462  void breakUpChord(const MAKVRinTerra::DtProj& proj, DtChord, ChordVector& chords);
463 
464  typedef std::pair<double,double> Segment;
465  typedef std::set<Segment> SegmentSet;
466 
467 protected:
470  const osgEarth::TileKey& tilekey, const osgEarth::Map* map, unsigned lod,
472  double bias, double factor);
473 
476  const osgEarth::TileKey& tilekey,
477  const osg::HeightField* field,
478  unsigned xmin, unsigned xmax, unsigned ymin, unsigned ymax,
480  double bias, double factor);
481 
487  void removeSegments(const DtChord& chord, SegmentSet& set);
488 
490  void createBoundaries();
491 
493  void setMaxHeight();
494 
495  typedef boost::ptr_vector<DtTerrainAltitudeTable> SubCellVector;
496  typedef std::vector<DtChord> BoundaryVector;
497 
498  osgEarth::TileKey myTileKey;
502  double myMaxHeight;
504  double myBias;
505  double myFactor;
506 };

Document ID: Generated on Mon Apr 8 19:24:01 EDT 2013 from SVN revision 125877
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)