MeshLib Documentation
Loading...
Searching...
No Matches
MRChangeVoxelsAction.h
Go to the documentation of this file.
1#pragma once
2#include "MRVoxelsFwd.h"
3
5#include "MRObjectVoxels.h"
6#include "MRMesh/MRMesh.h"
8#include "MRFloatGrid.h"
9#include <memory>
10
11namespace MR
12{
13
16
19{
20public:
23 ChangeIsoAction( std::string name, const std::shared_ptr<ObjectVoxels>& obj ) :
24 objVoxels_{ obj },
25 name_{ std::move( name ) }
26 {
27 if ( obj )
28 {
29 storedIso_ = obj->getIsoValue();
30 }
31 }
32
33 virtual std::string name() const override
34 {
35 return name_;
36 }
37
38 virtual void action( HistoryAction::Type ) override
39 {
40 if ( !objVoxels_ )
41 return;
42
43 float newIso = objVoxels_->getIsoValue();
44 objVoxels_->setIsoValue( storedIso_, {}, false );
45 storedIso_ = newIso;
46 }
47
48 static void setObjectDirty( const std::shared_ptr<Obj>& )
49 {
50 }
51
52 [[nodiscard]] virtual size_t heapBytes() const override
53 {
54 return name_.capacity();
55 }
56
57private:
58 std::shared_ptr<ObjectVoxels> objVoxels_;
59 float storedIso_{ 0.0f };
60
61 std::string name_;
62};
63
66{
67public:
70 ChangeDualMarchingCubesAction( std::string name, const std::shared_ptr<ObjectVoxels>& obj ) :
71 objVoxels_{ obj },
72 name_{ std::move( name ) }
73 {
74 if ( obj )
75 {
76 storedDual_ = obj->getDualMarchingCubes();
77 }
78 }
79
81 ChangeDualMarchingCubesAction( std::string name, const std::shared_ptr<ObjectVoxels>& obj, bool storeDual ) :
82 objVoxels_{ obj },
83 storedDual_( storeDual ),
84 name_{ std::move( name ) }
85 {
86 }
87
88 virtual std::string name() const override
89 {
90 return name_;
91 }
92
93 virtual void action( HistoryAction::Type ) override
94 {
95 if ( !objVoxels_ )
96 return;
97
98 auto newDual = objVoxels_->getDualMarchingCubes();
99 objVoxels_->setDualMarchingCubes( storedDual_, false );
100 storedDual_ = newDual;
101 }
102
103 static void setObjectDirty( const std::shared_ptr<Obj>& )
104 {
105 }
106
107 [[nodiscard]] virtual size_t heapBytes() const override
108 {
109 return name_.capacity();
110 }
111
112private:
113 std::shared_ptr<ObjectVoxels> objVoxels_;
114 bool storedDual_{ true };
115
116 std::string name_;
117};
118
119// Undo action for ObjectVoxels active bounds change
121{
122public:
125 ChangeActiveBoxAction( std::string name, const std::shared_ptr<ObjectVoxels>& obj ) :
126 objVoxels_{ obj },
127 name_{ std::move( name ) }
128 {
129 if ( obj )
130 {
131 activeBox_ = obj->getActiveBounds();
132 }
133 }
134
135 virtual std::string name() const override
136 {
137 return name_;
138 }
139
140 virtual void action( HistoryAction::Type ) override
141 {
142 if ( !objVoxels_ )
143 return;
144
145 auto box = objVoxels_->getActiveBounds();
146 objVoxels_->setActiveBounds( activeBox_, {}, false );
147 activeBox_ = box;
148 }
149
150 static void setObjectDirty( const std::shared_ptr<Obj>& )
151 {
152 }
153
154 [[nodiscard]] virtual size_t heapBytes() const override
155 {
156 return name_.capacity();
157 }
158
159private:
160 std::shared_ptr<ObjectVoxels> objVoxels_;
161 Box3i activeBox_;
162
163 std::string name_;
164};
165
166// Undo action for ObjectVoxels surface change (need for faster undo redo)
168{
169public:
172 ChangeSurfaceAction( std::string name, const std::shared_ptr<ObjectVoxels>& obj ) :
173 objVoxels_{ obj },
174 name_{ std::move( name ) }
175 {
176 if ( obj )
177 {
178 if ( auto m = obj->mesh() )
179 cloneSurface_ = std::make_shared<Mesh>( *m );
180 }
181 }
182
183 virtual std::string name() const override
184 {
185 return name_;
186 }
187
188 virtual void action( HistoryAction::Type ) override
189 {
190 if ( !objVoxels_ )
191 return;
192
193 cloneSurface_ = objVoxels_->updateIsoSurface( cloneSurface_ );
194 }
195
196 static void setObjectDirty( const std::shared_ptr<Obj>& obj )
197 {
198 if ( obj )
199 obj->setDirtyFlags( DIRTY_ALL );
200 }
201
202 [[nodiscard]] virtual size_t heapBytes() const override
203 {
204 return name_.capacity() + MR::heapBytes( cloneSurface_ );
205 }
206
207private:
208 std::shared_ptr<ObjectVoxels> objVoxels_;
209 std::shared_ptr<Mesh> cloneSurface_;
210
211 std::string name_;
212};
213
214// Undo action for ObjectVoxels all data change (need for faster undo redo)
216{
217public:
220 ChangeGridAction( std::string name, const std::shared_ptr<ObjectVoxels>& obj ) :
221 objVoxels_{ obj },
222 changeIsoAction_( name, obj ),
223 changeSurfaceAction_(name, obj),
224 name_{ std::move( name ) }
225 {
226 if ( obj )
227 {
228 vdbVolume_ = obj->vdbVolume();
229 histogram_ = obj->histogram();
230 }
231 }
232
233 virtual std::string name() const override
234 {
235 return name_;
236 }
237
238 virtual void action( HistoryAction::Type obj ) override
239 {
240 if ( !objVoxels_ )
241 return;
242
243 vdbVolume_ = objVoxels_->updateVdbVolume( std::move( vdbVolume_ ) );
244 histogram_ = objVoxels_->updateHistogram( std::move( histogram_ ) );
245 changeIsoAction_.action( obj );
246 changeSurfaceAction_.action( obj );
247 }
248
249 static void setObjectDirty( const std::shared_ptr<Obj>& obj )
250 {
251 if ( obj )
252 obj->setDirtyFlags( DIRTY_ALL );
253 }
254
255 [[nodiscard]] virtual size_t heapBytes() const override
256 {
257 return name_.capacity() + histogram_.heapBytes() + changeIsoAction_.heapBytes() + changeSurfaceAction_.heapBytes() + MR::heapBytes( vdbVolume_.data );
258 }
259
260private:
261 std::shared_ptr<ObjectVoxels> objVoxels_;
262 VdbVolume vdbVolume_;
263 Histogram histogram_;
264 ChangeIsoAction changeIsoAction_;
265 ChangeSurfaceAction changeSurfaceAction_;
266
267 std::string name_;
268};
269
271
272}
Definition MRChangeVoxelsAction.h:121
virtual std::string name() const override
Definition MRChangeVoxelsAction.h:135
ChangeActiveBoxAction(std::string name, const std::shared_ptr< ObjectVoxels > &obj)
use this constructor to remember object's active box before making any changes in it
Definition MRChangeVoxelsAction.h:125
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeVoxelsAction.h:154
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeVoxelsAction.h:140
static void setObjectDirty(const std::shared_ptr< Obj > &)
Definition MRChangeVoxelsAction.h:150
Undo action for ObjectVoxels dual/standard marching cubes change.
Definition MRChangeVoxelsAction.h:66
virtual std::string name() const override
Definition MRChangeVoxelsAction.h:88
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeVoxelsAction.h:107
ChangeDualMarchingCubesAction(std::string name, const std::shared_ptr< ObjectVoxels > &obj, bool storeDual)
use this constructor to remember given dual-value (and not the current value in the object)
Definition MRChangeVoxelsAction.h:81
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeVoxelsAction.h:93
static void setObjectDirty(const std::shared_ptr< Obj > &)
Definition MRChangeVoxelsAction.h:103
ChangeDualMarchingCubesAction(std::string name, const std::shared_ptr< ObjectVoxels > &obj)
use this constructor to remember object's dual-value before making any changes in it
Definition MRChangeVoxelsAction.h:70
Definition MRChangeVoxelsAction.h:216
virtual void action(HistoryAction::Type obj) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeVoxelsAction.h:238
ChangeGridAction(std::string name, const std::shared_ptr< ObjectVoxels > &obj)
use this constructor to remember object's data before making any changes in it
Definition MRChangeVoxelsAction.h:220
static void setObjectDirty(const std::shared_ptr< Obj > &obj)
Definition MRChangeVoxelsAction.h:249
virtual std::string name() const override
Definition MRChangeVoxelsAction.h:233
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeVoxelsAction.h:255
Undo action for ObjectVoxels iso-value change.
Definition MRChangeVoxelsAction.h:19
virtual std::string name() const override
Definition MRChangeVoxelsAction.h:33
static void setObjectDirty(const std::shared_ptr< Obj > &)
Definition MRChangeVoxelsAction.h:48
ChangeIsoAction(std::string name, const std::shared_ptr< ObjectVoxels > &obj)
use this constructor to remember object's iso before making any changes in it
Definition MRChangeVoxelsAction.h:23
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeVoxelsAction.h:38
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeVoxelsAction.h:52
Definition MRChangeVoxelsAction.h:168
virtual std::string name() const override
Definition MRChangeVoxelsAction.h:183
ChangeSurfaceAction(std::string name, const std::shared_ptr< ObjectVoxels > &obj)
use this constructor to remember object's surface before making any changes in it
Definition MRChangeVoxelsAction.h:172
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeVoxelsAction.h:202
static void setObjectDirty(const std::shared_ptr< Obj > &obj)
Definition MRChangeVoxelsAction.h:196
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeVoxelsAction.h:188
Definition MRHistogram.h:10
size_t heapBytes() const
returns the amount of memory this object occupies on heap
Definition MRHistogram.h:36
Definition MRHistoryAction.h:12
Type
Definition MRHistoryAction.h:19
Definition MRObjectVoxels.h:17
size_t heapBytes(const std::vector< T > &vec)
returns the amount of memory given vector occupies on heap
Definition MRHeapBytes.h:15
@ DIRTY_ALL
Definition MRVisualObject.h:109
Definition MRCameraOrientationPlugin.h:8