Commit e2767352 authored by Alexis Girault's avatar Alexis Girault
Browse files

STYLE: Clean up geometry and maps

- Add imstk::Mat4f and imstk::Mat4d
- Add imstk::MAX_D and imstk::MIN_D
- Remove 'Map' from GeometryMap functions
- Reorder functions in a consistent manner
- Correct reference returns
- remove unnecessary ismtk:: due to namespace
- rename vertex/triangle/hexadron/tetrahedron composed
methods with their plural form when needed
- follow style rule with return type on a line and
function name on the following one during declaration
- move print() to geometryMap base class and use it in
override functions
- use for each c++11 architecture when possible
- correct wrong iteration in HexahedralMesh::getVolume
- place conditions for return at the top of functions
- declare WeightsArray in TetrahedralMesh instead of
TetraTriangleMap
- Rename findEclosingTetrahedra to findEnclosingTetrahedra
- add override on virtual functions in child classes
- correct test function name in Sandbox
parent e287e58d
......@@ -27,6 +27,8 @@
#include <Eigen/Geometry>
namespace imstk {
// 2D vector
using Vec2f = Eigen::Vector2f;
using Vec2d = Eigen::Vector2d;
......@@ -51,6 +53,10 @@ using Quatd = Eigen::Quaterniond;
using Mat3f = Eigen::Matrix3f;
using Mat3d = Eigen::Matrix3d;
// 4x4 Matrix
using Mat4f = Eigen::Matrix4f;
using Mat4d = Eigen::Matrix4d;
// Rigid transform (translation and rotation)
using RigidTransform3f = Eigen::Isometry3f;
using RigidTransform3d = Eigen::Isometry3d;
......@@ -83,6 +89,8 @@ const double LOG10E = 0.434294481903251827651;
const double LN2 = 0.693147180559945309417;
const double LN10 = 2.30258509299404568402;
const double MAX_D = std::numeric_limits<double>::max();
const double MIN_D = std::numeric_limits<double>::min();
}
#endif // ifndef imstkMath_h
......@@ -22,29 +22,34 @@
#include "imstkGeometryMap.h"
namespace imstk {
void
GeometryMap::muteMap()
GeometryMap::mute()
{
m_isActive = false;
}
void
GeometryMap::activateMap()
GeometryMap::activate()
{
m_isActive = true;
}
const
GeometryMapType& GeometryMap::getType() const
void
GeometryMap::print() const
{
return m_type;
LOG(INFO) << this->getTypeName();
}
void
GeometryMap::setMaster(std::shared_ptr<Geometry> master)
bool
GeometryMap::isActive() const
{
m_master = master;
return m_isActive;
}
const
GeometryMapType& GeometryMap::getType() const
{
return m_type;
}
const
......@@ -67,6 +72,12 @@ std::string GeometryMap::getTypeName() const
}
}
void
GeometryMap::setMaster(std::shared_ptr<Geometry> master)
{
m_master = master;
}
std::shared_ptr<Geometry>
GeometryMap::getMaster() const
{
......@@ -84,10 +95,4 @@ GeometryMap::getSlave() const
{
return m_slave;
}
bool
GeometryMap::isActive() const
{
return m_isActive;
}
}
\ No newline at end of file
......@@ -48,25 +48,36 @@ public:
///
/// \brief Compute the map
///
virtual void computeMap() = 0;
virtual void compute() = 0;
///
/// \brief Apply the map
///
virtual void applyMap() = 0;
virtual void apply() = 0;
///
/// \brief Print the map
///
virtual void print() const;
///
/// \brief Deactivate the map
///
void muteMap();
void mute();
///
/// \brief Activate the map
///
void activateMap();
void activate();
///
/// \brief Returns true if the map is actively applied at runtime, else false.
///
bool isActive() const;
// Accessors
const GeometryMapType& getType() const;
const std::string getTypeName() const;
virtual void setMaster(std::shared_ptr<Geometry> master);
virtual std::shared_ptr<Geometry> getMaster() const;
......@@ -74,18 +85,6 @@ public:
virtual void setSlave(std::shared_ptr<Geometry> slave);
virtual std::shared_ptr<Geometry> getSlave() const;
const std::string getTypeName() const;
///
/// \brief Returns true if the map is actively applied at runtime, else false.
///
bool isActive() const;
///
/// \brief Print the map
///
virtual void print() const = 0;
protected:
GeometryMap(GeometryMapType type) : m_type(type), m_isActive(true) {}
......
......@@ -22,45 +22,42 @@
#include "imstkHexahedralMesh.h"
namespace imstk {
const std::vector<HexahedralMesh::HexaArray>&
HexahedralMesh::getHexahedronMeshVertices() const
void
HexahedralMesh::setHexahedraVertices(const std::vector<HexaArray>& hexahedra)
{
return m_hexahedronVertices;
m_hexahedraVertices = hexahedra;
}
void
HexahedralMesh::setHexahedronMeshVertices(const std::vector<HexaArray>& hexahedrons)
const std::vector<HexahedralMesh::HexaArray>&
HexahedralMesh::getHexahedraVertices() const
{
m_hexahedronVertices = hexahedrons;
return m_hexahedraVertices;
}
const imstk::HexahedralMesh::HexaArray&
HexahedralMesh::getHexahedronVertices(const int hexaNum) const
const HexahedralMesh::HexaArray&
HexahedralMesh::getHexahedronVertices(const int& hexaNum) const
{
return m_hexahedronVertices.at(hexaNum);
return m_hexahedraVertices.at(hexaNum);
}
int
HexahedralMesh::getNumHexahedra() const
{
return m_hexahedronVertices.size();
return m_hexahedraVertices.size();
}
double
HexahedralMesh::getVolume() const
{
Vec3d v[8];
Mat3d A;
Vec3d a, b, c;
double volume = 0.0;
imstk::Vec3d v[8];
imstk::Vec3d a, b, c;
imstk::Mat3d A;
for (int i = 0; i < getNumHexahedra(); ++i)
for (const HexaArray& hexArray : m_hexahedraVertices)
{
auto hexVerts = getHexahedronVertices(i);
for (int i = 0; i < 8; ++i)
{
v[i] = getVertexPosition(hexVerts[i]);
v[i] = this->getVerticePosition(hexArray[i]);
}
a = v[7] - v[0];
......@@ -68,8 +65,8 @@ HexahedralMesh::getVolume() const
c = v[3] - v[5];
A << a[0], b[0], c[0],
a[1], b[1], c[1],
a[2], b[2], c[2];
a[1], b[1], c[1],
a[2], b[2], c[2];
volume += A.determinant();
......@@ -77,8 +74,8 @@ HexahedralMesh::getVolume() const
c = v[5] - v[6];
A << a[0], b[0], c[0],
a[1], b[1], c[1],
a[2], b[2], c[2];
a[1], b[1], c[1],
a[2], b[2], c[2];
volume += A.determinant();
......@@ -86,13 +83,12 @@ HexahedralMesh::getVolume() const
c = v[6] - v[3];
A << a[0], b[0], c[0],
a[1], b[1], c[1],
a[2], b[2], c[2];
a[1], b[1], c[1],
a[2], b[2], c[2];
volume += A.determinant();
}
return volume/6;
}
}
......@@ -37,20 +37,24 @@ public:
~HexahedralMesh() = default;
const std::vector<HexaArray>& getHexahedronMeshVertices() const;
void setHexahedronMeshVertices(const std::vector<HexaArray>& hexahedrons);
// Accessors
void setHexahedraVertices(const std::vector<HexaArray>& hexahedra);
const std::vector<HexaArray>& getHexahedraVertices() const;
const HexaArray& getHexahedronVertices(const int& hexaNum) const;
const imstk::HexahedralMesh::HexaArray& getHexahedronVertices(const int hexaNum) const;
///
/// \brief Returns the number of hexahedra
///
int getNumHexahedra() const;
///
/// \brief Get the total volume of the hexahedral mesh
/// \brief Compute and return the volume of the hexahedral mesh
///
double getVolume() const;
protected:
std::vector<HexaArray> m_hexahedronVertices;
std::vector<HexaArray> m_hexahedraVertices; ///< vertices of the hexahedra
};
}
......
......@@ -22,33 +22,31 @@
#include "imstkIdentityMap.h"
namespace imstk {
const imstk::RigidTransform3d
IdentityMap::getTransform() const
{
return imstk::RigidTransform3d::Identity();
}
void IdentityMap::printMap() const
{
std::cout << this->getTypeName() << std::endl;
}
void
IdentityMap::applyMap()
IdentityMap::apply()
{
if (m_isActive)
// Check Map active
if (!m_isActive)
{
if (!m_master || !m_slave)
{
LOG(WARNING) << "Identity map is being applied without valid geometries\n";
return;
}
// Set the follower mesh configuration to be same as that of master
m_slave->setPosition(m_master->getPosition());
m_slave->setOrientation(m_master->getOrientation());
LOG(WARNING) << "Identity map is not active";
return;
}
// Check geometries
if (!m_master || !m_slave)
{
LOG(WARNING) << "Identity map is being applied without valid geometries";
return;
}
// Set the follower mesh configuration to be same as that of master
m_slave->setPosition(m_master->getPosition());
m_slave->setOrientation(m_master->getOrientation());
}
}
\ No newline at end of file
const RigidTransform3d
IdentityMap::getTransform() const
{
return RigidTransform3d::Identity();
}
}
......@@ -30,19 +30,22 @@ class IdentityMap : public GeometryMap
{
public:
~IdentityMap() = default;
IdentityMap() : GeometryMap(GeometryMapType::Identity){}
IdentityMap() : GeometryMap(GeometryMapType::Identity) {}
void applyMap();
~IdentityMap() = default;
void computeMap(){};
///
/// \brief Compute the map
///
void compute() override {}
void printMap() const;
///
/// \brief Apply the map
///
void apply() override;
// Accessors
void setTransform(const RigidTransform3d& affineTransform);
void setTransform(const RigidTransform3d& affineTransform) = delete;
const RigidTransform3d getTransform() const;
};
}
......
......@@ -21,6 +21,30 @@
#include "imstkIsometricMap.h"
namespace imstk {
void
IsometricMap::apply()
{
// Check Map active
if (!m_isActive)
{
LOG(WARNING) << "Isometric map is not active";
return;
}
// Check geometries
if (!m_master || !m_slave)
{
LOG(WARNING) << "Isometric map is being applied without valid geometries";
return;
}
// Set the follower mesh configuration to that of master
m_slave->setPosition(m_master->getPosition());
m_slave->setOrientation(m_master->getOrientation());
// Apply the offset transform
m_slave->transform(m_rigidTransform);
}
void
IsometricMap::setTransform(const RigidTransform3d& affineTransform)
......@@ -28,35 +52,10 @@ IsometricMap::setTransform(const RigidTransform3d& affineTransform)
m_rigidTransform = affineTransform;
}
const imstk::RigidTransform3d
const RigidTransform3d&
IsometricMap::getTransform() const
{
return m_rigidTransform;
}
void IsometricMap::print() const
{
std::cout << this->getTypeName() << std::endl;
}
void
IsometricMap::applyMap()
{
if (m_isActive)
{
if (!m_master || !m_slave)
{
LOG(WARNING) << "Isometric map is being applied without valid geometries\n";
return;
}
// First set the follower mesh configuration to that of master
m_slave->setPosition(m_master->getPosition());
m_slave->setOrientation(m_master->getOrientation());
// Now, apply the offset transform
m_slave->transform(m_rigidTransform);
}
}
}
\ No newline at end of file
......@@ -30,22 +30,31 @@ class IsometricMap : public GeometryMap
{
public:
~IsometricMap() = default;
IsometricMap() :
GeometryMap(GeometryMapType::Isometric),
m_rigidTransform(RigidTransform3d::Identity())
{}
IsometricMap() : GeometryMap(GeometryMapType::Isometric), m_rigidTransform(RigidTransform3d::Identity()){}
~IsometricMap() = default;
void applyMap();
///
/// \brief Compute the map
///
void compute() override {}
void computeMap(){};
///
/// \brief Apply the map
///
void apply() override;
// Accessors
void setTransform(const RigidTransform3d& affineTransform);
const RigidTransform3d getTransform() const;
void print() const;
const RigidTransform3d& getTransform() const;
protected:
RigidTransform3d m_rigidTransform;
};
}
......
......@@ -22,78 +22,83 @@
#include "imstkMesh.h"
namespace imstk {
void
Mesh::setInitialVerticesPositions(const std::vector<Vec3d>& vertices)
{
m_initialVerticesPositions = vertices;
}
const std::vector<Vec3d>&
Mesh::getInitialVertexPositions() const
Mesh::getInitialVerticesPositions() const
{
return m_initialVertexPositions;
return m_initialVerticesPositions;
}
const imstk::Vec3d& Mesh::getInitialVertexPosition(const int vertNum) const
const Vec3d&
Mesh::getInitialVerticePosition(const int& vertNum) const
{
return m_initialVertexPositions.at(vertNum);
return m_initialVerticesPositions.at(vertNum);
}
void
Mesh::setInitialVertexPositions(const std::vector<Vec3d>& vertices)
Mesh::setVerticesPositions(const std::vector<Vec3d>& vertices)
{
m_initialVertexPositions = vertices;
m_verticesPositions = vertices;
}
const std::vector<Vec3d>&
Mesh::getVertexPositions() const
Mesh::getVerticesPositions() const
{
return m_vertexPositions;
return m_verticesPositions;
}
void
Mesh::setVertexPositions(const std::vector<Vec3d>& vertices)
void Mesh::setVerticePosition(const int& vertNum, const Vec3d& pos)
{
m_vertexPositions = vertices;
m_verticesPositions.at(vertNum) = pos;
}
const imstk::Vec3d& Mesh::getVertexPosition(const int vertNum) const
const Vec3d&
Mesh::getVerticePosition(const int& vertNum) const
{
return m_vertexPositions.at(vertNum);
return m_verticesPositions.at(vertNum);
}
void Mesh::setVertexPosition(const int vertNum, const imstk::Vec3d& pos)
void
Mesh::setVerticesDisplacements(const std::vector<Vec3d>& diff)
{
m_vertexPositions.at(vertNum) = pos;
m_verticesDisplacements = diff;
}
const std::vector<Vec3d>&
Mesh::getVertexDisplacements() const
Mesh::getVerticesDisplacements() const
{
return m_vertexDisplacements;
return m_verticesDisplacements;
}
void
Mesh::setVertexDisplacements(const std::vector<Vec3d>& diff)
{
m_vertexDisplacements = diff;
}
const imstk::Vec3d& Mesh::getVertexDisplacement(const int vertNum) const
const Vec3d&
Mesh::getVerticeDisplacement(const int& vertNum) const
{
return m_vertexDisplacements.at(vertNum);
return m_verticesDisplacements.at(vertNum);
}
int Mesh::getNumVertices() const
const int
Mesh::getNumVertices() const
{
return m_initialVertexPositions.size();
return m_initialVerticesPositions.size();
}
void Mesh::computeBoundingBox(imstk::Vec3d& min, imstk::Vec3d& max, const double percent) const
void
Mesh::computeBoundingBox(Vec3d& min, Vec3d& max, const double percent) const
{
min = imstk::Vec3d(std::numeric_limits<double>::max(),
min = Vec3d(std::numeric_limits<double>::max(),
std::numeric_limits<double>::max(),
std::numeric_limits<double>::max());
max = imstk::Vec3d(std::numeric_limits<double>::min(),
max = Vec3d(std::numeric_limits<double>::min(),
std::numeric_limits<double>::min(),
std::numeric_limits<double>::min());
for (auto it = m_vertexPositions.begin(); it != m_vertexPositions.end(); ++it)
for (auto it = m_verticesPositions.begin(); it != m_verticesPositions.end(); ++it)
{
for (int i = 0; i < 3; ++i)
{
......@@ -108,10 +113,9 @@ void Mesh::computeBoundingBox(imstk::Vec3d& min, imstk::Vec3d& max, const double
}
else
{
imstk::Vec3d range = max - min;
Vec3d range = max - min;
min = min - range*(percent / 100);
max = max + range*(percent / 100);
}
}
}
......@@ -32,37 +32,34 @@ public:
~Mesh() = default;
// Accessors
const std::vector<Vec3d>& getInitialVertexPositions() const;
void setInitialVertexPositions(const std::vector<Vec3d>& vertices);
void setInitialVerticesPositions(const std::vector<Vec3d>& vertices);