Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
ElevLayer.h
1 //
2 // ElevLayer.h
3 //
4 // Copyright (c) 2001-2011 Virtual Terrain Project
5 // Free for all uses, see license.txt for details.
6 //
7 
8 #ifndef ELEVLAYER_H
9 #define ELEVLAYER_H
10 
11 #include "wx/image.h"
12 #include "vtdata/ElevationGrid.h"
13 #include "vtdata/HeightField.h"
14 #include "Layer.h"
15 #include "ElevDrawOptions.h"
16 #include "TilingOptions.h"
17 
18 #define SHADING_BIAS 200
19 
20 class vtBitmap;
21 class vtDIB;
22 class vtElevationGrid;
23 class vtFeatureSet;
24 class vtTin2d;
27 class vtHeightField;
28 
30 
31 class vtElevLayer : public vtLayer
32 {
33 public:
34  vtElevLayer();
35  vtElevLayer(const DRECT &area, int iColumns, int iRows,
36  bool bFloats, float fScale, const vtProjection &proj);
38  virtual ~vtElevLayer();
39 
40  // overrides
41  bool GetExtent(DRECT &rect);
42  void DrawLayer(wxDC *pDC, vtScaledView *pView);
43  bool TransformCoords(vtProjection &proj);
44  bool OnSave(bool progress_callback(int) = NULL);
45  bool OnLoad();
46  void GetProjection(vtProjection &proj);
47  void SetProjection(const vtProjection &proj);
48 
49  // optional overrides
50  bool SetExtent(const DRECT &rect);
51  void GetPropertyText(wxString &str);
52  wxString GetFileExtension();
53  bool AskForSaveFilename();
54  bool GetAreaExtent(DRECT &rect);
55 
56  int GetMemoryUsed() const;
57  int MemoryNeededToLoad() const;
58  void FreeData();
59  bool HasData();
60 
61  void OnLeftDown(BuilderView *pView, UIContext &ui);
62  void OnLeftUp(BuilderView *pView, UIContext &ui);
63  void OnMouseMove(BuilderView *pView, UIContext &ui);
64 
65  void DrawLayerBitmap(wxDC *pDC, vtScaledView *pView);
66  void DrawLayerOutline(wxDC *pDC, vtScaledView *pView);
67  bool AppendDataFrom(vtLayer *pL);
68  void ReRender();
69  void ReImage();
70  bool IsGrid() { return m_pGrid != NULL; }
71  void SetPreferGZip(bool val) { m_bPreferGZip = val; }
72 
73  void SetupDefaults();
74 
75  // heightfield operations
76  vtHeightField *GetHeightField();
77  void Offset(const DPoint2 &p);
78  float GetElevation(const DPoint2 &p);
79  bool GetHeightExtents(float &fMinHeight, float &fMaxHeight) const;
80  bool ImportFromFile(const wxString &strFileName, bool progress_callback(int) = NULL);
81  bool CreateFromPoints(vtFeatureSet *set, int iXSize, int iYSize,
82  float fDistanceRatio);
83 
84  // grid operations
85  void SetGrid(vtElevationGrid *grid);
86  vtElevationGrid *GetGrid() { return m_pGrid; }
87  int RemoveElevRange(float zmin, float zmax, const DRECT *area = NULL);
88  int SetUnknown(float fValue, const DRECT *area = NULL);
89  void DetermineMeterSpacing();
90  bool WriteGridOfElevTilePyramids(TilingOptions &opts, BuilderView *pView);
91  bool ImportFromDB(const char *szFileName, bool progress_callback(int));
92 
93  // TIN operations
94  void SetTin(vtTin2d *pTin);
95  vtTin2d *GetTin() { return m_pTin; }
96  void MergeSharedVerts(bool bSilent = false);
97  void SetupTinTriangleBins(int target_triangles_per_bin);
98 
99  // drawing
100  void SetupBitmap(wxDC *pDC);
101  void RenderBitmap();
102  static void SetupDefaultColors(ColorMap &cmap);
103 
104  static ElevDrawOptions m_draw;
105  static bool m_bDefaultGZip;
106 
107  // only this many elevation files may be loaded, the rest are paged out on an LRU basis
108  static int m_iElevMemLimit;
109 
110  bool NeedsDraw();
111 
112 protected:
113  // We can store either a grid or a TIN, so at most one of these two
114  // pointers will be set:
115  vtElevationGrid *m_pGrid;
116  vtTin2d *m_pTin;
117 
118  bool m_bNeedsDraw;
119  bool m_bBitmapRendered;
120  bool m_bHasMask;
121  float m_fSpacing;
122  bool m_bPreferGZip; // user wants their elevation treated as a .gz file
123 
124  int m_iImageWidth, m_iImageHeight;
125 
126  vtBitmap *m_pBitmap;
127  wxMask *m_pMask;
128 };
129 
130 // Helpers
131 FPoint3 LightDirection(float angle, float direction);
132 bool MatchTilingToResolution(const DRECT &original_area, const DPoint2 &resolution,
133  int &iTileSize, bool bGrow, bool bShrink, DRECT &new_area,
134  IPoint2 &tiling);
135 bool ElevCacheOpen(vtElevLayer *pLayer, const char *fname, enum vtElevError *err);
136 bool ElevCacheLoadData(vtElevLayer *elev);
137 void ElevCacheRemove(vtElevLayer *elev);
138 
139 #endif // ELEVLAYER_H
140