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 { 00101 namespace landr { 00102 00103 class VectorDataset; 00104 00105 /** 00106 * @brief A LandRGraph composed of LineStringEntities. 00107 */ 00108 class DLLEXPORT LineStringGraph: public LandRGraph 00109 { 00110 private: 00111 00112 LineStringGraph(LineStringGraph& Other); 00113 00114 protected: 00115 00116 LineStringGraph(); 00117 00118 /** 00119 * @brief Creates a new LineStringGraph initialized from a core::GeoVectorValue. 00120 */ 00121 LineStringGraph(openfluid::core::GeoVectorValue& Val); 00122 00123 /** 00124 * @brief Creates a new LineStringGraph initialized from a VectorDataset. 00125 */ 00126 LineStringGraph(openfluid::landr::VectorDataset& Vect); 00127 00128 /** 00129 * @brief Adds a LandREntity into this LineStringGraph. 00130 */ 00131 virtual void addEntity(LandREntity* Entity); 00132 00133 /** 00134 * @brief Creates a new LineStringEntity. 00135 * 00136 * @param Geom The geos::geom::Geometry of the new LineStringEntity to create. 00137 * @param OfldId The identifier of the new LineStringEntity. 00138 * 00139 * @return A new LandREntity. 00140 */ 00141 virtual LandREntity* getNewEntity(const geos::geom::Geometry* Geom, 00142 unsigned int OfldId); 00143 00144 00145 00146 00147 public: 00148 00149 /** 00150 * @brief Creates a new LineStringGraph initialized from a core::GeoVectorValue. 00151 * @param Val A core::GeoVectorValue which must be composed of one or many LineStrings, and each of them must contain a "OFLD_ID" attribute. 00152 */ 00153 static LineStringGraph* create(openfluid::core::GeoVectorValue& Val); 00154 00155 /** 00156 * @brief Creates a new LineStringGraph initialized from a VectorDataset. 00157 * @param Vect A VectorDataset which must be composed of one or many LineStrings, and each of them must contain a "OFLD_ID" attribute. 00158 */ 00159 static LineStringGraph* create(openfluid::landr::VectorDataset& Vect); 00160 00161 /** 00162 * @brief Creates a new LineStringGraph initialized with a list of LandREntity. 00163 * @param Entities A list of LandREntity which must be LineStringEntity. 00164 */ 00165 static LineStringGraph* create(const LandRGraph::Entities_t& Entities); 00166 00167 virtual ~LineStringGraph(); 00168 00169 /** 00170 * @brief Returns the type of graph. 00171 */ 00172 LandRGraph::GraphType getType(); 00173 00174 /** 00175 * @brief Returns a LineStringEntity with OFLD_ID, or 0 if it doesn't exist. 00176 */ 00177 LineStringEntity* getEntity(int OfldId); 00178 00179 /** 00180 * @brief Removes from this LineStringGraph the LineStringEntity with OFLD_ID and its associated nodes. 00181 * @param OfldId The identifier. 00182 */ 00183 virtual void removeEntity(int OfldId); 00184 00185 /** 00186 * @brief Returns the last LineStringEntity of this LineStringGraph, according to the LineStringEntity orientations, 00187 * ie the one that has no down neighbour. 00188 * 00189 * @return The last LineStringEntity or 0 if there is zero or more than one LineStringEntity whith no down neighbour. 00190 */ 00191 LineStringEntity* getLastLineStringEntity(); 00192 00193 /** 00194 * @brief Returns a vector of LineStringEntity that have no down neighbour, according to the LineStringEntity orientations. 00195 */ 00196 std::vector<LineStringEntity*> getEndLineStringEntities(); 00197 00198 /** 00199 * @brief Returns a vector of LineStringEntity that have no up neighbour, according to the LineStringEntity orientations. 00200 */ 00201 std::vector<LineStringEntity*> getStartLineStringEntities(); 00202 00203 /** 00204 * @brief Fetch the associated raster value corresponding to the LineStringEntity StartNode coordinate. 00205 * 00206 * @param Entity The LineStringEntity to get the StartNode coordinate from. 00207 * @return The raster value corresponding to the LineStringEntity StartNode coordinate. 00208 */ 00209 float* getRasterValueForEntityStartNode(LineStringEntity& Entity); 00210 00211 /** 00212 * @brief Fetch the associated raster value corresponding to the LineStringEntity EndNode coordinate. 00213 * 00214 * @param Entity The LineStringEntity to get the EndNode coordinate from. 00215 * @return The raster value corresponding to the LineStringEntity EndNode coordinate. 00216 */ 00217 float* getRasterValueForEntityEndNode(LineStringEntity& Entity); 00218 00219 /** 00220 * @brief Creates a new attribute for these LineStringGraph entities, and set for each LineStringEntity 00221 * this attribute value as the associated raster values corresponding to the StartNode LineStringEntity coordinates. 00222 * 00223 * @param AttributeName The name of the attribute to create for the StartNode 00224 */ 00225 void setAttributeFromRasterValueAtStartNode(const std::string& AttributeName); 00226 00227 /** 00228 * @brief Creates a new attribute for these LineStringGraph entities, and set for each LineStringEntity 00229 * this attribute value as the associated raster values corresponding to the EndNode LineStringEntity coordinates. 00230 * 00231 * @param AttributeName The name of the attribute to create for the EndNode 00232 */ 00233 void setAttributeFromRasterValueAtEndNode(const std::string& AttributeName); 00234 00235 /** 00236 * @brief Reverse a LineStringEntity orientation. 00237 * 00238 * @param Entity The LineStringEntity to reverse. 00239 */ 00240 void reverseLineStringEntity(LineStringEntity& Entity); 00241 00242 /** 00243 * @brief Returns true if this LineStringGraph is an arborescence, false otherwise. 00244 * @details An arborescence is a graph with no loop; edges can be well directed or not. 00245 */ 00246 bool isLineStringGraphArborescence(); 00247 00248 /** 00249 * @brief Creates a new attribute for this LineStringGraph entities, and set for each LineStringEntity 00250 * this attribute value as the mean of the StartNode altitude and the EndNode altitude. 00251 * @param AttributeName The name of the attribute to create. 00252 */ 00253 virtual void setAttributeFromMeanRasterValues(const std::string& AttributeName); 00254 00255 /** 00256 * @brief Creates a new attribute for this LineStringGraph entities, and set for each LineStringEntity 00257 * this attribute value as the vector value corresponding to the Vector Entity Geometry. 00258 * 00259 * @param AttributeName The name of the attribute to create. 00260 * @param Vector The Name of the core::GeoVectorValue. 00261 * @param Column The column of the core::GeoVectorValue to upload. 00262 * @param Thresh The threshold of minimum distance between the core::GeoVectorValue geometry and the LineStringGraph geometry. 00263 */ 00264 virtual void setAttributeFromVectorLocation(const std::string& AttributeName, openfluid::core::GeoVectorValue& Vector, 00265 const std::string& Column,double Thresh=0.0001); 00266 00267 /** 00268 * @brief Creates a new attribute for this LineStringGraph entities, and set for each LineStringEntity. 00269 * this attribute value as the vector value corresponding to the Vector Entity Geometry 00270 * 00271 * @param AttributeName The name of the attribute to create. 00272 * @param Vector The Name of the VectorDataset. 00273 * @param Column The column of the VectorDataset to upload. 00274 * @param Thresh The threshold of minimum distance between the VectorDataset geometry and the LineStringGraph geometry. 00275 */ 00276 virtual void setAttributeFromVectorLocation(const std::string& AttributeName, openfluid::landr::VectorDataset& Vector, 00277 const std::string& Column,double Thresh=0.0001); 00278 00279 /** 00280 * @brief Merges a LineStringEntity into an other one. 00281 * @details The LineStringEntity to merge is deleted. 00282 * 00283 * @param Entity An existent LineStringEntity. 00284 * @param EntityToMerge The LineStringEntity which will be merged into Entity and will be deleted. 00285 */ 00286 void mergeLineStringEntities(LineStringEntity& Entity, LineStringEntity& EntityToMerge); 00287 00288 00289 /** 00290 * @brief Gets a map of small LineStringEntity under length threshold and only if the LineStringEntity is 00291 * not between two confluences. 00292 * 00293 * @param MinLength The length threshold (in map units). 00294 * @param rmDangle : if true, get also dangles under the threshold. 00295 * @return a multimap of LineStringEntity with key is the length of each LineStringEntity. 00296 */ 00297 std::multimap<double, LineStringEntity*> getLineStringEntitiesByMinLength(double MinLength,bool rmDangle=true); 00298 00299 00300 00301 00302 00303 }; 00304 00305 } // namespace landr 00306 } /* namespace openfluid */ 00307 00308 #endif /* LINESTRINGGRAPH_HPP_ */