fw4spl
SResection.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/SResection.hpp"
8 
9 #include "visuVTKAdaptor/SReconstruction.hpp"
10 
11 #include <fwData/Reconstruction.hpp>
12 #include <fwData/Resection.hpp>
13 
14 #include <fwServices/macros.hpp>
15 
16 fwServicesRegisterMacro( ::fwRenderVTK::IAdaptor, ::visuVTKAdaptor::SResection);
17 
18 namespace visuVTKAdaptor
19 {
20 
21 const ::fwServices::IService::KeyType SResection::s_RESECTION_INPUT = "resection";
22 
23 SResection::SResection() noexcept :
24  m_autoResetCamera(true)
25 {
26 }
27 
28 //------------------------------------------------------------------------------
29 
30 SResection::~SResection() noexcept
31 {
32 }
33 
34 //------------------------------------------------------------------------------
35 
37 {
38  this->configureParams();
39 
40  const ConfigType config = this->getConfigTree().get_child("config.<xmlattr>");
41 
42  this->setClippingPlanes(config.get("clippingplanes", ""));
43 
44  const std::string autoresetcamera = config.get<std::string>("autoresetcamera", "yes");
45  SLM_ASSERT("'autoresetcamera' value must be 'yes' or 'no', actual: " + autoresetcamera,
46  autoresetcamera == "yes" || autoresetcamera == "no");
47  m_autoResetCamera = (autoresetcamera == "yes");
48 }
49 
50 //------------------------------------------------------------------------------
51 
53 {
54  this->initialize();
55  this->updating();
56 }
57 
58 //------------------------------------------------------------------------------
59 
61 {
62  this->stopping();
63 
64  ::fwData::Resection::csptr resec = this->getInput< ::fwData::Resection >(s_RESECTION_INPUT);
65 
66  if (resec->getIsVisible())
67  {
68  std::vector< ::fwData::Reconstruction::sptr > vReconst;
69  bool resectionIsValid = resec->getIsValid();
70  if(resec->getIsSafePart() || resectionIsValid)
71  {
72  vReconst = resec->getOutputs();
73  }
74  else
75  {
76  vReconst = resec->getInputs();
77  }
78  for (const ::fwData::Reconstruction::sptr& resec: vReconst)
79  {
80  // create the srv configuration for objects auto-connection
81  auto reconstAdaptor =
82  this->registerService< ::visuVTKAdaptor::SReconstruction>("::visuVTKAdaptor::SReconstruction");
83  reconstAdaptor->registerInput(resec, SReconstruction::s_RECONSTRUCTION_INPUT, true);
84 
85  reconstAdaptor->setTransformId( this->getTransformId() );
86  reconstAdaptor->setRendererId( this->getRendererId() );
87  reconstAdaptor->setPickerId( this->getPickerId() );
88  reconstAdaptor->setRenderService(this->getRenderService());
89  if(!resectionIsValid)
90  {
91  reconstAdaptor->setClippingPlanes( m_clippingPlanes );
92  }
93  reconstAdaptor->setAutoResetCamera(m_autoResetCamera);
94  reconstAdaptor->start();
95  }
96  }
97  this->setVtkPipelineModified();
98 }
99 
100 //------------------------------------------------------------------------------
101 
103 {
104  this->unregisterServices();
105 }
106 
107 //------------------------------------------------------------------------------
108 
110 {
111  KeyConnectionsMap connections;
112  connections.push(s_RESECTION_INPUT, ::fwData::Resection::s_MODIFIED_SIG, s_UPDATE_SLOT);
113  connections.push(s_RESECTION_INPUT, ::fwData::Resection::s_VISIBILITY_MODIFIED_SIG, s_UPDATE_SLOT);
114  connections.push(s_RESECTION_INPUT, ::fwData::Resection::s_RECONSTRUCTION_ADDED_SIG, s_UPDATE_SLOT);
115 
116  return connections;
117 }
118 
119 //------------------------------------------------------------------------------
120 
121 } //namespace visuVTKAdaptor
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.
virtual VISUVTKADAPTOR_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
Definition: SResection.cpp:109
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 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.
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
VISUVTKADAPTOR_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
Definition: SResection.cpp:60
VISUVTKADAPTOR_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
Definition: SResection.cpp:102
FWRENDERVTK_API SRender::VtkObjectIdType getTransformId() const
Returns the identifier of the transform used by this adaptor.
This service displays a ResectionDB (it launchs Reconstruction adators)
Definition: SResection.hpp:38
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).
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_RECONSTRUCTION_ADDED_SIG
Key in m_signals map of signal m_sigReconstructionAdded.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_VISIBILITY_MODIFIED_SIG
Key in m_signals map of signal m_sigVisibilityModified.
VISUVTKADAPTOR_API void configuring() override
Configure the service before starting. Apply the configuration to service.
Definition: SResection.cpp:36
VISUVTKADAPTOR_API void starting() override
Initialize the service activity.
Definition: SResection.cpp:52
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_SLOT
Slot to call start method.
Definition: IService.hpp:177
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.
Definition: IService.cpp:247