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

« back to all changes in this revision

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

  • 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
#ifdef WIN32
 
25
#pragma warning ( disable: 4786 )
 
26
#endif
 
27
 
 
28
#include "TeNeighbours.h"
 
29
 
 
30
TeProxMatrixAttributes::TeProxMatrixAttributes() 
 
31
{
 
32
        _weight = 1;                                    //default
 
33
        _slice  = 1;                                    //default
 
34
        _order  = 1;                                    //defaul
 
35
        _centroid_distance      = -1.0;         //not computed
 
36
        _borders_length         = -1.0;         //not computed
 
37
        _net_objects_distance           = -1.0;   //not computed
 
38
        _net_minimum_path= -1.0;                //not computed
 
39
}  
 
40
 
 
41
 
 
42
TeProxMatrixAttributes::TeProxMatrixAttributes (const TeProxMatrixAttributes& att) 
 
43
{               
 
44
        _weight = att._weight;
 
45
        _slice = att._slice; 
 
46
        _order = att._order; 
 
47
        _centroid_distance = att._centroid_distance;
 
48
        _borders_length = att._borders_length; 
 
49
        _net_objects_distance = att._net_objects_distance;
 
50
        _net_minimum_path = att._net_minimum_path;
 
51
}
 
52
 
 
53
 
 
54
TePropertyVector 
 
55
TeProxMatrixAttributes::getProperties ()
 
56
{
 
57
        TePropertyVector vec;
 
58
        TeProperty prop1; prop1.value_ = Te2String (_weight); vec.push_back ( prop1 );
 
59
        TeProperty prop2; prop2.value_ = Te2String (_slice); vec.push_back ( prop2 );
 
60
        TeProperty prop3; prop3.value_ = Te2String (_order); vec.push_back ( prop3 );
 
61
        TeProperty prop4; prop4.value_ = Te2String (_borders_length); vec.push_back ( prop4 );
 
62
        TeProperty prop5; prop5.value_ = Te2String (_centroid_distance); vec.push_back ( prop5 );       
 
63
        TeProperty prop6; prop6.value_ = Te2String (_net_objects_distance); vec.push_back ( prop6 );    
 
64
        TeProperty prop7; prop7.value_ = Te2String (_net_minimum_path); vec.push_back ( prop7 );
 
65
        return vec; 
 
66
}
 
67
 
 
68
 
 
69
TeProxMatrixAttributes& 
 
70
TeProxMatrixAttributes::operator= (const TeProxMatrixAttributes& att)
 
71
{               
 
72
        _weight = att._weight;
 
73
        _slice = att._slice; 
 
74
        _order = att._order; 
 
75
        _centroid_distance = att._centroid_distance;
 
76
        _borders_length = att._borders_length; 
 
77
        _net_objects_distance = att._net_objects_distance;
 
78
        _net_minimum_path = att._net_minimum_path;
 
79
        return *this;
 
80
}
 
81
 
 
82
 
 
83
 
 
84
bool 
 
85
TeProxMatrixAttributes::operator==(const TeProxMatrixAttributes& att) const
 
86
{
 
87
        return ((_weight == att._weight) && 
 
88
                (_slice == att._slice) && 
 
89
                (_order == att._order) && 
 
90
                (_centroid_distance == att._centroid_distance) && 
 
91
                (_borders_length == att._borders_length) &&  
 
92
                (_net_objects_distance == att._net_objects_distance) && 
 
93
                (_net_minimum_path == att._net_minimum_path));
 
94
}
 
95
 
 
96
 
 
97
TeNeighbours::TeNeighbours(const TeNeighboursMap& neigh)  
 
98
{
 
99
 
 
100
        TeNeighboursMap::const_iterator pos = neigh.begin(); 
 
101
 
 
102
        for (pos = neigh.begin(); pos != neigh.end(); ++pos)
 
103
                _neigh.push_back(make_pair (pos->first, pos->second));
 
104
}
 
105
 
 
106
 
 
107
 
 
108
TeNeighbours::TeNeighbours (const TeNeighbours& neigh)
 
109
{
 
110
        const_iterator it;
 
111
        for (it = neigh._neigh.begin(); it != neigh._neigh.end(); ++it) 
 
112
                _neigh.push_back(*it);
 
113
}
 
114
 
 
115
                
 
116
string
 
117
TeNeighbours::ObjectId (int n) 
 
118
{
 
119
        if (n < (int)_neigh.size()) 
 
120
                return _neigh[n].first;
 
121
 
 
122
        else {
 
123
                string empty;
 
124
                return empty;
 
125
        }
 
126
}
 
127
 
 
128
 
 
129
string 
 
130
TeNeighbours:: operator[](int n)
 
131
{
 
132
        if (n < (int)_neigh.size()) 
 
133
                return _neigh[n].first;
 
134
 
 
135
        else {
 
136
                string empty;
 
137
                return empty;
 
138
        }
 
139
}
 
140
 
 
141
double 
 
142
TeNeighbours:: Weight (int n)
 
143
{
 
144
        if (n < (int)_neigh.size()) 
 
145
                return _neigh[n].second.Weight();
 
146
 
 
147
        else
 
148
                return 0.0;
 
149
}               
 
150
 
 
151
        
 
152
double 
 
153
TeNeighbours:: Weight (const string& object_id)
 
154
{
 
155
        for (unsigned int i = 0; i< _neigh.size(); ++i) {
 
156
                if (object_id == _neigh[i].first) 
 
157
                        return _neigh[i].second.Weight();
 
158
        }
 
159
        return 0.0;
 
160
}               
 
161
 
 
162
        
 
163
TeProxMatrixAttributes 
 
164
TeNeighbours:: Attributes (int n)
 
165
{
 
166
        TeProxMatrixAttributes attr;
 
167
 
 
168
        if (n < (int)_neigh.size()) 
 
169
                return _neigh[n].second;
 
170
        else
 
171
                return attr;
 
172
}
 
173
        
 
174
bool
 
175
TeNeighbours:: operator== (const TeNeighbours& neigh)
 
176
{
 
177
        if (_neigh == neigh._neigh) return true;
 
178
        else return false;
 
179
}
 
180
 
 
181
 
 
182
TeNeighbours& 
 
183
TeNeighbours::operator= (const TeNeighbours& neigh)
 
184
{
 
185
        if (*this == neigh)
 
186
            return *this;
 
187
 
 
188
        _neigh.clear();
 
189
 
 
190
        const_iterator it;
 
191
        for (it = neigh._neigh.begin(); it != neigh._neigh.end(); ++it) 
 
192
                _neigh.push_back(*it);
 
193
 
 
194
    return *this; 
 
195
}
 
196
 
 
197
 
 
198
bool
 
199
TeNeighbours:: Insert (const string& object_id, const TeProxMatrixAttributes& attr)
 
200
{
 
201
        for (unsigned int i = 0; i< _neigh.size(); i++) {
 
202
                if (object_id == _neigh[i].first) 
 
203
                        return false;
 
204
        }
 
205
        _neigh.push_back (make_pair (object_id, attr));
 
206
        return true;
 
207
}
 
208
 
 
209
 
 
210
bool 
 
211
TeNeighbours:: Remove (const string& object_id)
 
212
{
 
213
        iterator it = _neigh.begin();
 
214
        while (it!= _neigh.end()) 
 
215
                if (object_id == (*it).first)
 
216
                {
 
217
                        _neigh.erase (it);
 
218
                        return true;
 
219
                }
 
220
        return false;
 
221
}