]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/imageUndoRedo/imageInfoUR.cxx
DFCH: ManualPaint + imageUndoRedo: Undo/Redo functionality its now working =) =)
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / imageUndoRedo / imageInfoUR.cxx
1 /*!
2  * @file        imageInfoUR.cxx
3  * @brief       This file contains the implementation of the ImageInfoUR class.
4  * @author      Info-Dev
5  * @author      Diego CACERES (diego.caceres[AT]creatis.insa-lyon.fr)
6  * @date        2011-11-15
7  */
8
9 #include "imageInfoUR.h"
10
11 // ----------------------------------------------------------------------------------
12 ImageInfoUR::ImageInfoUR() {
13         this->m_OnMemory = false;
14         this->m_OnDisk = false;
15 }
16 // ----------------------------------------------------------------------------------
17 ImageInfoUR::~ImageInfoUR() {
18 }
19 // ----------------------------------------------------------------------------------
20 void ImageInfoUR::SetImageName(const StringType &imgName) {
21         this->m_ImageName = imgName;
22 }
23 // ----------------------------------------------------------------------------------
24 void ImageInfoUR::SetImageMManager(ImageMManagerType* imMManager) {
25         this->m_ImageMManager = imMManager;
26 }
27 // ----------------------------------------------------------------------------------
28 void ImageInfoUR::SetStatus(const bool& onMemory) {
29         this->m_OnMemory = onMemory;
30 }
31 // ----------------------------------------------------------------------------------
32 ImageInfoUR::StringType ImageInfoUR::GetImageName() {
33         return (this->m_ImageName);
34 }
35 // ----------------------------------------------------------------------------------
36 ImageInfoUR::VTKImageDataPointerType ImageInfoUR::GetUndoImage() {
37         return (this->m_UndoImage);
38 }
39 // ----------------------------------------------------------------------------------
40 ImageInfoUR::VTKImageDataPointerType ImageInfoUR::GetRedoImage() {
41         return (this->m_RedoImage);
42 }
43 // ----------------------------------------------------------------------------------
44 ImageInfoUR::ImageMManagerType* ImageInfoUR::GetImageMManager() {
45         return (this->m_ImageMManager);
46 }
47 // ----------------------------------------------------------------------------------
48 bool ImageInfoUR::GetStatus() {
49         return (this->m_OnMemory);
50 }
51 // ----------------------------------------------------------------------------------
52 void ImageInfoUR::SetImages(VTKImageDataPointerType imgUndo,
53                 VTKImageDataPointerType imgRedo) {
54         this->m_UndoImage = imgUndo;
55         this->m_RedoImage = imgRedo;
56         this->SetStatus(true);
57 }
58 // ----------------------------------------------------------------------------------
59 void ImageInfoUR::LoadImagesToMemory(const StringType& gPath) {
60         //setting paths
61         StringType filename = gPath + this->m_ImageName;
62         StringType undoImagePath = filename + "_Undo.mhd";
63         StringType redoImagePath = filename + "_Redo.mhd";
64         //Loading Undo Image
65         VTKMetaImageReaderPointerType readerUndo =
66                         VTKMetaImageReaderPointerType::New();
67         readerUndo->SetFileName(undoImagePath.c_str());
68         this->m_UndoImage = readerUndo->GetOutput();
69         this->m_UndoImage->Update();
70         //Loading Redo Image
71         VTKMetaImageReaderPointerType readerRedo =
72                         VTKMetaImageReaderPointerType::New();
73         readerRedo->SetFileName(redoImagePath.c_str());
74         this->m_RedoImage = readerRedo->GetOutput();
75         this->m_RedoImage->Update();
76         //Updating status
77         this->m_OnMemory = true;
78 }
79 // ----------------------------------------------------------------------------------
80 void ImageInfoUR::RemoveImagesFromMemory(const StringType& gPath) {
81         if (!this->m_OnDisk) {
82                 this->SaveImagesOnDisk(gPath);
83         }
84         this->m_UndoImage = NULL;
85         this->m_RedoImage = NULL;
86         this->SetStatus(false);
87 }
88 // ----------------------------------------------------------------------------------
89 void ImageInfoUR::SaveImagesOnDisk(const StringType& gPath) {
90         this->m_OnDisk = true;
91         StringType filename = gPath + this->m_ImageName;
92         StringType undoImagePath = filename + "_Undo.mhd";
93         StringType redoImagePath = filename + "_Redo.mhd";
94         this->SaveImageAsMHD(undoImagePath, this->m_UndoImage);
95         this->SaveImageAsMHD(redoImagePath, this->m_RedoImage);
96 }
97 // ----------------------------------------------------------------------------------
98 void ImageInfoUR::RemoveImagesFromDisk(const StringType& gPath) {
99         StringType filename = gPath + this->m_ImageName;
100         StringType undoImagePathMHD = filename + "_Undo.mhd";
101         StringType redoImagePathMHD = filename + "_Redo.mhd";
102         StringType undoImagePathRAW = filename + "_Undo.raw";
103         StringType redoImagePathRAW = filename + "_Redo.raw";
104         remove(undoImagePathMHD.c_str());
105         remove(redoImagePathMHD.c_str());
106         remove(undoImagePathRAW.c_str());
107         remove(redoImagePathRAW.c_str());
108 }
109 // ----------------------------------------------------------------------------------
110 void ImageInfoUR::SaveImageAsMHD(const StringType& filename,
111                 VTKImageDataPointerType image) {
112         VTKMetaImageWriterPointerType w = VTKMetaImageWriterPointerType::New();
113         w->SetInput(image);
114         w->SetCompression(false);
115         w->SetFileDimensionality(image->GetDataDimension());
116         w->SetFileName(filename.c_str());
117         w->Write();
118 }
119 // ----------------------------------------------------------------------------------