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
120}
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 std::vector< T > &vec)
returns the amount of memory given vector occupies on heap
Definition MRHeapBytes.h:15
@ DIRTY_POSITION
Definition MRVisualObject.h:90
@ DIRTY_ALL
Definition MRVisualObject.h:109