Library of Assembled Shared Sources
point_3dh.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/** @struct lass::prim::Point3DH
46 * @brief homogenous 3D Point
47 * @author BdG
48 * @date 2003
49 */
50
51
52
53#ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_POINT_3DH_H
54#define LASS_GUARDIAN_OF_INCLUSION_PRIM_POINT_3DH_H
55
56
57
58
59#include "prim_common.h"
60#include "point_3d.h"
61#include "vector_4d.h"
62
63
64namespace lass
65{
66
67namespace prim
68{
69
70template<typename T>
71struct LASS_SIMD_ALIGN Point3DH
72{
73public:
74
75 typedef Point3DH<T> TSelf;
76
77 typedef Point3D<T> TPoint;
78 typedef Vector4D<T> TVector;
79
80 typedef typename TVector::TValue TValue;
81 typedef typename TVector::TParam TParam;
82 typedef typename TVector::TReference TReference;
83 typedef typename TVector::TConstReference TConstReference;
84 typedef typename TVector::TNumTraits TNumTraits;
85
86 enum { dimension = TPoint::dimension }; /**< number of dimensions */
87
88 template <typename U> struct Rebind
89 {
90 typedef Point3DH<U> Type;
91 };
92
93 TValue x;
94 TValue y;
95 TValue z;
96 TValue w;
97
98 Point3DH();
99 Point3DH(TParam iX, TParam iY, TParam iZ, TParam iW = TNumTraits::one);
100 Point3DH(const TPoint& iAffinePoint);
101 explicit Point3DH(const TVector& iPositionVector);
102
103 const TVector position() const;
104 TConstReference operator[](size_t iIndex) const;
105 TReference operator[](size_t iIndex);
106 TConstReference at(signed iIndex) const;
107 TReference at(signed iIndex);
108
109 const Point3DH<T>& operator+() const;
110 const Point3DH<T> operator-() const;
111
112 Point3DH<T>& operator+=(const Point3DH<T>& iB);
113 Point3DH<T>& operator-=(const Point3DH<T>& iB);
114 Point3DH<T>& operator*=(TParam iB);
115 Point3DH<T>& operator/=(TParam iB);
116
117 bool isZero() const;
118 bool isNaN() const;
119 bool isInfinite() const;
120 bool isValid() const;
121 const TParam weight() const;
122 const TPoint affine() const;
123
125};
126
127template<typename T> bool operator==(const Point3DH<T>& iA, const Point3DH<T>& iB);
128template<typename T> bool operator!=(const Point3DH<T>& iA, const Point3DH<T>& iB);
129
130template<typename T> Point3DH<T> operator+(const Point3DH<T>& iA, const Point3DH<T>& iB);
131template<typename T> Point3DH<T> operator-(const Point3DH<T>& iA, Point3DH<T>& iB);
132
133template<typename T> Point3DH<T> operator*(const Point3DH<T>& iA, typename Point3DH<T>::TParam iB);
134template<typename T> Point3DH<T> operator/(const Point3DH<T>& iA, typename Point3DH<T>::TParam iB);
135template<typename T> Point3DH<T> operator*(typename Point3DH<T>::TParam iA, const Point3DH<T>& iB);
136
137template<typename T> std::ostream& operator<<(std::ostream& oOStream, const Point3DH<T>& iB);
138template<typename T> io::XmlOStream& operator<<(io::XmlOStream& oOStream, const Point3DH<T>& iB);
139template<typename T> std::istream& operator>>(std::istream& ioIStream, Point3DH<T>& oB);
140
141
142// redirectors (stuff because template instantiation doesn't understand it can convert
143// regular points to homogenous points:
144template<typename T> inline Point3DH<T> operator+(const Point3D<T>& iA, const Point3D<T>& iB)
145{
146 return Point3DH<T>(iA) + Point3DH<T>(iB);
147}
148template<typename T> inline Point3DH<T> operator*(typename Point3D<T>::TParam iA, const Point3D<T>& iB)
149{
150 return iA * Point3DH<T>(iB);
151}
152template<typename T> inline Point3DH<T> operator*(const Point3D<T>& iA, typename Point3D<T>::TParam iB)
153{
154 return Point3DH<T>(iA) * iB;
155}
156
157
158
159}
160
161}
162
163#include "point_3dh.inl"
164
165#endif
166
167// --- END OF FILE ------------------------------------------------------------------------------
Output stream for writing a selection of geometric primitives to XML files.
#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
const Point3DH< T > & operator+() const
A weird way to get back the same object.
const TParam weight() const
Return weight of point.
bool isZero() const
Return true if point is origin (0, 0, 0, w).
TConstReference at(signed iIndex) const
Wrap index around range.
const TPoint affine() const
Return rescaled version of point with weight = 1.
TReference at(signed iIndex)
Wrap index around range.
bool isNaN() const
Return true if at least one of the components is NaN.
bool isInfinite() const
Return true if point is at infinite distance of origin.
bool isValid() const
Return true if point is valid.
void homogenize()
Rescale point so that weight is 1.