-/*
- * imageUndoRedo.cxx
- *
- * Created on: Sep 26, 2011
- * Author: caceres
+/*# ---------------------------------------------------------------------
+#
+# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
+# pour la Sant�)
+# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
+# Previous Authors : Laurent Guigues, Jean-Pierre Roux
+# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
+#
+# This software is governed by the CeCILL-B license under French law and
+# abiding by the rules of distribution of free software. You can use,
+# modify and/ or redistribute the software under the terms of the CeCILL-B
+# license as circulated by CEA, CNRS and INRIA at the following URL
+# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+# or in the file LICENSE.txt.
+#
+# As a counterpart to the access to the source code and rights to copy,
+# modify and redistribute granted by the license, users are provided only
+# with a limited warranty and the software's author, the holder of the
+# economic rights, and the successive licensors have only limited
+# liability.
+#
+# The fact that you are presently reading this means that you have had
+# knowledge of the CeCILL-B license and that you accept its terms.
+# ------------------------------------------------------------------------ */
+
+/*!
+ * @file imageUndoRedo.cxx
+ * @brief This file contains the implementation of the ImageUndoRedo class.
+ * @author Info-Dev
+ * @author Diego CACERES (diego.caceres[AT]creatis.insa-lyon.fr)
+ * @date 2011-11-15
*/
#include "imageUndoRedo.h"
-ImageUndoRedo::ImageUndoRedo() {
- this->m_ImagesDeque = new IDequeType();
+// ----------------------------------------------------------------------------------
+ImageUndoRedo::ImageUndoRedo( )
+{
+ this->m_ImagesDeque = new IDequeType( );
}
+// ----------------------------------------------------------------------------------
//virtual
-ImageUndoRedo::~ImageUndoRedo() {
+ImageUndoRedo::~ImageUndoRedo( )
+{
}
+// ----------------------------------------------------------------------------------
//virtual
-void ImageUndoRedo::Undo() {
- ImageInfoUR* imageInfo = this->m_ImagesDeque->Undo();
- this->SetRedoImage(imageInfo->GetRegion());
- std::cout<<"undooooooooooooooooooooooooooo"<<std::endl;
- this->DrawUR(imageInfo);
+void ImageUndoRedo::Undo( )
+{
+ ImageInfoUR* imageInfo = this->m_ImagesDeque->Undo( );
+ if( imageInfo != NULL)
+ {
+ this->DrawUR( imageInfo, true );
+ this->UpdateUndoImage( );
+ }
}
+// ----------------------------------------------------------------------------------
//virtual
-void ImageUndoRedo::Redo() {
- ImageInfoUR* imageInfo = this->m_ImagesDeque->Redo();
- this->DrawUR(imageInfo);
+void ImageUndoRedo::Redo( )
+{
+ ImageInfoUR* imageInfo = this->m_ImagesDeque->Redo( );
+ if( imageInfo != NULL)
+ {
+ this->DrawUR( imageInfo, false );
+ this->UpdateUndoImage( );
+ }
}
-void ImageUndoRedo::SetImage(vtkImageData *image) {
+// ----------------------------------------------------------------------------------
+void ImageUndoRedo::SetImage( VTKImageDataPointerType image )
+{
this->m_CurrentImage = image;
- this->m_CurrentImage->Update();
- this->m_OriginalImage = ImageType::New();
- this->m_OriginalImage->DeepCopy(m_CurrentImage);
+ this->m_CurrentImage->Update( );
+ this->UpdateUndoImage( );
}
+// ----------------------------------------------------------------------------------
//virtual
-void ImageUndoRedo::SetUndoImage(const RegionSType& region) {
- vtkSmartPointer<vtkExtractVOI> extract =
- vtkSmartPointer<vtkExtractVOI>::New();
- extract->SetVOI(region.minX, region.maxX, region.minY, region.maxY,
- region.minZ, region.maxZ);
- extract->SetSampleRate(1, 1, 1);
- extract->SetInput(this->m_OriginalImage);
- vtkImageData* imgResult = extract->GetOutput();
- this->m_ImagesDeque->AddImageToUndoContainer(imgResult, region);
+void ImageUndoRedo::SetURImages( ImageMManagerType* imMManager )
+{
+ ImageMManagerType* newImageManager = new ImageMManagerType( imMManager );
+ if( newImageManager->ValidateRegion( ) )
+ {
+ RegionSType region = newImageManager->GetModifiedRegion( );
+ VTKImageDataPointerType imgUndo = this->GetImageRegion( region,
+ this->m_UndoImage );
+ VTKImageDataPointerType imgRedo = this->GetImageRegion( region,
+ this->m_CurrentImage );
+ this->m_ImagesDeque->AddImagesToURContainer( imgUndo, imgRedo,
+ newImageManager );
+ this->UpdateUndoImage( );
+ }
+ else
+ {
+ std::cerr << "INVALID REGION" << std::endl;
+ }
}
-//virtual
-void ImageUndoRedo::SetRedoImage(const RegionSType& region) {
- vtkSmartPointer<vtkExtractVOI> extract =
- vtkSmartPointer<vtkExtractVOI>::New();
- extract->SetVOI(region.minX, region.maxX, region.minY, region.maxY,
- region.minZ, region.maxZ);
- extract->SetSampleRate(1, 1, 1);
- extract->SetInput(this->m_CurrentImage);
- vtkImageData* imgResult = extract->GetOutput();
- this->m_ImagesDeque->AddImageToRedoContainer(imgResult, region);
+// ----------------------------------------------------------------------------------
+void ImageUndoRedo::UpdateUndoImage( )
+{
+ this->m_CurrentImage->Update( );
+ this->m_UndoImage = VTKImageDataPointerType::New( );
+ this->m_UndoImage->DeepCopy( m_CurrentImage );
+ this->m_UndoImage->Update( );
}
-void ImageUndoRedo::SetOriginalImage(ImageType* img) {
- this->m_OriginalImage = img;
+// ----------------------------------------------------------------------------------
+ImageUndoRedo::VTKImageDataPointerType ImageUndoRedo::GetImageRegion(
+ const RegionSType& region, VTKImageDataPointerType img )
+{
+ VTKExtractVOIPointerType extract = VTKExtractVOIPointerType::New( );
+ extract->SetVOI( region.minX, region.maxX, region.minY, region.maxY,
+ region.minZ, region.maxZ );
+ extract->SetSampleRate( 1, 1, 1 );
+ extract->SetInput( img );
+ VTKImageDataPointerType imgResult = extract->GetOutput( );
+ imgResult->Update( );
+ return ( imgResult );
}
-void ImageUndoRedo::SetCurrentImage(ImageType* img) {
+// ----------------------------------------------------------------------------------
+void ImageUndoRedo::SetCurrentImage( VTKImageDataPointerType img )
+{
this->m_CurrentImage = img;
}
+// ----------------------------------------------------------------------------------
//virtual
-void ImageUndoRedo::DrawUR(ImageInfoUR* imageInfo) {
-
+void ImageUndoRedo::DrawUR( ImageInfoUR* imageInfo, const bool& undo )
+{
+ VTKImageDataPointerType img;
+ if( undo )
+ {
+ img = imageInfo->GetUndoImage( );
+ } //fi
+ else
+ {
+ img = imageInfo->GetRedoImage( );
+ } //else
+ RegionSType region = imageInfo->GetImageMManager( )->GetModifiedRegion( );
+ if( img != NULL)
+ {
+ int *dim = img->GetDimensions( );
+ int sizeXImageIn = dim[ 0 ];
+ size_t linesize = sizeXImageIn * sizeof(unsigned short);
+ for( int j = region.minY, y = 0; j <= region.maxY; j++, y++ )
+ {
+ for( int k = region.minZ, z = 0; k <= region.maxZ; k++, z++ )
+ {
+ void* ptrsrc = img->GetScalarPointer( 0, y, z );
+ void* ptrdest = this->m_CurrentImage->GetScalarPointer(
+ region.minX, j, k );
+ memcpy( ptrdest, ptrsrc, linesize );
+ }
+ }
+ this->m_CurrentImage->Modified( );
+ }
+ this->m_ImagesDeque->ManageMemory( );
}
-
+// ----------------------------------------------------------------------------------