MeshLib C++ Docs
Loading...
Searching...
No Matches
MRSurfaceManipulationWidget.h
Go to the documentation of this file.
1#pragma once
2#include "MRViewerFwd.h"
4#include "MRMesh/MRMeshFwd.h"
5#include "MRMesh/MREnums.h"
6#include "MRMesh/MRBitSet.h"
8#include <chrono>
9
10namespace MR
11{
12
18class MRVIEWER_CLASS SurfaceManipulationWidget :
19 public MultiListener<MouseDownListener, MouseMoveListener, MouseUpListener,
20 PostDrawListener>
21{
22public:
25
27 enum class WorkMode
28 {
29 Add,
30 Remove,
31 Relax,
33 Patch
34 };
35
38 {
41 ExactDistance
42 };
43
44
46 struct Settings
47 {
48 WorkMode workMode = WorkMode::Add;
49 float radius = 1.f;
50 float relaxForce = 0.2f;
51 float editForce = 1.f;
52 float sharpness = 50.f;
53 float relaxForceAfterEdit = 0.25f;
54 EdgeWeights edgeWeights = EdgeWeights::Cotan;
55 };
56
58 MRVIEWER_API void init( const std::shared_ptr<ObjectMesh>& objectMesh );
60 MRVIEWER_API void reset();
63 MRVIEWER_API void setFixedRegion( const FaceBitSet& region );
64
66 MRVIEWER_API void setSettings( const Settings& settings );
68 MRVIEWER_API const Settings& getSettings() { return settings_; }
69
71 MRVIEWER_API float getMinRadius() { return minRadius_; }
72
74 Palette& palette() { return *palette_; }
76 MRVIEWER_API void updateTexture();
78 MRVIEWER_API void updateUVs();
80 MRVIEWER_API void enableDeviationVisualization( bool enable );
84 MRVIEWER_API DeviationCalculationMethod deviationCalculationMethod() const { return deviationCalculationMethod_; }
86 MRVIEWER_API bool sameValidVerticesAsInOriginMesh() const { return sameValidVerticesAsInOriginMesh_; }
88 MRVIEWER_API Vector2f getMinMax();
89
91 MRVIEWER_API void setIgnoreOcclusion( bool ignore ) { ignoreOcclusion_ = ignore; }
92 MRVIEWER_API bool ignoreOcclusion() const { return ignoreOcclusion_; }
93private:
95 MRVIEWER_API bool onMouseDown_( MouseButton button, int modifiers ) override;
97 MRVIEWER_API bool onMouseUp_( MouseButton button, int modifiers ) override;
99 MRVIEWER_API bool onMouseMove_( int mouse_x, int mouse_y ) override;
101 MRVIEWER_API void postDraw_() override;
102
103 void reallocData_( size_t size );
104 void clearData_();
105
106 void initConnections_();
107 void resetConnections_();
108
109 void changeSurface_();
110 void updateUVmap_( bool set );
111 void updateRegion_( const Vector2f& mousePos );
112 void abortEdit_();
114 void laplacianPickVert_( const PointOnFace& pick );
115 void laplacianMoveVert_( const Vector2f& mousePos );
116
117 void updateVizualizeSelection_( const ObjAndPick& objAndPick );
118
119 void updateRegionUVs_( const VertBitSet& region );
120 void updateValueChanges_( const VertBitSet& region );
121 void updateValueChangesPointToPoint_( const VertBitSet& region );
122 void updateValueChangesPointToPlane_( const VertBitSet& region );
123 void updateValueChangesExactDistance_( const VertBitSet& region );
124 void createLastStableObjMesh_();
125 void removeLastStableObjMesh_();
126
129 void compressChangePointsAction_();
130
131 Settings settings_;
132
133 std::shared_ptr<ObjectMesh> obj_;
134 VertBitSet unchangeableVerts_;
135 float minRadius_ = 1.f;
136 Vector2f mousePos_;
137 VertBitSet singleEditingRegion_;
138 VertBitSet visualizationRegion_;
139 VertBitSet generalEditingRegion_;
140 VertScalars pointsShift_;
141 VertScalars editingDistanceMap_;
142 VertScalars visualizationDistanceMap_;
143 VertBitSet changedRegion_;
144 VertScalars valueChanges_;
145 VertScalars lastStableValueChanges_;
146 std::shared_ptr<Mesh> originalMesh_;
147 VertBitSet unknownSign_;
148 std::shared_ptr<ObjectMesh> lastStableObjMesh_;
149 bool firstInit_ = true;
150 bool badRegion_ = false;
151
152 bool mousePressed_ = false;
153
154 std::chrono::time_point<std::chrono::high_resolution_clock> timePoint_;
155 boost::signals2::scoped_connection meshChangedConnection_;
156 bool ownMeshChangedSignal_ = false;
157
158 bool connectionsInitialized_ = false;
159
161 VertId touchVertId_;
162 Vector3f touchVertIniPos_;
163 Vector2i storedDown_;
164 std::unique_ptr<Laplacian> laplacian_;
165
167 class SmartChangeMeshPointsAction;
168 std::shared_ptr<SmartChangeMeshPointsAction> historyAction_;
169
171 bool appendHistoryAction_ = false;
172
173 std::shared_ptr<Palette> palette_;
174 bool enableDeviationTexture_ = false;
175 DeviationCalculationMethod deviationCalculationMethod_ = DeviationCalculationMethod::ExactDistance;
176 bool sameValidVerticesAsInOriginMesh_ = true;
177
179 bool ignoreOcclusion_ = false;
180};
181
182}
183
Definition MRMesh/MRLaplacian.h:32
Class to hold one dimension texture with value to UV mapping.
Definition MRPalette.h:25
widget for surface modifying @detail available 3 modes: add (move surface region in direction of norm...
Definition MRSurfaceManipulationWidget.h:21
DeviationCalculationMethod
Method for calculating mesh changes.
Definition MRSurfaceManipulationWidget.h:38
MRVIEWER_API void setSettings(const Settings &settings)
set widget settings (mesh change settings)
MRVIEWER_API bool sameValidVerticesAsInOriginMesh() const
checks for a one-to-one correspondence between the vertices of the original grid and the modified one
Definition MRSurfaceManipulationWidget.h:86
MRVIEWER_API ~SurfaceManipulationWidget()
MRVIEWER_API void init(const std::shared_ptr< ObjectMesh > &objectMesh)
initialize widget according ObjectMesh
MRVIEWER_API void reset()
reset widget state
MRVIEWER_API SurfaceManipulationWidget()
MRVIEWER_API const Settings & getSettings()
get widget settings
Definition MRSurfaceManipulationWidget.h:68
MRVIEWER_API void setFixedRegion(const FaceBitSet &region)
MRVIEWER_API DeviationCalculationMethod deviationCalculationMethod() const
get method for calculating mesh changes
Definition MRSurfaceManipulationWidget.h:84
WorkMode
widget work modes
Definition MRSurfaceManipulationWidget.h:28
Palette & palette()
get palette used for visualization point shifts
Definition MRSurfaceManipulationWidget.h:74
MRVIEWER_API Vector2f getMinMax()
get min / max point shifts for (usefull for setup palette)
MRVIEWER_API void updateUVs()
update texture uv coords used for colorize surface (use after change ranges in palette)
MRVIEWER_API bool ignoreOcclusion() const
Definition MRSurfaceManipulationWidget.h:92
MRVIEWER_API float getMinRadius()
mimum radius of editing area.
Definition MRSurfaceManipulationWidget.h:71
MRVIEWER_API void enableDeviationVisualization(bool enable)
enable visualization of mesh deviations
MRVIEWER_API void updateTexture()
update texture used for colorize surface (use after change colorMap in palette)
MRVIEWER_API void setDeviationCalculationMethod(DeviationCalculationMethod method)
set method for calculating mesh changes
MRVIEWER_API void setIgnoreOcclusion(bool ignore)
allow the user to edit parts of object that are hidden in the current view by other objects
Definition MRSurfaceManipulationWidget.h:91
MouseButton
Definition MRMouse.h:9
EdgeWeights
determines the weight of each edge in applications like Laplacian
Definition MREnums.h:8
std::pair< std::shared_ptr< MR::VisualObject >, MR::PointOnObject > ObjAndPick
Definition MRViewerFwd.h:69
@ PointToPlane
converge much faster than PointToPoint in case of many good (with not all points/normals in one plane...
@ PointToPoint
it is the safest approach but can converge slowly
Definition MRViewerEventsListener.h:29
Definition MRMesh/MRPointOnFace.h:11
Mesh change settings.
Definition MRSurfaceManipulationWidget.h:47