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

95{
96 auto const& elems = mesh.getElements();
97 std::size_t const n_elems = mesh.getNumberOfElements();
98 auto mat_ids = MeshLib::materialIDs(mesh);
99 auto const& fnodes = fault.getNodes();
100 auto const& felems = fault.getElements();
101 GeoLib::AABB const fault_aabb(fnodes.cbegin(), fnodes.cend());
102 auto [min_pnt, max_pnt] = fault_aabb.getMinMaxPoints();
103
104 // get bounding box of fault + voxel extent
105 min_pnt -= half_cell_size;
106 max_pnt += half_cell_size;
107
108 std::array<Eigen::Vector3d, 2> const fault_extent{{min_pnt, max_pnt}};
109 GeoLib::AABB const fault_aabb_ext(fault_extent.cbegin(),
110 fault_extent.cend());
111
112 // test each voxel grid element vs each fault triangle
113 Eigen::Vector3d const extent{half_cell_size};
114 for (std::size_t j = 0; j < n_elems; ++j)
115 {
116 // test if bounding box of fault is intersecting voxel
117 auto const& centre_pnt = MeshLib::getCenterOfGravity(*elems[j]);
118 if (!fault_aabb_ext.containsPoint(centre_pnt, 0))
119 {
120 continue;
121 }
122
123 // test if voxel is intersecting triangle
124 auto const& c(centre_pnt.asEigenVector3d());
125 for (auto const* const fault_elem : felems)
126 {
127 if (fault_elem->getDimension() != 2)
128 {
129 continue;
130 }
131
133 *fault_elem->getNode(0), *fault_elem->getNode(1),
134 *fault_elem->getNode(2), c, extent))
135 {
136 (*mat_ids)[j] = fault_id;
137 break;
138 }
139
140 if (fault_elem->getGeomType() == MeshLib::MeshElemType::QUAD)
141 {
143 *fault_elem->getNode(0), *fault_elem->getNode(2),
144 *fault_elem->getNode(3), c, extent))
145 {
146 (*mat_ids)[j] = fault_id;
147 break;
148 }
149 }
150 }
151 }
152}
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 31 of file AddFaultToVoxelGrid.cpp.

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

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

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