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