CentroidArea.h

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

Generated on Thu Mar 14 16:37:09 2013 for GEOS by  doxygen 1.4.7