Blender  V2.93
geometry_component_volume.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #include "DNA_volume_types.h"
18 
19 #include "BKE_geometry_set.hh"
20 #include "BKE_lib_id.h"
21 #include "BKE_volume.h"
22 
23 /* -------------------------------------------------------------------- */
28 {
29 }
30 
32 {
33  this->clear();
34 }
35 
37 {
38  VolumeComponent *new_component = new VolumeComponent();
39  if (volume_ != nullptr) {
40  new_component->volume_ = BKE_volume_copy_for_eval(volume_, false);
41  new_component->ownership_ = GeometryOwnershipType::Owned;
42  }
43  return new_component;
44 }
45 
47 {
48  BLI_assert(this->is_mutable());
49  if (volume_ != nullptr) {
50  if (ownership_ == GeometryOwnershipType::Owned) {
51  BKE_id_free(nullptr, volume_);
52  }
53  volume_ = nullptr;
54  }
55 }
56 
58 {
59  return volume_ != nullptr;
60 }
61 
62 /* Clear the component and replace it with the new volume. */
64 {
65  BLI_assert(this->is_mutable());
66  this->clear();
67  volume_ = volume;
68  ownership_ = ownership;
69 }
70 
71 /* Return the volume and clear the component. The caller takes over responsibility for freeing the
72  * volume (if the component was responsible before). */
74 {
75  BLI_assert(this->is_mutable());
76  Volume *volume = volume_;
77  volume_ = nullptr;
78  return volume;
79 }
80 
81 /* Get the volume from this component. This method can be used by multiple threads at the same
82  * time. Therefore, the returned volume should not be modified. No ownership is transferred. */
84 {
85  return volume_;
86 }
87 
88 /* Get the volume from this component. This method can only be used when the component is mutable,
89  * i.e. it is not shared. The returned volume can be modified. No ownership is transferred. */
91 {
92  BLI_assert(this->is_mutable());
93  if (ownership_ == GeometryOwnershipType::ReadOnly) {
94  volume_ = BKE_volume_copy_for_eval(volume_, false);
95  ownership_ = GeometryOwnershipType::Owned;
96  }
97  return volume_;
98 }
99 
101 {
102  return ownership_ == GeometryOwnershipType::Owned;
103 }
104 
106 {
107  BLI_assert(this->is_mutable());
108  if (ownership_ != GeometryOwnershipType::Owned) {
109  volume_ = BKE_volume_copy_for_eval(volume_, false);
110  ownership_ = GeometryOwnershipType::Owned;
111  }
112 }
113 
@ GEO_COMPONENT_TYPE_VOLUME
GeometryOwnershipType
void BKE_id_free(struct Main *bmain, void *idv)
Volume datablock.
struct Volume * BKE_volume_copy_for_eval(struct Volume *volume_src, bool reference)
Definition: volume.cc:1390
#define BLI_assert(a)
Definition: BLI_assert.h:58
bool is_mutable() const
Definition: geometry_set.cc:81
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