openModeller
Version 1.4.0
|
00001 00029 #include <openmodeller/env_io/Header.hh> 00030 00031 #include <openmodeller/Log.hh> 00032 00033 using std::string; 00034 using std::pair; 00035 using std::make_pair; 00036 00037 /****************************************************************/ 00038 /***************************** Header ***************************/ 00039 00040 /******************/ 00041 /*** construtor ***/ 00042 00043 Header::Header( int xd, int yd, Coord xm, Coord ym, 00044 Coord xM, Coord yM, Scalar nv, int nb, int gd ) : 00045 xdim( xd ), 00046 ydim( yd ), 00047 xmin( xm ), 00048 ymin( ym ), 00049 xmax( xM ), 00050 ymax( yM ), 00051 xcel( 0 ), 00052 ycel( 0 ), 00053 noval( nv ), 00054 nband( nb ), 00055 grid( gd ), 00056 categ( 0 ), 00057 minmax( 0 ), 00058 vmin( 0.0 ), 00059 vmax( 0.0 ), 00060 proj() 00061 { 00062 calculateCell(); 00063 00064 // Given the information provided in this constructor, 00065 // We pretty much have to assume this is the geotransform. 00066 00067 gt[0] = xmin; 00068 gt[1] = xcel; 00069 gt[2] = 0.0; 00070 gt[3] = ymax; 00071 gt[4] = 0.0; 00072 gt[5] = -1.0*ycel; 00073 } 00074 00075 Header::Header( const Header &h ) 00076 { 00077 operator=( h ); 00078 } 00079 00080 00081 /*****************/ 00082 /*** destrutor ***/ 00083 00084 Header::~Header() 00085 { 00086 } 00087 00088 00089 /******************/ 00090 /*** operator = ***/ 00091 Header & 00092 Header::operator=( const Header &h ) 00093 { 00094 xdim = h.xdim; 00095 ydim = h.ydim; 00096 00097 xmin = h.xmin; 00098 ymin = h.ymin; 00099 xmax = h.xmax; 00100 ymax = h.ymax; 00101 00102 xcel = h.xcel; 00103 ycel = h.ycel; 00104 00105 gt[0] = h.gt[0]; 00106 gt[1] = h.gt[1]; 00107 gt[2] = h.gt[2]; 00108 gt[3] = h.gt[3]; 00109 gt[4] = h.gt[4]; 00110 gt[5] = h.gt[5]; 00111 00112 noval = h.noval; 00113 nband = h.nband; 00114 grid = h.grid; 00115 categ = h.categ; 00116 00117 minmax = h.minmax; 00118 vmin = h.vmin; 00119 vmax = h.vmax; 00120 00121 proj = h.proj; 00122 00123 return *this; 00124 } 00125 00126 00127 /**********************/ 00128 /*** calculate Cell ***/ 00129 void 00130 Header::calculateCell() 00131 { 00132 // todo: verify if it is true for "grid" and "pixel". 00133 00134 xcel = (xmax - xmin) / xdim; 00135 ycel = (ymax - ymin) / ydim; 00136 } 00137 00138 00139 /****************/ 00140 /*** set Proj ***/ 00141 void 00142 Header::setProj( const string& projection ) 00143 { 00144 proj = projection; 00145 } 00146 00147 // Does not support rotations. 00148 pair<Coord,Coord> 00149 Header::convertXY2LonLat( int x, int y ) const 00150 { 00151 // Get the coordinates associated with the center of the cell 00152 Coord lon = gt[1]*(x+0.5) + gt[0]; 00153 Coord lat = gt[5]*(y+0.5) + gt[3]; 00154 00155 return make_pair(lon,lat); 00156 } 00157 00158 // Does not support rotations. 00159 pair<int,int> 00160 Header::convertLonLat2XY( Coord lon, Coord lat ) const 00161 { 00162 int x = static_cast<int>((lon - gt[0]) / gt[1]); 00163 int y = static_cast<int>((lat - gt[3]) / gt[5]); 00164 00165 return make_pair(x,y); 00166 } 00167 00168 /*************/ 00169 /*** print ***/ 00170 void 00171 Header::printHeader( const std::string& msg ) const 00172 { 00173 Log::instance()->info( "%s\n", msg.c_str() ); 00174 00175 Log::instance()->info( "xdim: %d\n", xdim ); 00176 Log::instance()->info( "ydim: %d\n", ydim ); 00177 Log::instance()->info( "xmin: %.4f\n", xmin ); 00178 Log::instance()->info( "ymin: %.4f\n", ymin ); 00179 Log::instance()->info( "xmax: %.4f\n", xmax ); 00180 Log::instance()->info( "ymax: %.4f\n", ymax ); 00181 Log::instance()->info( "xcel: %.4f\n", xcel ); 00182 Log::instance()->info( "ycel: %.4f\n", ycel ); 00183 Log::instance()->info( "noval: %.4f\n", noval ); 00184 Log::instance()->info( "band: %d\n", nband ); 00185 Log::instance()->info( "grid: %d\n", grid ); 00186 Log::instance()->info( "var : %s\n", categ ? "categorical" : "continuous" ); 00187 00188 if ( minmax ) 00189 { 00190 Log::instance()->info( "min: %f\n", vmin ); 00191 Log::instance()->info( "max: %f\n", vmax ); 00192 } 00193 else 00194 Log::instance()->info( "No minimum or maximum available.\n" ); 00195 00196 for( int i=0;i<6; i++ ) { 00197 Log::instance()->info( "GT[%d] = %f\n",i,gt[i] ); 00198 } 00199 00200 Log::instance()->info( "proj: %s\n", proj.c_str() ); 00201 }