[Bf-blender-cvs] [1faab5c82dc] attribute-accessor: cleanup naming

Jacques Lucke noreply at git.blender.org
Tue Nov 17 13:55:45 CET 2020


Commit: 1faab5c82dcb2f9cae329a92d687a22b7372c570
Author: Jacques Lucke
Date:   Tue Nov 17 13:42:44 2020 +0100
Branches: attribute-accessor
https://developer.blender.org/rB1faab5c82dcb2f9cae329a92d687a22b7372c570

cleanup naming

===================================================================

M	source/blender/blenkernel/BKE_attribute_accessor.hh
M	source/blender/blenkernel/intern/attribute_accessor.cc
M	source/blender/nodes/NOD_geometry_exec.hh
M	source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc

===================================================================

diff --git a/source/blender/blenkernel/BKE_attribute_accessor.hh b/source/blender/blenkernel/BKE_attribute_accessor.hh
index 8f71e4d304f..4a43e12044a 100644
--- a/source/blender/blenkernel/BKE_attribute_accessor.hh
+++ b/source/blender/blenkernel/BKE_attribute_accessor.hh
@@ -27,19 +27,19 @@ namespace blender::bke {
 
 using fn::CPPType;
 
-class AttributeAccessor {
+class ReadAttribute {
  protected:
   const AttributeDomain domain_;
   const CPPType &cpp_type_;
   const int64_t size_;
 
  public:
-  AttributeAccessor(AttributeDomain domain, const CPPType &cpp_type, const int64_t size)
+  ReadAttribute(AttributeDomain domain, const CPPType &cpp_type, const int64_t size)
       : domain_(domain), cpp_type_(cpp_type), size_(size)
   {
   }
 
-  virtual ~AttributeAccessor() = default;
+  virtual ~ReadAttribute() = default;
 
   AttributeDomain domain() const
   {
@@ -59,7 +59,7 @@ class AttributeAccessor {
   void get(const int64_t index, void *r_value) const
   {
     BLI_assert(index < size_);
-    this->access_single(index, r_value);
+    this->get_internal(index, r_value);
   }
 
   template<typename T> T get(const int64_t index) const
@@ -67,29 +67,28 @@ class AttributeAccessor {
     BLI_assert(index < size_);
     T value;
     value.~T();
-    this->access_single(index, &value);
+    this->get_internal(index, &value);
     return value;
   }
 
  protected:
   /* r_value is expected to be uninitialized. */
-  virtual void access_single(const int64_t index, void *r_value) const = 0;
+  virtual void get_internal(const int64_t index, void *r_value) const = 0;
 };
 
-using AttributeAccessorPtr = std::unique_ptr<AttributeAccessor>;
+using ReadAttributePtr = std::unique_ptr<ReadAttribute>;
 
-AttributeAccessorPtr mesh_attribute_get_accessor(const MeshComponent &mesh_component,
-                                                 const StringRef attribute_name);
+ReadAttributePtr mesh_attribute_get_for_read(const MeshComponent &mesh_component,
+                                             const StringRef attribute_name);
 
-AttributeAccessorPtr mesh_attribute_adapt_accessor_domain(const MeshComponent &mesh_component,
-                                                          AttributeAccessorPtr attribute_accessor,
-                                                          const AttributeDomain to_domain);
+ReadAttributePtr mesh_attribute_adapt_domain(const MeshComponent &mesh_component,
+                                             ReadAttributePtr attribute,
+                                             const AttributeDomain to_domain);
 
-AttributeAccessorPtr mesh_attribute_get_accessor_for_domain_with_type(
-    const MeshComponent &mesh_component,
-    const StringRef attribute_name,
-    const AttributeDomain domain,
-    const CPPType &cpp_type,
-    const void *default_value = nullptr);
+ReadAttributePtr mesh_attribute_get_for_read(const MeshComponent &mesh_component,
+                                             const StringRef attribute_name,
+                                             const AttributeDomain domain,
+                                             const CPPType &cpp_type,
+                                             const void *default_value = nullptr);
 
 }  // namespace blender::bke
diff --git a/source/blender/blenkernel/intern/attribute_accessor.cc b/source/blender/blenkernel/intern/attribute_accessor.cc
index 73b656057bf..803de4c50d6 100644
--- a/source/blender/blenkernel/intern/attribute_accessor.cc
+++ b/source/blender/blenkernel/intern/attribute_accessor.cc
@@ -28,22 +28,20 @@
 
 namespace blender::bke {
 
-class VertexWeightAttributeAccessor final : public AttributeAccessor {
+class VertexWeightReadAttribute final : public ReadAttribute {
  private:
   Span<MDeformVert> dverts_;
   int dvert_index_;
 
  public:
-  VertexWeightAttributeAccessor(const MDeformVert *dverts,
-                                const int totvert,
-                                const int dvert_index)
-      : AttributeAccessor(ATTR_DOMAIN_VERTEX, CPPType::get<float>(), totvert),
+  VertexWeightReadAttribute(const MDeformVert *dverts, const int totvert, const int dvert_index)
+      : ReadAttribute(ATTR_DOMAIN_VERTEX, CPPType::get<float>(), totvert),
         dverts_(dverts, totvert),
         dvert_index_(dvert_index)
   {
   }
 
-  void access_single(const int64_t index, void *r_value) const override
+  void get_internal(const int64_t index, void *r_value) const override
   {
     const MDeformVert &dvert = dverts_[index];
     for (const MDeformWeight &weight : Span(dvert.dw, dvert.totweight)) {
@@ -56,24 +54,24 @@ class VertexWeightAttributeAccessor final : public AttributeAccessor {
   }
 };
 
-template<typename T> class ArrayAttributeAccessor final : public AttributeAccessor {
+template<typename T> class ArrayReadAttribute final : public ReadAttribute {
  private:
   Span<T> data_;
 
  public:
-  ArrayAttributeAccessor(AttributeDomain domain, Span<T> data)
-      : AttributeAccessor(domain, CPPType::get<T>(), data.size()), data_(data)
+  ArrayReadAttribute(AttributeDomain domain, Span<T> data)
+      : ReadAttribute(domain, CPPType::get<T>(), data.size()), data_(data)
   {
   }
 
-  void access_single(const int64_t index, void *r_value) const override
+  void get_internal(const int64_t index, void *r_value) const override
   {
     new (r_value) T(data_[index]);
   }
 };
 
 template<typename StructT, typename FuncT>
-class DerivedArrayAttributeAccessor final : public AttributeAccessor {
+class DerivedArrayReadAttribute final : public ReadAttribute {
  private:
   using ElemT = decltype(std::declval<FuncT>()(std::declval<StructT>()));
 
@@ -81,14 +79,14 @@ class DerivedArrayAttributeAccessor final : public AttributeAccessor {
   FuncT function_;
 
  public:
-  DerivedArrayAttributeAccessor(AttributeDomain domain, Span<StructT> data, FuncT function)
-      : AttributeAccessor(domain, CPPType::get<ElemT>(), data.size()),
+  DerivedArrayReadAttribute(AttributeDomain domain, Span<StructT> data, FuncT function)
+      : ReadAttribute(domain, CPPType::get<ElemT>(), data.size()),
         data_(data),
         function_(std::move(function))
   {
   }
 
-  void access_single(const int64_t index, void *r_value) const override
+  void get_internal(const int64_t index, void *r_value) const override
   {
     const StructT &struct_value = data_[index];
     const ElemT value = function_(struct_value);
@@ -96,90 +94,49 @@ class DerivedArrayAttributeAccessor final : public AttributeAccessor {
   }
 };
 
-class ConstantAttributeAccessor final : public AttributeAccessor {
+class ConstantReadAttribute final : public ReadAttribute {
  private:
   void *value_;
 
  public:
-  ConstantAttributeAccessor(AttributeDomain domain,
-                            const int64_t size,
-                            const CPPType &type,
-                            const void *value)
-      : AttributeAccessor(domain, type, size)
+  ConstantReadAttribute(AttributeDomain domain,
+                        const int64_t size,
+                        const CPPType &type,
+                        const void *value)
+      : ReadAttribute(domain, type, size)
   {
     value_ = MEM_mallocN_aligned(type.size(), type.alignment(), __func__);
     type.copy_to_uninitialized(value, value_);
   }
 
-  void access_single(const int64_t UNUSED(index), void *r_value) const override
+  void get_internal(const int64_t UNUSED(index), void *r_value) const override
   {
     this->cpp_type_.copy_to_uninitialized(value_, r_value);
   }
 };
 
-class VertexToEdgeAccessor final : public AttributeAccessor {
- private:
-  AttributeAccessorPtr vertex_accessor_;
-  Span<MEdge> edges_;
-
- public:
-  VertexToEdgeAccessor(AttributeAccessorPtr vertex_accessor, Span<MEdge> edges)
-      : AttributeAccessor(ATTR_DOMAIN_EDGE, vertex_accessor->cpp_type(), edges.size()),
-        vertex_accessor_(std::move(vertex_accessor)),
-        edges_(edges)
-  {
-  }
-
-  void access_single(const int64_t index, void *r_value) const override
-  {
-    const MEdge &edge = edges_[index];
-    /* TODO: Interpolation. */
-    vertex_accessor_->get(edge.v1, r_value);
-  }
-};
-
-class VertexToCornerAccessor final : public AttributeAccessor {
- private:
-  AttributeAccessorPtr vertex_accessor_;
-  Span<MLoop> loops_;
-
- public:
-  VertexToCornerAccessor(AttributeAccessorPtr vertex_accessor, Span<MLoop> loops)
-      : AttributeAccessor(ATTR_DOMAIN_CORNER, vertex_accessor->cpp_type(), loops.size()),
-        vertex_accessor_(std::move(vertex_accessor)),
-        loops_(loops)
-  {
-  }
-
-  void access_single(const int64_t index, void *r_value) const override
-  {
-    const MLoop &loop = loops_[index];
-    vertex_accessor_->get(loop.v, r_value);
-  }
-};
-
-static AttributeAccessorPtr get_attribute_layer_accessor(const CustomData &custom_data,
-                                                         const int size,
-                                                         const StringRef attribute_name,
-                                                         const AttributeDomain domain)
+static ReadAttributePtr get_custom_data_read_attribute(const CustomData &custom_data,
+                                                       const int size,
+                                                       const StringRef attribute_name,
+                                                       const AttributeDomain domain)
 {
   for (const CustomDataLayer &layer : Span(custom_data.layers, custom_data.totlayer)) {
     if (layer.name != nullptr && layer.name == attribute_name) {
       switch (layer.type) {
         case CD_PROP_FLOAT:
-          return std::make_unique<ArrayAttributeAccessor<float>>(
+          return std::make_unique<ArrayReadAttribute<float>>(
               domain, Span(static_cast<float *>(layer.data), size));
         case CD_PROP_FLOAT2:
-          return std::make_unique<ArrayAttributeAccessor<float2>>(
+          return std::make_unique<ArrayReadAttribute<float2>>(
               domain, Span(static_cast<float2 *>(layer.data), size));
         case CD_PROP_FLOAT3:
-          return std::make_unique<ArrayAttributeAccessor<float3>>(
+          return std::make_unique<ArrayReadAttribute<float3>>(
         

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list