- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

# OffsetSegmentGenerator.h

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