fw4spl
ImageGetter.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 "fwDataTools/helper/ImageGetter.hpp"
8 
9 #include <fwCom/Signal.hpp>
10 #include <fwCom/Signal.hxx>
11 #include <fwCom/Signals.hpp>
12 
13 #include <fwData/Composite.hpp>
14 #include <fwData/PointList.hpp>
15 #include <fwData/TransferFunction.hpp>
16 
17 namespace fwDataTools
18 {
19 namespace helper
20 {
21 
22 //-----------------------------------------------------------------------------
23 
24 ImageGetter::ImageGetter( ::fwData::Image::csptr ImageGetter ) :
25  m_image(ImageGetter)
26 {
27  if ( ImageGetter )
28  {
29  m_lock = ImageGetter->getDataArray()->getBufferObject()->lock();
30  }
31 }
32 
33 //-----------------------------------------------------------------------------
34 
36 {
37 }
38 
39 //-----------------------------------------------------------------------------
40 
42 {
43  return m_lock.getBuffer();
44 }
45 
46 //------------------------------------------------------------------------------
47 
48 void* ImageGetter::getPixelBuffer( SizeType::value_type x, SizeType::value_type y, SizeType::value_type z ) const
49 {
50  SizeType size = m_image->getSize();
51  IndexType offset = x + size[0]*y + z*size[0]*size[1];
52  return this->getPixelBuffer(offset);
53 }
54 
55 //------------------------------------------------------------------------------
56 
57 void* ImageGetter::getPixelBuffer( IndexType index ) const
58 {
59  std::uint8_t imageGetterPixelSize = m_image->getType().sizeOf() * m_image->getNumberOfComponents();
60  BufferType* buf = static_cast < BufferType* > (this->getBuffer());
61  BufferIndexType bufIndex = index * imageGetterPixelSize;
62  return buf + bufIndex;
63 }
64 
65 //------------------------------------------------------------------------------
66 
67 const std::string ImageGetter::getPixelAsString(SizeType::value_type x,
68  SizeType::value_type y,
69  SizeType::value_type z ) const
70 {
71  return m_image->getType().toString(this->getPixelBuffer(x, y, z));
72 }
73 
74 //------------------------------------------------------------------------------
75 
76 } // helper
77 } // fwDataTools
virtual FWDATATOOLS_API ~ImageGetter()
Destrucotr. Do nothing.
Definition: ImageGetter.cpp:35
FWDATATOOLS_API const std::string getPixelAsString(SizeType::value_type x, SizeType::value_type y, SizeType::value_type z) const
Helpers for 3D images.
Definition: ImageGetter.cpp:67
The namespace fwDataTools contains classes which provide helpers to manipulate fwData::Object. *.
FWDATATOOLS_API void * getBuffer() const
Returns image buffer.
Definition: ImageGetter.cpp:41
FWDATATOOLS_API ImageGetter(::fwData::Image::csptr image)
Constructor. Initialize parameters.
Definition: ImageGetter.cpp:24
LockBase< T >::BufferType getBuffer() const
Returns BufferObject&#39;s buffer pointer.
FWDATATOOLS_API void * getPixelBuffer(SizeType::value_type x, SizeType::value_type y, SizeType::value_type z) const
Helpers for 3D images.
Definition: ImageGetter.cpp:48
Defines an helper to modify an fwData::Image by adding few medical fields and create in parallel the ...
Definition: ImageGetter.hpp:23