VR-Forces 4.7 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
osgEarthTerrainSourceTracker.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2010 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
8 
9 #pragma once
10 
16 
18 
19 #include <vrfutil/vertexList.h>
20 
21 //Mak Terrain Toolkit includes
22 #include <geometry/sphere.h>
23 
24 //#include <vlutil/vlSmartPointers.h>
25 
26 #include <osgTerrain/TerrainTile>
27 #include <osgEarth/Profile>
28 #include <osgEarth/TileKey>
29 #include <osgEarth/MapNode>
30 #include <osgEarth/TerrainTileModel>
31 
32 #include <string>
33 #include <list>
34 #include <vector>
35 
36 #include <boost/ptr_container/ptr_vector.hpp>
37 
38 #include <tbb/spin_rw_mutex.h>
39 
43 class DtPoint;
44 class DtGeodeticCoord;
52 
53 typedef std::list<osgEarth::TileKey> DtTileKeyList;
54 
57 {
58  enum TileType
59  {
61  Empty
62  };
63 
66  {
67  typedef std::vector<Extent> Vector;
68 
70  static Vector Simplify(const Vector& extents);
71 
72  explicit Extent(const osgEarth::TileKey&);
73  explicit Extent(const DtVector& min, const DtVector& max);
74 
75  DtVector min, max;
76  };
77 
80  {
81  typedef std::vector<IndexExtent> Vector;
82 
83  explicit IndexExtent(const DtTileData& tile, const Extent& extent);
84 
85  unsigned minx, miny, maxx, maxy;
86  };
87 
89  explicit DtTileData(
90  const DtOsgEarthTerrainSourceTracker& tracker,
91  const osgEarth::TileKey& key);
92 
94  virtual ~DtTileData();
95 
98 
100  const osgEarth::TileKey tileKey;
101 
103  osg::ref_ptr<osgEarth::TerrainTileModel> tileModel;
104 
107 
109  virtual void addMaskExtents(const Extent::Vector& extents);
110 
116  virtual bool insideValidArea(const DtPoint& p) const;
117 
124  virtual bool extentInsideValidArea(unsigned x1, unsigned y1, unsigned x2, unsigned y2) const;
125 
131  virtual bool extentOutsideValidArea(unsigned x1, unsigned y1, unsigned x2, unsigned y2) const;
132 
138  virtual bool addActiveTileKey(const osgEarth::TileKey& key) = 0;
139 
145  virtual void recomputeActiveTileKeyAreas() = 0;
146 
149 
152  std::vector< osg::ref_ptr<osg::Node> > geometries;
153 
155  virtual std::string description() const = 0;
156 
158  virtual unsigned numberOfVertices() const = 0;
159 
163  virtual unsigned numberOfTrianglesForVertices() const;
164 
166  virtual void getTriangleVertices(unsigned xindex, unsigned yindex, double& x, double& y) const = 0;
167 
169  virtual DtVector getTriangleVertices(unsigned xindex, unsigned yindex) const;
170 
172  virtual void getTriangleIndices(double x, double y, unsigned& xindex, unsigned& yindex) const = 0;
173 
176  virtual void heightfieldIndexForTriangleIndex(
177  unsigned triangleXIndex, unsigned triangleYIndex,
178  unsigned& heightFieldXUsed, unsigned& heightFieldYUsed) const = 0;
179 
181  virtual double interpolateHeight(
182  unsigned triangleXIndex, unsigned triangleYIndex,
183  unsigned* heightFieldXUsed = 0, unsigned* heightFieldYUsed = 0) const = 0;
184 
187  tbb::atomic<unsigned int> numTriangles;
188 
192 
194  virtual DtTerrainIntersectIDType getLastUsed() const = 0;
195 
197  virtual bool updateLastUsed(DtTerrainIntersectIDType value) = 0;
198 
205  virtual bool findIntersections(
206  const DtChord& chord,
207  unsigned x1, unsigned y1, unsigned x2, unsigned y2,
210  bool singleCell = false,
211  bool insideValidAreaChecked = false) const;
212 
215  virtual bool findIntersections(
216  const DtChord& chord,
218  DtIntersectionRecord::DtIntersectionType irtFlag) const = 0;
219 
226  virtual void findTriangles(
227  const DtTerrainProcessPolygonsBox& box,
228  unsigned x1, unsigned y1, unsigned x2, unsigned y2,
230  bool singleCell = false,
231  bool insideValidAreaChecked = false) const;
232 
235  virtual void findTriangles(
236  const DtTerrainProcessPolygonsBox& box,
237  DtTriangleOutputInterface&) const = 0;
238 
239 protected:
240  mutable tbb::spin_rw_mutex maskExtentsMutex;
241 
245 
248 };
249 
251 {
252 public:
253  class TileDataCallback;
254 
257  osgEarth::MapNode* mapNode);
258 
260  virtual bool useRawElevation() const;
261 
263  virtual boost::optional<DtTerrainIntersectOptions::Fidelity> intersectFidelity() const;
264 
267  virtual unsigned maxLOD() const;
268  virtual void setMaxLOD(unsigned);
270 
274  virtual unsigned getMaxLODForBilinearIntersection() const;
275  virtual void setMaxLODForBilinearIntersection(unsigned);
277 
284  virtual double triangleOutputMergeTolerance() const;
285  virtual void setTriangleOutputMergeTolerance(double tol);
286  virtual double intersetionTriangleMergeTolerance() const;
287  virtual void setIntersectionTriangleMergeTolerance(double tol);
289 
292  virtual unsigned minElevationIndexLOD() const;
293  virtual void setMinElevationIndexLOD(unsigned);
294  virtual unsigned maxElevationIndexLOD() const;
295  virtual void setMaxElevationIndexLOD(unsigned);
297 
300  virtual double maxChordLengthBeforeSplitSquared() const;
301  virtual void setMaxChordLengthBeforeSplit(double);
303 
306  virtual unsigned maxElevationChordSplitTestLOD() const;
307  virtual void setMaxElevationChordSplitTestLOD(unsigned);
309 
311  virtual unsigned tileCount() const;
312 
314  virtual unsigned cellCount() const;
315 
317  virtual osgEarth::MapNode* mapNode() const;
318 
320  virtual bool init(DtTerrainSourcePager&);
321 
325  virtual void addPagedInTile(
326  const osgEarth::TileKey& tilekey,
327  const boost::shared_ptr<DtTileData>& tileData);
328 
330  virtual void removePagedInTile(const osgEarth::TileKey tileKey);
331 
338  virtual bool dataAvailable(DtPagingMetaDataPtr metaData,
339  DtTerrainPagingGeometryPtr geometry);
340 
346  virtual bool findHeightFieldIntersections(
347  DtTerrainIntersectStatus& status,
348  const DtChord& chord,
350  const DtTerrainIntersectOptions& options) const;
351 
356  virtual bool halveChordAndFindHeightFieldIntrx(
357  const DtChord& chord, DtChord convertedChord,
358  const DtTerrainIntersectOptions& options,
359  DtTerrainIntersectStatus& status,
360  DtVrfChordIntersectRecordList& intList) const;
361 
365  virtual bool splitChordAt180AndFindHeightFieldIntrx(
366  const DtChord& chord,
367  const DtTerrainIntersectOptions& options,
368  DtTerrainIntersectStatus& status,
369  DtVrfChordIntersectRecordList& intList) const;
370 
374  virtual void processTriangles(
376  const DtTerrainProcessPolygonsBox& box) const;
377 
385  virtual void pageInData(DtPagingMetaDataPtr metaData,
386  DtTerrainPagingGeometryPtr geometry);
387 
393  virtual DtTerrainIntersectIDType findOldestPagedData(unsigned int& numTrianglesOut);
394 
397  virtual void pageOutOldestData(const int priority);
398 
400  virtual bool canPageOutData(DtTerrainIntersectIDType intersectId);
401 
408  virtual osgEarth::TileKey getBestTileKey(const osgEarth::TileKey&) const;
409 
411  virtual void findMissingTiles(const DtTerrainPagingGeometryPtr& geometry, DtTileKeyList& tiles) const;
412 
415  {
416  public:
418  virtual bool processIndex(const DtString& name) { return true; }
420  virtual bool process(const osgEarth::TileKey& key) { return true; }
422  virtual bool traverse(const osgEarth::TileKey& key) { return true; }
424  virtual void tileWritten(const osgEarth::TileKey& key, double min, double max) { }
425  };
426 
429  {
430  public:
433  static std::auto_ptr<IndexOutputInterface> Create(const DtFilename&, unsigned precision);
434 
435  virtual ~IndexOutputInterface();
436 
437  virtual void write(const osgEarth::TileKey& tile, double min, double max, bool valid) = 0;
438  };
439 
441  virtual void writeIndex(IndexInterface&, IndexOutputInterface&) const;
444  virtual bool writeIndexLayers(IndexInterface&, unsigned precision) const;
445 
448  {
449  public:
451  static std::auto_ptr<IndexInputInterface> Create(const DtFilename&);
452 
453  virtual ~IndexInputInterface();
454 
455  virtual bool read(unsigned& lod, unsigned& x, unsigned& y, double& min, double& max, bool& valid) = 0;
456  };
457 
460  {
461  std::string name;
462  osgEarth::URI file;
463  bool isDefault;
464  double minTolerance, maxTolerance;
465  unsigned minlod, maxlod;
466  osgEarth::GeoExtent extent;
467 
468  explicit IndexConfig(const DtOsgEarthTerrainSourceTracker&, const osgEarth::Config&);
470  };
471 
473  virtual std::vector<IndexConfig> getIndexConfigInfoForLayer(
474  const osgEarth::ElevationLayer& layer) const;
475 
477  virtual void readIndex(
479  unsigned layerNumber,
480  const IndexConfig& idxConfig);
481 
484  virtual bool readIndexLayers();
485 
486 protected:
487 
488  virtual DtPageInTilesCommand* createPageInTilesCommand(
489  DtPagingMetaDataPtr metaData);
490 
491  virtual DtPageOutTilesCommand* createPageOutTilesCommand(
492  DtPagingMetaDataPtr metaData);
493 
494 protected:
495 
497  {
498  public:
500  {
501  static boost::optional<ElevationRange> Merge(
502  const boost::optional<ElevationRange>& r1,
503  const boost::optional<ElevationRange>& r2);
504 
505  double min, max;
506 
507  ElevationRange();
508  ElevationRange(double min, double max);
509 
510  void merge(const ElevationRange&);
511  };
512 
514  const DtOsgEarthTerrainSourceTracker& tracker,
515  const osgEarth::TileKey& tilekey,
516  TileSpatialIndex* parent);
517 
518  void getExtent(DtVector& lower, DtVector& upper, bool useElevation = true) const;
519  void getSubTileExtent(unsigned i, DtVector& lower, DtVector& upper, bool useElevation = true) const;
520 
521  bool intersects(const DtTerrainPagingGeometry& geometry) const;
522  bool intersectsSubTile(const DtTerrainPagingGeometry& geometry, int i) const;
523 
524  bool chordIntersects(const DtChord& chord, bool useElevation = true) const;
525  bool extentIntersects(const DtExtent& extent) const;
526  bool sphereIntersects(const DtSphere& sphere) const;
527  bool shapeIntersects(const DtLocalVertexList& shape) const;
528  bool chordIntersectsSubTile(const DtChord& chord, int i, bool useElevation = true) const;
529  bool extentIntersectsSubTile(const DtExtent& shape, int i) const;
530  bool sphereIntersectsSubTile(const DtSphere& sphere, int i) const;
531  bool shapeIntersectsSubTile(const DtLocalVertexList& shape, int i) const;
532 
534  void findMissing(
535  const DtTerrainPagingGeometry& geometry,
536  DtTileKeyList& missing) const;
537 
540  bool findData(
541  const DtTerrainPagingGeometry* geometry,
542  std::vector< boost::shared_ptr<DtTileData> >& data,
543  TileDataCallback* callback = 0) const;
544 
547  boost::optional<double> getMaxAltForChord(const DtChord& chord, unsigned maxlod) const;
548 
550  boost::shared_ptr<DtTileData> findOldest() const;
551 
557  bool addTile(const osgEarth::TileKey& key, const boost::shared_ptr<DtTileData>& data);
558 
560  void removeTile(const osgEarth::TileKey& tilekey);
561 
563  unsigned tileCount() const;
564 
566  unsigned cellCount() const;
567 
569  const osgEarth::TileKey tileKey() const { return myTileKey; }
570 
572  TileSpatialIndex* setAltitudeRange(
573  const osgEarth::TileKey& key,
574  const ElevationRange& range,
575  const ElevationRange& offsets,
576  unsigned layerNum,
577  bool coversTile);
578 
580  bool postProcessIndexLayer(unsigned layerNum);
581 
584  void writeIndex(
585  IndexInterface& iface,
586  IndexOutputInterface& output,
587  osgEarth::ElevationLayer* layer = 0) const;
588 
589  protected:
591  bool isTileEmpty() const;
592 
595  virtual void recomputePagedInData();
596 
599 
601  const osgEarth::TileKey myTileKey;
603  const osgEarth::GeoExtent myGeoExtent;
605  const bool myUseElevationFlag;
606 
608  boost::optional<ElevationRange> myElevationRange;
609 
614  {
617 
618  ValidElevationRange(const ElevationRange& range, bool coversTile)
619  : range(range), coversTile(coversTile) { }
620  };
621 
622  std::vector< boost::optional<ValidElevationRange> > myPreviousLayersElevationRange;
624 
626  bool myPinned;
627 
628  struct SubTileSlot
629  {
630  osgEarth::GeoExtent extent;
631  boost::scoped_ptr<TileSpatialIndex> subtile;
632  };
633 
635  SubTileSlot& getOrCreateSlot(unsigned i);
636 
638  void pageOutSlotIfUnused(unsigned i);
639 
641  SubTileSlot mySubTiles[4];
642 
644  boost::shared_ptr<DtTileData> myTileData;
645 
649 
652  };
653 
656  virtual void convertGeometry(
657  const DtTerrainPagingGeometryPtr& geometry,
658  std::vector<DtTerrainPagingGeometryPtr>& output) const;
659 
660  virtual bool convertGeometry(
661  const DtTerrainPagingChord& geometry,
662  std::vector<DtTerrainPagingGeometryPtr>& output) const;
663 
664  virtual bool convertGeometry(
665  const DtTerrainPagingSphere& geometry,
666  std::vector<DtTerrainPagingGeometryPtr>& output) const;
667 
668  virtual bool convertGeometry(
669  const DtTerrainPagingShape& geometry,
670  std::vector<DtTerrainPagingGeometryPtr>& output) const;
672 
673  virtual bool nearCenterOfEarth(const DtChord& chord) const;
674 
675  virtual bool aboveAllTerrain(
676  const DtChord& geocentricChord,
677  const DtChord& geodeticCoord) const;
678 
681  virtual bool shortEnoughForIntersection(
682  const DtChord& geocentricChord,
683  const DtChord& geodeticChord,
684  double chordLengthSq) const;
685 
688  virtual bool crosses180Lon(const DtChord& geodeticChord) const;
689 
690  virtual bool findData(
691  const DtTerrainPagingGeometry* geometry,
692  std::vector< boost::shared_ptr<DtTileData> >& data,
693  const DtPagingMetaDataPtr& metaData = DtPagingMetaDataPtr(),
694  TileDataCallback* callback = 0) const;
695 
696  virtual bool findData(
697  const DtTerrainPagingGeometry* geometry,
698  std::vector< boost::shared_ptr<DtTileData> >& data,
699  TileDataCallback* callback) const;
700 
701  virtual void findMissing(
702  const DtTerrainPagingGeometry& geometry,
703  DtTileKeyList& missing) const;
704 
705  virtual boost::shared_ptr<DtTileData> findOldest() const;
706  virtual boost::shared_ptr<DtTileData> findOldestUnlocked() const;
707 
708  typedef boost::ptr_vector<TileSpatialIndex> TileRoots;
709 
711  const osg::ref_ptr<osgEarth::MapNode> myMapNode;
712 
714  osgEarth::ElevationLayerVector myElevationLayers;
715 
717  osgEarth::ElevationLayerVector myFlattenedElevationLayers;
718 
720  const bool myUseRawElevation;
721 
723  unsigned int myMaxLOD;
724 
727 
731 
735 
738 
741 
744 
746  const double myWorldWidth;
747 
750 
752  boost::weak_ptr<DtTileData> myOldestData;
753 };
754 
756 {
757 public:
758  explicit TileDataCallback();
759 
760  virtual bool operator()(const boost::shared_ptr<DtTileData>& tile) = 0;
761 
762 private:
764 
766 };

Document ID: Generated on Fri Apr 26 21:53:14 EDT 2019 from SVN revision 197883
Copyright © 2005-2019 VT MAK. All Rights Reserved (www.mak.com)