MeshLib C++ Docs
Loading...
Searching...
No Matches
MRPickPointManager.h
Go to the documentation of this file.
1#pragma once
2
4#include "MRViewport.h"
6#include "MRHistoryStore.h"
8#include "MRMesh/MRMeshFwd.h"
10#include <MRMesh/MRphmap.h>
11#include <unordered_map>
12
13namespace MR
14{
17
18
21class MRVIEWER_CLASS PickPointManager : public MultiListener<
22 MouseDownListener,
23 MouseMoveListener>
24{
25public:
26 using PickerPointCallBack = std::function<void( std::shared_ptr<VisualObject> obj, int index )>;
27 using AllowCallBack = std::function<bool( const std::shared_ptr<VisualObject>& obj, int index )>;
28 using ChangeObjectCallBack = std::function<bool( const std::shared_ptr<VisualObject>& obj )>;
29
30 struct Params
31 {
33 int widgetContourCloseMod = getGlfwModPrimaryCtrl();
34
36 int widgetDeletePointMod = GLFW_MOD_SHIFT;
37
39 bool writeHistory = true;
40
42 std::string historyNameSuffix;
43
45 bool startDraggingJustAddedPoint = true;
46
50
52 Color ordinaryPointColor = Color::gray();
53
55 Color lastPointColor = Color::green();
56
58 Color closeContourPointColor = Color::transparent();
59
62
66
69
73
76
79
82
86
89
93
94 };
96
99
100 using SurfaceContour = std::vector<std::shared_ptr<SurfacePointWidget>>;
101 using SurfaceContours = std::unordered_map <std::shared_ptr<VisualObject>, SurfaceContour>;
102
104 MRVIEWER_API PickPointManager();
105
107 MRVIEWER_API ~PickPointManager();
108
110 [[nodiscard]] const SurfaceContour& getSurfaceContour( const std::shared_ptr<VisualObject>& obj ) { return pickedPoints_[obj]; }
111
113 [[nodiscard]] const SurfaceContours& getSurfaceContours() const { return pickedPoints_; }
114
116 [[nodiscard]] MRVIEWER_API bool isClosedContour( const std::shared_ptr<VisualObject>& obj ) const;
117
119 [[nodiscard]] MRVIEWER_API size_t numPickPoints( const std::shared_ptr<VisualObject>& obj ) const;
120
122 [[nodiscard]] MRVIEWER_API std::shared_ptr<SurfacePointWidget> getPointWidget( const std::shared_ptr<VisualObject>& obj, int index ) const;
123
125 [[nodiscard]] MRVIEWER_API int getPointIndex( const std::shared_ptr<VisualObject>& obj, SurfacePointWidget& pointWidget ) const;
126
128 [[nodiscard]] SurfacePointWidget* draggedPointWidget() const { return draggedPointWidget_; }
129
132 MRVIEWER_API bool appendPoint( const std::shared_ptr<VisualObject>& obj, const PickedPoint& triPoint, bool startDragging = false );
133
137 MRVIEWER_API bool insertPoint( const std::shared_ptr<VisualObject>& obj, int index, const PickedPoint& triPoint, bool startDragging = false );
138
140 MRVIEWER_API bool removePoint( const std::shared_ptr<VisualObject>& obj, int pickedIndex );
141
145 MRVIEWER_API bool closeContour( const std::shared_ptr<VisualObject>& obj, bool makeClosed = true );
146
148 {
149 std::weak_ptr<VisualObject> objPtr;
150 std::vector<PickedPoint> pickedPoints;
151 };
152 using FullState = std::vector<ObjectState>;
153
155 MRVIEWER_API FullState getFullState() const;
156
158 MRVIEWER_API void clear();
159
161 MRVIEWER_API void setFullState( FullState s );
162
163private:
164 MRVIEWER_API bool onMouseDown_( MouseButton button, int modifier ) override;
165 MRVIEWER_API bool onMouseMove_( int mouse_x, int mouse_y ) override;
166
167 ObjAndPick pick_() const;
168
171 void colorLast2Points_( const std::shared_ptr<VisualObject>& obj );
172
174 [[nodiscard]] std::shared_ptr<SurfacePointWidget> createPickWidget_( const std::shared_ptr<VisualObject>& obj, const PickedPoint& pt );
175
177 void clearNoHistory_();
178
181 void swapStateNoHistory_( FullState& s );
182
185 int insertPointNoHistory_( const std::shared_ptr<VisualObject>& obj, int index, const PickedPoint& point, bool startDragging );
186
188 PickedPoint removePointNoHistory_( const std::shared_ptr<VisualObject>& obj, int index );
189
191 template<class HistoryActionType, typename... Args>
192 void appendHistory_( Args&&... args );
193
195 void appendHistory_( std::shared_ptr<HistoryAction> action ) const;
196
198 void setHoveredPointWidget_( SurfacePointWidget* newHoveredPoint );
199
201 bool moveClosedPoint_ = false;
202
204 SurfacePointWidget* hoveredPointWidget_ = nullptr;
205
207 SurfacePointWidget* draggedPointWidget_ = nullptr;
208
210 SurfaceContours pickedPoints_;
211
213 HashSet<const VisualObject*> myPickSpheres_;
214
216 struct ConnectionHolder
217 {
218 boost::signals2::scoped_connection onMeshChanged;
219 boost::signals2::scoped_connection onPointsChanged;
220 };
221 HashMap<std::shared_ptr<VisualObject>, ConnectionHolder> connectionHolders_;
222
224 class SetStateHistoryAction;
225 class AddRemovePointHistoryAction;
226 class MovePointHistoryAction;
227};
228
229}
Definition MRHistoryAction.h:15
Definition MRPickPointManager.h:24
Widget for controlling point on surface with mouse.
Definition MRSurfacePointPicker.h:21
MRVIEWER_API bool insertPoint(const std::shared_ptr< VisualObject > &obj, int index, const PickedPoint &triPoint, bool startDragging=false)
const SurfaceContour & getSurfaceContour(const std::shared_ptr< VisualObject > &obj)
return contour for specific object (creating new one if necessary)
Definition MRPickPointManager.h:110
MRVIEWER_API FullState getFullState() const
returns the state of this
std::vector< ObjectState > FullState
Definition MRPickPointManager.h:152
MouseButton
Definition MRMouse.h:12
AllowCallBack canRemovePoint
Definition MRPickPointManager.h:85
boost::signals2::scoped_connection onPointsChanged
Definition MRPickPointManager.h:219
PickerPointCallBack onPointMoveFinish
This callback is invoked when point's dragging is completed.
Definition MRPickPointManager.h:81
PickerPointCallBack onPointRemove
This callback is invoked when a point is removed with its index before deletion.
Definition MRPickPointManager.h:88
std::function< bool(const VisualObject *, ViewportMask)> PickRenderObjectPredicate
Predicate to additionally filter objects that should be treated as pickable.
Definition MRViewport.h:187
MRVIEWER_API ~PickPointManager()
destroy this and remove the undo/redo actions referring this from the history.
boost::signals2::scoped_connection onMeshChanged
Definition MRPickPointManager.h:218
std::variant< std::monostate, MeshTriPoint, EdgePoint, VertId > PickedPoint
Definition MRPointOnObject.h:45
ChangeObjectCallBack onUpdatePoints
Definition MRPickPointManager.h:92
std::unordered_map< std::shared_ptr< VisualObject >, SurfaceContour > SurfaceContours
Definition MRPickPointManager.h:101
MRVIEWER_API int getPointIndex(const std::shared_ptr< VisualObject > &obj, SurfacePointWidget &pointWidget) const
returns index of given point widget on given object or -1 if this widget is not from given object
SurfacePointWidget::Parameters surfacePointParams
Definition MRPickPointManager.h:49
SurfacePointWidget * draggedPointWidget() const
returns point widget currently dragged by mouse
Definition MRPickPointManager.h:128
PickerPointCallBack onPointAdd
This callback is invoked after a point is added with its index.
Definition MRPickPointManager.h:68
std::vector< std::shared_ptr< SurfacePointWidget > > SurfaceContour
Definition MRPickPointManager.h:100
std::vector< PickedPoint > pickedPoints
Definition MRPickPointManager.h:150
const SurfaceContours & getSurfaceContours() const
return all contours, i.e. per object unorderd_map of ordered surface points [vector].
Definition MRPickPointManager.h:113
MRVIEWER_API bool removePoint(const std::shared_ptr< VisualObject > &obj, int pickedIndex)
Remove point with pickedIndex index from contour connected with obj.
MRVIEWER_API void clear()
removes all points from all objects
MRVIEWER_API PickPointManager()
create an object and starts listening for mouse events
MRVIEWER_API bool isClosedContour(const std::shared_ptr< VisualObject > &obj) const
check whether the contour is closed for a particular object.
MRVIEWER_API void setFullState(FullState s)
removes all current points, then adds pick points on all objects as prescribed by given state
Viewport::PickRenderObjectPredicate pickPredicate
Predicate to additionally filter objects that should be treated as pickable.
Definition MRPickPointManager.h:61
PickerPointCallBack onPointMove
This callback is invoked every time after currently dragged point is moved (in between onPointMoveSta...
Definition MRPickPointManager.h:78
Params params
Definition MRPickPointManager.h:95
MRVIEWER_API size_t numPickPoints(const std::shared_ptr< VisualObject > &obj) const
returns the total number of pick points (including extra point if the contour is closed) on given obj...
std::function< bool(const std::shared_ptr< VisualObject > &obj, int index)> AllowCallBack
Definition MRPickPointManager.h:27
std::function< bool(const std::shared_ptr< VisualObject > &obj)> ChangeObjectCallBack
Definition MRPickPointManager.h:28
PickerPointCallBack onPointMoveStart
This callback is invoked when a point starts being dragged.
Definition MRPickPointManager.h:75
AllowCallBack canAddPoint
Definition MRPickPointManager.h:65
std::weak_ptr< VisualObject > objPtr
Definition MRPickPointManager.h:149
std::function< void(std::shared_ptr< VisualObject > obj, int index)> PickerPointCallBack
Definition MRPickPointManager.h:26
AllowCallBack canMovePoint
Definition MRPickPointManager.h:72
MRVIEWER_API bool appendPoint(const std::shared_ptr< VisualObject > &obj, const PickedPoint &triPoint, bool startDragging=false)
MRVIEWER_API std::shared_ptr< SurfacePointWidget > getPointWidget(const std::shared_ptr< VisualObject > &obj, int index) const
returns point widget by index from given object or nullptr if no such widget exists
std::string historyNameSuffix
This is appended to the names of all undo/redo actions.
Definition MRPickPointManager.h:42
MRVIEWER_API bool closeContour(const std::shared_ptr< VisualObject > &obj, bool makeClosed=true)
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
MRVIEWER_API int getGlfwModPrimaryCtrl()
Returns modifier id of SUPER on mac or wasm on macos, or CTRL otherwise.
Definition MRColor.h:12
Definition MRViewerEventsListener.h:32
Definition MRPickPointManager.h:148
Definition MRPickPointManager.h:31
A common base class for all history actions of this widget.
Definition MRPickPointManager.h:98
Definition MRSurfacePointPicker.h:35