| 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/TeProxMatrixConstructionStrategy.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 *************************************************************************************/
    00027 #ifndef TeProxMatrixConstructionStrategy_H
    00028 #define TeProxMatrixConstructionStrategy_H
    00029
    00030 #include "TeProxMatrixImplementation.h"
    00031 #include "TeSTElementSet.h"
    00032 #include "TeNetwork.h"
    00033 #include "TeDatabase.h"
    00034 #include "TeMultiGeometry.h"
    00035 #include "TeSTEvent.h"
    00036
    00037
    00038 class TeSTEventSet;
    00039
    00040 TL_DLL bool TeFindObjectCentroid (TeMultiGeometry& mGeom, TeGeomRep rep, TeCoord2D& p);
    00041
    00042 struct TL_DLL TeProxMatrixConstructionParams
    00043 {
    00044 public:
    00045
    00046            //construction parameters
    00047            int                                                               theme_id1_;
    00048            TeGeomRep                                   geom_rep1_;
    00049            int                                                               theme_id2_;
    00050            TeGeomRep                                   geom_rep2_;
    00051            TeGPMConstructionStrategy                   strategy_;
    00052            double                                                            max_distance_;
    00053            int                                                                          num_neighbours_;
    00054            double                                                            max_net_distance_;
    00055            double                                                            max_connection_distance_;
    00056            bool                                                              calculate_distance_;
    00057
    00059            TeProxMatrixConstructionParams():
    00060                       theme_id1_(-1),
    00061                       geom_rep1_(TeGEOMETRYNONE),
    00062                       theme_id2_(-1),
    00063                       geom_rep2_(TeGEOMETRYNONE),
    00064                       strategy_(TeAdjacencyStrategy),
    00065                       max_distance_(0.),
    00066                       num_neighbours_(0),
    00067                       max_net_distance_(0.),
    00068                       max_connection_distance_(0.),
    00069                       calculate_distance_(false)
    00070            { }
    00071
    00073            TeProxMatrixConstructionParams(const int& theme1, const TeGeomRep& geomRep1, const TeGPMConstructionStrategy& strType):
    00074                       theme_id1_(theme1),
    00075                       geom_rep1_(geomRep1),
    00076                       theme_id2_(-1),
    00077                       geom_rep2_(TeGEOMETRYNONE),
    00078                       strategy_(strType),
    00079                       max_distance_(0.),
    00080                       num_neighbours_(0),
    00081                       max_net_distance_(0.),
    00082                       max_connection_distance_(0.),
    00083                       calculate_distance_(false)
    00084            { }
    00085
    00087            bool operator==(const TeProxMatrixConstructionParams& other) const
    00088            {
    00089                       return(    (theme_id1_==other.theme_id1_) && (geom_rep1_==other.geom_rep1_) &&
    00090                                             (theme_id2_==other.theme_id2_) && (geom_rep2_==other.geom_rep2_) &&
    00091                                             (strategy_==other.strategy_) && (max_distance_==other.max_distance_) &&
    00092                                             (num_neighbours_==other.num_neighbours_) && (max_net_distance_==other.max_net_distance_) &&
    00093                                             (max_connection_distance_==other.max_connection_distance_) &&
    00094                                             (calculate_distance_==other.calculate_distance_));
    00095            }
    00096 };
    00097
    00099 template<typename T>
    00100 class TeProxMatrixConstructionStrategy
    00101 {
    00102 protected:
    00104            T*   objects_;
    00105
    00107            TeProxMatrixConstructionParams  params_;
    00108
    00110            TeProxMatrixConstructionStrategy();
    00111
    00113            TeProxMatrixConstructionStrategy(T* objects, TeGeomRep geomRep, const TeGPMConstructionStrategy& type=TeAdjacencyStrategy);
    00114
    00116            TeProxMatrixConstructionStrategy(const TeProxMatrixConstructionStrategy& st);
    00117
    00118 public:
    00120            virtual bool Construct(TeProxMatrixImplementation*)=0;
    00121
    00123            virtual ~TeProxMatrixConstructionStrategy()
    00124            {}
    00125
    00127            void setSTObjects (T*  objects, TeGeomRep  geomRep);
    00128
    00130            T* objects()  { return objects_; }
    00131
    00133            TeProxMatrixConstructionParams& constructionParams() { return params_; }
    00134
    00136            virtual bool IsEqual (const TeProxMatrixConstructionStrategy<T>& other) const;
    00137 };
    00138
    00139 template<typename T>
    00140 TeProxMatrixConstructionStrategy<T>::TeProxMatrixConstructionStrategy() :
    00141            objects_(0),
    00142            params_(-1, TeGEOMETRYNONE, TeAdjacencyStrategy)
    00143            { }
    00144
    00145 template<typename T>
    00146 TeProxMatrixConstructionStrategy<T>::TeProxMatrixConstructionStrategy(T*  objects, TeGeomRep geomRep, const TeGPMConstructionStrategy& type) :
    00147            objects_(objects)
    00148            {
    00149                       if(objects->theme())
    00150                                  params_.theme_id1_ = objects->theme()->id();
    00151                       params_.geom_rep1_ = geomRep;
    00152                       params_.strategy_ = type;
    00153            }
    00154
    00155 template<typename T>
    00156 TeProxMatrixConstructionStrategy<T>::TeProxMatrixConstructionStrategy (const TeProxMatrixConstructionStrategy& st)
    00157 {
    00158            objects_ = st.objects_;
    00159            params_ = st.params_;
    00160 }
    00161
    00162 template<typename T> void
    00163 TeProxMatrixConstructionStrategy<T>::setSTObjects (T*  objects, TeGeomRep  geomRep)
    00164 {
    00165            objects_ = objects;
    00166            if(objects->theme())
    00167                       params_.theme_id1_ = objects->theme()->id();
    00168            params_.geom_rep1_ = geomRep;
    00169 }
    00170
    00171 template<typename T> bool
    00172 TeProxMatrixConstructionStrategy<T>::IsEqual (const TeProxMatrixConstructionStrategy<T>& other) const
    00173 {
    00174            return ((params_==other.params_) &&
    00175                       ((&objects_)==(&other.objects_)));
    00176 }
    00177
    00178
    00180 class TL_DLL TeProxMatrixLocalAdjacencyStrategy : public  TeProxMatrixConstructionStrategy<TeSTElementSet>
    00181 {
    00182 public:
    00183
    00185            TeProxMatrixLocalAdjacencyStrategy ();
    00186
    00188            TeProxMatrixLocalAdjacencyStrategy (TeSTElementSet*  objects, TeGeomRep      geomRep, bool calcDistance=false);
    00189
    00191            TeProxMatrixLocalAdjacencyStrategy (TeProxMatrixLocalAdjacencyStrategy& st);
    00192
    00194            virtual ~TeProxMatrixLocalAdjacencyStrategy() {}
    00195
    00197            virtual bool Construct (TeProxMatrixImplementation* imp);
    00198
    00200            bool operator== (const TeProxMatrixLocalAdjacencyStrategy& rhs) const;
    00201
    00203            TeProxMatrixLocalAdjacencyStrategy& operator= (const TeProxMatrixLocalAdjacencyStrategy& rhs);
    00204
    00205 };
    00206
    00207
    00209 template<typename Set>
    00210 class TeProxMatrixLocalDistanceStrategy : public TeProxMatrixConstructionStrategy<Set>
    00211 {
    00212 public:
    00213
    00215            TeProxMatrixLocalDistanceStrategy ();
    00216
    00218            TeProxMatrixLocalDistanceStrategy (Set*  objects, TeGeomRep geomRep, double max_distance);
    00219
    00221            TeProxMatrixLocalDistanceStrategy (const TeProxMatrixLocalDistanceStrategy<Set>& st);
    00222
    00224            virtual ~TeProxMatrixLocalDistanceStrategy(){}
    00225
    00227            virtual bool Construct (TeProxMatrixImplementation* imp);
    00228
    00230            bool operator== (const TeProxMatrixLocalDistanceStrategy<Set>& s) const;
    00231
    00233            TeProxMatrixLocalDistanceStrategy<Set>& operator= (const TeProxMatrixLocalDistanceStrategy<Set>& rhs);
    00234
    00235 };
    00236
    00237
    00239 class TL_DLL TeProxMatrixNearestNeighbourStrategy : public  TeProxMatrixConstructionStrategy<TeSTEventSet>
    00240 {
    00241 public:
    00243            TeProxMatrixNearestNeighbourStrategy ();
    00244
    00246            // The STEventSet must be created with geometries, using kdTree and ordered by object_id
    00247            TeProxMatrixNearestNeighbourStrategy (TeSTEventSet* objects, int num_neighbours);
    00248
    00250            TeProxMatrixNearestNeighbourStrategy (const TeProxMatrixNearestNeighbourStrategy& st);
    00251
    00253            virtual ~TeProxMatrixNearestNeighbourStrategy(){}
    00254
    00256            virtual bool Construct (TeProxMatrixImplementation* imp);
    00257
    00259            bool operator== (const TeProxMatrixNearestNeighbourStrategy& s) const;
    00260
    00262            TeProxMatrixNearestNeighbourStrategy& operator= (const TeProxMatrixNearestNeighbourStrategy& rhs);
    00263
    00264 };
    00265
    00266
    00268 class TL_DLL TeProxMatrixClosedNetworkStrategy : public TeProxMatrixConstructionStrategy<TeSTElementSet>
    00269 {
    00270 private:
    00271            TeGraphNetwork*                  net_;
    00272
    00273 public:
    00275            TeProxMatrixClosedNetworkStrategy (         TeSTElementSet*  objects, TeGeomRep rep, double max_local_distance,
    00276                                                                                                               double max_net_distance, double  max_connection_distance,
    00277                                                                                                               TeGraphNetwork* input_net);
    00278
    00280            TeProxMatrixClosedNetworkStrategy (const TeProxMatrixClosedNetworkStrategy& rhs);
    00281
    00283            virtual ~TeProxMatrixClosedNetworkStrategy()
    00284            {
    00285                       if(net_)
    00286                                  delete (net_);
    00287            }
    00288
    00290            virtual bool Construct (TeProxMatrixImplementation* imp);
    00291
    00293            virtual bool IsEqual (const TeProxMatrixConstructionStrategy<TeSTElementSet>& other) const;
    00294
    00296            TeProxMatrixClosedNetworkStrategy& operator= (const TeProxMatrixClosedNetworkStrategy& rhs);
    00297
    00299            bool operator== (const TeProxMatrixClosedNetworkStrategy& other) const;
    00300
    00302            TeSTElementSet* objects() { return objects_; }
    00303 };
    00304
    00306 class TL_DLL TeProxMatrixOpenNetworkStrategy : public TeProxMatrixConstructionStrategy<TeSTElementSet>
    00307 {
    00308 private:
    00309            TeGraphNetwork*                  net_;
    00310
    00311 public:
    00312
    00314            TeProxMatrixOpenNetworkStrategy (           TeSTElementSet*  objects, TeGeomRep rep, double max_local_distance,
    00315                                                                                                               double     max_net_distance, double  max_connetion_distance,
    00316                                                                                                               TeGraphNetwork* input_net);
    00318            TeProxMatrixOpenNetworkStrategy (const TeProxMatrixOpenNetworkStrategy& rhs);
    00319
    00321            virtual ~TeProxMatrixOpenNetworkStrategy()
    00322            {
    00323                       if(net_)
    00324                                  delete (net_);
    00325            }
    00326
    00328            virtual bool Construct (TeProxMatrixImplementation* imp);
    00329
    00331            virtual bool IsEqual (const TeProxMatrixConstructionStrategy<TeSTElementSet>& other) const;
    00332
    00334            bool operator== (const TeProxMatrixOpenNetworkStrategy& other) const;
    00335
    00337            TeProxMatrixOpenNetworkStrategy& operator= (const TeProxMatrixOpenNetworkStrategy& rhs);
    00338 };
    00339
    00340
    00342 class TL_DLL TeProxMatrixOpenNetworkStrategy2 : public TeProxMatrixConstructionStrategy<TeSTElementSet>
    00343 {
    00344 private:
    00345            TeSTElementSet*                  objects2_;
    00346            TeGraphNetwork*                  net_;
    00347 public:
    00348
    00350            TeProxMatrixOpenNetworkStrategy2 (          TeSTElementSet*  objects1, TeGeomRep rep1,
    00351                                                                                                               TeSTElementSet*  objects2, TeGeomRep rep2,
    00352                                                                                                               double max_local_distance,
    00353                                                                                                               double     max_net_distance, double  max_connetion_distance,
    00354                                                                                                               TeGraphNetwork* input_net);
    00356            TeProxMatrixOpenNetworkStrategy2 (const TeProxMatrixOpenNetworkStrategy2& rhs);
    00357
    00359            virtual ~TeProxMatrixOpenNetworkStrategy2 ()
    00360            {
    00361                       if(net_)
    00362                                  delete (net_);
    00363            }
    00364
    00366            virtual bool Construct (TeProxMatrixImplementation* imp);
    00367
    00369            virtual bool IsEqual (const TeProxMatrixConstructionStrategy<TeSTElementSet>& other) const;
    00370
    00372            bool operator== (const TeProxMatrixOpenNetworkStrategy2& other) const;
    00373
    00375            TeProxMatrixOpenNetworkStrategy2& operator= (const TeProxMatrixOpenNetworkStrategy2& rhs);
    00376
    00377 };
    00378
    00380 // TeProxMatrixLocalDistanceStrategy
    00382 template<typename Set>
    00383 TeProxMatrixLocalDistanceStrategy<Set>::TeProxMatrixLocalDistanceStrategy ():
    00384                       TeProxMatrixConstructionStrategy<Set> (0, TeGEOMETRYNONE, TeDistanceStrategy)
    00385                       {}
    00386
    00387
    00388 template<typename Set>
    00389 TeProxMatrixLocalDistanceStrategy<Set>::TeProxMatrixLocalDistanceStrategy (Set*  objects, TeGeomRep geomRep, double max_distance):
    00390                       TeProxMatrixConstructionStrategy<Set>(objects, geomRep, TeDistanceStrategy)
    00391                       {
    00392                                  TeProxMatrixConstructionStrategy<Set>::params_.max_distance_ = max_distance;
    00393                       }
    00394
    00395
    00396 template<typename Set>
    00397 TeProxMatrixLocalDistanceStrategy<Set>::TeProxMatrixLocalDistanceStrategy (const TeProxMatrixLocalDistanceStrategy<Set>& st):
    00398                       TeProxMatrixConstructionStrategy<Set>(st)
    00399                       {}
    00400
    00401 template<typename Set> bool
    00402 TeProxMatrixLocalDistanceStrategy<Set>::Construct(TeProxMatrixImplementation* imp)
    00403 {
    00404            if (imp == 0)
    00405                       return false;
    00406
    00407            // Iterate over all selected objects, selecting their neighbours
    00408            TeSTElementSet::iterator itobj1 = TeProxMatrixConstructionStrategy<Set>::objects_->begin();
    00409
    00410            // ----- progress bar
    00411            int step = 0;
    00412            if(TeProgress::instance())
    00413                       TeProgress::instance()->setTotalSteps(TeProxMatrixConstructionStrategy<Set>::objects_->numSTInstance());
    00414            // -----
    00415
    00416            TeProjection* proj = 0;
    00417            if(TeProxMatrixConstructionStrategy<Set>::objects_->theme())
    00418                       proj = TeProxMatrixConstructionStrategy<Set>::objects_->theme()->layer()->projection();
    00419            else if(TeProxMatrixConstructionStrategy<Set>::objects_->getLayer())
    00420                       proj = TeProxMatrixConstructionStrategy<Set>::objects_->getLayer()->projection();
    00421
    00422            TePrecision::instance().setPrecision(TeGetPrecision(proj));
    00423            double max_d = TeProxMatrixConstructionStrategy<Set>::params_.max_distance_;
    00424
    00425            while ( itobj1 != TeProxMatrixConstructionStrategy<Set>::objects_->end())
    00426            {
    00427                       // Gets the possible objects from RTree in the element set
    00428                       vector<TeSTInstance*> result;
    00429                       TeBox b = (*itobj1).getGeometries().getBox();
    00430                       TeBox bAux(b.x1()-max_d, b.y1()-max_d, b.x2()+max_d, b.y2()+max_d);
    00431
    00432                       TeProxMatrixConstructionStrategy<Set>::objects_->search(bAux, result);
    00433
    00434                       string object_id1 = (*itobj1).getObjectId();
    00435                       TeCoord2D coord1 = itobj1->getCentroid();
    00436                       for(unsigned int index =0; index<result.size(); ++index)
    00437                       {
    00438                                  string object_id2 = result[index]->getObjectId();
    00439                                  if(object_id1==object_id2)
    00440                                             continue;
    00441
    00442                                  TeCoord2D coord2 = result[index]->getCentroid();
    00443                                  double dist = TeDistance(coord1, coord2);
    00444                                  if(dist <= max_d)
    00445                                  {
    00446                                             if(!imp->isConnected (object_id1,object_id2))
    00447                                             {
    00448                                                        TeProxMatrixAttributes attr;
    00449                                                        attr.CentroidDistance (dist);
    00450                                                        imp->connectObjects (object_id1, object_id2, attr);
    00451                                                        imp->connectObjects (object_id2, object_id1, attr);
    00452                                             }
    00453                                  }
    00454                       }
    00455
    00456                       if(TeProgress::instance())
    00457                       {
    00458                                  if (TeProgress::instance()->wasCancelled())
    00459                                  {
    00460                                             TeProgress::instance()->reset();
    00461                                             return false;
    00462                                  }
    00463                                  else
    00464                                             TeProgress::instance()->setProgress(step);
    00465                       }
    00466                       ++step;
    00467                       ++itobj1;
    00468            }
    00469
    00470            if (TeProgress::instance())
    00471                       TeProgress::instance()->reset();
    00472            return true;
    00473 }
    00474
    00475 template<typename Set> bool
    00476 TeProxMatrixLocalDistanceStrategy<Set>::operator== (const TeProxMatrixLocalDistanceStrategy<Set>& s) const
    00477 {
    00478            return ( TeProxMatrixConstructionStrategy<Set>::IsEqual(s));
    00479 }
    00480
    00481 template<typename Set> TeProxMatrixLocalDistanceStrategy<Set>&
    00482 TeProxMatrixLocalDistanceStrategy<Set>::operator= (const TeProxMatrixLocalDistanceStrategy<Set>& rhs)
    00483 {
    00484            if ( this != &rhs )
    00485            {
    00486                       TeProxMatrixConstructionStrategy<Set>::objects_ = rhs.objects_;
    00487                       TeProxMatrixConstructionStrategy<Set>::params_ = rhs.params_;
    00488            }
    00489            return *this;
    00490 }
    00491
    00493
    00495 class TL_DLL TeProxMatrixLocalTopologyStrategy : public  TeProxMatrixConstructionStrategy<TeSTElementSet>
    00496 {
    00497 private:
    00498            TeSTElementSet*                  objects2_;
    00499            TeGeomRep  geomRep2_;
    00500            int toprel_;
    00501 public:
    00502
    00504            TeProxMatrixLocalTopologyStrategy ();
    00505
    00507            TeProxMatrixLocalTopologyStrategy (TeSTElementSet*  objects, TeGeomRep       geomRep, TeSTElementSet*  objects2, TeGeomRep          geomRep2, int toprel= TeINTERSECTS, bool calcDistance=false);
    00508
    00510            TeProxMatrixLocalTopologyStrategy (TeProxMatrixLocalTopologyStrategy& st);
    00511
    00513            virtual ~TeProxMatrixLocalTopologyStrategy() {}
    00514
    00516            virtual bool Construct (TeProxMatrixImplementation* imp);
    00517
    00519            bool operator== (const TeProxMatrixLocalTopologyStrategy& rhs) const;
    00520
    00522            TeProxMatrixLocalTopologyStrategy& operator= (const TeProxMatrixLocalTopologyStrategy& rhs);
    00523
    00524 };
    00525
    00527 class TL_DLL TeProxMatrixChooseOneTopologyStrategy : public  TeProxMatrixConstructionStrategy<TeSTElementSet>
    00528 {
    00529 private:
    00530            TeSTElementSet*                  objects2_;
    00531            TeGeomRep  geomRep2_;
    00532            int toprel_;
    00533 public:
    00534
    00536            TeProxMatrixChooseOneTopologyStrategy ();
    00537
    00539            TeProxMatrixChooseOneTopologyStrategy (TeSTElementSet*  objects, TeGeomRep   geomRep, TeSTElementSet*  objects2, TeGeomRep          geomRep2, int toprel= TeINTERSECTS, bool calcDistance=false);
    00540
    00542            TeProxMatrixChooseOneTopologyStrategy (TeProxMatrixChooseOneTopologyStrategy& st);
    00543
    00545            virtual ~TeProxMatrixChooseOneTopologyStrategy() {}
    00546
    00548            virtual bool Construct (TeProxMatrixImplementation* imp);
    00549
    00551            bool operator== (const TeProxMatrixChooseOneTopologyStrategy& rhs) const;
    00552
    00554            TeProxMatrixChooseOneTopologyStrategy& operator= (const TeProxMatrixChooseOneTopologyStrategy& rhs);
    00555
    00556 };
    00557
    00559 class TL_DLL TeProxMatrixKeepInBothTopologyStrategy : public  TeProxMatrixConstructionStrategy<TeSTElementSet>
    00560 {
    00561 private:
    00562            TeSTElementSet*                  objects2_;
    00563            TeGeomRep  geomRep2_;
    00564            int toprel_;
    00565 public:
    00566
    00568            TeProxMatrixKeepInBothTopologyStrategy ();
    00569
    00571            TeProxMatrixKeepInBothTopologyStrategy (TeSTElementSet*  objects, TeGeomRep  geomRep, TeSTElementSet*  objects2, TeGeomRep          geomRep2, int toprel= TeINTERSECTS, bool calcDistance=false);
    00572
    00574            TeProxMatrixKeepInBothTopologyStrategy (TeProxMatrixKeepInBothTopologyStrategy& st);
    00575
    00577            virtual ~TeProxMatrixKeepInBothTopologyStrategy() {}
    00578
    00580            virtual bool Construct (TeProxMatrixImplementation* imp);
    00581
    00583            bool operator== (const TeProxMatrixKeepInBothTopologyStrategy& rhs) const;
    00584
    00586            TeProxMatrixKeepInBothTopologyStrategy& operator= (const TeProxMatrixKeepInBothTopologyStrategy& rhs);
    00587
    00588 };
    00589
    00590 #endif

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines