Library of Assembled Shared Sources
triangle_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::Triangle3D
46 * @brief A very simple 3D polygon :)
47 * @author Bram de Greve [BdG]
48 */
49
50#ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_TRIANGLE_3D_H
51#define LASS_GUARDIAN_OF_INCLUSION_PRIM_TRIANGLE_3D_H
52
53#include "prim_common.h"
54#include "line_segment_3d.h"
55#include "plane_3d.h"
56
57namespace lass
58{
59namespace prim
60{
61
62template <typename T>
64{
65public:
66
67 typedef Triangle3D<T> TSelf;
68
69 typedef Point3D<T> TPoint;
70 typedef Point3DH<T> TPointH;
71 typedef typename TPoint::TVector TVector;
72 typedef LineSegment3D<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 Triangle3D<U> Type;
86 };
87
89 Triangle3D(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 const TPlane plane() const;
98
99 bool isEmpty() const;
100 size_t size() const;
101
102 const TValue squaredArea() const;
103 const TValue area() const;
104 const TValue perimeter() const;
105 const TPointH vertexCentroid() const;
106 const TPointH surfaceCentroid() const;
107
108 bool isSimple() const;
109 bool isConvex() const;
110
111 bool isReflex(int iIndexOfVertex) const;
112
113private:
114
115 bool isInRange(size_t iIndexOfVertex) const;
116
117 enum { size_ = 3 };
118
119 TPoint vertices_[size_];
120};
121
122template <typename T>
123io::XmlOStream& operator<<(io::XmlOStream& ioOStream, const Triangle3D<T>& iTriangle);
124template <typename T>
125std::ostream& operator<<(std::ostream& ioOStream, const Triangle3D<T>& iTriangle);
126
127
128
129}
130
131}
132
133#include "triangle_3d.inl"
134
135#ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_AABB_3D_H
136# include "aabb_3d_triangle_3d.h"
137#endif
138
139#ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_RAY_3D_H
140# include "ray_3d_triangle_3d.h"
141#endif
142
143#endif
144
145// EOF
Output stream for writing a selection of geometric primitives to XML files.
A 3D hyper plane.
Definition plane_3d.h:361
const TValue squaredArea() const
returns squared area of triangle to avoid the square root.
const TPoint & operator[](size_t iIndexOfVertex) const
return vertex of polygon by its index, not wrapped, no bounds check.
bool isEmpty() const
return true if polygon has no vertices
size_t size() const
return number of vertices
Triangle3D(const TPoint &iA, const TPoint &iB, const TPoint &iC)
Constructs a triangle through three points in positive sequence.
const TValue area() const
return area of the polygons surface.
bool isSimple() const
return true if polygon is simple, false if not.
const TPoint & at(int iIndexOfVertex) const
return vertex of polygon by its index, but wrap around the bounds.
const TLineSegment edge(int iIndexOfTailVertex) const
return the edge of the polygon between vertices at(iIndex) and at(iIndex + 1).
bool isReflex(int iIndexOfVertex) const
return true if inner angle of vertex is reflex (is > 180 degrees).
const TPointH vertexCentroid() const
return the barycenter of all vertices.
const TPlane plane() const
return support plane of polygon.
bool isConvex() const
return true if polygon is convex, false if not.
const TVector vector(int iIndexOfTailVertex) const
return the vector between vertices at(iIndex) and at(iIndex + 1)\
const TPointH surfaceCentroid() const
return the centroid of the filled 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
TPoint & at(int iIndexOfVertex)
return vertex of polygon by its index, but wrap around the bounds.
Triangle3D()
constructs an empty triangle.
#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
Library for Assembled Shared Sources.
Definition config.h:53
homogenous 3D Point
Definition point_3dh.h:72