]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageInfoUR.cxx
#3109 creaMaracasVisu Bug New Normal - branch vtk7itk4 compilation with vtk7
[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 //EED 2017-01-01 Migration VTK7
95 #if VTK_MAJOR_VERSION <= 5
96         this->m_UndoImage->Update();
97 #else
98         // ..
99 #endif
100         //Loading Redo Image
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
106         // ..
107 #else
108         readerRedo->Update();
109 #endif
110
111         this->m_RedoImage = readerRedo->GetOutput();
112 //EED 2017-01-01 Migration VTK7
113 #if VTK_MAJOR_VERSION <= 5
114         this->m_RedoImage->Update();
115 #else
116         // ...
117 #endif
118         //Updating status
119         this->m_OnMemory = true;
120 }
121 // ----------------------------------------------------------------------------------
122 void ImageInfoUR::RemoveImagesFromMemory(const StringType& gPath) {
123         if (!this->m_OnDisk) {
124                 this->SaveImagesOnDisk(gPath);
125         }
126         this->m_UndoImage = NULL;
127         this->m_RedoImage = NULL;
128         this->SetStatus(false);
129 }
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);
138 }
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());
150 }
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
157         w->SetInput(image);
158 #else
159         w->SetInputData(image);
160 #endif
161         w->SetCompression(false);
162         w->SetFileDimensionality(image->GetDataDimension());
163         w->SetFileName(filename.c_str());
164         w->Write();
165 }
166 // ----------------------------------------------------------------------------------