Commit b4c7b5be authored by Sreekanth Arikatla's avatar Sreekanth Arikatla
Browse files

ENH: Adds functions to print geometry info

Adds a function to check if a geometry is a mesh.
Adds printing to geometry class
Stylistic changes in extract mesh class
parent 3b8727c2
......@@ -23,6 +23,14 @@
namespace imstk {
void
Cube::print() const
{
Geometry::print();
LOG(INFO) << "Width: " << m_width << "\n";
}
const double&
Cube::getWidth() const
{
......
......@@ -50,8 +50,12 @@ public:
///
double getVolume() const;
// Accessors
///
/// \brief Print the cube info
///
void print() const;
// Accessors
///
/// \brief Returns the width of the cube
///
......
......@@ -22,6 +22,15 @@
#include "imstkPlane.h"
namespace imstk {
void
Plane::print() const
{
Geometry::print();
LOG(INFO) << "Width: " << m_width << "\n";
}
Vec3d
Plane::getNormal() const
{
......
......@@ -46,6 +46,11 @@ public:
~Plane() = default;
///
/// \brief Print the plane info
///
void print() const override;
///
/// \brief Returns the normal of the plane
///
......
......@@ -22,6 +22,15 @@
#include "imstkSphere.h"
namespace imstk {
void
Sphere::print() const
{
Geometry::print();
LOG(INFO) << "Radius: " << m_radius << "\n";
}
const double&
Sphere::getRadius() const
{
......
......@@ -45,6 +45,11 @@ public:
~Sphere() = default;
///
/// \brief Print the sphere info
///
void print() const override;
///
/// \brief Returns the radius of the sphere
///
......
......@@ -22,6 +22,7 @@
#include "imstkGeometryMap.h"
namespace imstk {
void
GeometryMap::mute()
{
......
......@@ -22,6 +22,7 @@
#include "imstkIdentityMap.h"
namespace imstk {
void
IdentityMap::apply()
{
......
......@@ -141,9 +141,7 @@ OneToOneMap::print() const
void
OneToOneMap::setMaster(std::shared_ptr<Geometry> master)
{
if (master->getType() != GeometryType::HexahedralMesh &&
master->getType() != GeometryType::SurfaceMesh &&
master->getType() != GeometryType::TetrahedralMesh)
if (!master->isMesh())
{
LOG(WARNING) << "The geometry provided is not a mesh!\n";
return;
......@@ -154,9 +152,7 @@ OneToOneMap::setMaster(std::shared_ptr<Geometry> master)
void
OneToOneMap::setSlave(std::shared_ptr<Geometry> slave)
{
if (slave->getType() != GeometryType::HexahedralMesh &&
slave->getType() != GeometryType::SurfaceMesh &&
slave->getType() != GeometryType::TetrahedralMesh)
if (!slave->isMesh())
{
LOG(WARNING) << "The geometry provided is not a mesh!\n";
return;
......
......@@ -22,6 +22,30 @@
#include "imstkHexahedralMesh.h"
namespace imstk {
void
HexahedralMesh::print() const
{
Geometry::print();
LOG(INFO) << "Number of vertices: " << this->getNumVertices() << "\n";
LOG(INFO) << "Number of Hexahedra: " << this->getNumHexahedra() << "\n";
LOG(INFO) << "Hexahedra:\n";
for (auto &hexVerts : this->getHexahedraVertices())
{
LOG(INFO) << "(" << hexVerts[0] << ", " << hexVerts[1] << "," << hexVerts[2] <<
hexVerts[3] << ", " << hexVerts[4] << "," << hexVerts[5] << ", " <<
hexVerts[6] << "," << hexVerts[7] << ")\n";
}
LOG(INFO) << "Vertex positions:\n";
for (auto &verts : this->getVerticesPositions())
{
LOG(INFO) << "(" << verts.x() << ", " << verts.y() << "," << verts.z() << ")\n";
}
}
void
HexahedralMesh::setHexahedraVertices(const std::vector<HexaArray>& hexahedra)
{
......
......@@ -45,6 +45,11 @@ public:
// Accessors
///
/// \brief Print the hexahedral mesh
///
void print() const override;
///
/// \brief Sets/Returns the hexahedral connectivity
///
......
......@@ -23,26 +23,31 @@
namespace imstk {
void SurfaceMesh::initialize(const std::vector<Vec3d>& vertices,
const std::vector<TriangleArray>& triangles,
const std::vector<Vec2f>& texCoords,
const bool computDerivedData)
void
SurfaceMesh::initialize(const std::vector<Vec3d>& vertices,
const std::vector<TriangleArray>& triangles,
const std::vector<Vec2f>& texCoords,
const bool computDerivedData)
{
this->clear();
setInitialVerticesPositions(vertices);
setInitialVerticesPositions(vertices);
setTrianglesVertices(triangles);
if (texCoords.size() > 0)
{
this->clear();
setInitialVerticesPositions(vertices);
setInitialVerticesPositions(vertices);
setTrianglesVertices(triangles);
setTextureCoordinates(texCoords);
}
if (computDerivedData)
{
computeVerticesNormals();
computeTrianglesNormals();
computeVerticesTangents();
}
if (computDerivedData)
{
computeVerticesNormals();
computeTrianglesNormals();
computeVerticesTangents();
}
}
void
void
SurfaceMesh::computeVerticesNeighborTriangles()
{
m_verticesNeighborTriangles.resize(m_verticesPositions.size());
......@@ -304,19 +309,21 @@ SurfaceMesh::clear()
void
SurfaceMesh::print() const
{
Geometry::print();
LOG(INFO) << "Number of vertices: " << this->getNumVertices() << "\n";
LOG(INFO) << "Number of triangles: " << this->getNumTriangles() << "\n";
LOG(INFO) << "Triangles:\n";
for (auto &triVerts : this->getTrianglesVertices())
{
LOG(INFO) << "(" << triVerts[0] << ", " << triVerts[1] << "," << triVerts[2] << ")\n";
LOG(INFO) << "(" << triVerts[0] << ", " << triVerts[1] << ", " << triVerts[2] << ")\n";
}
LOG(INFO) << "Vertex positions:\n";
for (auto &verts : this->getInitialVerticesPositions())
for (auto &verts : this->getVerticesPositions())
{
LOG(INFO) << "(" << verts.x() << ", " << verts.y() << "," << verts.z() << ")\n";
LOG(INFO) << "(" << verts.x() << ", " << verts.y() << ", " << verts.z() << ")\n";
}
}
......
......@@ -90,9 +90,9 @@ public:
void clear();
///
/// \brief Print the mesh
/// \brief Print the surface mesh
///
void print() const;
void print() const override;
// Accessors
......
......@@ -135,15 +135,12 @@ TetrahedralMesh::extractSurfaceMesh(std::shared_ptr<SurfaceMesh> surfaceMesh)
LOG(WARNING) << "Cannot extract SurfaceMesh: The surface mesh provided is not instantiated!";
return false;
}
using triArray = SurfaceMesh::TriangleArray;
std::vector<SurfaceMesh::TriangleArray> facePattern;
facePattern.push_back({ { 0, 1, 2 } });
facePattern.push_back({ { 0, 1, 3 } });
facePattern.push_back({ { 0, 2, 3 } });
facePattern.push_back({ { 1, 2, 3 } });
const std::vector<triArray> facePattern = { triArray{ { 0, 1, 2 } }, triArray{ { 0, 1, 3 } }, triArray{ { 0, 2, 3 } }, triArray{ { 1, 2, 3 } } };
// Find number of common vertices
auto getNumCommonVerts = [facePattern](const TetraArray& array1, const TetraArray& array2, SurfaceMesh::TriangleArray& commonFace) -> int
auto getNumCommonVerts = [facePattern](const TetraArray& array1, const TetraArray& array2, triArray& commonFace) -> int
{
int numCommonVerts = 0;
std::array<bool, 4> tmpFace = {{0,0,0,0}};
......@@ -163,7 +160,7 @@ TetrahedralMesh::extractSurfaceMesh(std::shared_ptr<SurfaceMesh> surfaceMesh)
{
for (size_t j = 0; j < 3; ++j)
{
commonFace[j] = array1[facePattern[3-i][j]];// this is specific to the above pattern
commonFace[j] = array1[facePattern[3-i][j]];
}
}
}
......@@ -171,8 +168,8 @@ TetrahedralMesh::extractSurfaceMesh(std::shared_ptr<SurfaceMesh> surfaceMesh)
return numCommonVerts;
};
// Find the common face irrespecive of the order
auto findCommonFace = [facePattern](const TetraArray& tetVertArray, const SurfaceMesh::TriangleArray& triVertArray) -> int
// Find the common face irrespective of the order
auto findCommonFace = [facePattern](const TetraArray& tetVertArray, const triArray& triVertArray) -> int
{
for (size_t i = 0; i < 4; ++i)
{
......@@ -188,19 +185,18 @@ TetrahedralMesh::extractSurfaceMesh(std::shared_ptr<SurfaceMesh> surfaceMesh)
}
}
LOG(WARNING) << "There is no common face!";
return -1;// something wrong if you are here
return -1;// something wrong if you reach this point
};
// Find and store the tetrahedral faces that are unique
std::vector<SurfaceMesh::TriangleArray> surfaceTri;
auto vertArray = this->getTetrahedraVertices();
std::vector<triArray> surfaceTri;
std::vector<int> surfaceTriTet;
std::vector<int> tetRemainingVert;
auto vertArray = this->getTetrahedraVertices();
SurfaceMesh::TriangleArray possibleFaces[4];
SurfaceMesh::TriangleArray commonFace;
triArray possibleFaces[4];
triArray commonFace;
bool foundFaces[4];
std::cout << this->getNumTetrahedra() << std::endl;
for (size_t tetId = 0; tetId < this->getNumTetrahedra(); ++tetId)
{
auto tetVertArray = vertArray.at(tetId);
......@@ -236,7 +232,7 @@ TetrahedralMesh::extractSurfaceMesh(std::shared_ptr<SurfaceMesh> surfaceMesh)
{
for (size_t faceId = 0; faceId < 4; ++faceId)
{
possibleFaces[faceId] = SurfaceMesh::TriangleArray{ {
possibleFaces[faceId] = triArray{ {
tetVertArray[facePattern[faceId].at(0)],
tetVertArray[facePattern[faceId].at(1)],
tetVertArray[facePattern[faceId].at(2)] } };
......@@ -316,4 +312,25 @@ TetrahedralMesh::clear()
m_tetrahedraVertices.clear();
Mesh::clear();
}
void
TetrahedralMesh::print() const
{
Geometry::print();
LOG(INFO) << "Number of vertices: " << this->getNumVertices() << "\n";
LOG(INFO) << "Number of tetrahedra: " << this->getNumTetrahedra() << "\n";
LOG(INFO) << "Tetrahedra:\n";
for (auto &tetVerts : this->getTetrahedraVertices())
{
LOG(INFO) << "(" << tetVerts[0] << ", " << tetVerts[1] << ", " << tetVerts[2] << ", " << tetVerts[3] << ")\n";
}
LOG(INFO) << "Vertex positions:\n";
for (auto &verts : this->getVerticesPositions())
{
LOG(INFO) << "(" << verts.x() << ", " << verts.y() << ", " << verts.z() << ")\n";
}
}
}
......@@ -95,6 +95,11 @@ public:
/// \brief Clear all the mesh data
///
void clear();
///
/// \brief Print the tetrahedral mesh
///
void print() const override;
protected:
std::vector<TetraArray> m_tetrahedraVertices; ///< vertices of the tetrahedra
......
......@@ -68,6 +68,22 @@ Geometry::transform(const RigidTransform3d& transform)
this->translate(transform.translation());
}
bool
Geometry::isMesh() const
{
return (this->m_type == GeometryType::HexahedralMesh ||
this->m_type == GeometryType::SurfaceMesh ||
this->m_type == GeometryType::TetrahedralMesh) ? true : false;
}
void
Geometry::print() const
{
LOG(INFO) << this->getTypeName();
LOG(INFO) << "Position: " << "(" << this->m_position.x() << ", " << this->m_position.y() << ", " << this->m_position.z() << ")\n";
LOG(INFO) << "Scaling: " << m_scaling << "\n";
}
const Vec3d&
Geometry::getPosition() const
{
......@@ -129,4 +145,27 @@ Geometry::getType() const
{
return m_type;
}
const std::string
Geometry::getTypeName() const
{
switch (m_type)
{
case GeometryType::Cube:
return "Cube";
case GeometryType::Plane:
return "Plane";
case GeometryType::Sphere:
return "Sphere";
case GeometryType::SurfaceMesh:
return "Surface trianglar mesh";
case GeometryType::TetrahedralMesh:
return "Tetrahedral mesh";
case GeometryType::HexahedralMesh:
return "Hexahedral Mesh";
default:
return "Mesh type not determined!";
}
}
}
......@@ -73,6 +73,21 @@ public:
///
void transform(const RigidTransform3d& transform);
///
/// \brief Returns the volume of the geometry (if valid)
///
virtual double getVolume() const = 0;
///
/// \brief Returns true if the geometry is a mesh, else returns false
///
bool isMesh() const;
///
/// \brief Print
///
virtual void print() const;
// Accessors
///
......@@ -104,10 +119,9 @@ public:
const GeometryType& getType() const;
///
/// \brief Returns the volume of the geometry (if valid)
/// \brief Returns the string representing the type name of the geometry
///
virtual double getVolume() const = 0;
const std::string getTypeName() const;
protected:
Geometry(GeometryType type,
......
......@@ -46,8 +46,8 @@ int main()
//testScenesManagement();
//testIsometricMap();
//testTetraTriangleMap();
testExtractSurfaceMesh();
//testOneToOneNodalMap();
//testExtractSurfaceMesh();
testOneToOneNodalMap();
return 0;
}
......@@ -356,6 +356,8 @@ void testOneToOneNodalMap()
tetMesh->setInitialVerticesPositions(vertList);
tetMesh->setVerticesPositions(vertList);
tetMesh->print();
// b. Construct a surface mesh
auto triMesh = std::make_shared<imstk::SurfaceMesh>();
......@@ -379,6 +381,8 @@ void testOneToOneNodalMap()
triConnectivity.push_back({ { 2, 3, 4 } });
triMesh->setTrianglesVertices(triConnectivity);
triMesh->print();
// c. Construct the one to one nodal map based on the above meshes
auto oneToOneNodalMap = std::make_shared<imstk::OneToOneMap>();
oneToOneNodalMap->setMaster(tetMesh);
......
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