TerraLib 4.1
E:/Projetos_Primeiro_Semestre_2012/TerraView/terralib/src/terralib/kernel/TeDecoderSmartMem.h
Go to the documentation of this file.
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_DECODERSMARTMEM_H
00027 #define  __TERRALIB_INTERNAL_DECODERSMARTMEM_H
00028 
00029 #include "TeDecoder.h"
00030 #include "TeRasterMemManager.h"
00031 #include "TeAgnostic.h"
00032 
00040 class TL_DLL TeDecoderSmartMem : public TeDecoder
00041 {
00042 
00043 public:
00044 
00046   TeDecoderSmartMem ();
00047 
00049   TeDecoderSmartMem ( const TeRasterParams& par );
00050 
00052   virtual ~TeDecoderSmartMem ();
00053 
00055 
00061   inline bool setElement (int col,int lin, double val, int band=0)
00062   {
00063     TEAGN_DEBUG_CONDITION( ( setelement_ptrs_vec_ != 0 ),
00064       "invalid setElement function pointers vector" )
00065     TEAGN_DEBUG_CONDITION( ( col < params_.ncols_ ),
00066       "Invalid number of columns" )
00067     TEAGN_DEBUG_CONDITION( ( lin < params_.nlines_ ),
00068       "Invalid number of lines" )
00069     TEAGN_DEBUG_CONDITION( ( band < params_.nBands() ),
00070       "Invalid band" )
00071     TEAGN_DEBUG_CONDITION( 
00072       ( params_.status_ != TeRasterParams::TeNotReady),
00073       "Raster not Ready" );      
00074     
00075     ( this->*( setelement_ptrs_vec_[ band ] ) )( col, lin, val, band );
00076   
00077     return true;  
00078   };
00079   
00081 
00087   inline bool getElement (int col,int lin, double &val,int band=0)
00088   {
00089     TEAGN_DEBUG_CONDITION( ( getelement_ptrs_vec_ != 0 ),
00090       "invalid getElement function pointers vector" )
00091     TEAGN_DEBUG_CONDITION( ( col < params_.ncols_ ),
00092       "Invalid number of columns" )
00093     TEAGN_DEBUG_CONDITION( ( lin < params_.nlines_ ),
00094       "Invalid number of lines" )
00095     TEAGN_DEBUG_CONDITION( ( band < params_.nBands() ),
00096       "Invalid band" )    
00097     TEAGN_DEBUG_CONDITION( 
00098       ( params_.status_ != TeRasterParams::TeNotReady),
00099       "Raster not Ready" );      
00100     
00101     ( this->*( getelement_ptrs_vec_[ band ] ) )( col, lin, val, band );
00102     
00103     return true;  
00104   };
00105   
00115   template< typename ValueType > 
00116   inline void setValue( const int& col, const int& lin, 
00117     const ValueType& val, const int& band )
00118   {
00119     TEAGN_DEBUG_CONDITION( ( getelement_ptrs_vec_ != 0 ),
00120       "invalid getElement function pointers vector" )
00121     TEAGN_DEBUG_CONDITION( ( col < params_.ncols_ ),
00122       "Invalid number of columns" )
00123     TEAGN_DEBUG_CONDITION( ( lin < params_.nlines_ ),
00124       "Invalid number of lines" )
00125     TEAGN_DEBUG_CONDITION( ( band < params_.nBands() ),
00126       "Invalid band" )    
00127     TEAGN_DEBUG_CONDITION( 
00128       ( params_.status_ != TeRasterParams::TeNotReady),
00129       "Raster not Ready" );  
00130         
00131     *( ( (ValueType*)man_manager_.getTilePointer( band, lin ) ) + col ) = val;  
00132   };  
00133   
00143   template< typename ValueType >    
00144   inline void getValue( const int& col, const int& lin, 
00145     ValueType& val, const int& band ) const
00146   {
00147     TEAGN_DEBUG_CONDITION( ( getelement_ptrs_vec_ != 0 ),
00148       "invalid getElement function pointers vector" )
00149     TEAGN_DEBUG_CONDITION( ( col < params_.ncols_ ),
00150       "Invalid number of columns" )
00151     TEAGN_DEBUG_CONDITION( ( lin < params_.nlines_ ),
00152       "Invalid number of lines" )
00153     TEAGN_DEBUG_CONDITION( ( band < params_.nBands() ),
00154       "Invalid band" )    
00155     TEAGN_DEBUG_CONDITION( 
00156       ( params_.status_ != TeRasterParams::TeNotReady),
00157       "Raster not Ready" );  
00158         
00159     val = ( *( ( (ValueType*)man_manager_.getTilePointer( band, 
00160       lin ) ) + col ) );
00161   };  
00162 
00172   inline void* getScanLine( const int& lin, const int& band )
00173   {
00174     TEAGN_DEBUG_CONDITION( ( lin < params_.nlines_ ),
00175       "Invalid number of lines" )
00176     TEAGN_DEBUG_CONDITION( ( band < params_.nBands() ),
00177       "Invalid band" )    
00178     TEAGN_DEBUG_CONDITION( 
00179       ( params_.status_ != TeRasterParams::TeNotReady),
00180       "Raster not Ready" );  
00181         
00182     return man_manager_.getTilePointer( band, lin );
00183   };    
00184 
00186   virtual void  init  ();
00187   
00189   virtual bool  clear  ();
00190 
00191 protected:
00192 
00201   typedef void (TeDecoderSmartMem::*GetEleFunctPtrT)( const int& col,
00202     const int& lin, double& val, const int& band );
00203 
00212   typedef void (TeDecoderSmartMem::*SetEleFunctPtrT)( const int& col, 
00213     const int& lin, const double& val, const int& band );
00214   
00218   mutable TeRasterMemManager man_manager_;
00219 
00224   GetEleFunctPtrT* getelement_ptrs_vec_;
00225 
00230   SetEleFunctPtrT* setelement_ptrs_vec_;
00231   
00235   void initVars();
00236   
00241   void updateFuncPtrVectors();  
00242   
00246   void dummyFill();    
00247 
00256   inline void setElement_TeBIT( const int& col, const int& lin, 
00257     const double& val, const int& band )
00258   {
00259     *( ( (unsigned char*)man_manager_.getTilePointer( band, lin ) ) + col ) = 
00260       (unsigned char)val;  
00261   };
00262   
00271   inline void setElement_TeUNSIGNEDCHAR( const int& col, const int& lin, 
00272     const double& val, const int& band )
00273   {
00274     *( ( (unsigned char*)man_manager_.getTilePointer( band, lin ) ) + col ) = 
00275       (unsigned char)val;  
00276   };  
00277   
00286   inline void setElement_TeCHAR( const int& col, const int& lin, 
00287     const double& val, const int& band )
00288   {
00289     *( ( (char*)man_manager_.getTilePointer( band, lin ) ) + col ) = 
00290       (char)val;  
00291   };      
00292 
00301   inline void setElement_TeUNSIGNEDSHORT( const int& col, const int& lin, 
00302     const double& val, const int& band )
00303   {
00304     *( ( (unsigned short*)man_manager_.getTilePointer( band, lin ) ) + col ) = 
00305       (unsigned short)val;  
00306   };
00307 
00316   inline void setElement_TeSHORT( const int& col, const int& lin, 
00317     const double& val, const int& band )
00318   {
00319     *( ( (short*)man_manager_.getTilePointer( band, lin ) ) + col ) = 
00320       (short)val;
00321   };
00322 
00331   inline void setElement_TeINTEGER( const int& col, const int& lin, 
00332     const double& val, const int& band )
00333   {
00334     *( ( (int*)man_manager_.getTilePointer( band, lin ) ) + col ) = 
00335       (int)val;
00336   }
00337 
00346   inline void setElement_TeUNSIGNEDLONG( const int& col, const int& lin, 
00347     const double& val, const int& band )
00348   {
00349     *( ( (unsigned long*)man_manager_.getTilePointer( band, lin ) ) + col ) = 
00350       (unsigned long)val;  
00351   };
00352 
00361   inline void setElement_TeLONG( const int& col, const int& lin, 
00362     const double& val, const int& band )
00363   {
00364     *( ( (long*)man_manager_.getTilePointer( band, lin ) ) + col ) = 
00365       (long)val;  
00366   };
00367 
00376   inline void setElement_TeFLOAT( const int& col, const int& lin, 
00377     const double& val, const int& band )
00378   {
00379     *( ( (float*)man_manager_.getTilePointer( band, lin ) ) + col ) = 
00380       (float)val;    
00381   };
00382 
00391   inline void setElement_TeDOUBLE( const int& col, const int& lin, 
00392     const double& val, const int& band )
00393   {
00394     *( ( (double*)man_manager_.getTilePointer( band, lin ) ) + col ) = val;    
00395   };
00396   
00405   inline void getElement_TeBIT( const int& col, const int& lin, 
00406     double& val, const int& band )
00407   {
00408     val = (double)( *( ( (unsigned char*)man_manager_.getTilePointer( band, 
00409       lin ) ) + col ) );
00410   };
00411     
00420   inline void getElement_TeUNSIGNEDCHAR( const int& col, const int& lin, 
00421     double& val, const int& band )
00422   {
00423     val = (double)( *( ( (unsigned char*)man_manager_.getTilePointer( band, 
00424       lin ) ) + col ) );
00425   };
00426   
00435   inline void getElement_TeCHAR( const int& col, const int& lin, 
00436     double& val, const int& band )
00437   {
00438     val = (double)( *( ( (char*)man_manager_.getTilePointer( band, 
00439       lin ) ) + col ) );
00440   };
00441 
00450   inline void getElement_TeUNSIGNEDSHORT( const int& col, const int& lin, 
00451     double& val, const int& band )
00452   {
00453     val = (double)( *( ( (unsigned short*)man_manager_.getTilePointer( band, 
00454       lin ) ) + col ) );
00455   };
00456 
00465   inline void getElement_TeSHORT( const int& col, const int& lin, 
00466     double& val, const int& band )
00467   {
00468     val = (double)( *( ( (short*)man_manager_.getTilePointer( band, 
00469       lin ) ) + col ) );
00470   };
00471 
00480   inline void getElement_TeINTEGER( const int& col, const int& lin, 
00481     double& val, const int& band )
00482   {
00483     val = (double)( *( ( (int*)man_manager_.getTilePointer( band, 
00484       lin ) ) + col ) );
00485   };
00486 
00495   inline void getElement_TeUNSIGNEDLONG( const int& col, const int& lin, 
00496     double& val, const int& band )
00497   {
00498     val = (double)( *( ( (unsigned long*)man_manager_.getTilePointer( band, 
00499       lin ) ) + col ) );
00500   };
00501 
00510   inline void getElement_TeLONG( const int& col, const int& lin, 
00511     double& val, const int& band )
00512   {
00513     val = (double)( *( ( (long*)man_manager_.getTilePointer( band, 
00514       lin ) ) + col ) );
00515   };
00516 
00525   inline void getElement_TeFLOAT( const int& col, const int& lin, 
00526     double& val, const int& band )
00527   {
00528     val = (double)( *( ( (float*)man_manager_.getTilePointer( band, 
00529       lin ) ) + col ) );
00530   };
00531 
00540   inline void getElement_TeDOUBLE( const int& col, const int& lin, 
00541     double& val, const int& band )
00542   {
00543     val = ( *( ( (double*)man_manager_.getTilePointer( band, 
00544       lin ) ) + col ) );
00545   };
00546   
00547 };
00548 
00550 class TL_DLL TeDecoderSmartMemFactory : public TeDecoderFactory
00551 {
00552 public:
00553 
00555   TeDecoderSmartMemFactory(const string& name) : TeDecoderFactory(name) {}
00556 
00558   virtual TeDecoder* build (const TeRasterParams& arg)
00559   {  return new TeDecoderSmartMem(arg); }
00560 };
00561 #endif
00562 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines