Blender  V3.3
node_geo_curve_endpoint_selection.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include "BKE_curves.hh"
4 
5 #include "UI_interface.h"
6 #include "UI_resources.h"
7 
8 #include "node_geometry_util.hh"
9 
11 
13 {
14  b.add_input<decl::Int>(N_("Start Size"))
15  .min(0)
16  .default_value(1)
17  .supports_field()
18  .description(N_("The amount of points to select from the start of each spline"));
19  b.add_input<decl::Int>(N_("End Size"))
20  .min(0)
21  .default_value(1)
22  .supports_field()
23  .description(N_("The amount of points to select from the end of each spline"));
24  b.add_output<decl::Bool>(N_("Selection"))
25  .field_source()
26  .description(
27  N_("The selection from the start and end of the splines based on the input sizes"));
28 }
29 
31  Field<int> start_size_;
32  Field<int> end_size_;
33 
34  public:
36  : GeometryFieldInput(CPPType::get<bool>(), "Endpoint Selection node"),
37  start_size_(start_size),
38  end_size_(end_size)
39  {
41  }
42 
44  const eAttrDomain domain,
45  IndexMask UNUSED(mask)) const final
46  {
47  if (component.type() != GEO_COMPONENT_TYPE_CURVE || domain != ATTR_DOMAIN_POINT) {
48  return nullptr;
49  }
50 
51  const CurveComponent &curve_component = static_cast<const CurveComponent &>(component);
52  if (!curve_component.has_curves()) {
53  return nullptr;
54  }
55 
56  const Curves &curves_id = *curve_component.get_for_read();
58  if (curves.points_num() == 0) {
59  return nullptr;
60  }
61 
62  GeometryComponentFieldContext size_context{curve_component, ATTR_DOMAIN_CURVE};
63  fn::FieldEvaluator evaluator{size_context, curves.curves_num()};
64  evaluator.add(start_size_);
65  evaluator.add(end_size_);
66  evaluator.evaluate();
67  const VArray<int> start_size = evaluator.get_evaluated<int>(0);
68  const VArray<int> end_size = evaluator.get_evaluated<int>(1);
69 
70  Array<bool> selection(curves.points_num(), false);
71  MutableSpan<bool> selection_span = selection.as_mutable_span();
72  devirtualize_varray2(start_size, end_size, [&](const auto &start_size, const auto &end_size) {
73  threading::parallel_for(curves.curves_range(), 1024, [&](IndexRange curves_range) {
74  for (const int i : curves_range) {
75  const IndexRange range = curves.points_for_curve(i);
76  const int start = std::max(start_size[i], 0);
77  const int end = std::max(end_size[i], 0);
78 
79  selection_span.slice(range.take_front(start)).fill(true);
80  selection_span.slice(range.take_back(end)).fill(true);
81  }
82  });
83  });
84 
85  return VArray<bool>::ForContainer(std::move(selection));
86  };
87 
88  uint64_t hash() const override
89  {
90  return get_default_hash_2(start_size_, end_size_);
91  }
92 
93  bool is_equal_to(const fn::FieldNode &other) const override
94  {
95  if (const EndpointFieldInput *other_endpoint = dynamic_cast<const EndpointFieldInput *>(
96  &other)) {
97  return start_size_ == other_endpoint->start_size_ && end_size_ == other_endpoint->end_size_;
98  }
99  return false;
100  }
101 };
102 
104 {
105  Field<int> start_size = params.extract_input<Field<int>>("Start Size");
106  Field<int> end_size = params.extract_input<Field<int>>("End Size");
107  Field<bool> selection_field{std::make_shared<EndpointFieldInput>(start_size, end_size)};
108  params.set_output("Selection", std::move(selection_field));
109 }
110 } // namespace blender::nodes::node_geo_curve_endpoint_selection_cc
111 
113 {
115 
116  static bNodeType ntype;
117 
119  &ntype, GEO_NODE_CURVE_ENDPOINT_SELECTION, "Endpoint Selection", NODE_CLASS_INPUT);
122 
123  nodeRegisterType(&ntype);
124 }
eAttrDomain
Definition: BKE_attribute.h:25
@ ATTR_DOMAIN_CURVE
Definition: BKE_attribute.h:31
@ ATTR_DOMAIN_POINT
Definition: BKE_attribute.h:27
Low-level operations for curves.
@ GEO_COMPONENT_TYPE_CURVE
#define GEO_NODE_CURVE_ENDPOINT_SELECTION
Definition: BKE_node.h:1469
#define NODE_CLASS_INPUT
Definition: BKE_node.h:345
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define final(a, b, c)
Definition: BLI_hash.h:21
#define UNUSED(x)
static uint8 component(Color32 c, uint i)
Definition: ColorBlock.cpp:108
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to curves
const Curves * get_for_read() const
static VArray ForContainer(ContainerT container)
static CurvesGeometry & wrap(::CurvesGeometry &dna_struct)
Definition: BKE_curves.hh:138
GVArray get_varray_for_context(const GeometryComponent &component, const eAttrDomain domain, IndexMask UNUSED(mask)) const final
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
Definition: math_float4.h:513
void parallel_for(IndexRange range, int64_t grain_size, const Function &function)
Definition: BLI_task.hh:51
void devirtualize_varray2(const VArray< T1 > &varray1, const VArray< T2 > &varray2, const Func &func, bool enable=true)
uint64_t get_default_hash_2(const T1 &v1, const T2 &v2)
Definition: BLI_hash.hh:223
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void register_node_type_geo_curve_endpoint_selection()
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
#define min(a, b)
Definition: sort.c:35
unsigned __int64 uint64_t
Definition: stdint.h:90
CurvesGeometry geometry
Defines a node type.
Definition: BKE_node.h:226
NodeGeometryExecFunction geometry_node_execute
Definition: BKE_node.h:316
NodeDeclareFunction declare
Definition: BKE_node.h:324
#define N_(msgid)