Blender  V3.3
Public Member Functions | Static Public Member Functions | List of all members
blender::IndexMask Class Reference

#include <BLI_index_mask.hh>

Public Member Functions

 IndexMask ()=default
 
 IndexMask (Span< int64_t > indices)
 
 IndexMask (IndexRange range)
 
 IndexMask (const std::initializer_list< int64_t > &indices)
 
 IndexMask (int64_t n)
 
 operator Span< int64_t > () const
 
const int64_tbegin () const
 
const int64_tend () const
 
int64_t operator[] (int64_t n) const
 
int64_t min_array_size () const
 
Span< int64_tindices () const
 
bool is_range () const
 
IndexRange as_range () const
 
template<typename CallbackT >
void foreach_index (const CallbackT &callback) const
 
template<typename Fn >
void to_best_mask_type (const Fn &fn) const
 
IndexRange index_range () const
 
int64_t last () const
 
int64_t size () const
 
bool is_empty () const
 
bool contained_in (const IndexRange range) const
 
IndexMask slice (int64_t start, int64_t size) const
 
IndexMask slice (IndexRange slice) const
 
IndexMask slice_and_offset (IndexRange slice, Vector< int64_t > &r_new_indices) const
 
IndexMask invert (const IndexRange full_range, Vector< int64_t > &r_new_indices) const
 
Vector< IndexRangeextract_ranges () const
 
Vector< IndexRangeextract_ranges_invert (const IndexRange full_range, Vector< int64_t > *r_skip_amounts=nullptr) const
 

Static Public Member Functions

static bool indices_are_valid_index_mask (Span< int64_t > indices)
 

Detailed Description

Definition at line 32 of file BLI_index_mask.hh.

Constructor & Destructor Documentation

◆ IndexMask() [1/5]

blender::IndexMask::IndexMask ( )
default

Creates an IndexMask that contains no indices.

Referenced by slice(), and slice_and_offset().

◆ IndexMask() [2/5]

blender::IndexMask::IndexMask ( Span< int64_t indices)
inline

Create an IndexMask using the given integer array. This constructor asserts that the given integers are in ascending order and that there are no duplicates.

Definition at line 46 of file BLI_index_mask.hh.

References BLI_assert, indices(), and indices_are_valid_index_mask().

◆ IndexMask() [3/5]

blender::IndexMask::IndexMask ( IndexRange  range)
inline

Use this method when you know that no indices are skipped. It is more efficient than preparing an integer array all the time.

Definition at line 55 of file BLI_index_mask.hh.

◆ IndexMask() [4/5]

blender::IndexMask::IndexMask ( const std::initializer_list< int64_t > &  indices)
inline

Construct an IndexMask from a sorted list of indices. Note, the created IndexMask is only valid as long as the initializer_list is valid.

Don't do this: IndexMask mask = {3, 4, 5};

Do this: do_something_with_an_index_mask({3, 4, 5});

Definition at line 69 of file BLI_index_mask.hh.

◆ IndexMask() [5/5]

blender::IndexMask::IndexMask ( int64_t  n)
inlineexplicit

Creates an IndexMask that references the indices [0, n-1].

Definition at line 76 of file BLI_index_mask.hh.

Member Function Documentation

◆ as_range()

IndexRange blender::IndexMask::as_range ( ) const
inline

Returns the IndexRange referenced by this IndexMask. This method should only be called after the caller made sure that this IndexMask is actually a range.

Definition at line 151 of file BLI_index_mask.hh.

References BLI_assert, blender::Span< T >::first(), is_range(), and blender::Span< T >::size().

Referenced by blender::fn::materialize_detail::execute_materialized(), blender::nodes::node_geo_extrude_mesh_cc::save_selection_as_attribute(), and to_best_mask_type().

◆ begin()

const int64_t* blender::IndexMask::begin ( ) const
inline

Definition at line 101 of file BLI_index_mask.hh.

References blender::Span< T >::begin().

◆ contained_in()

bool blender::IndexMask::contained_in ( const IndexRange  range) const
inline

◆ end()

const int64_t* blender::IndexMask::end ( ) const
inline

Definition at line 106 of file BLI_index_mask.hh.

References blender::Span< T >::end().

◆ extract_ranges()

Vector< IndexRange > blender::IndexMask::extract_ranges ( ) const

Get all contiguous index ranges within the mask.

Definition at line 59 of file index_mask.cc.

References blender::Vector< T, InlineBufferCapacity, Allocator >::append(), is_range(), blender::Span< T >::size(), and slice().

Referenced by extract_ranges_invert(), and blender::tests::TEST().

