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 this->m_UndoImage->Update();
96 VTKMetaImageReaderPointerType readerRedo =
97 VTKMetaImageReaderPointerType::New();
98 readerRedo->SetFileName(redoImagePath.c_str());
99 this->m_RedoImage = readerRedo->GetOutput();
100 this->m_RedoImage->Update();
102 this->m_OnMemory = true;
104 // ----------------------------------------------------------------------------------
105 void ImageInfoUR::RemoveImagesFromMemory(const StringType& gPath) {
106 if (!this->m_OnDisk) {
107 this->SaveImagesOnDisk(gPath);
109 this->m_UndoImage = NULL;
110 this->m_RedoImage = NULL;
111 this->SetStatus(false);
113 // ----------------------------------------------------------------------------------
114 void ImageInfoUR::SaveImagesOnDisk(const StringType& gPath) {
115 this->m_OnDisk = true;
116 StringType filename = gPath + this->m_ImageName;
117 StringType undoImagePath = filename + "_Undo.mhd";
118 StringType redoImagePath = filename + "_Redo.mhd";
119 this->SaveImageAsMHD(undoImagePath, this->m_UndoImage);
120 this->SaveImageAsMHD(redoImagePath, this->m_RedoImage);
122 // ----------------------------------------------------------------------------------
123 void ImageInfoUR::RemoveImagesFromDisk(const StringType& gPath) {
124 StringType filename = gPath + this->m_ImageName;
125 StringType undoImagePathMHD = filename + "_Undo.mhd";
126 StringType redoImagePathMHD = filename + "_Redo.mhd";
127 StringType undoImagePathRAW = filename + "_Undo.raw";
128 StringType redoImagePathRAW = filename + "_Redo.raw";
129 remove(undoImagePathMHD.c_str());
130 remove(redoImagePathMHD.c_str());
131 remove(undoImagePathRAW.c_str());
132 remove(redoImagePathRAW.c_str());
134 // ----------------------------------------------------------------------------------
135 void ImageInfoUR::SaveImageAsMHD(const StringType& filename,
136 VTKImageDataPointerType image) {
137 VTKMetaImageWriterPointerType w = VTKMetaImageWriterPointerType::New();
139 w->SetCompression(false);
140 w->SetFileDimensionality(image->GetDataDimension());
141 w->SetFileName(filename.c_str());
144 // ----------------------------------------------------------------------------------