00001 /* 00002 00003 This file is part of OpenFLUID software 00004 Copyright(c) 2007, INRA - Montpellier SupAgro 00005 00006 00007 == GNU General Public License Usage == 00008 00009 OpenFLUID is free software: you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation, either version 3 of the License, or 00012 (at your option) any later version. 00013 00014 OpenFLUID is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>. 00021 00022 00023 == Other Usage == 00024 00025 Other Usage means a use of OpenFLUID that is inconsistent with the GPL 00026 license, and requires a written agreement between You and INRA. 00027 Licensees for Other Usage of OpenFLUID may use this file in accordance 00028 with the terms contained in the written agreement between You and INRA. 00029 00030 */ 00031 00032 /** 00033 \file LineStringGraph.hpp 00034 \brief Header of ... 00035 00036 \author Aline LIBRES <aline.libres@gmail.com> 00037 */ 00038 00039 #ifndef LINESTRINGGRAPH_HPP_ 00040 #define LINESTRINGGRAPH_HPP_ 00041 00042 #include <openfluid/landr/LandRGraph.hpp> 00043 #include <openfluid/dllexport.hpp> 00044 00045 // for covariant return type of getEntity 00046 #include <openfluid/landr/LineStringEntity.hpp> 00047 00048 /** 00049 Macro for declaration of a loop processing all entities of a graph 00050 @param[in] loopid ID of the loop 00051 */ 00052 #define DECLARE_ENTITIES_GRAPH_LOOP(loopid) \ 00053 std::list<openfluid::landr::LandREntity*>::iterator _M_##loopid##_it;\ 00054 std::list<openfluid::landr::LandREntity*> _M_##loopid##_uvect; \ 00055 00056 00057 /** 00058 Macro for declaration of a loop processing all entities of a graph, following their OFLD_ID 00059 @param[in] loopid ID of the loop 00060 */ 00061 #define DECLARE_ENTITIES_ORDERED_LOOP(loopid) \ 00062 std::list<openfluid::landr::LandREntity*>::iterator _M_##loopid##_it;\ 00063 std::list<openfluid::landr::LandREntity*> _M_##loopid##_uvect; \ 00064 00065 /** 00066 Macro for the beginning of a loop processing all entities of a graph 00067 @param[in] loopid ID of the loop, must match declaration 00068 @param[in] graph pointer to a openfluid::landr::LineStringGraph 00069 @param[out] entity pointer to a openfluid::landr::LineStringEntity object, pointing to the current processed entity 00070 */ 00071 #define BEGIN_ENTITIES_GRAPH_LOOP(loopid,graph,entity) \ 00072 if (graph) \ 00073 { \ 00074 _M_##loopid##_uvect = graph->getEntities();\ 00075 for (_M_##loopid##_it=_M_##loopid##_uvect.begin(); _M_##loopid##_it != _M_##loopid##_uvect.end(); ++_M_##loopid##_it) \ 00076 { \ 00077 entity = dynamic_cast<openfluid::landr::LineStringEntity*>(*_M_##loopid##_it); \ 00078 00079 /** 00080 Macro for the beginning of a loop processing all entities of a graph, following their OFLD_ID 00081 @param[in] loopid ID of the loop, must match declaration 00082 @param[in] graph pointer to a openfluid::landr::LineStringGraph 00083 @param[out] entity pointer to a openfluid::landr::LineStringEntity object, pointing to the current processed entity 00084 */ 00085 #define BEGIN_ENTITIES_ORDERED_LOOP(loopid,graph,entity) \ 00086 if (graph) \ 00087 { \ 00088 _M_##loopid##_uvect = graph->getOfldIdOrderedEntities();\ 00089 for (_M_##loopid##_it=_M_##loopid##_uvect.begin(); _M_##loopid##_it != _M_##loopid##_uvect.end(); ++_M_##loopid##_it) \ 00090 { \ 00091 entity = dynamic_cast<openfluid::landr::LineStringEntity*>(*_M_##loopid##_it); \ 00092 00093 /** 00094 Macro for the ending of a loop 00095 */ 00096 #define END_LOOP \ 00097 } \ 00098 } 00099 00100 namespace openfluid { namespace landr { 00101 00102 class VectorDataset; 00103 00104 /** 00105 @brief A LandRGraph composed of LineStringEntities. 00106 */ 00107 class DLLEXPORT LineStringGraph: public LandRGraph 00108 { 00109 private: 00110 00111 LineStringGraph(LineStringGraph& Other); 00112 00113 protected: 00114 00115 LineStringGraph(); 00116 00117 /** 00118 @brief Creates a new LineStringGraph initialized from a core::GeoVectorValue. 00119 */ 00120 LineStringGraph(openfluid::core::GeoVectorValue& Val); 00121 00122 /** 00123 @brief Creates a new LineStringGraph initialized from a VectorDataset. 00124 */ 00125 LineStringGraph(openfluid::landr::VectorDataset& Vect); 00126 00127 /** 00128 @brief Adds a LandREntity into this LineStringGraph. 00129 */ 00130 virtual void addEntity(LandREntity* Entity); 00131 00132 /** 00133 @brief Creates a new LineStringEntity. 00134 @param Geom The geos::geom::Geometry of the new LineStringEntity to create. 00135 @param OfldId The identifier of the new LineStringEntity. 00136 @return A new LandREntity. 00137 */ 00138 virtual LandREntity* getNewEntity(const geos::geom::Geometry* Geom, 00139 unsigned int OfldId); 00140 00141 00142 00143 00144 public: 00145 00146 /** 00147 @brief Creates a new LineStringGraph initialized from a core::GeoVectorValue. 00148 @param Val A core::GeoVectorValue which must be composed of one or many LineStrings, and each of them must contain a "OFLD_ID" attribute. 00149 */ 00150 static LineStringGraph* create(openfluid::core::GeoVectorValue& Val); 00151 00152 /** 00153 @brief Creates a new LineStringGraph initialized from a VectorDataset. 00154 @param Vect A VectorDataset which must be composed of one or many LineStrings, and each of them must contain a "OFLD_ID" attribute. 00155 */ 00156 static LineStringGraph* create(openfluid::landr::VectorDataset& Vect); 00157 00158 /** 00159 @brief Creates a new LineStringGraph initialized with a list of LandREntity. 00160 @param Entities A list of LandREntity which must be LineStringEntity. 00161 */ 00162 static LineStringGraph* create(const LandRGraph::Entities_t& Entities); 00163 00164 virtual ~LineStringGraph(); 00165 00166 /** 00167 @brief Returns the type of graph. 00168 */ 00169 LandRGraph::GraphType getType(); 00170 00171 /** 00172 @brief Returns a LineStringEntity with OFLD_ID, or 0 if it doesn't exist. 00173 */ 00174 LineStringEntity* getEntity(int OfldId); 00175 00176 /** 00177 @brief Removes from this LineStringGraph the LineStringEntity with OFLD_ID and its associated nodes. 00178 @param OfldId The identifier. 00179 */ 00180 virtual void removeEntity(int OfldId); 00181 00182 /** 00183 @brief Returns the last LineStringEntity of this LineStringGraph, according to the LineStringEntity orientations, 00184 ie the one that has no down neighbour. 00185 @return The last LineStringEntity or 0 if there is zero or more than one LineStringEntity whith no down neighbour. 00186 */ 00187 LineStringEntity* getLastLineStringEntity(); 00188 00189 /** 00190 @brief Returns a vector of LineStringEntity that have no down neighbour, according to the LineStringEntity orientations. 00191 */ 00192 std::vector<LineStringEntity*> getEndLineStringEntities(); 00193 00194 /** 00195 @brief Returns a vector of LineStringEntity that have no up neighbour, according to the LineStringEntity orientations. 00196 */ 00197 std::vector<LineStringEntity*> getStartLineStringEntities(); 00198 00199 /** 00200 @brief Fetch the associated raster value corresponding to the LineStringEntity StartNode coordinate. 00201 @param Entity The LineStringEntity to get the StartNode coordinate from. 00202 @return The raster value corresponding to the LineStringEntity StartNode coordinate. 00203 */ 00204 float* getRasterValueForEntityStartNode(LineStringEntity& Entity); 00205 00206 /** 00207 @brief Fetch the associated raster value corresponding to the LineStringEntity EndNode coordinate. 00208 @param Entity The LineStringEntity to get the EndNode coordinate from. 00209 @return The raster value corresponding to the LineStringEntity EndNode coordinate. 00210 */ 00211 float* getRasterValueForEntityEndNode(LineStringEntity& Entity); 00212 00213 /** 00214 @brief Creates a new attribute for these LineStringGraph entities, and set for each LineStringEntity 00215 this attribute value as the associated raster values corresponding to the StartNode LineStringEntity coordinates. 00216 @param AttributeName The name of the attribute to create for the StartNode 00217 */ 00218 void setAttributeFromRasterValueAtStartNode(const std::string& AttributeName); 00219 00220 /** 00221 @brief Creates a new attribute for these LineStringGraph entities, and set for each LineStringEntity 00222 this attribute value as the associated raster values corresponding to the EndNode LineStringEntity coordinates. 00223 @param AttributeName The name of the attribute to create for the EndNode 00224 */ 00225 void setAttributeFromRasterValueAtEndNode(const std::string& AttributeName); 00226 00227 /** 00228 @brief Reverse a LineStringEntity orientation. 00229 @param Entity The LineStringEntity to reverse. 00230 */ 00231 void reverseLineStringEntity(LineStringEntity& Entity); 00232 00233 /** 00234 @brief Returns true if this LineStringGraph is an arborescence, false otherwise. 00235 @details An arborescence is a graph with no loop; edges can be well directed or not. 00236 */ 00237 bool isLineStringGraphArborescence(); 00238 00239 /** 00240 @brief Creates a new attribute for this LineStringGraph entities, and set for each LineStringEntity 00241 this attribute value as the mean of the StartNode altitude and the EndNode altitude. 00242 @param AttributeName The name of the attribute to create. 00243 */ 00244 virtual void setAttributeFromMeanRasterValues(const std::string& AttributeName); 00245 00246 /** 00247 @brief Merges a LineStringEntity into an other one. 00248 @details The LineStringEntity to merge is deleted. 00249 @param Entity An existent LineStringEntity. 00250 @param EntityToMerge The LineStringEntity which will be merged into Entity and will be deleted. 00251 */ 00252 void mergeLineStringEntities(LineStringEntity& Entity, 00253 LineStringEntity& EntityToMerge); 00254 00255 00256 /** 00257 @brief Gets a map of small LineStringEntity under length threshold 00258 @param MinLength The length threshold (in map units). 00259 @param rmDangle : if true, get also dangles under the threshold. 00260 @param HighDegree : if true, do not get the if StartNode and EndNode of this LineStringEntitiy are Degree>=3. 00261 @return a multimap of LineStringEntity with key is the length of each LineStringEntity. 00262 */ 00263 std::multimap<double, LineStringEntity*> getLineStringEntitiesByMinLength(double MinLength, 00264 bool rmDangle=true, 00265 bool HighDegree=true); 00266 00267 /** 00268 @brief Set the orientation of the LineStringGraph with outlet identification by OFLD_ID identifier. 00269 Only for LineStringGraph of arborescence type 00270 @param OfldId The identifier of the outlet. 00271 */ 00272 void setOrientationByOfldId(int OfldId); 00273 00274 }; 00275 00276 } } // namespace landr, openfluid 00277 00278 #endif /* LINESTRINGGRAPH_HPP_ */