Blender  V3.3
geometry_component_volume.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include "DNA_volume_types.h"
4 
5 #include "BKE_geometry_set.hh"
6 #include "BKE_lib_id.h"
7 #include "BKE_volume.h"
8 
9 /* -------------------------------------------------------------------- */
14 {
15 }
16 
18 {
19  this->clear();
20 }
21 
23 {
24  VolumeComponent *new_component = new VolumeComponent();
25  if (volume_ != nullptr) {
26  new_component->volume_ = BKE_volume_copy_for_eval(volume_, false);
27  new_component->ownership_ = GeometryOwnershipType::Owned;
28  }
29  return new_component;
30 }
31 
33 {
34  BLI_assert(this->is_mutable());
35  if (volume_ != nullptr) {
36  if (ownership_ == GeometryOwnershipType::Owned) {
37  BKE_id_free(nullptr, volume_);
38  }
39  volume_ = nullptr;
40  }
41 }
42 
44 {
45  return volume_ != nullptr;
46 }
47 
49 {
50  BLI_assert(this->is_mutable());
51  this->clear();
52  volume_ = volume;
53  ownership_ = ownership;
54 }
55 
57 {
58  BLI_assert(this->is_mutable());
59  Volume *volume = volume_;
60  volume_ = nullptr;
61  return volume;
62 }
63 
65 {
66  return volume_;
67 }
68 
70 {
71  BLI_assert(this->is_mutable());
72  if (ownership_ == GeometryOwnershipType::ReadOnly) {
73  volume_ = BKE_volume_copy_for_eval(volume_, false);
74  ownership_ = GeometryOwnershipType::Owned;
75  }
76  return volume_;
77 }
78 
80 {
81  return ownership_ == GeometryOwnershipType::Owned;
82 }
83 
85 {
86  BLI_assert(this->is_mutable());
87  if (ownership_ != GeometryOwnershipType::Owned) {
88  volume_ = BKE_volume_copy_for_eval(volume_, false);
89  ownership_ = GeometryOwnershipType::Owned;
90  }
91 }
92 
@ GEO_COMPONENT_TYPE_VOLUME
GeometryOwnershipType
void BKE_id_free(struct Main *bmain, void *idv)
Volume data-block.
struct Volume * BKE_volume_copy_for_eval(struct Volume *volume_src, bool reference)
Definition: volume.cc:1515
#define BLI_assert(a)
Definition: BLI_assert.h:46
bool is_mutable() const
Definition: geometry_set.cc:97
void replace(Volume *volume, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
void ensure_owns_direct_data() override
GeometryComponent * copy() const override
const Volume * get_for_read() const
bool owns_direct_data() const override