iMSTK
Interactive Medical Simulation Toolkit
imstkAnalyticalGeometry.cpp
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #include "imstkAnalyticalGeometry.h"
8 #include "imstkLogger.h"
9 
10 namespace imstk
11 {
12 AnalyticalGeometry::AnalyticalGeometry() : ImplicitGeometry(),
13  m_position(Vec3d::Zero()), m_positionPostTransform(Vec3d::Zero()),
14  m_orientation(Quatd::Identity()), m_orientationPostTransform(Quatd::Identity())
15 {
16 }
17 
18 void
20 {
21  LOG(INFO) << "Position: (" <<
22  m_position.x() << ", " <<
23  m_position.y() << ", " <<
24  m_position.z() << ")";
25  LOG(INFO) << "Orientation: (" <<
26  m_orientation.x() << ", " <<
27  m_orientation.y() << ", " <<
28  m_orientation.z() << ", " <<
29  m_orientation.w();
30 }
31 
32 Vec3d
33 AnalyticalGeometry::getPosition(DataType type /* = DataType::PostTransform */)
34 {
35  if (type == DataType::PostTransform)
36  {
37  this->updatePostTransformData();
38  return m_positionPostTransform;
39  }
40  return m_position;
41 }
42 
43 void
45 {
46  if (m_position == p)
47  {
48  return;
49  }
50 
51  m_position = p;
52  m_transformApplied = false;
53  this->postModified();
54 }
55 
56 void
57 AnalyticalGeometry::setPosition(const double x, const double y, const double z)
58 {
59  this->setPosition(Vec3d(x, y, z));
60 }
61 
62 Quatd
64 {
65  if (type == DataType::PostTransform)
66  {
67  this->updatePostTransformData();
68  return m_orientationPostTransform;
69  }
70  return m_orientation;
71 }
72 
73 void
75 {
76  // Two quats can represent the same rotation, check coeffs
77  // for true difference
78  if (m_orientation.coeffs() == r.coeffs())
79  {
80  return;
81  }
82 
83  m_orientation = r;
84  m_transformApplied = false;
85  this->postModified();
86 }
87 
88 void
90 {
91  this->setPosition((m * Vec4d(m_position[0], m_position[1], m_position[2], 1.0)).head<3>());
92  this->setOrientation((m_orientation * Quatd(m.block<3, 3>(0, 0))).normalized());
93 }
94 
95 void
97 {
98  m_positionPostTransform = (m_transform * Vec4d(m_position[0], m_position[1], m_position[2], 1.0)).head<3>();
99  m_orientationPostTransform = (Quatd(getRotation()) * m_orientation).normalized();
100 }
101 } // namespace imstk
Quatd getOrientation(DataType type=DataType::PostTransform)
Get the local or global orientation (post transformed)
void updatePostTransformData() const override
Apply the global transform to the local parameters producing post transformed parameters.
Vec3d getPosition(DataType type=DataType::PostTransform)
Get the local or global position (post transformed)
Compound Geometry.
void print() const override
Print.
void setPosition(const Vec3d p)
Set the local position.
void setOrientation(const Quatd r)
Set the local orientation.
void applyTransform(const Mat4d &m) override
Apply a user transform directly to (pre-transformed) parameters producing new parameters.
DataType
Enumeration for the data to retrieve PreTransform for data where transform matrix is not applied Po...
Definition: imstkGeometry.h:41