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