MeshLib Documentation
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"
6#include "MRMesh/MREnums.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
37 struct Settings
38 {
39 WorkMode workMode = WorkMode::Add;
40 float radius = 1.f; // radius of editing region
41 float relaxForce = 0.2f; // speed of relaxing, typical values (0 - 0.5]
42 float editForce = 1.f; // the force of changing mesh
43 float sharpness = 50.f; // effect of force on points far from center editing area. [0 - 100]
44 float relaxForceAfterEdit = 0.25f; // force of relaxing modified area after editing (add / remove) is complete. [0 - 0.5], 0 - not relax
45 EdgeWeights edgeWeights = EdgeWeights::Cotan; // edge weights for Laplacian and Patch
46 };
47
49 MRVIEWER_API void init( const std::shared_ptr<ObjectMesh>& objectMesh );
51 MRVIEWER_API void reset();
52
54 MRVIEWER_API void setSettings( const Settings& settings );
56 MRVIEWER_API const Settings& getSettings() { return settings_; };
57
58 // mimum radius of editing area.
59 MRVIEWER_API float getMinRadius() { return minRadius_; };
60
61 // get palette used for visualization point shifts
62 Palette& palette() { return *palette_; }
63 // update texture used for colorize surface (use after change colorMap in palette)
64 MRVIEWER_API void updateTexture();
65 // update texture uv coords used for colorize surface (use after change ranges in palette)
66 MRVIEWER_API void updateUVs();
67 // enable visualization of mesh deviations
68 MRVIEWER_API void enableDeviationVisualization( bool enable );
69 // get min / max point shifts for (usefull for setup palette)
70 MRVIEWER_API Vector2f getMinMax();
71private:
73 MRVIEWER_API bool onMouseDown_( MouseButton button, int modifiers ) override;
75 MRVIEWER_API bool onMouseUp_( MouseButton button, int modifiers ) override;
77 MRVIEWER_API bool onMouseMove_( int mouse_x, int mouse_y ) override;
79 MRVIEWER_API void postDraw_() override;
80
81 void reallocData_( size_t size );
82 void clearData_();
83
84 void initConnections_();
85 void resetConnections_();
86
87 void changeSurface_();
88 void updateUVmap_( bool set );
89 void updateRegion_( const Vector2f& mousePos );
90 void abortEdit_();
91 // Laplacian
92 void laplacianPickVert_( const PointOnFace& pick );
93 void laplacianMoveVert_( const Vector2f& mousePos );
94
95 void updateVizualizeSelection_( const ObjAndPick& objAndPick );
96
97 void updateRegionUVs_( const VertBitSet& region );
98 void updateValueChanges_( const VertBitSet& region );
99 void updateValueChangesByDistance_( const VertBitSet& region );
100
101 Settings settings_;
102
103 std::shared_ptr<ObjectMesh> obj_;
104 float minRadius_ = 1.f;
105 Vector2f mousePos_;
106 VertBitSet singleEditingRegion_;
107 VertBitSet visualizationRegion_;
108 VertBitSet generalEditingRegion_;
109 VertScalars pointsShift_;
110 VertScalars editingDistanceMap_;
111 VertScalars visualizationDistanceMap_;
112 VertBitSet changedRegion_;
113 VertScalars valueChanges_;
114 VertScalars lastStableValueChanges_;
115 std::shared_ptr<Mesh> originalMesh_;
116 VertBitSet unknownSign_;
117 std::shared_ptr<ObjectMesh> lastStableObjMesh_;
118 bool firstInit_ = true; // need to save settings in re-initial
119 bool badRegion_ = false; // in selected region less than 3 points
120
121 bool mousePressed_ = false;
122
123 std::chrono::time_point<std::chrono::high_resolution_clock> timePoint_;
124 boost::signals2::scoped_connection meshChangedConnection_;
125 bool ownMeshChangedSignal_ = false;
126
127 bool connectionsInitialized_ = false;
128
129 // Laplacian
130 VertId touchVertId_; // we fix this vertex in Laplacian and move it manually
131 Vector3f touchVertIniPos_; // initial position of fixed vertex
132 Vector2i storedDown_;
133 std::unique_ptr<Laplacian> laplacian_;
134 std::shared_ptr<HistoryAction> historyAction_; // this action is prepared beforehand for better responsiveness, but pushed only on mouse move
135 bool appendHistoryAction_ = false;
136
137 std::shared_ptr<Palette> palette_;
138 bool enableDeviationTexture_ = true;
139};
140
141}
std::pair< std::shared_ptr< MR::VisualObject >, MR::PointOnObject > ObjAndPick
Definition MRViewport.h:21
Definition 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
MRVIEWER_API void setSettings(const Settings &settings)
set widget settings (mesh change settings)
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:56
WorkMode
widget work modes
Definition MRSurfaceManipulationWidget.h:28
Palette & palette()
Definition MRSurfaceManipulationWidget.h:62
MRVIEWER_API Vector2f getMinMax()
MRVIEWER_API void updateUVs()
MRVIEWER_API float getMinRadius()
Definition MRSurfaceManipulationWidget.h:59
MRVIEWER_API void enableDeviationVisualization(bool enable)
MRVIEWER_API void updateTexture()
Definition MRCameraOrientationPlugin.h:8
MouseButton
Definition MRMouse.h:9
EdgeWeights
determines the weight of each edge in applications like Laplacian
Definition MREnums.h:8
Definition MRViewerEventsListener.h:29
Definition MRMesh/MRPointOnFace.h:11
Mesh change settings.
Definition MRSurfaceManipulationWidget.h:38