MeshLib C++ Docs
Loading...
Searching...
No Matches
MRPartialChangeMeshAction.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRHistoryAction.h"
4#include "MRMesh.h"
5#include "MRMeshDiff.h"
6#include "MRObjectMesh.h"
7#include <cassert>
8
9namespace MR
10{
11
14
16struct CmpOld {};
17inline constexpr CmpOld cmpOld;
18
20struct SetNew {};
21inline constexpr SetNew setNew;
22
25{
26public:
29 PartialChangeMeshAction( std::string name, std::shared_ptr<ObjectMesh> obj, CmpOld, const Mesh &oldMesh ) :
30 objMesh_{ std::move( obj ) },
31 name_{ std::move( name ) }
32 {
33 assert( objMesh_ );
34 if ( objMesh_ && objMesh_->mesh() )
35 meshDiff_ = MeshDiff( *objMesh_->mesh(), oldMesh );
36 }
37
39 PartialChangeMeshAction( std::string name, std::shared_ptr<ObjectMesh> obj, SetNew, std::shared_ptr<Mesh>&& newMesh ) :
40 objMesh_{ std::move( obj ) },
41 name_{ std::move( name ) }
42 {
43 assert( objMesh_ && newMesh );
44 if ( objMesh_ )
45 {
46 auto oldMesh = objMesh_->updateMesh( std::move( newMesh ) );
47 if ( oldMesh && objMesh_->mesh() )
48 meshDiff_ = MeshDiff( *objMesh_->mesh(), *oldMesh );
49 }
50 }
51
52 virtual std::string name() const override
53 {
54 return name_;
55 }
56
57 virtual void action( HistoryAction::Type ) override
58 {
59 if ( !objMesh_ )
60 return;
61
62 auto m = objMesh_->varMesh();
63 assert( m );
64 if ( !m )
65 return;
66
67 meshDiff_.applyAndSwap( *m );
68 objMesh_->setDirtyFlags( DIRTY_ALL );
69 }
70
71 [[nodiscard]] virtual size_t heapBytes() const override
72 {
73 return name_.capacity() + meshDiff_.heapBytes();
74 }
75
76private:
77 std::shared_ptr<ObjectMesh> objMesh_;
78 MeshDiff meshDiff_;
79
80 std::string name_;
81};
82
85{
86public:
89 PartialChangeMeshPointsAction( std::string name, std::shared_ptr<ObjectMesh> obj, CmpOld, const VertCoords& oldPoints ) :
90 objMesh_{ std::move( obj ) },
91 name_{ std::move( name ) }
92 {
93 assert( objMesh_ );
94 if ( !objMesh_ )
95 return;
96
97 if ( auto m = objMesh_->varMesh() )
98 pointsDiff_ = VertCoordsDiff( m->points, oldPoints );
99 }
100
102 PartialChangeMeshPointsAction( std::string name, std::shared_ptr<ObjectMesh> obj, SetNew, VertCoords&& newPoints ) :
103 objMesh_{ std::move( obj ) },
104 name_{ std::move( name ) }
105 {
106 assert( objMesh_ );
107 if ( !objMesh_ )
108 return;
109
110 if ( auto m = objMesh_->varMesh() )
111 {
112 pointsDiff_ = VertCoordsDiff( newPoints, m->points );
113 m->points = std::move( newPoints );
114 objMesh_->setDirtyFlags( DIRTY_POSITION );
115 }
116 }
117
118 virtual std::string name() const override
119 {
120 return name_;
121 }
122
123 virtual void action( HistoryAction::Type ) override
124 {
125 if ( !objMesh_ )
126 return;
127
128 auto m = objMesh_->varMesh();
129 assert( m );
130 if ( !m )
131 return;
132
133 pointsDiff_.applyAndSwap( m->points );
134 objMesh_->setDirtyFlags( DIRTY_POSITION );
135 }
136
137 [[nodiscard]] virtual size_t heapBytes() const override
138 {
139 return name_.capacity() + pointsDiff_.heapBytes();
140 }
141
142private:
143 std::shared_ptr<ObjectMesh> objMesh_;
144 VertCoordsDiff pointsDiff_;
145
146 std::string name_;
147};
148
151{
152public:
155 PartialChangeMeshTopologyAction( std::string name, std::shared_ptr<ObjectMesh> obj, CmpOld, const MeshTopology& oldTopology ) :
156 objMesh_{ std::move( obj ) },
157 name_{ std::move( name ) }
158 {
159 assert( objMesh_ );
160 if ( !objMesh_ )
161 return;
162
163 if ( auto m = objMesh_->varMesh() )
164 topologyDiff_ = MeshTopologyDiff( m->topology, oldTopology );
165 }
166
168 PartialChangeMeshTopologyAction( std::string name, std::shared_ptr<ObjectMesh> obj, SetNew, MeshTopology&& newTopology ) :
169 objMesh_{ std::move( obj ) },
170 name_{ std::move( name ) }
171 {
172 assert( objMesh_ );
173 if ( !objMesh_ )
174 return;
175
176 if ( auto m = objMesh_->varMesh() )
177 {
178 topologyDiff_ = MeshTopologyDiff( newTopology, m->topology );
179 m->topology = std::move( newTopology );
180 objMesh_->setDirtyFlags( DIRTY_FACE );
181 }
182 }
183
184 virtual std::string name() const override
185 {
186 return name_;
187 }
188
189 virtual void action( HistoryAction::Type ) override
190 {
191 if ( !objMesh_ )
192 return;
193
194 auto m = objMesh_->varMesh();
195 assert( m );
196 if ( !m )
197 return;
198
199 topologyDiff_.applyAndSwap( m->topology );
200 objMesh_->setDirtyFlags( DIRTY_FACE );
201 }
202
203 [[nodiscard]] virtual size_t heapBytes() const override
204 {
205 return name_.capacity() + topologyDiff_.heapBytes();
206 }
207
208private:
209 std::shared_ptr<ObjectMesh> objMesh_;
210 MeshTopologyDiff topologyDiff_;
211
212 std::string name_;
213};
214
216
217} // namespace MR
Definition MRHistoryAction.h:12
Type
Definition MRHistoryAction.h:19
Definition MRMeshDiff.h:13
MRMESH_API void applyAndSwap(Mesh &m)
size_t heapBytes() const
returns the amount of memory this object occupies on heap
Definition MRMeshDiff.h:31
Definition MRMeshTopologyDiff.h:13
MRMESH_API size_t heapBytes() const
returns the amount of memory this object occupies on heap
MRMESH_API void applyAndSwap(MeshTopology &t)
Definition MRMesh/MRMeshTopology.h:19
Undo action for efficiently storage of partial change in mesh (e.g. a modification of small region)
Definition MRPartialChangeMeshAction.h:25
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRPartialChangeMeshAction.h:71
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRPartialChangeMeshAction.h:57
PartialChangeMeshAction(std::string name, std::shared_ptr< ObjectMesh > obj, CmpOld, const Mesh &oldMesh)
Definition MRPartialChangeMeshAction.h:29
virtual std::string name() const override
Definition MRPartialChangeMeshAction.h:52
PartialChangeMeshAction(std::string name, std::shared_ptr< ObjectMesh > obj, SetNew, std::shared_ptr< Mesh > &&newMesh)
use this constructor to set new object's mesh and remember its difference from existed mesh for futur...
Definition MRPartialChangeMeshAction.h:39
Undo action for efficiently storage of partial change in mesh points (e.g. a modification of small re...
Definition MRPartialChangeMeshAction.h:85
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRPartialChangeMeshAction.h:137
virtual std::string name() const override
Definition MRPartialChangeMeshAction.h:118
PartialChangeMeshPointsAction(std::string name, std::shared_ptr< ObjectMesh > obj, CmpOld, const VertCoords &oldPoints)
Definition MRPartialChangeMeshAction.h:89
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRPartialChangeMeshAction.h:123
PartialChangeMeshPointsAction(std::string name, std::shared_ptr< ObjectMesh > obj, SetNew, VertCoords &&newPoints)
use this constructor to set new object's points and remember its difference from existed points for f...
Definition MRPartialChangeMeshAction.h:102
Undo action for efficiently storage of partial change in mesh topology (e.g. a modification of small ...
Definition MRPartialChangeMeshAction.h:151
PartialChangeMeshTopologyAction(std::string name, std::shared_ptr< ObjectMesh > obj, SetNew, MeshTopology &&newTopology)
use this constructor to set new object's topology and remember its difference from existed topology f...
Definition MRPartialChangeMeshAction.h:168
PartialChangeMeshTopologyAction(std::string name, std::shared_ptr< ObjectMesh > obj, CmpOld, const MeshTopology &oldTopology)
Definition MRPartialChangeMeshAction.h:155
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRPartialChangeMeshAction.h:203
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRPartialChangeMeshAction.h:189
virtual std::string name() const override
Definition MRPartialChangeMeshAction.h:184
Definition MRVertCoordsDiff.h:12
MRMESH_API size_t heapBytes() const
returns the amount of memory this object occupies on heap
MRMESH_API void applyAndSwap(VertCoords &m)
constexpr SetNew setNew
Definition MRPartialChangeMeshAction.h:21
constexpr CmpOld cmpOld
Definition MRPartialChangeMeshAction.h:17
@ DIRTY_POSITION
Definition MRVisualObject.h:77
@ DIRTY_FACE
Definition MRVisualObject.h:86
@ DIRTY_ALL
Definition MRVisualObject.h:97
Definition MRCameraOrientationPlugin.h:8
argument of this type indicates that the object is already in new state, and the following argument i...
Definition MRPartialChangeMeshAction.h:16
Definition MRMesh/MRMesh.h:23
argument of this type indicates that the object is in old state, and the following argument is new st...
Definition MRPartialChangeMeshAction.h:20