4 * Created on: Sep 26, 2011
8 #include "imageUndoRedo.h"
10 ImageUndoRedo::ImageUndoRedo() {
11 this->m_ImagesDeque = new IDequeType();
14 ImageUndoRedo::~ImageUndoRedo() {
18 void ImageUndoRedo::Undo() {
19 ImageInfoUR* imageInfo = this->m_ImagesDeque->Undo();
20 if (imageInfo != NULL)
22 //this->SetRedoImage(imageInfo->GetImageMManager());
23 this->DrawUR(imageInfo);
24 this->UpdateUndoImage();
28 void ImageUndoRedo::Redo() {
29 /*ImageInfoUR* imageInfo = this->m_ImagesDeque->Redo();
30 if (imageInfo != NULL)
32 this->DrawUR(imageInfo);
35 void ImageUndoRedo::SetImage(VTKImageDataPointerType image) {
36 this->m_CurrentImage = image;
37 this->m_CurrentImage->Update();
38 this->UpdateUndoImage();
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,
47 this->m_ImagesDeque->AddImageToUndoContainer(imgResult,
49 this->UpdateUndoImage();
51 std::cerr << "INVALID REGION" << std::endl;
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,
66 std::cerr << "INVALID REGION" << std::endl;
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();
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();
89 void ImageUndoRedo::SetCurrentImage(VTKImageDataPointerType img) {
90 this->m_CurrentImage = img;
93 void ImageUndoRedo::DrawUR(ImageInfoUR* imageInfo) {
94 VTKImageDataPointerType img = imageInfo->GetImage();
95 RegionSType region = imageInfo->GetImageMManager()->GetModifiedRegion();
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,
106 this->m_CurrentImage->Modified();
108 this->m_ImagesDeque->ManageMemory();