]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageInfoUR.cxx
Support #1768 CREATIS Licence insertion
[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         this->m_OnMemory = false;
39         this->m_OnDisk = false;
40 }
41 // ----------------------------------------------------------------------------------
42 ImageInfoUR::~ImageInfoUR() {
43 }
44 // ----------------------------------------------------------------------------------
45 void ImageInfoUR::SetImageName(const StringType &imgName) {
46         this->m_ImageName = imgName;
47 }
48 // ----------------------------------------------------------------------------------
49 void ImageInfoUR::SetImageMManager(ImageMManagerType* imMManager) {
50         this->m_ImageMManager = imMManager;
51 }
52 // ----------------------------------------------------------------------------------
53 void ImageInfoUR::SetStatus(const bool& onMemory) {
54         this->m_OnMemory = onMemory;
55 }
56 // ----------------------------------------------------------------------------------
57 ImageInfoUR::StringType ImageInfoUR::GetImageName() {
58         return (this->m_ImageName);
59 }
60 // ----------------------------------------------------------------------------------
61 ImageInfoUR::VTKImageDataPointerType ImageInfoUR::GetUndoImage() {
62         return (this->m_UndoImage);
63 }
64 // ----------------------------------------------------------------------------------
65 ImageInfoUR::VTKImageDataPointerType ImageInfoUR::GetRedoImage() {
66         return (this->m_RedoImage);
67 }
68 // ----------------------------------------------------------------------------------
69 ImageInfoUR::ImageMManagerType* ImageInfoUR::GetImageMManager() {
70         return (this->m_ImageMManager);
71 }
72 // ----------------------------------------------------------------------------------
73 bool ImageInfoUR::GetStatus() {
74         return (this->m_OnMemory);
75 }
76 // ----------------------------------------------------------------------------------
77 void ImageInfoUR::SetImages(VTKImageDataPointerType imgUndo,
78                 VTKImageDataPointerType imgRedo) {
79         this->m_UndoImage = imgUndo;
80         this->m_RedoImage = imgRedo;
81         this->SetStatus(true);
82 }
83 // ----------------------------------------------------------------------------------
84 void ImageInfoUR::LoadImagesToMemory(const StringType& gPath) {
85         //setting paths
86         StringType filename = gPath + this->m_ImageName;
87         StringType undoImagePath = filename + "_Undo.mhd";
88         StringType redoImagePath = filename + "_Redo.mhd";
89         //Loading Undo Image
90         VTKMetaImageReaderPointerType readerUndo =
91                         VTKMetaImageReaderPointerType::New();
92         readerUndo->SetFileName(undoImagePath.c_str());
93         this->m_UndoImage = readerUndo->GetOutput();
94         this->m_UndoImage->Update();
95         //Loading Redo Image
96         VTKMetaImageReaderPointerType readerRedo =
97                         VTKMetaImageReaderPointerType::New();
98         readerRedo->SetFileName(redoImagePath.c_str());
99         this->m_RedoImage = readerRedo->GetOutput();
100         this->m_RedoImage->Update();
101         //Updating status
102         this->m_OnMemory = true;
103 }
104 // ----------------------------------------------------------------------------------
105 void ImageInfoUR::RemoveImagesFromMemory(const StringType& gPath) {
106         if (!this->m_OnDisk) {
107                 this->SaveImagesOnDisk(gPath);
108         }
109         this->m_UndoImage = NULL;
110         this->m_RedoImage = NULL;
111         this->SetStatus(false);
112 }
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);
121 }
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());
133 }
134 // ----------------------------------------------------------------------------------
135 void ImageInfoUR::SaveImageAsMHD(const StringType& filename,
136                 VTKImageDataPointerType image) {
137         VTKMetaImageWriterPointerType w = VTKMetaImageWriterPointerType::New();
138         w->SetInput(image);
139         w->SetCompression(false);
140         w->SetFileDimensionality(image->GetDataDimension());
141         w->SetFileName(filename.c_str());
142         w->Write();
143 }
144 // ----------------------------------------------------------------------------------