Library of Assembled Shared Sources
transformation_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::Transformation2D
46 * @brief a linear 2D transformation
47 * @author Bram de Greve [BdG]
48 */
49
50#ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_TRANSFORMATION_2D_H
51#define LASS_GUARDIAN_OF_INCLUSION_PRIM_TRANSFORMATION_2D_H
52
53#include "prim_common.h"
54#include "point_2d.h"
55#include "xyz.h"
56#include "impl/prim_allocator.h"
57#include "../io/xml_o_stream.h"
58#include "../num/num_traits.h"
59#include "../util/shared_ptr.h"
60#include "../util/thread.h"
61
62namespace lass
63{
64namespace prim
65{
66namespace impl
67{
68 template <typename T, typename Cascade>
69 class Transformation2DStorage: public util::ArrayStorage<T, Cascade>
70 {
71 public:
72 Transformation2DStorage(): util::ArrayStorage<T, Cascade>() {}
73 Transformation2DStorage(T* p): util::ArrayStorage<T, Cascade>(p) {}
74 protected:
75 void dispose()
76 {
77 impl::deallocateArray(this->pointer(), 9);
78 }
79 };
80}
81
82template <typename T>
84{
85public:
86
87 typedef Transformation2D<T> TSelf;
88
89 typedef Point2D<T> TPoint;
90 typedef typename TPoint::TVector TVector;
91 typedef typename util::CallTraits<T>::TValue TValue;
92 typedef typename util::CallTraits<T>::TParam TParam;
93 typedef typename util::CallTraits<T>::TReference TReference;
94 typedef typename util::CallTraits<T>::TConstReference TConstReference;
95 typedef num::NumTraits<T> TNumTraits;
96 typedef size_t TSize;
97
98 enum { dimension = 2 }; /**< number of dimensions of vector */
99
100 template <typename U> struct Rebind
101 {
102 typedef Transformation2D<U> Type;
103 };
104
106 Transformation2D(const TPoint& origin, const TVector& baseX, const TVector& baseY);
107 template <typename InputIterator> Transformation2D(InputIterator first, InputIterator last);
108
110
111 const TValue* matrix() const;
112
113 bool isIdentity() const;
114 bool isTranslation() const;
115
116 void swap(TSelf& other);
117
118 static const TSelf identity();
119 static const TSelf translation(const Vector2D<T>& offset);
120 static const TSelf scaler(const T& scale);
121 static const TSelf scaler(const Vector2D<T>& scale);
122 static const TSelf rotation(TParam radians);
123
124private:
125
126 enum { matrixSize_ = 9 };
127
128 typedef util::SharedPtr<TValue, impl::Transformation2DStorage> TMatrix;
129
130 Transformation2D(const TMatrix& matrix, const TMatrix& inverseMatrix, bool dummy);
131
132 static const TMatrix& getIdentityMatrix();
133
134 TMatrix matrix_;
135 mutable TMatrix inverseMatrix_;
136
137 static TMatrix identityMatrix_;
138
139 static util::Semaphore sync_;
140};
141
142template <typename T> Transformation2D<T> concatenate(const Transformation2D<T>& first, const Transformation2D<T>& second);
143
144template <typename T> Vector2D<T> transform(const Vector2D<T>& subject, const Transformation2D<T>& transformation);
145template <typename T> Point2D<T> transform(const Point2D<T>& subject, const Transformation2D<T>& transformation);
146template <typename T> Vector2D<T> normalTransform(const Vector2D<T>& subject, const Transformation2D<T>& transformation);
147template <typename T> std::pair<Vector2D<T>, T> normalTransform(const std::pair<Vector2D<T>, T>& subject, const Transformation2D<T>& transformation);
148
149template<typename T, typename Char, typename Traits>
150std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& stream, const Transformation2D<T>& transformation);
151
152template<typename T> io::XmlOStream& operator<<(io::XmlOStream& stream, const Transformation2D<T>& transformation);
153
154// static member initialisation
155
156template <typename T> util::Semaphore Transformation2D<T>::sync_;
157
158}
159
160}
161
162#include "transformation_2d.inl"
163
164#define LASS_PRIM_HAVE_PY_EXPORT_TRAITS_TRANSFORMATION_2D
165#ifdef LASS_GUARDIAN_OF_INCLUSION_UTIL_PYOBJECT_PLUS_H
167#endif
168
169#ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_AABB_2D_H
171#endif
172
173#endif
174
175// EOF
Output stream for writing a selection of geometric primitives to XML files.
static const TSelf translation(const Vector2D< T > &offset)
make a 2D transformation representing a translation
static const TSelf rotation(TParam radians)
make a 3D transformation representing a counterclockwise rotation
Transformation2D(InputIterator first, InputIterator last)
construct a transformation from a 3x3 tranformation matrix.
const TValue * matrix() const
Return pointer to row major matrix representation of transformation.
Transformation2D()
construct an identity transformation.
static const TSelf scaler(const Vector2D< T > &scale)
make a 3D transformation representing a scaling with different factors per axis
const Transformation2D< T > inverse() const
return the inverse transformation.
static const TSelf scaler(const T &scale)
make a 3D transformation representing a uniform scaling
static const TSelf identity()
make a 2D identity transformation
Lean and mean synchronisation object, without OS support.
Definition thread.h:414
implementation details of lass::prim
set of geometrical primitives
Definition aabb_2d.h:81
Library for Assembled Shared Sources.
Definition config.h:53