◆ extract_ranges_invert()

Vector< IndexRange > blender::IndexMask::extract_ranges_invert ( const IndexRange  full_range,
Vector< int64_t > *  r_skip_amounts = nullptr 
) const

Similar to extract ranges, but works on the inverted mask. So the returned ranges are in-between the indices in the mask.

Using this method is generally more efficient than first inverting the index mask and then extracting the ranges.

If #r_skip_amounts is passed in, it will contain the number of indices that have been skipped before each range in the return value starts.

Definition at line 100 of file index_mask.cc.

References blender::Vector< T, InlineBufferCapacity, Allocator >::append(), BLI_assert, contained_in(), extract_ranges(), blender::Vector< T, InlineBufferCapacity, Allocator >::index_range(), blender::IndexRange::one_after_last(), blender::IndexRange::size(), and blender::IndexRange::start().

Referenced by blender::bke::copy_with_removed_curves(), blender::bke::copy_with_removed_points(), blender::ed::sculpt_paint::DeleteOperationExecutor::execute(), blender::ed::sculpt_paint::DensitySubtractOperationExecutor::execute(), blender::geometry::fillet_curves(), invert(), blender::geometry::resample_to_evaluated(), blender::geometry::resample_to_uniform(), blender::geometry::subdivide_curves(), and blender::tests::TEST().

◆ foreach_index()

template<typename CallbackT >
void blender::IndexMask::foreach_index ( const CallbackT &  callback) const
inline

Calls the given callback for every referenced index. The callback has to take one unsigned integer as parameter.

This method implements different code paths for the cases when the IndexMask represents a range or not.

Definition at line 164 of file BLI_index_mask.hh.

References callback, mask(), and to_best_mask_type().

◆ index_range()

IndexRange blender::IndexMask::index_range ( ) const
inline

Returns an IndexRange that can be used to index this IndexMask.

The range is [0, number of indices - 1].

This is not to be confused with the as_range method.

Definition at line 200 of file BLI_index_mask.hh.

References blender::Span< T >::index_range().

Referenced by blender::nodes::node_geo_duplicate_elements_cc::accumulate_counts_to_offsets(), blender::nodes::node_geo_instance_on_points_cc::add_instances_from_component(), blender::geometry::calculate_result_offsets(), blender::ed::sculpt_paint::CombOperationExecutor::comb_projected(), blender::geometry::convert_curves_to_bezier(), blender::geometry::convert_curves_to_nurbs(), blender::nodes::node_geo_duplicate_elements_cc::copy_curve_attributes_without_id(), blender::bke::curves::copy_point_data(), blender::nodes::node_geo_duplicate_elements_cc::copy_stable_id_curves(), blender::nodes::node_geo_duplicate_elements_cc::copy_stable_id_faces(), blender::ed::sculpt_paint::DeleteOperationExecutor::delete_projected(), blender::nodes::node_geo_duplicate_elements_cc::duplicate_faces(), blender::geometry::duplicate_fillet_point_data(), blender::nodes::node_geo_duplicate_elements_cc::duplicate_instances(), blender::bke::CurvesGeometry::evaluated_tangents(), blender::nodes::node_geo_extrude_mesh_cc::extrude_individual_mesh_faces(), blender::nodes::node_geo_extrude_mesh_cc::extrude_mesh_edges(), blender::nodes::node_geo_extrude_mesh_cc::extrude_mesh_vertices(), blender::bke::curves::fill_points(), blender::geometry::fillet_curves(), blender::ed::sculpt_paint::PuffOperationExecutor::find_curve_weights_projected(), blender::index_mask_ops::find_indices_based_on_predicate(), blender::index_mask_ops::find_indices_from_virtual_array(), blender::ed::sculpt_paint::SmoothOperationExecutor::find_projected_smooth_factors(), blender::nodes::node_geo_flip_faces_cc::mesh_flip_faces(), blender::ed::sculpt_paint::PinchOperationExecutor::pinch_projected(), blender::geometry::point_merge_by_distance(), blender::geometry::resample_to_evaluated(), blender::geometry::resample_to_uniform(), blender::bke::reverse_curve_point_data(), blender::bke::reverse_swap_curve_point_data(), blender::nodes::node_geo_rotate_instances_cc::rotate_instances(), blender::nodes::node_geo_scale_instances_cc::scale_instances(), blender::nodes::node_geo_set_position_cc::set_computed_position_and_offset(), blender::nodes::node_geo_set_curve_handles_cc::set_position_in_component(), blender::geometry::subdivide_attribute_catmull_rom(), blender::geometry::subdivide_attribute_linear(), blender::geometry::subdivide_curves(), and blender::nodes::node_geo_translate_instances_cc::translate_instances().

◆ indices()

Span<int64_t> blender::IndexMask::indices ( ) const
inline

◆ indices_are_valid_index_mask()

static bool blender::IndexMask::indices_are_valid_index_mask ( Span< int64_t indices)
inlinestatic

Checks that the indices are non-negative and in ascending order.

Definition at line 81 of file BLI_index_mask.hh.

References blender::Span< T >::first(), indices(), blender::Span< T >::is_empty(), and blender::Span< T >::size().

Referenced by blender::fn::InstructionScheduler::add_owned_indices(), and IndexMask().

◆ invert()

IndexMask blender::IndexMask::invert ( const IndexRange  full_range,
Vector< int64_t > &  r_new_indices 
) const

Get a new mask that contains all the indices that are not in the current mask. If necessary, the indices referenced by the new mask are inserted in #r_new_indices.

Definition at line 39 of file index_mask.cc.

References blender::Vector< T, InlineBufferCapacity, Allocator >::append(), blender::Vector< T, InlineBufferCapacity, Allocator >::as_span(), BLI_assert, blender::Vector< T, InlineBufferCapacity, Allocator >::clear(), contained_in(), extract_ranges_invert(), blender::Span< T >::is_empty(), blender::IndexRange::size(), and blender::Span< T >::size().

Referenced by blender::tests::TEST().

◆ is_empty()

bool blender::IndexMask::is_empty ( ) const
inline

Definition at line 221 of file BLI_index_mask.hh.

References blender::Span< T >::is_empty().

Referenced by blender::nodes::node_geo_instance_on_points_cc::add_instances_from_component(), blender::ed::spreadsheet::GeometryDataSource::apply_selection_filter(), blender::nodes::node_geo_uv_unwrap_cc::construct_uv_gvarray(), blender::nodes::node_geo_uv_pack_islands_cc::construct_uv_gvarray(), blender::nodes::node_geo_instances_to_points_cc::convert_instances_to_points(), blender::nodes::node_geo_delete_geometry_cc::delete_curves_selection(), blender::nodes::node_geo_delete_geometry_cc::delete_selected_instances(), blender::bke::CurvesGeometry::evaluated_tangents(), blender::nodes::node_geo_extrude_mesh_cc::extrude_mesh_edges(), blender::nodes::node_geo_extrude_mesh_cc::extrude_mesh_face_regions(), blender::nodes::node_geo_input_shortest_edge_paths_cc::ShortestEdgePathsNextVertFieldInput::get_varray_for_context(), blender::nodes::node_geo_input_shortest_edge_paths_cc::ShortestEdgePathsCostFieldInput::get_varray_for_context(), blender::nodes::node_geo_merge_by_distance_cc::mesh_merge_by_distance_all(), blender::nodes::node_geo_curve_reverse_cc::node_geo_exec(), blender::nodes::node_geo_curve_spline_type_cc::node_geo_exec(), blender::nodes::node_geo_merge_by_distance_cc::pointcloud_merge_by_distance(), blender::bke::CurvesGeometry::remove_curves(), blender::bke::CurvesGeometry::remove_points(), blender::nodes::node_geo_delete_geometry_cc::separate_point_cloud_selection(), and blender::tests::TEST().

◆ is_range()

bool blender::IndexMask::is_range ( ) const
inline

◆ last()

int64_t blender::IndexMask::last ( ) const
inline

Returns the largest index that is referenced by this IndexMask.

Definition at line 208 of file BLI_index_mask.hh.

References blender::Span< T >::last().

◆ min_array_size()

int64_t blender::IndexMask::min_array_size ( ) const
inline

◆ operator Span< int64_t >()

blender::IndexMask::operator Span< int64_t > ( ) const
inline

Definition at line 96 of file BLI_index_mask.hh.

◆ operator[]()

int64_t blender::IndexMask::operator[] ( int64_t  n) const
inline

Returns the n-th index referenced by this IndexMask. The index_range method returns an IndexRange containing all indices that can be used as parameter here.

Definition at line 115 of file BLI_index_mask.hh.

◆ size()

int64_t blender::IndexMask::size ( ) const
inline

Returns the number of indices referenced by this IndexMask.

Definition at line 216 of file BLI_index_mask.hh.

References blender::Span< T >::size().

