MeshLib Documentation
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
31 virtual std::string name() const override
32 {
33 return name_;
34 }
35
36 virtual void action( HistoryAction::Type ) override
37 {
38 if ( !objPoints_ || !objPoints_->varPointCloud() )
39 return;
40
41 std::swap( objPoints_->varPointCloud()->normals, backupNormals_ );
42 setObjectDirty( objPoints_ );
43 }
44
45 static void setObjectDirty( const std::shared_ptr<ObjectPoints>& obj )
46 {
47 if ( obj )
48 obj->setDirtyFlags( DIRTY_RENDER_NORMALS );
49 }
50
51 [[nodiscard]] virtual size_t heapBytes() const override
52 {
53 return name_.capacity() + backupNormals_.heapBytes();
54 }
55
56private:
57 std::shared_ptr<ObjectPoints> objPoints_;
58 VertCoords backupNormals_;
59
60 std::string name_;
61};
62
63}
Definition MRChangePointCloudNormalsAction.h:15
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangePointCloudNormalsAction.h:51
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangePointCloudNormalsAction.h:36
static void setObjectDirty(const std::shared_ptr< ObjectPoints > &obj)
Definition MRChangePointCloudNormalsAction.h:45
ChangePointCloudNormalsAction(std::string name, const std::shared_ptr< ObjectPoints > &obj)
use this constructor to remember point cloud's normals before making any changes in it
Definition MRChangePointCloudNormalsAction.h:20
virtual std::string name() const override
Definition MRChangePointCloudNormalsAction.h:31
Definition MRHistoryAction.h:12
Type
Definition MRHistoryAction.h:19
Definition MRObjectPoints.h:11
@ DIRTY_RENDER_NORMALS
Definition MRVisualObject.h:95
Definition MRCameraOrientationPlugin.h:8