]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageInfoUR.cxx
ca2f43544bb6ae10259b9e2c5b7b339feadd33c7
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / imageUndoRedo / imageInfoUR.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        imageInfoUR.cxx
28  * @brief       This file contains the implementation of the ImageInfoUR 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 "imageInfoUR.h"
35
36 // ----------------------------------------------------------------------------------
37 ImageInfoUR::ImageInfoUR() 
38 {
39         this->m_OnMemory        = false;
40         this->m_OnDisk          = false;
41 }
42
43 // ----------------------------------------------------------------------------------
44 ImageInfoUR::~ImageInfoUR() 
45 {
46 }
47
48 // ----------------------------------------------------------------------------------
49 void ImageInfoUR::SetImageName(const StringType &imgName) 
50 {
51         this->m_ImageName               = imgName;
52 }
53
54 // ----------------------------------------------------------------------------------
55 void ImageInfoUR::SetImageMManager(ImageMManagerType* imMManager) 
56 {
57         this->m_ImageMManager   = imMManager;
58 }
59
60 // ----------------------------------------------------------------------------------
61 void ImageInfoUR::SetStatus(const bool& onMemory) 
62 {
63         this->m_OnMemory                = onMemory;
64 }
65
66 // ----------------------------------------------------------------------------------
67 ImageInfoUR::StringType ImageInfoUR::GetImageName() 
68 {
69         return (this->m_ImageName);
70 }
71
72 // ----------------------------------------------------------------------------------
73 ImageInfoUR::VTKImageDataPointerType ImageInfoUR::GetUndoImage() 
74 {
75         return (this->m_UndoImage);
76 }
77
78 // ----------------------------------------------------------------------------------
79 ImageInfoUR::VTKImageDataPointerType ImageInfoUR::GetRedoImage() 
80 {
81         return (this->m_RedoImage);
82 }
83
84 // ----------------------------------------------------------------------------------
85 ImageInfoUR::ImageMManagerType* ImageInfoUR::GetImageMManager() 
86 {
87         return (this->m_ImageMManager);
88 }
89
90 // ----------------------------------------------------------------------------------
91 bool ImageInfoUR::GetStatus() 
92 {
93         return (this->m_OnMemory);
94 }
95
96 // ----------------------------------------------------------------------------------
97 void ImageInfoUR::SetImages(VTKImageDataPointerType imgUndo, VTKImageDataPointerType imgRedo) 
98 {
99         this->m_UndoImage = imgUndo;
100         this->m_RedoImage = imgRedo;
101         this->SetStatus(true);
102 }
103
104 // ----------------------------------------------------------------------------------
105 void ImageInfoUR::LoadImagesToMemory(const StringType& gPath) 
106 {
107 printf("EED ImageInfoUR::LoadImagesToMemory Start\n");
108         //setting paths
109         StringType filename = gPath + this->m_ImageName;
110         StringType undoImagePath = filename + "_Undo.mhd";
111         StringType redoImagePath = filename + "_Redo.mhd";
112         //Loading Undo Image
113         VTKMetaImageReaderPointerType readerUndo = VTKMetaImageReaderPointerType::New();
114         readerUndo->SetFileName(undoImagePath.c_str());
115 //EED 2017-01-01 Migration VTK7
116 #if VTK_MAJOR_VERSION <= 5
117         // ..
118 #else
119         readerUndo->Update();
120 #endif
121
122         this->m_UndoImage = readerUndo->GetOutput();
123 //EED 2017-01-01 Migration VTK7
124 #if VTK_MAJOR_VERSION <= 5
125         this->m_UndoImage->Update();
126 #else
127         this->m_UndoImage->Modified();
128 #endif
129         //Loading Redo Image
130         VTKMetaImageReaderPointerType readerRedo = VTKMetaImageReaderPointerType::New();
131         readerRedo->SetFileName(redoImagePath.c_str());
132 //EED 2017-01-01 Migration VTK7
133 #if VTK_MAJOR_VERSION <= 5
134         // ..
135 #else
136         readerRedo->Update();
137 #endif
138
139         this->m_RedoImage = readerRedo->GetOutput();
140 //EED 2017-01-01 Migration VTK7
141 #if VTK_MAJOR_VERSION <= 5
142         this->m_RedoImage->Update();
143 #else
144         this->m_RedoImage->Modified();
145 #endif
146         //Updating status
147         this->m_OnMemory = true;
148
149 printf("EED ImageInfoUR::LoadImagesToMemory End\n");
150
151 }
152
153 // ----------------------------------------------------------------------------------
154 void ImageInfoUR::RemoveImagesFromMemory(const StringType& gPath) 
155 {
156         if (!this->m_OnDisk) 
157         {
158                 this->SaveImagesOnDisk(gPath);
159         }
160         this->m_UndoImage = NULL;
161         this->m_RedoImage = NULL;
162         this->SetStatus(false);
163 }
164
165 // ----------------------------------------------------------------------------------
166 void ImageInfoUR::SaveImagesOnDisk(const StringType& gPath) 
167 {
168         printf("EED ImageInfoUR::SaveImagesOnDisk Start  \n");
169         this->m_OnDisk                          = true;
170         StringType filename             = gPath + this->m_ImageName;
171         StringType undoImagePath        = filename + "_Undo.mhd";
172         StringType redoImagePath        = filename + "_Redo.mhd";
173         this->SaveImageAsMHD(undoImagePath, this->m_UndoImage);
174         this->SaveImageAsMHD(redoImagePath, this->m_RedoImage);
175         printf("EED ImageInfoUR::SaveImagesOnDisk %s \n", undoImagePath.c_str() );
176 }
177
178 // ----------------------------------------------------------------------------------
179 void ImageInfoUR::RemoveImagesFromDisk(const StringType& gPath) 
180 {
181         StringType filename             = gPath + this->m_ImageName;
182         StringType undoImagePathMHD = filename + "_Undo.mhd";
183         StringType redoImagePathMHD = filename + "_Redo.mhd";
184         StringType undoImagePathRAW = filename + "_Undo.raw";
185         StringType redoImagePathRAW = filename + "_Redo.raw";
186         remove(undoImagePathMHD.c_str());
187         remove(redoImagePathMHD.c_str());
188         remove(undoImagePathRAW.c_str());
189         remove(redoImagePathRAW.c_str());
190 }
191
192 // ----------------------------------------------------------------------------------
193 void ImageInfoUR::SaveImageAsMHD(const StringType& filename, VTKImageDataPointerType image) 
194 {
195         VTKMetaImageWriterPointerType w = VTKMetaImageWriterPointerType::New();
196 //EED 2017-01-01 Migration VTK7
197 #if VTK_MAJOR_VERSION <= 5
198         w->SetInput(image);
199 #else
200         w->SetInputData(image);
201 #endif
202         w->SetCompression(false);
203         w->SetFileDimensionality(image->GetDataDimension());
204         w->SetFileName(filename.c_str());
205         w->Write();
206 }
207 // ----------------------------------------------------------------------------------