[Bf-blender-cvs] [797a1356caa] master: Curves: Tweak evaluated offset functions
Hans Goudey
noreply at git.blender.org
Fri Mar 25 02:58:07 CET 2022
Commit: 797a1356caadc8df4b81d065d68dcc2ae4ce8f4b
Author: Hans Goudey
Date: Thu Mar 24 20:58:01 2022 -0500
Branches: master
https://developer.blender.org/rB797a1356caadc8df4b81d065d68dcc2ae4ce8f4b
Curves: Tweak evaluated offset functions
Add a function to retrieve the points for an index range of curves,
and move "ensuring" the offsets to a separate function, since it's
often nicer to call that if you don't need the result span immediately.
===================================================================
M source/blender/blenkernel/BKE_curves.hh
M source/blender/blenkernel/intern/curves_geometry.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_curves.hh b/source/blender/blenkernel/BKE_curves.hh
index 6a95bc7d2d2..0f2ae8a02a6 100644
--- a/source/blender/blenkernel/BKE_curves.hh
+++ b/source/blender/blenkernel/BKE_curves.hh
@@ -250,6 +250,7 @@ class CurvesGeometry : public ::CurvesGeometry {
* Call #evaluated_offsets() first to ensure that the evaluated offsets cache is current.
*/
IndexRange evaluated_points_for_curve(int index) const;
+ IndexRange evaluated_points_for_curves(IndexRange curves) const;
/**
* The index of the first evaluated point for every curve. The size of this span is one larger
@@ -258,6 +259,9 @@ class CurvesGeometry : public ::CurvesGeometry {
*/
Span<int> evaluated_offsets() const;
+ /** Makes sure the data described by #evaluated_offsets if necessary. */
+ void ensure_evaluated_offsets() const;
+
Span<float3> evaluated_positions() const;
private:
diff --git a/source/blender/blenkernel/intern/curves_geometry.cc b/source/blender/blenkernel/intern/curves_geometry.cc
index a069176c6f3..e31a983e0bb 100644
--- a/source/blender/blenkernel/intern/curves_geometry.cc
+++ b/source/blender/blenkernel/intern/curves_geometry.cc
@@ -469,16 +469,25 @@ IndexRange CurvesGeometry::evaluated_points_for_curve(int index) const
return offsets_to_range(this->runtime->evaluated_offsets_cache.as_span(), index);
}
-Span<int> CurvesGeometry::evaluated_offsets() const
+IndexRange CurvesGeometry::evaluated_points_for_curves(const IndexRange curves) const
+{
+ BLI_assert(!this->runtime->offsets_cache_dirty);
+ BLI_assert(this->curve_size > 0);
+ const int offset = this->runtime->evaluated_offsets_cache[curves.start()];
+ const int offset_next = this->runtime->evaluated_offsets_cache[curves.one_after_last()];
+ return {offset, offset_next - offset};
+}
+
+void CurvesGeometry::ensure_evaluated_offsets() const
{
if (!this->runtime->offsets_cache_dirty) {
- return this->runtime->evaluated_offsets_cache;
+ return;
}
/* A double checked lock. */
std::scoped_lock lock{this->runtime->offsets_cache_mutex};
if (!this->runtime->offsets_cache_dirty) {
- return this->runtime->evaluated_offsets_cache;
+ return;
}
threading::isolate_task([&]() {
@@ -496,6 +505,11 @@ Span<int> CurvesGeometry::evaluated_offsets() const
});
this->runtime->offsets_cache_dirty = false;
+}
+
+Span<int> CurvesGeometry::evaluated_offsets() const
+{
+ this->ensure_evaluated_offsets();
return this->runtime->evaluated_offsets_cache;
}
More information about the Bf-blender-cvs
mailing list