fw4spl
SComputeHistogram.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 "scene2D/processing/SComputeHistogram.hpp"
8 
9 #include "scene2D/processing/ComputeHistogramFunctor.hxx"
10 
11 #include <fwCom/Signal.hpp>
12 #include <fwCom/Signal.hxx>
13 #include <fwCom/Signals.hpp>
14 
15 #include <fwData/Histogram.hpp>
16 #include <fwData/Image.hpp>
17 #include <fwData/mt/ObjectReadLock.hpp>
18 #include <fwData/mt/ObjectWriteLock.hpp>
19 
20 #include <fwServices/macros.hpp>
21 
22 #include <boost/lexical_cast.hpp>
23 
25 
26 namespace scene2D
27 {
28 namespace processing
29 {
30 
31 static const ::fwServices::IService::KeyType s_IMAGE_INPUT = "image";
32 static const ::fwServices::IService::KeyType s_HISTOGRAM_INPUT = "histogram";
33 
35  m_binsWidth(1.0f)
36 {
37 }
38 
39 //-----------------------------------------------------------------------------
40 
42 {
43 }
44 
45 //-----------------------------------------------------------------------------
46 
48 {
49  const std::vector < ::fwRuntime::ConfigurationElement::sptr > binsWidthCfg = m_configuration->find("binsWidth");
50  SLM_ASSERT("Missing tag 'binsWidth'", !binsWidthCfg.empty());
51 
52  const std::string binsWidth = binsWidthCfg.front()->getValue();
53  SLM_ASSERT("'binsWidth' must not be empty", !binsWidth.empty());
54  m_binsWidth = ::boost::lexical_cast<float>(binsWidth);
55 }
56 
57 //-----------------------------------------------------------------------------
58 
60 {
61  m_slotUpdate->asyncRun();
62 }
63 
64 //-----------------------------------------------------------------------------
65 
67 {
68  ::fwData::Image::csptr image = this->getInput< ::fwData::Image>(s_IMAGE_INPUT);
69 
70  ::fwData::mt::ObjectReadLock imgLock(image);
71 
73  {
74  ::fwData::Histogram::sptr histogram = this->getInOut< ::fwData::Histogram>(s_HISTOGRAM_INPUT);
75 
76  ::fwData::mt::ObjectWriteLock lock(histogram);
77 
79  param.image = image;
80  param.histogram = histogram;
81  param.binsWidth = m_binsWidth;
82 
83  ::fwTools::DynamicType type = image->getPixelType();
85 
87  {
88  ::fwCom::Connection::Blocker block(sig->getConnection(m_slotUpdate));
89  sig->asyncEmit();
90  }
91  }
92 }
93 
94 //-----------------------------------------------------------------------------
95 
97 {
98  this->updating();
99 }
100 
101 //-----------------------------------------------------------------------------
102 
104 {
105 }
106 
107 //------------------------------------------------------------------------------
108 
110 {
111  KeyConnectionsMap connections;
112  connections.push( s_IMAGE_INPUT, ::fwData::Image::s_MODIFIED_SIG, s_UPDATE_SLOT );
113  connections.push( s_IMAGE_INPUT, ::fwData::Image::s_BUFFER_MODIFIED_SIG, s_UPDATE_SLOT );
114 
115  return connections;
116 }
117 
118 //-----------------------------------------------------------------------------
119 
120 } // namespace processing
121 } // namespace scene2D
122 
This class is a helper to define the connections of a service and its data.
Definition: IService.hpp:454
Class allowing to block a Connection.
Definition: Connection.hpp:20
A helper to lock object on read mode.
SCENE2D_API void starting() override
Starts the service. Calls updating().
A helper to lock object on exclusive mode.
virtual SCENE2D_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
Class defining an elementary C++ type aka unsigned char, signed char, .... signed long...
Definition: DynamicType.hpp:31
SCENE2D_API void updating() override
Computes the histogram and notifies Histogram::s_MODIFIED_SIG.
This bundles contains data and services used to display a 2D Qt scene.
UpdateSlotType::sptr m_slotUpdate
Slot to call update method.
Definition: IService.hpp:690
This interface defines control service API. Does nothing particularly, can be considered as a default...
Definition: IController.hpp:23
The SComputeHistogram service computes the histogram of the image.
#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
static void invoke()
Instanciate and invoke all functors.
Definition: Dispatcher.hpp:99
SCENE2D_API SComputeHistogram() noexcept
Constructor. Does nothing.
::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.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
static FWDATATOOLS_API bool checkImageValidity(::fwData::Image::csptr _pImg)
Check if the image is valid.
SCENE2D_API void swapping() override
Swaps the service. Calls updating().
SCENE2D_API void stopping() override
Stops the service. Does nothing.
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_SLOT
Slot to call start method.
Definition: IService.hpp:177
virtual SCENE2D_API ~SComputeHistogram() noexcept
Destructor. Does nothing.
SCENE2D_API void configuring() override
Configure the service before starting. Apply the configuration to service.