| 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/stat/TeStatDataStructures.h
Go to the documentation of this file.

    00001 /************************************************************************************
    00002 Exploring and analysis of geographical data using TerraLib and TerraView
    00003 Copyright � 2003-2007 INPE and LESTE/UFMG.
    00004
    00005 Partially funded by CNPq - Project SAUDAVEL, under grant no. 552044/2002-4,
    00006 SENASP-MJ and INPE
    00007
    00008 This program is free software; you can redistribute it and/or
    00009 modify it under the terms of the GNU Lesser General Public
    00010 License as published by the Free Software Foundation; either
    00011 version 2.1 of the License, or (at your option) any later version.
    00012
    00013 This program is distributed hoping it will be useful, however, WITHOUT ANY
    00014 WARRANTIES; neither to the implicit warranty of MERCHANTABILITY OR SUITABILITY FOR
    00015 AN SPECIFIC FINALITY. Consult the GNU General Public License for more details.
    00016
    00017 You must have received a copy of the GNU General Public License with this program.
    00018 In negative case, write to the Free Software Foundation, Inc. in the following
    00019 address: 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
    00020 ***********************************************************************************/
    00024 #ifndef __TERRALIB_INTERNAL_STATDATASTRUCTURES_H
    00025 #define __TERRALIB_INTERNAL_STATDATASTRUCTURES_H
    00026
    00027 #include "TeStatDefines.h"
    00028 #include "../kernel/TeProjection.h"
    00029 #include "../kernel/TeRaster.h"
    00030 #include "../kernel/TeAttribute.h"
    00031 #include "../kernel/TeCoord2D.h"
    00032 #include "../kernel/TeSTInstance.h"
    00033
    00034 class TeSTElementSet;
    00035
    00036 class STAT_DLL TeGridElement
    00037 {
    00038            TeRaster* parent_;
    00039
    00040 public:
    00041            int col_;
    00042            int lin_;
    00043
    00044            TeGridElement(TeRaster* rst=0, int col=0, int lin=0):
    00045            parent_(rst),
    00046            col_(col),
    00047            lin_(lin)
    00048            {}
    00049
    00050            void setColLin(int col, int lin)
    00051            {          col_ = col; lin_ = lin;          }
    00052
    00053            void setRaster(TeRaster* rst)
    00054            {          parent_ = rst; }
    00055
    00056            void addProperty(TeProperty propK)
    00057            {
    00058                       double val = atof(propK.value_.c_str());
    00059                       parent_->setElement(col_,lin_,val);
    00060            }
    00061
    00062            bool getDoubleProperty(int idx, double& value)
    00063            {          return parent_->getElement(col_, lin_, value, idx);    }
    00064
    00065            bool setDoubleProperty(int idx , double value)
    00066            {          return parent_->setElement(col_,lin_, value, idx);     }
    00067
    00068            bool getPropertyValue(const string& /* name */, string& value)
    00069            {
    00070                       double val;
    00071                       if (parent_->getElement(col_,lin_,val))
    00072                       {
    00073                                  value = Te2String(val,12);
    00074                                  return true;
    00075                       }
    00076                       value = Te2String(-1.0);
    00077                       return false;
    00078            }
    00079
    00080            bool setPropertyValue(const string& /* name */, const string&  value)
    00081            {
    00082                       double val;
    00083                       val = atof(value.c_str());
    00084                       return parent_->setElement(col_,lin_,val);
    00085            }
    00086
    00087            bool centroid(TeCoord2D& loc)
    00088            {
    00089                       TeCoord2D pt(col_,lin_);
    00090                       loc = parent_->index2Coord(pt);
    00091                       return true;
    00092            }
    00093
    00094            bool area(double& a)
    00095            {
    00096                       a = parent_->params().resx_ * parent_->params().resy_;
    00097                       return true;
    00098            }
    00099 };
    00101
    00107 class STAT_DLL TeKernelGridSupport
    00108 {
    00109            TeRaster* rasterImp_;
    00110 public:
    00111
    00112            TeKernelGridSupport(TeBox& bb, int ncols, TeProjection* proj, unsigned int nBands = 1)
    00113            {
    00114                       TeRasterParams par;
    00115                       par.decoderIdentifier_=  "MEM";
    00116                       par.fileName_ = "rasterTemp";
    00117                       rasterImp_ =0;
    00118
    00119                       double resx = bb.width()/ncols;
    00120                       TeBox newBox = adjustToCut(bb,resx,resx);
    00121                       par.boundingBoxResolution(newBox.x1_,newBox.y1_,newBox.x2_,newBox.y2_,resx,resx);
    00122                       newBox = par.boundingBox();
    00123                       par.nBands(nBands);
    00124                       par.projection(proj);
    00125                       par.setDataType(TeDOUBLE);
    00126                       par.setDummy(-TeMAXFLOAT);
    00127                       par.setPhotometric(TeRasterParams::TeMultiBand);
    00128                       par.useDummy_ = true;
    00129                       par.mode_ = 'c';
    00130
    00131                       rasterImp_ = new TeRaster(par);
    00132                       if(!rasterImp_)
    00133                                  rasterImp_ = 0;
    00134
    00135                       if (!rasterImp_->init())
    00136                       {
    00137                                  delete rasterImp_;
    00138                                  rasterImp_ = 0;
    00139                       }
    00140            }
    00141
    00142
    00143            ~TeKernelGridSupport()
    00144            {
    00145                       if (rasterImp_)
    00146                       {
    00147                                  delete rasterImp_;
    00148                                  rasterImp_ = 0;
    00149                       }
    00150            }
    00151
    00152            bool status()
    00153            {          return (rasterImp_ && rasterImp_->status()); }
    00154
    00155            double totalArea()
    00156            { return TeGeometryArea(rasterImp_->params().boundingBox()); }
    00157
    00158            int numObjects()
    00159            {
    00160                       TeRasterParams par;
    00161                       par = rasterImp_->params();
    00162                       return par.ncols_ * par.nlines_;
    00163            }
    00164
    00165            //-----
    00166            class iterator
    00167            {
    00168                       friend class TeKernelGridSupport;
    00169
    00170            protected:
    00171                       TeRaster::iterator  curItRaster_; //guarda iterador que pode ser de poligono ou nao
    00172                       TeGridElement elem_;
    00173
    00174            public:
    00175                       iterator(TeRaster* rst=0): curItRaster_(0)
    00176                       { elem_.setRaster(rst); }
    00177
    00178                       ~iterator() {}
    00179
    00180                       iterator(TeRaster::iterator itr, TeRaster* rst=0) :
    00181                                  curItRaster_(itr)
    00182                       {
    00183                                  elem_.setRaster(rst);
    00184                                  elem_.setColLin(curItRaster_.currentColumn(), curItRaster_.currentLine());
    00185                       }
    00186
    00187                       iterator& operator++()
    00188                       {
    00189                                  //curItRaster_->operator++();
    00190                                  curItRaster_.moveForward();
    00191                                  elem_.setColLin(curItRaster_.currentColumn(), curItRaster_.currentLine());
    00192                                  return *this;
    00193                       }
    00194
    00195                       bool operator==(const iterator& rhs) const
    00196                       { return ((this->curItRaster_) ==   (rhs.curItRaster_)); }
    00197
    00198                       bool operator!=(const iterator& rhs) const
    00199                       { return !((this->curItRaster_) ==   (rhs.curItRaster_));}
    00200
    00201                       iterator& operator=(const iterator& other)
    00202                       {
    00203                                  if ( this != &other )
    00204                                  {
    00205                                             curItRaster_ = other.curItRaster_;
    00206                                             elem_ = other.elem_;
    00207                                  }
    00208                                  return *this;
    00209                       }
    00210
    00211                       TeGridElement& operator*() { return elem_; }
    00212
    00213                       TeGridElement& operator->() { return elem_; }
    00214            };
    00215
    00216            //-----
    00217            class iteratorPoly
    00218            {
    00219                       friend class TeKernelGridSupport;
    00220
    00221            protected:
    00222     TeRaster::iteratorPoly curItRaster_; //guarda iterador que pode ser de poligono ou nao
    00223                       TeGridElement elem_;
    00224
    00225            public:
    00226                       iteratorPoly(TeRaster* rst=0): curItRaster_(0)
    00227                       { elem_.setRaster(rst); }
    00228
    00229         ~iteratorPoly() {}
    00230
    00231                       iteratorPoly(TeRaster::iteratorPoly itr, TeRaster* rst=0) :
    00232                                  curItRaster_(itr)
    00233                       {
    00234                                  elem_.setRaster(rst);
    00235                                  elem_.setColLin(curItRaster_.currentColumn(), curItRaster_.currentLine());
    00236                       }
    00237
    00238                       iteratorPoly& operator++()
    00239                       {
    00240                                  //curItRaster_->operator++();
    00241                                  curItRaster_.moveForward();
    00242                                  elem_.setColLin(curItRaster_.currentColumn(), curItRaster_.currentLine());
    00243                                  return *this;
    00244                       }
    00245
    00246                       bool operator==(const iteratorPoly& rhs) const
    00247                       {          return ((this->curItRaster_) ==   (rhs.curItRaster_)); }
    00248
    00249                       bool operator!=(const iteratorPoly& rhs) const
    00250                       { return !((this->curItRaster_) ==   (rhs.curItRaster_)); }
    00251
    00252                       iteratorPoly& operator=(const iteratorPoly& other)
    00253                       {
    00254                                  if ( this != &other )
    00255                                  {
    00256                                             curItRaster_ = other.curItRaster_;
    00257                                             elem_ = other.elem_;
    00258                                  }
    00259                                  return *this;
    00260                       }
    00261
    00262                       TeGridElement& operator*() { return elem_; }
    00263
    00264                       TeGridElement& operator->() { return elem_; }
    00265            };
    00266
    00267
    00268            //-----
    00269
    00270            TeRaster* raster()
    00271            {          return rasterImp_; }
    00272
    00273            iterator begin()
    00274            {
    00275                       TeRasterParams par = rasterImp_->params();
    00276                       TeRaster::iterator itbegin(0,0,par.ncols_,par.nlines_,par.nBands(),rasterImp_);
    00277                       TeKernelGridSupport::iterator it(itbegin,rasterImp_);
    00278                       return it;
    00279            }
    00280
    00281            iteratorPoly begin(TePolygon poly)
    00282            {
    00283                       TeRaster::iteratorPoly itRasterBegin_ = rasterImp_->begin(poly,TeBBoxPixelInters);
    00284                       TeKernelGridSupport::iteratorPoly it(itRasterBegin_, rasterImp_);
    00285                       return it;
    00286            }
    00287
    00288            iterator end()
    00289            {
    00290                       TeRasterParams par = rasterImp_->params();
    00291                       TeRaster::iterator itend =  TeRaster::iterator(par.ncols_,par.nlines_-1,par.ncols_,par.nlines_,par.nBands(),rasterImp_);
    00292                       TeKernelGridSupport::iterator it(itend,rasterImp_);
    00293                       return it;
    00294            }
    00295
    00296            iteratorPoly end(TePolygon poly)
    00297            {
    00298                       TeRaster::iteratorPoly itRasterEnd_ =  rasterImp_->end(poly,TeBBoxPixelInters);
    00299                       TeKernelGridSupport::iteratorPoly it(itRasterEnd_,rasterImp_);
    00300                       return it;
    00301            }
    00302 };
    00303
    00304
    00308 class STAT_DLL TeSTStatInstance : public  TeSTInstance
    00309 {
    00310
    00311   protected:
    00312
    00313            vector<double> dblProperties_;
    00314
    00316            void initDbl(int n)
    00317            {
    00318                       for(int i=0; i<n; ++i)
    00319                                  dblProperties_.push_back (0.0);
    00320            }
    00321
    00322   public:
    00323
    00325            TeSTStatInstance(int nDlbProp = 0);
    00326
    00328     TeSTStatInstance(TeSTInstance& other, int nd, int ad);
    00329
    00331     TeSTStatInstance(const TeSTStatInstance& other);
    00332
    00334     virtual ~TeSTStatInstance()
    00335            { }
    00336
    00338            TeSTStatInstance& operator=(const TeSTStatInstance& other);
    00339
    00340     bool setDoubleProperty(unsigned int idx, double value)
    00341            {
    00342                       if (idx >= dblProperties_.size())
    00343            return false;
    00344                       dblProperties_[idx] = value;
    00345                       return true;
    00346     }
    00347
    00348     bool getDoubleProperty(unsigned int idx, double& value)
    00349            {
    00350                       if (idx >= dblProperties_.size())
    00351                                  return false;
    00352                       value = dblProperties_[idx];
    00353                       return true;
    00354     }
    00355
    00356 };
    00357
    00358 class STAT_DLL TeSTStatInstanceSet
    00359 {
    00360
    00361
    00362   protected:
    00363
    00364     // map of object identification to its instances in time
    00365     vector<TeSTStatInstance >    objs_;
    00366
    00367   public:
    00368
    00370     TeSTStatInstanceSet()
    00371            {}
    00372
    00374            virtual ~TeSTStatInstanceSet()
    00375            {}
    00376
    00378     TeSTStatInstanceSet(const TeSTStatInstanceSet& other)
    00379            {
    00380                       this->objs_ = other.objs_;
    00381            }
    00382
    00384            virtual TeSTStatInstanceSet& operator=(const TeSTStatInstanceSet& other);
    00385
    00386
    00387     void Copy(TeSTElementSet& stoSet, int nDbl=0, int aDbl = 0);
    00388
    00389     int numObjects();
    00390
    00391     class iterator {
    00392       vector<TeSTStatInstance >::iterator it_;
    00393
    00394     public:
    00395       iterator(vector<TeSTStatInstance >::iterator i){it_ = i;}
    00396
    00397       ~iterator(){}
    00398
    00399       iterator& operator++()
    00400       {
    00401         ++it_;
    00402         return *this;
    00403       }
    00404
    00405       bool operator==(const iterator& rhs) const
    00406       {
    00407         return ((this->it_) ==   (rhs.it_));
    00408       }
    00409
    00410       bool operator!=(const iterator& rhs) const
    00411       {
    00412         return !((this->it_) ==   (rhs.it_));
    00413       }
    00414
    00415       iterator& operator=(const iterator& other)
    00416       {
    00417         if ( this != &other )
    00418         {
    00419           it_ = other.it_;
    00420         }
    00421         return *this;
    00422       }
    00423
    00424       TeSTStatInstance& operator*() { return *(it_); }
    00425     };
    00426
    00427     iterator begin() {
    00428       return TeSTStatInstanceSet::iterator(objs_.begin());
    00429     }
    00430
    00431     iterator end() {
    00432       return TeSTStatInstanceSet::iterator(objs_.end());
    00433     }
    00434
    00435 };
    00436
    00437 // Classe de eventos pontuais
    00438 class STAT_DLL TePointTInstanceSet : public TeSTStatInstanceSet
    00439 {
    00440
    00441   public:
    00442
    00443            TePointTInstanceSet() : TeSTStatInstanceSet()
    00444            {}
    00445
    00447            ~TePointTInstanceSet()
    00448            {}
    00449
    00450
    00451   iterator begin(const TeCoord2D& /* center */, const double& /* radius */)
    00452   {
    00453     return TeSTStatInstanceSet::begin();
    00454   }
    00455
    00456   iterator end(const TeCoord2D& /* center */, const double& /* radius */)
    00457   {
    00458     return TeSTStatInstanceSet::end();
    00459   }
    00460
    00461   iterator begin()
    00462   {
    00463     return TeSTStatInstanceSet::begin();
    00464   }
    00465
    00466   iterator end()
    00467   {
    00468     return TeSTStatInstanceSet::end();
    00469   }
    00470 };
    00471
    00472 #endif

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines