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
14class ChangePointCloudAction : public HistoryAction
15{
16public:
17 using Obj = ObjectPoints;
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
59class ChangePointCloudPointsAction : public HistoryAction
60{
61public:
62 using Obj = ObjectPoints;
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 {
82 action( HistoryAction::Type::Redo );
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
122class ChangeOnePointInCloudAction : public HistoryAction
123{
124public:
125 using Obj = ObjectPoints;
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 {
148 action( HistoryAction::Type::Redo );
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
unsafe ChangeOnePointInCloudAction(MR._ByValue_ChangeOnePointInCloudAction _other)
unsafe void action(MR.HistoryAction.Type _1)
unsafe void action(MR.HistoryAction.Type _1)
unsafe ChangePointCloudAction(MR._ByValue_ChangePointCloudAction _other)
unsafe ChangePointCloudPointsAction(MR._ByValue_ChangePointCloudPointsAction _other)
unsafe void action(MR.HistoryAction.Type _1)
size_t heapBytes(const BitSet &bs)
returns the amount of memory given BitSet occupies on heap
Definition MRMesh/MRBitSet.h:298
std::string name(const T &primitive)
Definition MRFeatures.h:309
Definition MRCameraOrientationPlugin.h:8