| TerraLib 4.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

E:/Projetos_Primeiro_Semestre_2012/TerraView/terralib/src/terralib/kernel/TeDecoderVirtualMemory.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_DECODERVIRTUALMEMORY_H
    00027 #define  __TERRALIB_INTERNAL_DECODERVIRTUALMEMORY_H
    00028
    00029 #include "TeDefines.h"
    00030 #include "TeDecoder.h"
    00031
    00032 #include <queue>
    00033 #include <vector>
    00034
    00035 using namespace std;
    00036
    00038 class TL_DLL TeMemoryPage
    00039 {
    00040 public:
    00041            void*   data_;                              //<! Pointer to the data in memory
    00042            bool       used_;                           //<! Flag that indicate if the page was modified in memory
    00043            unsigned long size_;  //<! Page number of elements
    00044
    00045            int ulLin_;                                            //<! Line index of the upper-left corner
    00046            int ulCol_;                                            //<! Column index of the upper-left corner
    00047            double   defValue_;              //<! Default value (fo initially fill the page)
    00048            TeDataType dataType_; //<! Pixel data type
    00049
    00051            TeMemoryPage(unsigned long size, double defValue, TeDataType dataType = TeDOUBLE);
    00052
    00054            ~TeMemoryPage();
    00055
    00057            TeMemoryPage(const TeMemoryPage& rhs);
    00058
    00060            TeMemoryPage& operator=(const TeMemoryPage& rhs);
    00061
    00063            /*
    00064                       \par col column identifier of the position
    00065                       \par lin line identifier of the position
    00066                       \par nCols number of columns per line of the block
    00067                       \returns the value of the position indicated by (col x lin)
    00068            */
    00069            double getVal(int col,int lin, int nCols);
    00070
    00072            /*
    00073                       \par col column identifier of the position
    00074                       \par lin line identifier of the position
    00075                       \par nCols number of columns per line of the block
    00076                       \par val the value to be put in the position
    00077            */
    00078            void setVal(int col,int lin,int nCols, double val);
    00079
    00081            void clear();
    00082
    00084            long pageSize();
    00085 };
    00086
    00087 class TL_DLL TeBlockIndex{
    00088 public:
    00089            TeBlockIndex()
    00090            {
    00091                       col_ = 0;
    00092                       lin_ = 0;
    00093                       band_ = -1;
    00094            }
    00095
    00096            int col_;
    00097            int lin_;
    00098            int band_;
    00099
    00100            int column()  const
    00101            {
    00102                       return col_;
    00103            }
    00104
    00105            int line() const
    00106            {
    00107                       return lin_;
    00108            }
    00109
    00110            int band() const
    00111            {
    00112                       return band_;
    00113            }
    00114
    00115            int operator==(const TeBlockIndex& idx2) const
    00116            {
    00117                       if(col_ != idx2.col_)
    00118                                  return 0;
    00119
    00120                       if(lin_ != idx2.lin_)
    00121                                  return 0;
    00122
    00123                       return (band_ == idx2.band_);
    00124            }
    00125 };
    00126
    00128 /*
    00129            It should be used as a parent class of decoder that access raster
    00130            blocks from a physical storage
    00131 */
    00132 class TL_DLL TeDecoderVirtualMemory: public TeDecoder
    00133 {
    00134 public:
    00135
    00137            TeDecoderVirtualMemory() {};
    00138
    00140            TeDecoderVirtualMemory( const TeRasterParams par);
    00141
    00143            virtual ~TeDecoderVirtualMemory();
    00144
    00146
    00152            bool getElement(int col,int lin, double &val,int band);
    00153
    00155
    00161            bool setElement(int col, int lin, double val,int band);
    00162
    00164            void init();
    00165
    00167            bool clear();
    00168
    00170            void setCacheSize(int size);
    00171
    00173            int getCacheSize();
    00174
    00176            void setCacheNTiles(int n);
    00177
    00179            int getCacheNTiles();
    00180
    00181 protected:
    00182            struct TeBlockIndexMapFunc
    00183            {
    00184                       bool operator()(const TeBlockIndex& idx1, const TeBlockIndex& idx2) const;
    00185            };
    00186
    00188
    00193            virtual bool putRasterBlock(const TeBlockIndex& index, void *buf, long bsize) = 0; /******/
    00194
    00196
    00200            virtual bool getRasterBlock(const TeBlockIndex& index, void *buf) = 0; /******/
    00201
    00203
    00209            virtual TeBlockIndex blockIndex(int col, int lin, int band);
    00210
    00212            virtual void blockIndexPos( const TeBlockIndex& index, int& ulCol, int& ulLin, int& band); /******/
    00213
    00215            TeMemoryPage* loadBlock(int col,int lin, int band);
    00216
    00217 private:
    00218
    00220            typedef map<TeBlockIndex, TeMemoryPage*, TeBlockIndexMapFunc> MapMemoryPage;
    00221
    00223            typedef MapMemoryPage::const_iterator MapMemoryPageIterator;
    00224
    00225            MapMemoryPage virtualMemory_;
    00226            queue<TeBlockIndex> pagesQueue_;
    00227            vector<TeBlockIndex> indexCache_;
    00228            vector<TeMemoryPage*> pageCache_;
    00229 };
    00230
    00231 inline bool TeDecoderVirtualMemory::TeBlockIndexMapFunc::operator()(const TeBlockIndex& idx1, const TeBlockIndex& idx2) const
    00232 {
    00233   if(idx1.band_ != idx2.band_)
    00234     return (idx1.band_ < idx2.band_);
    00235
    00236   if(idx1.lin_ != idx2.lin_)
    00237     return idx1.lin_ < idx2.lin_;
    00238
    00239   return (idx1.col_ < idx2.col_);
    00240 }
    00241 #endif

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines