24 const bool check_convexity)
28 for (
auto& face : cell.
faces_)
30 const auto& v0 = face.centroid_;
31 const size_t num_edges = face.vertex_ids_.size();
33 for (
size_t e=0; e<num_edges; ++e)
37 const auto& v1 = mesh.
vertices[edge.first];
38 const auto& v2 = mesh.
vertices[edge.second];
43 auto n = v01.Cross(v02);
44 auto C_tri = (v0+v1+v2)/3.0;
48 if (CC.Dot(n)<0.0)
return false;
55 std::vector<std::vector<uint64_t>> proxy_faces;
56 for (
const auto& face : cell.
faces_)
57 proxy_faces.push_back(face.vertex_ids_);
60 for (
const auto& face : cell.
faces_)
62 std::set<size_t> neighbor_face_indices =
65 for (
size_t ofi : neighbor_face_indices)
67 auto& other_face = cell.
faces_[ofi];
68 auto CFC_OFC = other_face.centroid_ - face.centroid_;
70 if (CFC_OFC.Dot(other_face.normal_) < 0.0)
86 const size_t face_index)
88 const auto& face = proxy_faces.at(face_index);
89 const size_t num_faces = proxy_faces.size();
91 std::set<size_t> neighbor_face_indices;
92 const size_t face_num_edges = face.size();
93 for (
size_t e=0; e<face_num_edges; ++e)
98 for (
size_t of=0; of<num_faces; ++of)
100 if (of == face_index)
continue;
101 const auto& other_face = proxy_faces[of];
103 const size_t other_face_num_edges = other_face.size();
104 for (
size_t ofe=0; ofe<other_face_num_edges; ++ofe)
109 if (face_uniq_edge == other_face_uniq_edge)
111 neighbor_face_indices.insert(of);
118 return neighbor_face_indices;
127 std::vector<Edge> non_manifold_edges;
133 non_manifold_edges.reserve(10);
137 const size_t num_proxy_faces = proxy_faces.size();
138 std::vector<std::vector<Edge>> faces_edges;
139 faces_edges.reserve(num_proxy_faces);
140 for (
const auto& proxy_face : proxy_faces)
142 std::vector<Edge> face_edges(proxy_face.size());
143 for (
size_t e=0; e<proxy_face.size(); ++e)
146 faces_edges.push_back(std::move(face_edges));
152 for (
size_t cf=0; cf<num_proxy_faces; ++cf)
154 for (
const auto& cur_edge : faces_edges[cf])
156 bool is_manifold =
false;
157 for (
size_t af=0; af<num_proxy_faces; ++af)
159 if (af == cf)
continue;
160 for (
const auto& alt_edge : faces_edges[af])
165 goto before_next_edge;
171 if (not is_manifold) {non_manifold_edges.push_back(cur_edge);}
175 return non_manifold_edges;
184 const std::string fname = __FUNCTION__;
185 std::vector<Edge> stitched_nm_edges;
186 stitched_nm_edges.reserve(edges.size());
190 std::queue<Edge> unused_candidate_edges;
191 std::queue<Edge> unused_noncandidate_edges;
194 for (
auto& edge : edges)
195 unused_candidate_edges.push(edge);
199 stitched_nm_edges.push_back(unused_candidate_edges.front());
200 unused_candidate_edges.pop();
204 const size_t num_candidates = unused_candidate_edges.size();
205 for (
size_t k=0; k<num_candidates; ++k)
207 const auto& edge_previously_added = stitched_nm_edges.back();
211 while (not unused_candidate_edges.empty())
213 const auto& edge = unused_candidate_edges.front();
215 if (edge.first == edge_previously_added.second)
216 stitched_nm_edges.push_back(edge);
218 unused_noncandidate_edges.push(edge);
220 unused_candidate_edges.pop();
223 std::swap(unused_noncandidate_edges, unused_candidate_edges);
224 if (unused_candidate_edges.empty())
break;
227 if (stitched_nm_edges.size() != edges.size())
228 throw std::logic_error(fname +
": stitching failed.");
230 return stitched_nm_edges;
237 const std::vector<std::vector<uint64_t>> &raw_faces,
240 std::vector<uint64_t> cell_vertex_ids;
243 auto AddIDToCellVertexIDs = [&cell_vertex_ids](uint64_t new_id)
245 auto find_result = std::find(cell_vertex_ids.begin(),
246 cell_vertex_ids.end(),
249 if (find_result == cell_vertex_ids.end())
250 cell_vertex_ids.push_back(new_id);
255 cell.
faces_.reserve(raw_faces.size());
256 for (
auto& raw_face : raw_faces)
259 for (uint64_t vid : raw_face)
261 face_centroid += mesh.
vertices[vid];
262 AddIDToCellVertexIDs(vid);
264 face_centroid /=
static_cast<double>(raw_face.size());
270 cell.
faces_.push_back(std::move(new_face));
275 for (uint64_t vid : cell_vertex_ids)
276 cell_centroid += mesh.
vertices[vid];
277 cell_centroid /=
static_cast<double>(cell_vertex_ids.size());
std::vector< uint64_t > vertex_ids_
Vertex centroid_
The face centroid.
std::vector< CellFace > faces_
std::vector< uint64_t > vertex_ids_
Edge MakeUniqueEdge(const Edge &edge)
std::set< size_t > FindNeighborFaceIndices(const std::vector< std::vector< uint64_t > > &proxy_faces, size_t face_index)
Edge MakeEdgeFromPolygonEdgeIndex(const std::vector< uint64_t > &vertex_ids, size_t edge_index)
std::vector< Edge > FindNonManifoldEdges(const std::vector< std::vector< uint64_t > > &proxy_faces)
void PopulatePolyhedronFromFaces(const MeshContinuum &mesh, const std::vector< std::vector< uint64_t > > &raw_faces, chi_mesh::Cell &cell)
std::vector< Edge > StitchEdgesEndToEnd(const std::vector< Edge > &edges)
bool CheckPolyhedronQuality(const MeshContinuum &mesh, const chi_mesh::Cell &cell, bool check_convexity=false)