fw4spl
ComputeHistogramFunctor.hxx
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 #ifndef __SCENE2D_PROCESSING_COMPUTEHISTOGRAMFUNCTOR_HXX__
8 #define __SCENE2D_PROCESSING_COMPUTEHISTOGRAMFUNCTOR_HXX__
9 
10 #include "scene2D/processing/SComputeHistogram.hpp"
11 
12 #include <fwDataTools/fieldHelper/MedicalImageHelpers.hpp>
13 #include <fwDataTools/helper/Array.hpp>
14 #include <fwDataTools/helper/ImageGetter.hpp>
15 
16 namespace scene2D
17 {
18 namespace processing
19 {
20 
25 {
27  struct Parameter
28  {
29  ::fwData::Image::csptr image;
30  ::fwData::Histogram::sptr histogram;
31  float binsWidth;
32  };
33 
34  //------------------------------------------------------------------------------
35 
36  template<class IMAGETYPE>
37  void operator()(Parameter& param)
38  {
39  ::fwData::Image::csptr image = param.image;
40  ::fwData::Histogram::sptr histogram = param.histogram;
41 
42  ::fwDataTools::helper::ImageGetter imgHelper(image);
43 
44  IMAGETYPE min = std::numeric_limits<IMAGETYPE>::max();
45  IMAGETYPE max = std::numeric_limits<IMAGETYPE>::min();
46 
48  SLM_ASSERT("Wrong image", max > min);
49  if( max > min )
50  {
51  histogram->initialize( min, max, param.binsWidth );
52 
53  ::fwData::Array::sptr array = image->getDataArray();
54  ::fwDataTools::helper::Array arrayHelper(array);
55 
56  IMAGETYPE* itr = arrayHelper.begin<IMAGETYPE>();
57  IMAGETYPE* itrEnd = arrayHelper.end<IMAGETYPE>();
58 
59  for(; itr != itrEnd; ++itr)
60  {
61  histogram->addPixel( static_cast< float >( *itr ) );
62  }
63  }
64 
65  }
66 };
67 
68 } // namespace processing
69 } // namespace scene2D
70 
71 #endif /* __SCENE2D_PROCESSING_COMPUTEHISTOGRAMFUNCTOR_HXX__ */
72 
This bundles contains data and services used to display a 2D Qt scene.
virtual FWDATATOOLS_API char * begin()
Returns the begining/end of the buffer interpreted as a char buffer.
#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
Defines an helper to modify an fwData::Image by adding few medical fields and create in parallel the ...
Definition: ImageGetter.hpp:23
Functor use to compute the histogram of the image.
static void getMinMax(const ::fwData::Image::csptr _img, MINMAXTYPE &_min, MINMAXTYPE &_max)
Return minimum and maximum values contained in image. If image min or max value is out of MINMAXTYPE ...
Helper to manage array buffer. Lock the buffer before to modify it.