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 imageInfoUR.cxx
28 * @brief This file contains the implementation of the ImageInfoUR class.
30 * @author Diego CACERES (diego.caceres[AT]creatis.insa-lyon.fr)
34 #include "imageInfoUR.h"
36 // ----------------------------------------------------------------------------------
37 ImageInfoUR::ImageInfoUR()
39 this->m_OnMemory = false;
40 this->m_OnDisk = false;
43 // ----------------------------------------------------------------------------------
44 ImageInfoUR::~ImageInfoUR()
48 // ----------------------------------------------------------------------------------
49 void ImageInfoUR::SetImageName(const StringType &imgName)
51 this->m_ImageName = imgName;
54 // ----------------------------------------------------------------------------------
55 void ImageInfoUR::SetImageMManager(ImageMManagerType* imMManager)
57 this->m_ImageMManager = imMManager;
60 // ----------------------------------------------------------------------------------
61 void ImageInfoUR::SetStatus(const bool& onMemory)
63 this->m_OnMemory = onMemory;
66 // ----------------------------------------------------------------------------------
67 ImageInfoUR::StringType ImageInfoUR::GetImageName()
69 return (this->m_ImageName);
72 // ----------------------------------------------------------------------------------
73 ImageInfoUR::VTKImageDataPointerType ImageInfoUR::GetUndoImage()
75 return (this->m_UndoImage);
78 // ----------------------------------------------------------------------------------
79 ImageInfoUR::VTKImageDataPointerType ImageInfoUR::GetRedoImage()
81 return (this->m_RedoImage);
84 // ----------------------------------------------------------------------------------
85 ImageInfoUR::ImageMManagerType* ImageInfoUR::GetImageMManager()
87 return (this->m_ImageMManager);
90 // ----------------------------------------------------------------------------------
91 bool ImageInfoUR::GetStatus()
93 return (this->m_OnMemory);
96 // ----------------------------------------------------------------------------------
97 void ImageInfoUR::SetImages(VTKImageDataPointerType imgUndo, VTKImageDataPointerType imgRedo)
99 this->m_UndoImage = imgUndo;
100 this->m_RedoImage = imgRedo;
101 this->SetStatus(true);
104 // ----------------------------------------------------------------------------------
105 void ImageInfoUR::LoadImagesToMemory(const StringType& gPath)
108 StringType filename = gPath + this->m_ImageName;
109 StringType undoImagePath = filename + "_Undo.mhd";
110 StringType redoImagePath = filename + "_Redo.mhd";
112 VTKMetaImageReaderPointerType readerUndo = VTKMetaImageReaderPointerType::New();
113 readerUndo->SetFileName(undoImagePath.c_str());
114 //EED 2017-01-01 Migration VTK7
115 #if VTK_MAJOR_VERSION <= 5
118 readerUndo->Update();
121 this->m_UndoImage = readerUndo->GetOutput();
122 //EED 2017-01-01 Migration VTK7
123 #if VTK_MAJOR_VERSION <= 5
124 this->m_UndoImage->Update();
126 this->m_UndoImage->Modified();
129 VTKMetaImageReaderPointerType readerRedo = VTKMetaImageReaderPointerType::New();
130 readerRedo->SetFileName(redoImagePath.c_str());
131 //EED 2017-01-01 Migration VTK7
132 #if VTK_MAJOR_VERSION <= 5
135 readerRedo->Update();
138 this->m_RedoImage = readerRedo->GetOutput();
139 //EED 2017-01-01 Migration VTK7
140 #if VTK_MAJOR_VERSION <= 5
141 this->m_RedoImage->Update();
143 this->m_RedoImage->Modified();
146 this->m_OnMemory = true;
149 // ----------------------------------------------------------------------------------
150 void ImageInfoUR::RemoveImagesFromMemory(const StringType& gPath)
154 this->SaveImagesOnDisk(gPath);
156 this->m_UndoImage = NULL;
157 this->m_RedoImage = NULL;
158 this->SetStatus(false);
161 // ----------------------------------------------------------------------------------
162 void ImageInfoUR::SaveImagesOnDisk(const StringType& gPath)
164 printf("EED ImageInfoUR::SaveImagesOnDisk Start \n");
165 this->m_OnDisk = true;
166 StringType filename = gPath + this->m_ImageName;
167 StringType undoImagePath = filename + "_Undo.mhd";
168 StringType redoImagePath = filename + "_Redo.mhd";
169 this->SaveImageAsMHD(undoImagePath, this->m_UndoImage);
170 this->SaveImageAsMHD(redoImagePath, this->m_RedoImage);
171 printf("EED ImageInfoUR::SaveImagesOnDisk %s \n", undoImagePath.c_str() );
174 // ----------------------------------------------------------------------------------
175 void ImageInfoUR::RemoveImagesFromDisk(const StringType& gPath)
177 StringType filename = gPath + this->m_ImageName;
178 StringType undoImagePathMHD = filename + "_Undo.mhd";
179 StringType redoImagePathMHD = filename + "_Redo.mhd";
180 StringType undoImagePathRAW = filename + "_Undo.raw";
181 StringType redoImagePathRAW = filename + "_Redo.raw";
182 remove(undoImagePathMHD.c_str());
183 remove(redoImagePathMHD.c_str());
184 remove(undoImagePathRAW.c_str());
185 remove(redoImagePathRAW.c_str());
188 // ----------------------------------------------------------------------------------
189 void ImageInfoUR::SaveImageAsMHD(const StringType& filename, VTKImageDataPointerType image)
191 VTKMetaImageWriterPointerType w = VTKMetaImageWriterPointerType::New();
192 //EED 2017-01-01 Migration VTK7
193 #if VTK_MAJOR_VERSION <= 5
196 w->SetInputData(image);
198 w->SetCompression(false);
199 w->SetFileDimensionality(image->GetDataDimension());
200 w->SetFileName(filename.c_str());
203 // ----------------------------------------------------------------------------------