GEOS
3.6.2
|
00001 /********************************************************************** 00002 * 00003 * GEOS - Geometry Engine Open Source 00004 * http://geos.osgeo.org 00005 * 00006 * Copyright (C) 2011 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: operation/buffer/OffsetSegmentGenerator.java r378 (JTS-1.12) 00016 * 00017 **********************************************************************/ 00018 00019 #ifndef GEOS_OP_BUFFER_OFFSETSEGMENTGENERATOR_H 00020 #define GEOS_OP_BUFFER_OFFSETSEGMENTGENERATOR_H 00021 00022 #include <geos/export.h> 00023 00024 #include <vector> 00025 00026 #include <geos/algorithm/LineIntersector.h> // for composition 00027 #include <geos/geom/Coordinate.h> // for composition 00028 #include <geos/geom/LineSegment.h> // for composition 00029 #include <geos/operation/buffer/BufferParameters.h> // for composition 00030 #include <geos/operation/buffer/OffsetSegmentString.h> // for composition 00031 00032 #ifdef _MSC_VER 00033 #pragma warning(push) 00034 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class 00035 #endif 00036 00037 // Forward declarations 00038 namespace geos { 00039 namespace geom { 00040 class CoordinateSequence; 00041 class PrecisionModel; 00042 } 00043 } 00044 00045 namespace geos { 00046 namespace operation { // geos.operation 00047 namespace buffer { // geos.operation.buffer 00048 00061 class GEOS_DLL OffsetSegmentGenerator { 00062 00063 public: 00064 00065 /* 00066 * @param nBufParams buffer parameters, this object will 00067 * keep a reference to the passed parameters 00068 * so caller must make sure the object is 00069 * kept alive for the whole lifetime of 00070 * the buffer builder. 00071 */ 00072 OffsetSegmentGenerator(const geom::PrecisionModel *newPrecisionModel, 00073 const BufferParameters& bufParams, double distance); 00074 00087 bool hasNarrowConcaveAngle() const 00088 { 00089 return _hasNarrowConcaveAngle; 00090 } 00091 00092 void initSideSegments(const geom::Coordinate &nS1, 00093 const geom::Coordinate &nS2, int nSide); 00094 00096 // 00103 void getCoordinates(std::vector<geom::CoordinateSequence*>& to) { 00104 to.push_back(segList.getCoordinates()); 00105 } 00106 00107 void closeRing() { 00108 segList.closeRing(); 00109 } 00110 00112 void createCircle(const geom::Coordinate &p, double distance); 00113 00115 void createSquare(const geom::Coordinate &p, double distance); 00116 00118 void addFirstSegment() 00119 { 00120 segList.addPt(offset1.p0); 00121 } 00122 00124 void addLastSegment() 00125 { 00126 segList.addPt(offset1.p1); 00127 } 00128 00129 void addNextSegment(const geom::Coordinate &p, bool addStartPoint); 00130 00134 void addLineEndCap(const geom::Coordinate &p0, 00135 const geom::Coordinate &p1); 00136 00137 void addSegments(const geom::CoordinateSequence& pts, bool isForward) 00138 { 00139 segList.addPts(pts, isForward); 00140 } 00141 00142 private: 00143 00148 static const double OFFSET_SEGMENT_SEPARATION_FACTOR; // 1.0E-3; 00149 00154 static const double INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR; // 1.0E-3; 00155 00159 static const double CURVE_VERTEX_SNAP_DISTANCE_FACTOR; // 1.0E-6; 00160 00164 static const int MAX_CLOSING_SEG_LEN_FACTOR = 80; 00165 00170 double maxCurveSegmentError; // 0.0 00171 00176 double filletAngleQuantum; 00177 00195 int closingSegLengthFactor; // 1; 00196 00198 // 00205 OffsetSegmentString segList; 00206 00207 double distance; 00208 00209 const geom::PrecisionModel* precisionModel; 00210 00211 const BufferParameters& bufParams; 00212 00213 algorithm::LineIntersector li; 00214 00215 geom::Coordinate s0, s1, s2; 00216 00217 geom::LineSegment seg0; 00218 00219 geom::LineSegment seg1; 00220 00221 geom::LineSegment offset0; 00222 00223 geom::LineSegment offset1; 00224 00225 int side; 00226 00227 bool _hasNarrowConcaveAngle; // =false 00228 00229 void addCollinear(bool addStartPoint); 00230 00232 // 00237 void addMitreJoin(const geom::Coordinate& p, 00238 const geom::LineSegment& offset0, 00239 const geom::LineSegment& offset1, 00240 double distance); 00241 00243 // 00252 void addLimitedMitreJoin( 00253 const geom::LineSegment& offset0, 00254 const geom::LineSegment& offset1, 00255 double distance, double mitreLimit); 00256 00260 // 00264 void addBevelJoin(const geom::LineSegment& offset0, 00265 const geom::LineSegment& offset1); 00266 00267 static const double PI; // 3.14159265358979 00268 00269 // Not in JTS, used for single-sided buffers 00270 int endCapIndex; 00271 00272 void init(double newDistance); 00273 00281 static const double SIMPLIFY_FACTOR; // 100.0; 00282 00284 // 00288 void addOutsideTurn(int orientation, bool addStartPoint); 00289 00291 // 00295 void addInsideTurn(int orientation, bool addStartPoint); 00296 00309 void computeOffsetSegment(const geom::LineSegment& seg, 00310 int side, double distance, 00311 geom::LineSegment& offset); 00312 00324 void addFillet(const geom::Coordinate &p, const geom::Coordinate &p0, 00325 const geom::Coordinate &p1, 00326 int direction, double radius); 00327 00337 void addFillet(const geom::Coordinate &p, double startAngle, 00338 double endAngle, int direction, double radius); 00339 private: 00340 // An OffsetSegmentGenerator cannot be copied because of member "const BufferParameters& bufParams" 00341 // Not declaring these functions triggers MSVC warning C4512: "assignment operator could not be generated" 00342 OffsetSegmentGenerator(const OffsetSegmentGenerator&); 00343 void operator=(const OffsetSegmentGenerator&); 00344 00345 }; 00346 00347 } // namespace geos::operation::buffer 00348 } // namespace geos::operation 00349 } // namespace geos 00350 00351 #ifdef _MSC_VER 00352 #pragma warning(pop) 00353 #endif 00354 00355 #endif // ndef GEOS_OP_BUFFER_OFFSETSEGMENTGENERATOR_H 00356