2 * @file imageInfoUR.cxx
3 * @brief This file contains the implementation of the ImageInfoUR class.
5 * @author Diego CACERES (diego.caceres[AT]creatis.insa-lyon.fr)
9 #include "imageInfoUR.h"
11 // ----------------------------------------------------------------------------------
12 ImageInfoUR::ImageInfoUR() {
13 this->m_OnMemory = false;
14 this->m_OnDisk = false;
16 // ----------------------------------------------------------------------------------
17 ImageInfoUR::~ImageInfoUR() {
19 // ----------------------------------------------------------------------------------
20 void ImageInfoUR::SetImageName(const StringType &imgName) {
21 this->m_ImageName = imgName;
23 // ----------------------------------------------------------------------------------
24 void ImageInfoUR::SetImageMManager(ImageMManagerType* imMManager) {
25 this->m_ImageMManager = imMManager;
27 // ----------------------------------------------------------------------------------
28 void ImageInfoUR::SetStatus(const bool& onMemory) {
29 this->m_OnMemory = onMemory;
31 // ----------------------------------------------------------------------------------
32 ImageInfoUR::StringType ImageInfoUR::GetImageName() {
33 return (this->m_ImageName);
35 // ----------------------------------------------------------------------------------
36 ImageInfoUR::VTKImageDataPointerType ImageInfoUR::GetUndoImage() {
37 return (this->m_UndoImage);
39 // ----------------------------------------------------------------------------------
40 ImageInfoUR::VTKImageDataPointerType ImageInfoUR::GetRedoImage() {
41 return (this->m_RedoImage);
43 // ----------------------------------------------------------------------------------
44 ImageInfoUR::ImageMManagerType* ImageInfoUR::GetImageMManager() {
45 return (this->m_ImageMManager);
47 // ----------------------------------------------------------------------------------
48 bool ImageInfoUR::GetStatus() {
49 return (this->m_OnMemory);
51 // ----------------------------------------------------------------------------------
52 void ImageInfoUR::SetImages(VTKImageDataPointerType imgUndo,
53 VTKImageDataPointerType imgRedo) {
54 this->m_UndoImage = imgUndo;
55 this->m_RedoImage = imgRedo;
56 this->SetStatus(true);
58 // ----------------------------------------------------------------------------------
59 void ImageInfoUR::LoadImagesToMemory(const StringType& gPath) {
61 StringType filename = gPath + this->m_ImageName;
62 StringType undoImagePath = filename + "_Undo.mhd";
63 StringType redoImagePath = filename + "_Redo.mhd";
65 VTKMetaImageReaderPointerType readerUndo =
66 VTKMetaImageReaderPointerType::New();
67 readerUndo->SetFileName(undoImagePath.c_str());
68 this->m_UndoImage = readerUndo->GetOutput();
69 this->m_UndoImage->Update();
71 VTKMetaImageReaderPointerType readerRedo =
72 VTKMetaImageReaderPointerType::New();
73 readerRedo->SetFileName(redoImagePath.c_str());
74 this->m_RedoImage = readerRedo->GetOutput();
75 this->m_RedoImage->Update();
77 this->m_OnMemory = true;
79 // ----------------------------------------------------------------------------------
80 void ImageInfoUR::RemoveImagesFromMemory(const StringType& gPath) {
81 if (!this->m_OnDisk) {
82 this->SaveImagesOnDisk(gPath);
84 this->m_UndoImage = NULL;
85 this->m_RedoImage = NULL;
86 this->SetStatus(false);
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);
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());
109 // ----------------------------------------------------------------------------------
110 void ImageInfoUR::SaveImageAsMHD(const StringType& filename,
111 VTKImageDataPointerType image) {
112 VTKMetaImageWriterPointerType w = VTKMetaImageWriterPointerType::New();
114 w->SetCompression(false);
115 w->SetFileDimensionality(image->GetDataDimension());
116 w->SetFileName(filename.c_str());
119 // ----------------------------------------------------------------------------------