rasdaman complete source
int16.hh
Go to the documentation of this file.
1 /*
2 * This file is part of rasdaman community.
3 *
4 * Rasdaman community is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * Rasdaman community is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
18 rasdaman GmbH.
19 *
20 * For more information please see <http://www.rasdaman.org>
21 * or contact Peter Baumann via <baumann@rasdaman.com>.
22 /
34 #ifndef _R_CONV_int16_HH_
35 #define _R_CONV_int16_HH_
36 
37 #include <sstream>
38 #include <vector>
39 #include <string>
40 #include <cstdio>
41 using std::vector;
42 using std::ofstream;
43 using std::string;
44 
45 #include "conversion/convertor.hh"
46 #include "raslib/odmgtypes.hh"
47 
48 //@ManMemo: Module {\bf conversion}
49 
50 /*@Doc:
51  int16 convertor class.
52 
53  Supported parameters are
54 
55  \begin{tabular}{lcl}
56  {\tt flipx} && int && flip image flag on x axis, default 0\\
57  {\tt flipy} && int && flip image flag on y axis, default 1\\
58  {\tt startx} && double && start value on x axis \\
59  {\tt endx} && double && end value on x axis \\
60  {\tt sizex} && int && number of pixels in horizontal direction (int >0)
61  {\tt sizey} && int && number of pixels in vertical direction (int >0)
62  {\tt resx} && double && resolution on x axis \\
63  {\tt starty} && double && start value on y axis \\
64  {\tt endy} && double && end value on y axis \\
65  {\tt resy} && double && resolution on y axis \\
66  {\tt hstep} && double && resolution on h axis \\
67  \end{tabular}
68 
69  The "flipx" parameter is a flag for mirroring the image on x axis.
70  The "flipy" parameter is a flag for mirroring the image on y axis.
71  [startx:endx, starty:endy] represents the geographical bounding box
72  of the whole image. The corresponding pixel bounding box is calculated
73  as follows:
74  if flipy is disabled:
75  [(minx-startx)/resx:(maxx-startx)/resx, (miny-starty)/resy:(maxy-starty)/resy]
76  else
77  [(minx-startx)/resx:(maxx-startx)/resx, (endy-maxy)/resy:(endy-miny)/resy]
78 
79  if flipx is disabled:
80  [(minx-startx)/resx:(maxx-startx)/resx, (miny-starty)/resy:(maxy-starty)/resy]
81  else
82  [(endx-maxx)/resx:(endx-minx)/resx, (miny-starty)/resy:(maxy-starty)/resy]
83 
84  The pairs (startx, endx, resx), (starty, endy, resy) apply to the whole MDD object in the database
85  whereas the pairs (minx,maxx, resx), (miny, maxy, resy) describe the part of image under consideration.
86  They are used to compute the update part's position in RasDaMan coordinates.
87  Value hstep is vertical resolution (multiplied into the value read during conversion into internal format).
88 */
89 
90 
91 Format specification:
92 int16
93 
94 input parameters:
95 geox geo reference x of upper left point (float >0)
96 geoy geo reference y of upper left point (float >0)
97 resx horizontal resolution (pixel distance) in meters (float >0)
98 resy vertical resolution (pixel distance) in meters (float >0)
99 hstep factor by which pixel values have to be multiplied to obtain real height in meters (float >0)
100 
101 
102 An int16 file contains a sequence of sizex*sizey height values, advancing from west to east and from north to south. Each pixel consists of a 16 bit integer where the lower byte comes first in sequence (i.e., pixel value is byte[i]+byte[i+1]*256).
103 There is no file header, pixels start immediately at the beginning.
104 
105 Points are defined as follows for pixel position (i,j) in file (starting with (0/0):
106  geo position x = geox + i*resx
107  geo position y = geoy + j*resy
108  height = ( byte[ 2*i + 2*j*sizex] + byte[ 2*i + 2*j*sizex + 1] * 256 ) * hstep
109 
110  where / denotes integer division
111 
112  class r_Conv_int16 : public r_Convertor
113 {
114 public:
115  // constants to handle NULL
116  static const r_Double NULL_DB;
117  static const r_Double ZERO_DB;
118  static const r_Double ZERO_int16;
119 
120  //inner class for convertor parameters
121  class r_GeoBBox
122  {
123  public:
127  };
128 
129  r_Conv_int16(const char* source, const r_Minterval& lengthordomain, const r_Type* tp) throw(r_Error);
130 
131  r_Conv_int16(const char* source, const r_Minterval& lengthordomain, int tp) throw(r_Error);
132 
133  r_convDesc& convertFrom(const char* options = NULL) throw (r_Error);
134 
135  r_convDesc& convertTo(const char* options = NULL) throw (r_Error);
136 
137  const char* get_name() const throw();
138 
139  r_Data_Format get_data_format() const throw();
140 
141  r_Convertor* clone() const throw(r_Error);
142 
144  static const r_Dimension srcIntervDim;
145 
147  static const r_Dimension destIntervDim;
148 
150  static bool decodeOptions( const char* options,
151  r_GeoBBox& collBBox) throw();
152 
154  static string encodeOptions(const r_GeoBBox& collBBox) throw();
155 
157  virtual ~r_Conv_int16( void );
158 
160  static void initGeoBBox( r_GeoBBox& cBBox );
161 
162 private:
163 
164 
166  void checkLimits() throw(r_Error);
167 
169  void readFromSrcStream() throw(r_Error);
170  void readToSrcStream() throw(r_Error);
171  void writeFromDestStream() throw(r_Error);
172  void writeToDestStream(ofstream& oFile) throw(r_Error);
173 
176 
178  static const r_ULong paramMin;
179  static const char* paramSep;
180  static const char* paramEq;
181  static const char* paramFlipX;
182  static const char* paramFlipY;
183  static const char* paramStartX;
184  static const char* paramEndX;
185  static const char* paramResX;
186  static const char* paramStartY;
187  static const char* paramEndY;
188  static const char* paramResY;
189 
190 
192  class int16Row
193  {
194  public:
195  r_Double x,y,h;
196  };
197 
198  typedef vector<int16Row> int16RowVec;
199 
200  int16Row min, max;
201  int16RowVec demRows;
202 
203 };
204 
205 #endif
206 
vector< int16Row > int16RowVec
Definition: int16.hh:198
r_Double endx
Definition: int16.hh:124
unsigned int r_ULong
Definition: odmgtypes.hh:114
int16Row max
Definition: int16.hh:200
Definition: error.hh:88
Definition: raslib/type.hh:56
r_Double endy
Definition: int16.hh:125
unsigned int r_Dimension
Definition: mddtypes.hh:118
int16RowVec demRows
Definition: int16.hh:201
r_Data_Format get_data_format() const
double r_Double
Definition: odmgtypes.hh:138
r_Convertor * clone() const
Definition: convertor.hh:111
r_convDesc & convertFrom(const char *options=NULL)
r_Double resx
Definition: int16.hh:124
r_GeoBBox collBBox
parameters
Definition: int16.hh:175
r_Double starty
Definition: int16.hh:125
r_Data_Format
Definition: mddtypes.hh:133
Format advancing from west to east and from north to south Each pixel consists of a bit integer where the lower byte comes first in sequence(i.e., pixel value is byte[i]+byte[i+1]*256).There is no file header
Definition: int16.hh:121
r_Conv_int16(const char *source, const r_Minterval &lengthordomain, const r_Type *tp)
r_convDesc & convertTo(const char *options=NULL)
r_Double startx
Definition: int16.hh:124
r_Double resy
Definition: int16.hh:125
int16Row min
Definition: int16.hh:200
r_ULong flipx
Definition: int16.hh:126
Definition: convertor.hh:56
Format specification
Definition: int16.hh:102
const char * get_name() const
Definition: minterval.hh:249
r_ULong flipy
Definition: int16.hh:126