2 #include <cpExtensions/IO/MementoState.h>
5 #include <vtkMetaImageReader.h>
6 #include <vtkMetaImageWriter.h>
13 // -------------------------------------------------------------------------
14 cpExtensions::IO::MementoState::MementoState()
17 m_stateIt = m_stateReady.begin();
20 // -------------------------------------------------------------------------
22 cpExtensions::IO::MementoState::SetToMemento(cpPlugins::Interface::Image* _img)
24 char base[] = "state";
25 std::ostringstream oss;
28 std::string str = oss.str();
29 auto complement = str.c_str();
31 std::string fileName(base);
32 fileName.append(complement);
33 fileName.append(".mhd");
35 std::string fileNameRaw(base);
36 fileNameRaw.append(complement);
37 fileNameRaw.append(".raw");
38 //save(fileName, fileNameRaw, _img);
39 m_stateReady.insert(m_stateReady.begin() + m_Id, false);
40 std::async(std::launch::async, &MementoState::Save, this, fileName, fileNameRaw, _img);
42 m_stateReady[m_Id] = true;
54 // -------------------------------------------------------------------------
55 vtkSmartPointer<vtkImageData>
56 cpExtensions::IO::MementoState::GetFromMemento(long id)
63 char base[] = "state";
64 std::ostringstream oss;
66 std::string str = oss.str();
67 auto complement = str.c_str();
69 std::string fileName(base);
70 fileName.append(complement);
71 fileName.append(".mhd");
72 return Load(fileName);
73 //std::future<vtkSmartPointer<vtkImageData>> result(std::async(std::launch::async, &MementoState::Load, this, fileName));
74 //return result.get();
77 // -------------------------------------------------------------------------
78 vtkSmartPointer<vtkImageData>
79 cpExtensions::IO::MementoState::MementoUndo()
81 char base[] = "state";
82 std::ostringstream oss;
84 std::string str = oss.str();
85 auto complement = str.c_str();
87 std::string fileName(base);
88 fileName.append(complement);
89 fileName.append(".mhd");
91 if (m_stateReady.at(this->m_Id))
93 return Load(fileName);
100 vtkSmartPointer<vtkImageData>
101 cpExtensions::IO::MementoState::MementoRedo()
103 char base[] = "state";
104 std::ostringstream oss;
106 std::string str = oss.str();
107 auto complement = str.c_str();
109 std::string fileName(base);
110 fileName.append(complement);
111 fileName.append(".mhd");
113 if (m_stateReady.at(this->m_Id) &&
114 this->m_Id <= this->m_maxId)
116 return Load(fileName);
121 // -------------------------------------------------------------------------
123 cpExtensions::IO::MementoState::
124 Save(const std::string& filename, const std::string& filenameRaw, cpPlugins::Interface::Image* img) {
126 vtkSmartPointer<vtkMetaImageWriter> writer =
127 vtkSmartPointer<vtkMetaImageWriter>::New();
128 writer->SetInputData(img->GetVTK< vtkImageData >());
129 writer->SetFileName(filename.c_str());
130 writer->SetRAWFileName(filenameRaw.c_str());
134 // -------------------------------------------------------------------------
135 vtkSmartPointer<vtkImageData>
136 cpExtensions::IO::MementoState::Load(const std::string& filename) {
138 vtkSmartPointer<vtkMetaImageReader> reader =
139 vtkSmartPointer<vtkMetaImageReader>::New();
140 reader->SetFileName(filename.c_str());
143 return reader->GetOutput();