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) {
21 //this->SetRedoImage(imageInfo->GetImageMManager());
22 this->DrawUR(imageInfo, true);
23 this->UpdateUndoImage();
27 void ImageUndoRedo::Redo() {
28 /*ImageInfoUR* imageInfo = this->m_ImagesDeque->Redo();
29 if (imageInfo != NULL)
31 this->DrawUR(imageInfo);
34 void ImageUndoRedo::SetImage(VTKImageDataPointerType image) {
35 this->m_CurrentImage = image;
36 this->m_CurrentImage->Update();
37 this->UpdateUndoImage();
40 void ImageUndoRedo::SetURImages(ImageMManagerType* imMManager) {
41 ImageMManagerType* newImageManager = new ImageMManagerType(imMManager);
42 if (newImageManager->ValidateRegion()) {
43 RegionSType region = newImageManager->GetModifiedRegion();
44 VTKImageDataPointerType imgUndo = this->GetImageRegion(region,
46 VTKImageDataPointerType imgRedo = this->GetImageRegion(region,
47 this->m_CurrentImage);
48 this->m_ImagesDeque->AddImagesToURContainer(imgUndo, imgRedo,
50 this->UpdateUndoImage();
52 std::cerr << "INVALID REGION" << std::endl;
56 void ImageUndoRedo::UpdateUndoImage() {
57 this->m_CurrentImage->Update();
58 this->m_UndoImage = VTKImageDataPointerType::New();
59 this->m_UndoImage->DeepCopy(m_CurrentImage);
60 this->m_UndoImage->Update();
63 ImageUndoRedo::VTKImageDataPointerType ImageUndoRedo::GetImageRegion(
64 const RegionSType& region, VTKImageDataPointerType img) {
65 VTKExtractVOIPointerType extract = VTKExtractVOIPointerType::New();
66 extract->SetVOI(region.minX, region.maxX, region.minY, region.maxY,
67 region.minZ, region.maxZ);
68 extract->SetSampleRate(1, 1, 1);
69 extract->SetInput(this->m_UndoImage);
70 VTKImageDataPointerType imgResult = extract->GetOutput();
75 void ImageUndoRedo::SetCurrentImage(VTKImageDataPointerType img) {
76 this->m_CurrentImage = img;
79 void ImageUndoRedo::DrawUR(ImageInfoUR* imageInfo, const bool& undo) {
80 VTKImageDataPointerType img;
82 img = imageInfo->GetUndoImage();
85 img = imageInfo->GetRedoImage();
87 RegionSType region = imageInfo->GetImageMManager()->GetModifiedRegion();
89 for (int i = region.minX, x = 0; i <= region.maxX; i++, x++) {
90 for (int j = region.minY, y = 0; j <= region.maxY; j++, y++) {
91 for (int k = region.minZ, z = 0; k <= region.maxZ; k++, z++) {
92 float value = img->GetScalarComponentAsFloat(x, y, z, 0);
93 this->m_CurrentImage->SetScalarComponentFromFloat(i, j, k,
98 this->m_CurrentImage->Modified();
100 this->m_ImagesDeque->ManageMemory();