GEOS
3.6.2
|
00001 /********************************************************************** 00002 * 00003 * GEOS - Geometry Engine Open Source 00004 * http://geos.osgeo.org 00005 * 00006 * Copyright (C) 2013 Sandro Santilli <strk@keybit.net> 00007 * 00008 * This is free software; you can redistribute and/or modify it under 00009 * the terms of the GNU Lesser General Public Licence as published 00010 * by the Free Software Foundation. 00011 * See the COPYING file for more information. 00012 * 00013 ********************************************************************** 00014 * 00015 * Last port: algorithm/Centroid.java r728 (JTS-0.13+) 00016 * 00017 **********************************************************************/ 00018 00019 #ifndef GEOS_ALGORITHM_CENTROID_H 00020 #define GEOS_ALGORITHM_CENTROID_H 00021 00022 #include <geos/export.h> 00023 #include <geos/geom/Coordinate.h> // for composition 00024 #include <memory> // for std::auto_ptr 00025 00026 // Forward declarations 00027 namespace geos { 00028 namespace geom { 00029 class Geometry; 00030 class Polygon; 00031 class CoordinateSequence; 00032 } 00033 } 00034 00035 00036 namespace geos { 00037 namespace algorithm { // geos::algorithm 00038 00061 class GEOS_DLL Centroid { 00062 00063 public: 00064 00074 static bool getCentroid(const geom::Geometry& geom, geom::Coordinate& cent); 00075 00079 Centroid(const geom::Geometry& geom) 00080 : 00081 areasum2(0.0), 00082 totalLength(0.0), 00083 ptCount(0) 00084 { 00085 add(geom); 00086 } 00087 00096 bool getCentroid(geom::Coordinate& cent) const; 00097 00098 private: 00099 00100 std::auto_ptr<geom::Coordinate> areaBasePt; 00101 geom::Coordinate triangleCent3; 00102 geom::Coordinate cg3; 00103 geom::Coordinate lineCentSum; 00104 geom::Coordinate ptCentSum; 00105 double areasum2; 00106 double totalLength; 00107 int ptCount; 00108 00114 void add(const geom::Geometry& geom); 00115 00116 void setBasePoint(const geom::Coordinate& basePt); 00117 00118 void add(const geom::Polygon& poly); 00119 00120 void addShell(const geom::CoordinateSequence& pts); 00121 00122 void addHole(const geom::CoordinateSequence& pts); 00123 00124 void addTriangle(const geom::Coordinate& p0, const geom::Coordinate& p1, const geom::Coordinate& p2, bool isPositiveArea); 00125 00131 static void centroid3(const geom::Coordinate& p1, const geom::Coordinate& p2, const geom::Coordinate& p3, geom::Coordinate& c ); 00132 00137 static double area2(const geom::Coordinate& p1, const geom::Coordinate& p2, const geom::Coordinate& p3 ); 00138 00145 void addLineSegments(const geom::CoordinateSequence& pts); 00146 00151 void addPoint(const geom::Coordinate& pt); 00152 }; 00153 00154 } // namespace geos::algorithm 00155 } // namespace geos 00156 00157 #endif // GEOS_ALGORITHM_CENTROID_H