GEOS
3.4.2
|
00001 /********************************************************************** 00002 * 00003 * GEOS - Geometry Engine Open Source 00004 * http://geos.osgeo.org 00005 * 00006 * Copyright (C) 2005-2006 Refractions Research Inc. 00007 * Copyright (C) 2001-2002 Vivid Solutions Inc. 00008 * 00009 * This is free software; you can redistribute and/or modify it under 00010 * the terms of the GNU Lesser General Public Licence as published 00011 * by the Free Software Foundation. 00012 * See the COPYING file for more information. 00013 * 00014 ********************************************************************** 00015 * 00016 * Last port: algorithm/CentroidArea.java r612 00017 * 00018 **********************************************************************/ 00019 00020 #ifndef GEOS_ALGORITHM_CENTROIDAREA_H 00021 #define GEOS_ALGORITHM_CENTROIDAREA_H 00022 00023 00024 #include <geos/export.h> 00025 #include <geos/geom/Coordinate.h> 00026 00027 // Forward declarations 00028 namespace geos { 00029 namespace geom { 00030 class CoordinateSequence; 00031 class Geometry; 00032 class Polygon; 00033 } 00034 } 00035 00036 namespace geos { 00037 namespace algorithm { // geos::algorithm 00038 00060 class GEOS_DLL CentroidArea { 00061 00062 public: 00063 00064 CentroidArea() 00065 : 00066 basePt(0.0, 0.0), 00067 areasum2(0.0), 00068 totalLength(0.0) 00069 {} 00070 00071 ~CentroidArea() {} 00072 00079 void add(const geom::Geometry *geom); 00080 00087 void add(const geom::CoordinateSequence *ring); 00088 00089 // TODO: deprecate 00090 geom::Coordinate* getCentroid() const; 00091 00093 bool getCentroid(geom::Coordinate& ret) const; 00094 00095 private: 00096 00098 geom::Coordinate basePt; 00099 00100 // temporary variable to hold centroid of triangle 00101 geom::Coordinate triangleCent3; 00102 00104 double areasum2; 00105 00107 geom::Coordinate cg3; 00108 00109 // data for linear centroid computation, if needed 00110 geom::Coordinate centSum; 00111 double totalLength; 00112 00113 void setBasePoint(const geom::Coordinate &newbasePt); 00114 00115 void add(const geom::Polygon *poly); 00116 00117 void addShell(const geom::CoordinateSequence *pts); 00118 00119 void addHole(const geom::CoordinateSequence *pts); 00120 00121 void addTriangle(const geom::Coordinate &p0, const geom::Coordinate &p1, 00122 const geom::Coordinate &p2,bool isPositiveArea); 00123 00124 static void centroid3(const geom::Coordinate &p1, const geom::Coordinate &p2, 00125 const geom::Coordinate &p3, geom::Coordinate &c); 00126 00127 static double area2(const geom::Coordinate &p1, const geom::Coordinate &p2, 00128 const geom::Coordinate &p3); 00129 00139 void addLinearSegments(const geom::CoordinateSequence& pts); 00140 00141 }; 00142 00143 } // namespace geos::algorithm 00144 } // namespace geos 00145 00146 00147 #endif // GEOS_ALGORITHM_CENTROIDAREA_H