1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
27 * @file imageUndoRedo.cxx
28 * @brief This file contains the implementation of the ImageUndoRedo class.
30 * @author Diego CACERES (diego.caceres[AT]creatis.insa-lyon.fr)
34 #include "imageUndoRedo.h"
36 // ----------------------------------------------------------------------------------
37 ImageUndoRedo::ImageUndoRedo( )
39 this->m_ImagesDeque = new IDequeType( );
41 // ----------------------------------------------------------------------------------
43 ImageUndoRedo::~ImageUndoRedo( )
47 // ----------------------------------------------------------------------------------
49 void ImageUndoRedo::Undo( )
51 ImageInfoUR* imageInfo = this->m_ImagesDeque->Undo( );
52 if( imageInfo != NULL)
54 this->DrawUR( imageInfo, true );
55 this->UpdateUndoImage( );
58 // ----------------------------------------------------------------------------------
60 void ImageUndoRedo::Redo( )
62 ImageInfoUR* imageInfo = this->m_ImagesDeque->Redo( );
63 if( imageInfo != NULL)
65 this->DrawUR( imageInfo, false );
66 this->UpdateUndoImage( );
69 // ----------------------------------------------------------------------------------
70 void ImageUndoRedo::SetImage( VTKImageDataPointerType image )
72 this->m_CurrentImage = image;
74 //EED 2017-01-01 Migration VTK7
75 #if VTK_MAJOR_VERSION <= 5
76 this->m_CurrentImage->Update( );
81 this->UpdateUndoImage( );
83 // ----------------------------------------------------------------------------------
85 void ImageUndoRedo::SetURImages( ImageMManagerType* imMManager )
87 ImageMManagerType* newImageManager = new ImageMManagerType( imMManager );
88 if( newImageManager->ValidateRegion( ) )
90 RegionSType region = newImageManager->GetModifiedRegion( );
91 VTKImageDataPointerType imgUndo = this->GetImageRegion( region,
93 VTKImageDataPointerType imgRedo = this->GetImageRegion( region,
94 this->m_CurrentImage );
95 this->m_ImagesDeque->AddImagesToURContainer( imgUndo, imgRedo,
97 this->UpdateUndoImage( );
101 std::cerr << "INVALID REGION" << std::endl;
104 // ----------------------------------------------------------------------------------
105 void ImageUndoRedo::UpdateUndoImage( )
107 //EED 2017-01-01 Migration VTK7
108 #if VTK_MAJOR_VERSION <= 5
109 this->m_CurrentImage->Update( );
113 this->m_UndoImage = VTKImageDataPointerType::New( );
114 this->m_UndoImage->DeepCopy( m_CurrentImage );
115 //EED 2017-01-01 Migration VTK7
116 #if VTK_MAJOR_VERSION <= 5
117 this->m_UndoImage->Update( );
122 // ----------------------------------------------------------------------------------
123 ImageUndoRedo::VTKImageDataPointerType ImageUndoRedo::GetImageRegion(
124 const RegionSType& region, VTKImageDataPointerType img )
126 VTKExtractVOIPointerType extract = VTKExtractVOIPointerType::New( );
127 extract->SetVOI( region.minX, region.maxX, region.minY, region.maxY,
128 region.minZ, region.maxZ );
129 extract->SetSampleRate( 1, 1, 1 );
130 //EED 2017-01-01 Migration VTK7
131 #if VTK_MAJOR_VERSION <= 5
132 extract->SetInput( img );
134 extract->SetInputData( img );
136 VTKImageDataPointerType imgResult = extract->GetOutput( );
138 //EED 2017-01-01 Migration VTK7
139 #if VTK_MAJOR_VERSION <= 5
140 imgResult->Update( );
145 return ( imgResult );
147 // ----------------------------------------------------------------------------------
148 void ImageUndoRedo::SetCurrentImage( VTKImageDataPointerType img )
150 this->m_CurrentImage = img;
152 // ----------------------------------------------------------------------------------
154 void ImageUndoRedo::DrawUR( ImageInfoUR* imageInfo, const bool& undo )
156 VTKImageDataPointerType img;
159 img = imageInfo->GetUndoImage( );
163 img = imageInfo->GetRedoImage( );
165 RegionSType region = imageInfo->GetImageMManager( )->GetModifiedRegion( );
168 int *dim = img->GetDimensions( );
169 int sizeXImageIn = dim[ 0 ];
170 size_t linesize = sizeXImageIn * sizeof(unsigned short);
171 for( int j = region.minY, y = 0; j <= region.maxY; j++, y++ )
173 for( int k = region.minZ, z = 0; k <= region.maxZ; k++, z++ )
175 void* ptrsrc = img->GetScalarPointer( 0, y, z );
176 void* ptrdest = this->m_CurrentImage->GetScalarPointer(
178 memcpy( ptrdest, ptrsrc, linesize );
181 this->m_CurrentImage->Modified( );
183 this->m_ImagesDeque->ManageMemory( );
185 // ----------------------------------------------------------------------------------