~ubuntu-branches/ubuntu/hardy/libterralib/hardy

« back to all changes in this revision

Viewing changes to src/terralib/kernel/TeNeighbours.h

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2005-11-25 22:32:59 UTC
  • Revision ID: james.westby@ubuntu.com-20051125223259-3zubal8ux4ki4fjg
Tags: upstream-3.0.3b2
Import upstream version 3.0.3b2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/************************************************************************************
 
2
TerraLib - a library for developing GIS applications.
 
3
Copyright � 2001-2004 INPE and Tecgraf/PUC-Rio.
 
4
 
 
5
This code is part of the TerraLib library.
 
6
This library is free software; you can redistribute it and/or
 
7
modify it under the terms of the GNU Lesser General Public
 
8
License as published by the Free Software Foundation; either
 
9
version 2.1 of the License, or (at your option) any later version.
 
10
 
 
11
You should have received a copy of the GNU Lesser General Public
 
12
License along with this library.
 
13
 
 
14
The authors reassure the license terms regarding the warranties.
 
15
They specifically disclaim any warranties, including, but not limited to,
 
16
the implied warranties of merchantability and fitness for a particular purpose.
 
17
The library provided hereunder is on an "as is" basis, and the authors have no
 
18
obligation to provide maintenance, support, updates, enhancements, or modifications.
 
19
In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct,
 
20
indirect, special, incidental, or consequential damages arising out of the use
 
21
of this library and its documentation.
 
22
*************************************************************************************/
 
23
 
 
24
/*! \file TeNeighbours.h
 
25
    This file contains structures and definitions about neighborhood 
 
26
*/
 
27
 
 
28
#ifndef  __TERRALIB_INTERNAL_NEGHBOURS_H
 
29
#define  __TERRALIB_INTERNAL_NEGHBOURS_H
 
30
 
 
31
#include "TeUtils.h"
 
32
#include "TeAttribute.h"
 
33
 
 
34
#include <vector> 
 
35
#include <string>
 
36
#include <map> 
 
37
using namespace std;
 
38
 
 
39
 
 
40
//! Attributes associated with each neighborhood of a proximity matrix  
 
41
class TeProxMatrixAttributes  
 
42
{
 
43
        private:
 
44
                double  _weight;
 
45
                int             _slice;
 
46
                int             _order;
 
47
                double  _centroid_distance;
 
48
                double  _borders_length;
 
49
                double  _net_objects_distance;
 
50
                double  _net_minimum_path;
 
51
 
 
52
 
 
53
        public:
 
54
                
 
55
                //! Empty constructor 
 
56
                TeProxMatrixAttributes(); 
 
57
                
 
58
                //! Copy constuctor 
 
59
                TeProxMatrixAttributes (const TeProxMatrixAttributes& att); 
 
60
                
 
61
                //! Return weight
 
62
                double  Weight() {return _weight;}
 
63
 
 
64
                //! Return slice
 
65
                int             Slice () {return _slice;}
 
66
 
 
67
                //! Return order
 
68
                int             Order() {return _order;}
 
69
 
 
70
                //! Return border length
 
71
                double  BorderLength() {return _borders_length;}
 
72
 
 
73
                //! Return centroid distance
 
74
                double  CentroidDistance() {return _centroid_distance;}
 
75
 
 
76
                //! Return network objects distance
 
77
                double  NetworkObjectsDistance() {return _net_objects_distance;}
 
78
 
 
79
                //! Return network minimum path
 
80
                double  NetworkMinimumPath () {return _net_minimum_path;}
 
81
 
 
82
                //! Set weight
 
83
                void Weight(double w) {_weight = w;}
 
84
 
 
85
                //! Set slice
 
86
                void Slice (int s) {_slice = s;}
 
87
                
 
88
                //! Set order
 
89
                void Order(int o) {_order = o;}
 
90
 
 
91
                //! Set border length
 
92
                void BorderLength(double l) {_borders_length = l;}
 
93
 
 
94
                //! Set centroid distance
 
95
                void CentroidDistance(double d) {_centroid_distance = d;}
 
96
 
 
97
                //! Set network objects distance
 
98
                void NetworkObjectsDistance(double d) {_net_objects_distance = d;}
 
99
 
 
100
                //! Set network minimum path
 
101
                void NetworkMinimumPath (double d) {_net_minimum_path = d;}
 
102
 
 
103
                //! Return the attributes as a TePropertyVector
 
104
                TePropertyVector getProperties ();
 
105
 
 
106
                //! Return if the border length was computed 
 
107
                bool WasBordersLengthComputed () {if (_borders_length == -1.0) return false; else return true;}
 
108
                
 
109
                //! Return if the centroid distance was computed
 
110
                bool WasCentroidDistanceComputed () {if (_centroid_distance == -1.0) return false; else return true;}
 
111
                
 
112
                //! Return if the network objects distance was computed
 
113
                bool WasNetworkObjectsDistanceComputed () {if (_net_objects_distance == -1.0) return false; else return true;}
 
114
                
 
115
                //! Return if the network minimal path was computed
 
116
                bool WasNetworkMinimumPathComputed () {if (_net_minimum_path == -1.0) return false; else return true;}
 
117
 
 
118
                //! Copy operator
 
119
                TeProxMatrixAttributes& operator= (const TeProxMatrixAttributes& att); 
 
120
                
 
121
                //! Comparison Operator
 
122
                bool operator==(const TeProxMatrixAttributes& att) const;
 
123
                        
 
124
                //! Destructor
 
125
                virtual ~TeProxMatrixAttributes() {}
 
126
};
 
