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/MREnums.h"
5#include "MRMesh/MRBitSet.h"
6#include "MRMesh/MRVector2.h"
7#include <cfloat>
8
9namespace MR
10{
13
14
20class MRVIEWER_CLASS SurfaceManipulationWidget :
21 public MultiListener<MouseDownListener, MouseMoveListener, MouseUpListener,
22 PostDrawListener>
23{
24public:
26 MRVIEWER_API virtual ~SurfaceManipulationWidget();
27
37
45
46
48 struct Settings
49 {
52 float radius = 1.f;
53
55 float relaxForce = 0.2f;
56 bool relaxKeepCreases = false;
57 float relaxNormalsSmoothing = 100.f;
59 bool relaxMarkCreases = true;
60
62 float editForce = 1.f;
63 float sharpness = 50.f;
64 float relaxForceAfterEdit = 0.25f;
66 bool subdivideGrooves = false;
67
71 bool mimicPatch = false;
72 };
73
75 MRVIEWER_API void init( const std::shared_ptr<ObjectMesh>& objectMesh );
76
78 MRVIEWER_API void reset();
79
83 MRVIEWER_API void setFixedRegion( const FaceBitSet& region );
84
86 MRVIEWER_API void setSettings( const Settings& settings );
87
89 MRVIEWER_API const Settings& getSettings() const { return settings_; }
90
92 [[deprecated( "always returns 1" )]]
93 MRVIEWER_API float getMinRadius() const { return 1.f; }
94
96 Palette& palette() { return *palette_; }
97
99 MRVIEWER_API void updateTexture();
100
102 MRVIEWER_API void updateUVs();
103
105 MRVIEWER_API void enableDeviationVisualization( bool enable );
106
110
113
115 MRVIEWER_API bool sameOriginalMeshTopology() const { return sameOriginalMeshTopology_; }
116
118 MRVIEWER_API Vector2f getMinMax() const;
119
121 MRVIEWER_API void setIgnoreOcclusion( bool ignore ) { ignoreOcclusion_ = ignore; }
122 MRVIEWER_API bool ignoreOcclusion() const { return ignoreOcclusion_; }
123
126
129
130protected:
132 MRVIEWER_API bool onMouseDown_( MouseButton button, int modifiers ) override;
133
135 MRVIEWER_API bool onMouseUp_( MouseButton button, int modifiers ) override;
136
138 MRVIEWER_API bool onMouseMove_( int mouse_x, int mouse_y ) override;
139
141 MRVIEWER_API void postDraw_() override;
142
145 MRVIEWER_API virtual bool checkModifiers_( int modifiers ) const { return modifiers == 0; }
146
149 MRVIEWER_API virtual void appendMeshDataChangeHistory_( ObjectMeshData&& newMeshData, const FaceBitSet& newFaces );
150
151 void reallocData_( size_t size );
153
156
158 void updateUVmap_( bool set, bool wholeMesh = false );
159 void updateRegion_( const Vector2f& mousePos );
162
165 void laplacianPickVert_( const PointOnFace& pick );
166 void laplacianMoveVert_( const Vector2f& mousePos );
167
170
171 void updateRegionUVs_( const VertBitSet& region );
172 void updateValueChanges_( const VertBitSet& region );
173 void updateValueChangesPointToPoint_( const VertBitSet& region );
174 void updateValueChangesPointToPlane_( const VertBitSet& region );
175 void updateValueChangesExactDistance_( const VertBitSet& region );
178
182
186
187 void updateDistancesAndRegion_( const Mesh& mesh, const std::vector<MeshTriPoint>& start, VertScalars& distances, VertBitSet& region, const VertBitSet* untouchable );
188
190
191 std::shared_ptr<ObjectMesh> obj_;
193 Vector2f mousePos_;
194 std::vector<MeshTriPoint> pointsUnderMouse_;
198 VertScalars pointsShift_;
201 VertScalars valueChanges_;
202 std::shared_ptr<Mesh> originalMesh_;
203 VertBitSet unknownSign_;
204 std::shared_ptr<ObjectMesh> lastStableObjMesh_;
205 bool firstInit_ = true;
206 bool badRegion_ = false;
207
208 bool mousePressed_ = false;
209
210 boost::signals2::scoped_connection meshChangedConnection_;
212
214
218 Vector2i storedDown_;
219 std::unique_ptr<Laplacian> laplacian_;
220
222 VertBitSet pickedVerts_;
223
225 {
226 Vector3f target;
227 float minMouseDistSq = FLT_MAX;
228 };
229
232
235 std::shared_ptr<VersatileChangeMeshPointsAction> historyAction_;
236
239
242 std::shared_ptr<CombinedHistoryAction> combinedHistoryAction_;
243
244 std::shared_ptr<Palette> palette_;
249
251 bool ignoreOcclusion_ = false;
253};
254
255}
256
Class to hold one dimension texture with value to UV mapping.
Definition MRPalette.h:30
bool editOnlyCodirectedSurface_
Definition MRSurfaceManipulationWidget.h:252
Vector2i storedDown_
Definition MRSurfaceManipulationWidget.h:218
DeviationCalculationMethod
Method for calculating mesh changes.
Definition MRSurfaceManipulationWidget.h:40
bool enableDeviationTexture_
Definition MRSurfaceManipulationWidget.h:245
bool appendHistoryAction_
true if historyAction_ is prepared but not yet appended to HistoryStore, which is done on first mouse...
Definition MRSurfaceManipulationWidget.h:238
WorkMode workMode
common settings
Definition MRSurfaceManipulationWidget.h:51
MouseButton
Definition MRMouse.h:13
Settings settings_
Definition MRSurfaceManipulationWidget.h:189
void enableDeviationVisualization(bool enable)
enable visualization of mesh deviations; can be called before init()
bool connectionsInitialized_
Definition MRSurfaceManipulationWidget.h:213
void setEditOnlyCodirectedSurface(bool edit)
restricts editable area to vertices whose normals look into the same half-space as normal under curso...
Definition MRSurfaceManipulationWidget.h:125
boost::signals2::scoped_connection meshChangedConnection_
Definition MRSurfaceManipulationWidget.h:210
DeviationCalculationMethod requestedDeviationCalculationMethod_
last method passed to setDeviationCalculationMethod
Definition MRSurfaceManipulationWidget.h:247
void laplacianMoveVert_(const Vector2f &mousePos)
VertBitSet singleEditingRegion_
current (under the cursor) region of tool application
Definition MRSurfaceManipulationWidget.h:195
bool mousePressed_
Definition MRSurfaceManipulationWidget.h:208
EdgeWeights edgeWeights
Laplacian and Patch modes.
Definition MRSurfaceManipulationWidget.h:69
float relaxForce
Relax mode.
Definition MRSurfaceManipulationWidget.h:55
ImVec2 size(const ViewportRectangle &rect)
Definition MRViewport.h:59
bool sameOriginalMeshTopology_
Definition MRSurfaceManipulationWidget.h:248
float relaxNormalsSmoothing
if relaxKeepCreases, the amount of smoothing of face normals between creases (gamma in meshDenoiseWit...
Definition MRSurfaceManipulationWidget.h:57
void initLaplacian_(RememberShape rs)
Laplacian.
VertScalars pointsShift_
Definition MRSurfaceManipulationWidget.h:198
std::shared_ptr< Palette > palette_
Definition MRSurfaceManipulationWidget.h:244
float radius
radius of editing region
Definition MRSurfaceManipulationWidget.h:52
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:121
bool subdivideGrooves
if true in Add/Remove modes, changed parts of mesh will be subdivided on mouse up
Definition MRSurfaceManipulationWidget.h:66
VertId touchVertId_
Laplacian.
Definition MRSurfaceManipulationWidget.h:216
void init(const std::shared_ptr< ObjectMesh > &objectMesh)
initialize widget according ObjectMesh; if it was initialized with another object,...
VertScalars valueChanges_
Definition MRSurfaceManipulationWidget.h:201
std::unique_ptr< Laplacian > laplacian_
Definition MRSurfaceManipulationWidget.h:219
VertBitSet pickedVerts_
these are all vertices, which will are attracted to be under mouse considering material width since l...
Definition MRSurfaceManipulationWidget.h:222
void updateRegionUVs_(const VertBitSet &region)
bool mimicPatch
if true in Patch mode mixes CloseSurfaceFillMetric and disables smoothing
Definition MRSurfaceManipulationWidget.h:71
DeviationCalculationMethod deviationCalculationMethod_
Definition MRSurfaceManipulationWidget.h:246
void setDeviationCalculationMethod(DeviationCalculationMethod method)
VertBitSet visualizationRegion_
vertices of triangles partially or fully highlighted with red
Definition MRSurfaceManipulationWidget.h:196
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
void updateUVs()
update texture uv coords used for colorize surface (use after change ranges in palette)
void reset()
reset widget state including the fixed region; does nothing if the widget is not initialized
bool onMouseDown_(MouseButton button, int modifiers) override
start modifying mesh surface
void reallocData_(size_t size)
void updateTexture()
update texture used for colorize surface (use after change colorMap in palette)
DeviationCalculationMethod deviationCalculationMethod() const
get method for calculating mesh changes, which is currently in use
Definition MRSurfaceManipulationWidget.h:112
bool firstInit_
need to save settings in re-initial
Definition MRSurfaceManipulationWidget.h:205
Vector2f getMinMax() const
get min / max point shifts for (useful for setup palette)
std::shared_ptr< ObjectMesh > obj_
Definition MRSurfaceManipulationWidget.h:191
bool laplacianBasedAddRemove
if true in Add/Remove modes, the modification will be done using Laplacian solver,...
Definition MRSurfaceManipulationWidget.h:65
std::shared_ptr< VersatileChangeMeshPointsAction > historyAction_
Definition MRSurfaceManipulationWidget.h:235
bool ignoreOcclusion_
allow the user to edit parts of object that are hidden in the current view by other objects
Definition MRSurfaceManipulationWidget.h:251
void updateValueChanges_(const VertBitSet &region)
Vector3f touchVertIniPos_
initial position of fixed vertex
Definition MRSurfaceManipulationWidget.h:217
std::vector< MeshTriPoint > pointsUnderMouse_
mesh points under mouse in the current frame (could be many in case of fast mouse movement)
Definition MRSurfaceManipulationWidget.h:194
bool sameOriginalMeshTopology() const
returns true if the current object's mesh has the same topology as original input mesh (and vertices ...
Definition MRSurfaceManipulationWidget.h:115
float getMinRadius() const
minimum radius of editing area.
Definition MRSurfaceManipulationWidget.h:93
int relaxPointIters
if relaxKeepCreases, the number of iterations to update vertex coordinates from smoothed normals
Definition MRSurfaceManipulationWidget.h:58
phmap::flat_hash_map< K, V, Hash, Eq, Allocator< std::pair< const K, V > > > HashMap
Definition MRMeshFwd.h:631
VertBitSet unchangeableVerts_
Definition MRSurfaceManipulationWidget.h:192
std::shared_ptr< ObjectMesh > lastStableObjMesh_
Definition MRSurfaceManipulationWidget.h:204
bool relaxKeepCreases
if true in Relax mode, the selected edges and creases of the mesh are kept sharp (meshDenoiseWithCrea...
Definition MRSurfaceManipulationWidget.h:56
void updateValueChangesExactDistance_(const VertBitSet &region)
RememberShape
Definition MREnums.h:56
VertexMass vmass
vertex weights for Laplacian and Patch
Definition MRSurfaceManipulationWidget.h:70
WorkMode
widget work modes
Definition MRSurfaceManipulationWidget.h:30
float editForce
Add and Remove modes.
Definition MRSurfaceManipulationWidget.h:62
bool badRegion_
in selected region less than 3 points
Definition MRSurfaceManipulationWidget.h:206
float relaxForceAfterEdit
force of relaxing modified area after editing (add / remove) is complete. [0 - 0.5],...
Definition MRSurfaceManipulationWidget.h:64
bool ownMeshChangedSignal_
true while the widget changes the mesh itself, to ignore meshChangedSignal
Definition MRSurfaceManipulationWidget.h:211
void updateRegion_(const Vector2f &mousePos)
void setFixedRegion(const FaceBitSet &region)
Vector3f target
Definition MRSurfaceManipulationWidget.h:226
Palette & palette()
get palette used for visualization point shifts, available before init()
Definition MRSurfaceManipulationWidget.h:96
std::shared_ptr< Mesh > originalMesh_
original input mesh
Definition MRSurfaceManipulationWidget.h:202
VertBitSet unknownSign_
cached data to avoid reallocating memory
Definition MRSurfaceManipulationWidget.h:203
void markSelectedEdgesAsCreases_()
selected edges having a face in generalEditingRegion_ become creases, undone together with the smooth...
float sharpness
effect of force on points far from center editing area. [0 - 100]
Definition MRSurfaceManipulationWidget.h:63
virtual void appendMeshDataChangeHistory_(ObjectMeshData &&newMeshData, const FaceBitSet &newFaces)
VertBitSet generalEditingRegion_
united region of tool application since the last mouse down
Definition MRSurfaceManipulationWidget.h:197
bool isEditOnlyCodirectedSurface() const
get state of an editable region restriction
Definition MRSurfaceManipulationWidget.h:128
void laplacianPickVert_(const PointOnFace &pick)
for singleEditingRegion_
void updateValueChangesPointToPoint_(const VertBitSet &region)
VertexMass
determines the weight or mass of each vertex in applications like Laplacian
Definition MREnums.h:34
void updateDistancesAndRegion_(const Mesh &mesh, const std::vector< MeshTriPoint > &start, VertScalars &distances, VertBitSet &region, const VertBitSet *untouchable)
std::shared_ptr< CombinedHistoryAction > combinedHistoryAction_
Definition MRSurfaceManipulationWidget.h:242
void updateUVmap_(bool set, bool wholeMesh=false)
void postDraw_() override
need to visualize bad region (draw grey circle)
bool relaxMarkCreases
if true and relaxKeepCreases, then on mouse up in Relax mode the selected edges in the smoothed area ...
Definition MRSurfaceManipulationWidget.h:59
VertScalars editingDistanceMap_
Definition MRSurfaceManipulationWidget.h:199
bool ignoreOcclusion() const
Definition MRSurfaceManipulationWidget.h:122
void setSettings(const Settings &settings)
set widget settings (mesh change settings)
const Settings & getSettings() const
get widget settings
Definition MRSurfaceManipulationWidget.h:89
VertScalars visualizationDistanceMap_
Definition MRSurfaceManipulationWidget.h:200
bool onMouseMove_(int mouse_x, int mouse_y) override
update
float minMouseDistSq
attraction point
Definition MRSurfaceManipulationWidget.h:227
void updateValueChangesPointToPlane_(const VertBitSet &region)
virtual bool checkModifiers_(int modifiers) const
Definition MRSurfaceManipulationWidget.h:145
Vector2f mousePos_
mouse position of last updateRegion_
Definition MRSurfaceManipulationWidget.h:193
HashMap< VertId, PickedVertData > pickedVertsToData_
same vertices as in pickedVerts_ mapped to PickedVertData
Definition MRSurfaceManipulationWidget.h:231
void updateVizualizeSelection_()
when the mouse is not pressed, also sets singleEditingRegion_
@ PointToPlane
distance between the initial plane (starting point and normal to it) and the end point
Definition MRSurfaceManipulationWidget.h:42
@ ExactDistance
distance between the start and end meshes
Definition MRSurfaceManipulationWidget.h:43
@ PointToPoint
distance between the start and end points
Definition MRSurfaceManipulationWidget.h:41
@ Cotan
edge weight depends on local geometry and uses cotangent values
Definition MREnums.h:49
@ Remove
Definition MRSurfaceManipulationWidget.h:32
@ Patch
Definition MRSurfaceManipulationWidget.h:35
@ Laplacian
Definition MRSurfaceManipulationWidget.h:34
@ Add
Definition MRSurfaceManipulationWidget.h:31
@ Relax
Definition MRSurfaceManipulationWidget.h:33
@ NeiArea
vertex mass depends on local geometry and proportional to the area of first-ring triangles
Definition MREnums.h:39
Only strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
Definition MRCameraOrientationPlugin.h:8
Definition MRMesh.h:24
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
Definition MRSurfaceManipulationWidget.h:225
Mesh change settings.
Definition MRSurfaceManipulationWidget.h:49