fw4spl
SImageSeries.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/SImageSeries.hpp"
8 
9 #include <fwData/Boolean.hpp>
10 #include <fwData/Material.hpp>
11 #include <fwData/Reconstruction.hpp>
12 
13 #include <fwMedData/ImageSeries.hpp>
14 
15 #include <fwServices/macros.hpp>
16 #include <fwServices/op/Add.hpp>
17 
18 #include <vtkActor.h>
19 #include <vtkPolyDataMapper.h>
20 
21 fwServicesRegisterMacro( ::fwRenderVTK::IAdaptor, ::visuVTKAdaptor::SImageSeries);
22 
23 static const ::fwServices::IService::KeyType s_IMAGE_SERIES_INOUT = "imageSeries";
24 static const ::fwServices::IService::KeyType s_TF_INOUT = "tf";
25 
26 namespace visuVTKAdaptor
27 {
28 
29 SImageSeries::SImageSeries() noexcept :
30  m_allowAlphaInTF(false),
31  m_interpolation(false),
32  m_3dModeEnabled( ::boost::logic::indeterminate ),
33  m_sliceMode(SNegatoMPR::THREE_SLICES)
34 
35 {
36 }
37 
38 //------------------------------------------------------------------------------
39 
40 SImageSeries::~SImageSeries() noexcept
41 {
42 }
43 
44 //------------------------------------------------------------------------------
45 
47 {
48  this->configureParams();
49 
50  const ConfigType config = this->getConfigTree().get_child("config.<xmlattr>");
51 
52  if (config.count("mode"))
53  {
54  std::string value = config.get<std::string>("mode");
55  std::transform(value.begin(), value.end(), value.begin(), tolower);
56  SLM_ASSERT("Bad value '" + value + "' for attribute mode, it should either be '2d' or '3d'.",
57  value == "3d" || value == "2d");
58  this->set3dMode(value == "3d");
59  }
60  if (config.count("slices"))
61  {
62  const std::string value = config.get<std::string>("slices");
63 
64  if(value == "0")
65  {
66  this->setSliceMode(SNegatoMPR::NO_SLICE);
67  }
68  else if(value == "1")
69  {
70  this->setSliceMode(SNegatoMPR::ONE_SLICE);
71  }
72  else if(value == "3")
73  {
74  this->setSliceMode(SNegatoMPR::THREE_SLICES);
75  }
76  else
77  {
78  SLM_FATAL("'slice' value must be '0', '1' or '3', actual: " + value);
79  }
80  }
81 
82  const std::string orientation = config.get<std::string>("sliceIndex", "axial");
83  if(orientation == "axial" )
84  {
85  m_orientation = Z_AXIS;
86  }
87  else if(orientation == "frontal" )
88  {
89  m_orientation = Y_AXIS;
90  }
91  else if(orientation == "sagittal" )
92  {
93  m_orientation = X_AXIS;
94  }
95 
96  const std::string tfalpha = config.get<std::string>("tfalpha", "no");
97  SLM_ASSERT("'tfalpha' value must be 'yes' or 'no', actual: " + tfalpha, tfalpha == "yes" || tfalpha == "no");
98  this->setAllowAlphaInTF(tfalpha == "yes");
99 
100  const std::string interpolation = config.get<std::string>("interpolation", "off");
101  SLM_ASSERT("'interpolation' value must be 'on' or 'off', actual: " + interpolation,
102  interpolation == "on" || interpolation == "off");
103  this->setInterpolation(interpolation == "yes");
104 
105  this->setVtkImageSourceId( config.get<std::string>("vtkimagesource", ""));
106 }
107 
108 //------------------------------------------------------------------------------
109 
111 {
112  this->initialize();
113  this->updating();
114 }
115 
116 //------------------------------------------------------------------------------
117 
119 {
120  ::fwMedData::ImageSeries::sptr series = this->getInOut< ::fwMedData::ImageSeries >(s_IMAGE_SERIES_INOUT);
121  OSLM_ASSERT("Missing iamgeSeries", series);
122 
123  this->stopping();
124 
125  auto negato = this->registerService< ::visuVTKAdaptor::SNegatoMPR>("::visuVTKAdaptor::SNegatoMPR");
126 
127  // register image
128  ::fwData::Image::sptr image = series->getImage();
129  negato->registerInOut(image, SNegatoMPR::s_IMAGE_INOUT, true);
130 
131  ::fwData::TransferFunction::sptr tf = this->getInOut< ::fwData::TransferFunction >(s_TF_INOUT);
132  if (tf)
133  {
134  negato->registerInOut(tf, SNegatoMPR::s_TF_INOUT, false);
135  }
136 
137  negato->setTransformId( this->getTransformId() );
138  negato->setRendererId( this->getRendererId() );
139  negato->setPickerId( this->getPickerId() );
140  negato->setRenderService(this->getRenderService());
141 
142  negato->set3dMode(this->is3dModeEnabled());
143  negato->setSliceMode(this->getSliceMode());
144  negato->setOrientation(this->getOrientation());
145  negato->setAllowAlphaInTF(m_allowAlphaInTF);
146  negato->setInterpolation(m_interpolation);
147  negato->setVtkImageSourceId(m_imageSourceId);
148  negato->start();
149 }
150 
151 //------------------------------------------------------------------------------
152 
154 {
155  this->unregisterServices();
156 }
157 
158 //------------------------------------------------------------------------------
159 
160 void SImageSeries::setSliceMode(SNegatoMPR::SliceMode sliceMode)
161 {
162  if(m_sliceMode != sliceMode)
163  {
164  m_sliceMode = sliceMode;
165  }
166 }
167 
168 //------------------------------------------------------------------------------
169 
170 SNegatoMPR::SliceMode SImageSeries::getSliceMode()
171 {
172  return m_sliceMode;
173 }
174 
175 //------------------------------------------------------------------------------
176 
177 ::boost::logic::tribool SImageSeries::is3dModeEnabled()
178 {
179  return m_3dModeEnabled;
180 }
181 
182 //------------------------------------------------------------------------------
183 
184 void SImageSeries::set3dMode( bool enabled )
185 {
186  m_3dModeEnabled = enabled;
187 }
188 
189 //------------------------------------------------------------------------------
190 
192 {
193  KeyConnectionsMap connections;
194 
195  connections.push(s_IMAGE_SERIES_INOUT, ::fwData::Object::s_MODIFIED_SIG, s_UPDATE_SLOT);
196 
197  return connections;
198 }
199 
200 //------------------------------------------------------------------------------
201 
202 } //namespace visuVTKAdaptor
This class is a helper to define the connections of a service and its data.
Definition: IService.hpp:454
void set3dMode(bool enabled)
Defines 3D mode.
virtual VISUVTKADAPTOR_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
#define OSLM_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:310
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
This adaptor shows ImageSeries. Creates an adaptor for the image in the series.
FWRENDERVTK_API void configureParams()
Parse the xml configuration for renderer, picker and transform.
VISUVTKADAPTOR_API void updating() override
Creates and starts image adaptor. Redraw all (stop then restart sub services).
VISUVTKADAPTOR_API void starting() override
Calls doUpdate()
Orientation getOrientation() const
Return the image orientation.
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 stopping() override
Stops and unregister image subservice.
#define SLM_FATAL(message)
Definition: spyLog.hpp:283
Orientation m_orientation
Image orientation.
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.
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).
SNegatoMPR::SliceMode getSliceMode()
Gets adaptor slice mode (NO_SLICE, ONE_SLICE, THREE_SLICES)
VISUVTKADAPTOR_API void configuring() override
Configure the adaptor.
::boost::logic::tribool is3dModeEnabled()
Returns true if 3d mode is enabled, false if it is not and indeterminate if it is not defined...
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_SLOT
Slot to call start method.
Definition: IService.hpp:177
void setSliceMode(SNegatoMPR::SliceMode sliceMode)
Sets adaptor slice mode (NO_SLICE, ONE_SLICE, THREE_SLICES)
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.
Definition: IService.cpp:247