Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2022-02-23 13:13:54 +0300
committerJacques Lucke <jacques@blender.org>2022-02-23 13:14:07 +0300
commit34294449059744ba4b3d4b16eb5fb14a48c16265 (patch)
tree68b52e488e5d245f94cdf63874626df970b79d95 /source/blender/blenlib/BLI_index_mask.hh
parent66c0fe5b234fad377c21c25dc406309abcd57656 (diff)
BLI: add index mask utilities
Sometimes it is useful to get the index ranges that are in an index mask. That is because some algorithms can process index ranges more efficiently than generic index masks. Extracting ranges from an index mask is relatively efficient, because it is cheap to check if a span of indices contains a contiguous range.
Diffstat (limited to 'source/blender/blenlib/BLI_index_mask.hh')
-rw-r--r--source/blender/blenlib/BLI_index_mask.hh36
1 files changed, 36 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_index_mask.hh b/source/blender/blenlib/BLI_index_mask.hh
index 7f4e7be543b..3decd8b9441 100644
--- a/source/blender/blenlib/BLI_index_mask.hh
+++ b/source/blender/blenlib/BLI_index_mask.hh
@@ -209,6 +209,18 @@ class IndexMask {
return indices_.is_empty();
}
+ bool contained_in(const IndexRange range) const
+ {
+ if (indices_.is_empty()) {
+ return true;
+ }
+ if (range.size() < indices_.size()) {
+ return false;
+ }
+ return indices_.first() >= range.first() && indices_.last() <= range.last();
+ }
+
+ IndexMask slice(int64_t start, int64_t size) const;
IndexMask slice(IndexRange slice) const;
/**
* Create a sub-mask that is also shifted to the beginning.
@@ -229,6 +241,30 @@ class IndexMask {
* so that the first index in the output is zero.
*/
IndexMask slice_and_offset(IndexRange slice, 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.
+ */
+ IndexMask invert(const IndexRange full_range, Vector<int64_t> &r_new_indices) const;
+
+ /**
+ * Get all contiguous index ranges within the mask.
+ */
+ Vector<IndexRange> extract_ranges() 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.
+ */
+ Vector<IndexRange> extract_ranges_invert(const IndexRange full_range,
+ Vector<int64_t> *r_skip_amounts) const;
};
} // namespace blender