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 PolygonEntity.hpp 00034 \brief Header of ... 00035 00036 \author Aline LIBRES <aline.libres@gmail.com> 00037 */ 00038 00039 #ifndef POLYGONENTITY_HPP_ 00040 #define POLYGONENTITY_HPP_ 00041 00042 #include <openfluid/landr/LandREntity.hpp> 00043 #include <openfluid/landr/LandRTools.hpp> 00044 #include <openfluid/landr/VectorDataset.hpp> 00045 #include <openfluid/dllexport.hpp> 00046 #include <vector> 00047 00048 namespace geos { namespace geom { 00049 class Polygon; 00050 class LineString; 00051 } } 00052 00053 namespace openfluid { namespace landr { 00054 00055 class PolygonEdge; 00056 class LineStringGraph; 00057 class LineStringEntity; 00058 00059 00060 /** 00061 @brief A LandREntity representing a geos::geom::Polygon. 00062 @details A PolygonEntity has at least a PolygonEdge, all edges representing the Polygon exterior ring. 00063 */ 00064 class DLLEXPORT PolygonEntity: public LandREntity 00065 { 00066 private: 00067 00068 /** 00069 @brief The geos::geom::Polygon associated to this PolygonEntity. 00070 */ 00071 const geos::geom::Polygon* mp_Polygon; 00072 00073 PolygonEntity(); 00074 PolygonEntity(const PolygonEntity&); 00075 00076 public: 00077 00078 /** 00079 @brief A map of the PolygonEntity neighbours and their shared PolygonEdge to this PolygonEntity. 00080 */ 00081 typedef std::map<PolygonEntity*, std::vector<PolygonEdge*> > NeighboursMap_t; 00082 00083 /** 00084 @brief A map of the LineStringEntity neighbours and the PolygonEdge in contact with this PolygonEntity. 00085 */ 00086 typedef std::map<LineStringEntity*, PolygonEdge*> LineStringNeighboursMap_t; 00087 00088 /** 00089 @brief A Map of neighbours of PolygonEntity type and the related vector of PolygonEdge that are between this PolygonEntity and his neighbours. 00090 */ 00091 NeighboursMap_t* mp_NeighboursMap; 00092 00093 /** 00094 @brief A Map of neighbours of LineStringEntity type and the related PolygonEdge that is between this PolygonEntity and his neighbours, if exist. 00095 */ 00096 LineStringNeighboursMap_t* mp_LineStringNeighboursMap; 00097 00098 /** 00099 @brief A vector of the PolygonEdge of this PolygonEntity. 00100 */ 00101 std::vector<PolygonEdge*> m_PolyEdges; 00102 00103 /** 00104 @brief Create a new PolygonEntity. 00105 @details Takes ownership of NewPolygon. 00106 @param NewPolygon The geos::geom::Geometry of this new PolygonEntity. 00107 @param OfldId The identifier of this new PolygonEntity. 00108 @throw base::OFException if NewPolygon is not a geos::geom::Polygon or is not a valid geometry. 00109 */ 00110 PolygonEntity(const geos::geom::Geometry* NewPolygon, unsigned int OfldId); 00111 00112 virtual ~PolygonEntity(); 00113 00114 /** 00115 @brief Clone a new PolygonEntity from this PolygonEntity. 00116 @attention Doesn't deep-copy m_PolyEdges nor neighbours. 00117 */ 00118 PolygonEntity* clone(); 00119 00120 /** 00121 @brief Returns the geos::geom::Polygon associated to this PolygonEntity. 00122 */ 00123 const geos::geom::Polygon* getPolygon() const; 00124 00125 /** 00126 @brief Adds a PolygonEdge to this PolygonEntity. 00127 */ 00128 void addEdge(PolygonEdge& Edge); 00129 00130 /** 00131 @brief Removes a PolygonEdge to this PolygonEntity. 00132 @attention Also delete input parameter Edge. 00133 */ 00134 void removeEdge(PolygonEdge* Edge); 00135 00136 /** 00137 @brief Returns a vector of geos::geom::LineString representing the linear intersections between two PolygonEntity. 00138 @param Other The PolygonEntity to compare to. 00139 @return A vector of new allocated geos::geom::LineString representing the linear intersections (eventually merged) between this PolygonEntity and Other. 00140 */ 00141 std::vector<geos::geom::LineString*> getLineIntersectionsWith(PolygonEntity& Other); 00142 00143 /** 00144 @brief Returns the PolygonEdge containing Segment. 00145 @param Segment The geos::geom::LineString to find. 00146 @return The PolygonEdge of this PolygonEntity containing the input geos::geom::LineString, 00147 or 0 if not found. 00148 */ 00149 PolygonEdge* findEdgeLineIntersectingWith(geos::geom::LineString& Segment); 00150 00151 /** 00152 @brief Returns a map of this PolygonEntity neighbours with for each a vector of the shared PolygonEdge. 00153 */ 00154 const NeighboursMap_t* getNeighboursAndEdges(); 00155 00156 /** 00157 @brief Returns a vector of the OFLD_ID of this PolygonEntity neighbours, ascending ordered. 00158 */ 00159 std::vector<int> getOrderedNeighbourOfldIds(); 00160 00161 /** 00162 @brief Returns a multimap of the length of the shared boundary of each neighbour of this PolygonEntity and each PolygonEntity neighbour, 00163 ascending ordered by length shared boundary (shortest to longest boundary). 00164 */ 00165 std::multimap<double,PolygonEntity*> getOrderedNeighboursByLengthBoundary(); 00166 00167 /** 00168 @brief Check if this PolygonEntity is complete, that is if all PolygonEdge of this PolygonEntity, 00169 merged in a LineString, equals this PolygonEntity polygon exterior ring. 00170 @return True if complete, false otherwise. 00171 */ 00172 bool isComplete(); 00173 00174 /** 00175 @brief Gets the PolygonEdge of this PolygonEntity that are shared with Other. 00176 @param Other A PolygonEntity. 00177 @return A vector of PolygonEdge. 00178 */ 00179 std::vector<PolygonEdge*> getCommonEdgesWith(PolygonEntity& Other); 00180 00181 /** 00182 @brief Gets the PolygonEntity which share the same Edge with the current PolygonEntity. 00183 @param Edge A PolygonEdge. 00184 @return A vector a PolygonEntity. 00185 */ 00186 PolygonEntity * getNeighbourWithCommonEdge(PolygonEdge * Edge); 00187 00188 /** 00189 @brief Gets the boundary of this PolygonEntity polygon, with a buffer of BufferDistance. 00190 @param BufferDistance The buffer distance. 00191 @return A geos::geom::Geometry representing the buffered boundaries of this PolygonEntity. 00192 */ 00193 geos::geom::Geometry* getBufferedBoundary(double BufferDistance); 00194 00195 /** 00196 @brief Computes the neighbours of this PolygonEntity. 00197 @details A neighbour is another PolygonEntity that shares at least a PolygonEdge with this PolygonEntity. 00198 */ 00199 void computeNeighbours(); 00200 00201 /** 00202 @brief Computes the relations between this PolygonEntity and the LineStringEntity of an input LineStringGraph. 00203 @details A LineStringEntity is considered as a neighbour if it lies within the buffer of this PolygonEntity polygon boundary. 00204 @param Graph The LineStringGraph to compare to. 00205 @param Relation The Relationship to use for comparison. 00206 @param BufferDistance The distance below which we consider that two elements are related. 00207 @param ContactLength Min Length of the LineString in intersection with polygon Buffered Boundaries to be taking acccount (only for LandRTools::TOUCHES RelationShip) 00208 */ 00209 void computeLineStringNeighbours(LineStringGraph& Graph, 00210 LandRTools::Relationship Relation, 00211 double BufferDistance, 00212 double ContactLength=0); 00213 00214 /** 00215 @brief Computes the relations between this PolygonEntity and its PolygonEntities Neighbours by using 00216 the LineStringEntity of an input LineStringGraph which are considered as barriers. 00217 @details A barrier between two PolygonEntity will avoid to considered them as neighbours. 00218 @details A LineStringEntity is considered as a barrier if it lies within the buffer of this PolygonEntity polygon boundary. 00219 @param Graph The LineStringGraph to compare to. 00220 @param Relation The Relationship to use for comparison, the LandRTools::Relationship INTERSECTS is not allowed. 00221 @param BufferDistance The distance below which we consider that two elements are related. 00222 @param ContactLength Min Length of the LineString in intersection with polygon Buffered Boundaries to be taking acccount (only for LandRTools::TOUCHES RelationShip) 00223 */ 00224 void computeNeighboursWithBarriers(LineStringGraph& Graph, 00225 LandRTools::Relationship Relation, 00226 double BufferDistance, 00227 double ContactLength=0); 00228 00229 /** 00230 @brief Return the a map of the LineStringEntity neighbours of this PolygonEntity. 00231 */ 00232 LineStringNeighboursMap_t* getLineStringNeighbours(); 00233 00234 00235 /** 00236 @brief Merge a PolygonEdge into an other one. 00237 @param Edge An existent PolygonEdge. 00238 @param EdgeToMerge Another PolygonEdge to merge. 00239 @return A geos::geom:LineString which have the geometry of the merged PolygonEdge. 00240 */ 00241 geos::geom::LineString* mergeEdges(PolygonEdge* Edge, 00242 PolygonEdge* EdgeToMerge); 00243 00244 /** 00245 @brief Find the LandREntity neighbour of this PolygonEntity by using 00246 a line VectorDataset which indicates the neighbour relationship 00247 \verbatim 00248 ************** Following the directions of the 00249 * |-*--> * lines of the VectorDataset, 00250 * 1 * 3 * the neighbour of PolygonEntity 2 is 00251 * * * the PolygonEntity 1 and the neighbour 00252 * ^ ******** of PolygonEntity 1 is the PolygonEntity 00253 * | * 3. If a line of the VectorDataset crosses 00254 ******* a LineStringNeighbour of the PolygonEntity, 00255 * | * it becomes the neighbour :e.g, if LineStringNeighbour 00256 * - * exists between PolygonEntity 1 and 2, the neighbour 00257 * 2 * of PolygonEntity becomes this LineStringNeighbour. 00258 * * Do NOT work for PointEntity topology 00259 ******* 00260 \endverbatim 00261 @param LineTopology A line VectorDataset 00262 @return A openfluid::landr:landREntity or an empty entity if not found. 00263 */ 00264 LandREntity *getNeighbourByLineTopology(VectorDataset LineTopology); 00265 00266 00267 00268 }; 00269 00270 } } // namespace landr, openfluid 00271 #endif /* POLYGONENTITY_HPP_ */