Cleanup: Use standard variable names for curves

This commit is contained in:
Hans Goudey 2022-05-13 18:44:09 +02:00
parent cf69652618
commit ee363ee7b3
6 changed files with 56 additions and 56 deletions

View File

@ -373,15 +373,15 @@ static void copy_attributes_between_components(const GeometryComponent &src_comp
});
}
std::unique_ptr<CurveEval> curves_to_curve_eval(const Curves &curves)
std::unique_ptr<CurveEval> curves_to_curve_eval(const Curves &curves_id)
{
CurveComponent src_component;
src_component.replace(&const_cast<Curves &>(curves), GeometryOwnershipType::ReadOnly);
const blender::bke::CurvesGeometry &geometry = blender::bke::CurvesGeometry::wrap(
curves.geometry);
src_component.replace(&const_cast<Curves &>(curves_id), GeometryOwnershipType::ReadOnly);
const blender::bke::CurvesGeometry &curves = blender::bke::CurvesGeometry::wrap(
curves_id.geometry);
VArray<int> resolution = geometry.resolution();
VArray<int8_t> normal_mode = geometry.normal_mode();
VArray<int> resolution = curves.resolution();
VArray<int8_t> normal_mode = curves.normal_mode();
VArray_Span<float> nurbs_weights{
src_component.attribute_get_for_read<float>("nurbs_weight", ATTR_DOMAIN_POINT, 0.0f)};
@ -396,34 +396,34 @@ std::unique_ptr<CurveEval> curves_to_curve_eval(const Curves &curves)
src_component.attribute_get_for_read<int8_t>("handle_type_left", ATTR_DOMAIN_POINT, 0)};
/* Create splines with the correct size and type. */
VArray<int8_t> curve_types = geometry.curve_types();
VArray<int8_t> curve_types = curves.curve_types();
std::unique_ptr<CurveEval> curve_eval = std::make_unique<CurveEval>();
for (const int curve_index : curve_types.index_range()) {
const IndexRange point_range = geometry.points_for_curve(curve_index);
const IndexRange points = curves.points_for_curve(curve_index);
std::unique_ptr<Spline> spline;
/* #CurveEval does not support catmull rom curves, so convert those to poly splines. */
switch (std::max<int8_t>(1, curve_types[curve_index])) {
case CURVE_TYPE_POLY: {
spline = std::make_unique<PolySpline>();
spline->resize(point_range.size());
spline->resize(points.size());
break;
}
case CURVE_TYPE_BEZIER: {
std::unique_ptr<BezierSpline> bezier_spline = std::make_unique<BezierSpline>();
bezier_spline->resize(point_range.size());
bezier_spline->resize(points.size());
bezier_spline->set_resolution(resolution[curve_index]);
bezier_spline->handle_types_left().copy_from(handle_types_left.slice(point_range));
bezier_spline->handle_types_right().copy_from(handle_types_right.slice(point_range));
bezier_spline->handle_types_left().copy_from(handle_types_left.slice(points));
bezier_spline->handle_types_right().copy_from(handle_types_right.slice(points));
spline = std::move(bezier_spline);
break;
}
case CURVE_TYPE_NURBS: {
std::unique_ptr<NURBSpline> nurb_spline = std::make_unique<NURBSpline>();
nurb_spline->resize(point_range.size());
nurb_spline->resize(points.size());
nurb_spline->set_resolution(resolution[curve_index]);
nurb_spline->weights().copy_from(nurbs_weights.slice(point_range));
nurb_spline->weights().copy_from(nurbs_weights.slice(points));
nurb_spline->set_order(nurbs_orders[curve_index]);
nurb_spline->knots_mode = static_cast<KnotsMode>(nurbs_knots_modes[curve_index]);
@ -463,14 +463,14 @@ std::unique_ptr<CurveEval> curves_to_curve_eval(const Curves &curves)
Curves *curve_eval_to_curves(const CurveEval &curve_eval)
{
Curves *curves = blender::bke::curves_new_nomain(curve_eval.total_control_point_num(),
curve_eval.splines().size());
Curves *curves_id = blender::bke::curves_new_nomain(curve_eval.total_control_point_num(),
curve_eval.splines().size());
CurveComponent dst_component;
dst_component.replace(curves, GeometryOwnershipType::Editable);
dst_component.replace(curves_id, GeometryOwnershipType::Editable);
blender::bke::CurvesGeometry &geometry = blender::bke::CurvesGeometry::wrap(curves->geometry);
geometry.offsets_for_write().copy_from(curve_eval.control_point_offsets());
MutableSpan<int8_t> curve_types = geometry.curve_types_for_write();
blender::bke::CurvesGeometry &curves = blender::bke::CurvesGeometry::wrap(curves_id->geometry);
curves.offsets_for_write().copy_from(curve_eval.control_point_offsets());
MutableSpan<int8_t> curve_types = curves.curve_types_for_write();
OutputAttribute_Typed<int8_t> normal_mode =
dst_component.attribute_try_get_for_output_only<int8_t>("normal_mode", ATTR_DOMAIN_CURVE);
@ -498,22 +498,22 @@ Curves *curve_eval_to_curves(const CurveEval &curve_eval)
const Spline &spline = *curve_eval.splines()[curve_index];
curve_types[curve_index] = curve_eval.splines()[curve_index]->type();
normal_mode.as_span()[curve_index] = curve_eval.splines()[curve_index]->normal_mode;
const IndexRange point_range = geometry.points_for_curve(curve_index);
const IndexRange points = curves.points_for_curve(curve_index);
switch (spline.type()) {
case CURVE_TYPE_POLY:
break;
case CURVE_TYPE_BEZIER: {
const BezierSpline &src = static_cast<const BezierSpline &>(spline);
handle_type_right.as_span().slice(point_range).copy_from(src.handle_types_right());
handle_type_left.as_span().slice(point_range).copy_from(src.handle_types_left());
handle_type_right.as_span().slice(points).copy_from(src.handle_types_right());
handle_type_left.as_span().slice(points).copy_from(src.handle_types_left());
break;
}
case CURVE_TYPE_NURBS: {
const NURBSpline &src = static_cast<const NURBSpline &>(spline);
nurbs_knots_mode.as_span()[curve_index] = static_cast<int8_t>(src.knots_mode);
nurbs_order.as_span()[curve_index] = src.order();
nurbs_weight.as_span().slice(point_range).copy_from(src.weights());
nurbs_weight.as_span().slice(points).copy_from(src.weights());
break;
}
case CURVE_TYPE_CATMULL_ROM: {
@ -523,7 +523,7 @@ Curves *curve_eval_to_curves(const CurveEval &curve_eval)
}
}
geometry.update_curve_types();
curves.update_curve_types();
normal_mode.save();
nurbs_weight.save();
@ -537,7 +537,7 @@ Curves *curve_eval_to_curves(const CurveEval &curve_eval)
copy_attributes_between_components(src_component, dst_component, {});
return curves;
return curves_id;
}
void CurveEval::assert_valid_point_attributes() const

View File

@ -247,7 +247,7 @@ void *BKE_curves_add(Main *bmain, const char *name)
BoundBox *BKE_curves_boundbox_get(Object *ob)
{
BLI_assert(ob->type == OB_CURVES);
Curves *curves = static_cast<Curves *>(ob->data);
const Curves *curves_id = static_cast<const Curves *>(ob->data);
if (ob->runtime.bb != nullptr && (ob->runtime.bb->flag & BOUNDBOX_DIRTY) == 0) {
return ob->runtime.bb;
@ -256,11 +256,12 @@ BoundBox *BKE_curves_boundbox_get(Object *ob)
if (ob->runtime.bb == nullptr) {
ob->runtime.bb = MEM_cnew<BoundBox>(__func__);
blender::bke::CurvesGeometry &geometry = blender::bke::CurvesGeometry::wrap(curves->geometry);
const blender::bke::CurvesGeometry &curves = blender::bke::CurvesGeometry::wrap(
curves_id->geometry);
float3 min(FLT_MAX);
float3 max(-FLT_MAX);
if (!geometry.bounds_min_max(min, max)) {
if (!curves.bounds_min_max(min, max)) {
min = float3(-1);
max = float3(1);
}
@ -364,19 +365,19 @@ namespace blender::bke {
Curves *curves_new_nomain(const int points_num, const int curves_num)
{
Curves *curves = static_cast<Curves *>(BKE_id_new_nomain(ID_CV, nullptr));
CurvesGeometry &geometry = CurvesGeometry::wrap(curves->geometry);
geometry.resize(points_num, curves_num);
return curves;
Curves *curves_id = static_cast<Curves *>(BKE_id_new_nomain(ID_CV, nullptr));
CurvesGeometry &curves = CurvesGeometry::wrap(curves_id->geometry);
curves.resize(points_num, curves_num);
return curves_id;
}
Curves *curves_new_nomain_single(const int points_num, const CurveType type)
{
Curves *curves = curves_new_nomain(points_num, 1);
CurvesGeometry &geometry = CurvesGeometry::wrap(curves->geometry);
geometry.offsets_for_write().last() = points_num;
geometry.fill_curve_types(type);
return curves;
Curves *curves_id = curves_new_nomain(points_num, 1);
CurvesGeometry &curves = CurvesGeometry::wrap(curves_id->geometry);
curves.offsets_for_write().last() = points_num;
curves.fill_curve_types(type);
return curves_id;
}
Curves *curves_new_nomain(CurvesGeometry curves)

View File

@ -313,13 +313,13 @@ int CurveComponent::attribute_domain_num(const AttributeDomain domain) const
if (curves_ == nullptr) {
return 0;
}
const blender::bke::CurvesGeometry &geometry = blender::bke::CurvesGeometry::wrap(
const blender::bke::CurvesGeometry &curves = blender::bke::CurvesGeometry::wrap(
curves_->geometry);
if (domain == ATTR_DOMAIN_POINT) {
return geometry.points_num();
return curves.points_num();
}
if (domain == ATTR_DOMAIN_CURVE) {
return geometry.curves_num();
return curves.curves_num();
}
return 0;
}

View File

@ -163,10 +163,10 @@ struct DeleteOperationExecutor {
threading::parallel_for(curves_->curves_range(), 512, [&](IndexRange curve_range) {
for (const int curve_i : curve_range) {
const IndexRange point_range = curves_->points_for_curve(curve_i);
for (const int segment_i : IndexRange(point_range.size() - 1)) {
const float3 pos1_cu = brush_transform_inv * positions_cu[point_range[segment_i]];
const float3 pos2_cu = brush_transform_inv * positions_cu[point_range[segment_i + 1]];
const IndexRange points = curves_->points_for_curve(curve_i);
for (const int segment_i : IndexRange(points.size() - 1)) {
const float3 pos1_cu = brush_transform_inv * positions_cu[points[segment_i]];
const float3 pos2_cu = brush_transform_inv * positions_cu[points[segment_i + 1]];
float2 pos1_re, pos2_re;
ED_view3d_project_float_v2_m4(region_, pos1_cu, pos1_re, projection.values);

View File

@ -97,9 +97,9 @@ PointCloud *point_merge_by_distance(const PointCloudComponent &src_points,
const int merge_index = merge_indices[i];
const int dst_index = src_to_dst_indices[merge_index];
const IndexRange point_range(map_offsets[dst_index],
map_offsets[dst_index + 1] - map_offsets[dst_index]);
MutableSpan<int> point_merge_indices = merge_map.as_mutable_span().slice(point_range);
const IndexRange points(map_offsets[dst_index],
map_offsets[dst_index + 1] - map_offsets[dst_index]);
MutableSpan<int> point_merge_indices = merge_map.as_mutable_span().slice(points);
point_merge_indices[point_merge_counts[dst_index]] = i;
point_merge_counts[dst_index]++;
}
@ -116,9 +116,8 @@ PointCloud *point_merge_by_distance(const PointCloudComponent &src_points,
threading::parallel_for(IndexRange(dst_size), 1024, [&](IndexRange range) {
for (const int i_dst : range) {
const IndexRange point_range(map_offsets[i_dst],
map_offsets[i_dst + 1] - map_offsets[i_dst]);
dst_ids[i_dst] = src_ids[point_range.first()];
const IndexRange points(map_offsets[i_dst], map_offsets[i_dst + 1] - map_offsets[i_dst]);
dst_ids[i_dst] = src_ids[points.first()];
}
});
@ -147,9 +146,9 @@ PointCloud *point_merge_by_distance(const PointCloudComponent &src_points,
* in the mixer the size of the result point cloud and to improve memory locality. */
attribute_math::DefaultMixer<T> mixer{dst.slice(i_dst, 1)};
const IndexRange point_range(map_offsets[i_dst],
map_offsets[i_dst + 1] - map_offsets[i_dst]);
Span<int> src_merge_indices = merge_map.as_span().slice(point_range);
const IndexRange points(map_offsets[i_dst],
map_offsets[i_dst + 1] - map_offsets[i_dst]);
Span<int> src_merge_indices = merge_map.as_span().slice(points);
for (const int i_src : src_merge_indices) {
mixer.mix_in(0, src[i_src]);
}

View File

@ -812,8 +812,8 @@ static void duplicate_points_curve(GeometrySet &geometry_set,
Array<int> point_to_curve_map(src_curves.points_num());
threading::parallel_for(src_curves.curves_range(), 1024, [&](const IndexRange range) {
for (const int i_curve : range) {
const IndexRange point_range = src_curves.points_for_curve(i_curve);
point_to_curve_map.as_mutable_span().slice(point_range).fill(i_curve);
const IndexRange points = src_curves.points_for_curve(i_curve);
point_to_curve_map.as_mutable_span().slice(points).fill(i_curve);
}
});