7 #include "imstkOrientedBox.h" 8 #include "imstkLogger.h" 16 LOG(INFO) <<
"Extent0: " << m_extents[0];
17 LOG(INFO) <<
"Extent1: " << m_extents[1];
18 LOG(INFO) <<
"Extent2: " << m_extents[2];
24 if (type == DataType::PostTransform)
35 if (extents[0] <= 0.0 || extents[1] <= 0.0 || extents[2] <= 0.0)
37 LOG(WARNING) <<
"error: extents should be positive.";
40 if (m_extents == extents)
45 m_transformApplied =
false;
54 m.block<3, 1>(0, 0).norm(),
55 m.block<3, 1>(0, 1).norm(),
56 m.block<3, 1>(0, 2).norm());
64 if (m_transformApplied)
71 m_transformApplied =
true;
81 const Vec3d proj = rot * diff;
85 (std::abs(proj[0]) < extents[0]),
86 (std::abs(proj[1]) < extents[1]),
87 (std::abs(proj[2]) < extents[2])
89 bool isInsideCube = inside[0] && inside[1] && inside[2];
91 double signedDist = 0.0;
95 signedDist = std::numeric_limits<double>::lowest();
96 for (
int i = 0; i < 3; i++)
98 double dist = proj[i];
99 if (dist < extents[i] && dist >= 0.0)
101 const double unsignedDistToSide = (extents[i] - dist);
102 if (-unsignedDistToSide > signedDist)
104 signedDist = -unsignedDistToSide;
107 else if (dist > -extents[i] && dist < 0.0)
109 const double unsignedDistToSide = (extents[i] + dist);
110 if (-unsignedDistToSide > signedDist)
112 signedDist = -unsignedDistToSide;
121 Vec3d axialSignedDists = Vec3d::Zero();
122 for (
int i = 0; i < 3; i++)
124 double dist = proj[i];
127 if (dist >= extents[i] || dist <= -extents[i])
129 axialSignedDists[i] = std::abs(dist) - extents[i];
132 signedDist = axialSignedDists.norm();
159 for (
int i = 1; i < 8; i++)
161 min = min.cwiseMin(pts[i]);
162 max = max.cwiseMax(pts[i]);
void updatePostTransformData() const override
Update the Cube parameters applying the latest transform.
virtual void print() const
Print.
void updatePostTransformData() const override
Apply the global transform to the local parameters producing post transformed parameters.
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)
Vec3d getScaling() const
Get/Set scaling.
Vec3d getExtents(DataType type=DataType::PostTransform)
Returns the extents of the cube.
void postModified()
Post modified event.
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.
Quatd m_orientationPostTransform
orientation once transform is applied
void applyTransform(const Mat4d &m) override
Apply a user transform directly to (pre-transformed) parameters producing new parameters.
Vec3d m_positionPostTransform
position once transform applied
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...