iMSTK
Interactive Medical Simulation Toolkit
imstkPlane.h
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 #pragma once
8 
9 #include "imstkAnalyticalGeometry.h"
10 #include "imstkMacros.h"
11 
12 namespace imstk
13 {
19 class Plane : public AnalyticalGeometry
20 {
21 public:
22  Plane(const Vec3d& pos = Vec3d(0.0, 0.0, 0.0), const Vec3d& normal = Vec3d(0.0, 1.0, 0.0)) :
24  {
25  setPosition(pos);
26  setNormal(normal.normalized());
28  }
29 
30  ~Plane() override = default;
31 
32  IMSTK_TYPE_NAME(Plane)
33 
34 
35  Vec3d getNormal(DataType type = DataType::PostTransform);
38  void setNormal(const Vec3d n);
39  void setNormal(const double x, const double y, const double z);
41 
45  double getWidth();
46  void setWidth(const double w);
48 
52  double getFunctionValue(const Vec3d& pos) const override { return m_normalPostTransform.dot(pos - m_positionPostTransform); }
53 
57  void computeBoundingBox(Vec3d& min, Vec3d& max, const double paddingPercent = 0.0) override;
58 
62  void updatePostTransformData() const override;
63 
68  std::unique_ptr<Plane> clone()
69  {
70  return std::unique_ptr<Plane>(cloneImplementation());
71  }
72 
73 protected:
74  void applyTransform(const Mat4d& m) override;
75 
76  Vec3d m_normal;
77  mutable Vec3d m_normalPostTransform;
78  double m_width;
79 
80 private:
81  Plane* cloneImplementation() const
82  {
83  return new Plane(*this);
84  }
85 };
86 } // namespace imstk
Base class for any analytical geometrical representation.
Represents and infinite plane, width can be used for visual purposes.
Definition: imstkPlane.h:19
Compound Geometry.
double getFunctionValue(const Vec3d &pos) const override
Returns signed distance to surface at pos.
Definition: imstkPlane.h:52
std::unique_ptr< Plane > clone()
Polymorphic clone, hides the declaration in superclass return own type.
Definition: imstkPlane.h:68
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 setPosition(const Vec3d p)
Set the local position.
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
Vec3d m_positionPostTransform
position once transform applied
DataType
Enumeration for the data to retrieve PreTransform for data where transform matrix is not applied Po...
Definition: imstkGeometry.h:41