MeshLib C++ Docs
Loading...
Searching...
No Matches
MRChangePointCloudAction.h
Go to the documentation of this file.
1#pragma once
2#include "MRHistoryAction.h"
3#include "MRObjectPoints.h"
4#include "MRPointCloud.h"
5#include "MRHeapBytes.h"
6#include <memory>
7
8
9namespace MR
10{
13
14
18{
19public:
21
23 ChangePointCloudAction( std::string name, const std::shared_ptr<ObjectPoints>& obj ) :
24 objPoints_{ obj },
25 name_{ std::move( name ) }
26 {
27 if ( obj )
28 {
29 if ( auto m = obj->pointCloudPtr() )
30 clonePointCloud_ = std::make_shared<PointCloud>( *m );
31 }
32 }
33
35 ChangePointCloudAction( std::string name, const std::shared_ptr<ObjectPoints>& obj, std::shared_ptr<PointCloud> newPointCloud ) :
36 objPoints_{ obj },
37 name_{ std::move( name ) }
38 {
39 if ( objPoints_ )
40 {
41 clonePointCloud_ = std::move( newPointCloud );
42 objPoints_->swapPointCloud( clonePointCloud_ );
43 }
44 }
45
46 virtual std::string name() const override { return name_; }
47
48 virtual void action( HistoryAction::Type ) override
49 {
50 if ( !objPoints_ )
51 return;
52
53 objPoints_->swapPointCloud( clonePointCloud_ );
54 }
55
56 static void setObjectDirty( const std::shared_ptr<ObjectPoints>& obj )
57 {
58 if ( obj )
59 obj->setDirtyFlags( DIRTY_ALL );
60 }
61
62 [[nodiscard]] virtual size_t heapBytes() const override
63 { return name_.capacity() + MR::heapBytes( clonePointCloud_ ); }
64
65private:
66 std::shared_ptr<ObjectPoints> objPoints_;
67 std::shared_ptr<PointCloud> clonePointCloud_;
68
69 std::string name_;
70};
71
75{
76public:
78
80 ChangePointCloudPointsAction( std::string name, const std::shared_ptr<ObjectPoints>& obj ) :
81 objPoints_{ obj },
82 name_{ std::move( name ) }
83 {
84 if ( obj )
85 {
86 if ( auto m = obj->pointCloudPtr() )
87 clonePoints_ = m->points;
88 }
89 }
90
92 ChangePointCloudPointsAction( std::string name, const std::shared_ptr<ObjectPoints>& obj, VertCoords && newPoints ) :
93 objPoints_{ obj },
94 clonePoints_{ std::move( newPoints ) },
95 name_{ std::move( name ) }
96 {
98 }
99
100 virtual std::string name() const override
101 {
102 return name_;
103 }
104
105 virtual void action( HistoryAction::Type ) override
106 {
107 if ( !objPoints_ )
108 return;
109
110 if ( auto m = objPoints_->varPointCloud() )
111 {
112 std::swap( m->points, clonePoints_ );
113 objPoints_->setDirtyFlags( DIRTY_POSITION );
114 }
115 }
116
117 static void setObjectDirty( const std::shared_ptr<ObjectPoints>& obj )
118 {
119 if ( obj )
120 obj->setDirtyFlags( DIRTY_POSITION );
121 }
122
123 [[nodiscard]] virtual size_t heapBytes() const override
124 {
125 return name_.capacity() + clonePoints_.heapBytes();
126 }
127
128private:
129 std::shared_ptr<ObjectPoints> objPoints_;
130 VertCoords clonePoints_;
131
132 std::string name_;
133};
134
138{
139public:
141
143 ChangeOnePointInCloudAction( std::string name, const std::shared_ptr<ObjectPoints>& obj, VertId pointId ) :
144 objPoints_{ obj },
145 pointId_{ pointId },
146 name_{ std::move( name ) }
147 {
148 if ( obj )
149 {
150 if ( auto m = obj->pointCloudPtr() )
151 if ( m->points.size() > pointId_ )
152 safeCoords_ = m->points[pointId_];
153 }
154 }
155
157 ChangeOnePointInCloudAction( std::string name, const std::shared_ptr<ObjectPoints>& obj, VertId pointId, const Vector3f & newCoords ) :
158 objPoints_{ obj },
159 pointId_{ pointId },
160 safeCoords_{ newCoords },
161 name_{ std::move( name ) }
162 {
164 }
165
166 virtual std::string name() const override
167 {
168 return name_;
169 }
170
171 virtual void action( HistoryAction::Type ) override
172 {
173 if ( !objPoints_ )
174 return;
175
176 if ( auto m = objPoints_->varPointCloud() )
177 {
178 if ( m->points.size() > pointId_ )
179 {
180 std::swap( safeCoords_, m->points[pointId_] );
181 objPoints_->setDirtyFlags( DIRTY_POSITION );
182 }
183 }
184 }
185
186 static void setObjectDirty( const std::shared_ptr<ObjectPoints>& obj )
187 {
188 if ( obj )
189 obj->setDirtyFlags( DIRTY_POSITION );
190 }
191
192 [[nodiscard]] virtual size_t heapBytes() const override
193 {
194 return name_.capacity();
195 }
196
197private:
198 std::shared_ptr<ObjectPoints> objPoints_;
199 VertId pointId_;
200 Vector3f safeCoords_;
201
202 std::string name_;
203};
204
205}
Definition MRObjectPoints.h:14
size_t heapBytes(const BitSet &bs)
returns the amount of memory given BitSet occupies on heap
Definition MRBitSet.h:377
static void setObjectDirty(const std::shared_ptr< ObjectPoints > &obj)
Definition MRChangePointCloudAction.h:117
virtual std::string name() const override
Definition MRChangePointCloudAction.h:166
ChangeOnePointInCloudAction(std::string name, const std::shared_ptr< ObjectPoints > &obj, VertId pointId)
use this constructor to remember point's coordinates before making any changes in it
Definition MRChangePointCloudAction.h:143
ChangePointCloudAction(std::string name, const std::shared_ptr< ObjectPoints > &obj)
use this constructor to remember object's point cloud before making any changes in it
Definition MRChangePointCloudAction.h:23
virtual std::string name() const override
Definition MRChangePointCloudAction.h:46
ObjectPoints Obj
Definition MRChangePointCloudAction.h:140
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangePointCloudAction.h:48
static void setObjectDirty(const std::shared_ptr< ObjectPoints > &obj)
Definition MRChangePointCloudAction.h:186
ChangeOnePointInCloudAction(std::string name, const std::shared_ptr< ObjectPoints > &obj, VertId pointId, const Vector3f &newCoords)
use this constructor to remember point's coordinates and immediate set new coordinates
Definition MRChangePointCloudAction.h:157
ChangePointCloudPointsAction(std::string name, const std::shared_ptr< ObjectPoints > &obj)
use this constructor to remember object's points field before making any changes in it
Definition MRChangePointCloudAction.h:80
ObjectPoints Obj
Definition MRChangePointCloudAction.h:20
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangePointCloudAction.h:192
ChangePointCloudPointsAction(std::string name, const std::shared_ptr< ObjectPoints > &obj, VertCoords &&newPoints)
use this constructor to remember object's points field and immediate set new value
Definition MRChangePointCloudAction.h:92
ChangePointCloudAction(std::string name, const std::shared_ptr< ObjectPoints > &obj, std::shared_ptr< PointCloud > newPointCloud)
use this constructor to remember object's point cloud and immediately set new point cloud
Definition MRChangePointCloudAction.h:35
ObjectPoints Obj
Definition MRChangePointCloudAction.h:77
virtual std::string name() const override
Definition MRChangePointCloudAction.h:100
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangePointCloudAction.h:123
Type
Definition MRHistoryAction.h:27
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangePointCloudAction.h:105
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangePointCloudAction.h:171
HistoryAction()=default
explicitly define ctors to avoid warning C5267: definition of implicit copy constructor is deprecated...
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangePointCloudAction.h:62
static void setObjectDirty(const std::shared_ptr< ObjectPoints > &obj)
Definition MRChangePointCloudAction.h:56
@ Redo
Definition MRHistoryAction.h:29
@ DIRTY_POSITION
Definition MRVisualObject.h:77
@ DIRTY_ALL
Definition MRVisualObject.h:94
only for bindings generation
Definition MRCameraOrientationPlugin.h:8