[Bf-blender-cvs] [e7516174c70] geometry-nodes-curve-support: Cleanup: Use std::unique_ptr for spline vector
Hans Goudey
noreply at git.blender.org
Wed Apr 14 22:33:07 CEST 2021
Commit: e7516174c70e1de5a3d8e870ff8c62dfdfd18d90
Author: Hans Goudey
Date: Wed Apr 14 15:32:59 2021 -0500
Branches: geometry-nodes-curve-support
https://developer.blender.org/rBe7516174c70e1de5a3d8e870ff8c62dfdfd18d90
Cleanup: Use std::unique_ptr for spline vector
===================================================================
M source/blender/blenkernel/BKE_derived_curve.hh
M source/blender/blenkernel/intern/derived_curve.cc
M source/blender/blenkernel/intern/geometry_component_curve.cc
M source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc
M source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc
M source/blender/nodes/geometry/nodes/node_geo_transform.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_derived_curve.hh b/source/blender/blenkernel/BKE_derived_curve.hh
index 57054d8333c..3ca28487609 100644
--- a/source/blender/blenkernel/BKE_derived_curve.hh
+++ b/source/blender/blenkernel/BKE_derived_curve.hh
@@ -137,6 +137,8 @@ class Spline {
virtual float control_point_radius(const int index) const = 0;
};
+using SplinePtr = std::unique_ptr<Spline>;
+
class BezierSpline : public Spline {
public:
blender::Vector<BezierPoint> control_points;
@@ -145,8 +147,6 @@ class BezierSpline : public Spline {
int resolution_u;
public:
- ~BezierSpline() = default;
-
int size() const final;
int resolution() const final;
void set_resolution(const int value) final;
@@ -195,18 +195,11 @@ class NURBSPline : public Spline {
/* Proposed name to be different from DNA type. */
struct DCurve {
- blender::Vector<Spline *> splines;
+ blender::Vector<SplinePtr> splines;
// bool is_2d;
// DCurve *copy();
-
- ~DCurve()
- {
- for (Spline *spline : splines) {
- delete spline;
- }
- }
};
DCurve *dcurve_from_dna_curve(const Curve &curve);
\ No newline at end of file
diff --git a/source/blender/blenkernel/intern/derived_curve.cc b/source/blender/blenkernel/intern/derived_curve.cc
index bfc12b8c9cd..c63f6d2ddf8 100644
--- a/source/blender/blenkernel/intern/derived_curve.cc
+++ b/source/blender/blenkernel/intern/derived_curve.cc
@@ -78,7 +78,7 @@ DCurve *dcurve_from_dna_curve(const Curve &dna_curve)
LISTBASE_FOREACH (const Nurb *, nurb, nurbs) {
switch (nurb->type) {
case CU_BEZIER: {
- BezierSpline *spline = new BezierSpline();
+ std::unique_ptr<BezierSpline> spline = std::make_unique<BezierSpline>();
spline->set_resolution(nurb->resolu);
spline->type = Spline::Type::Bezier;
spline->is_cyclic = nurb->flagu & CU_NURB_CYCLIC;
@@ -95,7 +95,7 @@ DCurve *dcurve_from_dna_curve(const Curve &dna_curve)
spline->control_points.append(std::move(point));
}
- curve->splines.append(spline);
+ curve->splines.append(std::move(spline));
break;
}
case CU_NURBS: {
@@ -114,7 +114,7 @@ DCurve *dcurve_from_dna_curve(const Curve &dna_curve)
/* TODO: Decide whether to store this in the spline or the curve. */
const Spline::NormalCalculationMode normal_mode = normal_mode_from_dna_curve(
dna_curve.twist_mode);
- for (Spline *spline : curve->splines) {
+ for (SplinePtr &spline : curve->splines) {
spline->normal_mode = normal_mode;
}
diff --git a/source/blender/blenkernel/intern/geometry_component_curve.cc b/source/blender/blenkernel/intern/geometry_component_curve.cc
index 52d3f6665ad..9a3ec4fca9e 100644
--- a/source/blender/blenkernel/intern/geometry_component_curve.cc
+++ b/source/blender/blenkernel/intern/geometry_component_curve.cc
@@ -127,7 +127,7 @@ int CurveComponent::attribute_domain_size(const AttributeDomain domain) const
}
if (domain == ATTR_DOMAIN_POINT) {
int total = 0;
- for (const Spline *spline : curve_->splines) {
+ for (const SplinePtr &spline : curve_->splines) {
total += spline->size();
}
return total;
@@ -205,12 +205,12 @@ class BuiltinSplineAttributeProvider final : public BuiltinAttributeProvider {
}
};
-static int get_spline_resolution(Spline *const &spline)
+static int get_spline_resolution(const SplinePtr &spline)
{
return spline->resolution();
}
-static void set_spline_resolution(Spline *&spline, const int &resolution)
+static void set_spline_resolution(SplinePtr &spline, const int &resolution)
{
spline->set_resolution(std::max(resolution, 1));
spline->mark_cache_invalid();
@@ -218,18 +218,18 @@ static void set_spline_resolution(Spline *&spline, const int &resolution)
static ReadAttributePtr make_resolution_read_attribute(const DCurve &curve)
{
- return std::make_unique<DerivedArrayReadAttribute<Spline *, int, get_spline_resolution>>(
+ return std::make_unique<DerivedArrayReadAttribute<SplinePtr, int, get_spline_resolution>>(
ATTR_DOMAIN_CURVE, curve.splines.as_span());
}
static WriteAttributePtr make_resolution_write_attribute(DCurve &curve)
{
return std::make_unique<
- DerivedArrayWriteAttribute<Spline *, int, get_spline_resolution, set_spline_resolution>>(
+ DerivedArrayWriteAttribute<SplinePtr, int, get_spline_resolution, set_spline_resolution>>(
ATTR_DOMAIN_CURVE, curve.splines.as_mutable_span());
}
-static float get_spline_length(Spline *const &spline)
+static float get_spline_length(const SplinePtr &spline)
{
Span<float> lengths = spline->evaluated_lengths();
@@ -238,31 +238,33 @@ static float get_spline_length(Spline *const &spline)
static ReadAttributePtr make_length_attribute(const DCurve &curve)
{
- return std::make_unique<DerivedArrayReadAttribute<Spline *, float, get_spline_length>>(
+ return std::make_unique<DerivedArrayReadAttribute<SplinePtr, float, get_spline_length>>(
ATTR_DOMAIN_CURVE, curve.splines.as_span());
}
-static bool get_cyclic_value(Spline *const &spline)
+static bool get_cyclic_value(const SplinePtr &spline)
{
return spline->is_cyclic;
}
-static void set_cyclic_value(Spline *&spline, const bool &value)
+static void set_cyclic_value(SplinePtr &spline, const bool &value)
{
- spline->is_cyclic = value;
- spline->mark_cache_invalid();
+ if (spline->is_cyclic != value) {
+ spline->is_cyclic = value;
+ spline->mark_cache_invalid();
+ }
}
static ReadAttributePtr make_cyclic_read_attribute(const DCurve &curve)
{
- return std::make_unique<DerivedArrayReadAttribute<Spline *, bool, get_cyclic_value>>(
+ return std::make_unique<DerivedArrayReadAttribute<SplinePtr, bool, get_cyclic_value>>(
ATTR_DOMAIN_CURVE, curve.splines.as_span());
}
static WriteAttributePtr make_cyclic_write_attribute(DCurve &curve)
{
return std::make_unique<
- DerivedArrayWriteAttribute<Spline *, bool, get_cyclic_value, set_cyclic_value>>(
+ DerivedArrayWriteAttribute<SplinePtr, bool, get_cyclic_value, set_cyclic_value>>(
ATTR_DOMAIN_CURVE, curve.splines.as_mutable_span());
}
@@ -303,7 +305,7 @@ class BuiltinPointAttributeProvider final : public BuiltinAttributeProvider {
Array<T> values(curve_component.attribute_domain_size(ATTR_DOMAIN_POINT));
int offset = 0;
- for (const Spline *spline : curve->splines) {
+ for (const SplinePtr &spline : curve->splines) {
const int spline_total = spline->evaluated_points_size();
MutableSpan<T> spline_data = values.as_mutable_span().slice(offset, spline_total);
fn::GMutableSpan generic_spline_data(spline_data);
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc
index 3b97a0c9b0c..a2f53001886 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc
@@ -212,7 +212,7 @@ static Mesh *curve_to_mesh_calculate(const DCurve &curve, const DCurve &profile_
{
int profile_vert_total = 0;
int profile_edge_total = 0;
- for (const Spline *profile_spline : profile_curve.splines) {
+ for (const SplinePtr &profile_spline : profile_curve.splines) {
profile_vert_total += profile_spline->evaluated_points_size();
profile_edge_total += profile_spline->evaluated_edges_size();
}
@@ -220,7 +220,7 @@ static Mesh *curve_to_mesh_calculate(const DCurve &curve, const DCurve &profile_
int vert_total = 0;
int edge_total = 0;
int poly_total = 0;
- for (const Spline *spline : curve.splines) {
+ for (const SplinePtr &spline : curve.splines) {
const int spline_vert_len = spline->evaluated_points_size();
const int spline_edge_len = spline->evaluated_edges_size();
vert_total += spline_vert_len * profile_vert_total;
@@ -248,8 +248,8 @@ static Mesh *curve_to_mesh_calculate(const DCurve &curve, const DCurve &profile_
int edge_offset = 0;
int loop_offset = 0;
int poly_offset = 0;
- for (const Spline *spline : curve.splines) {
- for (const Spline *profile_spline : profile_curve.splines) {
+ for (const SplinePtr &spline : curve.splines) {
+ for (const SplinePtr &profile_spline : profile_curve.splines) {
spline_extrude_to_mesh_data(*spline,
*profile_spline,
verts,
@@ -272,13 +272,13 @@ static Mesh *curve_to_mesh_calculate(const DCurve &curve, const DCurve &profile_
static DCurve get_curve_single_vert()
{
DCurve curve;
- BezierSpline *spline = new BezierSpline();
+ std::unique_ptr<BezierSpline> spline = std::make_unique<BezierSpline>();
BezierPoint control_point;
control_point.position = float3(0);
control_point.handle_position_a = float3(0);
control_point.handle_position_b = float3(0);
spline->control_points.append(control_point);
- curve.splines.append(static_cast<Spline *>(spline));
+ curve.splines.append(std::move(spline));
return curve;
}
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc
index 174557c31cc..2d285c1134b 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc
@@ -87,7 +87,7 @@ static void geo_node_curve_trim_exec(GeoNodeExecParams params)
case GEO_NODE_CURVE_TRIM_FACTOR: {
const float factor_start = params.extract_input<float>("Start");
const float factor_end = params.extract_input<float>("End");
- for (Spline *spline : curve.splines) {
+ for (SplinePtr &spline : curve.splines) {
const float length = spline->evaluated_lengths().last();
const float length_start = factor_start * length;
const float length_end = factor_end * length;
@@ -98,7 +98,7 @@ static void geo_node_curve_trim_exec(GeoNodeExecParams params)
case GEO_NODE_CURVE_TRIM_LENGTH: {
const float length_start = params.extract_input<float>("Start_001");
const float length_end = params.extract_input<float>("End_001");
- for (Spline *spline : curve.splines) {
+ for (SplinePt
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list