Changeset View
Changeset View
Standalone View
Standalone View
source/blender/functions/FN_field.hh
| Show First 20 Lines • Show All 307 Lines • ▼ Show 20 Lines | private: | ||||
| const FieldContext &context_; | const FieldContext &context_; | ||||
| const IndexMask mask_; | const IndexMask mask_; | ||||
| Vector<GField> fields_to_evaluate_; | Vector<GField> fields_to_evaluate_; | ||||
| Vector<GVMutableArray> dst_varrays_; | Vector<GVMutableArray> dst_varrays_; | ||||
| Vector<GVArray> evaluated_varrays_; | Vector<GVArray> evaluated_varrays_; | ||||
| Vector<OutputPointerInfo> output_pointer_infos_; | Vector<OutputPointerInfo> output_pointer_infos_; | ||||
| bool is_evaluated_ = false; | bool is_evaluated_ = false; | ||||
| Field<bool> selection_field_; | |||||
| IndexMask selection_mask_; | |||||
| public: | public: | ||||
| /** Takes #mask by pointer because the mask has to live longer than the evaluator. */ | /** Takes #mask by pointer because the mask has to live longer than the evaluator. */ | ||||
| FieldEvaluator(const FieldContext &context, const IndexMask *mask) | FieldEvaluator(const FieldContext &context, const IndexMask *mask) | ||||
| : context_(context), mask_(*mask) | : context_(context), mask_(*mask) | ||||
| { | { | ||||
| } | } | ||||
| /** Construct a field evaluator for all indices less than #size. */ | /** Construct a field evaluator for all indices less than #size. */ | ||||
| FieldEvaluator(const FieldContext &context, const int64_t size) : context_(context), mask_(size) | FieldEvaluator(const FieldContext &context, const int64_t size) : context_(context), mask_(size) | ||||
| { | { | ||||
| } | } | ||||
| ~FieldEvaluator() | ~FieldEvaluator() | ||||
| { | { | ||||
| /* While this assert isn't strictly necessary, and could be replaced with a warning, | /* While this assert isn't strictly necessary, and could be replaced with a warning, | ||||
| * it will catch cases where someone forgets to call #evaluate(). */ | * it will catch cases where someone forgets to call #evaluate(). */ | ||||
| BLI_assert(is_evaluated_); | BLI_assert(is_evaluated_); | ||||
| } | } | ||||
| /** | /** | ||||
| * The selection field is evaluated first to determine which indices of the other fields should | |||||
| * be evaluated. Calling this method multiple times will just replace the previously set | |||||
| * selection field. | |||||
| * If no selection field is set, it is assumed that all indices passed to the constructor are | |||||
| * selected. | |||||
HooglyBoogly: Might be helpful to say something like "Only the elements selected by both this selection *and*… | |||||
| */ | |||||
| void set_selection(Field<bool> selection) | |||||
| { | |||||
| selection_field_ = std::move(selection); | |||||
| } | |||||
| /** | |||||
| * \param field: Field to add to the evaluator. | * \param field: Field to add to the evaluator. | ||||
| * \param dst: Mutable virtual array that the evaluated result for this field is be written into. | * \param dst: Mutable virtual array that the evaluated result for this field is be written into. | ||||
| */ | */ | ||||
| int add_with_destination(GField field, GVMutableArray dst); | int add_with_destination(GField field, GVMutableArray dst); | ||||
| /** Same as #add_with_destination but typed. */ | /** Same as #add_with_destination but typed. */ | ||||
| template<typename T> int add_with_destination(Field<T> field, VMutableArray<T> dst) | template<typename T> int add_with_destination(Field<T> field, VMutableArray<T> dst) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | const GVArray &get_evaluated(const int field_index) const | ||||
| return evaluated_varrays_[field_index]; | return evaluated_varrays_[field_index]; | ||||
| } | } | ||||
| template<typename T> VArray<T> get_evaluated(const int field_index) | template<typename T> VArray<T> get_evaluated(const int field_index) | ||||
| { | { | ||||
| return this->get_evaluated(field_index).typed<T>(); | return this->get_evaluated(field_index).typed<T>(); | ||||
| } | } | ||||
| IndexMask get_evaluated_selection_as_mask(); | |||||
| /** | /** | ||||
| * Retrieve the output of an evaluated boolean field and convert it to a mask, which can be used | * Retrieve the output of an evaluated boolean field and convert it to a mask, which can be used | ||||
| * to avoid calculations for unnecessary elements later on. The evaluator will own the indices in | * to avoid calculations for unnecessary elements later on. The evaluator will own the indices in | ||||
| * some cases, so it must live at least as long as the returned mask. | * some cases, so it must live at least as long as the returned mask. | ||||
| */ | */ | ||||
| IndexMask get_evaluated_as_mask(const int field_index); | IndexMask get_evaluated_as_mask(const int field_index); | ||||
| }; | }; | ||||
| ▲ Show 20 Lines • Show All 236 Lines • Show Last 20 Lines | |||||
Might be helpful to say something like "Only the elements selected by both this selection *and* the selection provided in the constructor are calculated."