Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/intern/delaunay_2d.cc
| Show First 20 Lines • Show All 332 Lines • ▼ Show 20 Lines | public: | ||||
| /** How close before coords considered equal. */ | /** How close before coords considered equal. */ | ||||
| T epsilon; | T epsilon; | ||||
| explicit CDT_state(int num_input_verts, int num_input_edges, int num_input_faces, T epsilon); | explicit CDT_state(int num_input_verts, int num_input_edges, int num_input_faces, T epsilon); | ||||
| }; | }; | ||||
| template<typename T> CDTArrangement<T>::~CDTArrangement() | template<typename T> CDTArrangement<T>::~CDTArrangement() | ||||
| { | { | ||||
| for (int i : this->verts.index_range()) { | for (int i : iter_indices(this->verts)) { | ||||
| CDTVert<T> *v = this->verts[i]; | CDTVert<T> *v = this->verts[i]; | ||||
| BLI_linklist_free(v->input_ids, nullptr); | BLI_linklist_free(v->input_ids, nullptr); | ||||
| delete v; | delete v; | ||||
| this->verts[i] = nullptr; | this->verts[i] = nullptr; | ||||
| } | } | ||||
| for (int i : this->edges.index_range()) { | for (int i : iter_indices(this->edges)) { | ||||
| CDTEdge<T> *e = this->edges[i]; | CDTEdge<T> *e = this->edges[i]; | ||||
| BLI_linklist_free(e->input_ids, nullptr); | BLI_linklist_free(e->input_ids, nullptr); | ||||
| delete e; | delete e; | ||||
| this->edges[i] = nullptr; | this->edges[i] = nullptr; | ||||
| } | } | ||||
| for (int i : this->faces.index_range()) { | for (int i : iter_indices(this->faces)) { | ||||
| CDTFace<T> *f = this->faces[i]; | CDTFace<T> *f = this->faces[i]; | ||||
| BLI_linklist_free(f->input_ids, nullptr); | BLI_linklist_free(f->input_ids, nullptr); | ||||
| delete f; | delete f; | ||||
| this->faces[i] = nullptr; | this->faces[i] = nullptr; | ||||
| } | } | ||||
| } | } | ||||
| #define DEBUG_CDT | #define DEBUG_CDT | ||||
| ▲ Show 20 Lines • Show All 2,307 Lines • ▼ Show 20 Lines | extern "C" ::CDT_result *BLI_delaunay_2d_cdt_calc(const ::CDT_input *input, | ||||
| output->faces_orig_len_table = static_cast<int *>(MEM_malloc_arrayN(nf, sizeof(int), __func__)); | output->faces_orig_len_table = static_cast<int *>(MEM_malloc_arrayN(nf, sizeof(int), __func__)); | ||||
| int v_orig_index = 0; | int v_orig_index = 0; | ||||
| for (int v = 0; v < nv; ++v) { | for (int v = 0; v < nv; ++v) { | ||||
| output->vert_coords[v][0] = static_cast<float>(res.vert[v][0]); | output->vert_coords[v][0] = static_cast<float>(res.vert[v][0]); | ||||
| output->vert_coords[v][1] = static_cast<float>(res.vert[v][1]); | output->vert_coords[v][1] = static_cast<float>(res.vert[v][1]); | ||||
| int this_start = v_orig_index; | int this_start = v_orig_index; | ||||
| output->verts_orig_start_table[v] = this_start; | output->verts_orig_start_table[v] = this_start; | ||||
| for (int j : res.vert_orig[v].index_range()) { | for (int j : iter_indices(res.vert_orig[v])) { | ||||
| output->verts_orig[v_orig_index++] = res.vert_orig[v][j]; | output->verts_orig[v_orig_index++] = res.vert_orig[v][j]; | ||||
| } | } | ||||
| output->verts_orig_len_table[v] = v_orig_index - this_start; | output->verts_orig_len_table[v] = v_orig_index - this_start; | ||||
| } | } | ||||
| int e_orig_index = 0; | int e_orig_index = 0; | ||||
| for (int e = 0; e < ne; ++e) { | for (int e = 0; e < ne; ++e) { | ||||
| output->edges[e][0] = res.edge[e].first; | output->edges[e][0] = res.edge[e].first; | ||||
| output->edges[e][1] = res.edge[e].second; | output->edges[e][1] = res.edge[e].second; | ||||
| int this_start = e_orig_index; | int this_start = e_orig_index; | ||||
| output->edges_orig_start_table[e] = this_start; | output->edges_orig_start_table[e] = this_start; | ||||
| for (int j : res.edge_orig[e].index_range()) { | for (int j : iter_indices(res.edge_orig[e])) { | ||||
| output->edges_orig[e_orig_index++] = res.edge_orig[e][j]; | output->edges_orig[e_orig_index++] = res.edge_orig[e][j]; | ||||
| } | } | ||||
| output->edges_orig_len_table[e] = e_orig_index - this_start; | output->edges_orig_len_table[e] = e_orig_index - this_start; | ||||
| } | } | ||||
| int f_orig_index = 0; | int f_orig_index = 0; | ||||
| int f_index = 0; | int f_index = 0; | ||||
| for (int f = 0; f < nf; ++f) { | for (int f = 0; f < nf; ++f) { | ||||
| output->faces_start_table[f] = f_index; | output->faces_start_table[f] = f_index; | ||||
| int flen = res.face[f].size(); | int flen = res.face[f].size(); | ||||
| output->faces_len_table[f] = flen; | output->faces_len_table[f] = flen; | ||||
| for (int j = 0; j < flen; ++j) { | for (int j = 0; j < flen; ++j) { | ||||
| output->faces[f_index++] = res.face[f][j]; | output->faces[f_index++] = res.face[f][j]; | ||||
| } | } | ||||
| int this_start = f_orig_index; | int this_start = f_orig_index; | ||||
| output->faces_orig_start_table[f] = this_start; | output->faces_orig_start_table[f] = this_start; | ||||
| for (int k : res.face_orig[f].index_range()) { | for (int k : iter_indices(res.face_orig[f])) { | ||||
| output->faces_orig[f_orig_index++] = res.face_orig[f][k]; | output->faces_orig[f_orig_index++] = res.face_orig[f][k]; | ||||
| } | } | ||||
| output->faces_orig_len_table[f] = f_orig_index - this_start; | output->faces_orig_len_table[f] = f_orig_index - this_start; | ||||
| } | } | ||||
| return output; | return output; | ||||
| } | } | ||||
| extern "C" void BLI_delaunay_2d_cdt_free(::CDT_result *result) | extern "C" void BLI_delaunay_2d_cdt_free(::CDT_result *result) | ||||
| Show All 17 Lines | |||||