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