Blender V4.3
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/* -------------------------------------------------------------------- */
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
118/* -------------------------------------------------------------------- */
122static void tag_component_positions_changed(void *owner)
123{
124 PointCloud &points = *static_cast<PointCloud *>(owner);
125 points.tag_positions_changed();
126}
127
128static void tag_component_radius_changed(void *owner)
129{
130 PointCloud &points = *static_cast<PointCloud *>(owner);
131 points.tag_radii_changed();
132}
133
139{
140 static CustomDataAccessInfo point_access = {
141 [](void *owner) -> CustomData * {
142 PointCloud *pointcloud = static_cast<PointCloud *>(owner);
143 return &pointcloud->pdata;
144 },
145 [](const void *owner) -> const CustomData * {
146 const PointCloud *pointcloud = static_cast<const PointCloud *>(owner);
147 return &pointcloud->pdata;
148 },
149 [](const void *owner) -> int {
150 const PointCloud *pointcloud = static_cast<const PointCloud *>(owner);
151 return pointcloud->totpoint;
152 }};
153
154 static BuiltinCustomDataLayerProvider position("position",
158 point_access,
160 static BuiltinCustomDataLayerProvider radius("radius",
164 point_access,
166 static BuiltinCustomDataLayerProvider id("id",
170 point_access,
171 nullptr);
172 static CustomDataAttributeProvider point_custom_data(AttrDomain::Point, point_access);
173 return ComponentAttributeProviders({&position, &radius, &id}, {&point_custom_data});
174}
175
177{
178 static const ComponentAttributeProviders providers =
182 fn.domain_size = [](const void *owner, const AttrDomain domain) {
183 if (owner == nullptr) {
184 return 0;
185 }
186 const PointCloud &pointcloud = *static_cast<const PointCloud *>(owner);
187 switch (domain) {
189 return pointcloud.totpoint;
190 default:
191 return 0;
192 }
193 };
194 fn.domain_supported = [](const void * /*owner*/, const AttrDomain domain) {
195 return domain == AttrDomain::Point;
196 };
197 fn.adapt_domain = [](const void * /*owner*/,
198 const GVArray &varray,
199 const AttrDomain from_domain,
200 const AttrDomain to_domain) {
201 if (from_domain == to_domain && from_domain == AttrDomain::Point) {
202 return varray;
203 }
204 return GVArray{};
205 };
206 return fn;
207}
208
214
215} // namespace blender::bke
216
218{
221}
222
223blender::bke::MutableAttributeAccessor PointCloud::attributes_for_write()
224{
227}
228
229namespace blender::bke {
230
231std::optional<AttributeAccessor> PointCloudComponent::attributes() const
232{
234}
235
236std::optional<MutableAttributeAccessor> PointCloudComponent::attributes_for_write()
237{
238 PointCloud *pointcloud = this->get_for_write();
240}
241
244} // 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:50
@ CD_PROP_FLOAT
@ CD_PROP_FLOAT3
@ CD_PROP_INT32
AttributeSet attributes
GeometryComponentPtr copy() const override
void count_memory(MemoryCounter &memory) const override
void replace(PointCloud *pointcloud, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
AttributeAccessorFunctions accessor_functions_for_providers()
ImplicitSharingPtr< GeometryComponent > GeometryComponentPtr
static ComponentAttributeProviders create_attribute_providers_for_point_cloud()
static void tag_component_positions_changed(void *owner)
static void tag_component_radius_changed(void *owner)
static const AttributeAccessorFunctions & get_pointcloud_accessor_functions_ref()
static AttributeAccessorFunctions get_pointcloud_accessor_functions()
struct CustomData pdata
GVArray(* adapt_domain)(const void *owner, const GVArray &varray, AttrDomain from_domain, AttrDomain to_domain)
bool(* domain_supported)(const void *owner, AttrDomain domain)
int(* domain_size)(const void *owner, AttrDomain domain)