openModeller  Version 1.5.0
Header.cpp
Go to the documentation of this file.
1 
30 
31 #include <openmodeller/Log.hh>
32 
33 using std::string;
34 using std::pair;
35 using std::make_pair;
36 
37 /****************************************************************/
38 /***************************** Header ***************************/
39 
40 /******************/
41 /*** construtor ***/
42 
43 Header::Header( int xd, int yd, Coord xm, Coord ym,
44  Coord xM, Coord yM, Scalar nv, int nb, int gd ) :
45  xdim( xd ),
46  ydim( yd ),
47  xmin( xm ),
48  ymin( ym ),
49  xmax( xM ),
50  ymax( yM ),
51  xcel( 0 ),
52  ycel( 0 ),
53  noval( nv ),
54  nband( nb ),
55  grid( gd ),
56  categ( 0 ),
57  minmax( 0 ),
58  vmin( 0.0 ),
59  vmax( 0.0 ),
60  proj()
61 {
62  calculateCell();
63 
64  // Given the information provided in this constructor,
65  // We pretty much have to assume this is the geotransform.
66 
67  gt[0] = xmin;
68  gt[1] = xcel;
69  gt[2] = 0.0;
70  gt[3] = ymax;
71  gt[4] = 0.0;
72  gt[5] = -1.0*ycel;
73 }
74 
76 {
77  operator=( h );
78 }
79 
80 
81 /*****************/
82 /*** destrutor ***/
83 
85 {
86 }
87 
88 
89 /******************/
90 /*** operator = ***/
91 Header &
93 {
94  xdim = h.xdim;
95  ydim = h.ydim;
96 
97  xmin = h.xmin;
98  ymin = h.ymin;
99  xmax = h.xmax;
100  ymax = h.ymax;
101 
102  xcel = h.xcel;
103  ycel = h.ycel;
104 
105  gt[0] = h.gt[0];
106  gt[1] = h.gt[1];
107  gt[2] = h.gt[2];
108  gt[3] = h.gt[3];
109  gt[4] = h.gt[4];
110  gt[5] = h.gt[5];
111 
112  noval = h.noval;
113  nband = h.nband;
114  grid = h.grid;
115  categ = h.categ;
116 
117  minmax = h.minmax;
118  vmin = h.vmin;
119  vmax = h.vmax;
120 
121  proj = h.proj;
122 
123  return *this;
124 }
125 
126 
127 /**********************/
128 /*** calculate Cell ***/
129 void
131 {
132  // todo: verify if it is true for "grid" and "pixel".
133 
134  xcel = (xmax - xmin) / xdim;
135  ycel = (ymax - ymin) / ydim;
136 }
137 
138 
139 /****************/
140 /*** set Proj ***/
141 void
142 Header::setProj( const string& projection )
143 {
144  proj = projection;
145 }
146 
147 // Does not support rotations.
148 pair<Coord,Coord>
149 Header::convertXY2LonLat( int x, int y ) const
150 {
151  // Get the coordinates associated with the center of the cell
152  Coord lon = gt[1]*(x+0.5) + gt[0];
153  Coord lat = gt[5]*(y+0.5) + gt[3];
154 
155  return make_pair(lon,lat);
156 }
157 
158 // Does not support rotations.
159 pair<int,int>
161 {
162  int x = static_cast<int>((lon - gt[0]) / gt[1]);
163  int y = static_cast<int>((lat - gt[3]) / gt[5]);
164 
165  return make_pair(x,y);
166 }
167 
168 /*************/
169 /*** print ***/
170 void
171 Header::printHeader( const std::string& msg ) const
172 {
173  Log::instance()->info( "%s\n", msg.c_str() );
174 
175  Log::instance()->info( "xdim: %d\n", xdim );
176  Log::instance()->info( "ydim: %d\n", ydim );
177  Log::instance()->info( "xmin: %.4f\n", xmin );
178  Log::instance()->info( "ymin: %.4f\n", ymin );
179  Log::instance()->info( "xmax: %.4f\n", xmax );
180  Log::instance()->info( "ymax: %.4f\n", ymax );
181  Log::instance()->info( "xcel: %.4f\n", xcel );
182  Log::instance()->info( "ycel: %.4f\n", ycel );
183  Log::instance()->info( "noval: %.4f\n", noval );
184  Log::instance()->info( "band: %d\n", nband );
185  Log::instance()->info( "grid: %d\n", grid );
186  Log::instance()->info( "var : %s\n", categ ? "categorical" : "continuous" );
187 
188  if ( minmax )
189  {
190  Log::instance()->info( "min: %f\n", vmin );
191  Log::instance()->info( "max: %f\n", vmax );
192  }
193  else
194  Log::instance()->info( "No minimum or maximum available.\n" );
195 
196  for( int i=0;i<6; i++ ) {
197  Log::instance()->info( "GT[%d] = %f\n",i,gt[i] );
198  }
199 
200  Log::instance()->info( "proj: %s\n", proj.c_str() );
201 }
Coord xcel
Definition: Header.hh:78
int categ
Definition: Header.hh:93
Coord ycel
Definition: Header.hh:79
Scalar vmin
Definition: Header.hh:101
int xdim
Definition: Header.hh:72
Scalar vmax
Definition: Header.hh:102
double Scalar
Type of map values.
Definition: om_defs.hh:39
void calculateCell()
Definition: Header.cpp:130
int ydim
Definition: Header.hh:73
~Header()
Definition: Header.cpp:84
int nband
Definition: Header.hh:83
Coord xmin
Definition: Header.hh:74
Coord xmax
Definition: Header.hh:76
static Log * instance()
Returns the instance pointer, creating the object on the first call.
Definition: Log.cpp:45
void printHeader(const std::string &msg="") const
Definition: Header.cpp:171
std::pair< int, int > convertLonLat2XY(Coord lon, Coord lat) const
Definition: Header.cpp:160
Scalar noval
Definition: Header.hh:82
Header()
Definition: Header.hh:49
Definition: Header.hh:45
std::pair< Coord, Coord > convertXY2LonLat(int x, int y) const
Definition: Header.cpp:149
std::string proj
Definition: Header.hh:104
Coord gt[6]
Definition: Header.hh:80
Coord ymin
Definition: Header.hh:75
int grid
Definition: Header.hh:86
Coord ymax
Definition: Header.hh:77
int minmax
Definition: Header.hh:99
void info(const char *format,...)
'Info' level.
Definition: Log.cpp:256
Header & operator=(const Header &h)
Definition: Header.cpp:92
double Coord
Type of map coordinates.
Definition: om_defs.hh:38
void setProj(const std::string &projection)
Definition: Header.cpp:142