fw4spl
FileWriter.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "fwGdcmIO/helper/FileWriter.hpp"
8 
9 #include "fwGdcmIO/exception/Failed.hpp"
10 
11 #include <gdcmFileMetaInformation.h>
12 #include <gdcmWriter.h>
13 
14 namespace fwGdcmIO
15 {
16 namespace helper
17 {
18 //------------------------------------------------------------------------------
19 
20 void FileWriter::write(const ::boost::filesystem::path& filename,
21  const SPTR(::gdcm::Writer)& writer)
22 {
23  // Set file header
24  ::gdcm::FileMetaInformation& metaInformation = writer->GetFile().GetHeader();
25 
26  // Transfer syntax - Type 1
27  metaInformation.SetDataSetTransferSyntax(::gdcm::TransferSyntax::ExplicitVRLittleEndian);
28 
29  // Initialize the file
30  writer->SetFileName(filename.string().c_str()); // NOTE: Must be called when file is ready to be written
31 
32  // Write data
33  if (!writer->Write())
34  {
35  const std::string msg = "Unable to write the file " + filename.string();
36  throw ::fwGdcmIO::exception::Failed(msg);
37  }
38 }
39 
40 //------------------------------------------------------------------------------
41 
42 } // namespace helper
43 } // namespace fwGdcmIO
44 
#define SPTR(_cls_)
The namespace fwGdcmIO contains reader, writer and helper for dicom data.
static FWGDCMIO_API void write(const ::boost::filesystem::path &filename, const std::shared_ptr< ::gdcm::Writer > &writer)
Write a file from the dataset.
Definition: FileWriter.cpp:20