2 * @file imageUndoRedo.cxx
3 * @brief This file contains the implementation of the ImageUndoRedo class.
5 * @author Diego CACERES (diego.caceres[AT]creatis.insa-lyon.fr)
9 #include "imageUndoRedo.h"
11 // ----------------------------------------------------------------------------------
12 ImageUndoRedo::ImageUndoRedo() {
13 this->m_ImagesDeque = new IDequeType();
15 // ----------------------------------------------------------------------------------
17 ImageUndoRedo::~ImageUndoRedo() {
20 // ----------------------------------------------------------------------------------
22 void ImageUndoRedo::Undo() {
23 ImageInfoUR* imageInfo = this->m_ImagesDeque->Undo();
24 if (imageInfo != NULL) {
25 this->DrawUR(imageInfo, true);
26 this->UpdateUndoImage();
29 // ----------------------------------------------------------------------------------
31 void ImageUndoRedo::Redo() {
32 ImageInfoUR* imageInfo = this->m_ImagesDeque->Redo();
33 if (imageInfo != NULL) {
34 this->DrawUR(imageInfo, false);
35 this->UpdateUndoImage();
38 // ----------------------------------------------------------------------------------
39 void ImageUndoRedo::SetImage(VTKImageDataPointerType image) {
40 this->m_CurrentImage = image;
41 this->m_CurrentImage->Update();
42 this->UpdateUndoImage();
44 // ----------------------------------------------------------------------------------
46 void ImageUndoRedo::SetURImages(ImageMManagerType* imMManager) {
47 ImageMManagerType* newImageManager = new ImageMManagerType(imMManager);
48 if (newImageManager->ValidateRegion()) {
49 RegionSType region = newImageManager->GetModifiedRegion();
50 VTKImageDataPointerType imgUndo = this->GetImageRegion(region,
52 VTKImageDataPointerType imgRedo = this->GetImageRegion(region,
53 this->m_CurrentImage);
54 this->m_ImagesDeque->AddImagesToURContainer(imgUndo, imgRedo,
56 this->UpdateUndoImage();
58 std::cerr << "INVALID REGION" << std::endl;
61 // ----------------------------------------------------------------------------------
62 void ImageUndoRedo::UpdateUndoImage() {
63 this->m_CurrentImage->Update();
64 this->m_UndoImage = VTKImageDataPointerType::New();
65 this->m_UndoImage->DeepCopy(m_CurrentImage);
66 this->m_UndoImage->Update();
68 // ----------------------------------------------------------------------------------
69 ImageUndoRedo::VTKImageDataPointerType ImageUndoRedo::GetImageRegion(
70 const RegionSType& region, VTKImageDataPointerType img) {
71 VTKExtractVOIPointerType extract = VTKExtractVOIPointerType::New();
72 extract->SetVOI(region.minX, region.maxX, region.minY, region.maxY,
73 region.minZ, region.maxZ);
74 extract->SetSampleRate(1, 1, 1);
75 extract->SetInput(img);
76 VTKImageDataPointerType imgResult = extract->GetOutput();
80 // ----------------------------------------------------------------------------------
81 void ImageUndoRedo::SetCurrentImage(VTKImageDataPointerType img) {
82 this->m_CurrentImage = img;
84 // ----------------------------------------------------------------------------------
86 void ImageUndoRedo::DrawUR(ImageInfoUR* imageInfo, const bool& undo) {
87 VTKImageDataPointerType img;
89 img = imageInfo->GetUndoImage();
92 img = imageInfo->GetRedoImage();
94 RegionSType region = imageInfo->GetImageMManager()->GetModifiedRegion();
96 for (int i = region.minX, x = 0; i <= region.maxX; i++, x++) {
97 for (int j = region.minY, y = 0; j <= region.maxY; j++, y++) {
98 for (int k = region.minZ, z = 0; k <= region.maxZ; k++, z++) {
99 float value = img->GetScalarComponentAsFloat(x, y, z, 0);
100 this->m_CurrentImage->SetScalarComponentFromFloat(i, j, k,
105 this->m_CurrentImage->Modified();
107 this->m_ImagesDeque->ManageMemory();
109 // ----------------------------------------------------------------------------------