cisst-saw
Loading...
Searching...
No Matches
vctAngleRotation2.h
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3
4/*
5 Author(s): Anton Deguet
6 Created on: 2005-01-13
7
8 (C) Copyright 2005-2018 Johns Hopkins University (JHU), All Rights Reserved.
9
10--- begin cisst license - do not edit ---
11
12This software is provided "as is" under an open source license, with
13no warranty. The complete license can be found in license.txt and
14http://www.cisst.org/cisst/license.txt.
15
16--- end cisst license ---
17*/
18
19#pragma once
20#ifndef _vctAngleRotation2_h
21#define _vctAngleRotation2_h
22
27
30
33
45{
46public:
48 enum {DIMENSION = 2};
51
52protected:
53 AngleType AngleMember;
54
55
57 inline void ThrowUnlessIsNormalized(void) const CISST_THROW(std::runtime_error) {
58 if (! IsNormalized()) {
59 cmnThrow(std::runtime_error("vctAngleRotation2: This rotation is not normalized"));
60 }
61 }
62
67 template <class _inputType>
68 inline void ThrowUnlessIsNormalized(const _inputType & input) const CISST_THROW(std::runtime_error) {
69 if (! input.IsNormalized()) {
70 cmnThrow(std::runtime_error("vctAngleRotation2: Input is not normalized"));
71 }
72 }
73
74
75 public:
76
79 AngleMember(0.0)
80 {}
81
82
96
97 inline explicit
98 vctAngleRotation2(const AngleType angle)
99 CISST_THROW(std::runtime_error)
100 {
101 From(angle);
102 }
103
105 template <class _containerType>
107 CISST_THROW(std::runtime_error)
108 {
109 From(matrixRotation);
110 }
111
112
113
135
136 inline vctAngleRotation2(const AngleType angle,
137 bool normalizeInput)
138 {
139 if (normalizeInput) {
140 FromNormalized(angle);
141 } else {
142 FromRaw(angle);
143 }
144 }
145
147 template <class _containerType>
149 bool normalizeInput)
150 {
151 if (normalizeInput) {
152 FromNormalized(matrixRotation);
153 } else {
154 FromRaw(matrixRotation);
155 }
156 }
157
158
162
163
164 inline const AngleType & Angle(void) const {
165 return this->AngleMember;
166 }
167
168 inline AngleType & Angle(void) {
169 return this->AngleMember;
170 }
171
172
173
187
189 inline ThisType &
190 From(const AngleType angle)
191 CISST_THROW(std::runtime_error)
192 {
193 this->AngleMember = angle;
194 // this->ThrowUnlessIsNormalized();
195 return *this;
196 }
197
199 template <class _containerType>
200 inline ThisType &
202 CISST_THROW(std::runtime_error)
203 {
204 this->ThrowUnlessIsNormalized(matrixRotation);
205 this->AngleMember = atan2(matrixRotation.Element(0, 1), matrixRotation.Element(0, 0));
206 return *this;
207 }
208
209
210
220
222 inline ThisType &
223 FromNormalized(const AngleType angle)
224 {
225 this->AngleMember = angle;
226 this->NormalizedSelf();
227 return *this;
228 }
229
231 template <class _containerType>
232 inline ThisType &
234 return FromRaw(matrixRotation.Normalized());
235 }
236
238
248
250 inline ThisType &
251 FromRaw(const AngleType angle)
252 {
253 this->AngleMember = angle;
254 return *this;
255 }
256
258 template <class _containerType>
259 inline ThisType &
261 AngleMember = atan2(matrixRotation.Element(0, 1), matrixRotation.Element(0, 0));
262 return *this;
263 }
264
266
267
271
272 inline ThisType & InverseSelf(void) {
274 return *this;
275 }
276
279 inline ThisType & InverseOf(const ThisType & otherRotation) {
280 AngleMember = 2 * cmnPI - otherRotation.Angle();
281 return *this;
282 }
283
287 inline ThisType Inverse(void) const {
288 ThisType result;
289 result.Angle() = 2 * cmnPI - this->Angle();
290 return result;
291 }
292
293
296 inline ThisType & NormalizedSelf(void) {
297 AngleMember = fmod(AngleMember, 2.0 * cmnPI);
298 if (AngleMember < 0.0) {
299 AngleMember += (2.0 * cmnPI);
300 }
301 return *this;
302 }
303
309 inline ThisType & NormalizedOf(const ThisType & otherRotation) {
310 AngleMember = otherRotation.Angle();
311 return *this;
312 }
313
317 inline ThisType Normalized(void) const {
318 ThisType result(*this);
319 result.NormalizedSelf();
320 return result;
321 }
322
332 inline bool IsNormalized(AngleType CMN_UNUSED(tolerance) = TypeTraits::Tolerance()) const {
333 return true;
334 }
335
336
337 std::string ToString(void) const {
338 std::stringstream outputStream;
339 ToStream(outputStream);
340 return outputStream.str();
341 }
342
344 inline void ToStream(std::ostream & outputStream) const {
345 outputStream << "Angle: "
346 << std::endl
347 << this->Angle();
348 }
349
351 void ToStreamRaw(std::ostream & outputStream, const char CMN_UNUSED(delimiter) = ' ',
352 bool headerOnly = false, const std::string & headerPrefix = "") const {
353 if (headerOnly) {
354 outputStream << headerPrefix << "angle";
355 } else {
356 outputStream << this->Angle();
357 }
358 }
359
361 void SerializeRaw(std::ostream & outputStream) const
362 {
363 cmnSerializeRaw(outputStream, this->Angle());
364 }
365
367 void DeSerializeRaw(std::istream & inputStream)
368 {
369 cmnDeSerializeRaw(inputStream, this->Angle());
370 }
371};
372
373
375inline
376std::ostream & operator << (std::ostream & output,
377 const vctAngleRotation2 & angleRotation) {
378 angleRotation.ToStream(output);
379 return output;
380}
381
382
383#endif // _vctAngleRotation2_h
A collection of useful information about the C++ basic types, represented in a generic programming wa...
Definition cmnTypeTraits.h:155
static Type Tolerance(void)
Definition cmnTypeTraits.h:170
Define a rotation based on an angle for a space of dimension 2.
Definition vctAngleRotation2.h:45
ThisType Normalized(void) const
Definition vctAngleRotation2.h:317
ThisType & From(const AngleType angle) CISST_THROW(std
Definition vctAngleRotation2.h:190
std::string ToString(void) const
Definition vctAngleRotation2.h:337
VCT_CONTAINER_TRAITS_TYPEDEFS(double)
cmnTypeTraits< AngleType > TypeTraits
Definition vctAngleRotation2.h:50
ThisType & InverseOf(const ThisType &otherRotation)
Definition vctAngleRotation2.h:279
bool IsNormalized(AngleType CMN_UNUSED(tolerance)=TypeTraits::Tolerance()) const
Definition vctAngleRotation2.h:332
vctAngleRotation2(const AngleType angle) CISST_THROW(std
Definition vctAngleRotation2.h:98
ThisType & FromRaw(const vctMatrixRotation2Base< _containerType > &matrixRotation)
Definition vctAngleRotation2.h:260
ThisType & From(const vctMatrixRotation2Base< _containerType > &matrixRotation) CISST_THROW(std
Definition vctAngleRotation2.h:201
void SerializeRaw(std::ostream &outputStream) const
Definition vctAngleRotation2.h:361
AngleType AngleMember
Definition vctAngleRotation2.h:53
ThisType & InverseSelf(void)
Definition vctAngleRotation2.h:272
void ToStreamRaw(std::ostream &outputStream, const char CMN_UNUSED(delimiter)=' ', bool headerOnly=false, const std::string &headerPrefix="") const
Definition vctAngleRotation2.h:351
AngleType & Angle(void)
Definition vctAngleRotation2.h:168
const AngleType & Angle(void) const
Definition vctAngleRotation2.h:164
static CISST_EXPORT const ThisType & Identity()
vctAngleRotation2 ThisType
Definition vctAngleRotation2.h:49
ThisType & FromNormalized(const AngleType angle)
Definition vctAngleRotation2.h:223
void ThrowUnlessIsNormalized(const _inputType &input) const CISST_THROW(std
Definition vctAngleRotation2.h:68
ThisType & NormalizedSelf(void)
Definition vctAngleRotation2.h:296
vctAngleRotation2()
Definition vctAngleRotation2.h:78
ThisType & FromNormalized(const vctMatrixRotation2Base< _containerType > &matrixRotation)
Definition vctAngleRotation2.h:233
@ DIMENSION
Definition vctAngleRotation2.h:48
ThisType & FromRaw(const AngleType angle)
Definition vctAngleRotation2.h:251
void ThrowUnlessIsNormalized(void) const CISST_THROW(std
Definition vctAngleRotation2.h:57
vctAngleRotation2(const AngleType angle, bool normalizeInput)
Definition vctAngleRotation2.h:136
void DeSerializeRaw(std::istream &inputStream)
Definition vctAngleRotation2.h:367
ThisType Inverse(void) const
Definition vctAngleRotation2.h:287
void ToStream(std::ostream &outputStream) const
Definition vctAngleRotation2.h:344
vctAngleRotation2(const vctMatrixRotation2Base< _containerType > &matrixRotation, bool normalizeInput)
Definition vctAngleRotation2.h:148
vctAngleRotation2(const vctMatrixRotation2Base< _containerType > &matrixRotation) CISST_THROW(std
Definition vctAngleRotation2.h:106
ThisType & NormalizedOf(const ThisType &otherRotation)
Definition vctAngleRotation2.h:309
Define a rotation matrix for a space of dimension 2.
Definition vctMatrixRotation2Base.h:56
ThisType Normalized(void) const
Definition vctMatrixRotation2Base.h:617
Declaration of various constants.
const double cmnPI
Definition cmnConstants.h:38
void cmnDeSerializeRaw(std::istream &inputStream, _elementType &data) CISST_THROW(std
Definition cmnDeSerializer.h:82
#define CISST_EXPORT
Definition cmnExportMacros.h:50
#define CMN_UNUSED(argument)
Definition cmnPortability.h:497
#define CISST_THROW(exceptionParameter)
Somewhat portable compilation warning message. This works with very recent versions of gcc (4....
Definition cmnPortability.h:559
Declaration of cmnSerializer and functions cmnSerializeRaw.
void cmnSerializeRaw(std::ostream &outputStream, const _elementType &data) CISST_THROW(std
Definition cmnSerializer.h:76
void cmnThrow(const _exceptionType &except, cmnLogLevel lod=CMN_LOG_LEVEL_INIT_ERROR)
Definition cmnThrow.h:76
std::ostream & operator<<(std::ostream &output, const vctAngleRotation2 &angleRotation)
Definition vctAngleRotation2.h:376
vctDynamicConstMatrixBase< _matrixOwnerType, _elementType > ThisType
Definition vctDynamicConstMatrixBase.h:86
Macros to export the symbols of cisstVector (in a Dll).
Declaration of vctFixedSizeVector.