TeNeighbours.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 *************************************************************************************/
00023 /*! \file TeNeighbours.h
00024     \brief This file contains structures and definitions about neighborhood 
00025 */
00026 
00027 #ifndef  __TERRALIB_INTERNAL_NEGHBOURS_H
00028 #define  __TERRALIB_INTERNAL_NEGHBOURS_H
00029 
00030 #include "TeUtils.h"
00031 #include "TeAttribute.h"
00032 
00033 #include <vector> 
00034 #include <string>
00035 #include <map> 
00036 using namespace std;
00037 
00038 
00039 //! Attributes associated with each neighborhood of a proximity matrix  
00040 class TL_DLL TeProxMatrixAttributes  
00041 {
00042         private:
00043                 double  _weight;
00044                 int             _slice;
00045                 int             _order;
00046                 double  _centroid_distance;
00047                 double  _borders_length;
00048                 double  _net_objects_distance;
00049                 double  _net_minimum_path;
00050 
00051 
00052         public:
00053                 
00054                 //! Empty constructor 
00055                 TeProxMatrixAttributes(); 
00056 
00057                 //! Constructor 
00058                 TeProxMatrixAttributes(const double& w, const int& slice, const int& order, 
00059                         const double& cent_dist, const double& border_length, 
00060                         const double& net_distance, const double& net_minimun_path): 
00061                                 _weight(w), _slice(slice), 
00062                                 _order(order), _centroid_distance(cent_dist), 
00063                 _borders_length(border_length), 
00064                 _net_objects_distance(net_distance), 
00065                 _net_minimum_path(net_minimun_path)
00066                 {}
00067                 
00068                 //! Copy constuctor 
00069                 TeProxMatrixAttributes (const TeProxMatrixAttributes& att); 
00070                 
00071                 //! Return weight
00072                 double  Weight() {return _weight;}
00073 
00074                 //! Return slice
00075                 int             Slice () {return _slice;}
00076 
00077                 //! Return order
00078                 int             Order() {return _order;}
00079 
00080                 //! Return border length
00081                 double  BorderLength() {return _borders_length;}
00082 
00083                 //! Return centroid distance
00084                 double  CentroidDistance() {return _centroid_distance;}
00085 
00086                 //! Return network objects distance
00087                 double  NetworkObjectsDistance() {return _net_objects_distance;}
00088 
00089                 //! Return network minimum path
00090                 double  NetworkMinimumPath () {return _net_minimum_path;}
00091 
00092                 //! Set weight
00093                 void Weight(double w) {_weight = w;}
00094 
00095                 //! Set slice
00096                 void Slice (int s) {_slice = s;}
00097                 
00098                 //! Set order
00099                 void Order(int o) {_order = o;}
00100 
00101                 //! Set border length
00102                 void BorderLength(double l) {_borders_length = l;}
00103 
00104                 //! Set centroid distance
00105                 void CentroidDistance(double d) {_centroid_distance = d;}
00106 
00107                 //! Set network objects distance
00108                 void NetworkObjectsDistance(double d) {_net_objects_distance = d;}
00109 
00110                 //! Set network minimum path
00111                 void NetworkMinimumPath (double d) {_net_minimum_path = d;}
00112 
00113                 //! Return the attributes as a TePropertyVector
00114                 TePropertyVector getProperties ();
00115 
00116                 //! Return if the border length was computed 
00117                 bool WasBordersLengthComputed () {if (_borders_length == -1.0) return false; else return true;}
00118                 
00119                 //! Return if the centroid distance was computed
00120                 bool WasCentroidDistanceComputed () {if (_centroid_distance == -1.0) return false; else return true;}
00121                 
00122                 //! Return if the network objects distance was computed
00123                 bool WasNetworkObjectsDistanceComputed () {if (_net_objects_distance == -1.0) return false; else return true;}
00124                 
00125                 //! Return if the network minimal path was computed
00126                 bool WasNetworkMinimumPathComputed () {if (_net_minimum_path == -1.0) return false; else return true;}
00127 
00128                 //! Copy operator
00129                 TeProxMatrixAttributes& operator= (const TeProxMatrixAttributes& att); 
00130                 
00131                 //! Comparison Operator
00132                 bool operator==(const TeProxMatrixAttributes& att) const;
00133                         
00134                 //! Destructor
00135                 virtual ~TeProxMatrixAttributes() {}
00136 };
00137 
00138 //! A map from a object to its attributes
00139 typedef map<string, TeProxMatrixAttributes> TeNeighboursMap;
00140 
00141 
00142 //! A class to representate the neighbours of a object 
00143 class TL_DLL TeNeighbours  
00144 {
00145 private:
00146         typedef pair<string, TeProxMatrixAttributes>    neigh_values;
00147         typedef vector<neigh_values>                                    neigh_vector;
00148 
00149         neigh_vector _neigh; 
00150         
00151 
00152 public:
00153 
00154         typedef neigh_vector::iterator iterator;
00155         typedef neigh_vector::const_iterator const_iterator;
00156 
00157         //! Empty constructor
00158         TeNeighbours () {};
00159 
00160         //! Copy constructor
00161         TeNeighbours(const TeNeighboursMap& neigh);
00162 
00163         //! Copy constructor
00164         TeNeighbours(const TeNeighbours& neigh);
00165         
00166         //! Return the number of the neighbours
00167         int size() const  { return _neigh.size();}
00168 
00169         //! Return a iterator to the begin of the neighbours
00170     iterator begin()     { return _neigh.begin();}
00171 
00172         //! Return a iterator to the one past end of the neighbours
00173     iterator end()       { return _neigh.end();}
00174 
00175         //! Return the n-th neighbour object_id, if n < map size.
00176         string ObjectId (int n);  
00177 
00178         //! Return the n-th neighbour object_id, if n < map size.
00179         string operator[](int n);  
00180 
00181         //! Return the n-th connection weight (corresponding to the n-th neighbour), if n < map size.
00182         double Weight (int n);          
00183 
00184         //! Return the connection weight, given the neighbour object_id 
00185         double Weight (const string& object_id);        
00186         
00187         //! Return the complete set of connection attributes (corresponding to the ith neighbour), packed in a TeProxMatrixAttributes object.
00188         TeProxMatrixAttributes Attributes (int n);
00189         
00190         //! Insert a new neighbour
00191         bool Insert (const string& object_id, const TeProxMatrixAttributes& attr);
00192 
00193         //! Remove a neighbour
00194         bool Remove (const string& object_id);
00195 
00196         //! Copy operator
00197         TeNeighbours& operator= (const TeNeighbours& neigh);
00198 
00199         //! Comparison Operator
00200         bool operator==(const TeNeighbours& p);
00201 
00202         //! Destructor
00203         virtual ~TeNeighbours() {}
00204 
00205 };
00206 
00207 #endif

Generated on Sun Jul 29 04:01:22 2012 for TerraLib - Development Source by  doxygen 1.5.3