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