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 "MRHeapBytes.h"
8#include <cassert>
9
10namespace MR
11{
12
15
17struct CmpOld {};
18inline constexpr CmpOld cmpOld;
19
21struct SetNew {};
22inline constexpr SetNew setNew;
23
26{
27public:
30 PartialChangeMeshAction( std::string name, std::shared_ptr<ObjectMesh> obj, CmpOld, const Mesh &oldMesh ) :
31 objMesh_{ std::move( obj ) },
32 name_{ std::move( name ) }
33 {
34 assert( objMesh_ );
35 if ( objMesh_ && objMesh_->meshPtr() )
36 meshDiff_ = MeshDiff( *objMesh_->meshPtr(), oldMesh );
37 }
38
40 PartialChangeMeshAction( std::string name, std::shared_ptr<ObjectMesh> obj, SetNew, std::shared_ptr<Mesh>&& newMesh ) :
41 objMesh_{ std::move( obj ) },
42 name_{ std::move( name ) }
43 {
44 assert( objMesh_ && newMesh );
45 if ( objMesh_ )
46 {
47 auto oldMesh = objMesh_->updateMesh( std::move( newMesh ) );
48 if ( oldMesh && objMesh_->meshPtr() )
49 meshDiff_ = MeshDiff( *objMesh_->meshPtr(), *oldMesh );
50 }
51 }
52
53 virtual std::string name() const override
54 {
55 return name_;
56 }
57
58 virtual void action( HistoryAction::Type ) override
59 {
60 if ( !objMesh_ )
61 return;
62
63 auto m = objMesh_->varMesh();
64 assert( m );
65 if ( !m )
66 return;
67
68 meshDiff_.applyAndSwap( *m );
69 objMesh_->setDirtyFlags( DIRTY_ALL );
70 }
71
72 [[nodiscard]] virtual size_t heapBytes() const override
73 {
74 return name_.capacity() + meshDiff_.heapBytes();
75 }
76
77private:
78 std::shared_ptr<ObjectMesh> objMesh_;
79 MeshDiff meshDiff_;
80
81 std::string name_;
82};
83
86{
87public:
90 PartialChangeMeshPointsAction( std::string name, std::shared_ptr<ObjectMesh> obj, CmpOld, const VertCoords& oldPoints ) :
91 objMesh_{ std::move( obj ) },
92 name_{ std::move( name ) }
93 {
94 assert( objMesh_ );
95 if ( !objMesh_ )
96 return;
97
98 if ( auto m = objMesh_->varMesh() )
99 pointsDiff_ = VertCoordsDiff( m->points, oldPoints );
100 }
101
103 PartialChangeMeshPointsAction( std::string name, std::shared_ptr<ObjectMesh> obj, SetNew, VertCoords&& newPoints ) :
104 objMesh_{ std::move( obj ) },
105 name_{ std::move( name ) }
106 {
107 assert( objMesh_ );
108 if ( !objMesh_ )
109 return;
110
111 if ( auto m = objMesh_->varMesh() )
112 {
113 pointsDiff_ = VertCoordsDiff( newPoints, m->points );
114 m->points = std::move( newPoints );
115 objMesh_->setDirtyFlags( DIRTY_POSITION );
116 }
117 }
118
119 virtual std::string name() const override
120 {
121 return name_;
122 }
123
124 virtual void action( HistoryAction::Type ) override
125 {
126 if ( !objMesh_ )
127 return;
128
129 auto m = objMesh_->varMesh();
130 assert( m );
131 if ( !m )
132 return;
133
134 pointsDiff_.applyAndSwap( m->points );
135 objMesh_->setDirtyFlags( DIRTY_POSITION );
136 }
137
138 [[nodiscard]] virtual size_t heapBytes() const override
139 {
140 return name_.capacity() + pointsDiff_.heapBytes();
141 }
142
143private:
144 std::shared_ptr<ObjectMesh> objMesh_;
145 VertCoordsDiff pointsDiff_;
146
147 std::string name_;
148};
149
152{
153public:
156 PartialChangeMeshTopologyAction( std::string name, std::shared_ptr<ObjectMesh> obj, CmpOld, const MeshTopology& oldTopology ) :
157 objMesh_{ std::move( obj ) },
158 name_{ std::move( name ) }
159 {
160 assert( objMesh_ );
161 if ( !objMesh_ )
162 return;
163
164 if ( auto m = objMesh_->varMesh() )
165 topologyDiff_ = MeshTopologyDiff( m->topology, oldTopology );
166 }
167
169 PartialChangeMeshTopologyAction( std::string name, std::shared_ptr<ObjectMesh> obj, SetNew, MeshTopology&& newTopology ) :
170 objMesh_{ std::move( obj ) },
171 name_{ std::move( name ) }
172 {
173 assert( objMesh_ );
174 if ( !objMesh_ )
175 return;
176
177 if ( auto m = objMesh_->varMesh() )
178 {
179 topologyDiff_ = MeshTopologyDiff( newTopology, m->topology );
180 m->topology = std::move( newTopology );
181 objMesh_->setDirtyFlags( DIRTY_FACE );
182 }
183 }
184
185 virtual std::string name() const override
186 {
187 return name_;
188 }
189
190 virtual void action( HistoryAction::Type ) override
191 {
192 if ( !objMesh_ )
193 return;
194
195 auto m = objMesh_->varMesh();
196 assert( m );
197 if ( !m )
198 return;
199
200 topologyDiff_.applyAndSwap( m->topology );
201 objMesh_->setDirtyFlags( DIRTY_FACE );
202 }
203
204 [[nodiscard]] virtual size_t heapBytes() const override
205 {
206 return name_.capacity() + topologyDiff_.heapBytes();
207 }
208
209private:
210 std::shared_ptr<ObjectMesh> objMesh_;
211 MeshTopologyDiff topologyDiff_;
212
213 std::string name_;
214};
215
217
218}
Definition MRMeshDiff.h:16
Definition MRMeshTopologyDiff.h:16
Definition MRMeshTopology.h:30
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRPartialChangeMeshAction.h:72
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRPartialChangeMeshAction.h:58
PartialChangeMeshAction(std::string name, std::shared_ptr< ObjectMesh > obj, CmpOld, const Mesh &oldMesh)
Definition MRPartialChangeMeshAction.h:30
virtual std::string name() const override
Definition MRPartialChangeMeshAction.h:53
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:40
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRPartialChangeMeshAction.h:138
virtual std::string name() const override
Definition MRPartialChangeMeshAction.h:119
PartialChangeMeshPointsAction(std::string name, std::shared_ptr< ObjectMesh > obj, CmpOld, const VertCoords &oldPoints)
Definition MRPartialChangeMeshAction.h:90
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRPartialChangeMeshAction.h:124
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:103
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:169
PartialChangeMeshTopologyAction(std::string name, std::shared_ptr< ObjectMesh > obj, CmpOld, const MeshTopology &oldTopology)
Definition MRPartialChangeMeshAction.h:156
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRPartialChangeMeshAction.h:204
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRPartialChangeMeshAction.h:190
virtual std::string name() const override
Definition MRPartialChangeMeshAction.h:185
Definition MRVertCoordsDiff.h:15
Type
Definition MRHistoryAction.h:27
HistoryAction()=default
explicitly define ctors to avoid warning C5267: definition of implicit copy constructor is deprecated...
constexpr SetNew setNew
Definition MRPartialChangeMeshAction.h:22
constexpr CmpOld cmpOld
Definition MRPartialChangeMeshAction.h:18
@ DIRTY_POSITION
Definition MRVisualObject.h:77
@ DIRTY_FACE
Definition MRVisualObject.h:85
@ DIRTY_ALL
Definition MRVisualObject.h:94
only for bindings generation
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:17
Definition MRMesh.h:24
argument of this type indicates that the object is in old state, and the following argument is new st...
Definition MRPartialChangeMeshAction.h:21