fw4spl
core/fwDataTools/include/fwDataTools/Image.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_IMAGE_HPP__
8 #define __FWDATATOOLS_IMAGE_HPP__
9 
10 #include "fwDataTools/config.hpp"
11 #include <fwDataTools/helper/Array.hpp>
12 
13 #include <fwCore/base.hpp>
14 
15 #include <fwData/Image.hpp>
16 
17 #include <fwMath/Compare.hpp>
18 
19 #include <fwTools/Type.hpp>
20 
21 namespace fwDataTools
22 {
23 
27 class Image
28 {
29 
30 public:
31 
37  FWDATATOOLS_API static void applyRoi( ::fwData::Image::sptr image,
38  ::fwData::Image::sptr roi );
39 
44  FWDATATOOLS_API static bool isRoiApplyed( ::fwData::Image::sptr image,
45  ::fwData::Image::sptr imgRoiApplyed,
46  ::fwData::Image::sptr roi );
47 
51  template<typename IMG_DEST_TYPE, typename MASK_TYPE>
52  void mergeMask(::fwData::Image::sptr imgDest, ::fwData::Image::sptr mask, IMG_DEST_TYPE val );
53 
54 };
55 
56 //------------------------------------------------------------------------------
57 
58 template<typename IMG_DEST_TYPE, typename MASK_TYPE>
59 void Image::mergeMask(::fwData::Image::sptr imgDest, ::fwData::Image::sptr mask, IMG_DEST_TYPE val )
60 {
61  typedef IMG_DEST_TYPE ImgDestType;
62  typedef MASK_TYPE MaskType;
63  SLM_ASSERT( "Image dest has not correct type", imgDest->getType().isOfType< ImgDestType >());
64  SLM_ASSERT( "Image mask has not correct type", mask->getType().isOfType< MaskType >());
65 
66  SLM_ASSERT( "Images have not the same size", imgDest->getSize() == mask->getSize() );
67  SLM_ASSERT( "Images have not the same spacing",
68  ::fwMath::isContainerEqual(imgDest->getSpacing(), mask->getSpacing()) );
69  SLM_ASSERT( "Images have not the same origin",
70  ::fwMath::isContainerEqual(imgDest->getOrigin(), mask->getOrigin()) );
71 
72  ::fwData::Array::sptr imgData;
73  ::fwData::Array::sptr maskData;
74  imgData = imgDest->getDataArray();
75  maskData = mask->getDataArray();
76 
77  ::fwDataTools::helper::Array imgHelper(imgData);
78  ::fwDataTools::helper::Array maskHelper(maskData);
79 
80  ImgDestType* imgIt = imgHelper.begin<ImgDestType>();
81  MaskType* maskIt = maskHelper.begin<MaskType>();
82 
83  const ImgDestType* imgEnd = imgIt + maskData->getNumberOfElements();
84 
85  for (; imgIt != imgEnd; ++imgIt, ++maskIt)
86  {
87  if (*maskIt != 0)
88  {
89  *imgIt = val;
90  }
91  }
92 }
93 
94 } // namespace fwDataTools
95 
96 #endif // __FWDATATOOLS_IMAGE_HPP__
void mergeMask(::fwData::Image::sptr imgDest,::fwData::Image::sptr mask, IMG_DEST_TYPE val)
Merge mask in image imgDest: put value &#39;val&#39; in imgDest when mask value != 0.
The namespace fwDataTools contains classes which provide helpers to manipulate fwData::Object. *.
bool isContainerEqual(CONTAINER &containerA, CONTAINER &containerB, const float epsilon=0.00001F)
Returns true iff container a and b are equal with &#39;epsilon&#39; error margin.
Definition: Compare.hpp:36
virtual FWDATATOOLS_API char * begin()
Returns the begining/end of the buffer interpreted as a char buffer.
static FWDATATOOLS_API void applyRoi(::fwData::Image::sptr image,::fwData::Image::sptr roi)
Apply roi to 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
This class contains helper to generate and compare images.
Helper to manage array buffer. Lock the buffer before to modify it.
static FWDATATOOLS_API bool isRoiApplyed(::fwData::Image::sptr image,::fwData::Image::sptr imgRoiApplyed,::fwData::Image::sptr roi)
Check if &#39;imgRoiApplyed&#39; is the result of &#39;roi&#39; applyed to &#39;image&#39;.