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{
17
18
20class MRVIEWER_CLASS SurfacePointWidget : public MultiListener<PreDrawListener, MouseDownListener, MouseMoveListener, MouseUpListener>
21{
22public:
23 MRVIEWER_API ~SurfacePointWidget();
24
25 enum class PositionType
26 {
27 Faces,
28 FaceCenters,
29 Edges,
30 EdgeCenters,
31 Verts
32 };
33
35 {
36 enum class PointSizeType {
37 Metrical,
38 Pixel
39 };
41 PositionType positionType{ PositionType::Faces };
43 Color baseColor{ Color::gray() };
45 Color hoveredColor{ Color::red() };
47 Color activeColor{ { Color::red() } };
49 PointSizeType radiusSizeType{ PointSizeType::Pixel };
52 float radius{ 0.0f };
55 int customModifiers = 0;
57 bool pickInBackFaceObject = true;
58 };
59
62 MRVIEWER_API const PickedPoint& create( const std::shared_ptr<VisualObject>& surface, const PointOnObject& startPos );
63 MRVIEWER_API const PickedPoint& create( const std::shared_ptr<VisualObject>& surface, const PickedPoint& startPos );
64
66 MRVIEWER_API void reset();
68 const std::shared_ptr<SphereObject>& getPickSphere() const
69 {
70 return pickSphere_;
71 }
74 {
75 return params_;
76 }
77
79 MRVIEWER_API void setParameters( const Parameters& params );
80
82 MRVIEWER_API void setBaseColor( const Color& color );
83
86 MRVIEWER_API void updateParameters( const std::function<void ( Parameters& )>& visitor );
87
90 bool getAutoHover()const
91 {
92 return autoHover_;
93 }
94 void setAutoHover( bool on )
95 {
96 autoHover_ = on;
97 }
100 MRVIEWER_API void setHovered( bool on );
101
104 {
105 return currentPos_;
106 }
107
109 MRVIEWER_API Vector3f getCoords() const;
110 [[deprecated]] Vector3f toVector3f() const { return getCoords(); }
111
113 std::optional<Vector3f> findCoords() const { return getPickedPointPosition( *baseObject_, currentPos_ ); }
114
116 std::optional<Vector3f> findNormal() const { return getPickedPointNormal( *baseObject_, currentPos_ ); }
117
120 {
121 if ( const MeshTriPoint* triPoint = std::get_if<MeshTriPoint>( &currentPos_ ) )
122 return *triPoint;
123 else
124 return {};
125 }
126
128 MRVIEWER_API void setCurrentPosition( const PointOnObject& pos );
129
131 MRVIEWER_API void setCurrentPosition( const PickedPoint& pos );
132
134 MRVIEWER_API void swapCurrentPosition( PickedPoint& pos );
135
137 void setCanMoveCallback( std::function<bool( SurfacePointWidget&, const PickedPoint& )> canMove )
138 {
139 canMove_ = std::move( canMove );
140 }
142 void setStartMoveCallback( std::function<void( SurfacePointWidget &, const PickedPoint& )> startMove )
143 {
144 startMove_ = std::move( startMove );
145 }
147 void setOnMoveCallback( std::function<void( SurfacePointWidget &, const PickedPoint& )> onMove )
148 {
149 onMove_ = std::move( onMove );
150 }
152 void setEndMoveCallback( std::function<void( SurfacePointWidget &, const PickedPoint& )> endMove )
153 {
154 endMove_ = std::move( endMove );
155 }
156
157 std::shared_ptr<VisualObject>& getBaseSurface()
158 {
159 return baseObject_;
160 }
161
163 [[nodiscard]] bool isOnMove() const { return isOnMove_; }
164
166 [[nodiscard]] static bool isPickIntoBackFace( const std::shared_ptr<MR::VisualObject>& obj, const MR::PointOnObject& pick, const Vector3f& cameraEye );
167
173
174private:
175 MRVIEWER_API virtual bool onMouseDown_( MouseButton button, int modifier ) override;
176 MRVIEWER_API virtual bool onMouseUp_( MouseButton button, int modifier ) override;
177 MRVIEWER_API virtual bool onMouseMove_( int mouse_x, int mouse_y ) override;
178
179 void updatePositionAndRadius_();
180 void updatePositionAndRadiusMesh_( MeshTriPoint mtp );
181
182 Parameters params_;
183
184 bool autoHover_{ true };
185 bool isOnMove_{ false };
186 bool isHovered_{ false };
187 MRVIEWER_API void preDraw_() override;
188
189 PickedPoint currentPos_;
190
191 std::shared_ptr<SphereObject> pickSphere_;
192 std::shared_ptr<VisualObject> baseObject_;
193
194 boost::signals2::scoped_connection onBaseObjectWorldXfChanged_;
195
196 std::function<bool( SurfacePointWidget &, const PickedPoint& )> canMove_;
197 std::function<void( SurfacePointWidget &, const PickedPoint& )> startMove_;
198 std::function<void( SurfacePointWidget &, const PickedPoint& )> onMove_;
199 std::function<void( SurfacePointWidget &, const PickedPoint& )> endMove_;
200
202 void setPointRadius_();
203
205 void setSphereColor_();
206};
207
208}
Widget for controlling point on surface with mouse.
Definition MRSurfacePointPicker.h:21
void setOnMoveCallback(std::function< void(SurfacePointWidget &, const PickedPoint &)> onMove)
this callback is called on modification if it is set
Definition MRSurfacePointPicker.h:147
const std::shared_ptr< SphereObject > & getPickSphere() const
returns object of control sphere
Definition MRSurfacePointPicker.h:68
std::optional< Vector3f > findNormal() const
return the normal in local object's coordinates at the current position, or std::nullopt if it is inv...
Definition MRSurfacePointPicker.h:116
void setEndMoveCallback(std::function< void(SurfacePointWidget &, const PickedPoint &)> endMove)
this callback is called when modification ends if it is set
Definition MRSurfacePointPicker.h:152
MouseButton
Definition MRMouse.h:12
Faces
Definition MRObjectMeshHolder.h:17
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
Edges
Definition MRObjectMeshHolder.h:19
std::variant< std::monostate, MeshTriPoint, EdgePoint, VertId > PickedPoint
Definition MRPointOnObject.h:45
MRVIEWER_API void setHovered(bool on)
std::optional< Vector3f > findCoords() const
return local object's coordinates at the current position, or std::nullopt if it is invalid
Definition MRSurfacePointPicker.h:113
void setCanMoveCallback(std::function< bool(SurfacePointWidget &, const PickedPoint &)> canMove)
this callback is called before modification starts if it is set, and can cancel it by returning false
Definition MRSurfacePointPicker.h:137
MRVIEWER_API void setBaseColor(const Color &color)
set baseColor parameter for this widget
MeshTriPoint getCurrentPositionMeshTriPoint() const
returns stored position as MeshTriPoint, otherwise returns invalid (default) MeshTriPoint
Definition MRSurfacePointPicker.h:119
PointSizeType
Definition MRSurfacePointPicker.h:36
MRVIEWER_API void setParameters(const Parameters &params)
set parameters for this widget
bool getAutoHover() const
Definition MRSurfacePointPicker.h:90
MRVIEWER_API ~SurfacePointWidget()
MRMESH_API Vector3f triPoint(const MeshTopology &topology, const VertCoords &points, const MeshTriPoint &p)
computes coordinates of point given as face and barycentric representation
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
returns whether is the widget moving
Definition MRSurfacePointPicker.h:163
std::shared_ptr< VisualObject > & getBaseSurface()
Definition MRSurfacePointPicker.h:157
static bool isPickIntoBackFace(const std::shared_ptr< MR::VisualObject > &obj, const MR::PointOnObject &pick, const Vector3f &cameraEye)
Checks whether the current peak is a peak in the invisible (reverse) side of the mesh or cloud point.
const Parameters & getParameters() const
get current setup of this widget
Definition MRSurfacePointPicker.h:73
MRVIEWER_API const PickedPoint & create(const std::shared_ptr< VisualObject > &surface, const PickedPoint &startPos)
MRVIEWER_API Vector3f getCoords() const
return local object's coordinates at the current position where the center of sphere is located
void setStartMoveCallback(std::function< void(SurfacePointWidget &, const PickedPoint &)> startMove)
this callback is called when modification starts if it is set
Definition MRSurfacePointPicker.h:142
Vector3f toVector3f() const
Definition MRSurfacePointPicker.h:110
PositionType
Definition MRSurfacePointPicker.h:26
MRVIEWER_API void reset()
resets whole widget
const PickedPoint & getCurrentPosition() const
returns stored position of this widget
Definition MRSurfacePointPicker.h:103
MRMESH_API std::optional< Vector3f > getPickedPointPosition(const VisualObject &object, const PickedPoint &point)
void setAutoHover(bool on)
Definition MRSurfacePointPicker.h:94
MRMESH_API std::optional< Vector3f > getPickedPointNormal(const VisualObject &object, const PickedPoint &point, bool interpolated=true)
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRColor.h:12
Definition MRMeshTriPoint.h:26
Definition MRViewerEventsListener.h:32
Definition MRPointOnObject.h:21
Definition MRSurfacePointPicker.h:35