Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/intern/mesh_intersect.cc
| Show First 20 Lines • Show All 468 Lines • ▼ Show 20 Lines | # endif | ||||
| * Since it is only used for that purpose, access is not lock-protected. | * Since it is only used for that purpose, access is not lock-protected. | ||||
| * The argument vs can be a cyclic shift of the actual stored Face. | * The argument vs can be a cyclic shift of the actual stored Face. | ||||
| */ | */ | ||||
| const Face *find_face(Span<const Vert *> vs) | const Face *find_face(Span<const Vert *> vs) | ||||
| { | { | ||||
| Array<int> eorig(vs.size(), NO_INDEX); | Array<int> eorig(vs.size(), NO_INDEX); | ||||
| Array<bool> is_intersect(vs.size(), false); | Array<bool> is_intersect(vs.size(), false); | ||||
| Face ftry(vs, NO_INDEX, NO_INDEX, eorig, is_intersect); | Face ftry(vs, NO_INDEX, NO_INDEX, eorig, is_intersect); | ||||
| for (const int i : allocated_faces_.index_range()) { | for (const int i : iter_indices(allocated_faces_)) { | ||||
| if (ftry.cyclic_equal(*allocated_faces_[i])) { | if (ftry.cyclic_equal(*allocated_faces_[i])) { | ||||
| return allocated_faces_[i].get(); | return allocated_faces_[i].get(); | ||||
| } | } | ||||
| } | } | ||||
| return nullptr; | return nullptr; | ||||
| } | } | ||||
| private: | private: | ||||
| ▲ Show 20 Lines • Show All 153 Lines • ▼ Show 20 Lines | std::sort(vert_.begin(), vert_.end(), [](const Vert *a, const Vert *b) { | ||||
| if (a->orig != NO_INDEX) { | if (a->orig != NO_INDEX) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| if (b->orig != NO_INDEX) { | if (b->orig != NO_INDEX) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| return a->id < b->id; | return a->id < b->id; | ||||
| }); | }); | ||||
| for (int i : vert_.index_range()) { | for (int i : iter_indices(vert_)) { | ||||
| const Vert *v = vert_[i]; | const Vert *v = vert_[i]; | ||||
| vert_to_index_.add_overwrite(v, i); | vert_to_index_.add_overwrite(v, i); | ||||
| } | } | ||||
| } | } | ||||
| vert_populated_ = true; | vert_populated_ = true; | ||||
| } | } | ||||
| bool IMesh::erase_face_positions(int f_index, Span<bool> face_pos_erase, IMeshArena *arena) | bool IMesh::erase_face_positions(int f_index, Span<bool> face_pos_erase, IMeshArena *arena) | ||||
| ▲ Show 20 Lines • Show All 332 Lines • ▼ Show 20 Lines | public: | ||||
| const CoplanarCluster *end() | const CoplanarCluster *end() | ||||
| { | { | ||||
| return clusters_.end(); | return clusters_.end(); | ||||
| } | } | ||||
| IndexRange index_range() const | IndexRange index_range() const | ||||
| { | { | ||||
| return clusters_.index_range(); | return iter_indices(clusters_); | ||||
| } | } | ||||
| const CoplanarCluster &cluster(int index) const | const CoplanarCluster &cluster(int index) const | ||||
| { | { | ||||
| BLI_assert(index < clusters_.size()); | BLI_assert(index < clusters_.size()); | ||||
| return clusters_[index]; | return clusters_[index]; | ||||
| } | } | ||||
| }; | }; | ||||
| ▲ Show 20 Lines • Show All 736 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| constexpr int dbg_level = 0; | constexpr int dbg_level = 0; | ||||
| CDT_input<mpq_class> cdt_in; | CDT_input<mpq_class> cdt_in; | ||||
| cdt_in.vert = Span<mpq2>(cd.vert); | cdt_in.vert = Span<mpq2>(cd.vert); | ||||
| cdt_in.edge = Span<std::pair<int, int>>(cd.edge); | cdt_in.edge = Span<std::pair<int, int>>(cd.edge); | ||||
| cdt_in.face = Span<Vector<int>>(cd.face); | cdt_in.face = Span<Vector<int>>(cd.face); | ||||
| if (dbg_level > 0) { | if (dbg_level > 0) { | ||||
| std::cout << "CDT input\nVerts:\n"; | std::cout << "CDT input\nVerts:\n"; | ||||
| for (int i : cdt_in.vert.index_range()) { | for (int i : iter_indices(cdt_in.vert)) { | ||||
| std::cout << "v" << i << ": " << cdt_in.vert[i] << "=(" << cdt_in.vert[i][0].get_d() << "," | std::cout << "v" << i << ": " << cdt_in.vert[i] << "=(" << cdt_in.vert[i][0].get_d() << "," | ||||
| << cdt_in.vert[i][1].get_d() << ")\n"; | << cdt_in.vert[i][1].get_d() << ")\n"; | ||||
| } | } | ||||
| std::cout << "Edges:\n"; | std::cout << "Edges:\n"; | ||||
| for (int i : cdt_in.edge.index_range()) { | for (int i : iter_indices(cdt_in.edge)) { | ||||
| std::cout << "e" << i << ": (" << cdt_in.edge[i].first << ", " << cdt_in.edge[i].second | std::cout << "e" << i << ": (" << cdt_in.edge[i].first << ", " << cdt_in.edge[i].second | ||||
| << ")\n"; | << ")\n"; | ||||
| } | } | ||||
| std::cout << "Tris\n"; | std::cout << "Tris\n"; | ||||
| for (int f : cdt_in.face.index_range()) { | for (int f : iter_indices(cdt_in.face)) { | ||||
| std::cout << "f" << f << ": "; | std::cout << "f" << f << ": "; | ||||
| for (int j : cdt_in.face[f].index_range()) { | for (int j : iter_indices(cdt_in.face[f])) { | ||||
| std::cout << cdt_in.face[f][j] << " "; | std::cout << cdt_in.face[f][j] << " "; | ||||
| } | } | ||||
| std::cout << "\n"; | std::cout << "\n"; | ||||
| } | } | ||||
| } | } | ||||
| cdt_in.epsilon = 0; /* TODO: needs attention for non-exact T. */ | cdt_in.epsilon = 0; /* TODO: needs attention for non-exact T. */ | ||||
| cd.cdt_out = blender::meshintersect::delaunay_2d_calc(cdt_in, CDT_INSIDE); | cd.cdt_out = blender::meshintersect::delaunay_2d_calc(cdt_in, CDT_INSIDE); | ||||
| if (dbg_level > 0) { | if (dbg_level > 0) { | ||||
| std::cout << "\nCDT result\nVerts:\n"; | std::cout << "\nCDT result\nVerts:\n"; | ||||
| for (int i : cd.cdt_out.vert.index_range()) { | for (int i : iter_indices(cd.cdt_out.vert)) { | ||||
| std::cout << "v" << i << ": " << cd.cdt_out.vert[i] << "=(" << cd.cdt_out.vert[i][0].get_d() | std::cout << "v" << i << ": " << cd.cdt_out.vert[i] << "=(" << cd.cdt_out.vert[i][0].get_d() | ||||
| << "," << cd.cdt_out.vert[i][1].get_d() << "\n"; | << "," << cd.cdt_out.vert[i][1].get_d() << "\n"; | ||||
| } | } | ||||
| std::cout << "Tris\n"; | std::cout << "Tris\n"; | ||||
| for (int f : cd.cdt_out.face.index_range()) { | for (int f : iter_indices(cd.cdt_out.face)) { | ||||
| std::cout << "f" << f << ": "; | std::cout << "f" << f << ": "; | ||||
| for (int j : cd.cdt_out.face[f].index_range()) { | for (int j : iter_indices(cd.cdt_out.face[f])) { | ||||
| std::cout << cd.cdt_out.face[f][j] << " "; | std::cout << cd.cdt_out.face[f][j] << " "; | ||||
| } | } | ||||
| std::cout << "orig: "; | std::cout << "orig: "; | ||||
| for (int j : cd.cdt_out.face_orig[f].index_range()) { | for (int j : iter_indices(cd.cdt_out.face_orig[f])) { | ||||
| std::cout << cd.cdt_out.face_orig[f][j] << " "; | std::cout << cd.cdt_out.face_orig[f][j] << " "; | ||||
| } | } | ||||
| std::cout << "\n"; | std::cout << "\n"; | ||||
| } | } | ||||
| std::cout << "Edges\n"; | std::cout << "Edges\n"; | ||||
| for (int e : cd.cdt_out.edge.index_range()) { | for (int e : iter_indices(cd.cdt_out.edge)) { | ||||
| std::cout << "e" << e << ": (" << cd.cdt_out.edge[e].first << ", " | std::cout << "e" << e << ": (" << cd.cdt_out.edge[e].first << ", " | ||||
| << cd.cdt_out.edge[e].second << ") "; | << cd.cdt_out.edge[e].second << ") "; | ||||
| std::cout << "orig: "; | std::cout << "orig: "; | ||||
| for (int j : cd.cdt_out.edge_orig[e].index_range()) { | for (int j : iter_indices(cd.cdt_out.edge_orig[e])) { | ||||
| std::cout << cd.cdt_out.edge_orig[e][j] << " "; | std::cout << cd.cdt_out.edge_orig[e][j] << " "; | ||||
| } | } | ||||
| std::cout << "\n"; | std::cout << "\n"; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static int get_cdt_edge_orig( | static int get_cdt_edge_orig( | ||||
| int i0, int i1, const CDT_data &cd, const IMesh &in_tm, bool *r_is_intersect) | int i0, int i1, const CDT_data &cd, const IMesh &in_tm, bool *r_is_intersect) | ||||
| { | { | ||||
| int foff = cd.cdt_out.face_edge_offset; | int foff = cd.cdt_out.face_edge_offset; | ||||
| *r_is_intersect = false; | *r_is_intersect = false; | ||||
| for (int e : cd.cdt_out.edge.index_range()) { | for (int e : iter_indices(cd.cdt_out.edge)) { | ||||
| std::pair<int, int> edge = cd.cdt_out.edge[e]; | std::pair<int, int> edge = cd.cdt_out.edge[e]; | ||||
| if ((edge.first == i0 && edge.second == i1) || (edge.first == i1 && edge.second == i0)) { | if ((edge.first == i0 && edge.second == i1) || (edge.first == i1 && edge.second == i0)) { | ||||
| /* Pick an arbitrary orig, but not one equal to NO_INDEX, if we can help it. */ | /* Pick an arbitrary orig, but not one equal to NO_INDEX, if we can help it. */ | ||||
| /* TODO: if edge has origs from more than on part of the nary input, | /* TODO: if edge has origs from more than on part of the nary input, | ||||
| * then want to set *r_is_intersect to true. */ | * then want to set *r_is_intersect to true. */ | ||||
| for (int orig_index : cd.cdt_out.edge_orig[e]) { | for (int orig_index : cd.cdt_out.edge_orig[e]) { | ||||
| /* orig_index encodes the triangle and pos within the triangle of the input edge. */ | /* orig_index encodes the triangle and pos within the triangle of the input edge. */ | ||||
| if (orig_index >= foff) { | if (orig_index >= foff) { | ||||
| ▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | static IMesh extract_subdivided_tri(const CDT_data &cd, | ||||
| if (t_in_cdt == -1) { | if (t_in_cdt == -1) { | ||||
| std::cout << "Could not find " << t << " in cdt input tris\n"; | std::cout << "Could not find " << t << " in cdt input tris\n"; | ||||
| BLI_assert(false); | BLI_assert(false); | ||||
| return IMesh(); | return IMesh(); | ||||
| } | } | ||||
| int t_orig = in_tm.face(t)->orig; | int t_orig = in_tm.face(t)->orig; | ||||
| constexpr int inline_buf_size = 20; | constexpr int inline_buf_size = 20; | ||||
| Vector<Face *, inline_buf_size> faces; | Vector<Face *, inline_buf_size> faces; | ||||
| for (int f : cdt_out.face.index_range()) { | for (int f : iter_indices(cdt_out.face)) { | ||||
| if (cdt_out.face_orig[f].contains(t_in_cdt)) { | if (cdt_out.face_orig[f].contains(t_in_cdt)) { | ||||
| BLI_assert(cdt_out.face[f].size() == 3); | BLI_assert(cdt_out.face[f].size() == 3); | ||||
| int i0 = cdt_out.face[f][0]; | int i0 = cdt_out.face[f][0]; | ||||
| int i1 = cdt_out.face[f][1]; | int i1 = cdt_out.face[f][1]; | ||||
| int i2 = cdt_out.face[f][2]; | int i2 = cdt_out.face[f][2]; | ||||
| mpq3 v0co = unproject_cdt_vert(cd, cdt_out.vert[i0]); | mpq3 v0co = unproject_cdt_vert(cd, cdt_out.vert[i0]); | ||||
| mpq3 v1co = unproject_cdt_vert(cd, cdt_out.vert[i1]); | mpq3 v1co = unproject_cdt_vert(cd, cdt_out.vert[i1]); | ||||
| mpq3 v2co = unproject_cdt_vert(cd, cdt_out.vert[i2]); | mpq3 v2co = unproject_cdt_vert(cd, cdt_out.vert[i2]); | ||||
| ▲ Show 20 Lines • Show All 961 Lines • Show Last 20 Lines | |||||