X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpExtensions%2FIO%2FMementoState.cxx;fp=lib%2FcpExtensions%2FIO%2FMementoState.cxx;h=2af5abfe4cf3720fad8df6b00ae63230cb003ed4;hb=1b0022070ff3b5f80f6f8c8b87f73032f5685eaf;hp=0000000000000000000000000000000000000000;hpb=98390bcac544f7f3a6762ce812dda491213d6f13;p=cpPlugins.git diff --git a/lib/cpExtensions/IO/MementoState.cxx b/lib/cpExtensions/IO/MementoState.cxx new file mode 100644 index 0000000..2af5abf --- /dev/null +++ b/lib/cpExtensions/IO/MementoState.cxx @@ -0,0 +1,148 @@ +/* +#include + + +#include +#include +#include + + + + + +// ------------------------------------------------------------------------- +cpExtensions::IO::MementoState::MementoState() +{ + m_maxId = m_Id = 0; + m_stateIt = m_stateReady.begin(); +}; + +// ------------------------------------------------------------------------- +bool +cpExtensions::IO::MementoState::SetToMemento(cpPlugins::Interface::Image* _img) +{ + char base[] = "state"; + std::ostringstream oss; + this->m_Id; + oss << this->m_Id; + std::string str = oss.str(); + auto complement = str.c_str(); + + std::string fileName(base); + fileName.append(complement); + fileName.append(".mhd"); + + std::string fileNameRaw(base); + fileNameRaw.append(complement); + fileNameRaw.append(".raw"); + //save(fileName, fileNameRaw, _img); + m_stateReady.insert(m_stateReady.begin() + m_Id, false); + std::async(std::launch::async, &MementoState::Save, this, fileName, fileNameRaw, _img); + + m_stateReady[m_Id] = true; + m_Id++; + + if (m_Id > m_maxId) + { + m_maxId = m_Id; + } + + return true; +} + + +// ------------------------------------------------------------------------- +vtkSmartPointer +cpExtensions::IO::MementoState::GetFromMemento(long id) +{ + if (id > m_maxId) + { + return nullptr; + } + + char base[] = "state"; + std::ostringstream oss; + oss << id; + std::string str = oss.str(); + auto complement = str.c_str(); + + std::string fileName(base); + fileName.append(complement); + fileName.append(".mhd"); + return Load(fileName); + //std::future> result(std::async(std::launch::async, &MementoState::Load, this, fileName)); + //return result.get(); +} + +// ------------------------------------------------------------------------- +vtkSmartPointer +cpExtensions::IO::MementoState::MementoUndo() +{ + char base[] = "state"; + std::ostringstream oss; + oss << --this->m_Id; + std::string str = oss.str(); + auto complement = str.c_str(); + + std::string fileName(base); + fileName.append(complement); + fileName.append(".mhd"); + + if (m_stateReady.at(this->m_Id)) + { + return Load(fileName); + } + + return nullptr; +} + + +vtkSmartPointer +cpExtensions::IO::MementoState::MementoRedo() +{ + char base[] = "state"; + std::ostringstream oss; + oss << ++this->m_Id; + std::string str = oss.str(); + auto complement = str.c_str(); + + std::string fileName(base); + fileName.append(complement); + fileName.append(".mhd"); + + if (m_stateReady.at(this->m_Id) && + this->m_Id <= this->m_maxId) + { + return Load(fileName); + } + return nullptr; +} + +// ------------------------------------------------------------------------- +void +cpExtensions::IO::MementoState:: +Save(const std::string& filename, const std::string& filenameRaw, cpPlugins::Interface::Image* img) { + + vtkSmartPointer writer = + vtkSmartPointer::New(); + writer->SetInputData(img->GetVTK< vtkImageData >()); + writer->SetFileName(filename.c_str()); + writer->SetRAWFileName(filenameRaw.c_str()); + writer->Write(); +} + +// ------------------------------------------------------------------------- +vtkSmartPointer +cpExtensions::IO::MementoState::Load(const std::string& filename) { + + vtkSmartPointer reader = + vtkSmartPointer::New(); + reader->SetFileName(filename.c_str()); + + reader->Update(); + return reader->GetOutput(); + +} +*/ + +// eof - $RCSfile$