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 96 of file AddFaultToVoxelGrid.cpp.

98{
99 auto const& elems = mesh.getElements();
100 std::size_t const n_elems = mesh.getNumberOfElements();
101 auto mat_ids = MeshLib::materialIDs(mesh);
102 auto const& fnodes = fault.getNodes();
103 auto const& felems = fault.getElements();
104 GeoLib::AABB const fault_aabb(fnodes.cbegin(), fnodes.cend());
105 auto [min_pnt, max_pnt] = fault_aabb.getMinMaxPoints();
106
107 // get bounding box of fault + voxel extent
108 min_pnt -= half_cell_size;
109 max_pnt += half_cell_size;
110
111 std::array<Eigen::Vector3d, 2> const fault_extent{{min_pnt, max_pnt}};
112 GeoLib::AABB const fault_aabb_ext(fault_extent.cbegin(),
113 fault_extent.cend());
114
115 // test each voxel grid element vs each fault triangle
116 Eigen::Vector3d const extent{half_cell_size};
117 for (std::size_t j = 0; j < n_elems; ++j)
118 {
119 // test if bounding box of fault is intersecting voxel
120 auto const& centre_pnt = MeshLib::getCenterOfGravity(*elems[j]);
121 if (!fault_aabb_ext.containsPoint(centre_pnt, 0))
122 {
123 continue;
124 }
125
126 // test if voxel is intersecting triangle
127 auto const& c(centre_pnt.asEigenVector3d());
128 for (auto const* const fault_elem : felems)
129 {
130 if (fault_elem->getDimension() != 2)
131 {
132 continue;
133 }
134
136 *fault_elem->getNode(0), *fault_elem->getNode(1),
137 *fault_elem->getNode(2), c, extent))
138 {
139 (*mat_ids)[j] = fault_id;
140 break;
141 }
142
143 if (fault_elem->getGeomType() == MeshLib::MeshElemType::QUAD)
144 {
146 *fault_elem->getNode(0), *fault_elem->getNode(2),
147 *fault_elem->getNode(3), c, extent))
148 {
149 (*mat_ids)[j] = fault_id;
150 break;
151 }
152 }
153 }
154 }
155}
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Definition AABB.h:56
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:109
std::size_t getNumberOfElements() const
Get the number of elements.
Definition Mesh.h:97
PropertyVector< int > const * materialIDs(Mesh const &mesh)
Definition Mesh.cpp:268
MathLib::Point3d getCenterOfGravity(Element const &element)
Calculates the center of gravity for the mesh element.
Definition Element.cpp:124
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 34 of file AddFaultToVoxelGrid.cpp.

38{
39 double const r = aabb_extent.dot(plane_normal.cwiseAbs());
40 double const s = plane_normal.dot(aabb_centre) - pd;
41 return std::abs(s) > r;
42}

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 45 of file AddFaultToVoxelGrid.cpp.

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