1
/************************************************************************************
2
TerraLib - a library for developing GIS applications.
3
Copyright ļæ½ 2001, 2002, 2003 INPE and Tecgraf/PUC-Rio.
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.
11
You should have received a copy of the GNU Lesser General Public
12
License along with this library.
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
*************************************************************************************/
24
#include "TeSTElementSet.h"
25
#include "TeGeneralizedProxMatrix.h"
29
TeGeneralizedProxMatrix::IsValid () const
31
if ((imp_) && (sc_) && (ss_) && (sw_))
38
TeProxMatrixImplementation*
39
TeGeneralizedProxMatrix::getImplementation (const string type)
42
imp_ = TeProxMatrixAbstractFactory::MakeConcreteImplementation (type);
48
TeGeneralizedProxMatrix::TeGeneralizedProxMatrix(TeSTElementSet* objects, TeGeomRep geom_type, const string imp_type)
51
imp_ = getImplementation(imp_type);
54
if ((geom_type==TePOLYGONS) || (geom_type==TeCELLS))
55
sc_ = new TeProxMatrixLocalAdjacencyStrategy (objects, geom_type);
62
ss_ = new TeProxMatrixNoSlicingStrategy;
63
sw_ = new TeProxMatrixNoWeightsStrategy;
66
if (sc_->Construct (imp_)) {
68
sw_->ComputeWeigths (imp_);
81
TeGeneralizedProxMatrix::TeGeneralizedProxMatrix (TeProxMatrixConstructionStrategy* sc, TeProxMatrixWeightsStrategy* sw, TeProxMatrixSlicingStrategy* ss, const string imp_type)
84
imp_ = getImplementation(imp_type);
92
ss_ = new TeProxMatrixNoSlicingStrategy();
97
sw_ = new TeProxMatrixNoWeightsStrategy();
101
if (sc_->Construct (imp_)) {
103
sw_->ComputeWeigths (imp_);
115
TeGeneralizedProxMatrix::TeGeneralizedProxMatrix(const TeGeneralizedProxMatrix& pm)
120
imp_ = pm.imp_->CreateCopy ();
122
total_slices_ = pm.total_slices_;
127
if (IsValid() == false)
137
TeGeneralizedProxMatrix&
138
TeGeneralizedProxMatrix::operator=(const TeGeneralizedProxMatrix& pm)
140
if (*this == pm) return *this;
142
if (imp_) delete imp_;
144
if (pm.imp_) imp_ = pm.imp_->CreateCopy ();
146
total_slices_ = pm.total_slices_;
151
if (IsValid() == false)
164
TeGeneralizedProxMatrix::operator==(const TeGeneralizedProxMatrix& pm) const
166
if (IsValid() && pm.IsValid())
168
if ((sc_->IsEqual (*(pm.sc_))) &&
169
(ss_->IsEqual (*(pm.ss_))) &&
170
(sw_->IsEqual (*(pm.sw_))) &&
171
(total_slices_ == pm.total_slices_) &&
173
(imp_->IsEqual(*(pm.imp_)))) return true;
175
if ((IsValid() == false) && (pm.IsValid() == false))
183
TeGeneralizedProxMatrix:: getNeighbours (const string& object_id, int slice)
186
if (slice > total_slices_) return neigh2;
191
imp_->getNeighbours (object_id, neigh1);
192
for (int i=0; i < neigh1.size(); i++)
193
if (neigh1.Attributes(i).Slice() == slice)
194
neigh2.Insert (neigh1.ObjectId(i), neigh1.Attributes(i));
202
TeGeneralizedProxMatrix::operator[](const string& object_id)
204
return getNeighbours(object_id);
209
TeGeneralizedProxMatrix::getMapNeighbours (const string& object_id, int slice)
212
if (slice > total_slices_) return map;
217
imp_->getNeighbours (object_id, neigh);
219
for (int i=0; i < neigh.size(); i++)
220
if (neigh.Attributes(i).Slice() == slice)
221
map[neigh.ObjectId(i)] = neigh.Attributes(i);
229
TeGeneralizedProxMatrix::getSTENeighbours(const string& object_id)
231
TeSTElementSet selected_objects;
235
imp_->getNeighbours (object_id, neigh);
237
for (int i = 0; i < neigh.size(); i++)
239
// Construct a sto instance with its attributes
241
obj.objectId(neigh.ObjectId(i));
243
//load the attributes
244
TePropertyVector propVector;
245
sc_->objects()->getPropertyVector(object_id, propVector);
246
obj.properties(propVector);
248
// insert object in the return vector
249
selected_objects.insertSTInstance(obj);
252
return selected_objects;
257
TeGeneralizedProxMatrix::setCurrentConstructionStrategy (TeProxMatrixConstructionStrategy* sc)
267
TeGeneralizedProxMatrix::setCurrentWeightsStrategy (TeProxMatrixWeightsStrategy* sw)
276
TeGeneralizedProxMatrix::setCurrentSlicingStrategy (TeProxMatrixSlicingStrategy* ss)
285
TeGeneralizedProxMatrix:: ConstructMatrix ()
288
// ClearImplementation();
290
imp_ = getImplementation();
294
if (sc_->Construct (imp_))
296
if (ss_) ss_->Slice (imp_);
297
if (sw_) sw_->ComputeWeigths (imp_);
306
TeGeneralizedProxMatrix:: ClearImplementation ()
308
TeProxMatrixImplementation* aux;
309
if (imp_ == 0) aux = getImplementation ();
310
else aux = getImplementation (imp_->Type().c_str());
312
if (aux == 0) return false;
320
TeGeneralizedProxMatrix:: RecomputeWeights ()
323
sw_->ComputeWeigths (imp_); return true;
330
TeGeneralizedProxMatrix:: RecomputeSlicing ()
333
ss_->Slice (imp_); return true;
340
TeGeneralizedProxMatrix::IsConnected (const string& object_id1, const string& object_id2)
344
return imp_->isConnected (object_id1, object_id2);
348
TeGeneralizedProxMatrix::ConnectObjects (const string& object_id1, const string& object_id2, const TeProxMatrixAttributes& attr)
352
imp_->connectObjects (object_id1, object_id2, attr);
357
TeGeneralizedProxMatrix::ConnectObjects (const string& object_id1, const string& object_id2)
361
TeProxMatrixAttributes attr;
362
imp_->connectObjects (object_id1, object_id2, attr);
367
TeGeneralizedProxMatrix::DisconnectObjects (const string& object_id1, const string& object_id2)
371
return imp_->disconnectObjects (object_id1, object_id2);
375
TeGeneralizedProxMatrix::RemoveObject (const string& object_id)
379
return imp_->removeObject (object_id);
383
TeGeneralizedProxMatrix::GetConnectionAttributes (const string& object_id1, string& object_id2, TeProxMatrixAttributes& attr)
387
return imp_->getConnectionAttributes (object_id1, object_id2, attr);
391
TeGeneralizedProxMatrix::NumberOfObjects ()
395
return imp_->NumberOfObjects ();
399
TeGeneralizedProxMatrix::SaveTextFile (string name)
403
return imp_->SaveTextFile (name);
408
TeGeneralizedProxMatrix::SaveGALFile (string name)
412
return imp_->SaveGALFile (name);
416
TeGeneralizedProxMatrix::SaveGWTFile (string name)
420
return imp_->SaveGWTFile (name);
423
TeGeneralizedProxMatrix::~TeGeneralizedProxMatrix()
426
delete imp_; //It is not counted.