]> Creatis software - cpPlugins.git/blob - appli/ImageMPR/MementoState.cxx
update: undo/redo for image to image filters
[cpPlugins.git] / appli / ImageMPR / MementoState.cxx
1 #include "MementoState.h"
2
3 #include <vtkMetaImageReader.h>
4 #include <vtkMetaImageWriter.h>
5
6
7 // -------------------------------------------------------------------------
8 MementoState::MementoState()
9 {
10         m_Id = 0;
11 };
12
13 // -------------------------------------------------------------------------
14 MementoState::MementoState(long id, TPluginImage* _img)
15 {
16         char * base = "state";
17         std::ostringstream oss;
18         oss << id;
19         std::string str = oss.str();
20         auto complement = str.c_str();
21
22         std::string fileName(base);
23         fileName.append(complement);
24         fileName.append(".mhd");
25
26         std::string fileNameRaw(base);
27         fileNameRaw.append(complement);
28         fileNameRaw.append(".raw");
29         save(fileName, fileNameRaw, _img);
30 }
31
32 // -------------------------------------------------------------------------
33 vtkSmartPointer<vtkMetaImageReader>
34 MementoState::getMemento(long id)
35 {
36         char * base = "state";
37         std::ostringstream oss;
38         oss << id;
39         std::string str = oss.str();
40         auto complement = str.c_str();
41
42         std::string fileName(base);
43         fileName.append(complement);
44         fileName.append(".mhd");
45         return load(fileName);
46 }
47
48 // -------------------------------------------------------------------------
49 void MementoState::
50 save(const std::string& filename, const std::string& filenameRaw, TPluginImage* img) {
51         vtkSmartPointer<vtkMetaImageWriter> writer =
52                 vtkSmartPointer<vtkMetaImageWriter>::New();
53         writer->SetInputData(img->GetVTK< vtkImageData >());
54         writer->SetFileName(filename.c_str());
55         writer->SetRAWFileName(filenameRaw.c_str());
56         writer->Write();
57 }
58
59 // -------------------------------------------------------------------------
60 vtkSmartPointer<vtkMetaImageReader>
61 MementoState::load(const std::string& filename) {
62         vtkSmartPointer<vtkMetaImageReader> reader =
63                 vtkSmartPointer<vtkMetaImageReader>::New();
64         reader->SetFileName(filename.c_str());
65         reader->Update();
66         return reader;
67 }
68
69 // eof - $RCSfile$