MeshLib Documentation
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#include <optional>
13
14namespace MR
15{
16
17// Widget for controlling point on surface with mouse
18class MRVIEWER_CLASS SurfacePointWidget : public MultiListener<PreDrawListener, MouseDownListener, MouseMoveListener, MouseUpListener>
19{
20public:
21 MRVIEWER_API ~SurfacePointWidget();
22
23 enum class PositionType
24 {
25 Faces, // point can be in any place of surface
26 FaceCenters, // point can be only in face center
27 Edges, // point can be only on edges
28 EdgeCeneters, // point can be only in edge center
29 Verts // point can be only in vertex
30 };
31
33 {
34 enum class PointSizeType {
35 Metrical, // point size in mm
36 Pixel // point size in pixels
37 };
38 // type of point positioning, look at PositionType comments for more info
39 PositionType positionType{ PositionType::Faces };
40 // basic color of control sphere
41 Color baseColor{ Color::gray() };
42 // color of control sphere when it is hovered by mouse
43 Color hoveredColor{ Color::red() };
44 // color of control sphere when it is in move
45 Color activeColor{ { Color::red() } };
46 // how to set the size of the dots in mm or in pixels.
47 PointSizeType radiusSizeType{ PointSizeType::Metrical };
48 // radius of control sphere, if <= 0.0f it is equal to 5e-3*box.diagonal()
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 std::shared_ptr<SphereObject> getPickSphere() const
66 {
67 return pickSphere_;
68 }
69 // get current setup of this widget
71 {
72 return params_;
73 }
74 // set parameters for this widget
75 MRVIEWER_API void setParameters( const Parameters& params );
78 MRVIEWER_API void updateParameters( const std::function<void ( Parameters& )>& visitor );
79
80 // if auto hover is enabled, pick_render_object() is used
81 // !note: disabling it is useful if there are many widgets, not to call `pick_render_object()` for each of them separately
82 bool getAutoHover()const
83 {
84 return autoHover_;
85 }
86 void setAutoHover( bool on )
87 {
88 autoHover_ = on;
89 }
90 // function for manual enable and disable hover mode
91 // use it if auto hover is disabled
92 MRVIEWER_API void setHovered( bool on );
93
94 // returns stored position of this widget
96 {
97 return currentPos_;
98 }
99
100 // return current position transformed to Vector3f
101 MRVIEWER_API Vector3f toVector3f() const;
102
103 // returns stored position in MeshTriPointFormat if it is possible
104 std::optional<MeshTriPoint> getCurrentPositionMeshTriPoint() const
105 {
106 if ( const MeshTriPoint* triPoint = std::get_if<MeshTriPoint>( &currentPos_ ) )
107 return *triPoint;
108 else
109 return std::nullopt;
110 }
111
112 MRVIEWER_API void updateCurrentPosition( const PointOnObject& pos );
113 MRVIEWER_API void updateCurrentPosition( const PickedPoint& pos );
114
115 // this callback is called when modification starts if it is set
116 void setStartMoveCallback( std::function<void( const PickedPoint& )> startMove )
117 {
118 startMove_ = startMove;
119 }
120 // this callback is called on modification if it is set
121 void setOnMoveCallback( std::function<void( const PickedPoint& )> onMove )
122 {
123 onMove_ = onMove;
124 }
125 // this callback is called when modification ends if it is set
126 void setEndMoveCallback( std::function<void( const PickedPoint& )> endMove )
127 {
128 endMove_ = endMove;
129 }
130
131 std::shared_ptr<VisualObject>& getBaseSurface()
132 {
133 return baseObject_;
134 }
135
136 // returns whether is the widget moving
137 [[nodiscard]] bool isOnMove() const { return isOnMove_; }
138
139 // Checks whether the current peak is a peak in the invisible (reverse) side of the mesh or cloud point.
140 [[nodiscard]] static bool isPickIntoBackFace( const std::shared_ptr<MR::VisualObject>& obj, const MR::PointOnObject& pick, const Vector3f& cameraEye );
141
142private:
143 MRVIEWER_API virtual bool onMouseDown_( MouseButton button, int modifier ) override;
144 MRVIEWER_API virtual bool onMouseUp_( MouseButton button, int modifier ) override;
145 MRVIEWER_API virtual bool onMouseMove_( int mouse_x, int mouse_y ) override;
146
147 void updatePositionAndRadius_();
148 void updatePositionAndRadiusMesh_( MeshTriPoint mtp );
149 void updatePositionAndRadiusPoints_( const VertId& v );
150 void updatePositionAndRadiusLines_( const EdgePoint& ep );
151
152 Parameters params_;
153
154 bool autoHover_{ true };
155 bool isOnMove_{ false };
156 bool isHovered_{ false };
157 MRVIEWER_API void preDraw_() override;
158
159 PickedPoint currentPos_;
160
161 std::shared_ptr<SphereObject> pickSphere_;
162 std::shared_ptr<VisualObject> baseObject_;
163
164 boost::signals2::scoped_connection onBaseObjectWorldXfChanged_;
165
166 std::function<void( const PickedPoint& )> startMove_;
167 std::function<void( const PickedPoint& )> onMove_;
168 std::function<void( const PickedPoint& )> endMove_;
169
170 // Depending on the type of selected size, sets the point size
171 void setPointRadius_();
172
173};
174
175
176
177}
Faces
Definition MRObjectMeshHolder.h:12
Edges
Definition MRObjectMeshHolder.h:14
Definition MRSurfacePointPicker.h:19
void setOnMoveCallback(std::function< void(const PickedPoint &)> onMove)
Definition MRSurfacePointPicker.h:121
MRVIEWER_API void setHovered(bool on)
void setEndMoveCallback(std::function< void(const PickedPoint &)> endMove)
Definition MRSurfacePointPicker.h:126
MRVIEWER_API void updateCurrentPosition(const PickedPoint &pos)
std::optional< MeshTriPoint > getCurrentPositionMeshTriPoint() const
Definition MRSurfacePointPicker.h:104
void setStartMoveCallback(std::function< void(const PickedPoint &)> startMove)
Definition MRSurfacePointPicker.h:116
MRVIEWER_API void setParameters(const Parameters &params)
bool getAutoHover() const
Definition MRSurfacePointPicker.h:82
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:137
std::shared_ptr< VisualObject > & getBaseSurface()
Definition MRSurfacePointPicker.h:131
static bool isPickIntoBackFace(const std::shared_ptr< MR::VisualObject > &obj, const MR::PointOnObject &pick, const Vector3f &cameraEye)
std::shared_ptr< SphereObject > getPickSphere() const
Definition MRSurfacePointPicker.h:65
const Parameters & getParameters() const
Definition MRSurfacePointPicker.h:70
MRVIEWER_API void updateCurrentPosition(const PointOnObject &pos)
MRVIEWER_API const PickedPoint & create(const std::shared_ptr< VisualObject > &surface, const PickedPoint &startPos)
PositionType
Definition MRSurfacePointPicker.h:24
MRVIEWER_API void reset()
const PickedPoint & getCurrentPosition() const
Definition MRSurfacePointPicker.h:95
void setAutoHover(bool on)
Definition MRSurfacePointPicker.h:86
MRVIEWER_API Vector3f toVector3f() const
Definition MRCameraOrientationPlugin.h:8
MouseButton
Definition MRMouse.h:9
std::variant< MeshTriPoint, EdgePoint, VertId, int > PickedPoint
Definition MRPointOnObject.h:40
Definition 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:33
PointSizeType
Definition MRSurfacePointPicker.h:34