23 "surface_mesh_handle",
24 "Handle to a surface mesh that will represent this object");
34 params.GetParamValue<size_t>(
"surface_mesh_handle"),
36 xbounds_({1.0e6, -1.0e6}),
37 ybounds_({1.0e6, -1.0e6}),
38 zbounds_({1.0e6, -1.0e6})
40 const auto& vertices = surf_mesh->GetVertices();
41 for (
auto& vertex : vertices)
43 const double x = vertex.x;
44 const double y = vertex.y;
45 const double z = vertex.z;
46 if (std::addressof(vertex) == std::addressof(vertices.front()))
57 xbounds_[0] = std::min(xbounds_[0],x);
58 xbounds_[1] = std::max(xbounds_[1],x);
59 ybounds_[0] = std::min(ybounds_[0],y);
60 ybounds_[1] = std::max(ybounds_[1],y);
61 zbounds_[0] = std::min(zbounds_[0],z);
62 zbounds_[1] = std::max(zbounds_[1],z);
71 double tolerance = 1.0e-5;
87 bool cheap_pass =
true;
88 for (
auto& face :
surf_mesh->GetTriangles())
93 p_to_fc = p_to_fc / p_to_fc.
Norm();
95 double sense = p_to_fc.
Dot(face.geometric_normal);
97 if (sense < (0.0 - tolerance))
105 if (cheap_pass)
return true;
110 for (
size_t f = 0; f <
surf_mesh->GetTriangles().size(); f++)
114 double distance_to_face = p_to_fc.
Norm();
115 double closest_distance = 1.0e16;
116 bool closest_sense_pos =
false;
118 p_to_fc = p_to_fc / p_to_fc.
Norm();
120 double sense = p_to_fc.
Dot(
surf_mesh->GetTriangles()[f].geometric_normal);
122 bool good_to_go =
true;
123 if (sense < (0.0 - tolerance))
126 for (
size_t fi = 0; fi <
surf_mesh->GetTriangles().size(); fi++)
128 if (fi == f)
continue;
131 int v0_i =
surf_mesh->GetTriangles()[fi].v_index[0];
132 int v1_i =
surf_mesh->GetTriangles()[fi].v_index[1];
133 int v2_i =
surf_mesh->GetTriangles()[fi].v_index[2];
140 std::pair<double, double> weights;
142 surf_mesh->GetTriangles()[fi].geometric_normal,
148 if (!intersects_plane)
continue;
151 bool intersects_triangle =
true;
169 x0p = x0p / x0p.
Norm();
170 x1p = x1p / x1p.
Norm();
171 x2p = x2p / x2p.
Norm();
174 surf_mesh->GetTriangles()[fi].geometric_normal /
175 surf_mesh->GetTriangles()[fi].geometric_normal.Norm();
177 if (x0p.
Dot(face_norm) < 0.0) intersects_triangle =
false;
178 if (x1p.
Dot(face_norm) < 0.0) intersects_triangle =
false;
179 if (x2p.
Dot(face_norm) < 0.0) intersects_triangle =
false;
181 if (!intersects_triangle)
continue;
184 double sense_with_this_tri =
185 p_to_fc.
Dot(
surf_mesh->GetTriangles()[fi].geometric_normal);
186 double distance_to_triangle = weights.second * distance_to_face;
188 if (distance_to_triangle < closest_distance)
190 closest_distance = distance_to_triangle;
192 if (sense_with_this_tri > 0.0) closest_sense_pos =
true;
194 closest_sense_pos =
false;
200 if ((closest_distance < distance_to_face) && closest_sense_pos)
203 if (!good_to_go)
return false;
static chi::InputParameters GetInputParameters()
bool Inside(const chi_mesh::Vector3 &point) const override
const SurfaceMeshPtr surf_mesh
std::array< double, 2 > xbounds_
SurfaceMeshLogicalVolume(const chi::InputParameters ¶ms)
std::array< double, 2 > ybounds_
std::array< double, 2 > zbounds_
static chi::InputParameters GetInputParameters()
bool CheckPlaneLineIntersect(const chi_mesh::Normal &plane_normal, const chi_mesh::Vector3 &plane_point, const chi_mesh::Vector3 &line_point_0, const chi_mesh::Vector3 &line_point_1, chi_mesh::Vector3 &intersection_point, std::pair< double, double > *weights=nullptr)
RegisterChiObject(chi_mesh, BooleanLogicalVolume)
Vector3 Cross(const Vector3 &that) const
Vector3 Dot(const chi_mesh::TensorRank2Dim3 &that) const