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
61
63 MRVIEWER_API void init( const std::shared_ptr<ObjectMesh>& objectMesh );
64
66 MRVIEWER_API void reset();
67
70 MRVIEWER_API void setFixedRegion( const FaceBitSet& region );
71
73 MRVIEWER_API void setSettings( const Settings& settings );
74
76 MRVIEWER_API const Settings& getSettings() { return settings_; }
77
79 MRVIEWER_API float getMinRadius() { return minRadius_; }
80
82 Palette& palette() { return *palette_; }
83
85 MRVIEWER_API void updateTexture();
86
88 MRVIEWER_API void updateUVs();
89
91 MRVIEWER_API void enableDeviationVisualization( bool enable );
92
95
98
100 MRVIEWER_API bool sameOriginalMeshTopology() const { return sameOriginalMeshTopology_; }
101
103 MRVIEWER_API Vector2f getMinMax();
104
106 MRVIEWER_API void setIgnoreOcclusion( bool ignore ) { ignoreOcclusion_ = ignore; }
107 MRVIEWER_API bool ignoreOcclusion() const { return ignoreOcclusion_; }
108
111
114
115protected:
117 MRVIEWER_API bool onMouseDown_( MouseButton button, int modifiers ) override;
118
120 MRVIEWER_API bool onMouseUp_( MouseButton button, int modifiers ) override;
121
123 MRVIEWER_API bool onMouseMove_( int mouse_x, int mouse_y ) override;
124
126 MRVIEWER_API void postDraw_() override;
127
130 MRVIEWER_API virtual bool checkModifiers_( int modifiers ) const { return modifiers == 0; }
131
134 MRVIEWER_API virtual void appendMeshDataChangeHistory_( ObjectMeshData&& newMeshData, const FaceBitSet& newFaces );
135
136 void reallocData_( size_t size );
138
141
143 void updateUVmap_( bool set, bool wholeMesh = false );
144 void updateRegion_( const Vector2f& mousePos );
147
150 void laplacianPickVert_( const PointOnFace& pick );
151 void laplacianMoveVert_( const Vector2f& mousePos );
152
154
155 void updateRegionUVs_( const VertBitSet& region );
156 void updateValueChanges_( const VertBitSet& region );
157 void updateValueChangesPointToPoint_( const VertBitSet& region );
158 void updateValueChangesPointToPlane_( const VertBitSet& region );
159 void updateValueChangesExactDistance_( const VertBitSet& region );
162
166
168
169 void updateDistancesAndRegion_( const Mesh& mesh, const std::vector<MeshTriPoint>& start, VertScalars& distances, VertBitSet& region, const VertBitSet* untouchable );
170
172
173 std::shared_ptr<ObjectMesh> obj_;
175 float minRadius_ = 1.f;
176 Vector2f mousePos_;
177 std::vector<MeshTriPoint> pointsUnderMouse_;
181 VertScalars pointsShift_;
184 VertScalars valueChanges_;
186 std::shared_ptr<Mesh> originalMesh_;
187 VertBitSet unknownSign_;
188 std::shared_ptr<ObjectMesh> lastStableObjMesh_;
189 bool firstInit_ = true;
190 bool badRegion_ = false;
191
192 bool mousePressed_ = false;
193
194 boost::signals2::scoped_connection meshChangedConnection_;
196
198
202 Vector2i storedDown_;
203 std::unique_ptr<Laplacian> laplacian_;
204
206 VertBitSet pickedVerts_;
207
209 {
210 Vector3f target;
211 float minMouseDistSq = FLT_MAX;
212 };
213
216
219 std::shared_ptr<VersatileChangeMeshPointsAction> historyAction_;
220
223
224 std::shared_ptr<Palette> palette_;
228
230 bool ignoreOcclusion_ = false;
232};
233
234}
235
Class to hold one dimension texture with value to UV mapping.
Definition MRPalette.h:30
bool editOnlyCodirectedSurface_
Definition MRSurfaceManipulationWidget.h:231
Vector2i storedDown_
initial position of fixed vertex
Definition MRSurfaceManipulationWidget.h:202
DeviationCalculationMethod
Method for calculating mesh changes.
Definition MRSurfaceManipulationWidget.h:40
bool enableDeviationTexture_
Definition MRSurfaceManipulationWidget.h:225
bool appendHistoryAction_
true if historyAction_ is prepared but not yet appended to HistoryStore, which is done on first mouse...
Definition MRSurfaceManipulationWidget.h:222
WorkMode workMode
Definition MRSurfaceManipulationWidget.h:50
MouseButton
Definition MRMouse.h:12
Settings settings_
Definition MRSurfaceManipulationWidget.h:171
void enableDeviationVisualization(bool enable)
enable visualization of mesh deviations
bool connectionsInitialized_
Definition MRSurfaceManipulationWidget.h:197
void setEditOnlyCodirectedSurface(bool edit)
restricts editable area to vertices whose normals look into the same half-space as normal under curso...
Definition MRSurfaceManipulationWidget.h:110
boost::signals2::scoped_connection meshChangedConnection_
Definition MRSurfaceManipulationWidget.h:194
void laplacianMoveVert_(const Vector2f &mousePos)
VertBitSet singleEditingRegion_
current (under the cursor) region of tool application
Definition MRSurfaceManipulationWidget.h:178
bool mousePressed_
in selected region less than 3 points
Definition MRSurfaceManipulationWidget.h:192
EdgeWeights edgeWeights
edge weights for Laplacian and Patch
Definition MRSurfaceManipulationWidget.h:56
float relaxForce
speed of relaxing, typical values (0 - 0.5]
Definition MRSurfaceManipulationWidget.h:52
ImVec2 size(const ViewportRectangle &rect)
Definition MRViewport.h:32
bool sameOriginalMeshTopology_
Definition MRSurfaceManipulationWidget.h:227
void initLaplacian_(RememberShape rs)
Laplacian.
VertScalars pointsShift_
Definition MRSurfaceManipulationWidget.h:181
std::shared_ptr< Palette > palette_
Definition MRSurfaceManipulationWidget.h:224
float radius
radius of editing region
Definition MRSurfaceManipulationWidget.h:51
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:106
float minRadius_
Definition MRSurfaceManipulationWidget.h:175
bool subdivideGrooves
if true in Add/Remove modes, changed parts of mesh will be subdivided on mouse up
Definition MRSurfaceManipulationWidget.h:59
VertId touchVertId_
Laplacian.
Definition MRSurfaceManipulationWidget.h:200
void init(const std::shared_ptr< ObjectMesh > &objectMesh)
initialize widget according ObjectMesh
VertScalars valueChanges_
Definition MRSurfaceManipulationWidget.h:184
std::unique_ptr< Laplacian > laplacian_
Definition MRSurfaceManipulationWidget.h:203
VertScalars lastStableValueChanges_
Definition MRSurfaceManipulationWidget.h:185
VertBitSet pickedVerts_
these are all vertices, which will are attracted to be under mouse considering material width since l...
Definition MRSurfaceManipulationWidget.h:206
void updateRegionUVs_(const VertBitSet &region)
DeviationCalculationMethod deviationCalculationMethod_
Definition MRSurfaceManipulationWidget.h:226
void setDeviationCalculationMethod(DeviationCalculationMethod method)
set method for calculating mesh changes
VertBitSet visualizationRegion_
vertices of triangles partially or fully highlighted with red
Definition MRSurfaceManipulationWidget.h:179
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
const Settings & getSettings()
get widget settings
Definition MRSurfaceManipulationWidget.h:76
void updateUVs()
update texture uv coords used for colorize surface (use after change ranges in palette)
void reset()
reset widget state
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
Definition MRSurfaceManipulationWidget.h:97
bool firstInit_
Definition MRSurfaceManipulationWidget.h:189
std::shared_ptr< ObjectMesh > obj_
Definition MRSurfaceManipulationWidget.h:173
bool laplacianBasedAddRemove
if true in Add/Remove modes, the modification will be done using Laplacian solver,...
Definition MRSurfaceManipulationWidget.h:58
std::shared_ptr< VersatileChangeMeshPointsAction > historyAction_
Definition MRSurfaceManipulationWidget.h:219
bool ignoreOcclusion_
allow the user to edit parts of object that are hidden in the current view by other objects
Definition MRSurfaceManipulationWidget.h:230
void updateValueChanges_(const VertBitSet &region)
float getMinRadius()
minimum radius of editing area.
Definition MRSurfaceManipulationWidget.h:79
Vector3f touchVertIniPos_
we fix this vertex in Laplacian and move it manually
Definition MRSurfaceManipulationWidget.h:201
std::vector< MeshTriPoint > pointsUnderMouse_
mesh points under mouse in the current frame (could be many in case of fast mouse movement)
Definition MRSurfaceManipulationWidget.h:177
bool sameOriginalMeshTopology() const
returns true if the current object's mesh has the same topology as original input mesh (and vertices ...
Definition MRSurfaceManipulationWidget.h:100
VertBitSet unchangeableVerts_
Definition MRSurfaceManipulationWidget.h:174
std::shared_ptr< ObjectMesh > lastStableObjMesh_
Definition MRSurfaceManipulationWidget.h:188
void updateValueChangesExactDistance_(const VertBitSet &region)
RememberShape
Definition MREnums.h:56
VertexMass vmass
vertex weights for Laplacian and Patch
Definition MRSurfaceManipulationWidget.h:57
WorkMode
widget work modes
Definition MRSurfaceManipulationWidget.h:30
float editForce
material thickness added or removed to the surface
Definition MRSurfaceManipulationWidget.h:53
bool badRegion_
need to save settings in re-initial
Definition MRSurfaceManipulationWidget.h:190
float relaxForceAfterEdit
force of relaxing modified area after editing (add / remove) is complete. [0 - 0.5],...
Definition MRSurfaceManipulationWidget.h:55
bool ownMeshChangedSignal_
Definition MRSurfaceManipulationWidget.h:195
void updateRegion_(const Vector2f &mousePos)
void setFixedRegion(const FaceBitSet &region)
Vector3f target
Definition MRSurfaceManipulationWidget.h:210
Palette & palette()
get palette used for visualization point shifts
Definition MRSurfaceManipulationWidget.h:82
std::shared_ptr< Mesh > originalMesh_
original input mesh
Definition MRSurfaceManipulationWidget.h:186
VertBitSet unknownSign_
cached data to avoid reallocating memory
Definition MRSurfaceManipulationWidget.h:187
float sharpness
effect of force on points far from center editing area. [0 - 100]
Definition MRSurfaceManipulationWidget.h:54
virtual void appendMeshDataChangeHistory_(ObjectMeshData &&newMeshData, const FaceBitSet &newFaces)
VertBitSet generalEditingRegion_
united region of tool application since the last mouse down
Definition MRSurfaceManipulationWidget.h:180
bool isEditOnlyCodirectedSurface() const
get state of an editable region restriction
Definition MRSurfaceManipulationWidget.h:113
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)
void updateUVmap_(bool set, bool wholeMesh=false)
void postDraw_() override
need to visualize bad region (draw grey circle)
VertScalars editingDistanceMap_
Definition MRSurfaceManipulationWidget.h:182
bool ignoreOcclusion() const
Definition MRSurfaceManipulationWidget.h:107
void setSettings(const Settings &settings)
set widget settings (mesh change settings)
VertScalars visualizationDistanceMap_
Definition MRSurfaceManipulationWidget.h:183
bool onMouseMove_(int mouse_x, int mouse_y) override
update
Vector2f getMinMax()
get min / max point shifts for (useful for setup palette)
float minMouseDistSq
attraction point
Definition MRSurfaceManipulationWidget.h:211
void updateValueChangesPointToPlane_(const VertBitSet &region)
phmap::flat_hash_map< K, V, Hash, Eq > HashMap
Definition MRMeshFwd.h:606
virtual bool checkModifiers_(int modifiers) const
Definition MRSurfaceManipulationWidget.h:130
Vector2f mousePos_
mouse position of last updateRegion_
Definition MRSurfaceManipulationWidget.h:176
HashMap< VertId, PickedVertData > pickedVertsToData_
same vertices as in pickedVerts_ mapped to PickedVertData
Definition MRSurfaceManipulationWidget.h:215
@ 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 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
Definition MRSurfaceManipulationWidget.h:209
Mesh change settings.
Definition MRSurfaceManipulationWidget.h:49