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 18:56:27 +0300
committerJacques Lucke <jacques@blender.org>2022-02-23 18:56:27 +0300
commit226f0c4fef7e7792c16458cd3e456b169ddce918 (patch)
tree25c9a8214b66bbb06e86e0953189bb303e561323 /source/blender/blenlib/BLI_index_mask_ops.hh
parent120f16fa1f1efd3cbb4da191d2912e0a6ce3ea59 (diff)
Curves: initial brush implementations for curves sculpt mode
The main goal here is to add the boilerplate code to make it possible to add the actual sculpt tools more easily. Both brush implementations added by this patch are meant to be prototypes which will be removed or refined in the coming weeks. Ref T95773. Differential Revision: https://developer.blender.org/D14180
Diffstat (limited to 'source/blender/blenlib/BLI_index_mask_ops.hh')
-rw-r--r--source/blender/blenlib/BLI_index_mask_ops.hh60
1 files changed, 60 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_index_mask_ops.hh b/source/blender/blenlib/BLI_index_mask_ops.hh
new file mode 100644
index 00000000000..48a1f27a2fa
--- /dev/null
+++ b/source/blender/blenlib/BLI_index_mask_ops.hh
@@ -0,0 +1,60 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#pragma once
+
+/** \file
+ * \ingroup bli
+ *
+ * This is separate from `BLI_index_mask.hh` because it includes headers just `IndexMask` shouldn't
+ * depend on.
+ */
+
+#include "BLI_enumerable_thread_specific.hh"
+#include "BLI_index_mask.hh"
+#include "BLI_task.hh"
+#include "BLI_vector.hh"
+
+namespace blender::index_mask_ops {
+
+namespace detail {
+IndexMask find_indices_based_on_predicate__merge(
+ IndexMask indices_to_check,
+ threading::EnumerableThreadSpecific<Vector<Vector<int64_t>>> &sub_masks,
+ Vector<int64_t> &r_indices);
+} // namespace detail
+
+/**
+ * Evaluate the #predicate for all indices in #indices_to_check and return a mask that contains all
+ * indices where the predicate was true.
+ *
+ * #r_indices indices is only used if necessary.
+ */
+template<typename Predicate>
+inline IndexMask find_indices_based_on_predicate(const IndexMask indices_to_check,
+ const int64_t parallel_grain_size,
+ Vector<int64_t> &r_indices,
+ const Predicate &predicate)
+{
+ /* Evaluate predicate in parallel. Since the size of the final mask is not known yet, many
+ * smaller vectors have to be filled with all indices where the predicate is true. Those smaller
+ * vectors are joined afterwards. */
+ threading::EnumerableThreadSpecific<Vector<Vector<int64_t>>> sub_masks;
+ threading::parallel_for(
+ indices_to_check.index_range(), parallel_grain_size, [&](const IndexRange range) {
+ const IndexMask sub_mask = indices_to_check.slice(range);
+ Vector<int64_t> masked_indices;
+ for (const int64_t i : sub_mask) {
+ if (predicate(i)) {
+ masked_indices.append(i);
+ }
+ }
+ if (!masked_indices.is_empty()) {
+ sub_masks.local().append(std::move(masked_indices));
+ }
+ });
+
+ /* This part doesn't have to be in the header. */
+ return detail::find_indices_based_on_predicate__merge(indices_to_check, sub_masks, r_indices);
+}
+
+} // namespace blender::index_mask_ops