]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/image3DDequeUR.cxx
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / imageUndoRedo / image3DDequeUR.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
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
8 #
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.
15 #
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
20 #  liability.
21 #
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 # ------------------------------------------------------------------------ */
25
26 /*!
27  * @file        image3DDequeUR.cxx
28  * @brief       This file contains the implementation of the Image3DDequeUR class.
29  * @author      Info-Dev
30  * @author      Diego CACERES (diego.caceres[AT]creatis.insa-lyon.fr)
31  * @date        2011-11-15
32  */
33
34 #include "image3DDequeUR.h"
35 #include <iostream>
36 #include <sstream>
37
38 // ----------------------------------------------------------------------------------
39 Image3DDequeUR::Image3DDequeUR( )
40 {
41
42
43 #ifdef _WIN32
44         this->m_GlobalPath = std::getenv("TEMP");
45 #endif
46 #ifdef _WIN64
47         this->m_GlobalPath = std::getenv("TEMP");
48 #endif
49 #ifdef LINUX
50         this->m_GlobalPath = "/tmp/";
51 #endif // MACOSX
52         this->m_CurrentURPos = -1;
53 }
54 // ----------------------------------------------------------------------------------
55 //virtual
56 Image3DDequeUR::~Image3DDequeUR( )
57 {
58         this->CleanHardDisk( );
59 }
60 // ----------------------------------------------------------------------------------
61 //virtual
62 void Image3DDequeUR::AddImagesToURContainer( VTKImageDataPointerType imgUndo,
63         VTKImageDataPointerType imgRedo, ImageMManager* imMManager )
64 {
65         this->CleanURContainerFromIndex( this->m_CurrentURPos + 1 );
66         //Adding image
67         ImageInfoUR* imageInfo = new ImageInfoUR( );
68         imageInfo->SetImageName( this->GetImageName( this->m_ImgURDeque.size( ) ) );
69         imageInfo->SetImages( imgUndo, imgRedo );
70         imageInfo->SetImageMManager( imMManager );
71         //Adding to deque
72         this->m_ImgURDeque.push_back( imageInfo );
73         this->m_CurrentURPos = this->m_ImgURDeque.size( ) - 1;
74         //Managing memory
75         this->ManageMemory( );
76 }
77 // ----------------------------------------------------------------------------------
78 //virtual
79 ImageInfoUR* Image3DDequeUR::Undo( )
80 {
81         ImageInfoUR* imgRet = NULL;
82         int imgURDequeSize = this->m_ImgURDeque.size( );
83         if( ( this->m_ImgURDeque.size( ) > 0 ) && ( this->m_CurrentURPos != -1 )
84                 && ( this->m_CurrentURPos < imgURDequeSize ) )
85         {
86                 imgRet = this->m_ImgURDeque[ m_CurrentURPos ];
87                 this->m_CurrentURPos--;
88         } //fi
89         return ( imgRet );
90 }
91 // ----------------------------------------------------------------------------------
92 //virtual
93 ImageInfoUR* Image3DDequeUR::Redo( )
94 {
95         ImageInfoUR* imgRet = NULL;
96         this->m_CurrentURPos++;
97         int imgURDequeSize = this->m_ImgURDeque.size( );
98         if( ( this->m_ImgURDeque.size( ) > 0 ) && ( this->m_CurrentURPos != -1 )
99                 && ( this->m_CurrentURPos < imgURDequeSize ) )
100         {
101                 imgRet = this->m_ImgURDeque[ m_CurrentURPos ];
102         } //fi
103         else
104         {
105                 this->m_CurrentURPos--;
106         }
107         return ( imgRet );
108 }
109 // ----------------------------------------------------------------------------------
110 //virtual
111 void Image3DDequeUR::CleanURContainerFromIndex( const int& index )
112 {
113         int count = 0;
114         for( unsigned int i = index; i < this->m_ImgURDeque.size( ); i++ )
115         {
116                 this->m_ImgURDeque[ i ]->RemoveImagesFromMemory( this->m_GlobalPath );
117                 this->m_ImgURDeque[ i ]->RemoveImagesFromDisk( this->m_GlobalPath );
118                 count++;
119         }
120         for( int i = 0; i < count; i++ )
121         {
122                 this->m_ImgURDeque.pop_back( );
123         } //rof
124 }
125 // ----------------------------------------------------------------------------------
126 //virtual
127 void Image3DDequeUR::ManageMemory( )
128 {
129         int imgURDequeSize = this->m_ImgURDeque.size( );
130         for( int i = 0; i < imgURDequeSize; i++ )
131         {
132                 if( this->m_ImgURDeque[ i ]->GetStatus( ) )
133                 {
134                         this->m_ImgURDeque[ i ]->RemoveImagesFromMemory(
135                                 this->m_GlobalPath );
136                 } //fi
137         } //rof
138           //Adding CurrentUndoPos to memory
139         if( ( this->m_CurrentURPos != -1 )
140                 && !( this->m_ImgURDeque[ this->m_CurrentURPos ]->GetStatus( ) ) )
141         {
142                 this->m_ImgURDeque[ this->m_CurrentURPos ]->LoadImagesToMemory(
143                         this->m_GlobalPath );
144         }
145         int currentRedoPos = this->m_CurrentURPos + 1;
146         if( ( currentRedoPos < imgURDequeSize )
147                 && !( this->m_ImgURDeque[ currentRedoPos ]->GetStatus( ) ) )
148         {
149                 this->m_ImgURDeque[ currentRedoPos ]->LoadImagesToMemory(
150                         this->m_GlobalPath );
151         }
152 }
153 // ----------------------------------------------------------------------------------
154 void Image3DDequeUR::SetGlobalPath( const StringType& globalPath )
155 {
156         this->m_GlobalPath = globalPath;
157 }
158 // ----------------------------------------------------------------------------------
159 void Image3DDequeUR::CleanHardDisk( )
160 {
161         for( unsigned int i = 0; i < this->m_ImgURDeque.size( ); i++ )
162         {
163                 this->m_ImgURDeque[ i ]->RemoveImagesFromDisk( this->m_GlobalPath );
164         }
165 }
166 // ----------------------------------------------------------------------------------
167 Image3DDequeUR::StringType Image3DDequeUR::GetGlobalPath( )
168 {
169         return ( this->m_GlobalPath );
170 }
171 // ----------------------------------------------------------------------------------
172 Image3DDequeUR::StringType Image3DDequeUR::GetImageName( const int & pos )
173 {
174 //Giving a name to an image using the date and time
175         if( this->m_IDImages.empty( ) )
176         {
177                 time_t rawtime;
178                 struct tm * timeinfo;
179                 char buffer[ 80 ];
180                 time( &rawtime );
181                 timeinfo = localtime( &rawtime );
182                 strftime( buffer, 80, "%H%M%S_%a_%d_%b_%y_", timeinfo );
183                 StringType date( buffer );
184                 StringType aux( buffer );
185                 this->m_IDImages = "img_" + aux;
186         }
187         std::stringstream ss; //create a stringstream
188         ss << pos; //add number to the stream
189         StringType imageName = this->m_IDImages + ss.str( );
190         return ( imageName );
191 }
192 // ----------------------------------------------------------------------------------