12 const std::set<uint64_t> &cut_vertices,
18 const auto& p = plane_point;
19 const auto& n = plane_normal;
22 auto VertexIsCut = [&cut_vertices](uint64_t vid)
24 auto result = cut_vertices.find(vid);
26 if (result != cut_vertices.end())
33 auto EdgeIsCut = [&cut_edges](
const Edge& edge)
35 Edge edge_set(std::min(edge.first,edge.second),
36 std::max(edge.first,edge.second));
38 constexpr auto Arg1 = std::placeholders::_1;
39 constexpr auto Comparator = &ECI::Comparator;
41 auto result = std::find_if(cut_edges.begin(),
43 std::bind(Comparator,Arg1,edge_set));
45 if (result != cut_edges.end())
46 return std::make_pair(
true,*result);
48 return std::make_pair(
false,*result);
55 size_t num_edges = num_verts;
57 std::vector<bool> vertex_cut_flags(num_verts,
false);
58 std::vector<bool> edge_cut_flags(num_edges,
false);
59 std::vector<ECI> edge_cut_info(num_edges);
61 for (
size_t e=0; e<num_edges; ++e)
63 vertex_cut_flags[e] = VertexIsCut(cell.
vertex_ids_[e]);
66 auto cut_nature = EdgeIsCut(edge);
67 edge_cut_flags[e] = cut_nature.first;
68 if (cut_nature.first) edge_cut_info[e] = cut_nature.second;
70 edge_cut_info[e].vertex_ids = edge;
85 CurVertex which_vertex=CurVertex::AT_FIRST;
87 CurCutInfo() =
default;
89 CurCutInfo(
int in_which_edge, CurVertex in_which_vertex) :
90 which_edge(in_which_edge),
91 which_vertex(in_which_vertex) {}
100 auto GetVerticesTillNextCut =
101 [&cell,&edge_cut_flags,&edge_cut_info,&VertexIsCut](
102 CurCutInfo start_cut_info)
105 std::vector<uint64_t> vertex_ids;
106 vertex_ids.reserve(num_verts);
108 int e = start_cut_info.which_edge;
111 switch (start_cut_info.which_vertex)
113 case CurVertex::AT_FIRST:
115 vertex_ids.push_back(edge_cut_info[e].vertex_ids.first);
116 vertex_ids.push_back(edge_cut_info[e].vertex_ids.second);
118 if (VertexIsCut(edge_cut_info[e].vertex_ids.second))
120 end_type = CurVertex::AT_SECOND;
121 goto skip_to_return_portion;
126 case CurVertex::AT_CUT_POINT:
128 vertex_ids.push_back(edge_cut_info[e].cut_point_id);
129 vertex_ids.push_back(edge_cut_info[e].vertex_ids.second);
131 if (VertexIsCut(edge_cut_info[e].vertex_ids.second))
133 end_type = CurVertex::AT_SECOND;
134 goto skip_to_return_portion;
139 case CurVertex::AT_SECOND:
147 for (
int eref=0; eref<num_verts; ++eref)
149 e = (e<(num_verts-1))? e+1 : 0;
151 if (e == start_cut_info.which_edge)
break;
153 if (edge_cut_flags[e])
155 vertex_ids.push_back(edge_cut_info[e].cut_point_id);
156 end_type = CurVertex::AT_CUT_POINT;
159 else if (VertexIsCut(edge_cut_info[e].vertex_ids.second))
161 vertex_ids.push_back(edge_cut_info[e].vertex_ids.second);
162 end_type = CurVertex::AT_SECOND;
166 vertex_ids.push_back(edge_cut_info[e].vertex_ids.second);
169 skip_to_return_portion:
170 CurCutInfo end_cut_info(e, end_type);
172 return std::make_pair(vertex_ids,end_cut_info);
175 typedef std::pair<std::vector<uint64_t>,CurCutInfo> LoopInfo;
180 std::vector<std::vector<uint64_t>> loops_to_add_to_mesh;
181 std::vector<CurCutInfo> cut_history;
182 for (
size_t e=0; e<num_edges; ++e)
186 if (vertex_cut_flags[e])
187 loop_info = GetVerticesTillNextCut(CurCutInfo(e,CurVertex::AT_FIRST));
188 else if (edge_cut_flags[e])
189 loop_info = GetVerticesTillNextCut(CurCutInfo(e,CurVertex::AT_CUT_POINT));
192 std::vector<uint64_t> verts_to_next_cut = loop_info.first;
193 int end_edge = loop_info.second.which_edge;
194 CurVertex end_type = loop_info.second.which_vertex;
204 e = int(num_edges)-1;
205 else if (end_type == CurVertex::AT_SECOND)
210 loops_to_add_to_mesh.push_back(verts_to_next_cut);
218 if (not loops_to_add_to_mesh.empty())
220 auto& back_loop = loops_to_add_to_mesh.back();
223 loops_to_add_to_mesh.pop_back();
227 for (
auto& loop : loops_to_add_to_mesh)
229 auto new_cell = std::make_unique<chi_mesh::Cell>(CellType::POLYGON,
std::vector< uint64_t > vertex_ids_
void push_back(std::unique_ptr< chi_mesh::Cell > new_cell)
void PopulatePolygonFromVertices(const MeshContinuum &mesh, const std::vector< uint64_t > &vertex_ids, chi_mesh::Cell &cell)
void CutPolygon(const std::vector< ECI > &cut_edges, const std::set< uint64_t > &cut_vertices, const Vector3 &plane_point, const Vector3 &plane_normal, MeshContinuum &mesh, chi_mesh::Cell &cell)
Edge MakeEdgeFromPolygonEdgeIndex(const std::vector< uint64_t > &vertex_ids, size_t edge_index)
std::pair< uint64_t, uint64_t > Edge