fw4spl
Samples/Tutorials/Tuto02DataServiceBasicCtrl/src/Tuto02DataServiceBasicCtrl/Plugin.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2018.
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 "Tuto02DataServiceBasicCtrl/Plugin.hpp"
8 
9 #include <fwRuntime/operations.hpp>
10 #include <fwRuntime/utils/GenericExecutableFactoryRegistrar.hpp>
11 
12 #include <fwServices/op/Add.hpp>
13 #include <fwServices/registry/ObjectService.hpp>
14 
16 {
17 
18 static ::fwRuntime::utils::GenericExecutableFactoryRegistrar<Plugin> registrar("::Tuto02DataServiceBasicCtrl::Plugin");
19 
20 //------------------------------------------------------------------------------
21 
22 Plugin::Plugin() noexcept
23 {
24 }
25 
26 //------------------------------------------------------------------------------
27 
28 Plugin::~Plugin() noexcept
29 {
30 }
31 
32 //------------------------------------------------------------------------------
33 
35 {
36 }
37 
38 //------------------------------------------------------------------------------
39 
41 {
42  // create an empty image
43  m_image = ::fwData::Image::New();
44 
45  // create and register the reader service
46  m_readerSrv = ::fwServices::add("::ioVTK::SImageReader");
47  m_readerSrv->registerInOut(m_image, "data"); // add the in-out image
48  // create the reader configuration
49  ::fwServices::IService::ConfigType readerCfg;
50  readerCfg.put("file", "../../data/patient1.vtk");
51  m_readerSrv->setConfiguration( readerCfg );
52  m_readerSrv->configure();
53 
54  // create and register the render service
55  m_renderSrv = ::fwServices::add("::vtkSimpleNegato::SRenderer");
56  m_renderSrv->registerInput(m_image, "image"); // add the input image
57  m_renderSrv->setID( "myRenderingTuto" ); // set an identifier
58  m_renderSrv->configure();
59 
60  // create and register frame service
61  m_frameSrv = ::fwServices::add("::gui::frame::SDefaultFrame");
62 
63  // create the frame configuration
64  ::fwServices::IService::ConfigType frameConfig;
65  frameConfig.put("gui.frame.name", "tutoDataServiceBasicCtrl");
66  frameConfig.put("gui.frame.icon", "Tuto02DataServiceBasicCtrl-0.1/tuto.ico");
67  frameConfig.put("gui.frame.minSize.<xmlattr>.width", "800");
68  frameConfig.put("gui.frame.minSize.<xmlattr>.height", "600");
69  // use the render identifier to display it in the frame
70  frameConfig.put("registry.view.<xmlattr>.sid", "myRenderingTuto");
71 
72  m_frameSrv->setConfiguration( frameConfig );
73  m_frameSrv->configure();
74 
75  // start the services
76  m_frameSrv->start();
77  m_readerSrv->start();
78  m_renderSrv->start();
79 
80  // update the services
81  m_readerSrv->update();
82  m_renderSrv->update();
83 }
84 
85 //------------------------------------------------------------------------------
86 
87 void Plugin::stop() noexcept
88 {
89 }
90 
91 //------------------------------------------------------------------------------
92 
93 void Plugin::uninitialize() noexcept
94 {
95  // stop the services
96  m_renderSrv->stop();
97  m_readerSrv->stop();
98  m_frameSrv->stop();
99 
100  // unregister the services
101  ::fwServices::OSR::unregisterService( m_readerSrv );
102  ::fwServices::OSR::unregisterService( m_frameSrv );
103  ::fwServices::OSR::unregisterService( m_renderSrv );
104  m_image.reset();
105 }
106 
107 //------------------------------------------------------------------------------
108 
109 } // namespace Tuto02DataServiceBasicCtrl
TUTO02DATASERVICEBASICCTRL_API void uninitialize() noexcept
Notifies the plugin about its uninitialisation.
TUTO02DATASERVICEBASICCTRL_API void initialize()
Notifies the plugin about its initialisation.
TUTO02DATASERVICEBASICCTRL_API void stop() noexcept
Overrides stop method. Do nothing.