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 image3DDequeUR.cxx
28 * @brief This file contains the implementation of the Image3DDequeUR class.
30 * @author Diego CACERES (diego.caceres[AT]creatis.insa-lyon.fr)
34 #include "image3DDequeUR.h"
39 // ----------------------------------------------------------------------------------
40 Image3DDequeUR::Image3DDequeUR( )
43 this->m_GlobalPath = std::getenv("TEMP");
46 this->m_GlobalPath = std::getenv("TEMP");
49 this->m_GlobalPath = "/tmp/";
51 this->m_CurrentURPos = -1;
54 // ----------------------------------------------------------------------------------
56 Image3DDequeUR::~Image3DDequeUR( )
58 this->CleanHardDisk( );
61 // ----------------------------------------------------------------------------------
63 void Image3DDequeUR::AddImagesToURContainer( VTKImageDataPointerType imgUndo,
64 VTKImageDataPointerType imgRedo, ImageMManager* imMManager )
66 this->CleanURContainerFromIndex( this->m_CurrentURPos + 1 );
68 ImageInfoUR* imageInfo = new ImageInfoUR( );
69 imageInfo->SetImageName( this->GetImageName( this->m_ImgURDeque.size( ) ) );
70 imageInfo->SetImages( imgUndo, imgRedo );
71 imageInfo->SetImageMManager( imMManager );
73 this->m_ImgURDeque.push_back( imageInfo );
74 this->m_CurrentURPos = this->m_ImgURDeque.size( ) - 1;
76 this->ManageMemory( );
79 // ----------------------------------------------------------------------------------
81 ImageInfoUR* Image3DDequeUR::Undo( )
83 ImageInfoUR* imgRet = NULL;
84 int imgURDequeSize = this->m_ImgURDeque.size( );
85 if( ( this->m_ImgURDeque.size( ) > 0 ) && ( this->m_CurrentURPos != -1 )
86 && ( this->m_CurrentURPos < imgURDequeSize ) )
88 imgRet = this->m_ImgURDeque[ m_CurrentURPos ];
89 this->m_CurrentURPos--;
94 // ----------------------------------------------------------------------------------
96 ImageInfoUR* Image3DDequeUR::Redo( )
98 ImageInfoUR* imgRet = NULL;
99 this->m_CurrentURPos++;
100 int imgURDequeSize = this->m_ImgURDeque.size( );
101 if( ( this->m_ImgURDeque.size( ) > 0 ) && ( this->m_CurrentURPos != -1 )
102 && ( this->m_CurrentURPos < imgURDequeSize ) )
104 imgRet = this->m_ImgURDeque[ m_CurrentURPos ];
106 this->m_CurrentURPos--;
111 // ----------------------------------------------------------------------------------
113 void Image3DDequeUR::CleanURContainerFromIndex( const int& index )
116 for( unsigned int i = index; i < this->m_ImgURDeque.size( ); i++ )
118 this->m_ImgURDeque[ i ]->RemoveImagesFromMemory( this->m_GlobalPath );
119 this->m_ImgURDeque[ i ]->RemoveImagesFromDisk( this->m_GlobalPath );
122 for( int i = 0; i < count; i++ )
124 this->m_ImgURDeque.pop_back( );
128 // ----------------------------------------------------------------------------------
130 void Image3DDequeUR::ManageMemory( )
132 int imgURDequeSize = this->m_ImgURDeque.size( );
134 for( i = 0; i < imgURDequeSize; i++ )
136 if( this->m_ImgURDeque[ i ]->GetStatus( ) )
138 this->m_ImgURDeque[ i ]->RemoveImagesFromMemory( this->m_GlobalPath );
141 //Adding CurrentUndoPos to memory
142 if( ( this->m_CurrentURPos != -1 ) && !( this->m_ImgURDeque[ this->m_CurrentURPos ]->GetStatus( ) ) )
144 this->m_ImgURDeque[ this->m_CurrentURPos ]->LoadImagesToMemory( this->m_GlobalPath );
146 int currentRedoPos = this->m_CurrentURPos + 1;
147 if( ( currentRedoPos < imgURDequeSize ) && !( this->m_ImgURDeque[ currentRedoPos ]->GetStatus( ) ) )
149 this->m_ImgURDeque[ currentRedoPos ]->LoadImagesToMemory( this->m_GlobalPath );
153 // ----------------------------------------------------------------------------------
154 void Image3DDequeUR::SetGlobalPath( const StringType& globalPath )
156 this->m_GlobalPath = globalPath;
159 // ----------------------------------------------------------------------------------
160 void Image3DDequeUR::CleanHardDisk( )
162 for( unsigned int i = 0; i < this->m_ImgURDeque.size( ); i++ )
164 this->m_ImgURDeque[ i ]->RemoveImagesFromDisk( this->m_GlobalPath );
168 // ----------------------------------------------------------------------------------
169 Image3DDequeUR::StringType Image3DDequeUR::GetGlobalPath( )
171 return ( this->m_GlobalPath );
174 // ----------------------------------------------------------------------------------
175 Image3DDequeUR::StringType Image3DDequeUR::GetImageName( const int & pos )
177 //Giving a name to an image using the date and time
178 if( this->m_IDImages.empty( ) )
181 struct tm * timeinfo;
184 timeinfo = localtime( &rawtime );
185 strftime( buffer, 80, "%H%M%S_%a_%d_%b_%y_", timeinfo );
186 StringType date( buffer );
187 StringType aux( buffer );
188 this->m_IDImages = "img_" + aux;
190 std::stringstream ss; //create a stringstream
191 ss << pos; //add number to the stream
192 StringType imageName = this->m_IDImages + ss.str( );
193 return ( imageName );
196 // ----------------------------------------------------------------------------------