fw4spl
ImageDiffCommand.cpp
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 #include "fwCommand/ImageDiffCommand.hpp"
8 
9 #include <fwCom/Signal.hpp>
10 #include <fwCom/Signal.hxx>
11 #include <fwCom/Signals.hpp>
12 
13 #include <fwTools/Type.hpp>
14 
15 namespace fwCommand
16 {
17 
18 //------------------------------------------------------------------------------
19 
20 ImageDiffCommand::ImageDiffCommand(const ::fwData::Image::sptr& img, ::fwDataTools::ImageDiff diff) :
21  m_img(img),
22  m_modifSig(img->signal< ::fwData::Image::BufferModifiedSignalType >(::fwData::Image::s_BUFFER_MODIFIED_SIG)),
23  m_diff(diff)
24 {
25  m_diff.shrink();
26 }
27 
28 //------------------------------------------------------------------------------
29 
31 {
32  return sizeof(*this) + m_diff.getSize();
33 }
34 
35 //------------------------------------------------------------------------------
36 
38 {
39  m_diff.applyDiff(m_img);
40 
41  m_modifSig->asyncEmit();
42 
43  return true;
44 }
45 
46 //------------------------------------------------------------------------------
47 
49 {
50  m_diff.revertDiff(m_img);
51 
52  m_modifSig->asyncEmit();
53 
54  return true;
55 }
56 
57 //------------------------------------------------------------------------------
58 
59 const std::string ImageDiffCommand::getDescription() const
60 {
61  return "ImageDiff";
62 }
63 
64 } // namespace fwCommand
virtual FWCOMMAND_API size_t getSize() const
The diff size.
FWDATATOOLS_API void shrink()
Reallocate the buffer to fit the actual size of the container.
Definition: ImageDiff.cpp:180
FWDATATOOLS_API size_t getSize() const
Return the amount of memory actually used by the elements.
Definition: ImageDiff.cpp:159
FWDATATOOLS_API void revertDiff(const ::fwData::Image::sptr &img) const
Write the old value back in the image.
Definition: ImageDiff.cpp:147
virtual FWCOMMAND_API const std::string getDescription() const
Returns "ImageDiff".
FWDATATOOLS_API void applyDiff(const ::fwData::Image::sptr &img) const
Write the new values in the image.
Definition: ImageDiff.cpp:135
The namespace fwCommand contains classes describing and managing commands.
Definition: ICommand.hpp:15
FWCOMMAND_API ImageDiffCommand(const ::fwData::Image::sptr &img,::fwDataTools::ImageDiff diff)
Constructor, uses an image and a change list for that image.
virtual FWCOMMAND_API bool undo()
Revert diff.
Class memorizing pixel changes in an image.
Definition: ImageDiff.hpp:21
virtual FWCOMMAND_API bool redo()
Apply diff.
Contains the representation of the data objects used in the framework.