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