1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 This is an implementation of the Sutherland Hodgman algorithm:
29 Reentrant Polygon Clipping, Sutherland, Hodgman,
30 Communications of the ACM, 1974
32 Wikipedia has a very simple Pseudo-Code example of this algorithm
33 http://en.wikipedia.org/wiki/Sutherland-Hodgeman.
35 The subject polygon will be clipped by the clipping polygon.
38 Martin Beaudoin, Hydro-Quebec, (2008)
44 \*---------------------------------------------------------------------------*/
46 #ifndef SutherlandHodgman_H
47 #define SutherlandHodgman_H
49 #include "DynamicList.H"
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 /*---------------------------------------------------------------------------*\
58 Class SutherlandHodgman Declaration
59 \*---------------------------------------------------------------------------*/
61 class SutherlandHodgman
65 //- The current subjectPolygon
66 List<point2D> subjectPolygon_;
68 //- The clipping polygon
69 List<point2D> clippingPolygon_;
71 //- Clipped edge, polygon 1
72 label currentClipEdgeP1_;
74 //- Clipped edge, polygon 2
75 label currentClipEdgeP2_;
77 //- Tolerance for detecting intersecting segment
78 scalar intersectSegDistTol_;
81 // Private Member Functions
83 //- Disallow default bitwise copy construct
84 SutherlandHodgman(const SutherlandHodgman&);
86 //- Disallow default bitwise assignment
87 void operator=(const SutherlandHodgman&);
90 //- Compute intersection between 2 line segments
91 bool lineSegmentIntersection
97 point2D& intersectionPoint
100 //- Evaluate if point is visible from current clipping segment
101 inline bool isPointVisibleFromCuttingSegment
106 //- Compute intersection between clipping polygon current segment
107 // and the line formed by the point p1, p2
108 inline bool clipSegment
112 point2D& intersectionPoint
120 //- Construct from component
123 const List<point2D>& clippingPolygon,
124 const List<point2D>& subjectPolygon,
125 const scalar& intersectSegDistTol
129 // Destructor - default
134 // Implements the actual algorithm.
135 List<point2D> evaluate();
139 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
141 } // End namespace Foam
143 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 #include "SutherlandHodgmanI.H"
147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
151 // ************************************************************************* //