fw4spl
MedicalImageAdaptor.hpp
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 __FWDATATOOLS_HELPER_MEDICALIMAGEADAPTOR_HPP__
8 #define __FWDATATOOLS_HELPER_MEDICALIMAGEADAPTOR_HPP__
9 
10 #include "fwDataTools/config.hpp"
11 #include "fwDataTools/helper/ImageGetter.hpp"
12 
13 #include <fwCom/helper/SigSlotConnection.hpp>
14 #include <fwCom/Slot.hpp>
15 #include <fwCom/Slots.hpp>
16 
17 #include <fwData/Composite.hpp>
18 #include <fwData/Integer.hpp>
19 #include <fwData/String.hpp>
20 #include <fwData/TransferFunction.hpp>
21 
22 #include <vector>
23 
24 namespace fwDataTools
25 {
26 
27 namespace helper
28 {
29 
39 class FWDATATOOLS_CLASS_API MedicalImageAdaptor
40 {
41 
42 public:
44 
46  typedef enum
47  {
48  X_AXIS = 0,
49  Y_AXIS,
50  Z_AXIS
51  } Orientation;
52 
54  FWDATATOOLS_API virtual ~MedicalImageAdaptor();
55 
57  FWDATATOOLS_API virtual void setOrientation( Orientation orientation );
58 
60  Orientation getOrientation() const
61  {
62  return m_orientation;
63  }
64 
66  FWDATATOOLS_API void setTransferFunction( const ::fwData::TransferFunction::sptr& tf );
67 
68 protected:
69 
71  FWDATATOOLS_API MedicalImageAdaptor(); // this class VISUVTKADAPTOR_CLASS_API must be specialized
72 
77  FWDATATOOLS_API void setOrientation( int orientation );
78 
83  FWDATATOOLS_API void getImageSpacing(double spacing[3]) const;
84 
89  FWDATATOOLS_API void getImageOrigin(double origin[3]) const;
90 
95  FWDATATOOLS_API void getImageDataSize(int size[3]) const;
96 
101  FWDATATOOLS_API void getImageSize(double size[3]) const;
102 
107  FWDATATOOLS_API void getCurrentSliceCenter(double center[3]);
108 
114  FWDATATOOLS_API void worldToSliceIndex(const double world[3], int index[3] );
115 
121  FWDATATOOLS_API void worldToImageSliceIndex(const double world[3], int index[3] );
122 
128  FWDATATOOLS_API void sliceIndexToWorld(const int index[3], double world[3] );
129 
131  FWDATATOOLS_API ::fwData::Image::sptr getImage() const;
132 
137  template< typename FLOAT_ARRAY_3 >
138  void getImageSpacing(FLOAT_ARRAY_3 spacing);
139 
144  template< typename INT_INDEX >
145  void getImageDataSize(INT_INDEX size);
146 
152  template< typename WORLD, typename INT_INDEX >
153  void worldToSliceIndex(const WORLD world, INT_INDEX* index );
154 
160  template< typename WORLD, typename INT_INDEX >
161  void worldToImageSliceIndex(const WORLD world, INT_INDEX* index );
162 
170  FWDATATOOLS_API void getPlane( double points[4][3], int sliceNumber );
171 
173  FWDATATOOLS_API bool setSliceIndex(const int index[3]);
175  FWDATATOOLS_API void getSliceIndex(::fwData::Integer::sptr index[3]);
176 
178  FWDATATOOLS_API void updateImageInfos( ::fwData::Image::sptr image );
179 
187  FWDATATOOLS_API void createTransferFunction( ::fwData::Image::sptr image );
188 
194  FWDATATOOLS_API void setOrCreateTF(const ::fwData::TransferFunction::sptr& _tf, const fwData::Image::sptr& _image);
195 
197  FWDATATOOLS_API ::fwData::TransferFunction::sptr getTransferFunction() const;
198 
204  FWDATATOOLS_API void installTFConnections();
206 
208  FWDATATOOLS_API void removeTFConnections();
209 
217  FWDATATOOLS_API void installTFSlots(::fwCom::HasSlots* hasslots);
218 
220  FWDATATOOLS_API virtual void updateTFPoints();
221 
223  FWDATATOOLS_API virtual void updateTFWindowing(double window, double level);
224 
225  typedef ::fwCom::Slot<void ()> UpdateTFPointsSlotType;
226  typedef ::fwCom::Slot<void (double, double)> UpdateTFWindowingSlotType;
227 
229  UpdateTFPointsSlotType::sptr m_slotUpdateTFPoints;
230 
232  UpdateTFWindowingSlotType::sptr m_slotUpdateTFWindowing;
237  Orientation m_orientation;
239 
241  ::fwData::Integer::sptr m_axialIndex;
243  ::fwData::Integer::sptr m_frontalIndex;
245  ::fwData::Integer::sptr m_sagittalIndex;
246 
247 private:
248 
250  ::fwData::Image::wptr m_weakImage;
251 
253  ::fwData::TransferFunction::wptr m_transferFunction;
254 
256  ::fwCom::helper::SigSlotConnection m_tfConnections;
257 };
258 
259 //------------------------------------------------------------------------------
260 template< typename FLOAT_ARRAY_3 >
261 void MedicalImageAdaptor::getImageSpacing(FLOAT_ARRAY_3 spacing)
262 {
263  ::fwData::Image::sptr image = this->getImage();
264 
265  const ::fwData::Image::SpacingType imSpacing = image->getSpacing();
266  std::copy(imSpacing.begin(), imSpacing.end(), spacing);
267 }
268 
269 //------------------------------------------------------------------------------
270 template< typename INT_INDEX >
272 {
273  ::fwData::Image::sptr image = this->getImage();
274 
275  const ::fwData::Image::SizeType imSize = image->getSize();
276  std::copy(imSize.begin(), imSize.end(), size);
277 }
278 
279 //------------------------------------------------------------------------------
280 
281 template< typename WORLD, typename INT_INDEX >
282 void MedicalImageAdaptor::worldToSliceIndex(const WORLD world, INT_INDEX* index )
283 {
284  double spacing[3];
285  this->getImageSpacing(spacing);
286  double origin[3];
287  this->getImageOrigin(origin);
288  for ( int i = 0; i < 3; ++i )
289  {
290  index[i] =
291  static_cast< INT_INDEX >( ( (world[i] - origin[i])/spacing[i] ) +
292  ( ( (world[i] - origin[i])/spacing[i] ) >= 0 ? 0.5 : -0.5 ) );
293  }
294 }
295 
296 //------------------------------------------------------------------------------
297 
298 template< typename WORLD, typename INT_INDEX >
299 void MedicalImageAdaptor::worldToImageSliceIndex(const WORLD world, INT_INDEX* index )
300 {
301  INT_INDEX imageSize[3];
302  this->getImageDataSize(imageSize);
303  this->worldToSliceIndex(world, index);
304 
305  INT_INDEX idval;
306  for (int i = 0; i < 3; i++)
307  {
308  INT_INDEX max = imageSize[i]-1;
309  idval = index[i];
310  if (idval < 0)
311  {
312  index[i] = 0;
313  }
314  else if (idval > max)
315  {
316  index[i] = max;
317  }
318  }
319 }
320 
321 } //namespace helper
322 
323 } //namespace fwDataTools
324 
325 #endif // __FWDATATOOLS_HELPER_MEDICALIMAGEADAPTOR_HPP__
326 
::fwData::Integer::sptr m_axialIndex
Axial slice index.
The namespace fwDataTools contains classes which provide helpers to manipulate fwData::Object. *.
This class proposes a mapping between a SlotKeyType and a SlotBase.
Definition: HasSlots.hpp:22
Orientation getOrientation() const
Return the image orientation.
::fwData::Integer::sptr m_sagittalIndex
Sagittal slice index.
UpdateTFWindowingSlotType::sptr m_slotUpdateTFWindowing
Slot called when transfer function windowing is modified.
FWDATATOOLS_API void worldToSliceIndex(const double world[3], int index[3])
Convert world coordinates to slice index coordinates.
FWDATATOOLS_API void worldToImageSliceIndex(const double world[3], int index[3])
Convert coordinates in the world to coordinates in the image.
This class provides few tools to ease connect/disconnect between a signal emitter and a slot receiver...
::fwCom::Slot< void()> UpdateTFPointsSlotType
Slot called when transfer function points are modified.
::fwData::Integer::sptr m_frontalIndex
Frontal slice index.
::fwCom::Slot< void(double, double)> UpdateTFWindowingSlotType
Slot called when transfer function points are modified.
#define fwCoreBaseClassDefinitionsMacro(_classinfo_)
Generate common code for a base class (Interfaces, Abstract classes, ...)
UpdateTFPointsSlotType::sptr m_slotUpdateTFPoints
Slot called when transfer function points are modified.
FWDATATOOLS_API void getImageDataSize(int size[3]) const
Get the image data size (number of slices).
FWDATATOOLS_API void getImageSpacing(double spacing[3]) const
Get the image spacing.