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{
14
15
21class MRVIEWER_CLASS SurfaceManipulationWidget :
22 public MultiListener<MouseDownListener, MouseMoveListener, MouseUpListener,
23 PostDrawListener>
24{
25public:
27 MRVIEWER_API virtual ~SurfaceManipulationWidget();
28
30 enum class WorkMode
31 {
32 Add,
33 Remove,
34 Relax,
36 Patch
37 };
38
41 {
44 ExactDistance
45 };
46
47
49 struct Settings
50 {
51 WorkMode workMode = WorkMode::Add;
52 float radius = 1.f;
53 float relaxForce = 0.2f;
54 float editForce = 1.f;
55 float sharpness = 50.f;
56 float relaxForceAfterEdit = 0.25f;
57 EdgeWeights edgeWeights = EdgeWeights::Cotan;
58 };
59
61 MRVIEWER_API void init( const std::shared_ptr<ObjectMesh>& objectMesh );
63 MRVIEWER_API void reset();
66 MRVIEWER_API void setFixedRegion( const FaceBitSet& region );
67
69 MRVIEWER_API void setSettings( const Settings& settings );
71 MRVIEWER_API const Settings& getSettings() { return settings_; }
72
74 MRVIEWER_API float getMinRadius() { return minRadius_; }
75
77 Palette& palette() { return *palette_; }
79 MRVIEWER_API void updateTexture();
81 MRVIEWER_API void updateUVs();
83 MRVIEWER_API void enableDeviationVisualization( bool enable );
87 MRVIEWER_API DeviationCalculationMethod deviationCalculationMethod() const { return deviationCalculationMethod_; }
89 MRVIEWER_API bool sameValidVerticesAsInOriginMesh() const { return sameValidVerticesAsInOriginMesh_; }
91 MRVIEWER_API Vector2f getMinMax();
92
94 MRVIEWER_API void setIgnoreOcclusion( bool ignore ) { ignoreOcclusion_ = ignore; }
95 MRVIEWER_API bool ignoreOcclusion() const { return ignoreOcclusion_; }
96
98 void setEditOnlyCodirectedSurface( bool edit ) { editOnlyCodirectedSurface_ = edit; }
100 bool isEditOnlyCodirectedSurface() const { return editOnlyCodirectedSurface_; }
101protected:
103 MRVIEWER_API bool onMouseDown_( MouseButton button, int modifiers ) override;
105 MRVIEWER_API bool onMouseUp_( MouseButton button, int modifiers ) override;
107 MRVIEWER_API bool onMouseMove_( int mouse_x, int mouse_y ) override;
109 MRVIEWER_API void postDraw_() override;
110
113 MRVIEWER_API virtual bool checkModifiers_( int modifiers ) const { return modifiers == 0; }
114
117 MRVIEWER_API virtual void appendMeshDataChangeHistory_( ObjectMeshData&& newMeshData, const FaceBitSet& newFaces );
118
119 void reallocData_( size_t size );
121
124
126 void updateUVmap_( bool set, bool wholeMesh = false );
127 void updateRegion_( const Vector2f& mousePos );
131 void laplacianPickVert_( const PointOnFace& pick );
132 void laplacianMoveVert_( const Vector2f& mousePos );
133
135
136 void updateRegionUVs_( const VertBitSet& region );
137 void updateValueChanges_( const VertBitSet& region );
138 void updateValueChangesPointToPoint_( const VertBitSet& region );
139 void updateValueChangesPointToPlane_( const VertBitSet& region );
140 void updateValueChangesExactDistance_( const VertBitSet& region );
143
147
148 void updateDistancesAndRegion_( const Mesh& mesh, const VertBitSet& start, VertScalars& distances, VertBitSet& region, const VertBitSet* untouchable );
149
151
152 std::shared_ptr<ObjectMesh> obj_;
154 float minRadius_ = 1.f;
155 Vector2f mousePos_;
160 VertScalars pointsShift_;
163 VertBitSet changedRegion_;
164 VertScalars valueChanges_;
166 std::shared_ptr<Mesh> originalMesh_;
167 VertBitSet unknownSign_;
168 std::shared_ptr<ObjectMesh> lastStableObjMesh_;
169 bool firstInit_ = true;
170 bool badRegion_ = false;
171
172 bool mousePressed_ = false;
173
174 std::chrono::time_point<std::chrono::high_resolution_clock> timePoint_;
175 boost::signals2::scoped_connection meshChangedConnection_;
176 bool ownMeshChangedSignal_ = false;
177
178 bool connectionsInitialized_ = false;
179
183 Vector2i storedDown_;
184 std::unique_ptr<Laplacian> laplacian_;
185
187 class SmartChangeMeshPointsAction;
188 std::shared_ptr<SmartChangeMeshPointsAction> historyAction_;
189
191 bool appendHistoryAction_ = false;
192
193 std::shared_ptr<Palette> palette_;
194 bool enableDeviationTexture_ = false;
195 DeviationCalculationMethod deviationCalculationMethod_ = DeviationCalculationMethod::ExactDistance;
196 bool sameValidVerticesAsInOriginMesh_ = true;
197
199 bool ignoreOcclusion_ = false;
200 bool editOnlyCodirectedSurface_ = true;
201};
202
203}
204
Definition MRLaplacian.h:24
Class to hold one dimension texture with value to UV mapping.
Definition MRPalette.h:30
widget for surface modifying @detail available 3 modes: add (move surface region in direction of norm...
Definition MRSurfaceManipulationWidget.h:24
Vector2i storedDown_
initial position of fixed vertex
Definition MRSurfaceManipulationWidget.h:183
DeviationCalculationMethod
Method for calculating mesh changes.
Definition MRSurfaceManipulationWidget.h:41
MRVIEWER_API void setSettings(const Settings &settings)
set widget settings (mesh change settings)
MouseButton
Definition MRMouse.h:12
Settings settings_
Definition MRSurfaceManipulationWidget.h:150
void setEditOnlyCodirectedSurface(bool edit)
restricts editable area to vertices whose normals look into the same half-space as normal under curso...
Definition MRSurfaceManipulationWidget.h:98
boost::signals2::scoped_connection meshChangedConnection_
Definition MRSurfaceManipulationWidget.h:175
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:89
void laplacianMoveVert_(const Vector2f &mousePos)
VertBitSet singleEditingRegion_
current (under the cursor) region of tool application
Definition MRSurfaceManipulationWidget.h:157
MRVIEWER_API bool onMouseDown_(MouseButton button, int modifiers) override
start modifying mesh surface
VertScalars pointsShift_
Definition MRSurfaceManipulationWidget.h:160
std::shared_ptr< Palette > palette_
Definition MRSurfaceManipulationWidget.h:193
MRVIEWER_API void init(const std::shared_ptr< ObjectMesh > &objectMesh)
initialize widget according ObjectMesh
VertId touchVertId_
Laplacian.
Definition MRSurfaceManipulationWidget.h:181
VertScalars valueChanges_
Definition MRSurfaceManipulationWidget.h:164
std::unique_ptr< Laplacian > laplacian_
Definition MRSurfaceManipulationWidget.h:184
VertScalars lastStableValueChanges_
Definition MRSurfaceManipulationWidget.h:165
void updateRegionUVs_(const VertBitSet &region)
std::chrono::time_point< std::chrono::high_resolution_clock > timePoint_
Definition MRSurfaceManipulationWidget.h:174
VertBitSet visualizationRegion_
vertices of triangles partially or fully highlighted with red
Definition MRSurfaceManipulationWidget.h:158
MRVIEWER_API bool onMouseUp_(MouseButton button, int modifiers) override
stop modifying mesh surface, generate history action
EdgeWeights
determines the weight of each edge in applications like Laplacian
Definition MREnums.h:44
MRVIEWER_API void reset()
reset widget state
MRVIEWER_API SurfaceManipulationWidget()
std::shared_ptr< SmartChangeMeshPointsAction > historyAction_
Definition MRSurfaceManipulationWidget.h:188
void reallocData_(size_t size)
virtual MRVIEWER_API bool checkModifiers_(int modifiers) const
Definition MRSurfaceManipulationWidget.h:113
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:71
std::shared_ptr< ObjectMesh > obj_
Definition MRSurfaceManipulationWidget.h:152
void updateValueChanges_(const VertBitSet &region)
Vector3f touchVertIniPos_
we fix this vertex in Laplacian and move it manually
Definition MRSurfaceManipulationWidget.h:182
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:156
VertBitSet unchangeableVerts_
Definition MRSurfaceManipulationWidget.h:153
MRVIEWER_API DeviationCalculationMethod deviationCalculationMethod() const
get method for calculating mesh changes
Definition MRSurfaceManipulationWidget.h:87
std::shared_ptr< ObjectMesh > lastStableObjMesh_
Definition MRSurfaceManipulationWidget.h:168
void updateValueChangesExactDistance_(const VertBitSet &region)
WorkMode
widget work modes
Definition MRSurfaceManipulationWidget.h:31
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:77
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:166
VertBitSet unknownSign_
cached data to avoid reallocating memory
Definition MRSurfaceManipulationWidget.h:167
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:159
VertBitSet changedRegion_
Definition MRSurfaceManipulationWidget.h:163
virtual MRVIEWER_API void appendMeshDataChangeHistory_(ObjectMeshData &&newMeshData, const FaceBitSet &newFaces)
MRVIEWER_API bool ignoreOcclusion() const
Definition MRSurfaceManipulationWidget.h:95
MRVIEWER_API float getMinRadius()
mimum radius of editing area.
Definition MRSurfaceManipulationWidget.h:74
bool isEditOnlyCodirectedSurface() const
get state of an editable region restriction
Definition MRSurfaceManipulationWidget.h:100
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:161
VertScalars visualizationDistanceMap_
Definition MRSurfaceManipulationWidget.h:162
void updateValueChangesPointToPlane_(const VertBitSet &region)
Vector2f mousePos_
mouse position of last updateRegion_
Definition MRSurfaceManipulationWidget.h:155
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:94
@ Remove
Default: separate nested meshes and remove them, just like union operation should do,...
@ PointToPoint
it is the safest approach but can converge slowly
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRMesh.h:23
Definition MRViewerEventsListener.h:32
mesh and its per-element attributes for ObjectMeshHolder
Definition MRObjectMeshData.h:17
a point located on some mesh's face
Definition MRPointOnFace.h:16
Mesh change settings.
Definition MRSurfaceManipulationWidget.h:50