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 "MRObjectMesh.h"
5#include "MRMeshDiff.h"
6#include <cassert>
7
8namespace MR
9{
10
13
15struct CmpOld {};
16inline constexpr CmpOld cmpOld;
17
19struct SetNew {};
20inline constexpr SetNew setNew;
21
24{
25public:
28 PartialChangeMeshAction( std::string name, std::shared_ptr<ObjectMesh> obj, CmpOld, const Mesh &oldMesh ) :
29 objMesh_{ std::move( obj ) },
30 name_{ std::move( name ) }
31 {
32 assert( objMesh_ );
33 if ( objMesh_ && objMesh_->mesh() )
34 meshDiff_ = MeshDiff( *objMesh_->mesh(), oldMesh );
35 }
36
38 PartialChangeMeshAction( std::string name, std::shared_ptr<ObjectMesh> obj, SetNew, std::shared_ptr<Mesh>&& newMesh ) :
39 objMesh_{ std::move( obj ) },
40 name_{ std::move( name ) }
41 {
42 assert( objMesh_ && newMesh );
43 if ( objMesh_ )
44 {
45 auto oldMesh = objMesh_->updateMesh( std::move( newMesh ) );
46 if ( oldMesh && objMesh_->mesh() )
47 meshDiff_ = MeshDiff( *objMesh_->mesh(), *oldMesh );
48 }
49 }
50
51 virtual std::string name() const override
52 {
53 return name_;
54 }
55
56 virtual void action( HistoryAction::Type ) override
57 {
58 if ( !objMesh_ )
59 return;
60
61 auto m = objMesh_->varMesh();
62 assert( m );
63 if ( !m )
64 return;
65
66 meshDiff_.applyAndSwap( *m );
67 objMesh_->setDirtyFlags( DIRTY_ALL );
68 }
69
70 [[nodiscard]] virtual size_t heapBytes() const override
71 {
72 return name_.capacity() + meshDiff_.heapBytes();
73 }
74
75private:
76 std::shared_ptr<ObjectMesh> objMesh_;
77 MeshDiff meshDiff_;
78
79 std::string name_;
80};
81
84{
85public:
88 PartialChangeMeshPointsAction( std::string name, std::shared_ptr<ObjectMesh> obj, CmpOld, const VertCoords& oldPoints ) :
89 objMesh_{ std::move( obj ) },
90 name_{ std::move( name ) }
91 {
92 assert( objMesh_ );
93 if ( !objMesh_ )
94 return;
95
96 if ( auto m = objMesh_->varMesh() )
97 pointsDiff_ = VertCoordsDiff( m->points, oldPoints );
98 }
99
101 PartialChangeMeshPointsAction( std::string name, std::shared_ptr<ObjectMesh> obj, SetNew, VertCoords&& newPoints ) :
102 objMesh_{ std::move( obj ) },
103 name_{ std::move( name ) }
104 {
105 assert( objMesh_ );
106 if ( !objMesh_ )
107 return;
108
109 if ( auto m = objMesh_->varMesh() )
110 {
111 pointsDiff_ = VertCoordsDiff( newPoints, m->points );
112 m->points = std::move( newPoints );
113 objMesh_->setDirtyFlags( DIRTY_POSITION );
114 }
115 }
116
117 virtual std::string name() const override
118 {
119 return name_;
120 }
121
122 virtual void action( HistoryAction::Type ) override
123 {
124 if ( !objMesh_ )
125 return;
126
127 auto m = objMesh_->varMesh();
128 assert( m );
129 if ( !m )
130 return;
131
132 pointsDiff_.applyAndSwap( m->points );
133 objMesh_->setDirtyFlags( DIRTY_POSITION );
134 }
135
136 [[nodiscard]] virtual size_t heapBytes() const override
137 {
138 return name_.capacity() + pointsDiff_.heapBytes();
139 }
140
141private:
142 std::shared_ptr<ObjectMesh> objMesh_;
143 VertCoordsDiff pointsDiff_;
144
145 std::string name_;
146};
147
150{
151public:
154 PartialChangeMeshTopologyAction( std::string name, std::shared_ptr<ObjectMesh> obj, CmpOld, const MeshTopology& oldTopology ) :
155 objMesh_{ std::move( obj ) },
156 name_{ std::move( name ) }
157 {
158 assert( objMesh_ );
159 if ( !objMesh_ )
160 return;
161
162 if ( auto m = objMesh_->varMesh() )
163 topologyDiff_ = MeshTopologyDiff( m->topology, oldTopology );
164 }
165
167 PartialChangeMeshTopologyAction( std::string name, std::shared_ptr<ObjectMesh> obj, SetNew, MeshTopology&& newTopology ) :
168 objMesh_{ std::move( obj ) },
169 name_{ std::move( name ) }
170 {
171 assert( objMesh_ );
172 if ( !objMesh_ )
173 return;
174
175 if ( auto m = objMesh_->varMesh() )
176 {
177 topologyDiff_ = MeshTopologyDiff( newTopology, m->topology );
178 m->topology = std::move( newTopology );
179 objMesh_->setDirtyFlags( DIRTY_FACE );
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 ( !objMesh_ )
191 return;
192
193 auto m = objMesh_->varMesh();
194 assert( m );
195 if ( !m )
196 return;
197
198 topologyDiff_.applyAndSwap( m->topology );
199 objMesh_->setDirtyFlags( DIRTY_FACE );
200 }
201
202 [[nodiscard]] virtual size_t heapBytes() const override
203 {
204 return name_.capacity() + topologyDiff_.heapBytes();
205 }
206
207private:
208 std::shared_ptr<ObjectMesh> objMesh_;
209 MeshTopologyDiff topologyDiff_;
210
211 std::string name_;
212};
213
215
216} // 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:18
Undo action for efficiently storage of partial change in mesh (e.g. a modification of small region)
Definition MRPartialChangeMeshAction.h:24
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRPartialChangeMeshAction.h:70
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRPartialChangeMeshAction.h:56
PartialChangeMeshAction(std::string name, std::shared_ptr< ObjectMesh > obj, CmpOld, const Mesh &oldMesh)
Definition MRPartialChangeMeshAction.h:28
virtual std::string name() const override
Definition MRPartialChangeMeshAction.h:51
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:38
Undo action for efficiently storage of partial change in mesh points (e.g. a modification of small re...
Definition MRPartialChangeMeshAction.h:84
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRPartialChangeMeshAction.h:136
virtual std::string name() const override
Definition MRPartialChangeMeshAction.h:117
PartialChangeMeshPointsAction(std::string name, std::shared_ptr< ObjectMesh > obj, CmpOld, const VertCoords &oldPoints)
Definition MRPartialChangeMeshAction.h:88
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRPartialChangeMeshAction.h:122
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:101
Undo action for efficiently storage of partial change in mesh topology (e.g. a modification of small ...
Definition MRPartialChangeMeshAction.h:150
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:167
PartialChangeMeshTopologyAction(std::string name, std::shared_ptr< ObjectMesh > obj, CmpOld, const MeshTopology &oldTopology)
Definition MRPartialChangeMeshAction.h:154
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRPartialChangeMeshAction.h:202
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRPartialChangeMeshAction.h:188
virtual std::string name() const override
Definition MRPartialChangeMeshAction.h:183
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:20
constexpr CmpOld cmpOld
Definition MRPartialChangeMeshAction.h:16
@ DIRTY_POSITION
Definition MRVisualObject.h:90
@ DIRTY_FACE
Definition MRVisualObject.h:99
@ DIRTY_ALL
Definition MRVisualObject.h:109
argument of this type indicates that the object is already in new state, and the following argument i...
Definition MRPartialChangeMeshAction.h:15
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:19