Referenced by blender::nodes::node_geo_duplicate_elements_cc::accumulate_counts_to_offsets(), blender::fn::VariableState::add_as_output(), blender::fn::VariableStates::add_initial_variable_states(), blender::nodes::node_geo_set_material_cc::assign_material_to_faces(), blender::nodes::node_geo_instances_to_points_cc::convert_instances_to_points(), blender::nodes::node_geo_duplicate_elements_cc::copy_stable_id_edges(), blender::bke::copy_with_removed_points(), blender::nodes::node_geo_duplicate_elements_cc::create_duplicate_index_attribute(), blender::nodes::node_geo_delete_geometry_cc::delete_curves_selection(), blender::fn::VariableState::destruct(), blender::nodes::node_geo_duplicate_elements_cc::duplicate_faces(), blender::fn::evaluate_as_one(), blender::ed::sculpt_paint::DensitySubtractOperationExecutor::execute(), blender::ed::sculpt_paint::PuffOperationExecutor::execute(), blender::fn::materialize_detail::execute_materialized(), blender::fn::materialize_detail::execute_materialized_impl(), blender::nodes::node_geo_extrude_mesh_cc::extrude_individual_mesh_faces(), blender::nodes::node_geo_extrude_mesh_cc::extrude_mesh_edges(), blender::nodes::node_geo_extrude_mesh_cc::extrude_mesh_vertices(), blender::bke::CurvesGeometry::fill_curve_types(), blender::index_mask_ops::detail::find_indices_based_on_predicate__merge(), blender::nodes::node_geo_mesh_to_points_cc::geometry_set_mesh_to_points(), blender::nodes::node_geo_points_to_vertices_cc::geometry_set_points_to_vertices(), blender::length_parameterize::interpolate_to_masked(), blender::fn::VariableState::is_fully_initialized(), blender::geometry::mesh_merge_by_distance_all(), blender::nodes::node_geo_mesh_to_curve_cc::node_geo_exec(), blender::geometry::point_merge_by_distance(), blender::nodes::node_geo_scale_elements_cc::prepare_edge_islands(), blender::nodes::node_geo_scale_elements_cc::prepare_face_islands(), blender::bke::CurvesGeometry::remove_curves(), InstancesComponent::remove_instances(), blender::bke::CurvesGeometry::remove_points(), blender::nodes::node_geo_delete_geometry_cc::separate_point_cloud_selection(), slice(), slice_and_offset(), spreadsheet_main_region_draw(), blender::ed::spreadsheet::SpreadsheetLayoutDrawer::SpreadsheetLayoutDrawer(), blender::tests::TEST(), and blender::nodes::node_geo_duplicate_elements_cc::threaded_slice_fill().

◆ slice() [1/2]

IndexMask blender::IndexMask::slice ( IndexRange  slice) const

Definition at line 13 of file index_mask.cc.

References IndexMask(), slice(), and blender::Span< T >::slice().

◆ slice() [2/2]

IndexMask blender::IndexMask::slice ( int64_t  start,
int64_t  size 
) const

Definition at line 8 of file index_mask.cc.

References size().

Referenced by extract_ranges(), slice(), and slice_and_offset().

◆ slice_and_offset()

IndexMask blender::IndexMask::slice_and_offset ( IndexRange  slice,
Vector< int64_t > &  r_new_indices 
) const

Create a sub-mask that is also shifted to the beginning. The shifting to the beginning allows code to work with smaller indices, which is more memory efficient.

Returns
New index mask with the size of slice. It is either empty or starts with 0. It might reference indices that have been appended to #r_new_indices.

Example:

this: [2, 3, 5, 7, 8, 9, 10]
slice: ^--------^
output: [0, 2, 4, 5]

All the indices in the sub-mask are shifted by 3 towards zero, so that the first index in the output is zero.

Definition at line 18 of file index_mask.cc.

References blender::Vector< T, InlineBufferCapacity, Allocator >::as_span(), IndexMask(), offset, blender::Vector< T, InlineBufferCapacity, Allocator >::resize(), size(), slice(), and blender::Span< T >::slice().

◆ to_best_mask_type()

template<typename Fn >
void blender::IndexMask::to_best_mask_type ( const Fn &  fn) const
inline

Often an IndexMask wraps a range of indices without any gaps. In this case, it is more efficient to compute the indices in a loop on-the-fly instead of reading them from memory. This method makes it easy to generate code for both cases.

The given function is expected to take one parameter that can either be of type #IndexRange or Span<int64_t>.

Definition at line 181 of file BLI_index_mask.hh.

References as_range(), and is_range().

Referenced by foreach_index(), and blender::length_parameterize::interpolate_to_masked().


The documentation for this class was generated from the following files: