Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
MiniDatabuf.h
1 //
2 // MiniDatabuf.h
3 //
4 // Copyright (c) 2006-2008 Virtual Terrain Project and Stefan Roettger
5 // Free for all uses, see license.txt for details.
6 //
7 
8 #ifndef MINIDATABUF_H
9 #define MINIDATABUF_H
10 
11 #include "vtdata/HeightField.h" // for INVALID_ELEVATION
12 
13 #if !USE_LIBMINI_DATABUF
14 
15 /* This is a subset of a libMini class which represents a single 1D, 2D, 3D
16  or 4D data buffer, with associated metadata such as dimensions and type. */
17 
19 {
20 public:
22  MiniDatabuf();
23  ~MiniDatabuf();
24 
25  // mandatory metadata
26  unsigned int xsize; // data size along the x-axis of 1D data
27  unsigned int ysize; // optional data size along the y-axis of 2D data
28  unsigned int zsize; // optional data size along the z-axis of 3D data
29  unsigned int tsteps; // optional number of frames for time-dependent data
30  unsigned int type; // 0 = unsigned byte, 1 = signed short, 2 = float, 3 = RGB, 4 = RGBA, 5 = compressed RGB, 6 = compressed RGBA
31 
32  // optional metadata
33  float swx,swy; // SW corner of data brick
34  float nwx,nwy; // NW corner of data brick
35  float nex,ney; // NE corner of data brick
36  float sex,sey; // SE corner of data brick
37  float h0,dh; // base elevation and height of data brick
38  float t0,dt; // time frame start and exposure time
39 
40  // optional scaling
41  float scaling; // scale factor of data values, default=1.0f
42  float bias; // bias of data values, default=0.0f
43 
45  float minvalue;
46  float maxvalue;
47 
49  float LLWGS84_swx,LLWGS84_swy; // SW corner of data brick
50  float LLWGS84_nwx,LLWGS84_nwy; // NW corner of data brick
51  float LLWGS84_nex,LLWGS84_ney; // NE corner of data brick
52  float LLWGS84_sex,LLWGS84_sey; // SE corner of data brick
53 
54  // data chunk
55  void *data; // pointer to raw data, null pointer indicates missing data
56  unsigned int bytes; // number of raw data bytes
57 
58  void set_extents(float left, float right, float bottom, float top);
59  void set_LLWGS84corners(float sw_corner_x,float sw_corner_y,
60  float se_corner_x,float se_corner_y,
61  float nw_corner_x,float nw_corner_y,
62  float ne_corner_x,float ne_corner_y);
63 
64  // A useful method to set the extents (in local CRS) and the corners
65  // (in Geo WGS84) at the same time.
66  bool SetBounds(const vtProjection &proj, const DRECT &extents);
67 
68  // allocate a new memory chunk
69  void alloc(unsigned int xs,unsigned int ys,unsigned int zs,unsigned int ts=1,unsigned int ty=0);
70 
71  // reset buffer
72  void reset();
73 
74  // release buffer
75  void release();
76 
77  // native input/output
78  void savedata(const char *filename); // data is saved in MSB format
79 
80  // JPEG output
81  bool savedataJPEG(const char *filename, int quality);
82 
83 protected:
84  static int MAGIC;
85 
86 private:
87  static unsigned short int INTEL_CHECK;
88  void swapbytes();
89 };
90 
91 #endif // !USE_LIBMINI_DATABUF
92 
93 // Helper to write headers
94 class DRECT;
95 class vtProjection;
96 class LODMap // A simple 2D array of min/max LOD values (log2)
97 {
98 public:
99  LODMap()
100  {
101  m_min = m_max = NULL;
102  }
103  LODMap(int cols, int rows)
104  {
105  alloc(cols, rows);
106  }
107  ~LODMap()
108  {
109  delete [] m_min;
110  delete [] m_max;
111  }
112  bool exists() { return m_min != NULL; }
113  void alloc(int cols, int rows)
114  {
115  m_cols = cols;
116  m_rows = rows;
117  m_min = new int [cols*rows];
118  m_max = new int [cols*rows];
119  for (int i = 0; i < cols*rows; i++)
120  m_min[i] = m_max[i] = 0;
121  }
122  void set(int c, int r, int minlevel, int maxlevel)
123  {
124  m_min[c*m_rows+r] = minlevel;
125  m_max[c*m_rows+r] = maxlevel;
126  }
127  void get(int c, int r, int &minlevel, int &maxlevel)
128  {
129  minlevel = m_min[c*m_rows+r];
130  maxlevel = m_max[c*m_rows+r];
131  }
132  int m_cols, m_rows;
133  int *m_min, *m_max;
134 };
135 
136 bool WriteTilesetHeader(const char *filename, int cols, int rows, int lod0size,
137  const DRECT &area, const vtProjection &proj,
138  float minheight=INVALID_ELEVATION, float maxheight=INVALID_ELEVATION,
139  LODMap *lodmap = NULL, bool bJPEG = false);
140 
141 #endif