Commit ef55f5d5 authored by Nghia Truong's avatar Nghia Truong

ENH: Rewrite bounding box computation API and implement it for sphere

parent e41c3374
......@@ -57,7 +57,7 @@ Sphere::setRadius(const double r)
LOG(WARNING) << "Sphere::setRadius error: radius should be positive.";
return;
}
if (m_radius == r)
if (std::abs(m_radius - r) < 1e-20)
{
return;
}
......@@ -66,6 +66,21 @@ Sphere::setRadius(const double r)
m_transformApplied = false;
}
void
Sphere::computeBoundingBox(Vec3d& lowerCorner, Vec3d& upperCorner, const double paddingPercent)
{
updatePostTransformData();
const Vec3d span = Vec3d(1, 1, 1) * m_radiusPostTransform;
lowerCorner = m_positionPostTransform - span;
upperCorner = m_positionPostTransform + span;
if (paddingPercent > 0.0)
{
const Vec3d range = upperCorner - lowerCorner;
lowerCorner = lowerCorner - range * (paddingPercent / 100.0);
upperCorner = upperCorner + range * (paddingPercent / 100.0);
}
}
void
Sphere::applyScaling(const double s)
{
......
......@@ -59,6 +59,11 @@ public:
///
void setRadius(const double r);
///
/// \brief Compute the bounding box for the geometry
///
virtual void computeBoundingBox(Vec3d& lowerCorner, Vec3d& upperCorner, const double paddingPercent = 0.0) override;
protected:
friend class VTKSphereRenderDelegate;
......
......@@ -53,14 +53,15 @@ PointSet::print() const
}
void
PointSet::computeBoundingBox(Vec3d& min, Vec3d& max, const double paddingPercent) const
PointSet::computeBoundingBox(Vec3d& lowerCorner, Vec3d& upperCorner, const double paddingPercent)
{
ParallelUtils::findAABB(m_vertexPositions, min, max);
updatePostTransformData();
ParallelUtils::findAABB(m_vertexPositions, lowerCorner, upperCorner);
if (paddingPercent > 0.0)
{
Vec3d range = max - min;
min = min - range * (paddingPercent / 100.0);
max = max + range * (paddingPercent / 100.0);
const Vec3d range = upperCorner - lowerCorner;
lowerCorner = lowerCorner - range * (paddingPercent / 100.0);
upperCorner = upperCorner + range * (paddingPercent / 100.0);
}
}
......
......@@ -64,7 +64,7 @@ public:
///
/// \brief Compute the bounding box for the entire mesh
///
virtual void computeBoundingBox(Vec3d& min, Vec3d& max, const double paddingPercent = 0.0) const override;
virtual void computeBoundingBox(Vec3d& lowerCorner, Vec3d& upperCorner, const double paddingPercent = 0.0) override;
// Accessors
......
......@@ -63,7 +63,7 @@ Geometry::print() const
}
void
Geometry::computeBoundingBox(Vec3d& /*min*/, Vec3d& /*max*/, const double /* paddingPercent = 0.0*/) const
Geometry::computeBoundingBox(Vec3d&, Vec3d&, const double)
{
LOG(FATAL) << "computeBoundingBox() must be called from an instance of a specific geometry class";
}
......
......@@ -103,7 +103,7 @@ public:
///
/// \brief Compute the bounding box for the geometry
///
virtual void computeBoundingBox(Vec3d& min, Vec3d& max, const double paddingPercent = 0.0) const;
virtual void computeBoundingBox(Vec3d& lowerCorner, Vec3d& upperCorner, const double paddingPercent = 0.0);
///
/// \brief Translate the geometry in Cartesian space
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment