| 26 | } |
| 27 | |
| 28 | std::string mitk::ImageSerializer::Serialize() |
| 29 | { |
| 30 | const auto *image = dynamic_cast<const Image *>(m_Data.GetPointer()); |
| 31 | if (!image) |
| 32 | { |
| 33 | MITK_ERROR << " Object at " << (const void *)this->m_Data << " is not an mitk::Image. Cannot serialize as image."; |
| 34 | return ""; |
| 35 | } |
| 36 | |
| 37 | std::string filename(this->GetUniqueFilenameInWorkingDirectory()); |
| 38 | std::cout << "creating file " << filename << " in " << m_WorkingDirectory << std::endl; |
| 39 | filename += "_"; |
| 40 | filename += m_FilenameHint; |
| 41 | |
| 42 | std::string fullname(m_WorkingDirectory); |
| 43 | fullname += Poco::Path::separator(); |
| 44 | fullname += filename + ".nrrd"; |
| 45 | |
| 46 | try |
| 47 | { |
| 48 | IOUtil::Save(image, fullname); |
| 49 | } |
| 50 | catch (std::exception &e) |
| 51 | { |
| 52 | MITK_ERROR << " Error serializing object at " << (const void *)this->m_Data << " to " << fullname << ": " |
| 53 | << e.what(); |
| 54 | return ""; |
| 55 | } |
| 56 | return Poco::Path(fullname).getFileName(); |
| 57 | } |
no test coverage detected