All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LineStringGraph.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30  */
31 
32 /**
33  @file LineStringGraph.hpp
34 
35  @author Aline LIBRES <aline.libres@gmail.com>
36  @author Michael RABOTIN <michael.rabotin@supagro.inra.fr>
37  */
38 
39 #ifndef __OPENFLUID_LANDR_LINESTRINGGRAPH_HPP__
40 #define __OPENFLUID_LANDR_LINESTRINGGRAPH_HPP__
41 
43 #include <openfluid/dllexport.hpp>
44 
45 // for covariant return type of getEntity
47 
48 /**
49  Macro for declaration of a loop processing all entities of a graph
50  @param[in] loopid ID of the loop
51 */
52 #define DECLARE_ENTITIES_GRAPH_LOOP(loopid) \
53  std::list<openfluid::landr::LandREntity*>::iterator _M_##loopid##_it;\
54  std::list<openfluid::landr::LandREntity*> _M_##loopid##_uvect; \
55 
56 
57 /**
58  Macro for declaration of a loop processing all entities of a graph, following their OFLD_ID
59  @param[in] loopid ID of the loop
60 */
61 #define DECLARE_ENTITIES_ORDERED_LOOP(loopid) \
62  std::list<openfluid::landr::LandREntity*>::iterator _M_##loopid##_it;\
63  std::list<openfluid::landr::LandREntity*> _M_##loopid##_uvect; \
64 
65 /**
66  Macro for the beginning of a loop processing all entities of a graph
67  @param[in] loopid ID of the loop, must match declaration
68  @param[in] graph pointer to a openfluid::landr::LineStringGraph
69  @param[out] entity pointer to a openfluid::landr::LineStringEntity object, pointing to the current processed entity
70 */
71 #define BEGIN_ENTITIES_GRAPH_LOOP(loopid,graph,entity) \
72  if (graph) \
73  { \
74  _M_##loopid##_uvect = graph->getEntities();\
75  for (_M_##loopid##_it=_M_##loopid##_uvect.begin();\
76  _M_##loopid##_it != _M_##loopid##_uvect.end(); ++_M_##loopid##_it) \
77  { \
78  entity = dynamic_cast<openfluid::landr::LineStringEntity*>(*_M_##loopid##_it); \
79 
80 /**
81  Macro for the beginning of a loop processing all entities of a graph, following their OFLD_ID
82  @param[in] loopid ID of the loop, must match declaration
83  @param[in] graph pointer to a openfluid::landr::LineStringGraph
84  @param[out] entity pointer to a openfluid::landr::LineStringEntity object, pointing to the current processed entity
85 */
86 #define BEGIN_ENTITIES_ORDERED_LOOP(loopid,graph,entity) \
87  if (graph) \
88  { \
89  _M_##loopid##_uvect = graph->getOfldIdOrderedEntities();\
90  for (_M_##loopid##_it=_M_##loopid##_uvect.begin();\
91  _M_##loopid##_it != _M_##loopid##_uvect.end(); ++_M_##loopid##_it) \
92  { \
93  entity = dynamic_cast<openfluid::landr::LineStringEntity*>(*_M_##loopid##_it); \
94 
95 /**
96  Macro for the ending of a loop
97 */
98 #define END_LOOP \
99  } \
100  }
101 
102 namespace openfluid { namespace landr {
103 
104 class VectorDataset;
105 
106 /**
107  @brief A LandRGraph composed of LineStringEntities.
108 */
110 {
111 private:
112 
114 
115 protected:
116 
117  LineStringGraph();
118 
119  /**
120  @brief Creates a new LineStringGraph initialized from a core::GeoVectorValue.
121  */
123 
124  /**
125  @brief Creates a new LineStringGraph initialized from a VectorDataset.
126  */
128 
129  /**
130  @brief Adds a LandREntity into this LineStringGraph.
131  */
132  virtual void addEntity(LandREntity* Entity);
133 
134  /**
135  @brief Creates a new LineStringEntity.
136  @param Geom The geos::geom::Geometry of the new LineStringEntity to create.
137  @param OfldId The identifier of the new LineStringEntity.
138  @return A new LandREntity.
139  */
140  virtual LandREntity* createNewEntity(const geos::geom::Geometry* Geom,
141  unsigned int OfldId);
142 
143 
144 
145 
146 public:
147 
148  /**
149  @brief Creates a new LineStringGraph initialized from a core::GeoVectorValue.
150  @param Val A core::GeoVectorValue which must be composed of one or many LineStrings,
151  and each of them must contain a "OFLD_ID" attribute.
152  */
154 
155  /**
156  @brief Creates a new LineStringGraph initialized from a VectorDataset.
157  @param Vect A VectorDataset which must be composed of one or many LineStrings,
158  and each of them must contain a "OFLD_ID" attribute.
159  */
160  static LineStringGraph* create(openfluid::landr::VectorDataset& Vect);
161 
162  /**
163  @brief Creates a new LineStringGraph initialized with a list of LandREntity.
164  @param Entities A list of LandREntity which must be LineStringEntity.
165  */
166  static LineStringGraph* create(const LandRGraph::Entities_t& Entities);
167 
168  virtual ~LineStringGraph();
169 
170  /**
171  @brief Returns the type of graph.
172  */
173  LandRGraph::GraphType getType();
174 
175  /**
176  @brief Returns a LineStringEntity with OFLD_ID, or 0 if it doesn't exist.
177  */
178  LineStringEntity* entity(int OfldId);
179 
180  /**
181  @brief Removes from this LineStringGraph the LineStringEntity with OFLD_ID and its associated nodes.
182  @param OfldId The identifier.
183  */
184  virtual void removeEntity(int OfldId);
185 
186  /**
187  @brief Returns the last LineStringEntity of this LineStringGraph, according to the LineStringEntity orientations,
188  ie the one that has no down neighbour.
189  @return The last LineStringEntity or 0 if there is zero or more than one LineStringEntity whith no down neighbour.
190  */
191  LineStringEntity* lastLineStringEntity();
192 
193  /**
194  @brief Returns a vector of LineStringEntity that have no down neighbour,
195  according to the LineStringEntity orientations.
196  */
197  std::vector<LineStringEntity*> getEndLineStringEntities();
198 
199  /**
200  @brief Returns a vector of LineStringEntity that have no up neighbour,
201  according to the LineStringEntity orientations.
202  */
203  std::vector<LineStringEntity*> getStartLineStringEntities();
204 
205  /**
206  @brief Fetch the associated raster value corresponding to the LineStringEntity StartNode coordinate.
207  @param Entity The LineStringEntity to get the StartNode coordinate from.
208  @return The raster value corresponding to the LineStringEntity StartNode coordinate.
209  */
210  double getRasterValueForEntityStartNode(LineStringEntity& Entity);
211 
212  /**
213  @brief Fetch the associated raster value corresponding to the LineStringEntity EndNode coordinate.
214  @param Entity The LineStringEntity to get the EndNode coordinate from.
215  @return The raster value corresponding to the LineStringEntity EndNode coordinate.
216  */
217  double getRasterValueForEntityEndNode(LineStringEntity& Entity);
218 
219  /**
220  @brief Creates a new attribute for these LineStringGraph entities, and set for each LineStringEntity
221  this attribute value as the associated raster values corresponding to the StartNode LineStringEntity coordinates.
222  @param AttributeName The name of the attribute to create for the StartNode
223  */
224  void setAttributeFromRasterValueAtStartNode(const std::string& AttributeName);
225 
226  /**
227  @brief Creates a new attribute for these LineStringGraph entities, and set for each LineStringEntity
228  this attribute value as the associated raster values corresponding to the EndNode LineStringEntity coordinates.
229  @param AttributeName The name of the attribute to create for the EndNode
230  */
231  void setAttributeFromRasterValueAtEndNode(const std::string& AttributeName);
232 
233  /**
234  @brief Reverse a LineStringEntity orientation.
235  @param Entity The LineStringEntity to reverse.
236  */
237  void reverseLineStringEntity(LineStringEntity& Entity);
238 
239  /**
240  @brief Returns true if this LineStringGraph is an arborescence, false otherwise.
241  @details An arborescence is a graph with no loop; edges can be well directed or not.
242  */
243  bool isLineStringGraphArborescence();
244 
245  /**
246  @brief Creates a new attribute for this LineStringGraph entities, and set for each LineStringEntity
247  this attribute value as the mean of the StartNode altitude and the EndNode altitude.
248  @param AttributeName The name of the attribute to create.
249  */
250  virtual void setAttributeFromMeanRasterValues(const std::string& AttributeName);
251 
252  /**
253  @brief Merges a LineStringEntity into an other one.
254  @details The LineStringEntity to merge is deleted.
255  @param Entity An existent LineStringEntity.
256  @param EntityToMerge The LineStringEntity which will be merged into Entity and will be deleted.
257  */
258  void mergeLineStringEntities(LineStringEntity& Entity,
259  LineStringEntity& EntityToMerge);
260 
261  /**
262  @brief Gets a map of small LineStringEntity under length threshold
263  @param MinLength The length threshold (in map units).
264  @param rmDangle : if true, get also dangles under the threshold.
265  @param HighDegree : if true, do not get the if StartNode and EndNode of this LineStringEntitiy are Degree>=3.
266  @return a multimap of LineStringEntity with key is the length of each LineStringEntity.
267  */
268  std::multimap<double,LineStringEntity*> getLineStringEntitiesByMinLength(double MinLength,
269  bool rmDangle=true,
270  bool HighDegree=true);
271 
272  /**
273  @brief Set the orientation of the LineStringGraph with outlet identification by OFLD_ID identifier.
274  Only for LineStringGraph of arborescence type
275  @param OfldId The identifier of the outlet.
276  */
277  void setOrientationByOfldId(int OfldId);
278 
279  /**
280  @brief Merges the entities of this LineStringGraph under length threshold.
281  @param MinLength The length threshold (in map units).
282  @param rmDangle if true, remove also dangles under the threshold, default is true.
283  */
284  void mergeLineStringEntitiesByMinLength(double MinLength,bool rmDangle=true);
285 
286 };
287 
288 } } // namespace landr, openfluid
289 
290 #endif /* __OPENFLUID_LANDR_LINESTRINGGRAPH_HPP__ */
Definition: GeoVectorValue.hpp:52
Interface for a graph composed of LandREntity.
Definition: LandRGraph.hpp:78
Interface for managing Vector Data format.
Definition: VectorDataset.hpp:64
std::list< LandREntity * > Entities_t
Definition: LandRGraph.hpp:87
Interface for a landscape representation element.
Definition: LandREntity.hpp:63
A LandRGraph composed of LineStringEntities.
Definition: LineStringGraph.hpp:109
#define OPENFLUID_API
Definition: dllexport.hpp:87
A LandREntity representing a geos::geom::LineString.
Definition: LineStringEntity.hpp:57
GraphType
Definition: LandRGraph.hpp:82