Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
TiledGeom.h
1 //
2 // vtTiledGeom : Renders tiled heightfields using Roettger's libMini library
3 //
4 // Copyright (c) 2005-2011 Virtual Terrain Project
5 // Free for all uses, see license.txt for details.
6 //
7 
8 #ifndef TILEDGEOMH
9 #define TILEDGEOMH
10 
11 #include "vtdata/HeightField.h"
12 #include "vtdata/vtString.h"
13 #include "minidata/MiniDatabuf.h"
14 #include <map>
15 
16 #define TILEDGEOM_RESOLUTION_MIN 80.0f
17 #define TILEDGEOM_RESOLUTION_MAX 80000.0f
18 
21 
23 {
24 public:
26  bool Read(const char *ini_fname);
27  bool GetCorners(DLine2 &line, bool bGeo) const;
28 
29  int cols, rows;
30  int lod0size;
31  DRECT earthextents;
32  float minheight, maxheight; // for elevation tilesets only
33  vtProjection proj;
34  LODMap lodmap;
35  bool bJPEG;
36 };
37 
38 // Simple cache of tiles loaded from disk
39 typedef uchar *ucharptr;
40 class databuf;
41 class ReqContext;
42 
43 typedef bool (*ProgFuncPtrType)(int);
44 
50 class vtTiledGeom : public vtDynGeom, public vtHeightField3d
51 {
52 public:
53  vtTiledGeom();
54  ~vtTiledGeom();
55 
56  bool ReadTileList(const char *dataset_fname_elev,
57  const char *dataset_fname_image, bool bThreading, bool bGradual);
58  void SetVerticalExag(float fExag);
59  float GetVerticalExag() const { return m_fDrawScale; }
60  void SetVertexTarget(int iVertices);
61  int GetVertexTarget() { return m_iVertexTarget; }
62  FPoint2 GetWorldSpacingAtPoint(const DPoint2 &p);
63  void SetTexLODFactor(float factor);
64 
65  // overrides for vtDynGeom
66  void DoRender();
67  void DoCalcBoundBox(FBox3 &box);
68  void DoCull(const vtCamera *pCam);
69 
70  // overrides for vtHeightField
71  bool FindAltitudeOnEarth(const DPoint2 &p, float &fAltitude, bool bTrue = false) const;
72 
73  // overrides for vtHeightField3d
74  bool FindAltitudeAtPoint(const FPoint3 &p3, float &fAltitude,
75  bool bTrue = false, int iCultureFlags = 0,
76  FPoint3 *vNormal = NULL) const;
77  bool CastRayToSurface(const FPoint3 &point, const FPoint3 &dir,
78  FPoint3 &result) const;
79 
80  // Tile methods
81  databuf FetchTile(const char *fname);
82 
83  // CRS of this tileset
84  vtProjection m_proj;
85 
86  // detail level and vertex target
87  float m_fResolution;
88  float m_fHResolution;
89  float m_fLResolution;
90  int m_iVertexTarget;
91  int m_iVertexCount;
92 
93  // Tile cache in host RAM, to reduce loading from disk
94  int m_iFrame;
95  int m_iTileLoads;
96 
97  // Size of base texture LOD
98  int image_lod0size;
99 
100  // Values used to initialize miniload
101  int cols, rows;
102  float coldim, rowdim;
103  FPoint3 center;
104  ucharptr *hfields, *textures;
105  float prange;
106  float prange_min, prange_max;
107 
108  class miniload *GetMiniLoad() { return m_pMiniLoad; }
109  class minitile *GetMiniTile() { return m_pMiniTile; }
110  class datacloud *GetDataCloud() { return m_pDataCloud; }
111  void SetPagingRange(float val);
112  float GetPagingRange();
113 
114  // information about all the tiles LODs which exist
115  bool CheckMapFile(const char *mapfile, bool bIsTexture);
116  vtString m_folder_elev;
117  vtString m_folder_image;
118  TiledDatasetDescription m_elev_info, m_image_info;
119 
120  void SetProgressCallback(ProgFuncPtrType progress_callback)
121  { m_progress_callback = progress_callback; }
122  ProgFuncPtrType m_progress_callback;
123 
124  // Options WWW fetch
125  void SetBaseURL(const char *url);
126  vtString m_strBaseURL;
127  ReqContext *m_pReqContext;
128 
129 protected:
130  // a vtlib material
131  vtMaterial *m_pPlainMaterial;
132 
133  // Values used to render each frame
134  IPoint2 m_window_size;
135  FPoint3 m_eyepos_ogl;
136  float m_fFOVY;
137  float m_fAspect;
138  float m_fNear, m_fFar;
139  FPoint3 eye_up, eye_forward;
140  bool m_bNeedResolutionAdjust;
141 
142  // vertical scale (exaggeration)
143  float m_fMaximumScale;
144  float m_fHeightScale;
145  float m_fDrawScale;
146 
147  // the libMini objects
148  class miniload *m_pMiniLoad;
149  class minitile *m_pMiniTile;
150  class minicache *m_pMiniCache; // This is cache of OpenGL primitives to be rendered
151  class datacloud *m_pDataCloud;
152 
153  void SetupMiniLoad(bool bThreading, bool bGradual);
154 };
155 typedef osg::ref_ptr<vtTiledGeom> vtTiledGeomPtr;
156  // Group dynterr
158 
159 #endif // TILEDGEOMH
160