MeshLib C++ Docs
Loading...
Searching...
No Matches
MRChangePointCloudNormalsAction.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 ChangePointCloudNormalsAction( 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 pc = obj->pointCloud() )
27 backupNormals_ = pc->normals;
28 }
29 }
30
32 ChangePointCloudNormalsAction( std::string name, const std::shared_ptr<ObjectPoints>& obj, VertNormals && newNormals ) :
33 objPoints_{ obj },
34 backupNormals_{ std::move( newNormals ) },
35 name_{ std::move( name ) }
36 {
38 }
39
40 virtual std::string name() const override
41 {
42 return name_;
43 }
44
45 virtual void action( HistoryAction::Type ) override
46 {
47 if ( !objPoints_ || !objPoints_->varPointCloud() )
48 return;
49
50 std::swap( objPoints_->varPointCloud()->normals, backupNormals_ );
51 setObjectDirty( objPoints_ );
52 }
53
54 static void setObjectDirty( const std::shared_ptr<ObjectPoints>& obj )
55 {
56 if ( obj )
57 obj->setDirtyFlags( DIRTY_RENDER_NORMALS );
58 }
59
60 [[nodiscard]] virtual size_t heapBytes() const override
61 {
62 return name_.capacity() + backupNormals_.heapBytes();
63 }
64
65private:
66 std::shared_ptr<ObjectPoints> objPoints_;
67 VertNormals backupNormals_;
68
69 std::string name_;
70};
71
72}
Definition MRChangePointCloudNormalsAction.h:15
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangePointCloudNormalsAction.h:60
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangePointCloudNormalsAction.h:45
ChangePointCloudNormalsAction(std::string name, const std::shared_ptr< ObjectPoints > &obj, VertNormals &&newNormals)
use this constructor to remember point cloud's normals and immediate set new value
Definition MRChangePointCloudNormalsAction.h:32
static void setObjectDirty(const std::shared_ptr< ObjectPoints > &obj)
Definition MRChangePointCloudNormalsAction.h:54
ChangePointCloudNormalsAction(std::string name, const std::shared_ptr< ObjectPoints > &obj)
use this constructor to remember point cloud's normals before making any changes in them
Definition MRChangePointCloudNormalsAction.h:20
virtual std::string name() const override
Definition MRChangePointCloudNormalsAction.h:40
Definition MRHistoryAction.h:12
Type
Definition MRHistoryAction.h:19
Definition MRObjectPoints.h:11
@ DIRTY_RENDER_NORMALS
Definition MRVisualObject.h:95