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

« back to all changes in this revision

Viewing changes to src/terralib/kernel/TeGeneralizedProxMatrix.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, 2002, 2003 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 TeGeneralizedProxMatrix.h
 
25
    This file contains structures and definitions about 
 
26
        generalized proximity matrices support in TerraLib
 
27
*/
 
28
 
 
29
 
 
30
#ifndef TeProxMatrix_H
 
31
#define TeProxMatrix_H
 
32
 
 
33
#include "TeNeighbours.h"
 
34
#include "TeProxMatrixImplementation.h"
 
35
#include "TeProxMatrixConstructionStrategy.h"
 
36
#include "TeProxMatrixSlicingStrategy.h"
 
37
#include "TeProxMatrixWeightsStrategy.h"
 
38
 
 
39
 
 
40
//! A class to represent a generalized proximity matrix 
 
41
class TeGeneralizedProxMatrix  
 
42
{
 
43
private:
 
44
 
 
45
        TeProxMatrixImplementation*                             imp_;  
 
46
        TeProxMatrixConstructionStrategy*               sc_;   
 
47
        TeProxMatrixSlicingStrategy*                    ss_;   
 
48
        TeProxMatrixWeightsStrategy*                    sw_;   
 
49
 
 
50
        int                                                                             total_slices_;
 
51
 
 
52
protected:
 
53
 
 
54
        //! Get the implementation from a concrete factory defined by impl_type
 
55
        TeProxMatrixImplementation*                             getImplementation(const string implementation_type = "Breymann");
 
56
 
 
57
        //! Verify if a matrix was created correctly by the constructors.       
 
58
        bool IsValid() const;
 
59
        
 
60
public:
 
61
 
 
62
        //! Empty constructor
 
63
        TeGeneralizedProxMatrix ()
 
64
        {imp_ = 0; sc_ = 0; sw_ = 0; ss_ = 0; total_slices_=1;}
 
65
 
 
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");
 
68
 
 
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");
 
71
 
 
72
        //! Copy constructor
 
73
        TeGeneralizedProxMatrix(const TeGeneralizedProxMatrix& p);
 
74
 
 
75
        //! Attribution Operator 
 
76
        TeGeneralizedProxMatrix& operator=(const TeGeneralizedProxMatrix& p);
 
77
 
 
78
        bool ClearImplementation ();
 
79
 
 
80
        //! Comparison Operator
 
81
        bool operator==(const TeGeneralizedProxMatrix& p) const;
 
82
        
 
83
        
 
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).
 
90
        */
 
91
        //@{ 
 
92
        //! Return the neighbours of an object in a slice, packed in a TeNeighbours 
 
93
        TeNeighbours getNeighbours (const string& object_id, int slice = 1);
 
94
 
 
95
        //! Return the neighbours of an object in a slice, packed in a TeNeighboursMap
 
96
        TeNeighboursMap getMapNeighbours (const string& object_id, int slice = 1);
 
97
        
 
98
        //! Operator [], return the neighbours packed in a TeNeighbours
 
99
        TeNeighbours operator[] (const string& object_id); 
 
100
 
 
101
        //! Return the neighbours of an object and their attributes in a spatial temporal element set (TeSTElementSet)
 
102
        TeSTElementSet getSTENeighbours(const string& object_id); 
 
103
 
 
104
        //@}
 
105
 
 
106
        
 
107
        /** @name Methods for changing current strategies 
 
108
        *  change current strategies 
 
109
        */
 
110
        //@{ 
 
111
        //! Set current construction strategy 
 
112
        bool setCurrentConstructionStrategy (TeProxMatrixConstructionStrategy* sc);  
 
113
        
 
114
        //! Set current weights strategy 
 
115
        bool setCurrentWeightsStrategy (TeProxMatrixWeightsStrategy* sw); 
 
116
        
 
117
        //! Set current slicing strategy 
 
118
        bool setCurrentSlicingStrategy (TeProxMatrixSlicingStrategy* ss); 
 
119
        //@}
 
120
        
 
121
 
 
122
        //! Reconstruct matrix and recompute weights and slicing, accornding to current strategies.
 
123
        bool ConstructMatrix ();
 
124
 
 
125
        //! Recomputes the weigths, given a new strategy. The matrix is not reconstructed.
 
126
        bool RecomputeWeights ();
 
127
 
 
128
        //! Sets the slicing strategy for neighbours selection.
 
129
        bool RecomputeSlicing ();
 
130
 
 
131
        //! Verify if two objects are connected
 
132
        bool IsConnected (const string& object_id1, const string& object_id2); 
 
133
 
 
134
        //! Connect two objects
 
135
        bool ConnectObjects (const string& object_id1, const string& object_id2, const TeProxMatrixAttributes& attr); 
 
136
        
 
137
        //! Connect two objects
 
138
        bool ConnectObjects (const string& object_id1, const string& object_id2);
 
139
 
 
140
        //! Disconnect two objects
 
141
        bool DisconnectObjects (const string& object_id1, const string& object_id2); 
 
142
 
 
143
        //! Remove object
 
144
        bool RemoveObject (const string& object_id);  
 
145
 
 
146
        //! Get connection attributes
 
147
        bool GetConnectionAttributes (const string& object_id1, string& object_id2, TeProxMatrixAttributes& attr); 
 
148
 
 
149
        //! Return the number of objects
 
150
        int NumberOfObjects (); 
 
151
 
 
152
        //! Return the number of slices
 
153
        int NumerOfSlices () {return total_slices_;}
 
154
 
 
155
        //! Save the matrix in a text file
 
156
        bool SaveTextFile (string name); 
 
157
 
 
158
                //! Save the matrix in a text file
 
159
        bool SaveGALFile (string name);         
 
160
        
 
161
        //! Save the matrix in a text file
 
162
        bool SaveGWTFile (string name); 
 
163
 
 
164
        //! Destructor
 
165
        virtual ~TeGeneralizedProxMatrix();
 
166
 
 
167
};
 
168
 
 
169
#endif