iMSTK
Interactive Medical Simulation Toolkit
imstkCapsule.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 {
22 {
23 public:
24  Capsule(const Vec3d& pos = Vec3d(0.0, 0.0, 0.0), const double radius = 0.5,
25  const double length = 1.0, const Quatd orientation = Quatd::Identity()) :
27  {
28  setPosition(pos);
29  setOrientation(orientation);
30  setRadius(radius);
31  setLength(length);
33  }
34 
35  ~Capsule() override = default;
36 
37  IMSTK_TYPE_NAME(Capsule)
38 
39 
40  void print() const override;
43 
47  double getVolume() override { return PI * m_radius * m_radius * (m_length + 4.0 / 3.0 * m_radius); }
48 
52  double getRadius(DataType type = DataType::PostTransform);
53  void setRadius(const double r);
55 
59  double getLength(DataType type = DataType::PostTransform);
60  void setLength(const double l);
62 
66  double getFunctionValue(const Vec3d& x) const override;
67 
71  void computeBoundingBox(Vec3d& min, Vec3d& max, const double paddingPercent);
72 
76  void updatePostTransformData() const override;
77 
82  std::unique_ptr<Capsule> clone()
83  {
84  return std::unique_ptr<Capsule>(cloneImplementation());
85  }
86 
87 protected:
88  void applyTransform(const Mat4d& m) override;
89 
90  double m_radius = 1.0;
91  mutable double m_radiusPostTransform = 1.0;
92  double m_length = 1.0;
93  mutable double m_lengthPostTransform = 1.0;
94 
95 private:
96  Capsule* cloneImplementation() const
97  {
98  return new Capsule(*this);
99  }
100 };
101 } // namespace imstk
void print() const override
Print the capsule info.
double getLength(DataType type=DataType::PostTransform)
Get/Set the length of the capsule.
Base class for any analytical geometrical representation.
double getFunctionValue(const Vec3d &x) const override
Returns the signed distance to the capsule.
Compound Geometry.
void applyTransform(const Mat4d &m) override
Apply a user transform directly to (pre-transformed) parameters producing new parameters.
double m_radius
Radius of the hemispheres at the end of the capsule.
Definition: imstkCapsule.h:90
std::unique_ptr< Capsule > clone()
Polymorphic clone, hides the declaration in superclass return own type.
Definition: imstkCapsule.h:82
double m_length
Length between the centers of two hemispheres.
Definition: imstkCapsule.h:92
void setPosition(const Vec3d p)
Set the local position.
void setOrientation(const Quatd r)
Set the local orientation.
double getVolume() override
Returns the volume of the capsule.
Definition: imstkCapsule.h:47
void computeBoundingBox(Vec3d &min, Vec3d &max, const double paddingPercent)
Get the min, max of the AABB around the capsule.
double getRadius(DataType type=DataType::PostTransform)
Get/Set the radius of the capsule.
double m_radiusPostTransform
Radius after transform.
Definition: imstkCapsule.h:91
void updatePostTransformData() const override
Update the Capsule parameters applying the latest transform.
Capsule geometry, default configuration is centered at origin with length running up and down the y a...
Definition: imstkCapsule.h:21
DataType
Enumeration for the data to retrieve PreTransform for data where transform matrix is not applied Po...
Definition: imstkGeometry.h:41
double m_lengthPostTransform
Length after transform.
Definition: imstkCapsule.h:93