MeshLib Documentation
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
76 virtual std::string name() const override
77 {
78 return name_;
79 }
80
81 virtual void action( HistoryAction::Type ) override
82 {
83 if ( !objPoints_ )
84 return;
85
86 if ( auto m = objPoints_->varPointCloud() )
87 {
88 std::swap( m->points, clonePoints_ );
89 objPoints_->setDirtyFlags( DIRTY_POSITION );
90 }
91 }
92
93 static void setObjectDirty( const std::shared_ptr<ObjectPoints>& obj )
94 {
95 if ( obj )
96 obj->setDirtyFlags( DIRTY_POSITION );
97 }
98
99 [[nodiscard]] virtual size_t heapBytes() const override
100 {
101 return name_.capacity() + clonePoints_.heapBytes();
102 }
103
104private:
105 std::shared_ptr<ObjectPoints> objPoints_;
106 VertCoords clonePoints_;
107
108 std::string name_;
109};
110
111}
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:93
ChangePointCloudPointsAction(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:65
virtual std::string name() const override
Definition MRChangePointCloudAction.h:76
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangePointCloudAction.h:99
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangePointCloudAction.h:81
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
Definition MRCameraOrientationPlugin.h:8