fw4spl
SImageSignalForwarder.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
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/wrapper/SImageSignalForwarder.hpp"
8 
9 #include <fwCom/Signal.hpp>
10 #include <fwCom/Signal.hxx>
11 #include <fwCom/Signals.hpp>
12 #include <fwCom/Slot.hpp>
13 #include <fwCom/Slot.hxx>
14 #include <fwCom/Slots.hpp>
15 #include <fwCom/Slots.hxx>
16 
17 #include <fwData/Composite.hpp>
18 #include <fwData/Image.hpp>
19 
20 #include <fwServices/macros.hpp>
21 
22 #include <boost/regex.hpp>
23 
24 namespace ctrlSelection
25 {
26 namespace wrapper
27 {
28 
29 static const ::fwCom::Slots::SlotKeyType s_FORWARD_MODIFIED_SLOT = "forwardModified";
30 static const ::fwCom::Slots::SlotKeyType s_FORWARD_BUFFER_MODIFIED_SLOT = "forwardBufferModified";
31 static const ::fwCom::Slots::SlotKeyType s_FORWARD_LANDMARK_ADDED_SLOT = "forwardLandmarkAdded";
32 static const ::fwCom::Slots::SlotKeyType s_FORWARD_LANDMARK_REMOVED_SLOT = "forwardLandmarkRemoved";
33 static const ::fwCom::Slots::SlotKeyType s_FORWARD_LANDMARK_DISPLAYED_SLOT = "forwardLandmarkDisplayed";
34 static const ::fwCom::Slots::SlotKeyType s_FORWARD_DISTANCE_ADDED_SLOT = "forwardDistanceAdded";
35 static const ::fwCom::Slots::SlotKeyType s_FORWARD_DISTANCE_REMOVED_SLOT = "forwardDistanceRemoved";
36 static const ::fwCom::Slots::SlotKeyType s_FORWARD_DISTANCE_DISPLAYED_SLOT = "forwardDistanceDisplayed";
37 static const ::fwCom::Slots::SlotKeyType s_FORWARD_SLICE_INDEX_MODIFIED_SLOT = "forwardSliceIndexModified";
38 static const ::fwCom::Slots::SlotKeyType s_FORWARD_SLICE_TYPE_MODIFIED_SLOT = "forwardSliceTypeModified";
39 static const ::fwCom::Slots::SlotKeyType s_FORWARD_VISIBILITY_MODIFIED_SLOT = "forwardVisibilityModified";
40 static const ::fwCom::Slots::SlotKeyType s_FORWARD_TRANSPARENCY_MODIFIED_SLOT = "forwardTransparencyModified";
41 static const ::fwCom::Slots::SlotKeyType s_FORWARD_ADDED_FIELDS_SLOT = "forwardAddedFields";
42 static const ::fwCom::Slots::SlotKeyType s_FORWARD_CHANGED_FIELDS_SLOT = "forwardChangedFields";
43 static const ::fwCom::Slots::SlotKeyType s_FORWARD_REMOVED_FIELDS_SLOT = "forwardRemovedFields";
44 
45 static const ::fwServices::IService::KeyType s_SOURCE_INPUT = "source";
46 static const ::fwServices::IService::KeyType s_TARGET_INPUT = "target";
47 
48 SImageSignalForwarder::AvailableConnectionMapType SImageSignalForwarder::m_availableConnection;
49 
50 //-----------------------------------------------------------------------------
51 
53  ::fwData::Image );
54 
55 //-----------------------------------------------------------------------------
56 
57 SImageSignalForwarder::SImageSignalForwarder() noexcept
58 {
59  m_availableConnection[::fwData::Image::s_MODIFIED_SIG] = s_FORWARD_MODIFIED_SLOT;
60  m_availableConnection[::fwData::Image::s_BUFFER_MODIFIED_SIG] = s_FORWARD_BUFFER_MODIFIED_SLOT;
61  m_availableConnection[::fwData::Image::s_LANDMARK_ADDED_SIG] = s_FORWARD_LANDMARK_ADDED_SLOT;
62  m_availableConnection[::fwData::Image::s_LANDMARK_REMOVED_SIG] = s_FORWARD_LANDMARK_REMOVED_SLOT;
63  m_availableConnection[::fwData::Image::s_LANDMARK_DISPLAYED_SIG] = s_FORWARD_LANDMARK_DISPLAYED_SLOT;
64  m_availableConnection[::fwData::Image::s_DISTANCE_ADDED_SIG] = s_FORWARD_DISTANCE_ADDED_SLOT;
65  m_availableConnection[::fwData::Image::s_DISTANCE_REMOVED_SIG] = s_FORWARD_DISTANCE_REMOVED_SLOT;
66  m_availableConnection[::fwData::Image::s_DISTANCE_DISPLAYED_SIG] = s_FORWARD_DISTANCE_DISPLAYED_SLOT;
67  m_availableConnection[::fwData::Image::s_SLICE_INDEX_MODIFIED_SIG] = s_FORWARD_SLICE_INDEX_MODIFIED_SLOT;
68  m_availableConnection[::fwData::Image::s_SLICE_TYPE_MODIFIED_SIG] = s_FORWARD_SLICE_TYPE_MODIFIED_SLOT;
69  m_availableConnection[::fwData::Image::s_VISIBILITY_MODIFIED_SIG] = s_FORWARD_VISIBILITY_MODIFIED_SLOT;
70  m_availableConnection[::fwData::Image::s_TRANSPARENCY_MODIFIED_SIG] = s_FORWARD_TRANSPARENCY_MODIFIED_SLOT;
71  m_availableConnection[::fwData::Object::s_ADDED_FIELDS_SIG] = s_FORWARD_ADDED_FIELDS_SLOT;
72  m_availableConnection[::fwData::Object::s_CHANGED_FIELDS_SIG] = s_FORWARD_CHANGED_FIELDS_SLOT;
73  m_availableConnection[::fwData::Object::s_REMOVED_FIELDS_SIG] = s_FORWARD_REMOVED_FIELDS_SLOT;
74 
75  newSlot(s_FORWARD_MODIFIED_SLOT, &SImageSignalForwarder::forwardModified, this);
76  newSlot(s_FORWARD_BUFFER_MODIFIED_SLOT, &SImageSignalForwarder::forwardBufferModified, this);
77  newSlot(s_FORWARD_LANDMARK_ADDED_SLOT, &SImageSignalForwarder::forwardLandmarkAdded, this);
78  newSlot(s_FORWARD_LANDMARK_REMOVED_SLOT, &SImageSignalForwarder::forwardLandmarkRemoved, this);
79  newSlot(s_FORWARD_LANDMARK_DISPLAYED_SLOT, &SImageSignalForwarder::forwardLandmarkDisplayed, this);
80  newSlot(s_FORWARD_DISTANCE_ADDED_SLOT, &SImageSignalForwarder::forwardDistanceAdded, this);
81  newSlot(s_FORWARD_DISTANCE_REMOVED_SLOT, &SImageSignalForwarder::forwardDistanceRemoved, this);
82  newSlot(s_FORWARD_DISTANCE_DISPLAYED_SLOT, &SImageSignalForwarder::forwardDistanceDisplayed, this);
83  newSlot(s_FORWARD_SLICE_INDEX_MODIFIED_SLOT, &SImageSignalForwarder::forwardSliceIndexModified, this);
84  newSlot(s_FORWARD_SLICE_TYPE_MODIFIED_SLOT, &SImageSignalForwarder::forwardSliceTypeModified, this);
85  newSlot(s_FORWARD_VISIBILITY_MODIFIED_SLOT, &SImageSignalForwarder::forwardVisibilityModified, this);
86  newSlot(s_FORWARD_TRANSPARENCY_MODIFIED_SLOT, &SImageSignalForwarder::forwardTransparencyModified, this);
87  newSlot(s_FORWARD_ADDED_FIELDS_SLOT, &SImageSignalForwarder::forwardAddedFields, this);
88  newSlot(s_FORWARD_CHANGED_FIELDS_SLOT, &SImageSignalForwarder::forwardChangedFields, this);
89  newSlot(s_FORWARD_REMOVED_FIELDS_SLOT, &SImageSignalForwarder::forwardRemovedFields, this);
90 }
91 
92 //-----------------------------------------------------------------------------
93 
94 SImageSignalForwarder::~SImageSignalForwarder() noexcept
95 {
96 }
97 
98 //-----------------------------------------------------------------------------
99 
101 {
102  std::vector< ::fwRuntime::ConfigurationElement::sptr > configs = m_configuration->find("forward");
103 
104  for (auto cfg : configs)
105  {
106  std::string signal = cfg->getValue();
107  SLM_ASSERT("Signal '" + signal + "' is unknown.",
108  m_availableConnection.find(signal) != m_availableConnection.end());
109  m_managedSignals.push_back(signal);
110  }
111 }
112 
113 //-----------------------------------------------------------------------------
114 
116 {
117  ::fwData::Image::csptr src = this->getInput< ::fwData::Image >(s_SOURCE_INPUT);
118 
119  for (auto signalKey: m_managedSignals)
120  {
121  m_connections.connect(src, signalKey, this->getSptr(), m_availableConnection[signalKey]);
122  }
123 }
124 
125 //-----------------------------------------------------------------------------
126 
128 {
129  m_connections.disconnect();
130 }
131 
132 //-----------------------------------------------------------------------------
133 
135 {
136  this->stopping();
137  this->starting();
138 }
139 
140 //-----------------------------------------------------------------------------
141 
143 {
144 }
145 
146 //-----------------------------------------------------------------------------
147 
148 void SImageSignalForwarder::info( std::ostream& _sstream )
149 {
150 }
151 
152 //-----------------------------------------------------------------------------
153 
154 void SImageSignalForwarder::forwardModified()
155 {
156  ::fwData::Image::csptr image = this->getInput< ::fwData::Image >(s_TARGET_INPUT);
158  sig->asyncEmit();
159 }
160 
161 //-----------------------------------------------------------------------------
162 
163 void SImageSignalForwarder::forwardBufferModified()
164 {
165  ::fwData::Image::csptr image = this->getInput< ::fwData::Image >(s_TARGET_INPUT);
167  sig->asyncEmit();
168 }
169 
170 //-----------------------------------------------------------------------------
171 
172 void SImageSignalForwarder::forwardLandmarkAdded(SPTR(::fwData::Point)point)
173 {
174  ::fwData::Image::csptr image = this->getInput< ::fwData::Image >(s_TARGET_INPUT);
176  sig->asyncEmit(point);
177 }
178 
179 //-----------------------------------------------------------------------------
180 
181 void SImageSignalForwarder::forwardLandmarkRemoved(SPTR(::fwData::Point)point)
182 {
183  ::fwData::Image::csptr image = this->getInput< ::fwData::Image >(s_TARGET_INPUT);
185  sig->asyncEmit(point);
186 }
187 
188 //-----------------------------------------------------------------------------
189 
190 void SImageSignalForwarder::forwardLandmarkDisplayed(bool display)
191 {
192  ::fwData::Image::csptr image = this->getInput< ::fwData::Image >(s_TARGET_INPUT);
194  sig->asyncEmit(display);
195 }
196 
197 //-----------------------------------------------------------------------------
198 
199 void SImageSignalForwarder::forwardDistanceAdded(SPTR(::fwData::PointList)pointList)
200 {
201  ::fwData::Image::csptr image = this->getInput< ::fwData::Image >(s_TARGET_INPUT);
203  sig->asyncEmit(pointList);
204 }
205 
206 //-----------------------------------------------------------------------------
207 
208 void SImageSignalForwarder::forwardDistanceRemoved(CSPTR(::fwData::PointList)pointList)
209 {
210  ::fwData::Image::csptr image = this->getInput< ::fwData::Image >(s_TARGET_INPUT);
212  sig->asyncEmit(pointList);
213 }
214 
215 //-----------------------------------------------------------------------------
216 
217 void SImageSignalForwarder::forwardDistanceDisplayed(bool display)
218 {
219  ::fwData::Image::csptr image = this->getInput< ::fwData::Image >(s_TARGET_INPUT);
221  sig->asyncEmit(display);
222 }
223 
224 //-----------------------------------------------------------------------------
225 
226 void SImageSignalForwarder::forwardSliceIndexModified(int axial, int frontal, int sagittal)
227 {
228  ::fwData::Image::csptr image = this->getInput< ::fwData::Image >(s_TARGET_INPUT);
229  auto sig = image->signal< ::fwData::Image::SliceIndexModifiedSignalType >(
231  sig->asyncEmit(axial, frontal, sagittal);
232 }
233 
234 //-----------------------------------------------------------------------------
235 
236 void SImageSignalForwarder::forwardSliceTypeModified(int from, int to)
237 {
238  ::fwData::Image::csptr image = this->getInput< ::fwData::Image >(s_TARGET_INPUT);
239  auto sig =
241  sig->asyncEmit(from, to);
242 }
243 
244 //-----------------------------------------------------------------------------
245 
246 void SImageSignalForwarder::forwardVisibilityModified(bool visibility)
247 {
248  ::fwData::Image::csptr image = this->getInput< ::fwData::Image >(s_TARGET_INPUT);
249  auto sig =
251  sig->asyncEmit(visibility);
252 }
253 
254 //-----------------------------------------------------------------------------
255 
256 void SImageSignalForwarder::forwardTransparencyModified()
257 {
258  ::fwData::Image::csptr image = this->getInput< ::fwData::Image >(s_TARGET_INPUT);
259  auto sig = image->signal< ::fwData::Image::TransparencyModifiedSignalType >(
261  sig->asyncEmit();
262 }
263 
264 //-----------------------------------------------------------------------------
265 
266 void SImageSignalForwarder::forwardAddedFields(::fwData::Object::FieldsContainerType objects)
267 {
268  ::fwData::Image::csptr image = this->getInput< ::fwData::Image >(s_TARGET_INPUT);
270  sig->asyncEmit(objects);
271 }
272 
273 //-----------------------------------------------------------------------------
274 
275 void SImageSignalForwarder::forwardChangedFields(::fwData::Object::FieldsContainerType newObjects,
277 {
278  ::fwData::Image::csptr image = this->getInput< ::fwData::Image >(s_TARGET_INPUT);
280  sig->asyncEmit(newObjects, oldObjects);
281 }
282 
283 //-----------------------------------------------------------------------------
284 
285 void SImageSignalForwarder::forwardRemovedFields(::fwData::Object::FieldsContainerType objects)
286 {
287  ::fwData::Image::csptr image = this->getInput< ::fwData::Image >(s_TARGET_INPUT);
289  sig->asyncEmit(objects);
290 }
291 
292 //-----------------------------------------------------------------------------
293 
294 } // wrapper
295 } // ctrlSelection
virtual CTRLSELECTION_API void stopping() override
Implements stopping method derived from IService. Does nothing.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_SLICE_INDEX_MODIFIED_SIG
Type of signal when image&#39;s buffer is added.
#define SPTR(_cls_)
#define CSPTR(_cls_)
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_TRANSPARENCY_MODIFIED_SIG
Type of signal when image&#39;s buffer is added.
FWCOM_API void disconnect()
Disconnect all registered connections and clear m_connections.
This class define a 3D point.
Definition: Point.hpp:22
virtual CTRLSELECTION_API void info(std::ostream &_sstream) override
Implements info method derived from IService. Print classname.
virtual CTRLSELECTION_API void configuring() override
Configures the service.
virtual CTRLSELECTION_API void updating() override
Implements updating method derived from IService. Does nothing.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_CHANGED_FIELDS_SIG
Type of signal m_sigModified.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_LANDMARK_DISPLAYED_SIG
Type of signal when image&#39;s buffer is added.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_LANDMARK_ADDED_SIG
Type of signal when image&#39;s buffer is added.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_ADDED_FIELDS_SIG
Type of signal m_sigModified.
The purpose of this service is to wrap messages incoming to the object to new messages.
Definition: IWrapperSrv.hpp:24
std::map< std::string,::fwData::Object::sptr > FieldsContainerType
Type of signal m_sigModified.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_DISTANCE_ADDED_SIG
Type of signal when image&#39;s buffer is added.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_VISIBILITY_MODIFIED_SIG
Type of signal when image&#39;s buffer is added.
#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
::fwRuntime::ConfigurationElement::sptr m_configuration
Configuration element used to configure service internal state using a generic XML like structure TOD...
Definition: IService.hpp:670
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_BUFFER_MODIFIED_SIG
Type of signal when image&#39;s buffer is added.
This class defines a list of points.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_REMOVED_FIELDS_SIG
Type of signal m_sigModified.
This class defines an image.
virtual CTRLSELECTION_API void swapping() override
Implements swapping method derived from IService. Convert the image.
The namespace ctrlSelection contains several interfaces for manager, updater and wrapper.
Definition: BookmarkSrv.hpp:15
virtual CTRLSELECTION_API void starting() override
Implements starting method derived from IService. Does nothing.
FWCOM_API void connect(const ::fwCom::HasSignals::csptr &hasSignals,::fwCom::Signals::SignalKeyType signalKey, const ::fwCom::HasSlots::csptr &hasSlots,::fwCom::Slots::SlotKeyType slotKey)
Connect signal to slot, and register this new connection in m_connections.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_SLICE_TYPE_MODIFIED_SIG
Type of signal when image&#39;s buffer is added.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_DISTANCE_REMOVED_SIG
Type of signal when image&#39;s buffer is added.
This service forwards signals from an image ti another.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_LANDMARK_REMOVED_SIG
Type of signal when image&#39;s buffer is added.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_DISTANCE_DISPLAYED_SIG
Type of signal when image&#39;s buffer is added.