MeshLib C++ Docs
Loading...
Searching...
No Matches
MRPlaneWidget.h
Go to the documentation of this file.
1#pragma once
2
5#include "MRMesh/MRBox.h"
6#include "MRMesh/MRPlane3.h"
7#include "MRMesh/MRVector2.h"
8
9namespace MR
10{
11// Visual widget to draw a plane
12// present in scene (ancillary), subscribes to viewer events
13class MRVIEWER_CLASS PlaneWidget : public MultiListener<DragStartListener, DragListener, DragEndListener, NameTagClickListener>
14{
15 std::shared_ptr<ObjectMesh> planeObj_;
16 Plane3f plane_;
17 Box3f box_;
18 Vector3f cameraUp3Old_;
19
20 // if in this mode - newly setup plane always has 0.0 shift
21 bool localMode_{ false };
22 float localShift_{ 0.0f };
23
24 using OnPlaneUpdateCallback = std::function<void()>;
25 OnPlaneUpdateCallback onPlaneUpdate_;
26
27 bool pressed_ = false;
28 bool showPlaneByDefault_ = true;
29 Vector2f startMousePos_;
30 Vector2f endMousePos_;
31
32 std::shared_ptr<ObjectLines> line_;
33
34 bool importPlaneMode_ = false;
35public:
36
37 // updates plane, triggers callback if it is specified
38 // if updateCameraRotation is true, plane transform will be updated with respect of camera up direction
39 MRVIEWER_API void updatePlane( const Plane3f& plane, bool updateCameraRotation = true );
40 // updates box which is used to calculate size and position of the visualized plane part
41 // if updateCameraRotation is true, plane transform will be updated with respect of camera up direction
42 MRVIEWER_API void updateBox( const Box3f& box, bool updateCameraRotation = true );
43 // defines plane, adds plane object to scene
44 MRVIEWER_API void definePlane();
45 // undefines plane, removes PlaneObject from scene
46 MRVIEWER_API void undefinePlane();
47
48 // if local mode is active UI shows local shift
49 // which is 0.0 for each newly setup plane
50 MRVIEWER_API void setLocalMode( bool on );
51 bool isInLocalMode() const { return localMode_; }
52 void setLocalShift( float shift ) { localShift_ = shift; }
53 float getLocalShift() const { return localShift_; }
54
55 // returns plane
56 MRVIEWER_API const Plane3f& getPlane() const;
57 // returns plane object
58 MRVIEWER_API const std::shared_ptr<ObjectMesh>& getPlaneObject() const;
59 // specifies callback onPlaneUpdate_
60 // it is triggered when the method updatePlane is called
61 MRVIEWER_API void setOnPlaneUpdateCallback( OnPlaneUpdateCallback callback );
62
63 // returns box which is used to calculate size and position of the visualized plane part
64 MRVIEWER_API const Box3f& box() const;
65 // returns the flag importPlaneMode_, if it is true you can use a plain object from the scene
66 MRVIEWER_API bool importPlaneMode() const;
67 // sets the flag importPlaneMode_, if it is true you can use a plain object from the scene
68 MRVIEWER_API void setImportPlaneMode( bool val );
69
70 // returns the flag that is true if the plane is shown by default
71 bool getShowPlaneByDefault() const { return showPlaneByDefault_; }
72 // sets the flag that is true if the plane is shown by default
73 void setShowPlaneByDefault( bool val ) { showPlaneByDefault_ = val; }
74
75private:
76 MRVIEWER_API void updateWidget_( bool updateCameraRotation = true );
77
78 MRVIEWER_API virtual bool onDragStart_( MouseButton button, int modifier ) override;
79 MRVIEWER_API virtual bool onDragEnd_( MouseButton button, int modifier ) override;
80 MRVIEWER_API virtual bool onDrag_( int mouse_x, int mouse_y ) override;
81 MRVIEWER_API virtual bool onNameTagClicked_( Object& object, ImGuiMenu::NameTagSelectionMode ) override;
82
83 bool importPlaneObj_( Object& obj );
84};
85}
NameTagSelectionMode
Definition ImGuiMenu.h:304
Definition MRObject.h:62
Definition MRPlaneWidget.h:14
MRVIEWER_API const Plane3f & getPlane() const
MRVIEWER_API void setImportPlaneMode(bool val)
MRVIEWER_API void updatePlane(const Plane3f &plane, bool updateCameraRotation=true)
MRVIEWER_API void setOnPlaneUpdateCallback(OnPlaneUpdateCallback callback)
MRVIEWER_API const std::shared_ptr< ObjectMesh > & getPlaneObject() const
MRVIEWER_API void definePlane()
float getLocalShift() const
Definition MRPlaneWidget.h:53
void setLocalShift(float shift)
Definition MRPlaneWidget.h:52
bool getShowPlaneByDefault() const
Definition MRPlaneWidget.h:71
bool isInLocalMode() const
Definition MRPlaneWidget.h:51
MRVIEWER_API void updateBox(const Box3f &box, bool updateCameraRotation=true)
void setShowPlaneByDefault(bool val)
Definition MRPlaneWidget.h:73
MRVIEWER_API void undefinePlane()
MRVIEWER_API const Box3f & box() const
MRVIEWER_API void setLocalMode(bool on)
MRVIEWER_API bool importPlaneMode() const
Definition MRCameraOrientationPlugin.h:8
Definition MRViewerEventsListener.h:29