SimpleTorusParametrization.h
Go to the documentation of this file.
1 #ifndef SIMPLETORUSPARAMETRIZATION_HEADER
2 #define SIMPLETORUSPARAMETRIZATION_HEADER
3 #include "Torus.h"
4 #include "basic.h"
5 #include <GfxTL/VectorXD.h>
7 #include <GfxTL/MathHelper.h>
8 #include <GfxTL/AABox.h>
9 #include <utility>
10 #include <MiscLib/Vector.h>
11 #include <iostream>
12 
14 {
15 public:
16  SimpleTorusParametrization(const Torus& torus);
17  void Shape(const Torus& torus);
18  const Torus& Shape() const
19  {
20  return *m_torus;
21  }
22  inline void Parameters(const Vec3f& p,
23  std::pair< float, float >* param) const;
24  inline bool InSpace(float u, float v, Vec3f* p) const;
25  inline bool InSpace(float u, float v, Vec3f* p, Vec3f* n) const;
27  float epsilon, bool* uwrap, bool* vwrap) const;
29  float epsilon, size_t uextent, size_t vextent,
30  MiscLib::Vector< int >* componentImg,
31  MiscLib::Vector< std::pair< int, size_t > >* labels) const {}
32  static size_t SerializedSize();
33  void Serialize(std::ostream* o, bool binary) const;
34  void Deserialize(std::istream* i, bool binary);
35 
36 private:
37  const Torus* m_torus;
39 };
40 
42  std::pair< float, float >* param) const
43 {
44  Vec3f s = p - m_torus->Center();
45  float planex = s.dot(m_hcs[0].Data());
46  float planey = s.dot(m_hcs[1].Data());
47  param->first = std::atan2(planey, planex); // major angle
48  float minory = s.dot(m_torus->AxisDirection());
49  float minorx = std::sqrt(planex * planex + planey * planey) - m_torus->MajorRadius();
50  param->second = std::atan2(minory, minorx); // minor angle
51  if (m_torus->IsAppleShaped())
52  {
53  if (abs(param->second) > m_torus->AppleCutOffAngle())
54  param->second = GfxTL::Math< float >::Sign(param->second)
55  * m_torus->AppleCutOffAngle();
56  }
57  if (m_torus->MajorRadius() < m_torus->MinorRadius() * 2)
58  {
59  param->first *= m_torus->MajorRadius() + m_torus->MinorRadius();
60  }
61  else
62  {
63  param->first *= m_torus->MajorRadius();
64  }
65  param->second *= m_torus->MinorRadius();
66 }
67 
68 bool SimpleTorusParametrization::InSpace(float u, float v, Vec3f* p) const
69 {
70  float vangle = v / m_torus->MinorRadius();
71  float minorx = std::cos(vangle);
72  float minory = std::sin(vangle);
73  minorx = m_torus->MinorRadius() * minorx + m_torus->MajorRadius();
74  minory *= m_torus->MinorRadius();
75  Vec3f pp = minorx * Vec3f(m_hcs[0].Data()) + minory * m_torus->AxisDirection();
77  float majorRadius = (m_torus->MajorRadius() < m_torus->MinorRadius() * 2) ?
78  m_torus->MajorRadius() + m_torus->MinorRadius() : m_torus->MajorRadius();
79  float uangle = u / majorRadius;
80  q.RotationRad(uangle, m_torus->AxisDirection()[0], m_torus->AxisDirection()[1],
81  m_torus->AxisDirection()[2]);
82  q.Rotate(pp, p);
83  *p += m_torus->Center();
84  return true;
85 }
86 
88  Vec3f* n) const
89 {
90  float vangle = v / m_torus->MinorRadius();
91  float minorx = std::cos(vangle);
92  float minory = std::sin(vangle);
93  Vec3f nn = minorx * Vec3f(m_hcs[0].Data()) + minory * m_torus->AxisDirection();
94  minorx = m_torus->MinorRadius() * minorx + m_torus->MajorRadius();
95  minory *= m_torus->MinorRadius();
96  Vec3f pp = minorx * Vec3f(m_hcs[0].Data()) + minory * m_torus->AxisDirection();
98  float majorRadius = (m_torus->MajorRadius() < m_torus->MinorRadius() * 2) ?
99  m_torus->MajorRadius() + m_torus->MinorRadius() : m_torus->MajorRadius();
100  float uangle = u / majorRadius;
101  q.RotationRad(uangle, m_torus->AxisDirection()[0], m_torus->AxisDirection()[1],
102  m_torus->AxisDirection()[2]);
103  q.Rotate(pp, p);
104  q.Rotate(nn, n);
105  *p += m_torus->Center();
106  return true;
107 }
108 
109 #endif
Torus::IsAppleShaped
bool IsAppleShaped() const
Definition: Torus.h:59
GfxTL::sqrt
VectorXD< D, T > sqrt(const VectorXD< D, T > &a)
Definition: VectorXD.h:662
GfxTL::HyperplaneCoordinateSystem< float, 3 >
SimpleTorusParametrization::WrapBitmap
void WrapBitmap(const GfxTL::AABox< GfxTL::Vector2Df > &bbox, float epsilon, bool *uwrap, bool *vwrap) const
Definition: SimpleTorusParametrization.cpp:16
Vector.h
Torus::MinorRadius
const float MinorRadius() const
Definition: Torus.h:42
Vec3f
Definition: basic.h:16
Torus.h
Torus
Definition: Torus.h:18
SimpleTorusParametrization::Shape
const Torus & Shape() const
Definition: SimpleTorusParametrization.h:18
GfxTL::Quaternion
Definition: VectorXD.h:707
SimpleTorusParametrization::InSpace
bool InSpace(float u, float v, Vec3f *p) const
Definition: SimpleTorusParametrization.h:68
SimpleTorusParametrization::Parameters
void Parameters(const Vec3f &p, std::pair< float, float > *param) const
Definition: SimpleTorusParametrization.h:41
MiscLib::Vector< int >
VectorXD.h
GfxTL::Math::Sign
static ScalarT Sign(ScalarT s)
Definition: MathHelper.h:23
Torus::AxisDirection
const Vec3f & AxisDirection() const
Definition: Torus.h:38
armarx::abs
std::vector< T > abs(const std::vector< T > &v)
Definition: VectorHelpers.h:253
AABox.h
HyperplaneCoordinateSystem.h
SimpleTorusParametrization::Serialize
void Serialize(std::ostream *o, bool binary) const
Definition: SimpleTorusParametrization.cpp:44
SimpleTorusParametrization
Definition: SimpleTorusParametrization.h:13
q
#define q
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
SimpleTorusParametrization::WrapComponents
void WrapComponents(const GfxTL::AABox< GfxTL::Vector2Df > &bbox, float epsilon, size_t uextent, size_t vextent, MiscLib::Vector< int > *componentImg, MiscLib::Vector< std::pair< int, size_t > > *labels) const
Definition: SimpleTorusParametrization.h:28
basic.h
GfxTL::Vec3f
VectorXD< 3, float > Vec3f
Definition: VectorXD.h:691
Torus::MajorRadius
const float MajorRadius() const
Definition: Torus.h:46
SimpleTorusParametrization::SerializedSize
static size_t SerializedSize()
Definition: SimpleTorusParametrization.cpp:39
MathHelper.h
Torus::Center
const Vec3f & Center() const
Definition: Torus.h:34
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
GfxTL::AABox
Definition: AABox.h:18
SimpleTorusParametrization::Deserialize
void Deserialize(std::istream *i, bool binary)
Definition: SimpleTorusParametrization.cpp:58
Torus::AppleCutOffAngle
float AppleCutOffAngle() const
Definition: Torus.h:63
SimpleTorusParametrization::SimpleTorusParametrization
SimpleTorusParametrization(const Torus &torus)
Definition: SimpleTorusParametrization.cpp:3