]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageUndoRedo.cxx
DFCH: UndoRedo + ManualPaint - Code update. Undo beta1 working :) :) :)
[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         }
25 }
26 //virtual
27 void ImageUndoRedo::Redo() {
28         ImageInfoUR* imageInfo = this->m_ImagesDeque->Redo();
29         this->DrawUR(imageInfo);
30 }
31 void ImageUndoRedo::SetImage(VTKImageDataPointerType image) {
32         this->m_CurrentImage = image;
33         this->m_CurrentImage->Update();
34         this->m_OriginalImage = VTKImageDataPointerType::New();
35         this->m_OriginalImage->DeepCopy(m_CurrentImage);
36 }
37 //virtual
38 void ImageUndoRedo::SetUndoImage(const RegionSType& region) {
39         VTKImageDataPointerType imgResult = this->GetImageRegion(region,
40                         this->m_OriginalImage);
41         this->m_ImagesDeque->AddImageToUndoContainer(imgResult, region);
42 }
43 //virtual
44 void ImageUndoRedo::SetRedoImage(const RegionSType& region) {
45         VTKImageDataPointerType imgResult = this->GetImageRegion(region,
46                         this->m_CurrentImage);
47         this->m_ImagesDeque->AddImageToRedoContainer(imgResult, region);
48 }
49
50 ImageUndoRedo::VTKImageDataPointerType ImageUndoRedo::GetImageRegion(
51                 const RegionSType& region, VTKImageDataPointerType img) {
52         VTKExtractVOIPointerType extract = VTKExtractVOIPointerType::New();
53         VTKImageDataPointerType imgResult = VTKImageDataPointerType::New();
54         extract->SetVOI(region.minX, region.maxX, region.minY, region.maxY,
55                         region.minZ, region.maxZ);
56         extract->SetSampleRate(1, 1, 1);
57         extract->SetInput(this->m_OriginalImage);
58         imgResult = extract->GetOutput();
59         return (imgResult);
60 }
61
62 void ImageUndoRedo::SetOriginalImage(VTKImageDataPointerType img) {
63         this->m_OriginalImage = img;
64 }
65 void ImageUndoRedo::SetCurrentImage(VTKImageDataPointerType img) {
66         this->m_CurrentImage = img;
67 }
68 //virtual
69 void ImageUndoRedo::DrawUR(ImageInfoUR* imageInfo) {
70         VTKImageDataPointerType img = imageInfo->GetImage();
71         for (int i = imageInfo->GetRegion().minX, x = 0;
72                         i <= imageInfo->GetRegion().maxX; i++, x++) {
73                 for (int j = imageInfo->GetRegion().minY, y = 0;
74                                 j <= imageInfo->GetRegion().maxY; j++, y++) {
75                         for (int k = imageInfo->GetRegion().minZ, z = 0;
76                                         k <= imageInfo->GetRegion().maxZ; k++, z++) {
77                                 float value = img->GetScalarComponentAsFloat(i, j, k, 0);
78                                 this->m_CurrentImage->SetScalarComponentFromFloat(i, j, k, 0,
79                                                 value);
80                         } //rof
81                 } //rof
82         } //rof
83         this->m_CurrentImage->Modified();
84 }
85