diff options
Diffstat (limited to 'source/blender/geometry')
-rw-r--r-- | source/blender/geometry/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/blender/geometry/GEO_uv_parametrizer.h | 4 | ||||
-rw-r--r-- | source/blender/geometry/intern/add_curves_on_mesh.cc | 3 | ||||
-rw-r--r-- | source/blender/geometry/intern/resample_curves.cc | 2 | ||||
-rw-r--r-- | source/blender/geometry/intern/set_curve_type.cc | 124 | ||||
-rw-r--r-- | source/blender/geometry/intern/uv_parametrizer.cc (renamed from source/blender/geometry/intern/uv_parametrizer.c) | 355 |
6 files changed, 223 insertions, 267 deletions
diff --git a/source/blender/geometry/CMakeLists.txt b/source/blender/geometry/CMakeLists.txt index da83d9e8957..0f06890cbfa 100644 --- a/source/blender/geometry/CMakeLists.txt +++ b/source/blender/geometry/CMakeLists.txt @@ -27,7 +27,7 @@ set(SRC intern/reverse_uv_sampler.cc intern/set_curve_type.cc intern/subdivide_curves.cc - intern/uv_parametrizer.c + intern/uv_parametrizer.cc GEO_add_curves_on_mesh.hh GEO_fillet_curves.hh diff --git a/source/blender/geometry/GEO_uv_parametrizer.h b/source/blender/geometry/GEO_uv_parametrizer.h index 5285aefbd4c..ff110f18ffb 100644 --- a/source/blender/geometry/GEO_uv_parametrizer.h +++ b/source/blender/geometry/GEO_uv_parametrizer.h @@ -13,8 +13,8 @@ extern "C" { #endif typedef struct ParamHandle ParamHandle; /* Handle to an array of charts. */ -typedef intptr_t ParamKey; /* Key (hash) for identifying verts and faces. */ -#define PARAM_KEY_MAX INTPTR_MAX +typedef uintptr_t ParamKey; /* Key (hash) for identifying verts and faces. */ +#define PARAM_KEY_MAX UINTPTR_MAX /* -------------------------------------------------------------------- */ /** \name Chart Construction: diff --git a/source/blender/geometry/intern/add_curves_on_mesh.cc b/source/blender/geometry/intern/add_curves_on_mesh.cc index 7184d774a22..299040d4d32 100644 --- a/source/blender/geometry/intern/add_curves_on_mesh.cc +++ b/source/blender/geometry/intern/add_curves_on_mesh.cc @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ #include "BLI_length_parameterize.hh" +#include "BLI_task.hh" #include "BKE_attribute_math.hh" #include "BKE_mesh_sample.hh" @@ -102,8 +103,8 @@ void interpolate_from_neighbors(const Span<NeighborCurves> neighbors_per_curve, } } } + mixer.finalize(range); }); - mixer.finalize(); } static void interpolate_position_without_interpolation( diff --git a/source/blender/geometry/intern/resample_curves.cc b/source/blender/geometry/intern/resample_curves.cc index cac6d69f58c..e4cb99a9eac 100644 --- a/source/blender/geometry/intern/resample_curves.cc +++ b/source/blender/geometry/intern/resample_curves.cc @@ -154,7 +154,7 @@ static void gather_point_attributes_to_interpolate(const CurveComponent &src_com retrieve_attribute_spans( ids, src_component, dst_component, result.src, result.dst, result.dst_attributes); - /* Attributes that aren't interpolated like Bezier handles still have to be be copied + /* Attributes that aren't interpolated like Bezier handles still have to be copied * to the result when there are any unselected curves of the corresponding type. */ retrieve_attribute_spans(ids_no_interpolation, src_component, diff --git a/source/blender/geometry/intern/set_curve_type.cc b/source/blender/geometry/intern/set_curve_type.cc index 40ee2488a4b..92609a45bdc 100644 --- a/source/blender/geometry/intern/set_curve_type.cc +++ b/source/blender/geometry/intern/set_curve_type.cc @@ -286,42 +286,6 @@ static void retrieve_curve_sizes(const bke::CurvesGeometry &curves, MutableSpan< }); } -struct GenericAttributes : NonCopyable, NonMovable { - Vector<GSpan> src; - Vector<GMutableSpan> dst; - - Vector<bke::GSpanAttributeWriter> attributes; -}; - -static void retrieve_generic_point_attributes(const bke::AttributeAccessor &src_attributes, - bke::MutableAttributeAccessor &dst_attributes, - GenericAttributes &attributes) -{ - src_attributes.for_all( - [&](const bke::AttributeIDRef &id, const bke::AttributeMetaData meta_data) { - if (meta_data.domain != ATTR_DOMAIN_POINT) { - /* Curve domain attributes are all copied directly to the result in one step. */ - return true; - } - if (src_attributes.is_builtin(id)) { - if (!(id.is_named() && ELEM(id, "tilt", "radius"))) { - return true; - } - } - - GVArray src_attribute = src_attributes.lookup(id, ATTR_DOMAIN_POINT); - BLI_assert(src_attribute); - attributes.src.append(src_attribute.get_internal_span()); - - bke::GSpanAttributeWriter dst_attribute = dst_attributes.lookup_or_add_for_write_span( - id, ATTR_DOMAIN_POINT, meta_data.data_type); - attributes.dst.append(dst_attribute.span); - attributes.attributes.append(std::move(dst_attribute)); - - return true; - }); -} - static bke::CurvesGeometry convert_curves_to_bezier(const bke::CurvesGeometry &src_curves, const IndexMask selection) { @@ -347,8 +311,16 @@ static bke::CurvesGeometry convert_curves_to_bezier(const bke::CurvesGeometry &s const bke::AttributeAccessor src_attributes = src_curves.attributes(); bke::MutableAttributeAccessor dst_attributes = dst_curves.attributes_for_write(); - GenericAttributes attributes; - retrieve_generic_point_attributes(src_attributes, dst_attributes, attributes); + Vector<bke::AttributeTransferData> generic_attributes = bke::retrieve_attributes_for_transfer( + src_attributes, + dst_attributes, + ATTR_DOMAIN_MASK_POINT, + {"position", + "handle_type_left", + "handle_type_right", + "handle_right", + "handle_left", + "nurbs_weight"}); MutableSpan<float3> dst_positions = dst_curves.positions_for_write(); MutableSpan<float3> dst_handles_l = dst_curves.handle_positions_left_for_write(); @@ -373,9 +345,9 @@ static bke::CurvesGeometry convert_curves_to_bezier(const bke::CurvesGeometry &s } }); - for (const int i : attributes.src.index_range()) { + for (bke::AttributeTransferData &attribute : generic_attributes) { bke::curves::copy_point_data( - src_curves, dst_curves, selection, attributes.src[i], attributes.dst[i]); + src_curves, dst_curves, selection, attribute.src, attribute.dst.span); } }; @@ -384,9 +356,9 @@ static bke::CurvesGeometry convert_curves_to_bezier(const bke::CurvesGeometry &s bke::curves::fill_points<int8_t>(dst_curves, selection, BEZIER_HANDLE_VECTOR, dst_types_l); bke::curves::fill_points<int8_t>(dst_curves, selection, BEZIER_HANDLE_VECTOR, dst_types_r); dst_curves.calculate_bezier_auto_handles(); - for (const int i : attributes.src.index_range()) { + for (bke::AttributeTransferData &attribute : generic_attributes) { bke::curves::copy_point_data( - src_curves, dst_curves, selection, attributes.src[i], attributes.dst[i]); + src_curves, dst_curves, selection, attribute.src, attribute.dst.span); } }; @@ -404,9 +376,9 @@ static bke::CurvesGeometry convert_curves_to_bezier(const bke::CurvesGeometry &s dst_curves.calculate_bezier_auto_handles(); - for (const int i : attributes.src.index_range()) { + for (bke::AttributeTransferData &attribute : generic_attributes) { bke::curves::copy_point_data( - src_curves, dst_curves, selection, attributes.src[i], attributes.dst[i]); + src_curves, dst_curves, selection, attribute.src, attribute.dst.span); } }; @@ -445,14 +417,14 @@ static bke::CurvesGeometry convert_curves_to_bezier(const bke::CurvesGeometry &s } }); - for (const int i_attribute : attributes.src.index_range()) { + for (bke::AttributeTransferData &attribute : generic_attributes) { threading::parallel_for(selection.index_range(), 512, [&](IndexRange range) { for (const int i : selection.slice(range)) { const IndexRange src_points = src_curves.points_for_curve(i); const IndexRange dst_points = dst_curves.points_for_curve(i); - nurbs_to_bezier_assign(attributes.src[i_attribute].slice(src_points), + nurbs_to_bezier_assign(attribute.src.slice(src_points), KnotsMode(src_knot_modes[i]), - attributes.dst[i_attribute].slice(dst_points)); + attribute.dst.span.slice(dst_points)); } }); } @@ -469,13 +441,13 @@ static bke::CurvesGeometry convert_curves_to_bezier(const bke::CurvesGeometry &s const Vector<IndexRange> unselected_ranges = selection.extract_ranges_invert( src_curves.curves_range()); - for (const int i : attributes.src.index_range()) { + for (bke::AttributeTransferData &attribute : generic_attributes) { bke::curves::copy_point_data( - src_curves, dst_curves, unselected_ranges, attributes.src[i], attributes.dst[i]); + src_curves, dst_curves, unselected_ranges, attribute.src, attribute.dst.span); } - for (bke::GSpanAttributeWriter &attribute : attributes.attributes) { - attribute.finish(); + for (bke::AttributeTransferData &attribute : generic_attributes) { + attribute.dst.finish(); } return dst_curves; @@ -504,8 +476,16 @@ static bke::CurvesGeometry convert_curves_to_nurbs(const bke::CurvesGeometry &sr const bke::AttributeAccessor src_attributes = src_curves.attributes(); bke::MutableAttributeAccessor dst_attributes = dst_curves.attributes_for_write(); - GenericAttributes attributes; - retrieve_generic_point_attributes(src_attributes, dst_attributes, attributes); + Vector<bke::AttributeTransferData> generic_attributes = bke::retrieve_attributes_for_transfer( + src_attributes, + dst_attributes, + ATTR_DOMAIN_MASK_POINT, + {"position", + "handle_type_left", + "handle_type_right", + "handle_right", + "handle_left", + "nurbs_weight"}); MutableSpan<float3> dst_positions = dst_curves.positions_for_write(); @@ -529,13 +509,13 @@ static bke::CurvesGeometry convert_curves_to_nurbs(const bke::CurvesGeometry &sr } }); - for (const int i_attribute : attributes.src.index_range()) { + for (bke::AttributeTransferData &attribute : generic_attributes) { threading::parallel_for(selection.index_range(), 512, [&](IndexRange range) { for (const int i : selection.slice(range)) { const IndexRange src_points = src_curves.points_for_curve(i); const IndexRange dst_points = dst_curves.points_for_curve(i); - bezier_generic_to_nurbs(attributes.src[i_attribute].slice(src_points), - attributes.dst[i_attribute].slice(dst_points)); + bezier_generic_to_nurbs(attribute.src.slice(src_points), + attribute.dst.span.slice(dst_points)); } }); } @@ -563,12 +543,9 @@ static bke::CurvesGeometry convert_curves_to_nurbs(const bke::CurvesGeometry &sr }); } - for (const int i_attribute : attributes.src.index_range()) { - bke::curves::copy_point_data(src_curves, - dst_curves, - selection, - attributes.src[i_attribute], - attributes.dst[i_attribute]); + for (bke::AttributeTransferData &attribute : generic_attributes) { + bke::curves::copy_point_data( + src_curves, dst_curves, selection, attribute.src, attribute.dst.span); } }; @@ -591,13 +568,13 @@ static bke::CurvesGeometry convert_curves_to_nurbs(const bke::CurvesGeometry &sr } }); - for (const int i_attribute : attributes.src.index_range()) { + for (bke::AttributeTransferData &attribute : generic_attributes) { threading::parallel_for(selection.index_range(), 512, [&](IndexRange range) { for (const int i : selection.slice(range)) { const IndexRange src_points = src_curves.points_for_curve(i); const IndexRange dst_points = dst_curves.points_for_curve(i); - bezier_generic_to_nurbs(attributes.src[i_attribute].slice(src_points), - attributes.dst[i_attribute].slice(dst_points)); + bezier_generic_to_nurbs(attribute.src.slice(src_points), + attribute.dst.span.slice(dst_points)); } }); } @@ -614,12 +591,9 @@ static bke::CurvesGeometry convert_curves_to_nurbs(const bke::CurvesGeometry &sr dst_curves.nurbs_weights_for_write()); } - for (const int i_attribute : attributes.src.index_range()) { - bke::curves::copy_point_data(src_curves, - dst_curves, - selection, - attributes.src[i_attribute], - attributes.dst[i_attribute]); + for (bke::AttributeTransferData &attribute : generic_attributes) { + bke::curves::copy_point_data( + src_curves, dst_curves, selection, attribute.src, attribute.dst.span); } }; @@ -634,13 +608,13 @@ static bke::CurvesGeometry convert_curves_to_nurbs(const bke::CurvesGeometry &sr const Vector<IndexRange> unselected_ranges = selection.extract_ranges_invert( src_curves.curves_range()); - for (const int i : attributes.src.index_range()) { + for (bke::AttributeTransferData &attribute : generic_attributes) { bke::curves::copy_point_data( - src_curves, dst_curves, unselected_ranges, attributes.src[i], attributes.dst[i]); + src_curves, dst_curves, unselected_ranges, attribute.src, attribute.dst.span); } - for (bke::GSpanAttributeWriter &attribute : attributes.attributes) { - attribute.finish(); + for (bke::AttributeTransferData &attribute : generic_attributes) { + attribute.dst.finish(); } return dst_curves; diff --git a/source/blender/geometry/intern/uv_parametrizer.c b/source/blender/geometry/intern/uv_parametrizer.cc index 38924c718c3..b7526d82ecc 100644 --- a/source/blender/geometry/intern/uv_parametrizer.c +++ b/source/blender/geometry/intern/uv_parametrizer.cc @@ -30,7 +30,7 @@ /* Special Purpose Hash */ -typedef intptr_t PHashKey; +typedef uintptr_t PHashKey; typedef struct PHashLink { struct PHashLink *next; @@ -45,24 +45,22 @@ typedef struct PHash { /* Simplices */ -typedef struct PVert { +struct PVert { struct PVert *nextlink; union PVertUnion { PHashKey key; /* Construct. */ int id; /* ABF/LSCM matrix index. */ - float distortion; /* Area smoothing. */ HeapNode *heaplink; /* Edge collapsing. */ } u; struct PEdge *edge; float co[3]; float uv[2]; - uchar flag; - -} PVert; + uint flag; +}; -typedef struct PEdge { +struct PEdge { struct PEdge *nextlink; union PEdgeUnion { @@ -77,11 +75,10 @@ typedef struct PEdge { struct PEdge *next; struct PFace *face; float *orig_uv, old_uv[2]; - ushort flag; - -} PEdge; + uint flag; +}; -typedef struct PFace { +struct PFace { struct PFace *nextlink; union PFaceUnion { @@ -92,8 +89,8 @@ typedef struct PFace { } u; struct PEdge *edge; - uchar flag; -} PFace; + uint flag; +}; enum PVertFlag { PVERT_PIN = 1, @@ -126,7 +123,7 @@ enum PFaceFlag { /* Chart */ -typedef struct PChart { +struct PChart { PVert *verts; PEdge *edges; PFace *faces; @@ -153,12 +150,7 @@ typedef struct PChart { } pack; } u; - uchar flag; - ParamHandle *handle; -} PChart; - -enum PChartFlag { - PCHART_HAS_PINS = 1, + bool has_pins; }; enum PHandleState { @@ -168,7 +160,7 @@ enum PHandleState { PHANDLE_STATE_STRETCH, }; -typedef struct ParamHandle { +struct ParamHandle { enum PHandleState state; MemArena *arena; MemArena *polyfill_arena; @@ -189,7 +181,7 @@ typedef struct ParamHandle { RNG *rng; float blend; -} ParamHandle; +}; /* PHash * - special purpose hash that keeps all its elements in a single linked list. @@ -225,8 +217,10 @@ static PHash *phash_new(PHashLink **list, int sizehint) static void phash_delete(PHash *ph) { - MEM_freeN(ph->buckets); - MEM_freeN(ph); + if (ph) { + MEM_SAFE_FREE(ph->buckets); + MEM_freeN(ph); + } } static int phash_size(PHash *ph) @@ -240,7 +234,7 @@ static void phash_insert(PHash *ph, PHashLink *link) uintptr_t hash = PHASH_hash(ph, link->key); PHashLink *lookup = ph->buckets[hash]; - if (lookup == NULL) { + if (lookup == nullptr) { /* insert in front of the list */ ph->buckets[hash] = link; link->next = *(ph->list); @@ -255,13 +249,13 @@ static void phash_insert(PHash *ph, PHashLink *link) ph->size++; if (ph->size > (size * 3)) { - PHashLink *next = NULL, *first = *(ph->list); + PHashLink *next = nullptr, *first = *(ph->list); ph->cursize = PHashSizes[++ph->cursize_id]; MEM_freeN(ph->buckets); ph->buckets = (PHashLink **)MEM_callocN(ph->cursize * sizeof(*ph->buckets), "PHashBuckets"); ph->size = 0; - *(ph->list) = NULL; + *(ph->list) = nullptr; for (link = first; link; link = next) { next = link->next; @@ -280,7 +274,7 @@ static PHashLink *phash_lookup(PHash *ph, PHashKey key) return link; } if (PHASH_hash(ph, link->key) != hash) { - return NULL; + return nullptr; } } @@ -296,7 +290,7 @@ static PHashLink *phash_next(PHash *ph, PHashKey key, PHashLink *link) return link; } if (PHASH_hash(ph, link->key) != hash) { - return NULL; + return nullptr; } } @@ -462,7 +456,7 @@ static PEdge *p_wheel_edge_next(PEdge *e) static PEdge *p_wheel_edge_prev(PEdge *e) { - return (e->pair) ? e->pair->next : NULL; + return (e->pair) ? e->pair->next : nullptr; } static PEdge *p_boundary_edge_next(PEdge *e) @@ -670,9 +664,9 @@ static PVert *p_vert_lookup(ParamHandle *handle, PHashKey key, const float co[3] return p_vert_add(handle, key, co, e); } -static PVert *p_vert_copy(PChart *chart, PVert *v) +static PVert *p_vert_copy(ParamHandle *handle, PVert *v) { - PVert *nv = (PVert *)BLI_memarena_alloc(chart->handle->arena, sizeof(*nv)); + PVert *nv = (PVert *)BLI_memarena_alloc(handle->arena, sizeof(*nv)); copy_v3_v3(nv->co, v->co); nv->uv[0] = v->uv[0]; @@ -700,7 +694,7 @@ static PEdge *p_edge_lookup(ParamHandle *handle, const PHashKey *vkeys) e = (PEdge *)phash_next(handle->hash_edges, key, (PHashLink *)e); } - return NULL; + return nullptr; } static int p_face_exists(ParamHandle *handle, const ParamKey *pvkeys, int i1, int i2, int i3) @@ -727,20 +721,6 @@ static int p_face_exists(ParamHandle *handle, const ParamKey *pvkeys, int i1, in return false; } -static PChart *p_chart_new(ParamHandle *handle) -{ - PChart *chart = (PChart *)MEM_callocN(sizeof(*chart), "PChart"); - chart->handle = handle; - - return chart; -} - -static void p_chart_delete(PChart *chart) -{ - /* the actual links are free by memarena */ - MEM_freeN(chart); -} - static bool p_edge_implicit_seam(PEdge *e, PEdge *ep) { float *uv1, *uv2, *uvp1, *uvp2; @@ -789,7 +769,7 @@ static bool p_edge_has_pair(ParamHandle *handle, PEdge *e, bool topology_from_uv key = PHASH_edge(key1, key2); pe = (PEdge *)phash_lookup(handle->hash_edges, key); - *r_pair = NULL; + *r_pair = nullptr; while (pe) { if (pe != e) { @@ -802,7 +782,7 @@ static bool p_edge_has_pair(ParamHandle *handle, PEdge *e, bool topology_from_uv /* don't connect seams and t-junctions */ if ((pe->flag & PEDGE_SEAM) || *r_pair || (topology_from_uvs && p_edge_implicit_seam(e, pe))) { - *r_pair = NULL; + *r_pair = nullptr; return false; } @@ -816,12 +796,12 @@ static bool p_edge_has_pair(ParamHandle *handle, PEdge *e, bool topology_from_uv if (*r_pair && (e->vert == (*r_pair)->vert)) { if ((*r_pair)->next->pair || (*r_pair)->next->next->pair) { /* non unfoldable, maybe mobius ring or klein bottle */ - *r_pair = NULL; + *r_pair = nullptr; return false; } } - return (*r_pair != NULL); + return (*r_pair != nullptr); } static bool p_edge_connect_pair(ParamHandle *handle, @@ -829,7 +809,7 @@ static bool p_edge_connect_pair(ParamHandle *handle, bool topology_from_uvs, PEdge ***stack) { - PEdge *pair = NULL; + PEdge *pair = nullptr; if (!e->pair && p_edge_has_pair(handle, e, topology_from_uvs, &pair)) { if (e->vert == pair->vert) { @@ -845,13 +825,13 @@ static bool p_edge_connect_pair(ParamHandle *handle, } } - return (e->pair != NULL); + return (e->pair != nullptr); } static int p_connect_pairs(ParamHandle *handle, bool topology_from_uvs) { - PEdge **stackbase = MEM_mallocN(sizeof(*stackbase) * phash_size(handle->hash_faces), - "Pstackbase"); + PEdge **stackbase = (PEdge **)MEM_mallocN(sizeof(*stackbase) * phash_size(handle->hash_faces), + "Pstackbase"); PEdge **stack = stackbase; PFace *f, *first; PEdge *e, *e1, *e2; @@ -898,14 +878,14 @@ static int p_connect_pairs(ParamHandle *handle, bool topology_from_uvs) return ncharts; } -static void p_split_vert(PChart *chart, PEdge *e) +static void p_split_vert(ParamHandle *handle, PChart *chart, PEdge *e) { - PEdge *we, *lastwe = NULL; + PEdge *we, *lastwe = nullptr; PVert *v = e->vert; bool copy = true; if (e->flag & PEDGE_PIN) { - chart->flag |= PCHART_HAS_PINS; + chart->has_pins = true; } if (e->flag & PEDGE_VERTEX_SPLIT) { @@ -938,7 +918,7 @@ static void p_split_vert(PChart *chart, PEdge *e) if (copy) { /* not found, copying */ v->flag |= PVERT_SPLIT; - v = p_vert_copy(chart, v); + v = p_vert_copy(handle, v); v->flag |= PVERT_SPLIT; v->nextlink = chart->verts; @@ -957,20 +937,18 @@ static void p_split_vert(PChart *chart, PEdge *e) static PChart **p_split_charts(ParamHandle *handle, PChart *chart, int ncharts) { - PChart **charts = MEM_mallocN(sizeof(*charts) * ncharts, "PCharts"), *nchart; - PFace *f, *nextf; - int i; + PChart **charts = (PChart **)MEM_callocN(sizeof(*charts) * ncharts, "PCharts"); - for (i = 0; i < ncharts; i++) { - charts[i] = p_chart_new(handle); + for (int i = 0; i < ncharts; i++) { + charts[i] = (PChart *)MEM_callocN(sizeof(*chart), "PChart"); } - f = chart->faces; + PFace *f = chart->faces; while (f) { PEdge *e1 = f->edge, *e2 = e1->next, *e3 = e2->next; - nextf = f->nextlink; + PFace *nextf = f->nextlink; - nchart = charts[f->u.chart]; + PChart *nchart = charts[f->u.chart]; f->nextlink = nchart->faces; nchart->faces = f; @@ -984,9 +962,9 @@ static PChart **p_split_charts(ParamHandle *handle, PChart *chart, int ncharts) nchart->nfaces++; nchart->nedges += 3; - p_split_vert(nchart, e1); - p_split_vert(nchart, e2); - p_split_vert(nchart, e3); + p_split_vert(handle, nchart, e1); + p_split_vert(handle, nchart, e2); + p_split_vert(handle, nchart, e3); f = nextf; } @@ -1015,9 +993,9 @@ static PFace *p_face_add(ParamHandle *handle) e2->next = e3; e3->next = e1; - e1->pair = NULL; - e2->pair = NULL; - e3->pair = NULL; + e1->pair = nullptr; + e2->pair = nullptr; + e3->pair = nullptr; e1->flag = 0; e2->flag = 0; @@ -1086,16 +1064,16 @@ static PFace *p_face_add_construct(ParamHandle *handle, return f; } -static PFace *p_face_add_fill(PChart *chart, PVert *v1, PVert *v2, PVert *v3) +static PFace *p_face_add_fill(ParamHandle *handle, PChart *chart, PVert *v1, PVert *v2, PVert *v3) { - PFace *f = p_face_add(chart->handle); + PFace *f = p_face_add(handle); PEdge *e1 = f->edge, *e2 = e1->next, *e3 = e2->next; e1->vert = v1; e2->vert = v2; e3->vert = v3; - e1->orig_uv = e2->orig_uv = e3->orig_uv = NULL; + e1->orig_uv = e2->orig_uv = e3->orig_uv = nullptr; f->nextlink = chart->faces; chart->faces = f; @@ -1147,7 +1125,7 @@ static void p_chart_boundaries(PChart *chart, PEdge **r_outer) chart->nboundaries = 0; if (r_outer) { - *r_outer = NULL; + *r_outer = nullptr; } for (e = chart->edges; e; e = e->nextlink) { @@ -1202,7 +1180,7 @@ static float p_edge_boundary_angle(PEdge *e) return angle; } -static void p_chart_fill_boundary(PChart *chart, PEdge *be, int nedges) +static void p_chart_fill_boundary(ParamHandle *handle, PChart *chart, PEdge *be, int nedges) { PEdge *e, *e1, *e2; @@ -1238,12 +1216,12 @@ static void p_chart_fill_boundary(PChart *chart, PEdge *be, int nedges) BLI_heap_remove(heap, e1->u.heaplink); BLI_heap_remove(heap, e2->u.heaplink); - e->u.heaplink = e1->u.heaplink = e2->u.heaplink = NULL; + e->u.heaplink = e1->u.heaplink = e2->u.heaplink = nullptr; e->flag |= PEDGE_FILLED; e1->flag |= PEDGE_FILLED; - f = p_face_add_fill(chart, e->vert, e1->vert, e2->vert); + f = p_face_add_fill(handle, chart, e->vert, e1->vert, e2->vert); f->flag |= PFACE_FILLED; ne = f->edge->next->next; @@ -1276,10 +1254,10 @@ static void p_chart_fill_boundary(PChart *chart, PEdge *be, int nedges) } } - BLI_heap_free(heap, NULL); + BLI_heap_free(heap, nullptr); } -static void p_chart_fill_boundaries(PChart *chart, PEdge *outer) +static void p_chart_fill_boundaries(ParamHandle *handle, PChart *chart, PEdge *outer) { PEdge *e, *be; /* *enext - as yet unused */ int nedges; @@ -1300,7 +1278,7 @@ static void p_chart_fill_boundaries(PChart *chart, PEdge *outer) } while (be != e); if (e != outer) { - p_chart_fill_boundary(chart, e, nedges); + p_chart_fill_boundary(handle, chart, e, nedges); } } } @@ -1559,7 +1537,7 @@ static void p_vert_harmonic_insert(PVert *v) e = p_wheel_edge_next(e); } while (e && (e != v->edge)); - if (e == NULL) { + if (e == nullptr) { npoints++; } @@ -1573,7 +1551,7 @@ static void p_vert_harmonic_insert(PVert *v) points[i][0] = e->next->vert->uv[0]; points[i][1] = e->next->vert->uv[1]; - if (nexte == NULL) { + if (nexte == nullptr) { i++; points[i][0] = e->next->next->vert->uv[0]; points[i][1] = e->next->next->vert->uv[1]; @@ -1917,8 +1895,8 @@ static float p_collapse_cost(PEdge *edge, PEdge *pair) int nshapeold = 0, nshapenew = 0; p_collapsing_verts(edge, pair, &oldv, &keepv); - oldf1 = (edge) ? edge->face : NULL; - oldf2 = (pair) ? pair->face : NULL; + oldf1 = (edge) ? edge->face : nullptr; + oldf2 = (pair) ? pair->face : nullptr; sub_v3_v3v3(edgevec, keepv->co, oldv->co); @@ -1939,7 +1917,7 @@ static float p_collapse_cost(PEdge *edge, PEdge *pair) # if 0 shapecost += dot_v3v3(co1, keepv->co); - if (p_wheel_edge_next(e) == NULL) { + if (p_wheel_edge_next(e) == nullptr) { shapecost += dot_v3v3(co2, keepv->co); } # endif @@ -1992,14 +1970,14 @@ static void p_collapse_cost_vertex(PVert *vert, float *r_mincost, PEdge **r_mine { PEdge *e, *enext, *pair; - *r_mine = NULL; + *r_mine = nullptr; *r_mincost = 0.0f; e = vert->edge; do { if (p_collapse_allowed(e, e->pair)) { float cost = p_collapse_cost(e, e->pair); - if ((*r_mine == NULL) || (cost < *r_mincost)) { + if ((*r_mine == nullptr) || (cost < *r_mincost)) { *r_mincost = cost; *r_mine = e; } @@ -2007,14 +1985,14 @@ static void p_collapse_cost_vertex(PVert *vert, float *r_mincost, PEdge **r_mine enext = p_wheel_edge_next(e); - if (enext == NULL) { + if (enext == nullptr) { /* The other boundary edge, where we only have the pair half-edge. */ pair = e->next->next; - if (p_collapse_allowed(NULL, pair)) { - float cost = p_collapse_cost(NULL, pair); + if (p_collapse_allowed(nullptr, pair)) { + float cost = p_collapse_cost(nullptr, pair); - if ((*r_mine == NULL) || (cost < *r_mincost)) { + if ((*r_mine == nullptr) || (cost < *r_mincost)) { *r_mincost = cost; *r_mine = pair; } @@ -2031,13 +2009,13 @@ static void p_chart_post_collapse_flush(PChart *chart, PEdge *collapsed) { /* Move to `collapsed_*`. */ - PVert *v, *nextv = NULL, *verts = chart->verts; - PEdge *e, *nexte = NULL, *edges = chart->edges, *laste = NULL; - PFace *f, *nextf = NULL, *faces = chart->faces; + PVert *v, *nextv = nullptr, *verts = chart->verts; + PEdge *e, *nexte = nullptr, *edges = chart->edges, *laste = nullptr; + PFace *f, *nextf = nullptr, *faces = chart->faces; - chart->verts = chart->collapsed_verts = NULL; - chart->edges = chart->collapsed_edges = NULL; - chart->faces = chart->collapsed_faces = NULL; + chart->verts = chart->collapsed_verts = nullptr; + chart->edges = chart->collapsed_edges = nullptr; + chart->faces = chart->collapsed_faces = nullptr; chart->nverts = chart->nedges = chart->nfaces = 0; @@ -2101,9 +2079,9 @@ static void p_chart_post_split_flush(PChart *chart) { /* Move from `collapsed_*`. */ - PVert *v, *nextv = NULL; - PEdge *e, *nexte = NULL; - PFace *f, *nextf = NULL; + PVert *v, *nextv = nullptr; + PEdge *e, *nexte = nullptr; + PFace *f, *nextf = nullptr; for (v = chart->collapsed_verts; v; v = nextv) { nextv = v->nextlink; @@ -2126,9 +2104,9 @@ static void p_chart_post_split_flush(PChart *chart) chart->nfaces++; } - chart->collapsed_verts = NULL; - chart->collapsed_edges = NULL; - chart->collapsed_faces = NULL; + chart->collapsed_verts = nullptr; + chart->collapsed_edges = nullptr; + chart->collapsed_faces = nullptr; } static void p_chart_simplify_compute(PChart *chart) @@ -2140,7 +2118,7 @@ static void p_chart_simplify_compute(PChart *chart) Heap *heap = BLI_heap_new(); PVert *v, **wheelverts; - PEdge *collapsededges = NULL, *e; + PEdge *collapsededges = nullptr, *e; int nwheelverts, i, ncollapsed = 0; wheelverts = MEM_mallocN(sizeof(PVert *) * chart->nverts, "PChartWheelVerts"); @@ -2148,7 +2126,7 @@ static void p_chart_simplify_compute(PChart *chart) /* insert all potential collapses into heap */ for (v = chart->verts; v; v = v->nextlink) { float cost; - PEdge *e = NULL; + PEdge *e = nullptr; p_collapse_cost_vertex(v, &cost, &e); @@ -2156,12 +2134,12 @@ static void p_chart_simplify_compute(PChart *chart) v->u.heaplink = BLI_heap_insert(heap, cost, e); } else { - v->u.heaplink = NULL; + v->u.heaplink = nullptr; } } for (e = chart->edges; e; e = e->nextlink) { - e->u.nextcollapse = NULL; + e->u.nextcollapse = nullptr; } /* pop edge collapse out of heap one by one */ @@ -2181,12 +2159,12 @@ static void p_chart_simplify_compute(PChart *chart) if (edge->vert->u.heaplink != link) { edge->flag |= (PEDGE_COLLAPSE_EDGE | PEDGE_COLLAPSE_PAIR); - edge->next->vert->u.heaplink = NULL; + edge->next->vert->u.heaplink = nullptr; SWAP(PEdge *, edge, pair); } else { edge->flag |= PEDGE_COLLAPSE_EDGE; - edge->vert->u.heaplink = NULL; + edge->vert->u.heaplink = nullptr; } p_collapsing_verts(edge, pair, &oldv, &keepv); @@ -2199,7 +2177,7 @@ static void p_chart_simplify_compute(PChart *chart) wheelverts[nwheelverts++] = wheele->next->vert; nexte = p_wheel_edge_next(wheele); - if (nexte == NULL) { + if (nexte == nullptr) { wheelverts[nwheelverts++] = wheele->next->next->vert; } @@ -2211,13 +2189,13 @@ static void p_chart_simplify_compute(PChart *chart) for (i = 0; i < nwheelverts; i++) { float cost; - PEdge *collapse = NULL; + PEdge *collapse = nullptr; v = wheelverts[i]; if (v->u.heaplink) { BLI_heap_remove(heap, v->u.heaplink); - v->u.heaplink = NULL; + v->u.heaplink = nullptr; } p_collapse_cost_vertex(v, &cost, &collapse); @@ -2231,7 +2209,7 @@ static void p_chart_simplify_compute(PChart *chart) } MEM_freeN(wheelverts); - BLI_heap_free(heap, NULL); + BLI_heap_free(heap, nullptr); p_chart_post_collapse_flush(chart, collapsededges); } @@ -2282,14 +2260,14 @@ static void p_chart_simplify(PChart *chart) #define ABF_MAX_ITER 20 -typedef struct PAbfSystem { +using PAbfSystem = struct PAbfSystem { int ninterior, nfaces, nangles; float *alpha, *beta, *sine, *cosine, *weight; float *bAlpha, *bTriangle, *bInterior; float *lambdaTriangle, *lambdaPlanar, *lambdaLength; float (*J2dt)[3], *bstar, *dstar; float minangle, maxangle; -} PAbfSystem; +}; static void p_abf_setup_system(PAbfSystem *sys) { @@ -2309,7 +2287,7 @@ static void p_abf_setup_system(PAbfSystem *sys) sys->lambdaPlanar = (float *)MEM_callocN(sizeof(float) * sys->ninterior, "ABFlamdaplane"); sys->lambdaLength = (float *)MEM_mallocN(sizeof(float) * sys->ninterior, "ABFlambdalen"); - sys->J2dt = MEM_mallocN(sizeof(float) * sys->nangles * 3, "ABFj2dt"); + sys->J2dt = static_cast<float(*)[3]>(MEM_mallocN(sizeof(float) * sys->nangles * 3, "ABFj2dt")); sys->bstar = (float *)MEM_mallocN(sizeof(float) * sys->nfaces, "ABFbstar"); sys->dstar = (float *)MEM_mallocN(sizeof(float) * sys->nfaces, "ABFdstar"); @@ -2808,7 +2786,7 @@ static bool p_chart_abf_solve(PChart *chart) } } - chart->u.lscm.abf_alpha = MEM_dupallocN(sys.alpha); + chart->u.lscm.abf_alpha = (float *)MEM_dupallocN(sys.alpha); p_abf_free_system(&sys); return true; @@ -2869,8 +2847,8 @@ static void p_chart_pin_positions(PChart *chart, PVert **pin1, PVert **pin2) static bool p_chart_symmetry_pins(PChart *chart, PEdge *outer, PVert **pin1, PVert **pin2) { - PEdge *be, *lastbe = NULL, *maxe1 = NULL, *maxe2 = NULL, *be1, *be2; - PEdge *cure = NULL, *firste1 = NULL, *firste2 = NULL, *nextbe; + PEdge *be, *lastbe = nullptr, *maxe1 = nullptr, *maxe2 = nullptr, *be1, *be2; + PEdge *cure = nullptr, *firste1 = nullptr, *firste2 = nullptr, *nextbe; float maxlen = 0.0f, curlen = 0.0f, totlen = 0.0f, firstlen = 0.0f; float len1, len2; @@ -2909,7 +2887,7 @@ static bool p_chart_symmetry_pins(PChart *chart, PEdge *outer, PVert **pin1, PVe } curlen = 0.0f; - cure = NULL; + cure = nullptr; } lastbe = be; @@ -2984,8 +2962,8 @@ static void p_chart_extrema_verts(PChart *chart, PVert **pin1, PVert **pin2) minv[0] = minv[1] = minv[2] = 1e20; maxv[0] = maxv[1] = maxv[2] = -1e20; - minvert[0] = minvert[1] = minvert[2] = NULL; - maxvert[0] = maxvert[1] = maxvert[2] = NULL; + minvert[0] = minvert[1] = minvert[2] = nullptr; + maxvert[0] = maxvert[1] = maxvert[2] = nullptr; for (v = chart->verts; v; v = v->nextlink) { for (i = 0; i < 3; i++) { @@ -3049,7 +3027,7 @@ static void p_chart_lscm_begin(PChart *chart, bool live, bool abf) } if ((live && (!select || !deselect))) { - chart->u.lscm.context = NULL; + chart->u.lscm.context = nullptr; } else { #if 0 @@ -3266,16 +3244,14 @@ static void p_chart_lscm_transform_single_pin(PChart *chart) static void p_chart_lscm_end(PChart *chart) { - if (chart->u.lscm.context) { - EIG_linear_solver_delete(chart->u.lscm.context); - } + EIG_linear_solver_delete(chart->u.lscm.context); + chart->u.lscm.context = nullptr; MEM_SAFE_FREE(chart->u.lscm.abf_alpha); - chart->u.lscm.context = NULL; - chart->u.lscm.pin1 = NULL; - chart->u.lscm.pin2 = NULL; - chart->u.lscm.single_pin = NULL; + chart->u.lscm.pin1 = nullptr; + chart->u.lscm.pin2 = nullptr; + chart->u.lscm.single_pin = nullptr; chart->u.lscm.single_pin_area = 0.0f; } @@ -3288,7 +3264,7 @@ static void p_stretch_pin_boundary(PChart *chart) PVert *v; for (v = chart->verts; v; v = v->nextlink) { - if (v->edge->pair == NULL) { + if (v->edge->pair == nullptr) { v->flag |= PVERT_PIN; } else { @@ -3566,7 +3542,7 @@ static float p_chart_minimum_area_angle(PChart *chart) } /* find left/top/right/bottom points, and compute angle for each point */ - angles = MEM_mallocN(sizeof(float) * npoints, "PMinAreaAngles"); + angles = (float *)MEM_mallocN(sizeof(float) * npoints, "PMinAreaAngles"); i_min = i_max = 0; miny = 1e10; @@ -3690,7 +3666,8 @@ static void p_chart_rotate_minimum_area(PChart *chart) static void p_chart_rotate_fit_aabb(PChart *chart) { - float(*points)[2] = MEM_mallocN(sizeof(*points) * chart->nverts, __func__); + float(*points)[2] = static_cast<float(*)[2]>( + MEM_mallocN(sizeof(*points) * chart->nverts, __func__)); p_chart_uv_to_array(chart, points); @@ -3707,10 +3684,10 @@ static void p_chart_rotate_fit_aabb(PChart *chart) /* Exported */ -ParamHandle *GEO_uv_parametrizer_construct_begin(void) +ParamHandle *GEO_uv_parametrizer_construct_begin() { - ParamHandle *handle = MEM_callocN(sizeof(*handle), "ParamHandle"); - handle->construction_chart = p_chart_new(handle); + ParamHandle *handle = new ParamHandle(); + handle->construction_chart = (PChart *)MEM_callocN(sizeof(PChart), "PChart"); handle->state = PHANDLE_STATE_ALLOCATED; handle->arena = BLI_memarena_new(MEM_SIZE_OPTIMAL(1 << 16), "param construct arena"); handle->polyfill_arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "param polyfill arena"); @@ -3733,40 +3710,45 @@ void GEO_uv_parametrizer_aspect_ratio(ParamHandle *phandle, float aspx, float as void GEO_uv_parametrizer_delete(ParamHandle *phandle) { - int i; - + if (!phandle) { + return; + } param_assert(ELEM(phandle->state, PHANDLE_STATE_ALLOCATED, PHANDLE_STATE_CONSTRUCTED)); - for (i = 0; i < phandle->ncharts; i++) { - p_chart_delete(phandle->charts[i]); + for (int i = 0; i < phandle->ncharts; i++) { + MEM_SAFE_FREE(phandle->charts[i]); } MEM_SAFE_FREE(phandle->charts); if (phandle->pin_hash) { - BLI_ghash_free(phandle->pin_hash, NULL, NULL); - phandle->pin_hash = NULL; + BLI_ghash_free(phandle->pin_hash, nullptr, nullptr); + phandle->pin_hash = nullptr; } - if (phandle->construction_chart) { - p_chart_delete(phandle->construction_chart); + MEM_SAFE_FREE(phandle->construction_chart); - phash_delete(phandle->hash_verts); - phash_delete(phandle->hash_edges); - phash_delete(phandle->hash_faces); - } + phash_delete(phandle->hash_verts); + phash_delete(phandle->hash_edges); + phash_delete(phandle->hash_faces); BLI_memarena_free(phandle->arena); BLI_memarena_free(phandle->polyfill_arena); - BLI_heap_free(phandle->polyfill_heap, NULL); - MEM_freeN(phandle); + BLI_heap_free(phandle->polyfill_heap, nullptr); + + if (phandle->rng) { + BLI_rng_free(phandle->rng); + phandle->rng = nullptr; + } + + delete phandle; } -typedef struct GeoUVPinIndex { +using GeoUVPinIndex = struct GeoUVPinIndex { struct GeoUVPinIndex *next; float uv[2]; ParamKey reindex; -} GeoUVPinIndex; +}; /* Find a (mostly) unique ParamKey given a BMVert index and UV co-ordinates. * For each unique pinned UVs, return a unique ParamKey, starting with @@ -3782,7 +3764,8 @@ ParamKey GEO_uv_find_pin_index(ParamHandle *handle, const int bmvertindex, const return bmvertindex; /* No verts pinned. */ } - GeoUVPinIndex *pinuvlist = BLI_ghash_lookup(handle->pin_hash, POINTER_FROM_INT(bmvertindex)); + const GeoUVPinIndex *pinuvlist = (const GeoUVPinIndex *)BLI_ghash_lookup( + handle->pin_hash, POINTER_FROM_INT(bmvertindex)); if (!pinuvlist) { return bmvertindex; /* Vert not pinned. */ } @@ -3804,8 +3787,8 @@ ParamKey GEO_uv_find_pin_index(ParamHandle *handle, const int bmvertindex, const static GeoUVPinIndex *new_geo_uv_pinindex(ParamHandle *handle, const float uv[2]) { - GeoUVPinIndex *pinuv = BLI_memarena_alloc(handle->arena, sizeof(*pinuv)); - pinuv->next = NULL; + GeoUVPinIndex *pinuv = (GeoUVPinIndex *)BLI_memarena_alloc(handle->arena, sizeof(*pinuv)); + pinuv->next = nullptr; copy_v2_v2(pinuv->uv, uv); pinuv->reindex = PARAM_KEY_MAX - (handle->unique_pin_count++); return pinuv; @@ -3817,7 +3800,8 @@ void GEO_uv_prepare_pin_index(ParamHandle *handle, const int bmvertindex, const handle->pin_hash = BLI_ghash_int_new("uv pin reindex"); } - GeoUVPinIndex *pinuvlist = BLI_ghash_lookup(handle->pin_hash, POINTER_FROM_INT(bmvertindex)); + GeoUVPinIndex *pinuvlist = (GeoUVPinIndex *)BLI_ghash_lookup(handle->pin_hash, + POINTER_FROM_INT(bmvertindex)); if (!pinuvlist) { BLI_ghash_insert( handle->pin_hash, POINTER_FROM_INT(bmvertindex), new_geo_uv_pinindex(handle, uv)); @@ -3849,8 +3833,10 @@ static void p_add_ngon(ParamHandle *handle, MemArena *arena = handle->polyfill_arena; Heap *heap = handle->polyfill_heap; uint nfilltri = nverts - 2; - uint(*tris)[3] = BLI_memarena_alloc(arena, sizeof(*tris) * (size_t)nfilltri); - float(*projverts)[2] = BLI_memarena_alloc(arena, sizeof(*projverts) * (size_t)nverts); + uint(*tris)[3] = static_cast<uint(*)[3]>( + BLI_memarena_alloc(arena, sizeof(*tris) * (size_t)nfilltri)); + float(*projverts)[2] = static_cast<float(*)[2]>( + BLI_memarena_alloc(arena, sizeof(*projverts) * (size_t)nverts)); /* Calc normal, flipped: to get a positive 2d cross product. */ float normal[3]; @@ -3879,7 +3865,7 @@ static void p_add_ngon(ParamHandle *handle, BLI_polyfill_beautify(projverts, nverts, tris, arena, heap); /* Add triangles. */ - for (int j = 0; j < nfilltri; j++) { + for (uint j = 0; j < nfilltri; j++) { uint *tri = tris[j]; uint v0 = tri[0]; uint v1 = tri[1]; @@ -3906,7 +3892,7 @@ void GEO_uv_parametrizer_face_add(ParamHandle *phandle, const bool *pin, const bool *select) { - param_assert(phash_lookup(phandle->hash_faces, key) == NULL); + param_assert(phash_lookup(phandle->hash_faces, key) == nullptr); param_assert(phandle->state == PHANDLE_STATE_ALLOCATED); param_assert(ELEM(nverts, 3, 4)); @@ -3957,13 +3943,13 @@ void GEO_uv_parametrizer_construct_end(ParamHandle *phandle, phandle->ncharts = p_connect_pairs(phandle, topology_from_uvs); phandle->charts = p_split_charts(phandle, chart, phandle->ncharts); - p_chart_delete(phandle->construction_chart); - phandle->construction_chart = NULL; + MEM_freeN(phandle->construction_chart); + phandle->construction_chart = nullptr; phash_delete(phandle->hash_verts); phash_delete(phandle->hash_edges); phash_delete(phandle->hash_faces); - phandle->hash_verts = phandle->hash_edges = phandle->hash_faces = NULL; + phandle->hash_verts = phandle->hash_edges = phandle->hash_faces = nullptr; for (i = j = 0; i < phandle->ncharts; i++) { PVert *v; @@ -3972,8 +3958,8 @@ void GEO_uv_parametrizer_construct_end(ParamHandle *phandle, p_chart_boundaries(chart, &outer); if (!topology_from_uvs && chart->nboundaries == 0) { - p_chart_delete(chart); - if (count_fail != NULL) { + MEM_freeN(chart); + if (count_fail != nullptr) { *count_fail += 1; } continue; @@ -3983,7 +3969,7 @@ void GEO_uv_parametrizer_construct_end(ParamHandle *phandle, j++; if (fill && (chart->nboundaries > 1)) { - p_chart_fill_boundaries(chart, outer); + p_chart_fill_boundaries(phandle, chart, outer); } for (v = chart->verts; v; v = v->nextlink) { @@ -4025,7 +4011,7 @@ void GEO_uv_parametrizer_lscm_solve(ParamHandle *phandle, int *count_changed, in if (chart->u.lscm.context) { const bool result = p_chart_lscm_solve(phandle, chart); - if (result && !(chart->flag & PCHART_HAS_PINS)) { + if (result && !chart->has_pins) { p_chart_rotate_minimum_area(chart); } else if (result && chart->u.lscm.single_pin) { @@ -4033,17 +4019,17 @@ void GEO_uv_parametrizer_lscm_solve(ParamHandle *phandle, int *count_changed, in p_chart_lscm_transform_single_pin(chart); } - if (!result || !(chart->flag & PCHART_HAS_PINS)) { + if (!result || !chart->has_pins) { p_chart_lscm_end(chart); } if (result) { - if (count_changed != NULL) { + if (count_changed != nullptr) { *count_changed += 1; } } else { - if (count_failed != NULL) { + if (count_failed != nullptr) { *count_failed += 1; } } @@ -4053,11 +4039,9 @@ void GEO_uv_parametrizer_lscm_solve(ParamHandle *phandle, int *count_changed, in void GEO_uv_parametrizer_lscm_end(ParamHandle *phandle) { - int i; + BLI_assert(phandle->state == PHANDLE_STATE_LSCM); - param_assert(phandle->state == PHANDLE_STATE_LSCM); - - for (i = 0; i < phandle->ncharts; i++) { + for (int i = 0; i < phandle->ncharts; i++) { p_chart_lscm_end(phandle->charts[i]); #if 0 p_chart_complexify(phandle->charts[i]); @@ -4119,9 +4103,6 @@ void GEO_uv_parametrizer_stretch_end(ParamHandle *phandle) { param_assert(phandle->state == PHANDLE_STATE_STRETCH); phandle->state = PHANDLE_STATE_CONSTRUCTED; - - BLI_rng_free(phandle->rng); - phandle->rng = NULL; } /* don't pack, just rotate (used for better packing) */ @@ -4133,7 +4114,7 @@ static void GEO_uv_parametrizer_pack_rotate(ParamHandle *phandle, bool ignore_pi for (i = 0; i < phandle->ncharts; i++) { chart = phandle->charts[i]; - if (ignore_pinned && (chart->flag & PCHART_HAS_PINS)) { + if (ignore_pinned && chart->has_pins) { continue; } @@ -4169,12 +4150,12 @@ void GEO_uv_parametrizer_pack(ParamHandle *handle, } /* we may not use all these boxes */ - boxarray = MEM_mallocN(handle->ncharts * sizeof(BoxPack), "BoxPack box"); + boxarray = (BoxPack *)MEM_mallocN(handle->ncharts * sizeof(BoxPack), "BoxPack box"); for (i = 0; i < handle->ncharts; i++) { chart = handle->charts[i]; - if (ignore_pinned && (chart->flag & PCHART_HAS_PINS)) { + if (ignore_pinned && chart->has_pins) { unpacked++; continue; } @@ -4190,7 +4171,7 @@ void GEO_uv_parametrizer_pack(ParamHandle *handle, box->w = chart->u.pack.size[0] + trans[0]; box->h = chart->u.pack.size[1] + trans[1]; - box->index = i; /* warning this index skips PCHART_HAS_PINS boxes */ + box->index = i; /* Warning this index skips chart->has_pins boxes. */ if (margin > 0.0f) { area += (double)sqrtf(box->w * box->h); @@ -4207,7 +4188,7 @@ void GEO_uv_parametrizer_pack(ParamHandle *handle, for (i = 0; i < handle->ncharts; i++) { chart = handle->charts[i]; - if (ignore_pinned && (chart->flag & PCHART_HAS_PINS)) { + if (ignore_pinned && chart->has_pins) { unpacked++; continue; } @@ -4264,7 +4245,7 @@ void GEO_uv_parametrizer_average(ParamHandle *phandle, for (i = 0; i < phandle->ncharts; i++) { chart = phandle->charts[i]; - if (ignore_pinned && (chart->flag & PCHART_HAS_PINS)) { + if (ignore_pinned && chart->has_pins) { continue; } @@ -4367,7 +4348,7 @@ void GEO_uv_parametrizer_average(ParamHandle *phandle, for (i = 0; i < phandle->ncharts; i++) { chart = phandle->charts[i]; - if (ignore_pinned && (chart->flag & PCHART_HAS_PINS)) { + if (ignore_pinned && chart->has_pins) { continue; } |