fw4spl
ImageDiff.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 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_IMAGEDIFF_HPP__
8 #define __FWDATATOOLS_IMAGEDIFF_HPP__
9 
10 #include "fwDataTools/config.hpp"
11 #include "fwDataTools/helper/Image.hpp"
12 
13 #include <fwData/Image.hpp>
14 
15 namespace fwDataTools
16 {
17 
21 class FWDATATOOLS_CLASS_API ImageDiff
22 {
23 public:
24 
25  struct ElementType
26  {
27  ::fwData::Image::IndexType m_index;
28  ::fwData::Image::BufferType* m_oldValue;
29  ::fwData::Image::BufferType* m_newValue;
30  };
31 
33  FWDATATOOLS_API ImageDiff(const size_t imageElementSize = 0, const size_t reservedElements = 0);
34 
36  FWDATATOOLS_API ~ImageDiff();
37 
39  FWDATATOOLS_API ImageDiff(const ImageDiff& other);
40 
42  FWDATATOOLS_API ImageDiff(ImageDiff&& other);
43 
45  FWDATATOOLS_API ImageDiff& operator= (const ImageDiff& other);
46 
48  FWDATATOOLS_API ImageDiff& operator= (ImageDiff&& other);
49 
51  FWDATATOOLS_API void addDiff(const ImageDiff& diff);
52 
54  FWDATATOOLS_API void addDiff(const ::fwData::Image::IndexType index, const ::fwData::Image::BufferType* oldValue,
55  const ::fwData::Image::BufferType* newValue);
56 
58  FWDATATOOLS_API void applyDiff(const ::fwData::Image::sptr& img) const;
59 
61  FWDATATOOLS_API void revertDiff(const ::fwData::Image::sptr& img) const;
62 
64  FWDATATOOLS_API size_t getSize() const;
65 
67  FWDATATOOLS_API size_t getNumberOfElements() const;
68 
70  FWDATATOOLS_API void clear();
71 
73  FWDATATOOLS_API void shrink();
74 
76  FWDATATOOLS_API ElementType getElement(size_t index) const;
77 
79  inline ::fwData::Image::IndexType getElementDiffIndex(size_t eltIndex) const;
80 
81 private:
82 
84  void applyDiffElt(helper::Image& img, size_t eltIndex) const;
85 
87  void revertDiffElt(helper::Image& img, size_t eltIndex) const;
88 
90  size_t m_imgEltSize;
91 
93  size_t m_eltSize;
94 
96  size_t m_nbElts;
97 
99  size_t m_reservedSize;
100 
102  std::uint8_t* m_buffer;
103 };
104 
105 //------------------------------------------------------------------------------
106 
107 fwData::Image::IndexType ImageDiff::getElementDiffIndex(size_t eltIndex) const
108 {
109  std::uint8_t* eltPtr = m_buffer + eltIndex * m_eltSize;
110  return *reinterpret_cast< ::fwData::Image::IndexType* >(eltPtr);
111 }
112 
113 } // namespace fwDataTools
114 
115 #endif // __FWDATATOOLS_IMAGEDIFF_HPP__
The namespace fwDataTools contains classes which provide helpers to manipulate fwData::Object. *.
inline::fwData::Image::IndexType getElementDiffIndex(size_t eltIndex) const
Returns the image index from the element at the given index.
Definition: ImageDiff.hpp:107
Defines an helper to modify an fwData::Image by adding few medical fields and create in parallel the ...
Class memorizing pixel changes in an image.
Definition: ImageDiff.hpp:21