Blender V5.0
geometry_component_pointcloud.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6
7#include "BKE_geometry_set.hh"
8#include "BKE_lib_id.hh"
9#include "BKE_pointcloud.hh"
10
12
13namespace blender::bke {
14
15/* -------------------------------------------------------------------- */
18
20
22 : GeometryComponent(Type::PointCloud), pointcloud_(pointcloud), ownership_(ownership)
23{
24}
25
30
32{
33 PointCloudComponent *new_component = new PointCloudComponent();
34 if (pointcloud_ != nullptr) {
35 new_component->pointcloud_ = BKE_pointcloud_copy_for_eval(pointcloud_);
36 new_component->ownership_ = GeometryOwnershipType::Owned;
37 }
38 return GeometryComponentPtr(new_component);
39}
40
42{
43 BLI_assert(this->is_mutable() || this->is_expired());
44 if (pointcloud_ != nullptr) {
45 if (ownership_ == GeometryOwnershipType::Owned) {
46 BKE_id_free(nullptr, pointcloud_);
47 }
48 pointcloud_ = nullptr;
49 }
50}
51
53{
54 return pointcloud_ != nullptr;
55}
56
58{
59 BLI_assert(this->is_mutable());
60 this->clear();
61 pointcloud_ = pointcloud;
62 ownership_ = ownership;
63}
64
66{
67 BLI_assert(this->is_mutable());
68 PointCloud *pointcloud = pointcloud_;
69 pointcloud_ = nullptr;
70 return pointcloud;
71}
72
74{
75 return pointcloud_;
76}
77
79{
80 BLI_assert(this->is_mutable());
81 if (ownership_ == GeometryOwnershipType::ReadOnly) {
82 pointcloud_ = BKE_pointcloud_copy_for_eval(pointcloud_);
84 }
85 return pointcloud_;
86}
87
89{
90 return pointcloud_ == nullptr;
91}
92
94{
95 return ownership_ == GeometryOwnershipType::Owned;
96}
97
99{
100 BLI_assert(this->is_mutable());
101 if (ownership_ != GeometryOwnershipType::Owned) {
102 if (pointcloud_) {
103 pointcloud_ = BKE_pointcloud_copy_for_eval(pointcloud_);
104 }
105 ownership_ = GeometryOwnershipType::Owned;
106 }
107}
108
110{
111 if (pointcloud_) {
112 pointcloud_->count_memory(memory);
113 }
114}
115
117
118} // namespace blender::bke
119
120namespace blender::bke {
121
122/* -------------------------------------------------------------------- */
125
126std::optional<AttributeAccessor> PointCloudComponent::attributes() const
127{
129}
130
131std::optional<MutableAttributeAccessor> PointCloudComponent::attributes_for_write()
132{
133 PointCloud *pointcloud = this->get_for_write();
135}
136
138
139} // namespace blender::bke
void BKE_id_free(Main *bmain, void *idv)
General operations for point clouds.
PointCloud * BKE_pointcloud_copy_for_eval(const PointCloud *pointcloud_src)
#define BLI_assert(a)
Definition BLI_assert.h:46
GeometryComponentPtr copy() const override
void count_memory(MemoryCounter &memory) const override
void replace(PointCloud *pointcloud, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
std::optional< MutableAttributeAccessor > attributes_for_write() final
std::optional< AttributeAccessor > attributes() const final
ImplicitSharingPtr< GeometryComponent > GeometryComponentPtr
const AttributeAccessorFunctions & pointcloud_attribute_accessor_functions()