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() {
38 this->m_OnMemory = false;
39 this->m_OnDisk = false;
41 // ----------------------------------------------------------------------------------
42 ImageInfoUR::~ImageInfoUR() {
44 // ----------------------------------------------------------------------------------
45 void ImageInfoUR::SetImageName(const StringType &imgName) {
46 this->m_ImageName = imgName;
48 // ----------------------------------------------------------------------------------
49 void ImageInfoUR::SetImageMManager(ImageMManagerType* imMManager) {
50 this->m_ImageMManager = imMManager;
52 // ----------------------------------------------------------------------------------
53 void ImageInfoUR::SetStatus(const bool& onMemory) {
54 this->m_OnMemory = onMemory;
56 // ----------------------------------------------------------------------------------
57 ImageInfoUR::StringType ImageInfoUR::GetImageName() {
58 return (this->m_ImageName);
60 // ----------------------------------------------------------------------------------
61 ImageInfoUR::VTKImageDataPointerType ImageInfoUR::GetUndoImage() {
62 return (this->m_UndoImage);
64 // ----------------------------------------------------------------------------------
65 ImageInfoUR::VTKImageDataPointerType ImageInfoUR::GetRedoImage() {
66 return (this->m_RedoImage);
68 // ----------------------------------------------------------------------------------
69 ImageInfoUR::ImageMManagerType* ImageInfoUR::GetImageMManager() {
70 return (this->m_ImageMManager);
72 // ----------------------------------------------------------------------------------
73 bool ImageInfoUR::GetStatus() {
74 return (this->m_OnMemory);
76 // ----------------------------------------------------------------------------------
77 void ImageInfoUR::SetImages(VTKImageDataPointerType imgUndo,
78 VTKImageDataPointerType imgRedo) {
79 this->m_UndoImage = imgUndo;
80 this->m_RedoImage = imgRedo;
81 this->SetStatus(true);
83 // ----------------------------------------------------------------------------------
84 void ImageInfoUR::LoadImagesToMemory(const StringType& gPath) {
86 StringType filename = gPath + this->m_ImageName;
87 StringType undoImagePath = filename + "_Undo.mhd";
88 StringType redoImagePath = filename + "_Redo.mhd";
90 VTKMetaImageReaderPointerType readerUndo =
91 VTKMetaImageReaderPointerType::New();
92 readerUndo->SetFileName(undoImagePath.c_str());
93 this->m_UndoImage = readerUndo->GetOutput();
94 //EED 2017-01-01 Migration VTK7
95 #if VTK_MAJOR_VERSION <= 5
96 this->m_UndoImage->Update();
101 VTKMetaImageReaderPointerType readerRedo =
102 VTKMetaImageReaderPointerType::New();
103 readerRedo->SetFileName(redoImagePath.c_str());
104 //EED 2017-01-01 Migration VTK7
105 #if VTK_MAJOR_VERSION <= 5
108 readerRedo->Update();
111 this->m_RedoImage = readerRedo->GetOutput();
112 //EED 2017-01-01 Migration VTK7
113 #if VTK_MAJOR_VERSION <= 5
114 this->m_RedoImage->Update();
119 this->m_OnMemory = true;
121 // ----------------------------------------------------------------------------------
122 void ImageInfoUR::RemoveImagesFromMemory(const StringType& gPath) {
123 if (!this->m_OnDisk) {
124 this->SaveImagesOnDisk(gPath);
126 this->m_UndoImage = NULL;
127 this->m_RedoImage = NULL;
128 this->SetStatus(false);
130 // ----------------------------------------------------------------------------------
131 void ImageInfoUR::SaveImagesOnDisk(const StringType& gPath) {
132 this->m_OnDisk = true;
133 StringType filename = gPath + this->m_ImageName;
134 StringType undoImagePath = filename + "_Undo.mhd";
135 StringType redoImagePath = filename + "_Redo.mhd";
136 this->SaveImageAsMHD(undoImagePath, this->m_UndoImage);
137 this->SaveImageAsMHD(redoImagePath, this->m_RedoImage);
139 // ----------------------------------------------------------------------------------
140 void ImageInfoUR::RemoveImagesFromDisk(const StringType& gPath) {
141 StringType filename = gPath + this->m_ImageName;
142 StringType undoImagePathMHD = filename + "_Undo.mhd";
143 StringType redoImagePathMHD = filename + "_Redo.mhd";
144 StringType undoImagePathRAW = filename + "_Undo.raw";
145 StringType redoImagePathRAW = filename + "_Redo.raw";
146 remove(undoImagePathMHD.c_str());
147 remove(redoImagePathMHD.c_str());
148 remove(undoImagePathRAW.c_str());
149 remove(redoImagePathRAW.c_str());
151 // ----------------------------------------------------------------------------------
152 void ImageInfoUR::SaveImageAsMHD(const StringType& filename,
153 VTKImageDataPointerType image) {
154 VTKMetaImageWriterPointerType w = VTKMetaImageWriterPointerType::New();
155 //EED 2017-01-01 Migration VTK7
156 #if VTK_MAJOR_VERSION <= 5
159 w->SetInputData(image);
161 w->SetCompression(false);
162 w->SetFileDimensionality(image->GetDataDimension());
163 w->SetFileName(filename.c_str());
166 // ----------------------------------------------------------------------------------