![]() |
TerraLib 4.1
|
00001 /************************************************************************************ 00002 TerraLib - a library for developing GIS applications. 00003 Copyright � 2001-2007 INPE and Tecgraf/PUC-Rio. 00004 00005 This code is part of the TerraLib library. 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Lesser General Public 00008 License as published by the Free Software Foundation; either 00009 version 2.1 of the License, or (at your option) any later version. 00010 00011 You should have received a copy of the GNU Lesser General Public 00012 License along with this library. 00013 00014 The authors reassure the license terms regarding the warranties. 00015 They specifically disclaim any warranties, including, but not limited to, 00016 the implied warranties of merchantability and fitness for a particular purpose. 00017 The library provided hereunder is on an "as is" basis, and the authors have no 00018 obligation to provide maintenance, support, updates, enhancements, or modifications. 00019 In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct, 00020 indirect, special, incidental, or consequential damages arising out of the use 00021 of this library and its documentation. 00022 *************************************************************************************/ 00026 #ifndef __TERRALIB_INTERNAL_RASTER_H 00027 #define __TERRALIB_INTERNAL_RASTER_H 00028 00029 #include "TeDecoder.h" 00030 #include "TeDataTypes.h" 00031 #include "TeCoord2D.h" 00032 #include "TeAttribute.h" 00033 #include "TeGeometry.h" 00034 #include "TeGeometryAlgorithms.h" 00035 00036 class TeRasterTransform; 00037 00038 #include <map> 00039 00041 enum TeStrategicIterator 00042 { TeBoxPixelIn, 00043 TeBBoxPixelInters, 00044 TeBoxPixelOut, 00045 TeBBoxPixelNotInters 00046 }; 00047 00057 TL_DLL TeCoordPairVect applyStrategic(double& y, double ymin, double xmin, 00058 TeStrategicIterator st, TeRaster* raster, const TePolygon& poly); 00059 00061 /* 00062 \par A Raster Geometry is made of a matrix of ncolumns x nlines elements 00063 with nBands dimension. Each element, or pixel, of the raster its is 00064 indexed by a column, line and band and has a double value associated. 00065 \par Each Raster geometry has a decoder associated to it. Its decoder 00066 knows how to get return the value (as a double) of each pixel. 00067 \par All information about the data is stored in a TeRasterParams structure 00068 that is duplicated in its decoder. 00069 \sa TeDecoder TeRasterParams 00070 */ 00071 class TL_DLL TeRaster : public TeGeometry 00072 { 00073 TeRasterParams params_; 00074 TeDecoder *decoder_; 00075 00076 public: 00078 00085 TeRaster(const string& filename, const char& mode = 'r'); 00086 00088 00095 TeRaster(TeRasterParams& pars); 00096 00098 /* 00099 This method creates a raste data in memory, using only the most basic 00100 parameters: 00101 \par ncols number of columns 00102 \par nlines number of lines 00103 \par nbands number of bands 00104 \par elemType size of each element 00105 */ 00106 TeRaster(int ncols, int nlines, int nbands, TeDataType elemType); 00107 00109 TeRaster() : decoder_(0) {} 00110 00112 ~TeRaster (); 00113 00115 const TeRasterParams& params() const; 00116 00118 TeRasterParams& params(); 00119 00121 int nBands(); 00122 00124 00127 void updateParams(TeRasterParams& par); 00128 00130 TeGeomRep elemType(); 00131 00133 00136 void setDecoder(TeDecoder* dec); 00137 00139 /* 00140 \return true if raster is ready to be read or written and false otherwise 00141 */ 00142 bool status(); 00143 00145 TeDecoder* decoder(); 00146 00148 TeProjection* projection(); 00149 00151 00157 bool setElement (int col, int lin, double val, int band=0); 00158 00160 00166 bool getElement (int col, int lin, double& val, int band=0); 00167 00169 /* 00170 \param dstRaster destination raster 00171 \param transf pixel evaluator to be used 00172 \param bestRes flag to indicate that it should use the best resolution available 00173 */ 00174 bool fillRaster (TeRaster* dstRaster, TeRasterTransform* transf=0, bool bestRes = true); 00175 00177 00185 bool init(); 00186 00188 00191 bool init(TeRasterParams& pars); 00192 00194 void clear(); 00195 00197 TeCoord2D index2Coord(TeCoord2D pt); 00198 00200 TeCoord2D coord2Index(TeCoord2D pt); 00201 00202 //---------------- 00204 00208 class TL_DLL iterator 00209 { 00210 public: 00212 00220 iterator(int c0=0, int l0=0, int nc=0, int nl=0, int nb=0, TeRaster* pt=0) : 00221 linCurrent_(l0), 00222 colCurrent_(c0), 00223 nLines_(nl), 00224 nCols_(nc), 00225 nBands_(nb), 00226 raster_(pt) 00227 {} 00228 00230 virtual ~iterator() 00231 {} 00232 00234 virtual void moveForward(); 00235 00237 iterator& operator++(); 00238 00240 iterator operator++(int); 00241 00243 int currentLine(); 00244 00246 int currentColumn(); 00247 00249 int nBands(void); 00250 00252 00256 vector<double> operator*(); 00257 00259 double operator*(int band); 00260 00262 bool operator==(const iterator& rhs) const; 00263 00265 bool operator!=(const iterator& rhs) const; 00266 00267 protected: 00268 int linCurrent_, colCurrent_; 00269 int nLines_, nCols_; 00270 int nBands_; 00271 TeRaster* raster_; 00272 }; 00273 00274 // --------------------- End of class raster Iterator 00275 00276 //---------------- 00278 00282 class TL_DLL iteratorPoly : public iterator 00283 { 00284 public: 00286 00307 iteratorPoly(int colCurr, int linCurr, int nc, int nl, int nb, TeRaster* pt, const TePolygon& poly, 00308 TeStrategicIterator str, double linMin=0.0, double linMax=0.0, double colMin=0.0, 00309 double colMax=0.0, TeCoordPairVect seg=TeCoordPairVect(), 00310 int posSeg=0, int nlInPoly=0, int nColsInPoly=0, bool e=true, double minLinCM=0.0, int band = 0): 00311 iterator(colCurr,linCurr,nc,nl,nb,pt), 00312 linMin_(linMin), 00313 linMax_(linMax), 00314 colMin_(colMin), 00315 colMax_(colMax), 00316 segments_(seg), 00317 posSegments_(posSeg), 00318 poly_(poly), 00319 end_(e), 00320 strategy_(str), 00321 nLinesInPoly_(nlInPoly), 00322 nColsInPoly_(nColsInPoly), 00323 linMinCM_(minLinCM), 00324 band_(band) 00325 {} 00326 00328 iteratorPoly(TeRaster* raster = 0): 00329 iterator(0,0,0,0,0,raster), 00330 linMin_(0.0), 00331 linMax_(0.0), 00332 colMin_(0.0), 00333 colMax_(0.0), 00334 posSegments_(0), 00335 end_(true), 00336 nLinesInPoly_(0), 00337 nColsInPoly_(0), 00338 band_(0) 00339 {} 00340 00342 virtual ~iteratorPoly() {} 00343 00344 void moveForward(); 00345 00347 iteratorPoly& operator++(); 00348 00350 iteratorPoly operator++(int); 00351 00353 00359 double operator*(); 00360 00362 double operator*(int band); 00363 00365 00369 bool getProperty(TeProperty& prop); 00370 00372 bool end(); 00373 00375 int nLinesInPoly(); 00376 00378 int nColsInPoly(); 00379 00380 private: 00381 00383 void getNewSegment(int linCurr); 00384 00385 double linMin_, linMax_; 00386 double colMin_, colMax_; 00387 TeCoordPairVect segments_; 00388 int posSegments_; 00389 TePolygon poly_; 00390 bool end_; 00391 TeStrategicIterator strategy_; 00392 int nLinesInPoly_, nColsInPoly_; 00393 double linMinCM_; //minimal line in world coordinates 00394 int band_; // band restriction 00395 }; 00396 00398 iterator begin(); 00399 00401 00406 iteratorPoly begin(const TePolygon& poly, TeStrategicIterator st, int band=0); 00407 00409 iterator end() ; 00411 00416 iteratorPoly end(const TePolygon& poly, TeStrategicIterator st, int band=0); 00417 00419 bool selectBlocks(TeBox& bb, int resFac, TeRasterParams& parBlock); 00420 00422 int numberOfSelectedBlocks(); 00423 00425 bool fetchRasterBlock(TeDecoderMemory* memDec); 00426 00428 void clearBlockSelection(); 00429 00431 /* 00432 This method should be used only to set the values of images with 3 bands associated 00433 respectively to the three colour channes Red, Green and Blue 00434 \param col column of the image 00435 \param lin line of the image 00436 \param Rval the value associated to the band 0 (associated to the R colour Channel) 00437 \param Gval the value associated to the band 1 (associated to the G colour Channel) 00438 \param Bval the value associated to the band 2 (associated to the B colour Channel) 00439 \param transp an optional transparency degree, with a range of 0 (totally transparent) to 255 (totally opaque) 00440 \return true if if succeed and false otherwise 00441 */ 00442 bool setElement(int col, int lin, double Rval, double Gval, double Bval, unsigned int /*transp*/ = 255); 00443 00445 const string& errorMessage() const; 00446 00447 private : 00448 00450 TeRaster( const TeRaster& ) : TeGeometry() 00451 {} 00452 00454 const TeRaster& operator=( const TeRaster& ) { return *this; }; 00455 00456 }; 00457 00458 inline const TeRasterParams& TeRaster::params() const 00459 { return params_; } 00460 00461 inline TeRasterParams& TeRaster::params() 00462 { return params_; } 00463 00464 inline int TeRaster::nBands() 00465 { return params_.nBands(); } 00466 00467 inline TeGeomRep TeRaster::elemType() 00468 { return TeRASTER; } 00469 00470 inline bool TeRaster::status() 00471 { return params_.status_ != TeRasterParams::TeNotReady; } 00472 00473 inline TeDecoder* TeRaster::decoder() 00474 { return decoder_; } 00475 00476 inline TeProjection* TeRaster::projection() 00477 { return params_.projection(); } 00478 00479 inline TeCoord2D TeRaster::index2Coord(TeCoord2D pt) 00480 { return decoder_->index2Coord(pt); } 00481 00482 inline TeCoord2D TeRaster::coord2Index(TeCoord2D pt) 00483 { return decoder_->coord2Index(pt); } 00484 00485 00486 inline const string& TeRaster::errorMessage() const 00487 { return params_.errorMessage_; } 00488 00489 inline int TeRaster::iterator::currentLine() 00490 { return linCurrent_;} 00491 00492 inline int TeRaster::iterator::currentColumn() 00493 {return colCurrent_; } 00494 00495 inline int TeRaster::iterator::nBands(void) 00496 { return nBands_; } 00497 00498 inline bool TeRaster::iteratorPoly::end() 00499 { return end_; } 00500 00501 inline int TeRaster::iteratorPoly::nLinesInPoly() 00502 { return nLinesInPoly_;} 00503 00504 inline int TeRaster::iteratorPoly::nColsInPoly() 00505 { return nColsInPoly_;} 00506 00524 TL_DLL TeRaster* 00525 TeRasterClipping(TeRaster* whole, TePolygonSet& mask, TeProjection* geomProj, const string& clipName, double background, const string& decId=""); 00526 00528 00529 #endif 00530 00531