Commit 146713c6 authored by Sreekanth Arikatla's avatar Sreekanth Arikatla Committed by Andrew Wilson
Browse files

REFAC: Move barycentric coord computation to geo utils

parent ee1e637e
......@@ -23,6 +23,7 @@
#include "imstkMath.h"
#include "imstkTypes.h"
#include "imstkGeometryUtilities.h"
#include <algorithm>
#include <array>
......@@ -775,9 +776,26 @@ testSphereToTriangle(const Vec3d& spherePt, const double sphereRadius,
}
}
inline bool
testPointInsideTet(const std::array<Vec3d, 4>& inputTetVerts, const Vec3d& p)
{
std::array<double, 4> bCoord;
GeometryUtils::computePointBarycentricCoordinates(inputTetVerts, p, bCoord);
constexpr const double eps = VERY_SMALL_EPSILON;
if (bCoord[0] >= -eps
&& bCoord[1] >= -eps
&& bCoord[2] >= -eps
&& bCoord[3] >= -eps)
{
return true;
}
return false;
}
///
/// \brief Tests if the segment intersects any of the triangle faces of the tet
/// does not cover line completely inside tet case
/// \todo: Could be faster with SAT directly applied here
///
inline bool
......@@ -793,6 +811,13 @@ testTetToSegment(
return true;
}
}
// test if both points lie inside the tetrahedron
if (testPointInsideTet(inputTetVerts, x1) && testPointInsideTet(inputTetVerts, x2))
{
return true;
}
return false;
}
......
......@@ -22,6 +22,7 @@
#include "imstkTetrahedralMesh.h"
#include "imstkLogger.h"
#include "imstkParallelUtils.h"
#include "imstkGeometryUtilities.h"
#include "imstkSurfaceMesh.h"
namespace imstk
......@@ -239,29 +240,14 @@ void
TetrahedralMesh::computeBarycentricWeights(const size_t& tetId, const Vec3d& pos,
WeightsArray& weights) const
{
const Vec4i& tetIndices = (*m_tetrahedraIndices)[tetId];
Vec3d v[4];
double det;
const VecDataArray<double, 3>& vertices = *m_vertexPositions;
for (int i = 0; i < 4; ++i)
const Vec4i& tetIndices = (*m_tetrahedraIndices)[tetId];
std::array<Vec3d, 4> v;
for (size_t i = 0; i < 4; ++i)
{
v[i] = vertices[tetIndices[i]];
v[i] = getVertexPosition(tetIndices[i]);
}
Mat4d A;
A << v[0][0], v[0][1], v[0][2], 1, v[1][0], v[1][1], v[1][2], 1, v[2][0], v[2][1], v[2][2], 1, v[3][0], v[3][1], v[3][2], 1;
det = A.determinant();
for (int i = 0; i < 4; ++i)
{
Mat4d B = A;
B(i, 0) = pos[0];
B(i, 1) = pos[1];
B(i, 2) = pos[2];
weights[i] = B.determinant() / det;
}
GeometryUtils::computePointBarycentricCoordinates(v, pos, weights);
}
void
......
......@@ -29,6 +29,7 @@
#include <numeric>
#include <queue>
#include <set>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <vtkSmartPointer.h>
......@@ -241,6 +242,23 @@ std::shared_ptr<TetrahedralMesh> createUniformMesh(const Vec3d& aabbMin, const V
///
std::shared_ptr<TetrahedralMesh> createTetrahedralMeshCover(std::shared_ptr<SurfaceMesh> surfMesh, const int nx, const int ny, int nz);
inline void
computePointBarycentricCoordinates(const std::array<Vec3d, 4>& v, const Vec3d& p, std::array<double, 4>& weights)
{
Mat4d A;
A << v[0][0], v[0][1], v[0][2], 1, v[1][0], v[1][1], v[1][2], 1, v[2][0], v[2][1], v[2][2], 1, v[3][0], v[3][1], v[3][2], 1;
double det = A.determinant();
for (int i = 0; i < 4; ++i)
{
Mat4d B = A;
B(i, 0) = p[0];
B(i, 1) = p[1];
B(i, 2) = p[2];
weights[i] = B.determinant() / det;
}
}
///
/// \brief Enumeration for reordering method
///
......
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