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( )
42 const void * address = static_cast<const void*>(this);
45 m_PrivateID = ss.str();
48 this->m_GlobalPath = std::getenv("TEMP");
51 this->m_GlobalPath = std::getenv("TEMP");
54 this->m_GlobalPath = "/tmp/";
56 this->m_CurrentURPos = -1;
59 // ----------------------------------------------------------------------------------
61 Image3DDequeUR::~Image3DDequeUR( )
63 this->CleanHardDisk( );
66 // ----------------------------------------------------------------------------------
68 void Image3DDequeUR::AddImagesToURContainer( VTKImageDataPointerType imgUndo,
69 VTKImageDataPointerType imgRedo, ImageMManager* imMManager )
71 this->CleanURContainerFromIndex( this->m_CurrentURPos + 1 );
73 ImageInfoUR* imageInfo = new ImageInfoUR( );
74 imageInfo->SetImageName( this->GetImageName( this->m_ImgURDeque.size( ) ) );
75 imageInfo->SetImages( imgUndo, imgRedo );
76 imageInfo->SetImageMManager( imMManager );
79 this->m_ImgURDeque.push_back( imageInfo );
80 this->m_CurrentURPos = this->m_ImgURDeque.size( ) - 1;
82 this->ManageMemory( );
85 // ----------------------------------------------------------------------------------
87 ImageInfoUR* Image3DDequeUR::Undo( )
89 ImageInfoUR* imgRet = NULL;
90 int imgURDequeSize = this->m_ImgURDeque.size( );
91 if( ( this->m_ImgURDeque.size( ) > 0 ) && ( this->m_CurrentURPos != -1 )
92 && ( this->m_CurrentURPos < imgURDequeSize ) )
94 imgRet = this->m_ImgURDeque[ m_CurrentURPos ];
95 this->m_CurrentURPos--;
100 // ----------------------------------------------------------------------------------
102 ImageInfoUR* Image3DDequeUR::Redo( )
104 ImageInfoUR* imgRet = NULL;
105 this->m_CurrentURPos++;
106 int imgURDequeSize = this->m_ImgURDeque.size( );
107 if( ( this->m_ImgURDeque.size( ) > 0 ) && ( this->m_CurrentURPos != -1 )
108 && ( this->m_CurrentURPos < imgURDequeSize ) )
110 imgRet = this->m_ImgURDeque[ m_CurrentURPos ];
112 this->m_CurrentURPos--;
117 // ----------------------------------------------------------------------------------
119 void Image3DDequeUR::CleanURContainerFromIndex( const int& index )
122 for( unsigned int i = index; i < this->m_ImgURDeque.size( ); i++ )
124 this->m_ImgURDeque[ i ]->RemoveImagesFromMemory( this->m_GlobalPath );
125 this->m_ImgURDeque[ i ]->RemoveImagesFromDisk( this->m_GlobalPath );
128 for( int i = 0; i < count; i++ )
130 this->m_ImgURDeque.pop_back( );
134 // ----------------------------------------------------------------------------------
136 void Image3DDequeUR::ManageMemory( )
138 int imgURDequeSize = this->m_ImgURDeque.size( );
140 for( i = 0; i < imgURDequeSize; i++ )
142 if( this->m_ImgURDeque[ i ]->GetStatus( ) )
144 this->m_ImgURDeque[ i ]->RemoveImagesFromMemory( this->m_GlobalPath );
147 //Adding CurrentUndoPos to memory
148 if( ( this->m_CurrentURPos != -1 ) && !( this->m_ImgURDeque[ this->m_CurrentURPos ]->GetStatus( ) ) )
150 this->m_ImgURDeque[ this->m_CurrentURPos ]->LoadImagesToMemory( this->m_GlobalPath );
152 int currentRedoPos = this->m_CurrentURPos + 1;
153 if( ( currentRedoPos < imgURDequeSize ) && !( this->m_ImgURDeque[ currentRedoPos ]->GetStatus( ) ) )
155 this->m_ImgURDeque[ currentRedoPos ]->LoadImagesToMemory( this->m_GlobalPath );
159 // ----------------------------------------------------------------------------------
160 void Image3DDequeUR::SetGlobalPath( const StringType& globalPath )
162 this->m_GlobalPath = globalPath;
165 // ----------------------------------------------------------------------------------
166 void Image3DDequeUR::CleanHardDisk( )
168 for( unsigned int i = 0; i < this->m_ImgURDeque.size( ); i++ )
170 this->m_ImgURDeque[ i ]->RemoveImagesFromDisk( this->m_GlobalPath );
174 // ----------------------------------------------------------------------------------
175 Image3DDequeUR::StringType Image3DDequeUR::GetGlobalPath( )
177 return ( this->m_GlobalPath );
180 // ----------------------------------------------------------------------------------
181 Image3DDequeUR::StringType Image3DDequeUR::GetImageName( const int & pos )
183 //Giving a name to an image using the date and time
184 if( this->m_IDImages.empty( ) )
190 timeinfo = localtime( &rawtime );
191 strftime( buffer, 80, "%H%M%S_%a_%d_%b_%y_", timeinfo );
192 StringType date( buffer );
193 StringType aux( buffer );
194 this->m_IDImages = "img_" + aux;
196 std::stringstream ss; //create a stringstream
197 ss << pos; //add number to the stream
198 StringType imageName = this->m_IDImages + ss.str( )+ "_"+m_PrivateID;
199 return ( imageName );
202 // ----------------------------------------------------------------------------------