Commit 1ec0fe1d authored by Sreekanth Arikatla's avatar Sreekanth Arikatla

Merge branch 'RefactorGeometry' into 'master'

Refactor Geometry

See merge request !347
parents c2f5edb6 a510c694
Pipeline #142145 passed with stage
in 0 seconds
......@@ -21,7 +21,7 @@
#include "imstkSimulationManager.h"
#include "imstkSceneObject.h"
#include "imstkDebugGeometry.h"
#include "imstkDebugRenderGeometry.h"
#include "imstkAPIUtilities.h"
#include "imstkVTKViewer.h"
#include "imstkVTKTextStatusManager.h"
......
......@@ -21,7 +21,7 @@
#include "imstkSimulationManager.h"
#include "imstkSceneObject.h"
#include "imstkDebugGeometry.h"
#include "imstkDebugRenderGeometry.h"
#include "imstkAPIUtilities.h"
#include "imstkLooseOctree.h"
#include "imstkVTKViewer.h"
......
......@@ -24,7 +24,7 @@
#include "imstkGeometry.h"
#include "imstkPointSet.h"
#include "imstkSurfaceMesh.h"
#include "imstkDebugGeometry.h"
#include "imstkDebugRenderGeometry.h"
namespace imstk
{
......
......@@ -35,11 +35,6 @@ class AnalyticalGeometry : public Geometry
{
public:
///
/// \brief Destructor
///
virtual ~AnalyticalGeometry() = default;
///
/// \brief Print
///
......@@ -62,7 +57,7 @@ public:
protected:
AnalyticalGeometry(Type type) : Geometry(type) {}
AnalyticalGeometry(Type type, const std::string name = std::string("")) : Geometry(type, name) {}
void applyTranslation(const Vec3d t) override;
void applyRotation(const Mat3d r) override;
......
......@@ -37,12 +37,7 @@ public:
///
/// \brief Constructor
///
Capsule() : AnalyticalGeometry(Type::Capsule) {}
///
/// \brief Default destructor
///
~Capsule() = default;
Capsule(const std::string name = std::string("")) : AnalyticalGeometry(Type::Capsule, name) {}
///
/// \brief Print the capsule info
......
......@@ -34,9 +34,7 @@ class Cube : public AnalyticalGeometry
{
public:
Cube() : AnalyticalGeometry(Type::Cube) {}
~Cube() = default;
Cube(const std::string name = std::string("")) : AnalyticalGeometry(Type::Cube, name) {}
///
/// \brief Print the cube info
......
......@@ -37,12 +37,7 @@ public:
///
/// \brief Constructor
///
Cylinder() : AnalyticalGeometry(Type::Cylinder) {}
///
/// \brief Default destructor
///
~Cylinder() = default;
Cylinder(const std::string name = std::string("")) : AnalyticalGeometry(Type::Cylinder, name) {}
///
/// \brief Print the cylinder info
......
......@@ -37,12 +37,7 @@ public:
///
/// \brief Constructor
///
Plane() : AnalyticalGeometry(Type::Plane) {}
///
/// \brief Default destructor
///
~Plane() = default;
Plane(const std::string name = std::string("")) : AnalyticalGeometry(Type::Plane, name) {}
///
/// \brief Print the plane info
......
......@@ -37,12 +37,7 @@ public:
///
/// \brief Constructor
///
Sphere() : AnalyticalGeometry(Type::Sphere) {}
///
/// \brief Default destructor
///
~Sphere() = default;
Sphere(const std::string name = std::string("")) : AnalyticalGeometry(Type::Sphere, name) {}
///
/// \brief Print the sphere info
......
......@@ -23,8 +23,7 @@
namespace imstk
{
Decal::Decal()
: AnalyticalGeometry(Geometry::Type::Decal)
Decal::Decal(const std::string name) : AnalyticalGeometry(Geometry::Type::Decal, name)
{
m_dimensions = glm::vec3(1);
}
......@@ -73,4 +72,4 @@ Decal::updateDecal(glm::mat4& viewMatrix)
m_inverse = glm::inverse(m_transform);
}
}
\ No newline at end of file
}
......@@ -33,9 +33,7 @@ namespace imstk
class Decal : public AnalyticalGeometry
{
public:
Decal();
~Decal() = default;
Decal(const std::string name = std::string(""));
///
/// \brief Print the cube info
......
......@@ -23,8 +23,8 @@
namespace imstk
{
DecalPool::DecalPool(unsigned int maxNumDecals /*= 128*/)
: Geometry(Geometry::Type::DecalPool)
DecalPool::DecalPool(unsigned int maxNumDecals /*= 128*/, const std::string name)
: Geometry(Geometry::Type::DecalPool, name)
{
if (maxNumDecals <= 128)
{
......@@ -60,7 +60,7 @@ DecalPool::DecalPool(unsigned int maxNumDecals /*= 128*/)
for (unsigned int i = 0; i < maxNumDecals; i++)
{
m_freeDecals.push_back(std::make_shared<Decal>());
m_freeDecals.push_back(std::make_shared<Decal>("Decal-" + std::to_string(i)));
}
}
......@@ -128,4 +128,4 @@ DecalPool::getMaxNumDecals()
{
return m_maxNumDecals;
}
}
\ No newline at end of file
}
......@@ -33,7 +33,7 @@ namespace imstk
class DecalPool : public Geometry
{
public:
DecalPool(unsigned int maxNumDecals = 128);
DecalPool(unsigned int maxNumDecals = 128, const std::string name = std::string(""));
std::shared_ptr<Decal> addDecal();
......@@ -50,7 +50,7 @@ public:
///
/// \brief Returns the volume of the cube
///
double getVolume() const override { return 0; };
double getVolume() const override { return 0; }
protected:
friend class VulkanDecalRenderDelegate;
......@@ -58,10 +58,10 @@ protected:
std::deque<std::shared_ptr<Decal>> m_orderedDecals;
std::deque<std::shared_ptr<Decal>> m_freeDecals;
void applyTranslation(const Vec3d t) override {};
void applyRotation(const Mat3d r) override {};
void applyScaling(const double s) override {};
virtual void updatePostTransformData() override {};
void applyTranslation(const Vec3d t) override {}
void applyRotation(const Mat3d r) override {}
void applyScaling(const double s) override {}
virtual void updatePostTransformData() override {}
unsigned int m_maxNumDecals;
unsigned int m_numDecals = 0;
......
......@@ -41,12 +41,7 @@ public:
///
/// \brief Constructor
///
HexahedralMesh() : VolumetricMesh(Geometry::Type::HexahedralMesh) {}
///
/// \brief Destructor
///
~HexahedralMesh() = default;
HexahedralMesh(const std::string name = std::string("")) : VolumetricMesh(Geometry::Type::HexahedralMesh, name) {}
///
/// \brief Initializes the rest of the data structures given vertex positions and
......@@ -99,7 +94,6 @@ public:
size_t getNumHexahedra() const;
protected:
friend class VTKHexahedralMeshRenderDelegate;
std::vector<HexaArray> m_hexahedraVertices; ///< vertices of the hexahedra
......
......@@ -42,19 +42,13 @@ public:
///
/// \brief Constructor
///
LineMesh() : PointSet(Geometry::Type::LineMesh) {}
///
/// \brief Default destructor
///
~LineMesh() = default;
LineMesh(const std::string name = std::string("")) : PointSet(Geometry::Type::LineMesh, name) {}
///
/// \brief Initializes the rest of the data structures given vertex positions and
/// line connectivity
///
void initialize(const StdVectorOfVec3d& vertices,
const std::vector<LineArray>& lines);
void initialize(const StdVectorOfVec3d& vertices, const std::vector<LineArray>& lines);
///
/// \brief
......@@ -97,7 +91,6 @@ public:
std::vector<Color> getVertexColors() const;
private:
friend class VTKLineMeshRenderDelegate;
size_t m_originalNumLines = 0;
......
......@@ -21,6 +21,7 @@
#include "imstkPointSet.h"
#include "imstkGraph.h"
#include "imstkParallelUtils.h"
namespace imstk
{
......@@ -52,29 +53,14 @@ PointSet::print() const
}
void
PointSet::computeBoundingBox(Vec3d& min, Vec3d& max, const double percent) const
PointSet::computeBoundingBox(Vec3d& min, Vec3d& max, const double paddingPercent) const
{
min = Vec3d(MAX_D, MAX_D, MAX_D);
max = Vec3d(-MAX_D, -MAX_D, -MAX_D);
for (auto& pos : m_vertexPositions)
{
for (int i = 0; i < 3; ++i)
{
min[i] = std::min(min[i], pos[i]);
max[i] = std::max(max[i], pos[i]);
}
}
if (percent == 0.0)
{
return;
}
else
ParallelUtils::findAABB(m_vertexPositions, min, max);
if (paddingPercent > 0.0)
{
Vec3d range = max - min;
min = min - range * (percent / 100);
max = max + range * (percent / 100);
min = min - range * (paddingPercent / 100.0);
max = max + range * (paddingPercent / 100.0);
}
}
......@@ -85,7 +71,7 @@ PointSet::setInitialVertexPositions(const StdVectorOfVec3d& vertices)
{
m_initialVertexPositions = vertices;
m_originalNumVertices = vertices.size();
m_maxNumVertices = (size_t)(m_originalNumVertices * m_loadFactor);
m_maxNumVertices = static_cast<size_t>(m_originalNumVertices * m_loadFactor);
m_vertexPositions.reserve(m_maxNumVertices);
}
else
......@@ -101,9 +87,12 @@ PointSet::getInitialVertexPositions() const
}
const Vec3d&
PointSet::getInitialVertexPosition(const size_t& vertNum) const
PointSet::getInitialVertexPosition(const size_t vertNum) const
{
return m_initialVertexPositions.at(vertNum);
#if defined(DEBUG) || defined(_DEBUG) || !defined(NDEBUG)
LOG_IF(FATAL, (vertNum >= m_initialVertexPositions.size())) << "Invalid index";
#endif
return m_initialVertexPositions[vertNum];
}
void
......@@ -134,27 +123,35 @@ PointSet::getVertexPositions(DataType type /* = DataType::PostTransform */)
}
void
PointSet::setVertexPosition(const size_t& vertNum, const Vec3d& pos)
PointSet::setVertexPosition(const size_t vertNum, const Vec3d& pos)
{
m_vertexPositions.at(vertNum) = pos;
m_dataModified = true;
m_transformApplied = false;
#if defined(DEBUG) || defined(_DEBUG) || !defined(NDEBUG)
LOG_IF(FATAL, (vertNum >= m_vertexPositions.size())) << "Invalid index";
#endif
m_vertexPositions[vertNum] = pos;
m_dataModified = true;
m_transformApplied = false;
this->updatePostTransformData();
}
const Vec3d&
PointSet::getVertexPosition(const size_t& vertNum, DataType type)
PointSet::getVertexPosition(const size_t vertNum, DataType type)
{
return this->getVertexPositions(type).at(vertNum);
#if defined(DEBUG) || defined(_DEBUG) || !defined(NDEBUG)
LOG_IF(FATAL, (vertNum >= getVertexPositions().size())) << "Invalid index";
#endif
return this->getVertexPositions(type)[vertNum];
}
void
PointSet::setVertexDisplacements(const StdVectorOfVec3d& diff)
{
assert(diff.size() == m_vertexPositions.size());
for (size_t i = 0; i < m_vertexPositions.size(); ++i)
{
m_vertexPositions[i] = m_initialVertexPositions[i] + diff[i];
}
ParallelUtils::parallelFor(m_vertexPositions.size(),
[&](const size_t i)
{
m_vertexPositions[i] = m_initialVertexPositions[i] + diff[i];
});
m_dataModified = true;
m_transformApplied = false;
}
......@@ -163,12 +160,11 @@ void
PointSet::setVertexDisplacements(const Vectord& u)
{
assert(u.size() == 3 * m_vertexPositions.size());
size_t dofId = 0;
for (size_t i = 0; i < m_vertexPositions.size(); ++i)
{
m_vertexPositions[i] = m_initialVertexPositions[i] + Vec3d(u(dofId), u(dofId + 1), u(dofId + 2));
dofId += 3;
}
ParallelUtils::parallelFor(m_vertexPositions.size(),
[&](const size_t i)
{
m_vertexPositions[i] = m_initialVertexPositions[i] + Vec3d(u(i * 3), u(i * 3 + 1), u(i * 3 + 2));
});
m_dataModified = true;
m_transformApplied = false;
}
......@@ -176,10 +172,11 @@ PointSet::setVertexDisplacements(const Vectord& u)
void
PointSet::translateVertices(const Vec3d& t)
{
for (size_t i = 0; i < m_vertexPositions.size(); ++i)
{
m_vertexPositions[i] += t;
}
ParallelUtils::parallelFor(m_vertexPositions.size(),
[&](const size_t i)
{
m_vertexPositions[i] += t;
});
m_dataModified = true;
m_transformApplied = false;
}
......@@ -240,11 +237,12 @@ PointSet::getNumVertices() const
void
PointSet::applyTranslation(const Vec3d t)
{
for (size_t i = 0; i < m_vertexPositions.size(); ++i)
{
m_vertexPositions[i] += t;
m_initialVertexPositions[i] += t;
}
ParallelUtils::parallelFor(m_vertexPositions.size(),
[&](const size_t i)
{
m_vertexPositions[i] += t;
m_initialVertexPositions[i] += t;
});
m_dataModified = true;
m_transformApplied = false;
}
......@@ -252,11 +250,12 @@ PointSet::applyTranslation(const Vec3d t)
void
PointSet::applyRotation(const Mat3d r)
{
for (size_t i = 0; i < m_vertexPositions.size(); ++i)
{
m_vertexPositions[i] = r * m_vertexPositions[i];
m_initialVertexPositions[i] = r * m_initialVertexPositions[i];
}
ParallelUtils::parallelFor(m_vertexPositions.size(),
[&](const size_t i)
{
m_vertexPositions[i] = r * m_vertexPositions[i];
m_initialVertexPositions[i] = r * m_initialVertexPositions[i];
});
m_dataModified = true;
m_transformApplied = false;
}
......@@ -264,11 +263,12 @@ PointSet::applyRotation(const Mat3d r)
void
PointSet::applyScaling(const double s)
{
for (size_t i = 0; i < m_vertexPositions.size(); ++i)
{
m_vertexPositions[i] = s * m_vertexPositions[i];
m_initialVertexPositions[i] = s * m_initialVertexPositions[i];
}
ParallelUtils::parallelFor(m_vertexPositions.size(),
[&](const size_t i)
{
m_vertexPositions[i] = s * m_vertexPositions[i];
m_initialVertexPositions[i] = s * m_initialVertexPositions[i];
});
m_dataModified = true;
m_transformApplied = false;
}
......@@ -285,13 +285,15 @@ PointSet::updatePostTransformData()
{
m_vertexPositionsPostTransform.resize(m_vertexPositions.size());
}
for (size_t i = 0; i < m_vertexPositions.size(); ++i)
{
// NOTE: Right now scaling is appended on top of the rigid transform
// for scaling around the mesh center, and not concatenated within
// the transform, for ease of use.
m_vertexPositionsPostTransform[i] = m_transform * (m_vertexPositions[i] * m_scaling);
}
ParallelUtils::parallelFor(m_vertexPositions.size(),
[&](const size_t i)
{
// NOTE: Right now scaling is appended on top of the rigid transform
// for scaling around the mesh center, and not concatenated within
// the transform, for ease of use.
m_vertexPositionsPostTransform[i] = m_transform * (m_vertexPositions[i] * m_scaling);
});
m_transformApplied = true;
}
......
......@@ -35,16 +35,11 @@ class Graph;
class PointSet : public Geometry
{
public:
///
/// \brief Protected constructor
///
PointSet(Geometry::Type type = Geometry::Type::PointSet) : Geometry(type) {}
///
/// \brief Destructor
///
virtual ~PointSet() override = default;
PointSet(const Type type = Geometry::Type::PointSet, const std::string name = std::string("")) :
Geometry(type, name) {}
///
/// \brief Initializes the data structure given vertex positions
......@@ -64,12 +59,12 @@ public:
///
/// \brief Returns the volume of the geometry (if valid)
///
virtual double getVolume() const { return 0; };
virtual double getVolume() const override { return 0; }
///
/// \brief Compute the bounding box for the entire mesh
///
void computeBoundingBox(Vec3d& min, Vec3d& max, const double percent = 0.0) const;
virtual void computeBoundingBox(Vec3d& min, Vec3d& max, const double paddingPercent = 0.0) const override;
// Accessors
......@@ -86,7 +81,7 @@ public:
///
/// \brief Returns the initial position of a vertex given its index
///
const Vec3d& getInitialVertexPosition(const size_t& vertNum) const;
const Vec3d& getInitialVertexPosition(const size_t vertNum) const;
///
/// \brief Sets current vertex positions of the mesh from an array
......@@ -99,15 +94,14 @@ public:
const StdVectorOfVec3d& getVertexPositions(DataType type = DataType::PostTransform);
///
/// \brief Set the current position of a vertex given its index to certain position
/// \brief Set the current position of a vertex given its index to certain position (this is not a thread-safe method)
///
void setVertexPosition(const size_t& vertNum, const Vec3d& pos);
void setVertexPosition(const size_t vertNum, const Vec3d& pos);
///
/// \brief Returns the position of a vertex given its index
///
const Vec3d& getVertexPosition(const size_t& vertNum,
DataType type = DataType::PostTransform);
const Vec3d& getVertexPosition(const size_t vertNum, DataType type = DataType::PostTransform);
///
/// \brief Sets the displacements of mesh vertices from an array
......@@ -158,7 +152,7 @@ public:
/// \brief Set the topologyChanged flag
///
void setTopologyChangedFlag(const bool flag) { m_topologyChanged = flag; }
bool getTopologyChangedFlag() const { return m_topologyChanged; };
bool getTopologyChangedFlag() const { return m_topologyChanged; }
///
/// \brief Set load factor
......@@ -178,16 +172,12 @@ public:
virtual std::shared_ptr<Graph> getMeshGraph();
protected:
friend class VTKPointSetRenderDelegate;
///
/// \brief Get vertices positions
///
StdVectorOfVec3d& getVertexPositionsNotConst()
{
return m_vertexPositions;
}
StdVectorOfVec3d& getVertexPositionsNotConst() { return m_vertexPositions; }
void applyTranslation(const Vec3d t) override;
void applyRotation(const Mat3d r) override;
......@@ -200,8 +190,7 @@ protected:
std::map<std::string, StdVectorOfVectorf> m_pointDataMap; ///> vector of data arrays per vertice
bool m_topologyChanged = false;
bool m_topologyChanged = false;
double m_loadFactor = 2.0;
size_t m_maxNumVertices = 0;
size_t m_originalNumVertices = 0;
......
......@@ -83,12 +83,7 @@ public:
///
/// \brief Constructor
///
SurfaceMesh() : PointSet(Geometry::Type::SurfaceMesh) {}
///
/// \brief Default destructor
///
~SurfaceMesh() = default;
SurfaceMesh(const std::string name = std::string("")) : PointSet(Geometry::Type::SurfaceMesh, name) {}
///
/// \brief Initializes the rest of the data structures given vertex positions and
......@@ -209,7 +204,7 @@ public:
/// \brief Set load factor
/// \param loadFactor the maximum number of vertices; a multiple of the original vertex count
///
virtual void setLoadFactor(double loadFactor);
virtual void setLoadFactor(double loadFactor) override;
///
/// \brief Get the maximum number of triangles
......@@ -231,7 +226,6 @@ protected:
StdVectorOfVec3d& getVertexNormalsNotConst();
std::vector<TriangleArray> m_trianglesVertices; ///> Triangle connectivity
std::vector<NeighborsType> m_vertexNeighborTriangles; ///> Neighbor triangles to vertices
std::vector<NeighborsType> m_vertexNeighborVertices; ///> Neighbor vertices to vertices
......@@ -242,9 +236,8 @@ protected:
std::map<NormalGroup, std::shared_ptr<std::vector<size_t>>> m_UVSeamVertexGroups;
std::string m_defaultTCoords = ""; ///> Name of the array used as default material coordinates
size_t m_originalNumTriangles = 0;
size_t m_maxNumTriangles = 0;
std::string m_defaultTCoords = ""; ///> Name of the array used as default material coordinates
size_t m_originalNumTriangles = 0;
size_t m_maxNumTriangles = 0;
};
} // imstk
......@@ -45,12 +45,7 @@ public:
///
/// \brief Constructor
///
TetrahedralMesh() : VolumetricMesh(Geometry::Type::TetrahedralMesh) {}
///
/// \brief Destructor
///
virtual ~TetrahedralMesh() override = default;
TetrahedralMesh(const std::string name = std::string("")) : VolumetricMesh(Geometry::Type::TetrahedralMesh, name) {}
///
/// \brief Initializes the rest of the data structures given vertex positions and
......
......@@ -40,11 +40,6 @@ class VolumetricMesh : public PointSet
{
public:
///
/// \brief Default destructor
///
~VolumetricMesh() = default;
///
/// \brief Computes the attached surface mesh
///
......@@ -72,7 +67,7 @@ public:
protected:
VolumetricMesh(Geometry::Type type) : PointSet(type) {}
VolumetricMesh(Geometry::Type type, const std::string name = std::string("")) : PointSet(type, name) {}
std::shared_ptr<SurfaceMesh> m_attachedSurfaceMesh = nullptr; ///> Attached surface mesh
std::shared_ptr<vega::VolumetricMesh> m_attachedVegaMesh = nullptr; ///> Attached vega mesh
......
......@@ -23,8 +23,8 @@
namespace imstk
{
RenderParticles::RenderParticles(const unsigned int maxNumParticles /*=128*/)
: Geometry(Geometry::Type::RenderParticles)
RenderParticles::RenderParticles(const unsigned int maxNumParticles /*=128*/, const std::string name /*= std::string("")*/)
: Geometry(Geometry::Type::RenderParticles, name)
{
if (maxNumParticles <= 128)
{
......@@ -90,4 +90,4 @@ RenderParticles::getMaxNumParticles()
{
return m_maxNumParticles;
}
}
\ No newline at end of file
}
......@@ -68,7 +68,7 @@ public:
/// \param time Lifespan of each particle (in milliseconds)
/// \param mode Mode for emitter
///
RenderParticles(const unsigned int maxNumParticles = 128);
RenderParticles(const unsigned int maxNumParticles = 128, const std::string name = std::string(""));
///
/// \brief Set size of particle
......@@ -107,12 +107,13 @@ public:
/// \brief Get volume
/// As these are particles, the volume is 0
///
double getVolume() const override { return 0; };
double getVolume() const override { return 0; }
protected:
friend class VulkanParticleRenderDelegate;
friend class RenderParticles;
unsigned int m_numParticles = 0;
unsigned int m_maxNumParticles = 128; ///< Maximum particles
float m_particleSize = 0.1f;
......@@ -123,11 +124,9 @@ protected:
glm::vec2 m_vertexUVs[4];
glm::ivec3 m_triangles[2];
unsigned int m_numParticles = 0;
void applyTranslation(const Vec3d t) override {};
void applyRotation(const Mat3d r<