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