OGS
anonymous_namespace{AddFaultToVoxelGrid.cpp} Namespace Reference

Functions

bool testAABBIntersectingPlane (Eigen::Vector3d const &aabb_centre, Eigen::Vector3d const &aabb_extent, Eigen::Vector3d const &plane_normal, double const pd)
bool testTriangleIntersectingAABB (MeshLib::Node const &n0, MeshLib::Node const &n1, MeshLib::Node const &n2, Eigen::Vector3d const &c, Eigen::Vector3d const &e)
void markFaults (MeshLib::Mesh &mesh, MeshLib::Mesh const &fault, int const fault_id, Eigen::Vector3d const &half_cell_size)

Function Documentation

◆ markFaults()

void anonymous_namespace{AddFaultToVoxelGrid.cpp}::markFaults ( MeshLib::Mesh & mesh,
MeshLib::Mesh const & fault,
int const fault_id,
Eigen::Vector3d const & half_cell_size )

Definition at line 87 of file MeshToolsLib/MeshGenerators/AddFaultToVoxelGrid.cpp.

89{
90 auto const& elems = mesh.getElements();
91 std::size_t const n_elems = mesh.getNumberOfElements();
92 auto mat_ids = MeshLib::materialIDs(mesh);
93 auto const& fnodes = fault.getNodes();
94 auto const& felems = fault.getElements();
95 GeoLib::AABB const fault_aabb(fnodes.cbegin(), fnodes.cend());
96 auto [min_pnt, max_pnt] = fault_aabb.getMinMaxPoints();
97
98 // get bounding box of fault + voxel extent
99 min_pnt -= half_cell_size;
100 max_pnt += half_cell_size;
101
102 std::array<Eigen::Vector3d, 2> const fault_extent{{min_pnt, max_pnt}};
103 GeoLib::AABB const fault_aabb_ext(fault_extent.cbegin(),
104 fault_extent.cend());
105
106 // test each voxel grid element vs each fault triangle
107 Eigen::Vector3d const extent{half_cell_size};
108 for (std::size_t j = 0; j < n_elems; ++j)
109 {
110 // test if bounding box of fault is intersecting voxel
111 auto const& centre_pnt = MeshLib::getCenterOfGravity(*elems[j]);
112 if (!fault_aabb_ext.containsPoint(centre_pnt, 0))
113 {
114 continue;
115 }
116
117 // test if voxel is intersecting triangle
118 auto const& c(centre_pnt.asEigenVector3d());
119 for (auto const* const fault_elem : felems)
120 {
121 if (fault_elem->getDimension() != 2)
122 {
123 continue;
124 }
125
127 *fault_elem->getNode(0), *fault_elem->getNode(1),
128 *fault_elem->getNode(2), c, extent))
129 {
130 (*mat_ids)[j] = fault_id;
131 break;
132 }
133
134 if (fault_elem->getGeomType() == MeshLib::MeshElemType::QUAD)
135 {
137 *fault_elem->getNode(0), *fault_elem->getNode(2),
138 *fault_elem->getNode(3), c, extent))
139 {
140 (*mat_ids)[j] = fault_id;
141 break;
142 }
143 }
144 }
145 }
146}
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Definition AABB.h:45
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:100
std::size_t getNumberOfElements() const
Get the number of elements.
Definition Mesh.h:88
PropertyVector< int > const * materialIDs(Mesh const &mesh)
Definition Mesh.cpp:258
MathLib::Point3d getCenterOfGravity(Element const &element)
Calculates the center of gravity for the mesh element.
Definition Element.cpp:131
bool testTriangleIntersectingAABB(MeshLib::Node const &n0, MeshLib::Node const &n1, MeshLib::Node const &n2, Eigen::Vector3d const &c, Eigen::Vector3d const &e)

References GeoLib::AABB::containsPoint(), MeshLib::getCenterOfGravity(), MeshLib::Mesh::getElements(), GeoLib::AABB::getMinMaxPoints(), MeshLib::Mesh::getNodes(), MeshLib::Mesh::getNumberOfElements(), MeshLib::materialIDs(), MeshLib::QUAD, and testTriangleIntersectingAABB().

