Commit 6200d2d1 authored by Nghia Truong's avatar Nghia Truong

REFAC: Add computeBoundingBox to geometry class; add a unique ID to each...

REFAC: Add computeBoundingBox to geometry class; add a unique ID to each generated gemetry object; and fix race condition in pointset while accessing vertex positions by immediately update transformation upon initializing positions
parent 3a53b3e8
......@@ -114,6 +114,7 @@ PointSet::setVertexPositions(const StdVectorOfVec3d& vertices)
m_vertexPositions = vertices;
m_dataModified = true;
m_transformApplied = false;
this->updatePostTransformData();
}
else
{
......@@ -282,7 +283,6 @@ PointSet::updatePostTransformData()
if (m_vertexPositionsPostTransform.size() != m_vertexPositions.size())
{
m_vertexPositionsPostTransform.clear();
m_vertexPositionsPostTransform.resize(m_vertexPositions.size());
}
for (size_t i = 0; i < m_vertexPositions.size(); ++i)
......
......@@ -20,6 +20,7 @@
=========================================================================*/
#include "imstkGeometry.h"
#include "imstkLogUtility.h"
namespace imstk
{
......@@ -35,6 +36,12 @@ Geometry::print() const
LOG(INFO) << "Rotation:\n" << r;
}
void
Geometry::computeBoundingBox(Vec3d& /*min*/, Vec3d& /*max*/, const double /* paddingPercent = 0.0*/) const
{
LOG(FATAL) << "Call to unimplemented function";
}
void
Geometry::translate(const Vec3d& t, TransformType type)
{
......@@ -240,4 +247,22 @@ Geometry::isMesh() const
|| this->m_type == Type::LineMesh
) ? true : false;
}
// Static counter
unsigned int
Geometry::s_NumGeneratedGegometries;
// Static counter mutex lock
ParallelUtils::SpinLock
Geometry::s_RegistryLock;
unsigned int
Geometry::getUniqueID()
{
s_RegistryLock.lock();
const auto idx = s_NumGeneratedGegometries;
++s_NumGeneratedGegometries;
s_RegistryLock.unlock();
return idx;
}
} // imstk
......@@ -25,6 +25,7 @@
#include "imstkMath.h"
#include "imstkRenderMaterial.h"
#include "imstkParallelUtils.h"
namespace imstk
{
......@@ -81,12 +82,12 @@ public:
///
/// \brief Constructor
///
Geometry(Type type) : m_type(type) {}
Geometry(const Type type) : m_geometryIdx(Geometry::getUniqueID()), m_type(type) {}
///
/// \brief Destructor
///
virtual ~Geometry() {}
virtual ~Geometry() = default;
///
/// \brief Print
......@@ -98,6 +99,11 @@ public:
///
virtual double getVolume() const = 0;
///
/// \brief Compute the bounding box for the geometry
///
virtual void computeBoundingBox(Vec3d& min, Vec3d& max, const double paddingPercent = 0.0) const;
///
/// \brief Translate the geometry in Cartesian space
///
......@@ -164,7 +170,25 @@ public:
///
bool isMesh() const;
///
/// \brief Get the global (unique) index of the geometry
///
unsigned int getGlobalIndex() const { return m_geometryIdx; }
///
/// \brief Get a pointer to geometry that has been registered globally
///
static unsigned int getTotalNumberGeometries() { return s_NumGeneratedGegometries; }
protected:
///
/// \brief Get a unique ID for the object
///
static unsigned int getUniqueID();
static ParallelUtils::SpinLock s_RegistryLock; ///> Mutex lock for thread-safe registry modification
static unsigned int s_NumGeneratedGegometries; ///> Total number of geometries that have been created in this program
friend class VTKRenderer;
friend class VTKRenderDelegate;
......@@ -178,8 +202,11 @@ protected:
virtual void applyScaling(const double s) = 0;
virtual void updatePostTransformData() = 0;
Type m_type; ///> Geometry type
const unsigned int m_geometryIdx = 0; ///> Unique ID assigned to each geometry upon construction
const Type m_type; ///> Type of geometry
ParallelUtils::SpinLock m_dataLock;
ParallelUtils::SpinLock m_transformLock;
bool m_dataModified = false;
bool m_transformModified = false;
bool m_transformApplied = true;
......
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