fw4spl
ImageUpdateAxis.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 "ctrlSelection/ImageUpdateAxis.hpp"
8 
9 #include <fwCom/Signal.hpp>
10 #include <fwCom/Signal.hxx>
11 
12 #include <fwData/Float.hpp>
13 #include <fwData/Image.hpp>
14 
15 #include <fwServices/macros.hpp>
16 
17 #include <boost/algorithm/string/case_conv.hpp>
18 #include <boost/algorithm/string/trim.hpp>
19 
20 namespace ctrlSelection
21 {
22 
23 static const ::fwCom::Slots::SlotKeyType s_UPDATE_SLICE_TYPE_SLOT = "updateSliceType";
24 
25 //-----------------------------------------------------------------------------
26 
28 
29 //-----------------------------------------------------------------------------
30 
31 ImageUpdateAxis::ImageUpdateAxis() noexcept
32 {
33 }
34 
35 //-----------------------------------------------------------------------------
36 
37 ImageUpdateAxis::~ImageUpdateAxis() noexcept
38 {
39 }
40 
41 //-----------------------------------------------------------------------------
42 
43 void ImageUpdateAxis::updateSliceType(int from, int to)
44 {
45  if( to == static_cast< int > ( m_orientation ) )
46  {
47  m_orientation =
49  }
50  else if(from == static_cast<int>(m_orientation))
51  {
52  m_orientation = static_cast< ::fwDataTools::helper::MedicalImageAdaptor::Orientation >( to );
53  }
54  this->updating();
55 }
56 
57 //-----------------------------------------------------------------------------
58 
60 {
61  FW_DEPRECATED_MSG("This service is deprecated.", "18.0");
62  this->updating();
63 }
64 
65 //-----------------------------------------------------------------------------
66 
68 {
69 }
70 
71 //-----------------------------------------------------------------------------
72 
74 {
75 }
76 
77 //-----------------------------------------------------------------------------
78 
80 {
81  ::fwRuntime::ConfigurationElement::sptr config = m_configuration->findConfigurationElement("axis");
82  SLM_ASSERT("Problem with configuration for ImageUpdateAxis type, one element \"axis\" must be present", m_configuration->findAllConfigurationElement(
83  "axis").size() == 1 );
84 
85  SLM_FATAL_IF( "The attribute \"uid\" is missing, it represents the fwID of the ::fwData::Float to update",
86  !config->hasAttribute("uid") );
87  m_floatID = config->getExistingAttributeValue("uid");
88 
89  SLM_FATAL_IF( "The attribute \"orientation\" is missing, it represents the image orientation "
90  "(axial, frontal or sagittal)", !config->hasAttribute("orientation") );
91  std::string orientation = config->getExistingAttributeValue("orientation");
92  ::boost::algorithm::trim(orientation);
93  ::boost::algorithm::to_lower(orientation);
94 
95  if(orientation == "axial" )
96  {
97  m_orientation = ::fwDataTools::helper::MedicalImageAdaptor::Z_AXIS;
98  }
99  else if(orientation == "frontal" )
100  {
101  m_orientation = ::fwDataTools::helper::MedicalImageAdaptor::Y_AXIS;
102  }
103  else if(orientation == "sagittal" )
104  {
105  m_orientation = ::fwDataTools::helper::MedicalImageAdaptor::X_AXIS;
106  }
107  else
108  {
109  SLM_FATAL("The value for the xml element \"value\" can only be axial, frontal or sagittal.");
110  }
111 }
112 
113 //-----------------------------------------------------------------------------
114 
116 {
117 }
118 
119 //-----------------------------------------------------------------------------
120 
122 {
123  OSLM_ASSERT("Missing object " << m_floatID, ::fwTools::fwID::exist(m_floatID));
124  ::fwData::Float::sptr dataFloat = ::fwData::Float::dynamicCast(::fwTools::fwID::getObject(m_floatID));
125  OSLM_ASSERT("Object " << m_floatID << " is not a valid ::fwData::Float", dataFloat);
126 
127  dataFloat->value() = (float) m_orientation;
128  OSLM_TRACE(dataFloat->getID() << " new value : " << *dataFloat);
129 
131  sig->asyncEmit();
132 }
133 
134 //-----------------------------------------------------------------------------
135 
136 void ImageUpdateAxis::info( std::ostream& _sstream )
137 {
138 }
139 
140 //------------------------------------------------------------------------------
141 
143 {
144  KeyConnectionsType connections;
145  connections.push_back( std::make_pair( ::fwData::Image::s_SLICE_TYPE_MODIFIED_SIG, s_UPDATE_SLICE_TYPE_SLOT ) );
146 
147  return connections;
148 }
149 
150 //-----------------------------------------------------------------------------
151 
152 } // ctrlSelection
virtual CTRLSELECTION_API void info(std::ostream &_sstream) override
Implements info method derived from IService. Print classname.
virtual CTRLSELECTION_API KeyConnectionsType getObjSrvConnections() 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
static FWTOOLS_API bool exist(IDType _id)
Definition: fwID.cpp:33
virtual CTRLSELECTION_API void stopping() override
Does nothing.
#define OSLM_TRACE(message)
Definition: spyLog.hpp:230
#define FW_DEPRECATED_MSG(message, version)
Use this macro when deprecating a function to warn the developer.
Definition: spyLog.hpp:360
This service updates a fwData::Float given in configuration with the image axis.
#define SLM_FATAL(message)
Definition: spyLog.hpp:283
This interface defines control service API. Does nothing particularly, can be considered as a default...
Definition: IController.hpp:23
virtual CTRLSELECTION_API void configuring() override
Configures the service.
#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
virtual CTRLSELECTION_API void updating() override
Updates the float from the image axis orientation.
::fwRuntime::ConfigurationElement::sptr m_configuration
Configuration element used to configure service internal state using a generic XML like structure TOD...
Definition: IService.hpp:670
::fwCom::helper::SigSlotConnection::KeyConnectionsType KeyConnectionsType
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
Definition: IService.hpp:449
#define SLM_FATAL_IF(message, cond)
Definition: spyLog.hpp:287
virtual CTRLSELECTION_API void reconfiguring() override
Does nothing.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
This class defines an image.
The namespace ctrlSelection contains several interfaces for manager, updater and wrapper.
Definition: BookmarkSrv.hpp:15
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_SLICE_TYPE_MODIFIED_SIG
Type of signal when image&#39;s buffer is added.
virtual CTRLSELECTION_API void swapping() override
Does nothing.
virtual CTRLSELECTION_API void starting() override
Calls updating().
static FWTOOLS_API std::shared_ptr< ::fwTools::Object > getObject(IDType requestID)
Retrieve the object attached to the given id. Return a null sptr if no correspondence exist...
Definition: fwID.cpp:117