127
 
 
128
//! A map from a object to its attributes
 
129
typedef map<string, TeProxMatrixAttributes> TeNeighboursMap;
 
130
 
 
131
 
 
132
//! A class to representate the neighbours of a object 
 
133
class TeNeighbours  
 
134
{
 
135
private:
 
136
        typedef pair<string, TeProxMatrixAttributes>    neigh_values;
 
137
        typedef vector<neigh_values>                                    neigh_vector;
 
138
 
 
139
        neigh_vector _neigh; 
 
140
        
 
141
 
 
142
public:
 
143
 
 
144
        typedef neigh_vector::iterator iterator;
 
145
        typedef neigh_vector::const_iterator const_iterator;
 
146
 
 
147
        //! Empty constructor
 
148
        TeNeighbours () {};
 
149
 
 
150
        //! Copy constructor
 
151
        TeNeighbours(const TeNeighboursMap& neigh);
 
152
 
 
153
        //! Copy constructor
 
154
        TeNeighbours(const TeNeighbours& neigh);
 
155
        
 
156
        //! Return the number of the neighbours
 
157
        int size() const  { return _neigh.size();}
 
158
 
 
159
        //! Return a iterator to the begin of the neighbours
 
160
    iterator begin()     { return _neigh.begin();}
 
161
 
 
162
        //! Return a iterator to the one past end of the neighbours
 
163
    iterator end()       { return _neigh.end();}
 
164
 
 
165
        //! Return the n-th neighbour object_id, if n < map size.
 
166
        string ObjectId (int n);  
 
167
 
 
168
        //! Return the n-th neighbour object_id, if n < map size.
 
169
        string operator[](int n);  
 
170
 
 
171
        //! Return the n-th connection weight (corresponding to the n-th neighbour), if n < map size.
 
172
        double Weight (int n);          
 
173
 
 
174
        //! Return the connection weight, given the neighbour object_id 
 
175
        double Weight (const string& object_id);        
 
176
        
 
177
        //! Return the complete set of connection attributes (corresponding to the ith neighbour), packed in a TeProxMatrixAttributes object.
 
178
        TeProxMatrixAttributes Attributes (int n);
 
179
        
 
180
        //! Return the complete set of connection attributes, given the neighbour object_id, packed in a TeProxMatrixAttributes object.
 
181
        TeProxMatrixAttributes Attributes (const string& object_id);
 
182
 
 
183
        //! Insert a new neighbour
 
184
        bool Insert (const string& object_id, const TeProxMatrixAttributes& attr);
 
185
 
 
186
        //! Remove a neighbour
 
187
        bool Remove (const string& object_id);
 
188
 
 
189
        //! Copy operator
 
190
        TeNeighbours& operator= (const TeNeighbours& neigh);
 
191
 
 
192
        //! Comparison Operator
 
193
        bool operator==(const TeNeighbours& p);
 
194
 
 
195
        //! Destructor
 
196
        virtual ~TeNeighbours() {}
 
197
 
 
198
};
 
199
 
 
200
#endif