Library of Assembled Shared Sources
simple_polygon_3d.h
Go to the documentation of this file.
1/** @file
2 * @author Bram de Greve (bram@cocamware.com)
3 * @author Tom De Muer (tom@cocamware.com)
4 *
5 * *** BEGIN LICENSE INFORMATION ***
6 *
7 * The contents of this file are subject to the Common Public Attribution License
8 * Version 1.0 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://lass.sourceforge.net/cpal-license. The License is based on the
11 * Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover
12 * use of software over a computer network and provide for limited attribution for
13 * the Original Developer. In addition, Exhibit A has been modified to be consistent
14 * with Exhibit B.
15 *
16 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
17 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
18 * language governing rights and limitations under the License.
19 *
20 * The Original Code is LASS - Library of Assembled Shared Sources.
21 *
22 * The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
23 * The Original Developer is the Initial Developer.
24 *
25 * All portions of the code written by the Initial Developer are:
26 * Copyright (C) 2004-2011 the Initial Developer.
27 * All Rights Reserved.
28 *
29 * Contributor(s):
30 *
31 * Alternatively, the contents of this file may be used under the terms of the
32 * GNU General Public License Version 2 or later (the GPL), in which case the
33 * provisions of GPL are applicable instead of those above. If you wish to allow use
34 * of your version of this file only under the terms of the GPL and not to allow
35 * others to use your version of this file under the CPAL, indicate your decision by
36 * deleting the provisions above and replace them with the notice and other
37 * provisions required by the GPL License. If you do not delete the provisions above,
38 * a recipient may use your version of this file under either the CPAL or the GPL.
39 *
40 * *** END LICENSE INFORMATION ***
41 */
42
43
44
45/** @class lass::prim::SimplePolygon3D
46 * @brief convex or concave polygon in 3D (not selfintersecting, no holes)
47 * @author Bram de Greve [BdG]
48 *
49 * @warning SimplePolygon3D only @e assumes it's simple. there's no guarantee at any time.
50 * It's your own responsibility to keep it simple. We do it this way because
51 * it's just to costly to check it at every access to the polygon. However, we
52 * provide some methods to check it yourself.
53 *
54 * @warning also, SimplePolygon3D only @e assumes it's flat! It's up to you to feed it with
55 * vertices that are coplanar. However ... We provide tools to "flatten" it.
56 */
57
58#ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_SIMPLE_POLYGON_3D_H
59#define LASS_GUARDIAN_OF_INCLUSION_PRIM_SIMPLE_POLYGON_3D_H
60
61#include "prim_common.h"
62#include "line_segment_3d.h"
63#include "orientation.h"
64#include "plane_3d.h"
65#include "simple_polygon_2d.h"
66#include "xyz.h"
67
68namespace lass
69{
70namespace prim
71{
72
73template
74<
75 typename T,
76 class PlaneEquationPolicy = Cartesian,
77 class PlaneNormalizingPolicy = Normalized
78>
79class SimplePolygon3D
80{
81public:
82
83 typedef SimplePolygon3D<T> TSelf;
84
85 typedef Point3D<T> TPoint;
86 typedef Point3DH<T> TPointH;
87 typedef typename TPoint::TVector TVector;
88 typedef LineSegment3D<T> TLineSegment;
90
91 typedef typename TPoint::TValue TValue;
92 typedef typename TPoint::TParam TParam;
93 typedef typename TPoint::TReference TReference;
94 typedef typename TPoint::TConstReference TConstReference;
95 typedef typename TPoint::TNumTraits TNumTraits;
96
97 enum { dimension = TPoint::dimension }; /**< number of dimensions */
98
99 template <typename U> struct Rebind
100 {
101 typedef SimplePolygon3D<U, PlaneEquationPolicy, PlaneNormalizingPolicy> Type;
102 };
103
104 SimplePolygon3D(const TPlane& iPlane);
105 SimplePolygon3D(const TPoint& iA, const TPoint& iB, const TPoint& iC);
106
107 const TPoint& operator[](size_t iIndexOfVertex) const;
108 TPoint& operator[](size_t iIndexOfVertex);
109 const TPoint& at(int iIndexOfVertex) const;
110 TPoint& at(int iIndexOfVertex);
111 const TLineSegment edge(int iIndexOfTailVertex) const;
112 const TVector vector(int iIndexOfTailVertex) const;
113 const TPlane& plane() const;
114 TPlane& plane();
115 const TVector normal() const;
116 const XYZ majorAxis() const;
117
118 void add(const TPoint& iVertex);
119 void insert(int iIndexOfVertex, const TPoint& iVertex);
120 void remove(int iIndexOfVertex);
121
122 bool isEmpty() const;
123 size_t size() const;
124
125 const TValue signedArea() const;
126 const TValue area() const;
127 const TValue perimeter() const;
128 const TPointH vertexCentroid() const;
129 const TPointH surfaceCentroid() const;
130
131 bool isSimple() const;
132 bool isConvex() const;
133 bool isConcave() const;
135
136 bool isReflex(int iIndexOfVertex) const;
137
138 const SimplePolygon2D<T> mapping(XYZ iAxis) const;
139
140 Side classify(const TPoint& iP) const;
141 bool contains(const TPoint& iP) const;
142
143 void flip();
144
145private:
146
147 bool isInRange(size_t iIndexOfVertex) const;
148
149 typedef std::vector<TPoint> TVertices;
150
151 TVertices vertices_;
152 TPlane plane_;
153};
154
155template<typename T, class EP, class NP, class PP>
156Result intersect(const SimplePolygon3D<T, EP, NP>& iPolygon,
157 const LineSegment3D<T, PP>& iSegment,
158 T& oT, const T& iMinT = 0);
159
160template<typename T, class EP1, class NP1, class EP2, class NP2>
162 const SimplePolygon3D<T, EP2, NP2>& iPolygon);
163
164template <typename T, class EP, class NP>
165io::XmlOStream& operator<<(io::XmlOStream& ioOStream, const SimplePolygon3D<T, EP, NP>& iPolygon);
166
167template <typename T, class EP, class NP>
168std::ostream& operator<<(std::ostream& ioOStream, const SimplePolygon3D<T, EP, NP>& iPolygon);
169
170}
171
172}
173
174#include "simple_polygon_3d.inl"
175
176#define LASS_PRIM_HAVE_PY_EXPORT_TRAITS_SIMPLE_POLYGON_3D
177#ifdef LASS_GUARDIAN_OF_INCLUSION_UTIL_PYOBJECT_PLUS_H
179#endif
180
181#ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_AABB_3D_H
183#endif
184
185#ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_RAY_3D_H
187#endif
188
189#endif
190
191// EOF
Output stream for writing a selection of geometric primitives to XML files.
A 3D hyper plane.
Definition plane_3d.h:361
convex or concave polygon in 2D (not selfintersecting, no holes)
convex or concave polygon in 3D (not selfintersecting, no holes)
TPoint & operator[](size_t iIndexOfVertex)
return vertex of polygon by its index, not wrapped, no bounds check.
void insert(int iIndexOfVertex, const TPoint &iVertex)
insert a vertex at iIndex (so it will sit before the current at(iIndex)).
const TValue area() const
return area of the polygons surface.
const XYZ majorAxis() const
determines the major axis of the normal vector.
const TValue perimeter() const
return sum of the lengths of all edges
bool contains(const TPoint &iP) const
return true if a point iP is inside the polygon, on condition iP is on the plane
const TPointH vertexCentroid() const
return the barycenter of all vertices.
const TVector vector(int iIndexOfTailVertex) const
return the vector between vertices at(iIndex) and at(iIndex + 1)\
TPoint & at(int iIndexOfVertex)
return vertex of polygon by its index, but wrap around the bounds.
bool isConvex() const
return true if polygon is convex, false if not.
const SimplePolygon2D< T > mapping(XYZ iAxis) const
maps a 3D polygon as a 2D polygon by ignoring the component along an axis.
size_t size() const
return number of vertices
void flip()
flip normal and reverse sequence of vertices
const TPoint & operator[](size_t iIndexOfVertex) const
return vertex of polygon by its index, not wrapped, no bounds check.
Orientation orientation() const
return orientation of polygon
const TValue signedArea() const
return signed polygon area.
TPlane & plane()
access support plane of polygon.
const TPoint & at(int iIndexOfVertex) const
return vertex of polygon by its index, but wrap around the bounds.
bool isReflex(int iIndexOfVertex) const
return true if inner angle of vertex is reflex (is > 180 degrees).
void add(const TPoint &iVertex)
add a point at the "end" of the vertex list
const TVector normal() const
return normal of plane
bool isEmpty() const
return true if polygon has no vertices
void remove(int iIndexOfVertex)
remove the vertex at(iIndex)
const TPointH surfaceCentroid() const
return the centroid of the filled polygon.
bool isSimple() const
return true if polygon is simple, false if not.
const TLineSegment edge(int iIndexOfTailVertex) const
return the edge of the polygon between vertices at(iIndex) and at(iIndex + 1).
const TPlane & plane() const
return support plane of polygon.
cyclic iterator over xyz indices
Definition xyz.h:62
set of geometrical primitives
Definition aabb_2d.h:81
Side
Different sides of a surface.
Definition side.h:79
Orientation
enumeration of clockwise versus counterclockwise
Definition orientation.h:58
Result
meta information on the result you have from an operation like an intersection ...
Definition result.h:74
Library for Assembled Shared Sources.
Definition config.h:53
policy for an implementation based on the cartesian equation.
Policy to auto-normalize normals.
homogenous 3D Point
Definition point_3dh.h:72