Library of Assembled Shared Sources
disk_3d.inl
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#ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_DISK_3D_INL
46#define LASS_GUARDIAN_OF_INCLUSION_PRIM_DISK_3D_INL
47
48
49#include "disk_3d.h"
51
52namespace lass
53{
54namespace prim
55{
56
57// --- public --------------------------------------------------------------------------------------
58
59template <typename T>
60Disk3D<T>::Disk3D():
61 plane_(),
62 radius_(TNumTraits::zero)
63{
64}
65
66
67
68template <typename T>
69Disk3D<T>::Disk3D(const TPoint& center, const TVector& normal, TParam radius):
70 plane_(normal, center),
71 radius_(radius)
72{
73}
74
75
76
77template <typename T>
78const typename Disk3D<T>::TPoint&
79Disk3D<T>::center() const
80{
81 return plane_.support();
82}
83
84
85
86template <typename T>
87void Disk3D<T>::setCenter(const TPoint& center)
88{
89 plane_ = TPlane(plane_.normal(), center);
90}
91
92
93
94template <typename T>
95const typename Disk3D<T>::TVector&
96Disk3D<T>::normal() const
97{
98 return plane_.normal();
99}
100
103template <typename T>
104void Disk3D<T>::setNormal(const TVector& normal)
105{
106 plane_ = TPlane(normal, plane_.support());
107}
109
110
111template<typename T>
112typename Disk3D<T>::TConstReference
113Disk3D<T>::radius() const
114{
115 return radius_;
116}
117
118
119
120template<typename T>
121typename Disk3D<T>::TReference
122Disk3D<T>::radius()
123{
124 return radius_;
125}
126
127
128
129/** return area of surface of sphere
130 */
131template<typename T>
132const typename Disk3D<T>::TValue
134{
135 return TNumTraits::pi * num::sqr(radius_);
136}
137
138
139
140/** return area of surface of sphere
141 */
142template<typename T>
143const typename Disk3D<T>::TPlane&
145{
146 return plane_;
147}
148
149
150
151template <typename T>
152const typename Disk3D<T>::TPoint
153Disk3D<T>::point(TParam u, TParam v) const
154{
155 const TValue theta = 2 * TNumTraits::pi * v;
156 return plane_.support() + (u * radius_) * (num::cos(theta) * plane_.directionU() + num::sin(theta) * plane_.directionV());
157}
158
159
160
161template <typename T> inline
162const typename Disk3D<T>::TPoint
163Disk3D<T>::point(const TUV& uv) const
164{
165 return point(uv.x, uv.y);
166}
167
168
169
170template <typename T>
171const typename Disk3D<T>::TUV
172Disk3D<T>::uv(const TPoint& point) const
173{
174 const TVector relative = point - plane_.support();
175 const TValue x = dot(relative, plane_.reciprocalU());
176 const TValue y = dot(relative, plane_.reciprocalU());
177 const TValue u = relative.norm() / radius_;
178 TValue v = num::atan2(y, x) / (2 * TNumTraits::pi);
179 if (v < 0)
180 {
181 v += 1;
182 }
183 return TUV(u, v < 0 ? TNumTraits::one - v : v);
184}
185
186
187
188/** return true if sphere has a non-negative radius
189 */
190template <typename T>
192{
193 return plane_.isValid() && radius_ >= TNumTraits::zero;
194}
195
196
197
198// --- protected -----------------------------------------------------------------------------------
199
200
201
202// --- private -------------------------------------------------------------------------------------
203
204
205
206// --- free ----------------------------------------------------------------------------------------
207
208/** @relates lass::prim::Disk3D
209 */
210template<typename T>
211std::ostream& operator<<(std::ostream& stream, const Disk3D<T>& disk)
212{
213 LASS_ENFORCE(stream) << "{S=" << disk.center() << ", N=" << disk.normal() << ", r=" << disk.radius() << "}";
214 return stream;
215}
216
217
218
219/** @relates lass::prim::Disk3D
220 */
221template<typename T>
222io::XmlOStream& operator<<(io::XmlOStream& stream, const Disk3D<T>& disk)
223{
224 LASS_ENFORCE_STREAM(stream)
225 << "<Disk3D>\n"
226 << "<center>" << disk.center() << "</center>\n"
227 << "<normal>" << disk.normal() << "</normal>\n"
228 << "<radius>" << disk.radius() << "</radius>\n"
229 << "</Disk3D>\n";
230
231 return stream;
232}
233
234
235
236}
237
238}
239
240#endif
241
242// --- END OF FILE ------------------------------------------------------------------------------
Output stream for writing a selection of geometric primitives to XML files.
bool isValid() const
return true if sphere has a non-negative radius
Definition disk_3d.inl:191
const TValue area() const
return area of surface of sphere
Definition disk_3d.inl:133
const TPlane & plane() const
return area of surface of sphere
Definition disk_3d.inl:144
T sqr(const T &x)
return x * x
Definition basic_ops.h:162
set of geometrical primitives
Definition aabb_2d.h:81
Library for Assembled Shared Sources.
Definition config.h:53