Loading...
Searching...
No Matches
AbstractOperation.h
Go to the documentation of this file.
1/* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2
3 This file is part of the TerraLib - a Framework for building GIS enabled applications.
4
5 TerraLib is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 TerraLib is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with TerraLib. See COPYING. If not, write to
17 TerraLib Team at <terralib-team@terralib.org>.
18 */
19
20/*!
21\file terralib/vp/AbstractOperation.h
22
23\brief Abstract Class to represent an abstract vector operation.
24*/
25
26#ifndef __TERRALIB_VP_INTERNAL_ABSCTRACTOPERATION_H
27#define __TERRALIB_VP_INTERNAL_ABSCTRACTOPERATION_H
28
29#include "Config.h"
30
31#include "../common/AbstractFactory.h"
32#include "../geometry/Enums.h"
33
34// STL
35#include <string>
36#include <vector>
37#include <mutex>
38
39namespace te
40{
41 namespace da
42 {
43 class DataAccess;
44 class DataSetType;
45 }
46
47 namespace vp
48 {
49 struct AbstractOperationImpl;
50 class Feature;
51 class FeatureSet;
52 class OperationReport;
53
54 enum class OperationResult
55 {
57 };
58
59 /*!
60 \class AbstractParameters
61
62 \brief Abstract class used to define the input/ ouptut parameters for TerraAmazon Operations.
63
64 \note Not all parameters must be defined, each operation will validate the necessary parameters.
65 */
67 {
68 public:
69
70 /*! \brief Default constructor. */
72
73 /*! \brief Virtual destructor. */
74 virtual ~AbstractParameters() = default;
75
76 public:
77
78 /*!
79 \brief It checks the parameters for the operation.
80
81 \return True if the parameters is valid for this operation and false in other cases.
82 */
83 virtual bool isValid(std::string& errorMessage);
84
85 /*!
86 \brief It reports each parameter used in the operation
87
88 \param report Object used to report operation information.
89 */
91
92 /*!
93 \brief Adds an input data access to the params
94
95 \param dataAccess The input dataAccess to be added
96 */
98
99 /*!
100 \brief Adds an output data access to the params. Note that if the dataSet does not exist, it will be created by the operation
101
102 \param dataAccess The output dataAccess to be added
103 */
105
106 //!< Returns the input dataAccess vector
107 const std::vector<te::da::DataAccess*>& getInputDataAccessVector() const;
108
109 //!< Returns the output dataAccess vector
110 const std::vector<te::da::DataAccess*>& getOutputDataAccessVector() const;
111
112 //!< Sets the input dataAccess vector
113 void setInputDataAccessVector(const std::vector<te::da::DataAccess*>& vecDataAccess);
114
115 //!< Sets the output dataAccess vector
116 void setOutputDataAccessVector(const std::vector<te::da::DataAccess*>& vecDataAccess);
117
118 //!< Enables or disables geometry subdivision
119 void setMaxCoordinates(std::size_t maxCoordinates);
120
121 //!< Returns the current state of the geometry subdivision
122 std::size_t getMaxCoordinates() const;
123
124 //!< Sets the input to be swapped. This is very usefull for operations between 2 dataSets. If TRUE, the input will be swapped. Default is FALSE
125 void setSwapInput(bool swap);
126
127 //!< Returns TRUE if the input must be swaped. FALSE otherwise.
128 bool getSwapInput() const;
129
130 //!< Gets the result of the operation
132
133 //!< Sets the result of the operation
135
136 protected:
137
138 /*!
139 \brief It reports each specific parameter used in the operation
140
141 \param report Object used to report operation information.
142 */
144
145 protected:
146
147 std::vector<te::da::DataAccess*> m_inputDataVector; //!< Vector with input dataAccess
148 std::vector<te::da::DataAccess*> m_outputDataVector; //!< Vector with output dataAccess
149 bool m_swapInput; //!< This is very usefull for operations between 2 dataSets. If TRUE, the input will be swapped. Default is FALSE
150 bool m_snapGeometries; //!< If TRUE, the geometries will be snapped before the operation is executed. Default is TRUE
151 OperationResult m_operationResult; //!< Stores the result of the operation
152 std::size_t m_maxCoordinates; //!< If higher than 0, geometries will be subdivided until all the parts have less vertexes that this value
153 };
154
155 /*!
156 \class AbstractOperationCapabilities
157
158 \brief Abstract class used to define the capabilities of the operation, inclusing number of inputs and outputs.
159 */
161 {
162 public:
163 AbstractOperationCapabilities(const std::string& operationName, std::size_t numberOfInputs, std::size_t numberOfOutputs, const std::string& dataHandlerName, bool snapGeometries, bool allowCoordinateSubdivision);
164
165 //!< Destructor
167
168 //!< Returns the number of inputs of the operation
169 std::size_t getNumberOfInputs() const;
170
171 //!< Returns the number of outputs of the operation
172 std::size_t getNumberOfOutputs() const;
173
174 //!< Returns the name of the operation
175 const std::string& getName() const;
176
177 //!< Returns TRUE if the operation supports the subdivision of the geometries. FALSE otherwise
178 const std::string& getDataHandlerName() const;
179
180 //!< Checks if the geometries must be snapped to each other before the operation is executed
181 bool getSnapGeometries() const;
182
183 //!< Checks if the operation has the capability to handle geometry coordinate subdivision
185
186 //!< Creates the parameters for this operation. If the concrete operation has specific parameters, it must override this class and instantiate the correct parameters
187 virtual std::unique_ptr<AbstractParameters> createParameters() const;
188
189 protected:
190
191 std::string m_operationName; //!< The name of the operation
192 std::size_t m_numberOfInputs; //!< The number of inputs of the operation
193 std::size_t m_numberOfOutputs; //!< The number of outputs of the operation
194 std::string m_dataHandlerName; //!< TRUE if the operation supports the subdivision of the geometries. FALSE otherwise
195 bool m_snapGeometries; //!< TRUE if the geometries must be snapped to each other before the operation is executed. FALSE otherwise. Default is TRUE
196 bool m_allowCoordinateSubdivision; //!< TRUE if the operation has the capability to handle geometry coordinate subdivision
197 };
198
199 /*!
200 \class AbstractOperation
201
202 \brief Abstract class used to define an operation.
203 */
205 {
206 public:
207
208 /*!
209 \brief Default constructor.
210
211 \note This class will take the ownership of AbstractParameters pointer
212 */
213 AbstractOperation(const std::string& operationName);
214
215 /*! \brief Virtual destructor. */
217
218 //!< Initializes the operation input and output
219 virtual void initialize();
220
221 /*!
222 \brief It executes the operation.
223
224 \param input Input vector data to be processed.
225
226 \pre The parameters must be valid (internal check)
227
228 \exception Exception It throws an exception if something goes wrong during the execution.
229
230 \Return The output memory data processed.
231 */
232 virtual std::vector<te::vp::FeatureSet> execute(const std::vector<te::vp::FeatureSet>& vecInput);
233
234 /*!
235 \brief It creates the output feature based on the given output dataaccess index
236
237 \param outputIndex The index of the output dataAccess.
238 */
239 virtual te::vp::Feature* createOutputFeature(std::size_t outputIndex);
240
241 /*!
242 \brief Gets the dataSetType of the 'outputIndex-th' output
243
244 \param outputIndex The index of the output dataAccess.
245 */
246 virtual const te::da::DataSetType* getDataSetType(std::size_t outputIndex);
247
248 //!< Sets the parameters to be used by the operation
250
251 //!< Gets the operation current parameters
253
254 //!< Gets the operation report
256
257 //!< Gets the operation name
258 const std::string& getName() const;
259
260 //!< Gets the output geometry type
262
263 /*!
264 \brief Set the output geometry type
265 \note Default value: te::gm::UnknownGeometryType
266 */
268
269 /*!
270 \brief Aborts the execution of the operation.
271 \note Thread-safe method (using internal mutex).
272 */
273 void abort();
274
275 /*!
276 \brief Returns TRUE if the operation has been aborted. FALSE otherwise
277 \note Thread-safe method (using internal mutex).
278 */
279 bool isAborted() const;
280
281 //!< Get the capabilities of the operation. Basically, operation will have 2 inputs, 1 output, and support subdivision. If it is not the case of the concrete class, this function should be overriden
282 virtual std::unique_ptr<te::vp::AbstractOperationCapabilities> getCapabilities() const;
283
284 //!< Makes all the necessaries adaptations to the input dataAccess to avoid duplicate column names
286
288
289 bool handleOutputPropertyNamesChanges(const te::da::DataSetType* baseOutputDataSetType, const te::da::DataSetType* actualOutputDataSetType);
290
291 protected:
292
293 //!< Creates the basic dataSetType for the output containing all the columns that are required
294 virtual te::da::DataSetType* createBasicOutputDataSetType(const std::string& dataSetName, int srid, te::gm::GeomType geometryType, const std::string& geometryColumnName) const;
295
296 virtual void addOutputColumns(te::da::DataSetType* outputDataSetType);
297
298 //!< Initializes the operation input
299 virtual bool initializeInput();
300
301 //!< Initializes the operation output
302 virtual bool initializeOutput();
303
304 //!< Function that effectivelly executes the operation. It must be implemented by the concrete classes
305 virtual std::vector<te::vp::FeatureSet> executeImpl(const std::vector<te::vp::FeatureSet>& vecInput) = 0;
306
307 private:
308
309 AbstractOperationImpl* m_impl; //!< Holds all the attributes of the class
310 bool m_aborted; //!< Becames true if the abort function is called. Concrete classes must check for this value from time to time
311 mutable std::recursive_mutex m_mutex;
312 };
313
314 /*!
315 \class OperationFactory
316
317 \brief Abstract factory used to create Operations.
318 */
319 class TEVPEXPORT OperationFactory : public te::common::AbstractFactory < te::vp::AbstractOperation, std::string >
320 {
321 protected:
322
323 /*!
324 \brief Constructor.
325
326 \param factoryKey The key that identifies the factory.
327 */
328 OperationFactory(const std::string& factoryKey);
329
330 //!< Destructor
332 };
333
334 }
335}
336
337#endif // __TERRALIB_VP_INTERNAL_ABSCTRACTOPERATION_H
This class defines the interface of abstract factories without initializing parameters.
Class used to centralize and control access to data in terralib. It aims to create a high-level inter...
Definition DataAccess.h:77
A class that models the description of a dataset.
Definition DataSetType.h:73
Abstract class used to define the capabilities of the operation, inclusing number of inputs and outpu...
std::string m_operationName
The name of the operation.
bool getSnapGeometries() const
Checks if the operation has the capability to handle geometry coordinate subdivision.
bool m_snapGeometries
TRUE if the geometries must be snapped to each other before the operation is executed....
std::string m_dataHandlerName
TRUE if the operation supports the subdivision of the geometries. FALSE otherwise.
AbstractOperationCapabilities(const std::string &operationName, std::size_t numberOfInputs, std::size_t numberOfOutputs, const std::string &dataHandlerName, bool snapGeometries, bool allowCoordinateSubdivision)
Destructor.
std::size_t getNumberOfOutputs() const
Returns the name of the operation.
bool m_allowCoordinateSubdivision
TRUE if the operation has the capability to handle geometry coordinate subdivision.
std::size_t m_numberOfOutputs
The number of outputs of the operation.
std::size_t getNumberOfInputs() const
Returns the number of outputs of the operation.
bool getAllowCoordinateSubdivision() const
Creates the parameters for this operation. If the concrete operation has specific parameters,...
const std::string & getName() const
Returns TRUE if the operation supports the subdivision of the geometries. FALSE otherwise.
const std::string & getDataHandlerName() const
Checks if the geometries must be snapped to each other before the operation is executed.
virtual ~AbstractOperationCapabilities()
Returns the number of inputs of the operation.
std::size_t m_numberOfInputs
The number of inputs of the operation.
virtual std::unique_ptr< AbstractParameters > createParameters() const
Abstract class used to define an operation.
AbstractOperationImpl * m_impl
Holds all the attributes of the class.
const std::string & getName() const
Gets the output geometry type.
virtual void initialize()
std::recursive_mutex m_mutex
void abort()
Aborts the execution of the operation.
virtual bool initializeInput()
Initializes the operation output.
virtual te::vp::Feature * createOutputFeature(std::size_t outputIndex)
It creates the output feature based on the given output dataaccess index.
virtual const te::da::DataSetType * getDataSetType(std::size_t outputIndex)
Gets the dataSetType of the 'outputIndex-th' output.
virtual std::vector< te::vp::FeatureSet > execute(const std::vector< te::vp::FeatureSet > &vecInput)
It executes the operation.
bool isAborted() const
Returns TRUE if the operation has been aborted. FALSE otherwise.
virtual std::vector< te::vp::FeatureSet > executeImpl(const std::vector< te::vp::FeatureSet > &vecInput)=0
virtual void addOutputColumns(te::da::DataSetType *outputDataSetType)
Initializes the operation input.
virtual te::da::DataSetType * createBasicOutputDataSetType(const std::string &dataSetName, int srid, te::gm::GeomType geometryType, const std::string &geometryColumnName) const
< Creates the basic dataSetType for the output containing all the columns that are required
void setParameters(AbstractParameters *params)
Gets the operation current parameters.
virtual std::unique_ptr< te::vp::AbstractOperationCapabilities > getCapabilities() const
Makes all the necessaries adaptations to the input dataAccess to avoid duplicate column names.
bool m_aborted
Becames true if the abort function is called. Concrete classes must check for this value from time to...
OperationReport * getReport() const
Gets the operation name.
virtual bool initializeOutput()
Function that effectivelly executes the operation. It must be implemented by the concrete classes.
virtual ~AbstractOperation()
Virtual destructor.
AbstractParameters * getParameters() const
Gets the operation report.
bool handleOutputPropertyNamesChanges(const te::da::DataSetType *baseOutputDataSetType, const te::da::DataSetType *actualOutputDataSetType)
AbstractOperation(const std::string &operationName)
Default constructor.
void setOutputGeometryType(const te::gm::GeomType newType)
Set the output geometry type.
te::gm::GeomType getOutputGeometryType() const
Abstract class used to define the input/ ouptut parameters for TerraAmazon Operations.
bool m_swapInput
This is very usefull for operations between 2 dataSets. If TRUE, the input will be swapped....
virtual void reportSpecificParams(OperationReport *report)
It reports each specific parameter used in the operation.
OperationResult getOperationResult() const
Sets the result of the operation.
const std::vector< te::da::DataAccess * > & getInputDataAccessVector() const
Returns the output dataAccess vector.
void reportParams(OperationReport *report)
It reports each parameter used in the operation.
OperationResult m_operationResult
Stores the result of the operation.
virtual bool isValid(std::string &errorMessage)
It checks the parameters for the operation.
bool getSwapInput() const
Gets the result of the operation.
AbstractParameters()
Default constructor.
std::size_t getMaxCoordinates() const
Sets the input to be swapped. This is very usefull for operations between 2 dataSets....
void setSwapInput(bool swap)
Returns TRUE if the input must be swaped. FALSE otherwise.
void setInputDataAccessVector(const std::vector< te::da::DataAccess * > &vecDataAccess)
Sets the output dataAccess vector.
bool m_snapGeometries
If TRUE, the geometries will be snapped before the operation is executed. Default is TRUE.
const std::vector< te::da::DataAccess * > & getOutputDataAccessVector() const
Sets the input dataAccess vector.
std::size_t m_maxCoordinates
If higher than 0, geometries will be subdivided until all the parts have less vertexes that this valu...
std::vector< te::da::DataAccess * > m_outputDataVector
Vector with output dataAccess.
std::vector< te::da::DataAccess * > m_inputDataVector
Vector with input dataAccess.
void addInputDataAccess(te::da::DataAccess *dataAccess)
Adds an input data access to the params.
void setMaxCoordinates(std::size_t maxCoordinates)
Returns the current state of the geometry subdivision.
virtual ~AbstractParameters()=default
Virtual destructor.
void addOutputDataAccess(te::da::DataAccess *dataAccess)
Adds an output data access to the params. Note that if the dataSet does not exist,...
void setOutputDataAccessVector(const std::vector< te::da::DataAccess * > &vecDataAccess)
Enables or disables geometry subdivision.
void setOperationResult(OperationResult result)
A feature is a composition of a geometry and its attributes.
Definition Feature.h:70
Abstract factory used to create Operations.
OperationFactory(const std::string &factoryKey)
Constructor.
Class used as a report logger for Operations.
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition Enums.h:42
TerraLib.
#define TEVPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition Config.h:61
Proxy configuration file for TerraView (see terraview_config.h).