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->GetRegion());
23 this->DrawUR(imageInfo);
27 void ImageUndoRedo::Redo() {
28 ImageInfoUR* imageInfo = this->m_ImagesDeque->Redo();
29 this->DrawUR(imageInfo);
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);
38 void ImageUndoRedo::SetUndoImage(const RegionSType& region) {
39 VTKImageDataPointerType imgResult = this->GetImageRegion(region,
40 this->m_OriginalImage);
41 this->m_ImagesDeque->AddImageToUndoContainer(imgResult, region);
44 void ImageUndoRedo::SetRedoImage(const RegionSType& region) {
45 VTKImageDataPointerType imgResult = this->GetImageRegion(region,
46 this->m_CurrentImage);
47 this->m_ImagesDeque->AddImageToRedoContainer(imgResult, region);
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();
62 void ImageUndoRedo::SetOriginalImage(VTKImageDataPointerType img) {
63 this->m_OriginalImage = img;
65 void ImageUndoRedo::SetCurrentImage(VTKImageDataPointerType img) {
66 this->m_CurrentImage = img;
69 void ImageUndoRedo::DrawUR(ImageInfoUR* imageInfo) {
70 VTKImageDataPointerType img = imageInfo->GetImage();
73 for (int i = imageInfo->GetRegion().minX, x = 0;
74 i <= imageInfo->GetRegion().maxX; i++, x++) {
75 for (int j = imageInfo->GetRegion().minY, y = 0;
76 j <= imageInfo->GetRegion().maxY; j++, y++) {
77 for (int k = imageInfo->GetRegion().minZ, z = 0;
78 k <= imageInfo->GetRegion().maxZ; k++, z++) {
79 float value = img->GetScalarComponentAsFloat(i, j, k, 0);
80 this->m_CurrentImage->SetScalarComponentFromFloat(i, j, k, 0,
85 this->m_CurrentImage->Modified();