◆ testAABBIntersectingPlane()

bool anonymous_namespace{AddFaultToVoxelGrid.cpp}::testAABBIntersectingPlane ( Eigen::Vector3d const & aabb_centre,
Eigen::Vector3d const & aabb_extent,
Eigen::Vector3d const & plane_normal,
double const pd )

Definition at line 25 of file MeshToolsLib/MeshGenerators/AddFaultToVoxelGrid.cpp.

29{
30 double const r = aabb_extent.dot(plane_normal.cwiseAbs());
31 double const s = plane_normal.dot(aabb_centre) - pd;
32 return std::abs(s) > r;
33}

Referenced by testTriangleIntersectingAABB().

◆ testTriangleIntersectingAABB()

bool anonymous_namespace{AddFaultToVoxelGrid.cpp}::testTriangleIntersectingAABB ( MeshLib::Node const & n0,
MeshLib::Node const & n1,
MeshLib::Node const & n2,
Eigen::Vector3d const & c,
Eigen::Vector3d const & e )

Definition at line 36 of file MeshToolsLib/MeshGenerators/AddFaultToVoxelGrid.cpp.

41{
42 // Translate triangle as conceptually moving AABB to origin
43 Eigen::Matrix3d v;
44 v << n0.asEigenVector3d() - c, n1.asEigenVector3d() - c,
45 n2.asEigenVector3d() - c;
46
47 // Test the three axes corresponding to the face normals of AABB b
48 if (((v.rowwise().minCoeff() - e).array() > 0).any() ||
49 ((v.rowwise().maxCoeff() + e).array() < 0).any())
50 {
51 return false;
52 }
53
54 // separating axes
55 std::array<Eigen::Vector3d, 3> tri_edge{
56 {v.col(1) - v.col(0), v.col(2) - v.col(1), v.col(0) - v.col(2)}};
57 std::array<Eigen::Vector3d, 9> const axx{
58 {Eigen::Vector3d({0, -tri_edge[0].z(), tri_edge[0].y()}),
59 Eigen::Vector3d({0, -tri_edge[1].z(), tri_edge[1].y()}),
60 Eigen::Vector3d({0, -tri_edge[2].z(), tri_edge[2].y()}),
61 Eigen::Vector3d({tri_edge[0].z(), 0, -tri_edge[0].x()}),
62 Eigen::Vector3d({tri_edge[1].z(), 0, -tri_edge[1].x()}),
63 Eigen::Vector3d({tri_edge[2].z(), 0, -tri_edge[2].x()}),
64 Eigen::Vector3d({-tri_edge[0].y(), tri_edge[0].x(), 0}),
65 Eigen::Vector3d({-tri_edge[1].y(), tri_edge[1].x(), 0}),
66 Eigen::Vector3d({-tri_edge[2].y(), tri_edge[2].x(), 0})}};
67
68 // Separating axis tests to check if there's a plane separating the
69 // projections of the AABB and the triangle according to the Separating Axis
70 // Theorem (see C. Ericson "Real Time Collision Detection" for details)
71 for (auto const& a : axx)
72 {
73 Eigen::Vector3d p = v.transpose() * a;
74 double const r = e.dot(a.cwiseAbs());
75 if (std::max(-p.maxCoeff(), p.minCoeff()) > r)
76 {
77 return false;
78 }
79 }
80
81 // Test separating axis corresponding to triangle face normal
82 Eigen::Vector3d const plane_normal(tri_edge[0].cross(tri_edge[1]));
83 double const pd = plane_normal.dot(v.row(0));
84 return testAABBIntersectingPlane(c, e, plane_normal, pd);
85}
bool testAABBIntersectingPlane(Eigen::Vector3d const &aabb_centre, Eigen::Vector3d const &aabb_extent, Eigen::Vector3d const &plane_normal, double const pd)

References MathLib::Point3d::asEigenVector3d(), and testAABBIntersectingPlane().

Referenced by markFaults().