Library of Assembled Shared Sources
triangle_2d.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::Triangle2D
46 * @brief A very simple 2D polygon :)
47 * @author Bram de Greve [BdG]
48 */
49
50#ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_TRIANGLE_2D_H
51#define LASS_GUARDIAN_OF_INCLUSION_PRIM_TRIANGLE_2D_H
52
53#include "prim_common.h"
54#include "line_segment_2d.h"
55#include "orientation.h"
56#include "side.h"
57
58namespace lass
59{
60namespace prim
61{
62
63template <typename T>
65{
66public:
67
68 typedef Triangle2D<T> TSelf;
69
70 typedef Point2D<T> TPoint;
71 typedef Point2DH<T> TPointH;
72 typedef typename TPoint::TVector TVector;
73 typedef LineSegment2D<T> TLineSegment;
74
75 typedef typename TPoint::TValue TValue;
76 typedef typename TPoint::TParam TParam;
77 typedef typename TPoint::TReference TReference;
78 typedef typename TPoint::TConstReference TConstReference;
79 typedef typename TPoint::TNumTraits TNumTraits;
80
81 enum { dimension = TPoint::dimension }; /**< number of dimensions */
82
83 template <typename U> struct Rebind
84 {
85 typedef Triangle2D<U> Type;
86 };
87
89 Triangle2D(const TPoint& iA, const TPoint& iB, const TPoint& iC);
90
91 const TPoint& operator[](size_t iIndexOfVertex) const;
92 TPoint& operator[](size_t iIndexOfVertex);
93 const TPoint& at(int iIndexOfVertex) const;
94 TPoint& at(int iIndexOfVertex);
95 const TLineSegment edge(int iIndexOfTailVertex) const;
96 const TVector vector(int iIndexOfTailVertex) const;
97
98 bool isEmpty() const;
99 int size() const;
100
101 const TValue signedArea() const;
102 const TValue area() const;
103 const TValue perimeter() const;
104 const TPointH vertexCentroid() const;
105 const TPointH surfaceCentroid() const;
106
107 bool isSimple() const;
108 bool isConvex() const;
109 bool isConcave() const;
111
112 bool isReflex(int iIndexOfVertex) const;
113
114 Side classify(const TPoint& iP) const;
115 bool contains(const TPoint& iP) const;
116
117 void flip();
118
119private:
120
121 bool isInRange(size_t iIndexOfVertex) const;
122
123 enum { size_ = 3 };
124
125 TPoint vertices_[size_];
126};
127
128template <typename T> const T distance(const Triangle2D<T>& triangle, const Point2D<T>& point);
129template <typename T> bool intersects(const Triangle2D<T>& a, const Triangle2D<T>& b);
130
131template <typename T>
132io::XmlOStream& operator<<(io::XmlOStream& ioOStream, const Triangle2D<T>& iTriangle);
133template <typename T>
134std::ostream& operator<<(std::ostream& ioOStream, const Triangle2D<T>& iTriangle);
135template<typename T>
137 const Triangle2D<T>& iTriangle);
138
139template <typename T>
140T partialVoronoiArea(const Triangle2D<T> iT, int iIndexOfVertex);
141
142}
143
144}
145
146#include "triangle_2d.inl"
147
148#ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_AABB_2D_H
149# include "aabb_2d_triangle_2d.h"
150#endif
151
152#ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_RAY_2D_H
153# include "ray_2d_triangle_2d.h"
154#endif
155
156#endif
157
158// EOF
Output stream for writing a selection of geometric primitives to matlab M files.
Output stream for writing a selection of geometric primitives to XML files.
Triangle2D(const TPoint &iA, const TPoint &iB, const TPoint &iC)
Constructs a triangle through three points in positive sequence.
bool isSimple() const
return true if polygon is simple, false if not.
int size() const
return number of vertices
const TPoint & operator[](size_t iIndexOfVertex) const
return vertex of polygon by its index, not wrapped, no bounds check.
const TVector vector(int iIndexOfTailVertex) const
return the vector between vertices at(iIndex) and at(iIndex + 1)\
bool contains(const TPoint &iP) const
return true when a point is inside or on the edge of a triangle.
const TPointH vertexCentroid() const
return the barycenter of all vertices.
bool isReflex(int iIndexOfVertex) const
return true if inner angle of vertex is reflex (is > 180 degrees).
Orientation orientation() const
return orientation of polygon.
TPoint & operator[](size_t iIndexOfVertex)
return vertex of polygon by its index, not wrapped, no bounds check.
const TValue perimeter() const
return sum of the lengths of all edges
bool isEmpty() const
return true if polygon has no vertices
const TPoint & at(int iIndexOfVertex) const
return vertex of polygon by its index, but wrap around the bounds.
void flip()
flip orientation of polygon.
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 TValue signedArea() const
return signed polygon area.
const TLineSegment edge(int iIndexOfTailVertex) const
return the edge of the polygon between vertices at(iIndex) and at(iIndex + 1).
Triangle2D()
constructs an empty triangle.
const TValue area() const
return area of the polygons surface.
const TPointH surfaceCentroid() const
return the barycenter of all vertices.
#define LASS_SIMD_ALIGN
if LASS_SIMD_ALIGNMENT is set, use LASS_SIMD_ALIGN to align some structures on SIMD alignment boundar...
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
Library for Assembled Shared Sources.
Definition config.h:53
homogenous 2D Point
Definition point_2dh.h:63