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
14class ChangePointCloudNormalsAction : public HistoryAction
15{
16public:
17 using Obj = ObjectPoints;
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 {
37 action( HistoryAction::Type::Redo );
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
74class ChangeOneNormalInCloudAction : public HistoryAction
75{
76public:
77 using Obj = ObjectPoints;
78
80 ChangeOneNormalInCloudAction( std::string name, const std::shared_ptr<ObjectPoints>& obj, VertId pointId ) :
81 objPoints_{ obj },
82 pointId_{ pointId },
83 name_{ std::move( name ) }
84 {
85 if ( obj )
86 {
87 if ( auto m = obj->pointCloud() )
88 if ( m->normals.size() > pointId_ )
89 safeNormal_ = m->normals[pointId_];
90 }
91 }
92
94 ChangeOneNormalInCloudAction( std::string name, const std::shared_ptr<ObjectPoints>& obj, VertId pointId, const Vector3f & newNormal ) :
95 objPoints_{ obj },
96 pointId_{ pointId },
97 safeNormal_{ newNormal },
98 name_{ std::move( name ) }
99 {
100 action( HistoryAction::Type::Redo );
101 }
102
103 virtual std::string name() const override
104 {
105 return name_;
106 }
107
108 virtual void action( HistoryAction::Type ) override
109 {
110 if ( !objPoints_ )
111 return;
112
113 if ( auto m = objPoints_->varPointCloud() )
114 {
115 if ( m->normals.size() > pointId_ )
116 {
117 std::swap( safeNormal_, m->normals[pointId_] );
118 objPoints_->setDirtyFlags( DIRTY_RENDER_NORMALS );
119 }
120 }
121 }
122
123 static void setObjectDirty( const std::shared_ptr<ObjectPoints>& obj )
124 {
125 if ( obj )
126 obj->setDirtyFlags( DIRTY_RENDER_NORMALS );
127 }
128
129 [[nodiscard]] virtual size_t heapBytes() const override
130 {
131 return name_.capacity();
132 }
133
134private:
135 std::shared_ptr<ObjectPoints> objPoints_;
136 VertId pointId_;
137 Vector3f safeNormal_;
138
139 std::string name_;
140};
141
142} //namespace MR
unsafe ChangeOneNormalInCloudAction(MR._ByValue_ChangeOneNormalInCloudAction _other)
unsafe void action(MR.HistoryAction.Type _1)
unsafe void action(MR.HistoryAction.Type _1)
unsafe ChangePointCloudNormalsAction(MR._ByValue_ChangePointCloudNormalsAction _other)
std::string name(const T &primitive)
Definition MRFeatures.h:309
Definition MRCameraOrientationPlugin.h:8