fw4spl
SResectionDB.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 "visuVTKAdaptor/SResectionDB.hpp"
8 
9 #include "visuVTKAdaptor/SResection.hpp"
10 
11 #include <fwData/Resection.hpp>
12 #include <fwData/ResectionDB.hpp>
13 
14 #include <fwServices/macros.hpp>
15 
16 fwServicesRegisterMacro( ::fwRenderVTK::IAdaptor, ::visuVTKAdaptor::SResectionDB);
17 
18 namespace visuVTKAdaptor
19 {
20 
21 static const ::fwServices::IService::KeyType s_RESECTIONDB_INPUT = "resectionDB";
22 
23 //------------------------------------------------------------------------------
24 
25 SResectionDB::SResectionDB() noexcept
26 {
27 }
28 
29 //------------------------------------------------------------------------------
30 
31 SResectionDB::~SResectionDB() noexcept
32 {
33 }
34 
35 //------------------------------------------------------------------------------
36 
38 {
39  this->configureParams();
40 
41  const ConfigType config = this->getConfigTree().get_child("config.<xmlattr>");
42 
43  this->setClippingPlanes(config.get("clippingplanes", ""));
44 
45  const std::string autoresetcamera = config.get<std::string>("autoresetcamera", "yes");
46  SLM_ASSERT("'autoresetcamera' value must be 'yes' or 'no', actual: " + autoresetcamera,
47  autoresetcamera == "yes" || autoresetcamera == "no");
48  m_autoResetCamera = (autoresetcamera == "yes");
49 }
50 
51 //------------------------------------------------------------------------------
52 
54 {
55  this->initialize();
56  this->updating();
57 }
58 
59 //------------------------------------------------------------------------------
60 
62 {
63  this->stopping();
64 
65  ::fwData::ResectionDB::csptr resecDB = this->getInput< ::fwData::ResectionDB >(s_RESECTIONDB_INPUT);
66 
67  for( const ::fwData::Resection::sptr& resection : resecDB->getResections())
68  {
69  // create the srv configuration for objects auto-connection
70  auto resecSrv = this->registerService< ::visuVTKAdaptor::SResection>("::visuVTKAdaptor::SResection");
71  resecSrv->registerInput(resection, SResection::s_RESECTION_INPUT, true);
72 
73  resecSrv->setTransformId( this->getTransformId() );
74  resecSrv->setRendererId( this->getRendererId() );
75  resecSrv->setPickerId( this->getPickerId() );
76  resecSrv->setRenderService(this->getRenderService());
77 
78  resecSrv->setClippingPlanes( m_clippingPlanes );
79  resecSrv->setAutoResetCamera(m_autoResetCamera);
80  resecSrv->start();
81 
82  }
83 
84  // Safe part
85  ::fwData::Resection::sptr resec = resecDB->getSafeResection();
86  if(resec)
87  {
88  // create the srv configuration for objects auto-connection
89  auto service = this->registerService< ::visuVTKAdaptor::SResection>("::visuVTKAdaptor::SResection");
90  service->registerInput(resec, SResection::s_RESECTION_INPUT, true);
91 
92  service->setTransformId( this->getTransformId() );
93  service->setRendererId( this->getRendererId() );
94  service->setPickerId( this->getPickerId() );
95  service->setRenderService(this->getRenderService());
96  service->setAutoResetCamera(m_autoResetCamera);
97 
98  service->start();
99  }
100 }
101 
102 //------------------------------------------------------------------------------
103 
105 {
106  this->unregisterServices();
107 }
108 
109 //------------------------------------------------------------------------------
110 
112 {
113  KeyConnectionsMap connections;
114  connections.push(s_RESECTIONDB_INPUT, ::fwData::ResectionDB::s_MODIFIED_SIG, s_UPDATE_SLOT);
115  connections.push(s_RESECTIONDB_INPUT, ::fwData::ResectionDB::s_SAFE_PART_ADDED_SIG, s_UPDATE_SLOT);
116  connections.push(s_RESECTIONDB_INPUT, ::fwData::ResectionDB::s_RESECTION_ADDED_SIG, s_UPDATE_SLOT);
117 
118  return connections;
119 }
120 
121 //------------------------------------------------------------------------------
122 
123 } //namespace visuVTKAdaptor
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_SAFE_PART_ADDED_SIG
Key in m_signals map of signal m_sigSafePartAdded.
virtual VISUVTKADAPTOR_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
This class is a helper to define the connections of a service and its data.
Definition: IService.hpp:454
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.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_RESECTION_ADDED_SIG
Key in m_signals map of signal m_sigResectionAdded.
FWRENDERVTK_API SRender::sptr getRenderService() const
Returd the associated render service.
FWRENDERVTK_API SRender::PickerIdType getPickerId() const
Gets the identifier of the picker used by this adaptor.
VISUVTKADAPTOR_API void starting() override
Initialize the service activity.
FWSERVICES_API void unregisterServices(const std::string &_implType="")
Unregister all services linked to this service, optionally matches only a given type of services...
#define SLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:308
FWRENDERVTK_API SRender::VtkObjectIdType getTransformId() const
Returns the identifier of the transform used by this adaptor.
VISUVTKADAPTOR_API void configuring() override
Configure the service before starting. Apply the configuration to service.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
FWRENDERVTK_API SRender::RendererIdType getRendererId() const
Returns the renderer identifier.
FWRENDERVTK_API void initialize()
Initialize the adaptor with the associated render service. (must be call in starting).
This service displays a ResectionDB (it launchs Resection adators)
VISUVTKADAPTOR_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_SLOT
Slot to call start method.
Definition: IService.hpp:177
VISUVTKADAPTOR_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.
Definition: IService.cpp:247