iMSTK
Interactive Medical Simulation Toolkit
imstkPlane.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 "imstkPlane.h"
8 #include "imstkLogger.h"
9 
10 namespace imstk
11 {
12 Vec3d
13 Plane::getNormal(DataType type /* = DataType::PostTransform */)
14 {
15  if (type == DataType::PostTransform)
16  {
18  return m_normalPostTransform;
19  }
20  return m_normal;
21 }
22 
23 void
24 Plane::setNormal(const Vec3d n)
25 {
26  // A normal with no direction would destroy the basis
27  // of the transform
28  if (m_normal == n || n.norm() == 0.0)
29  {
30  return;
31  }
32  m_normal = n.normalized();
33  m_transformApplied = false;
34  this->postModified();
35 }
36 
37 void
38 Plane::setNormal(const double x, const double y, const double z)
39 {
40  this->setNormal(Vec3d(x, y, z));
41 }
42 
43 double
45 {
46  return m_width;
47 }
48 
49 void
50 Plane::setWidth(const double w)
51 {
52  if (m_width == w || m_width <= 0.0)
53  {
54  return;
55  }
56  m_width = w;
57  this->postModified();
58 }
59 
60 void
61 Plane::applyTransform(const Mat4d& m)
62 {
64  this->postModified();
65 }
66 
67 void
69 {
70  if (m_transformApplied)
71  {
72  return;
73  }
75  m_normalPostTransform = m_orientation._transformVector(m_normal);
76  m_transformApplied = true;
77 }
78 
79 void
80 Plane::computeBoundingBox(Vec3d& min, Vec3d& max, const double imstkNotUsed(paddingPercent))
81 {
83 
84  Vec3d p1 = m_position + Vec3d(0.5, 0.0, 0.5);
85  Vec3d p2 = m_position + Vec3d(0.5, 0.0, -0.5);
86  Vec3d p3 = m_position + Vec3d(-0.5, 0.0, 0.5);
87  Vec3d p4 = m_position + Vec3d(-0.5, 0.0, -0.5);
88 
89  p1 = (m_transform * Vec4d(p1[0], p1[1], p1[2], 1.0)).head<3>();
90  p2 = (m_transform * Vec4d(p2[0], p2[1], p2[2], 1.0)).head<3>();
91  p3 = (m_transform * Vec4d(p3[0], p3[1], p3[2], 1.0)).head<3>();
92  p4 = (m_transform * Vec4d(p4[0], p4[1], p4[2], 1.0)).head<3>();
93 
94  min = p1.cwiseMin(p2);
95  min = min.cwiseMin(p3);
96  min = min.cwiseMin(p4);
97 
98  max = p1.cwiseMax(p2);
99  max = max.cwiseMax(p3);
100  max = max.cwiseMax(p4);
101 }
102 } // namespace imstk
Mat4d m_transform
Transformation matrix.
void updatePostTransformData() const override
Apply the global transform to the local parameters producing post transformed parameters.
Compound Geometry.
void postModified()
Post modified event.
Vec3d getNormal(DataType type=DataType::PostTransform)
Get/Set the normal to the plane.
Definition: imstkPlane.cpp:13
void applyTransform(const Mat4d &m) override
Apply a user transform directly to (pre-transformed) parameters producing new parameters.
Definition: imstkPlane.cpp:61
double m_width
Width of plane, only used for visual purposes.
Definition: imstkPlane.h:78
void computeBoundingBox(Vec3d &min, Vec3d &max, const double paddingPercent=0.0) override
Get the min, max of the AABB around the plane.
Definition: imstkPlane.cpp:80
void updatePostTransformData() const override
Update the Plane parameters applying the latest transform.
Definition: imstkPlane.cpp:68
double getWidth()
Get/Set the width of the plane, only used for visual purposes.
Definition: imstkPlane.cpp:44
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