MeshLib
 
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 "MRViewer.h"
7#include "MRMesh/MREnums.h"
9#include <chrono>
10
11namespace MR
12{
13
19class MRVIEWER_CLASS SurfaceManipulationWidget :
20 public MultiListener<MouseDownListener, MouseMoveListener, MouseUpListener,
21 PostDrawListener>
22{
23public:
26
28 enum class WorkMode
29 {
30 Add,
31 Remove,
32 Relax,
34 Patch
35 };
36
38 struct Settings
39 {
40 WorkMode workMode = WorkMode::Add;
41 float radius = 1.f; // radius of editing region
42 float relaxForce = 0.2f; // speed of relaxing, typical values (0 - 0.5]
43 float editForce = 1.f; // the force of changing mesh
44 float sharpness = 50.f; // effect of force on points far from center editing area. [0 - 100]
45 float relaxForceAfterEdit = 0.25f; // force of relaxing modified area after editing (add / remove) is complete. [0 - 0.5], 0 - not relax
46 EdgeWeights edgeWeights = EdgeWeights::Cotan; // edge weights for Laplacian and Patch
47 };
48
50 MRVIEWER_API void init( const std::shared_ptr<ObjectMesh>& objectMesh );
52 MRVIEWER_API void reset();
53
55 MRVIEWER_API void setSettings( const Settings& settings );
57 MRVIEWER_API const Settings& getSettings() { return settings_; };
58
59 // mimum radius of editing area.
60 MRVIEWER_API float getMinRadius() { return minRadius_; };
61
62private:
64 MRVIEWER_API bool onMouseDown_( Viewer::MouseButton button, int modifiers ) override;
66 MRVIEWER_API bool onMouseUp_( Viewer::MouseButton button, int modifiers ) override;
68 MRVIEWER_API bool onMouseMove_( int mouse_x, int mouse_y ) override;
70 MRVIEWER_API void postDraw_() override;
71
72 void initConnections_();
73 void resetConnections_();
74
75 void changeSurface_();
76 void updateUVmap_( bool set );
77 void updateRegion_( const Vector2f& mousePos );
78 void abortEdit_();
79 // Laplacian
80 void laplacianPickVert_( const PointOnFace& pick );
81 void laplacianMoveVert_( const Vector2f& mousePos );
82
83 void updateVizualizeSelection_( const ObjAndPick& objAndPick );
84
85 Settings settings_;
86
87 std::shared_ptr<ObjectMesh> obj_;
88 float diagonal_ = 1.f;
89 float minRadius_ = 1.f;
90 Vector2f mousePos_;
91 VertBitSet singleEditingRegion_;
92 VertBitSet visualizationRegion_;
93 VertBitSet generalEditingRegion_;
94 VertScalars pointsShift_;
95 VertScalars editingDistanceMap_;
96 VertScalars visualizationDistanceMap_;
97 std::shared_ptr<ObjectMesh> oldMesh_;
98 bool firstInit_ = true; // need to save settings in re-initial
99 bool badRegion_ = false; // in selected region less than 3 points
100
101 bool mousePressed_ = false;
102
103 std::chrono::time_point<std::chrono::high_resolution_clock> timePoint_;
104 boost::signals2::scoped_connection meshChangedConnection_;
105 bool ownMeshChangedSignal_ = false;
106
107 bool connectionsInitialized_ = false;
108
109 // Laplacian
110 VertId touchVertId_; // we fix this vertex in Laplacian and move it manually
111 Vector3f touchVertIniPos_; // initial position of fixed vertex
112 Vector2i storedDown_;
113 std::unique_ptr<Laplacian> laplacian_;
114 std::shared_ptr<HistoryAction> historyAction_; // this action is prepared beforehand for better responsiveness, but pushed only on mouse move
115 bool appendHistoryAction_ = false;
116};
117
118}
int VertId
Definition MRDotNet/MRMeshFwd.h:51
std::pair< std::shared_ptr< MR::VisualObject >, MR::PointOnObject > ObjAndPick
Definition MRViewport.h:21
Definition MRDotNet/MRBitSet.h:39
Definition MRLaplacian.h:32
widget for surface modifying @detail available 3 modes: add (move surface region in direction of norm...
Definition MRSurfaceManipulationWidget.h:22
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:57
WorkMode
widget work modes
Definition MRSurfaceManipulationWidget.h:29
MRVIEWER_API float getMinRadius()
Definition MRSurfaceManipulationWidget.h:60
represents a 3-dimentional float-typed vector
Definition MRDotNet/MRVector3.h:8
Definition MRCameraOrientationPlugin.h:7
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 MRPointOnFace.h:11
Mesh change settings.
Definition MRSurfaceManipulationWidget.h:39