iMSTK
Interactive Medical Simulation Toolkit
imstkOrientedBox.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 {
20 {
21 public:
22  OrientedBox(const Vec3d& pos = Vec3d::Zero(),
23  const Vec3d extents = Vec3d(0.5, 0.5, 0.5),
24  const Quatd& orientation = Quatd::Identity()) : AnalyticalGeometry()
25  {
26  setPosition(pos);
27  setOrientation(orientation);
28  setExtents(extents);
30  }
31 
32  ~OrientedBox() override = default;
33 
34  IMSTK_TYPE_NAME(OrientedBox)
35 
36 
37  void print() const override;
40 
44  double getVolume() override { return m_extents[0] * m_extents[1] * m_extents[2] * 8.0; }
45 
49  Vec3d getExtents(DataType type = DataType::PostTransform);
50 
54  void setExtents(const Vec3d extents);
55 
59  void setExtents(const double x, const double y, const double z) { setExtents(Vec3d(x, y, z)); }
60 
64  double getFunctionValue(const Vec3d& pos) const override;
65 
69  void computeBoundingBox(Vec3d& min, Vec3d& max, const double paddingPercent = 0.0) override;
70 
74  void updatePostTransformData() const override;
75 
80  std::unique_ptr<OrientedBox> clone()
81  {
82  return std::unique_ptr<OrientedBox>(cloneImplementation());
83  }
84 
85 protected:
86  void applyTransform(const Mat4d& m) override;
87 
88  Vec3d m_extents = Vec3d(0.5, 0.5, 0.5); // Half dimensions of the oriented box
89  mutable Vec3d m_extentsPostTransform = Vec3d(0.5, 0.5, 0.5);
90 
91 private:
92  OrientedBox* cloneImplementation() const
93  {
94  return new OrientedBox(*this);
95  }
96 };
97 } // namespace imstk
OrientedBox geometry, specified with extents (half lengths)
Base class for any analytical geometrical representation.
void updatePostTransformData() const override
Update the Cube parameters applying the latest transform.
Vec3d m_extentsPostTransform
Half dimensions of the oriented box once transform applied.
void setExtents(const Vec3d extents)
Sets the extents of the cube (half dimensions)
Compound Geometry.
Vec3d getExtents(DataType type=DataType::PostTransform)
Returns the extents of the cube.
void computeBoundingBox(Vec3d &min, Vec3d &max, const double paddingPercent=0.0) override
Get the min, max of the AABB around the cube.
double getFunctionValue(const Vec3d &pos) const override
Returns signed distance to surface at pos.
void print() const override
Print the cube info.
std::unique_ptr< OrientedBox > clone()
Polymorphic clone, hides the declaration in superclass return own type.
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 cube.
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
void setExtents(const double x, const double y, const double z)
Sets the width of the cube (half dimensions)