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->DrawUR(imageInfo, true);
22 this->UpdateUndoImage();
26 void ImageUndoRedo::Redo() {
27 ImageInfoUR* imageInfo = this->m_ImagesDeque->Redo();
28 if (imageInfo != NULL) {
29 this->DrawUR(imageInfo, false);
30 this->UpdateUndoImage();
33 void ImageUndoRedo::SetImage(VTKImageDataPointerType image) {
34 this->m_CurrentImage = image;
35 this->m_CurrentImage->Update();
36 this->UpdateUndoImage();
39 void ImageUndoRedo::SetURImages(ImageMManagerType* imMManager) {
40 ImageMManagerType* newImageManager = new ImageMManagerType(imMManager);
41 if (newImageManager->ValidateRegion()) {
42 RegionSType region = newImageManager->GetModifiedRegion();
43 VTKImageDataPointerType imgUndo = this->GetImageRegion(region,
45 VTKImageDataPointerType imgRedo = this->GetImageRegion(region,
46 this->m_CurrentImage);
47 this->m_ImagesDeque->AddImagesToURContainer(imgUndo, imgRedo,
49 this->UpdateUndoImage();
51 std::cerr << "INVALID REGION" << std::endl;
55 void ImageUndoRedo::UpdateUndoImage() {
56 this->m_CurrentImage->Update();
57 this->m_UndoImage = VTKImageDataPointerType::New();
58 this->m_UndoImage->DeepCopy(m_CurrentImage);
59 this->m_UndoImage->Update();
62 ImageUndoRedo::VTKImageDataPointerType ImageUndoRedo::GetImageRegion(
63 const RegionSType& region, VTKImageDataPointerType img) {
64 VTKExtractVOIPointerType extract = VTKExtractVOIPointerType::New();
65 extract->SetVOI(region.minX, region.maxX, region.minY, region.maxY,
66 region.minZ, region.maxZ);
67 extract->SetSampleRate(1, 1, 1);
68 extract->SetInput(img);
69 VTKImageDataPointerType imgResult = extract->GetOutput();
74 void ImageUndoRedo::SetCurrentImage(VTKImageDataPointerType img) {
75 this->m_CurrentImage = img;
78 void ImageUndoRedo::DrawUR(ImageInfoUR* imageInfo, const bool& undo) {
79 VTKImageDataPointerType img;
81 img = imageInfo->GetUndoImage();
84 img = imageInfo->GetRedoImage();
86 RegionSType region = imageInfo->GetImageMManager()->GetModifiedRegion();
88 for (int i = region.minX, x = 0; i <= region.maxX; i++, x++) {
89 for (int j = region.minY, y = 0; j <= region.maxY; j++, y++) {
90 for (int k = region.minZ, z = 0; k <= region.maxZ; k++, z++) {
91 float value = img->GetScalarComponentAsFloat(x, y, z, 0);
92 this->m_CurrentImage->SetScalarComponentFromFloat(i, j, k,
97 this->m_CurrentImage->Modified();
99 this->m_ImagesDeque->ManageMemory();