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
/*! \file TeGeneralizedProxMatrix.h
25
This file contains structures and definitions about
26
generalized proximity matrices support in TerraLib
30
#ifndef TeProxMatrix_H
31
#define TeProxMatrix_H
33
#include "TeNeighbours.h"
34
#include "TeProxMatrixImplementation.h"
35
#include "TeProxMatrixConstructionStrategy.h"
36
#include "TeProxMatrixSlicingStrategy.h"
37
#include "TeProxMatrixWeightsStrategy.h"
40
//! A class to represent a generalized proximity matrix
41
class TeGeneralizedProxMatrix
45
TeProxMatrixImplementation* imp_;
46
TeProxMatrixConstructionStrategy* sc_;
47
TeProxMatrixSlicingStrategy* ss_;
48
TeProxMatrixWeightsStrategy* sw_;
54
//! Get the implementation from a concrete factory defined by impl_type
55
TeProxMatrixImplementation* getImplementation(const string implementation_type = "Breymann");
57
//! Verify if a matrix was created correctly by the constructors.
63
TeGeneralizedProxMatrix ()
64
{imp_ = 0; sc_ = 0; sw_ = 0; ss_ = 0; total_slices_=1;}
66
//! Constructor parametrized with specific strategies. Each stragegy must be previously created and correctly parametrized.
67
TeGeneralizedProxMatrix (TeProxMatrixConstructionStrategy* sc, TeProxMatrixWeightsStrategy* sw = 0, TeProxMatrixSlicingStrategy* ss = 0, const string type = "Breymann");
69
//! Constructor based on default strategies: (a) Local adjacency of first order; (b) No siling; and (c) No weighs (all equal to 1).
70
TeGeneralizedProxMatrix(TeSTElementSet* objects, TeGeomRep geom_type, const string type = "Breymann");
73
TeGeneralizedProxMatrix(const TeGeneralizedProxMatrix& p);
75
//! Attribution Operator
76
TeGeneralizedProxMatrix& operator=(const TeGeneralizedProxMatrix& p);
78
bool ClearImplementation ();
80
//! Comparison Operator
81
bool operator==(const TeGeneralizedProxMatrix& p) const;
84
/** @name Methods for return the neighbours
85
* All methods return the neighbours of a given object in a given slice. The default is the first slice.
86
* Slices are defined according to the Slicing Strategy in use (e.g., according to distance zones, corresponding to neighbourhood orders, weights intervals, etc.).
87
* If the parameter slice is not provided, the first slice is returned.
88
* The operator[] method should preferably be used
89
* For each object, all the connection attributes are stored as properties (weight is the first).
92
//! Return the neighbours of an object in a slice, packed in a TeNeighbours
93
TeNeighbours getNeighbours (const string& object_id, int slice = 1);
95
//! Return the neighbours of an object in a slice, packed in a TeNeighboursMap
96
TeNeighboursMap getMapNeighbours (const string& object_id, int slice = 1);
98
//! Operator [], return the neighbours packed in a TeNeighbours
99
TeNeighbours operator[] (const string& object_id);
101
//! Return the neighbours of an object and their attributes in a spatial temporal element set (TeSTElementSet)
102
TeSTElementSet getSTENeighbours(const string& object_id);
107
/** @name Methods for changing current strategies
108
* change current strategies
111
//! Set current construction strategy
112
bool setCurrentConstructionStrategy (TeProxMatrixConstructionStrategy* sc);
114
//! Set current weights strategy
115
bool setCurrentWeightsStrategy (TeProxMatrixWeightsStrategy* sw);
117
//! Set current slicing strategy
118
bool setCurrentSlicingStrategy (TeProxMatrixSlicingStrategy* ss);
122
//! Reconstruct matrix and recompute weights and slicing, accornding to current strategies.
123
bool ConstructMatrix ();
125
//! Recomputes the weigths, given a new strategy. The matrix is not reconstructed.
126
bool RecomputeWeights ();
128
//! Sets the slicing strategy for neighbours selection.
129
bool RecomputeSlicing ();
131
//! Verify if two objects are connected
132
bool IsConnected (const string& object_id1, const string& object_id2);
134
//! Connect two objects
135
bool ConnectObjects (const string& object_id1, const string& object_id2, const TeProxMatrixAttributes& attr);
137
//! Connect two objects
138
bool ConnectObjects (const string& object_id1, const string& object_id2);
140
//! Disconnect two objects
141
bool DisconnectObjects (const string& object_id1, const string& object_id2);
144
bool RemoveObject (const string& object_id);
146
//! Get connection attributes
147
bool GetConnectionAttributes (const string& object_id1, string& object_id2, TeProxMatrixAttributes& attr);
149
//! Return the number of objects
150
int NumberOfObjects ();
152
//! Return the number of slices
153
int NumerOfSlices () {return total_slices_;}
155
//! Save the matrix in a text file
156
bool SaveTextFile (string name);
158
//! Save the matrix in a text file
159
bool SaveGALFile (string name);
161
//! Save the matrix in a text file
162
bool SaveGWTFile (string name);
165
virtual ~TeGeneralizedProxMatrix();