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:
24 MRVIEWER_API virtual ~SurfaceManipulationWidget();
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_; }
93
95 void setEditOnlyCodirectedSurface( bool edit ) { editOnlyCodirectedSurface_ = edit; }
97 bool isEditOnlyCodirectedSurface() const { return editOnlyCodirectedSurface_; }
98protected:
100 MRVIEWER_API bool onMouseDown_( MouseButton button, int modifiers ) override;
102 MRVIEWER_API bool onMouseUp_( MouseButton button, int modifiers ) override;
104 MRVIEWER_API bool onMouseMove_( int mouse_x, int mouse_y ) override;
106 MRVIEWER_API void postDraw_() override;
107
110 MRVIEWER_API virtual void appendMeshChangeHistory_( std::shared_ptr<Mesh> newMesh, const FaceBitSet& newFaces );
111
112 void reallocData_( size_t size );
114
117
119 void updateUVmap_( bool set, bool wholeMesh = false );
120 void updateRegion_( const Vector2f& mousePos );
123 void laplacianPickVert_( const PointOnFace& pick );
124 void laplacianMoveVert_( const Vector2f& mousePos );
125
127
128 void updateRegionUVs_( const VertBitSet& region );
129 void updateValueChanges_( const VertBitSet& region );
130 void updateValueChangesPointToPoint_( const VertBitSet& region );
131 void updateValueChangesPointToPlane_( const VertBitSet& region );
132 void updateValueChangesExactDistance_( const VertBitSet& region );
135
139
140 void updateDistancesAndRegion_( const Mesh& mesh, const VertBitSet& start, VertScalars& distances, VertBitSet& region, const VertBitSet* untouchable );
141
143
144 std::shared_ptr<ObjectMesh> obj_;
146 float minRadius_ = 1.f;
147 Vector2f mousePos_;
152 VertScalars pointsShift_;
155 VertBitSet changedRegion_;
156 VertScalars valueChanges_;
158 std::shared_ptr<Mesh> originalMesh_;
159 VertBitSet unknownSign_;
160 std::shared_ptr<ObjectMesh> lastStableObjMesh_;
161 bool firstInit_ = true;
162 bool badRegion_ = false;
163
164 bool mousePressed_ = false;
165
166 std::chrono::time_point<std::chrono::high_resolution_clock> timePoint_;
167 boost::signals2::scoped_connection meshChangedConnection_;
168 bool ownMeshChangedSignal_ = false;
169
170 bool connectionsInitialized_ = false;
171
175 Vector2i storedDown_;
176 std::unique_ptr<Laplacian> laplacian_;
177
179 class SmartChangeMeshPointsAction;
180 std::shared_ptr<SmartChangeMeshPointsAction> historyAction_;
181
183 bool appendHistoryAction_ = false;
184
185 std::shared_ptr<Palette> palette_;
186 bool enableDeviationTexture_ = false;
187 DeviationCalculationMethod deviationCalculationMethod_ = DeviationCalculationMethod::ExactDistance;
188 bool sameValidVerticesAsInOriginMesh_ = true;
189
191 bool ignoreOcclusion_ = false;
192 bool editOnlyCodirectedSurface_ = true;
193};
194
195}
196
Definition MRMesh/MRLaplacian.h:34
Class to hold one dimension texture with value to UV mapping.
Definition MRPalette.h:26
widget for surface modifying @detail available 3 modes: add (move surface region in direction of norm...
Definition MRSurfaceManipulationWidget.h:21
virtual MRVIEWER_API void appendMeshChangeHistory_(std::shared_ptr< Mesh > newMesh, const FaceBitSet &newFaces)
Vector2i storedDown_
initial position of fixed vertex
Definition MRSurfaceManipulationWidget.h:175
DeviationCalculationMethod
Method for calculating mesh changes.
Definition MRSurfaceManipulationWidget.h:38
MRVIEWER_API void setSettings(const Settings &settings)
set widget settings (mesh change settings)
Settings settings_
Definition MRSurfaceManipulationWidget.h:142
void setEditOnlyCodirectedSurface(bool edit)
restricts editable area to vertices whose normals look into the same half-space as normal under curso...
Definition MRSurfaceManipulationWidget.h:95
boost::signals2::scoped_connection meshChangedConnection_
Definition MRSurfaceManipulationWidget.h:167
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
void laplacianMoveVert_(const Vector2f &mousePos)
VertBitSet singleEditingRegion_
current (under the cursor) region of tool application
Definition MRSurfaceManipulationWidget.h:149
MRVIEWER_API bool onMouseDown_(MouseButton button, int modifiers) override
start modifying mesh surface
VertScalars pointsShift_
Definition MRSurfaceManipulationWidget.h:152
std::shared_ptr< Palette > palette_
Definition MRSurfaceManipulationWidget.h:185
MRVIEWER_API void init(const std::shared_ptr< ObjectMesh > &objectMesh)
initialize widget according ObjectMesh
VertId touchVertId_
Laplacian.
Definition MRSurfaceManipulationWidget.h:173
VertScalars valueChanges_
Definition MRSurfaceManipulationWidget.h:156
std::unique_ptr< Laplacian > laplacian_
Definition MRSurfaceManipulationWidget.h:176
VertScalars lastStableValueChanges_
Definition MRSurfaceManipulationWidget.h:157
void updateRegionUVs_(const VertBitSet &region)
std::chrono::time_point< std::chrono::high_resolution_clock > timePoint_
Definition MRSurfaceManipulationWidget.h:166
VertBitSet visualizationRegion_
vertices of triangles partially or fully highlighted with red
Definition MRSurfaceManipulationWidget.h:150
MRVIEWER_API bool onMouseUp_(MouseButton button, int modifiers) override
stop modifying mesh surface, generate history action
MRVIEWER_API void reset()
reset widget state
MRVIEWER_API SurfaceManipulationWidget()
std::shared_ptr< SmartChangeMeshPointsAction > historyAction_
Definition MRSurfaceManipulationWidget.h:180
void reallocData_(size_t size)
void updateDistancesAndRegion_(const Mesh &mesh, const VertBitSet &start, VertScalars &distances, VertBitSet &region, const VertBitSet *untouchable)
MRVIEWER_API const Settings & getSettings()
get widget settings
Definition MRSurfaceManipulationWidget.h:68
std::shared_ptr< ObjectMesh > obj_
Definition MRSurfaceManipulationWidget.h:144
void updateValueChanges_(const VertBitSet &region)
Vector3f touchVertIniPos_
we fix this vertex in Laplacian and move it manually
Definition MRSurfaceManipulationWidget.h:174
MRVIEWER_API void setFixedRegion(const FaceBitSet &region)
MRVIEWER_API void postDraw_() override
need to visualize bad region (draw grey circle)
VertBitSet activePickedVertices_
vertices that are considered under mouse in curernt frame (could be many in case of fast mouse mouvem...
Definition MRSurfaceManipulationWidget.h:148
VertBitSet unchangeableVerts_
Definition MRSurfaceManipulationWidget.h:145
MRVIEWER_API DeviationCalculationMethod deviationCalculationMethod() const
get method for calculating mesh changes
Definition MRSurfaceManipulationWidget.h:84
std::shared_ptr< ObjectMesh > lastStableObjMesh_
Definition MRSurfaceManipulationWidget.h:160
void updateValueChangesExactDistance_(const VertBitSet &region)
WorkMode
widget work modes
Definition MRSurfaceManipulationWidget.h:28
MRVIEWER_API bool onMouseMove_(int mouse_x, int mouse_y) override
update
void updateRegion_(const Vector2f &mousePos)
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)
std::shared_ptr< Mesh > originalMesh_
original input mesh
Definition MRSurfaceManipulationWidget.h:158
VertBitSet unknownSign_
cached data to avoid reallocating memory
Definition MRSurfaceManipulationWidget.h:159
MRVIEWER_API void updateUVs()
update texture uv coords used for colorize surface (use after change ranges in palette)
VertBitSet generalEditingRegion_
united region of tool application since the last mouse down
Definition MRSurfaceManipulationWidget.h:151
VertBitSet changedRegion_
Definition MRSurfaceManipulationWidget.h:155
MRVIEWER_API bool ignoreOcclusion() const
Definition MRSurfaceManipulationWidget.h:92
MRVIEWER_API float getMinRadius()
mimum radius of editing area.
Definition MRSurfaceManipulationWidget.h:71
bool isEditOnlyCodirectedSurface() const
get state of an editable region restriction
Definition MRSurfaceManipulationWidget.h:97
void laplacianPickVert_(const PointOnFace &pick)
Laplacian.
void updateValueChangesPointToPoint_(const VertBitSet &region)
MRVIEWER_API void enableDeviationVisualization(bool enable)
enable visualization of mesh deviations
virtual MRVIEWER_API ~SurfaceManipulationWidget()
void updateUVmap_(bool set, bool wholeMesh=false)
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
VertScalars editingDistanceMap_
Definition MRSurfaceManipulationWidget.h:153
VertScalars visualizationDistanceMap_
Definition MRSurfaceManipulationWidget.h:154
void updateValueChangesPointToPlane_(const VertBitSet &region)
Vector2f mousePos_
mouse position of last updateRegion_
Definition MRSurfaceManipulationWidget.h:147
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
Definition MRCameraOrientationPlugin.h:8
MouseButton
Definition MRMouse.h:9
@ Remove
Default: separate nested meshes and remove them, just like union operation should do,...
EdgeWeights
determines the weight of each edge in applications like Laplacian
Definition MREnums.h:18
@ 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 MRMesh/MRMesh.h:22
Definition MRViewerEventsListener.h:29
a point located on some mesh's face
Definition MRMesh/MRPointOnFace.h:11
Mesh change settings.
Definition MRSurfaceManipulationWidget.h:47