fw4spl
S2DWheel.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "visuVTKAdaptor/S2DWheel.hpp"
8 
9 #include <fwCom/Signal.hxx>
10 #include <fwCom/Slot.hxx>
11 #include <fwCom/Slots.hxx>
12 
13 #include <fwServices/macros.hpp>
14 
15 #include <fwVtkIO/helper/vtkLambdaCommand.hpp>
16 
17 #include <vtkRenderer.h>
18 #include <vtkRenderWindow.h>
19 
20 fwServicesRegisterMacro( ::fwRenderVTK::IAdaptor, ::visuVTKAdaptor::S2DWheel);
21 
22 namespace visuVTKAdaptor
23 {
24 
25 static const ::fwCom::Signals::SignalKeyType s_WHEEL_UPDATED_SIG = "wheelUpdated";
26 
27 static const ::fwCom::Slots::SlotKeyType s_UPDATE_VISIBILITY_SLOT = "updateVisibility";
28 
29 //------------------------------------------------------------------------------
30 
31 S2DWheel::S2DWheel() noexcept :
32  m_wheelWidget(vtkSmartPointer<fwVtkWheelWidget>::New()),
33  m_visible(true)
34 {
35  m_wheelUpdatedSignal = newSignal<WheelUpdatedSignalType>(s_WHEEL_UPDATED_SIG);
36 
37  newSlot(s_UPDATE_VISIBILITY_SLOT, &S2DWheel::updateVisibility, this);
38 }
39 
40 //------------------------------------------------------------------------------
41 
43 {
44 }
45 
46 //------------------------------------------------------------------------------
47 
49 {
50  this->configureParams();
51 
52  const ConfigType& config = this->getConfigTree();
53 
54  m_visible = config.get<bool>("config.<xmlattr>.visible", true);
55 }
56 
57 //------------------------------------------------------------------------------
58 
60 {
61  this->initialize();
62 
64 
65  wheelRepresentation->SetVisibility(m_visible);
66  m_wheelWidget->SetInteractor(this->getRenderer()->GetRenderWindow()->GetInteractor());
67  m_wheelWidget->SetPriority(1.f); // Set a priority higher than that of the ::visuVTKAdaptor::SProbeCursor
68  m_wheelWidget->SetRepresentation(wheelRepresentation);
69  m_wheelWidget->On();
70  m_wheelWidget->SetWheelUpdateCallback([this](double cx, double cy, double o)
71  {
72  OSLM_DEBUG("Center : " << "(" << cx << ", " << cy << "), Orientation : " << o);
73  this->m_wheelUpdatedSignal->asyncEmit(cx, cy, o);
74  });
75 
76  m_resizeCallback = vtkSmartPointer< ::fwVtkIO::helper::vtkLambdaCommand >::New();
77  m_resizeCallback->SetCallback(
78  [this](vtkObject*, long unsigned int, void* )
79  {
80  const int viewportWidth = this->getRenderer()->GetRenderWindow()->GetSize()[0];
81  const int viewportHeight = this->getRenderer()->GetRenderWindow()->GetSize()[1];
82 
83  if(viewportHeight != 0 && viewportWidth != 0)
84  {
85  this->m_wheelWidget->GetRepresentation()->UpdateRepresentation();
86  }
87 
88  this->requestRender();
89  });
90  this->getRenderer()->GetRenderWindow()->AddObserver(vtkCommand::ModifiedEvent, m_resizeCallback);
91 
92  this->setVtkPipelineModified();
93  this->requestRender();
94 }
95 
96 //------------------------------------------------------------------------------
97 
99 {
100  m_wheelWidget->Off();
101 
102  this->getRenderer()->GetRenderWindow()->RemoveObserver(m_resizeCallback);
103 
105 
106  this->requestRender();
107 }
108 
109 //------------------------------------------------------------------------------
110 
112 {
113 }
114 
115 //------------------------------------------------------------------------------
116 
117 void S2DWheel::updateVisibility(bool _isVisible)
118 {
119  m_visible = _isVisible;
120  this->m_wheelWidget->GetRepresentation()->SetVisibility(static_cast<int>(_isVisible));
121 
122  this->setVtkPipelineModified();
123  this->requestRender();
124 }
125 
126 //------------------------------------------------------------------------------
127 
128 } // namespace visuVTKAdaptor
static FWRENDERVTK_API fwVtkWheelRepresentation * New()
Calls the constructor. Initializes wheel geometry and actor.
VISUVTKADAPTOR_API S2DWheel() noexcept
Constructor. Does nothing.
Definition: S2DWheel.cpp:31
FWRENDERVTK_API vtkRenderer * getRenderer()
Returns the renderer.
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
FWRENDERVTK_API void configureParams()
Parse the xml configuration for renderer, picker and transform.
Implements the interactions with the wheel widget.
FWRENDERVTK_API void requestRender()
notify a render request iff vtkPipeline is modified
virtual VISUVTKADAPTOR_API ~S2DWheel() noexcept
Destructor. Does nothing.
Definition: S2DWheel.cpp:42
FWRENDERVTK_API void setVtkPipelineModified()
End-user have to call this method when a vtk structure has been modified, thus a render request will ...
FWRENDERVTK_API void removeAllPropFromRenderer()
Removes all the vtkProp from the renderer.
virtual VISUVTKADAPTOR_API void stopping() override
Disables the widget.
Definition: S2DWheel.cpp:98
virtual VISUVTKADAPTOR_API void updating() override
Does nothing.
Definition: S2DWheel.cpp:111
FWRENDERVTK_API void initialize()
Initialize the adaptor with the associated render service. (must be call in starting).
virtual VISUVTKADAPTOR_API void configuring() override
Configure the service before starting. Apply the configuration to service.
Definition: S2DWheel.cpp:48
Render a rotatable 2D wheel in screen-space.
Definition: S2DWheel.hpp:44
Representation of a wheel widget.
#define OSLM_DEBUG(message)
Definition: spyLog.hpp:241
virtual VISUVTKADAPTOR_API void starting() override
Instantiates the widget and puts it in the scene.
Definition: S2DWheel.cpp:59
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.
Definition: IService.cpp:247