Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/geometry_component_pointcloud.cc
| Show First 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | PointCloud *PointCloudComponent::get_for_write() | ||||
| return pointcloud_; | return pointcloud_; | ||||
| } | } | ||||
| bool PointCloudComponent::is_empty() const | bool PointCloudComponent::is_empty() const | ||||
| { | { | ||||
| return pointcloud_ == nullptr; | return pointcloud_ == nullptr; | ||||
| } | } | ||||
| bool PointCloudComponent::owns_direct_data() const | |||||
| { | |||||
| return ownership_ == GeometryOwnershipType::Owned; | |||||
| } | |||||
| void PointCloudComponent::ensure_owns_direct_data() | |||||
| { | |||||
| BLI_assert(this->is_mutable()); | |||||
| if (ownership_ != GeometryOwnershipType::Owned) { | |||||
| pointcloud_ = BKE_pointcloud_copy_for_eval(pointcloud_, false); | |||||
| ownership_ = GeometryOwnershipType::Owned; | |||||
| } | |||||
| } | |||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Attribute Access | /** \name Attribute Access | ||||
| * \{ */ | * \{ */ | ||||
| int PointCloudComponent::attribute_domain_size(const AttributeDomain domain) const | int PointCloudComponent::attribute_domain_size(const AttributeDomain domain) const | ||||
| { | { | ||||
| if (pointcloud_ == nullptr) { | if (pointcloud_ == nullptr) { | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| if (domain != ATTR_DOMAIN_POINT) { | if (domain != ATTR_DOMAIN_POINT) { | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| return pointcloud_->totpoint; | return pointcloud_->totpoint; | ||||
| } | } | ||||
| namespace blender::bke { | namespace blender::bke { | ||||
| template<typename T, AttributeDomain Domain> | template<typename T> | ||||
| static ReadAttributePtr make_array_read_attribute(const void *data, const int domain_size) | static GVArrayPtr make_array_read_attribute(const void *data, const int domain_size) | ||||
| { | { | ||||
| return std::make_unique<ArrayReadAttribute<T>>(Domain, Span<T>((const T *)data, domain_size)); | return std::make_unique<fn::GVArray_For_Span<T>>(Span<T>((const T *)data, domain_size)); | ||||
| } | } | ||||
| template<typename T, AttributeDomain Domain> | template<typename T> | ||||
| static WriteAttributePtr make_array_write_attribute(void *data, const int domain_size) | static GVMutableArrayPtr make_array_write_attribute(void *data, const int domain_size) | ||||
| { | { | ||||
| return std::make_unique<ArrayWriteAttribute<T>>(Domain, MutableSpan<T>((T *)data, domain_size)); | return std::make_unique<fn::GVMutableArray_For_MutableSpan<T>>( | ||||
| MutableSpan<T>((T *)data, domain_size)); | |||||
| } | } | ||||
| /** | /** | ||||
| * In this function all the attribute providers for a point cloud component are created. Most data | * In this function all the attribute providers for a point cloud component are created. Most data | ||||
| * in this function is statically allocated, because it does not change over time. | * in this function is statically allocated, because it does not change over time. | ||||
| */ | */ | ||||
| static ComponentAttributeProviders create_attribute_providers_for_point_cloud() | static ComponentAttributeProviders create_attribute_providers_for_point_cloud() | ||||
| { | { | ||||
| Show All 13 Lines | static CustomDataAccessInfo point_access = { | ||||
| [](const GeometryComponent &component) -> const CustomData * { | [](const GeometryComponent &component) -> const CustomData * { | ||||
| const PointCloudComponent &pointcloud_component = static_cast<const PointCloudComponent &>( | const PointCloudComponent &pointcloud_component = static_cast<const PointCloudComponent &>( | ||||
| component); | component); | ||||
| const PointCloud *pointcloud = pointcloud_component.get_for_read(); | const PointCloud *pointcloud = pointcloud_component.get_for_read(); | ||||
| return pointcloud ? &pointcloud->pdata : nullptr; | return pointcloud ? &pointcloud->pdata : nullptr; | ||||
| }, | }, | ||||
| update_custom_data_pointers}; | update_custom_data_pointers}; | ||||
| static BuiltinCustomDataLayerProvider position( | static BuiltinCustomDataLayerProvider position("position", | ||||
| "position", | |||||
| ATTR_DOMAIN_POINT, | ATTR_DOMAIN_POINT, | ||||
| CD_PROP_FLOAT3, | CD_PROP_FLOAT3, | ||||
| CD_PROP_FLOAT3, | CD_PROP_FLOAT3, | ||||
| BuiltinAttributeProvider::NonCreatable, | BuiltinAttributeProvider::NonCreatable, | ||||
| BuiltinAttributeProvider::Writable, | BuiltinAttributeProvider::Writable, | ||||
| BuiltinAttributeProvider::NonDeletable, | BuiltinAttributeProvider::NonDeletable, | ||||
| point_access, | point_access, | ||||
| make_array_read_attribute<float3, ATTR_DOMAIN_POINT>, | make_array_read_attribute<float3>, | ||||
| make_array_write_attribute<float3, ATTR_DOMAIN_POINT>, | make_array_write_attribute<float3>, | ||||
| nullptr); | nullptr); | ||||
| static BuiltinCustomDataLayerProvider radius( | static BuiltinCustomDataLayerProvider radius("radius", | ||||
| "radius", | |||||
| ATTR_DOMAIN_POINT, | ATTR_DOMAIN_POINT, | ||||
| CD_PROP_FLOAT, | CD_PROP_FLOAT, | ||||
| CD_PROP_FLOAT, | CD_PROP_FLOAT, | ||||
| BuiltinAttributeProvider::Creatable, | BuiltinAttributeProvider::Creatable, | ||||
| BuiltinAttributeProvider::Writable, | BuiltinAttributeProvider::Writable, | ||||
| BuiltinAttributeProvider::Deletable, | BuiltinAttributeProvider::Deletable, | ||||
| point_access, | point_access, | ||||
| make_array_read_attribute<float, ATTR_DOMAIN_POINT>, | make_array_read_attribute<float>, | ||||
| make_array_write_attribute<float, ATTR_DOMAIN_POINT>, | make_array_write_attribute<float>, | ||||
| nullptr); | nullptr); | ||||
| static CustomDataAttributeProvider point_custom_data(ATTR_DOMAIN_POINT, point_access); | static CustomDataAttributeProvider point_custom_data(ATTR_DOMAIN_POINT, point_access); | ||||
| return ComponentAttributeProviders({&position, &radius}, {&point_custom_data}); | return ComponentAttributeProviders({&position, &radius}, {&point_custom_data}); | ||||
| } | } | ||||
| } // namespace blender::bke | } // namespace blender::bke | ||||
| const blender::bke::ComponentAttributeProviders *PointCloudComponent::get_attribute_providers() | const blender::bke::ComponentAttributeProviders *PointCloudComponent::get_attribute_providers() | ||||
| const | const | ||||
| { | { | ||||
| static blender::bke::ComponentAttributeProviders providers = | static blender::bke::ComponentAttributeProviders providers = | ||||
| blender::bke::create_attribute_providers_for_point_cloud(); | blender::bke::create_attribute_providers_for_point_cloud(); | ||||
| return &providers; | return &providers; | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||