Commit 33a65d44 authored by Sreekanth Arikatla's avatar Sreekanth Arikatla
Browse files

ENH: Makes extract surface function as utility

Makes extract surface functionality as utility as utility instead
of hardwiring to extract the attached surface mesh.
parent 6ba5d6a5
......@@ -32,7 +32,11 @@ HexahedralMesh::initialize(const std::vector<Vec3d>& vertices,
if(computeAttachedSurfaceMesh)
{
this->computeAttachedSurfaceMesh();
this->m_attachedSurfaceMesh = std::make_shared<imstk::SurfaceMesh>();
if (!this->extractSurfaceMesh(this->m_attachedSurfaceMesh))
{
LOG(WARNING) << "Surface mesh was not extracted!";
}
}
}
......@@ -105,10 +109,11 @@ HexahedralMesh::getVolume() const
return volume/6;
}
void
HexahedralMesh::computeAttachedSurfaceMesh()
bool
HexahedralMesh::extractSurfaceMesh(std::shared_ptr<SurfaceMesh> surfaceMesh)
{
LOG(WARNING) << "HexahedralMesh::computeAttachedSurfaceMesh error: not implemented.";
return false;
}
void
......
......@@ -69,7 +69,7 @@ public:
///
/// \brief Computes the attached surface mesh
///
void computeAttachedSurfaceMesh() override;
bool extractSurfaceMesh(std::shared_ptr<SurfaceMesh> surfaceMesh) override;
// Accessors
......
......@@ -208,7 +208,7 @@ SurfaceMesh::computeVerticesTangents()
double v2 = uv2[1] - uv0[1];
double div = u1 * v2 - u2 * v1;
double r = (div = 0.0f) ? 0.0f : (1.0f / div);
double r = (div == 0.0f) ? 0.0f : (1.0f / div);
Vec3d u_dir = (v2 * P1 - v1 * P2) * r;
Vec3d v_dir = (u2 * P1 - u1 * P2) * r;
......
......@@ -30,9 +30,13 @@ TetrahedralMesh::initialize(const std::vector<Vec3d>& vertices,
Mesh::initialize(vertices);
this->setTetrahedraVertices(tetrahedra);
if(computeAttachedSurfaceMesh)
if (computeAttachedSurfaceMesh)
{
this->computeAttachedSurfaceMesh();
this->m_attachedSurfaceMesh = std::make_shared<imstk::SurfaceMesh>();
if (!this->extractSurfaceMesh(this->m_attachedSurfaceMesh))
{
LOG(WARNING) << "Surface mesh was not extracted!";
}
}
}
......@@ -89,9 +93,15 @@ TetrahedralMesh::getVolume() const
return volume;
}
void
TetrahedralMesh::computeAttachedSurfaceMesh()
bool
TetrahedralMesh::extractSurfaceMesh(std::shared_ptr<SurfaceMesh> surfaceMesh)
{
if (!surfaceMesh)
{
LOG(WARNING) << "Cannot extract SurfaceMesh: The surface mesh provided is not instantiated!";
return false;
}
using triArray = SurfaceMesh::TriangleArray;
const std::vector<triArray> facePattern = { triArray{ { 0, 1, 2 } }, triArray{ { 0, 1, 3 } }, triArray{ { 0, 2, 3 } }, triArray{ { 1, 2, 3 } } };
......@@ -157,6 +167,7 @@ TetrahedralMesh::computeAttachedSurfaceMesh()
for (size_t tetId = 0; tetId < numTet; tetId++)
{
//std::cout << "tet: " << tetId << std::endl;
auto tetVertArray = vertArray.at(tetId);
foundFaces[0] = foundFaces[1] = foundFaces[2] = foundFaces[3] = false;
......@@ -255,9 +266,9 @@ TetrahedralMesh::computeAttachedSurfaceMesh()
}
// Create and attach surface mesh
auto surfaceMesh = std::make_shared<SurfaceMesh>();
surfaceMesh->initialize(vertPositions, surfaceTri);
this->setAttachedSurfaceMesh(surfaceMesh);
return true;
}
void
......
......@@ -74,8 +74,8 @@ public:
/// (a) Extracts the confirming triangular mesh from the tetrahedral mesh
/// (b) Checks and flips the triangle connectivity order if it is not consistent
/// (c) Renumbers the vertices
///
void computeAttachedSurfaceMesh() override;
/// TODO: OPTMIZE FOR SPEED
bool extractSurfaceMesh(std::shared_ptr<SurfaceMesh> surfaceMesh) override;
///
/// \brief compute the barycentric weights of a given point in 3D space for a given the tetrahedra
......
......@@ -43,12 +43,12 @@ public:
///
/// \brief Computes the attached surface mesh
///
virtual void computeAttachedSurfaceMesh() = 0;
virtual bool extractSurfaceMesh(std::shared_ptr<SurfaceMesh> surfaceMesh) = 0;
///
/// \brief Returns the attached surface mesh
///
std::shared_ptr<SurfaceMesh>getAttachedSurfaceMesh();
std::shared_ptr<SurfaceMesh> getAttachedSurfaceMesh();
///
/// \brief Sets the surface mesh that is attached
......
......@@ -71,11 +71,11 @@ void testReadMesh()
*/
// Read volumetricMesh
auto mesh = imstk::MeshReader::read("/home/virtualfls/Projects/IMSTK/resources/AVM/nidus-model/nidus10KTet.vtk");
auto mesh = imstk::MeshReader::read("nidus10KTet.vtk");
auto volumeMesh = std::dynamic_pointer_cast<imstk::VolumetricMesh>(mesh);
volumeMesh->computeAttachedSurfaceMesh();
auto surfaceMesh = volumeMesh->getAttachedSurfaceMesh();
auto surfaceMesh = std::make_shared<imstk::SurfaceMesh>();
volumeMesh->extractSurfaceMesh(surfaceMesh);
// Create object and add to scene
auto object = std::make_shared<imstk::VisualObject>("meshObject");
......@@ -346,10 +346,16 @@ void testExtractSurfaceMesh()
tetMesh->print();
// c. Extract the surface mesh
tetMesh->computeAttachedSurfaceMesh();
// d. Print the resulting mesh
tetMesh->getAttachedSurfaceMesh()->print();
auto surfMesh = std::make_shared<imstk::SurfaceMesh>();
if (tetMesh->extractSurfaceMesh(surfMesh))
{
// d. Print the resulting mesh
surfMesh->print();
}
else
{
LOG(WARNING) << "Surface mesh was not extracted!";
}
getchar();
}
......
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