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:
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_; }
98private:
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
108 void reallocData_( size_t size );
109 void clearData_();
110
111 void initConnections_();
112 void resetConnections_();
113
114 void changeSurface_();
115 void updateUVmap_( bool set );
116 void updateRegion_( const Vector2f& mousePos );
117 void abortEdit_();
119 void laplacianPickVert_( const PointOnFace& pick );
120 void laplacianMoveVert_( const Vector2f& mousePos );
121
122 void updateVizualizeSelection_( const ObjAndPick& objAndPick );
123
124 void updateRegionUVs_( const VertBitSet& region );
125 void updateValueChanges_( const VertBitSet& region );
126 void updateValueChangesPointToPoint_( const VertBitSet& region );
127 void updateValueChangesPointToPlane_( const VertBitSet& region );
128 void updateValueChangesExactDistance_( const VertBitSet& region );
129 void createLastStableObjMesh_();
130 void removeLastStableObjMesh_();
131
134 void compressChangePointsAction_();
135
136 void updateDistancesAndRegion_( const Mesh& mesh, const PointOnFace& pOnFace, VertScalars& distances, VertBitSet& region );
137
138 Settings settings_;
139
140 std::shared_ptr<ObjectMesh> obj_;
141 VertBitSet unchangeableVerts_;
142 float minRadius_ = 1.f;
143 Vector2f mousePos_;
144 VertBitSet singleEditingRegion_;
145 VertBitSet visualizationRegion_;
146 VertBitSet generalEditingRegion_;
147 VertScalars pointsShift_;
148 VertScalars editingDistanceMap_;
149 VertScalars visualizationDistanceMap_;
150 VertBitSet changedRegion_;
151 VertScalars valueChanges_;
152 VertScalars lastStableValueChanges_;
153 std::shared_ptr<Mesh> originalMesh_;
154 VertBitSet unknownSign_;
155 std::shared_ptr<ObjectMesh> lastStableObjMesh_;
156 bool firstInit_ = true;
157 bool badRegion_ = false;
158
159 bool mousePressed_ = false;
160
161 std::chrono::time_point<std::chrono::high_resolution_clock> timePoint_;
162 boost::signals2::scoped_connection meshChangedConnection_;
163 bool ownMeshChangedSignal_ = false;
164
165 bool connectionsInitialized_ = false;
166
168 VertId touchVertId_;
169 Vector3f touchVertIniPos_;
170 Vector2i storedDown_;
171 std::unique_ptr<Laplacian> laplacian_;
172
174 class SmartChangeMeshPointsAction;
175 std::shared_ptr<SmartChangeMeshPointsAction> historyAction_;
176
178 bool appendHistoryAction_ = false;
179
180 std::shared_ptr<Palette> palette_;
181 bool enableDeviationTexture_ = false;
182 DeviationCalculationMethod deviationCalculationMethod_ = DeviationCalculationMethod::ExactDistance;
183 bool sameValidVerticesAsInOriginMesh_ = true;
184
186 bool ignoreOcclusion_ = false;
187 bool editOnlyCodirectedSurface_ = true;
188};
189
190}
191
Definition MRMesh/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
DeviationCalculationMethod
Method for calculating mesh changes.
Definition MRSurfaceManipulationWidget.h:38
MRVIEWER_API void setSettings(const Settings &settings)
set widget settings (mesh change settings)
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
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
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:68
MRVIEWER_API void setFixedRegion(const FaceBitSet &region)
MRVIEWER_API DeviationCalculationMethod deviationCalculationMethod() const
get method for calculating mesh changes
Definition MRSurfaceManipulationWidget.h:84
WorkMode
widget work modes
Definition MRSurfaceManipulationWidget.h:28
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)
MRVIEWER_API void updateUVs()
update texture uv coords used for colorize surface (use after change ranges in palette)
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
MRVIEWER_API void enableDeviationVisualization(bool enable)
enable visualization of mesh deviations
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
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
MouseButton
Definition MRMouse.h:9
EdgeWeights
determines the weight of each edge in applications like Laplacian
Definition MREnums.h:18
std::pair< std::shared_ptr< MR::VisualObject >, MR::PointOnObject > ObjAndPick
Definition MRViewerFwd.h:73
@ 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