MeshLib C++ Docs
Loading...
Searching...
No Matches
MRSurfacePointPicker.h
Go to the documentation of this file.
1#pragma once
2
4
5#include "MRMesh/MRMeshFwd.h"
6#include "MRMesh/MRVector3.h"
8#include <MRMesh/MRColor.h>
10
11#include <functional>
12
13namespace MR
14{
15
16// Widget for controlling point on surface with mouse
17class MRVIEWER_CLASS SurfacePointWidget : public MultiListener<PreDrawListener, MouseDownListener, MouseMoveListener, MouseUpListener>
18{
19public:
20 MRVIEWER_API ~SurfacePointWidget();
21
22 enum class PositionType
23 {
24 Faces, // point can be in any place of surface
25 FaceCenters, // point can be only in face center
26 Edges, // point can be only on edges
27 EdgeCeneters, // point can be only in edge center
28 Verts // point can be only in vertex
29 };
30
32 {
33 enum class PointSizeType {
34 Metrical, // point size in mm
35 Pixel // point size in pixels (will automatically be multipled by the UI scale)
36 };
37 // type of point positioning, look at PositionType comments for more info
38 PositionType positionType{ PositionType::Faces };
39 // basic color of control sphere
40 Color baseColor{ Color::gray() };
41 // color of control sphere when it is hovered by mouse
42 Color hoveredColor{ Color::red() };
43 // color of control sphere when it is in move
44 Color activeColor{ { Color::red() } };
45 // how to set the size of the dots in mm or in pixels.
46 PointSizeType radiusSizeType{ PointSizeType::Pixel };
47 // Radius of control sphere. If <= 0.0f, uses a default value (a certain fraction of the AABB diagnoal of the target object for `radiusSizeType == Metrical`, or a fixed pixel size for `radiusSizeType == Pixel`).
48 // When `radiusSizeType == Pixel`, this is automatically multiplied by the current UI scale, you don't need to do that yourself.
49 float radius{ 0.0f };
50 // Typically, the widget does not respond to actions with a modifier.
51 // If the parameter is set, then custom modifiers located in this GLFW bitmask will be ignored and the widget will work with them as usual.
52 int customModifiers = 0; // GLFW modifier bitmask
53 // pick_render_object parameters. Allow to use object in which pick exactly fell, instead of closer object in pick radius.
54 bool pickInBackFaceObject = true;
55 };
56
57 // creates control sphere in start pos
58 // returns updated pos if it was moved according to PositionType
59 MRVIEWER_API const PickedPoint& create( const std::shared_ptr<VisualObject>& surface, const PointOnObject& startPos );
60 MRVIEWER_API const PickedPoint& create( const std::shared_ptr<VisualObject>& surface, const PickedPoint& startPos );
61
62 // resets whole widget
63 MRVIEWER_API void reset();
64 // returns object of control sphere
65 const std::shared_ptr<SphereObject>& getPickSphere() const
66 {
67 return pickSphere_;
68 }
69 // get current setup of this widget
71 {
72 return params_;
73 }
74
75 // set parameters for this widget
76 MRVIEWER_API void setParameters( const Parameters& params );
77
78 // set baseColor parameter for this widget
79 MRVIEWER_API void setBaseColor( const Color& color );
80
83 MRVIEWER_API void updateParameters( const std::function<void ( Parameters& )>& visitor );
84
85 // if auto hover is enabled, pick_render_object() is used
86 // !note: disabling it is useful if there are many widgets, not to call `pick_render_object()` for each of them separately
87 bool getAutoHover()const
88 {
89 return autoHover_;
90 }
91 void setAutoHover( bool on )
92 {
93 autoHover_ = on;
94 }
95 // function for manual enable and disable hover mode
96 // use it if auto hover is disabled
97 MRVIEWER_API void setHovered( bool on );
98
99 // returns stored position of this widget
101 {
102 return currentPos_;
103 }
104
106 MRVIEWER_API Vector3f toVector3f() const;
107
110 {
111 if ( const MeshTriPoint* triPoint = std::get_if<MeshTriPoint>( &currentPos_ ) )
112 return *triPoint;
113 else
114 return {};
115 }
116
118 MRVIEWER_API void setCurrentPosition( const PointOnObject& pos );
119
121 MRVIEWER_API void setCurrentPosition( const PickedPoint& pos );
122
124 MRVIEWER_API void swapCurrentPosition( PickedPoint& pos );
125
126 // this callback is called when modification starts if it is set
127 void setStartMoveCallback( std::function<void( SurfacePointWidget &, const PickedPoint& )> startMove )
128 {
129 startMove_ = startMove;
130 }
131 // this callback is called on modification if it is set
132 void setOnMoveCallback( std::function<void( SurfacePointWidget &, const PickedPoint& )> onMove )
133 {
134 onMove_ = onMove;
135 }
136 // this callback is called when modification ends if it is set
137 void setEndMoveCallback( std::function<void( SurfacePointWidget &, const PickedPoint& )> endMove )
138 {
139 endMove_ = endMove;
140 }
141
142 std::shared_ptr<VisualObject>& getBaseSurface()
143 {
144 return baseObject_;
145 }
146
147 // returns whether is the widget moving
148 [[nodiscard]] bool isOnMove() const { return isOnMove_; }
149
150 // Checks whether the current peak is a peak in the invisible (reverse) side of the mesh or cloud point.
151 [[nodiscard]] static bool isPickIntoBackFace( const std::shared_ptr<MR::VisualObject>& obj, const MR::PointOnObject& pick, const Vector3f& cameraEye );
152
153private:
154 MRVIEWER_API virtual bool onMouseDown_( MouseButton button, int modifier ) override;
155 MRVIEWER_API virtual bool onMouseUp_( MouseButton button, int modifier ) override;
156 MRVIEWER_API virtual bool onMouseMove_( int mouse_x, int mouse_y ) override;
157
158 void updatePositionAndRadius_();
159 void updatePositionAndRadiusMesh_( MeshTriPoint mtp );
160 void updatePositionAndRadiusPoints_( const VertId& v );
161 void updatePositionAndRadiusLines_( const EdgePoint& ep );
162
163 Parameters params_;
164
165 bool autoHover_{ true };
166 bool isOnMove_{ false };
167 bool isHovered_{ false };
168 MRVIEWER_API void preDraw_() override;
169
170 PickedPoint currentPos_;
171
172 std::shared_ptr<SphereObject> pickSphere_;
173 std::shared_ptr<VisualObject> baseObject_;
174
175 boost::signals2::scoped_connection onBaseObjectWorldXfChanged_;
176
177 std::function<void( SurfacePointWidget &, const PickedPoint& )> startMove_;
178 std::function<void( SurfacePointWidget &, const PickedPoint& )> onMove_;
179 std::function<void( SurfacePointWidget &, const PickedPoint& )> endMove_;
180
181 // Depending on the type of selected size, sets the point size
182 void setPointRadius_();
183
184};
185
186
187
188}
Faces
Definition MRObjectMeshHolder.h:12
Edges
Definition MRObjectMeshHolder.h:14
Definition MRSurfacePointPicker.h:18
void setOnMoveCallback(std::function< void(SurfacePointWidget &, const PickedPoint &)> onMove)
Definition MRSurfacePointPicker.h:132
const std::shared_ptr< SphereObject > & getPickSphere() const
Definition MRSurfacePointPicker.h:65
void setEndMoveCallback(std::function< void(SurfacePointWidget &, const PickedPoint &)> endMove)
Definition MRSurfacePointPicker.h:137
MRVIEWER_API void setCurrentPosition(const PickedPoint &pos)
sets new position for the widget
MRVIEWER_API void setCurrentPosition(const PointOnObject &pos)
sets new position for the widget
MRVIEWER_API void swapCurrentPosition(PickedPoint &pos)
sets new position for the widget and returns previous position in the argument
MRVIEWER_API void setHovered(bool on)
MRVIEWER_API void setBaseColor(const Color &color)
MeshTriPoint getCurrentPositionMeshTriPoint() const
returns stored position as MeshTriPoint, otherwise returns invalid (default) MeshTriPoint
Definition MRSurfacePointPicker.h:109
MRVIEWER_API void setParameters(const Parameters &params)
bool getAutoHover() const
Definition MRSurfacePointPicker.h:87
MRVIEWER_API ~SurfacePointWidget()
MRVIEWER_API const PickedPoint & create(const std::shared_ptr< VisualObject > &surface, const PointOnObject &startPos)
MRVIEWER_API void updateParameters(const std::function< void(Parameters &)> &visitor)
bool isOnMove() const
Definition MRSurfacePointPicker.h:148
std::shared_ptr< VisualObject > & getBaseSurface()
Definition MRSurfacePointPicker.h:142
static bool isPickIntoBackFace(const std::shared_ptr< MR::VisualObject > &obj, const MR::PointOnObject &pick, const Vector3f &cameraEye)
const Parameters & getParameters() const
Definition MRSurfacePointPicker.h:70
MRVIEWER_API const PickedPoint & create(const std::shared_ptr< VisualObject > &surface, const PickedPoint &startPos)
void setStartMoveCallback(std::function< void(SurfacePointWidget &, const PickedPoint &)> startMove)
Definition MRSurfacePointPicker.h:127
PositionType
Definition MRSurfacePointPicker.h:23
MRVIEWER_API void reset()
const PickedPoint & getCurrentPosition() const
Definition MRSurfacePointPicker.h:100
void setAutoHover(bool on)
Definition MRSurfacePointPicker.h:91
MRVIEWER_API Vector3f toVector3f() const
return current position transformed to Vector3f
MouseButton
Definition MRMouse.h:9
std::variant< MeshTriPoint, EdgePoint, VertId, int > PickedPoint
Definition MRPointOnObject.h:40
Definition MRMesh/MRColor.h:9
encodes a point on an edge of mesh or of polyline
Definition MREdgePoint.h:11
Definition MRMesh/MRMeshTriPoint.h:23
Definition MRViewerEventsListener.h:29
Definition MRPointOnObject.h:16
Definition MRSurfacePointPicker.h:32
PointSizeType
Definition MRSurfacePointPicker.h:33