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->pointCloud() )
30 clonePointCloud_ = std::make_shared<PointCloud>( *m );
31 }
32 }
33
34 virtual std::string name() const override { return name_; }
35
36 virtual void action( HistoryAction::Type ) override
37 {
38 if ( !objPoints_ )
39 return;
40
41 objPoints_->swapPointCloud( clonePointCloud_ );
42 }
43
44 static void setObjectDirty( const std::shared_ptr<ObjectPoints>& obj )
45 {
46 if ( obj )
47 obj->setDirtyFlags( DIRTY_ALL );
48 }
49
50 [[nodiscard]] virtual size_t heapBytes() const override
51 { return name_.capacity() + MR::heapBytes( clonePointCloud_ ); }
52
53private:
54 std::shared_ptr<ObjectPoints> objPoints_;
55 std::shared_ptr<PointCloud> clonePointCloud_;
56
57 std::string name_;
58};
59
63{
64public:
66
68 ChangePointCloudPointsAction( std::string name, const std::shared_ptr<ObjectPoints>& obj ) :
69 objPoints_{ obj },
70 name_{ std::move( name ) }
71 {
72 if ( obj )
73 {
74 if ( auto m = obj->pointCloud() )
75 clonePoints_ = m->points;
76 }
77 }
78
80 ChangePointCloudPointsAction( std::string name, const std::shared_ptr<ObjectPoints>& obj, VertCoords && newPoints ) :
81 objPoints_{ obj },
82 clonePoints_{ std::move( newPoints ) },
83 name_{ std::move( name ) }
84 {
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 ( !objPoints_ )
96 return;
97
98 if ( auto m = objPoints_->varPointCloud() )
99 {
100 std::swap( m->points, clonePoints_ );
101 objPoints_->setDirtyFlags( DIRTY_POSITION );
102 }
103 }
104
105 static void setObjectDirty( const std::shared_ptr<ObjectPoints>& obj )
106 {
107 if ( obj )
108 obj->setDirtyFlags( DIRTY_POSITION );
109 }
110
111 [[nodiscard]] virtual size_t heapBytes() const override
112 {
113 return name_.capacity() + clonePoints_.heapBytes();
114 }
115
116private:
117 std::shared_ptr<ObjectPoints> objPoints_;
118 VertCoords clonePoints_;
119
120 std::string name_;
121};
122
126{
127public:
129
131 ChangeOnePointInCloudAction( std::string name, const std::shared_ptr<ObjectPoints>& obj, VertId pointId ) :
132 objPoints_{ obj },
133 pointId_{ pointId },
134 name_{ std::move( name ) }
135 {
136 if ( obj )
137 {
138 if ( auto m = obj->pointCloud() )
139 if ( m->points.size() > pointId_ )
140 safeCoords_ = m->points[pointId_];
141 }
142 }
143
145 ChangeOnePointInCloudAction( std::string name, const std::shared_ptr<ObjectPoints>& obj, VertId pointId, const Vector3f & newCoords ) :
146 objPoints_{ obj },
147 pointId_{ pointId },
148 safeCoords_{ newCoords },
149 name_{ std::move( name ) }
150 {
152 }
153
154 virtual std::string name() const override
155 {
156 return name_;
157 }
158
159 virtual void action( HistoryAction::Type ) override
160 {
161 if ( !objPoints_ )
162 return;
163
164 if ( auto m = objPoints_->varPointCloud() )
165 {
166 if ( m->points.size() > pointId_ )
167 {
168 std::swap( safeCoords_, m->points[pointId_] );
169 objPoints_->setDirtyFlags( DIRTY_POSITION );
170 }
171 }
172 }
173
174 static void setObjectDirty( const std::shared_ptr<ObjectPoints>& obj )
175 {
176 if ( obj )
177 obj->setDirtyFlags( DIRTY_POSITION );
178 }
179
180 [[nodiscard]] virtual size_t heapBytes() const override
181 {
182 return name_.capacity();
183 }
184
185private:
186 std::shared_ptr<ObjectPoints> objPoints_;
187 VertId pointId_;
188 Vector3f safeCoords_;
189
190 std::string name_;
191};
192
193}
Definition MRChangePointCloudAction.h:126
Definition MRChangePointCloudAction.h:18
Definition MRChangePointCloudAction.h:63
Definition MRHistoryAction.h:15
Definition MRObjectPoints.h:14
size_t heapBytes(const BitSet &bs)
returns the amount of memory given BitSet occupies on heap
Definition MRBitSet.h:313
static void setObjectDirty(const std::shared_ptr< ObjectPoints > &obj)
Definition MRChangePointCloudAction.h:105
virtual std::string name() const override
Definition MRChangePointCloudAction.h:154
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:131
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:34
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangePointCloudAction.h:36
static void setObjectDirty(const std::shared_ptr< ObjectPoints > &obj)
Definition MRChangePointCloudAction.h:174
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:145
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:68
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangePointCloudAction.h:180
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:80
virtual std::string name() const override
Definition MRChangePointCloudAction.h:88
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangePointCloudAction.h:111
Type
Definition MRHistoryAction.h:22
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangePointCloudAction.h:93
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangePointCloudAction.h:159
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangePointCloudAction.h:50
static void setObjectDirty(const std::shared_ptr< ObjectPoints > &obj)
Definition MRChangePointCloudAction.h:44
@ DIRTY_POSITION
Definition MRVisualObject.h:77
@ DIRTY_ALL
Definition MRVisualObject.h:94
only for bindings generation
Definition MRCameraOrientationPlugin.h:8