cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
6  Author(s): Anton Deguet
7  Created on: 2005-01-13
8 
9  (C) Copyright 2005-2007 Johns Hopkins University (JHU), All Rights
10  Reserved.
11 
12 --- begin cisst license - do not edit ---
13 
14 This software is provided "as is" under an open source license, with
15 no warranty. The complete license can be found in license.txt and
16 http://www.cisst.org/cisst/license.txt.
17 
18 --- end cisst license ---
19 */
20 
21 #pragma once
22 #ifndef _vctAngleRotation2_h
23 #define _vctAngleRotation2_h
24 
32 
34 #include <cisstVector/vctExport.h>
35 
47 {
48 public:
50  enum {DIMENSION = 2};
53 
54 protected:
55  AngleType AngleMember;
56 
57 
59  inline void ThrowUnlessIsNormalized(void) const throw(std::runtime_error) {
60  if (! IsNormalized()) {
61  cmnThrow(std::runtime_error("vctAngleRotation2: This rotation is not normalized"));
62  }
63  }
64 
69  template <class _inputType>
70  inline void ThrowUnlessIsNormalized(const _inputType & input) const throw(std::runtime_error) {
71  if (! input.IsNormalized()) {
72  cmnThrow(std::runtime_error("vctAngleRotation2: Input is not normalized"));
73  }
74  }
75 
76 
77  public:
78 
81  AngleMember(0.0)
82  {}
83 
84 
99  inline explicit
100  vctAngleRotation2(const AngleType angle)
101  throw(std::runtime_error)
102  {
103  From(angle);
104  }
105 
107  template <class _containerType>
109  throw(std::runtime_error)
110  {
111  From(matrixRotation);
112  }
114 
115 
138  inline vctAngleRotation2(const AngleType angle,
139  bool normalizeInput)
140  {
141  if (normalizeInput) {
142  FromNormalized(angle);
143  } else {
144  FromRaw(angle);
145  }
146  }
147 
149  template <class _containerType>
151  bool normalizeInput)
152  {
153  if (normalizeInput) {
154  FromNormalized(matrixRotation);
155  } else {
156  FromRaw(matrixRotation);
157  }
158  }
159 
160 
163  static CISST_EXPORT const ThisType & Identity();
164 
165 
166  inline const AngleType & Angle(void) const {
167  return this->AngleMember;
168  }
169 
170  inline AngleType & Angle(void) {
171  return this->AngleMember;
172  }
173 
174 
175 
189 
191  inline ThisType &
192  From(const AngleType angle)
193  throw(std::runtime_error)
194  {
195  this->AngleMember = angle;
196  // this->ThrowUnlessIsNormalized();
197  return *this;
198  }
199 
201  template <class _containerType>
202  inline ThisType &
204  throw(std::runtime_error)
205  {
206  this->ThrowUnlessIsNormalized(matrixRotation);
207  this->AngleMember = atan2(matrixRotation.Element(0, 1), matrixRotation.Element(0, 0));
208  return *this;
209  }
211 
212 
222 
224  inline ThisType &
225  FromNormalized(const AngleType angle)
226  {
227  this->AngleMember = angle;
228  this->NormalizedSelf();
229  return *this;
230  }
231 
233  template <class _containerType>
234  inline ThisType &
236  return FromRaw(matrixRotation.Normalized());
237  }
238 
240 
250 
252  inline ThisType &
253  FromRaw(const AngleType angle)
254  {
255  this->AngleMember = angle;
256  return *this;
257  }
258 
260  template <class _containerType>
261  inline ThisType &
263  AngleMember = atan2(matrixRotation.Element(0, 1), matrixRotation.Element(0, 0));
264  return *this;
265  }
266 
268 
269 
274  inline ThisType & InverseSelf(void) {
275  AngleMember = 2 * cmnPI - AngleMember;
276  return *this;
277  }
278 
281  inline ThisType & InverseOf(const ThisType & otherRotation) {
282  AngleMember = 2 * cmnPI - otherRotation.Angle();
283  return *this;
284  }
285 
289  inline ThisType Inverse(void) const {
290  ThisType result;
291  result.Angle() = 2 * cmnPI - this->Angle();
292  return result;
293  }
294 
295 
298  inline ThisType & NormalizedSelf(void) {
299  AngleMember = fmod(AngleMember, 2.0 * cmnPI);
300  if (AngleMember < 0.0) {
301  AngleMember += (2.0 * cmnPI);
302  }
303  return *this;
304  }
305 
311  inline ThisType & NormalizedOf(const ThisType & otherRotation) {
312  AngleMember = otherRotation.Angle();
313  return *this;
314  }
315 
319  inline ThisType Normalized(void) const {
320  ThisType result(*this);
321  result.NormalizedSelf();
322  return result;
323  }
324 
334  inline bool IsNormalized(AngleType CMN_UNUSED(tolerance) = TypeTraits::Tolerance()) const {
335  return true;
336  }
337 
338 
339  std::string ToString(void) const {
340  std::stringstream outputStream;
341  ToStream(outputStream);
342  return outputStream.str();
343  }
344 
346  inline void ToStream(std::ostream & outputStream) const {
347  outputStream << "Angle: "
348  << std::endl
349  << this->Angle();
350  }
351 
353  void ToStreamRaw(std::ostream & outputStream, const char CMN_UNUSED(delimiter) = ' ',
354  bool headerOnly = false, const std::string & headerPrefix = "") const {
355  if (headerOnly) {
356  outputStream << headerPrefix << "angle";
357  } else {
358  outputStream << this->Angle();
359  }
360  }
361 
363  void SerializeRaw(std::ostream & outputStream) const
364  {
365  cmnSerializeRaw(outputStream, this->Angle());
366  }
367 
369  void DeSerializeRaw(std::istream & inputStream)
370  {
371  cmnDeSerializeRaw(inputStream, this->Angle());
372  }
373 };
374 
375 
377 inline
378 std::ostream & operator << (std::ostream & output,
379  const vctAngleRotation2 & angleRotation) {
380  angleRotation.ToStream(output);
381  return output;
382 }
383 
384 
385 #endif // _vctAngleRotation2_h
386 
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
cmnTypeTraits< AngleType > TypeTraits
Definition: vctAngleRotation2.h:52
Define a rotation based on an angle for a space of dimension 2.
Definition: vctAngleRotation2.h:46
AngleType & Angle(void)
Definition: vctAngleRotation2.h:170
VCT_CONTAINER_TRAITS_TYPEDEFS(double)
#define CMN_UNUSED(argument)
Definition: cmnPortability.h:479
ThisType Normalized(void) const
Definition: vctMatrixRotation2Base.h:619
vctAngleRotation2(const vctMatrixRotation2Base< _containerType > &matrixRotation)
Definition: vctAngleRotation2.h:108
Declaration of cmnSerializer and functions cmnSerializeRaw.
static Type Tolerance(void)
Definition: cmnTypeTraits.h:170
ThisType & FromNormalized(const vctMatrixRotation2Base< _containerType > &matrixRotation)
Definition: vctAngleRotation2.h:235
std::string ToString(void) const
Definition: vctAngleRotation2.h:339
ThisType & InverseOf(const ThisType &otherRotation)
Definition: vctAngleRotation2.h:281
vctAngleRotation2(const vctMatrixRotation2Base< _containerType > &matrixRotation, bool normalizeInput)
Definition: vctAngleRotation2.h:150
Declaration of various constants.
void ThrowUnlessIsNormalized(void) const
Definition: vctAngleRotation2.h:59
ThisType Inverse(void) const
Definition: vctAngleRotation2.h:289
vctAngleRotation2(const AngleType angle)
Definition: vctAngleRotation2.h:100
vctAngleRotation2()
Definition: vctAngleRotation2.h:80
void SerializeRaw(std::ostream &outputStream) const
Definition: vctAngleRotation2.h:363
ThisType & NormalizedOf(const ThisType &otherRotation)
Definition: vctAngleRotation2.h:311
Definition: vctAngleRotation2.h:50
AngleType AngleMember
Definition: vctAngleRotation2.h:55
Declaration of vctFixedSizeVector.
ThisType & InverseSelf(void)
Definition: vctAngleRotation2.h:274
ThisType & FromRaw(const AngleType angle)
Definition: vctAngleRotation2.h:253
void cmnDeSerializeRaw(std::istream &inputStream, _elementType &data)
Definition: cmnDeSerializer.h:82
Define a rotation matrix for a space of dimension 2.
Definition: vctForwardDeclarations.h:227
ThisType & From(const vctMatrixRotation2Base< _containerType > &matrixRotation)
Definition: vctAngleRotation2.h:203
const AngleType & Angle(void) const
Definition: vctAngleRotation2.h:166
void cmnSerializeRaw(std::ostream &outputStream, const _elementType &data)
Definition: cmnSerializer.h:78
vctAngleRotation2 ThisType
Definition: vctAngleRotation2.h:51
vctAngleRotation2(const AngleType angle, bool normalizeInput)
Definition: vctAngleRotation2.h:138
#define cmnThrow(a)
Definition: MinimalCmn.h:4
ThisType Normalized(void) const
Definition: vctAngleRotation2.h:319
ThisType & FromRaw(const vctMatrixRotation2Base< _containerType > &matrixRotation)
Definition: vctAngleRotation2.h:262
ThisType & FromNormalized(const AngleType angle)
Definition: vctAngleRotation2.h:225
ThisType & NormalizedSelf(void)
Definition: vctAngleRotation2.h:298
static CISST_EXPORT const ThisType & Identity()
std::ostream & operator<<(std::ostream &output, const vctAngleRotation2 &angleRotation)
Definition: vctAngleRotation2.h:378
void ToStreamRaw(std::ostream &outputStream, const char CMN_UNUSED(delimiter)= ' ', bool headerOnly=false, const std::string &headerPrefix="") const
Definition: vctAngleRotation2.h:353
void ToStream(std::ostream &outputStream) const
Definition: vctAngleRotation2.h:346
void DeSerializeRaw(std::istream &inputStream)
Definition: vctAngleRotation2.h:369
Macros to export the symbols of cisstVector (in a Dll).
A collection of useful information about the C++ basic types, represented in a generic programming wa...
Definition: cmnTypeTraits.h:155
void ThrowUnlessIsNormalized(const _inputType &input) const
Definition: vctAngleRotation2.h:70
const double cmnPI
Definition: cmnConstants.h:38
ThisType & From(const AngleType angle)
Definition: vctAngleRotation2.h:192
bool IsNormalized(AngleType CMN_UNUSED(tolerance)=TypeTraits::Tolerance()) const
Definition: vctAngleRotation2.h:334