]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.cxx
DFCH: imageUndoRedo + Manual Paint: It doesn't works :s :s
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / imageUndoRedo / imageUndoRedo.cxx
1 /*
2  * imageUndoRedo.cxx
3  *
4  *  Created on: Sep 26, 2011
5  *      Author: caceres
6  */
7
8 #include "imageUndoRedo.h"
9
10 ImageUndoRedo::ImageUndoRedo() {
11         this->m_ImagesDeque = new IDequeType();
12 }
13 //virtual
14 ImageUndoRedo::~ImageUndoRedo() {
15
16 }
17 //virtual
18 void ImageUndoRedo::Undo() {
19         ImageInfoUR* imageInfo = this->m_ImagesDeque->Undo();
20         if (imageInfo != NULL) {
21                 //this->SetRedoImage(imageInfo->GetImageMManager());
22                 this->DrawUR(imageInfo, true);
23                 this->UpdateUndoImage();
24         }
25 }
26 //virtual
27 void ImageUndoRedo::Redo() {
28         /*ImageInfoUR* imageInfo = this->m_ImagesDeque->Redo();
29          if (imageInfo != NULL)
30          {
31          this->DrawUR(imageInfo);
32          }*/
33 }
34 void ImageUndoRedo::SetImage(VTKImageDataPointerType image) {
35         this->m_CurrentImage = image;
36         this->m_CurrentImage->Update();
37         this->UpdateUndoImage();
38 }
39 //virtual
40 void ImageUndoRedo::SetURImages(ImageMManagerType* imMManager) {
41         ImageMManagerType* newImageManager = new ImageMManagerType(imMManager);
42         if (newImageManager->ValidateRegion()) {
43                 RegionSType region = newImageManager->GetModifiedRegion();
44                 VTKImageDataPointerType imgUndo = this->GetImageRegion(region,
45                                 this->m_UndoImage);
46                 VTKImageDataPointerType imgRedo = this->GetImageRegion(region,
47                                 this->m_CurrentImage);
48                 this->m_ImagesDeque->AddImagesToURContainer(imgUndo, imgRedo,
49                                 newImageManager);
50                 this->UpdateUndoImage();
51         } else {
52                 std::cerr << "INVALID REGION" << std::endl;
53         }
54 }
55
56 void ImageUndoRedo::UpdateUndoImage() {
57         this->m_CurrentImage->Update();
58         this->m_UndoImage = VTKImageDataPointerType::New();
59         this->m_UndoImage->DeepCopy(m_CurrentImage);
60         this->m_UndoImage->Update();
61 }
62
63 ImageUndoRedo::VTKImageDataPointerType ImageUndoRedo::GetImageRegion(
64                 const RegionSType& region, VTKImageDataPointerType img) {
65         VTKExtractVOIPointerType extract = VTKExtractVOIPointerType::New();
66         extract->SetVOI(region.minX, region.maxX, region.minY, region.maxY,
67                         region.minZ, region.maxZ);
68         extract->SetSampleRate(1, 1, 1);
69         extract->SetInput(this->m_UndoImage);
70         VTKImageDataPointerType imgResult = extract->GetOutput();
71         imgResult->Update();
72         return (imgResult);
73 }
74
75 void ImageUndoRedo::SetCurrentImage(VTKImageDataPointerType img) {
76         this->m_CurrentImage = img;
77 }
78 //virtual
79 void ImageUndoRedo::DrawUR(ImageInfoUR* imageInfo, const bool& undo) {
80         VTKImageDataPointerType img;
81         if (undo) {
82                 img = imageInfo->GetUndoImage();
83         } //fi
84         else {
85                 img = imageInfo->GetRedoImage();
86         } //else
87         RegionSType region = imageInfo->GetImageMManager()->GetModifiedRegion();
88         if (img != NULL) {
89                 for (int i = region.minX, x = 0; i <= region.maxX; i++, x++) {
90                         for (int j = region.minY, y = 0; j <= region.maxY; j++, y++) {
91                                 for (int k = region.minZ, z = 0; k <= region.maxZ; k++, z++) {
92                                         float value = img->GetScalarComponentAsFloat(x, y, z, 0);
93                                         this->m_CurrentImage->SetScalarComponentFromFloat(i, j, k,
94                                                         0, value);
95                                 } //rof
96                         } //rof
97                 } //rof
98                 this->m_CurrentImage->Modified();
99         }
100         this->m_ImagesDeque->ManageMemory();
101 }
102