STIR  6.2.0
InterfileImageInputFileFormat.h
Go to the documentation of this file.
1 //
2 //
3 #ifndef __stir_IO_InterfileImageInputFileFormat_h__
4 #define __stir_IO_InterfileImageInputFileFormat_h__
5 /*
6  Copyright (C) 2006 - 2007-10-08, Hammersmith Imanet Ltd
7  Copyright (C) 2013-01-01 - 2013, Kris Thielemans
8  This file is part of STIR.
9  SPDX-License-Identifier: Apache-2.0
10 
11  See STIR/LICENSE.txt for details
12 */
22 #include "stir/IO/interfile.h"
23 #include "stir/utilities.h"
26 #include "stir/error.h"
27 #include "stir/is_null_ptr.h"
28 
29 START_NAMESPACE_STIR
30 
32 
35 class InterfileImageInputFileFormat : public InputFileFormat<DiscretisedDensity<3, float>>
36 {
37 public:
38  const std::string get_name() const override { return "Interfile"; }
39 
40 protected:
41  bool actual_can_read(const FileSignature& signature, std::istream& input) const override
42  {
43  //. todo should check if it's an image
44  return is_interfile_signature(signature.get_signature());
45  }
46 
47  unique_ptr<data_type> read_from_file(std::istream& input) const override
48  {
49  unique_ptr<data_type> ret(read_interfile_image(input));
50  if (is_null_ptr(ret))
51  {
52  error("failed to read an Interfile image from stream");
53  }
54  return ret;
55  }
56  unique_ptr<data_type> read_from_file(const std::string& filename) const override
57  {
58  unique_ptr<data_type> ret(read_interfile_image(filename));
59  if (is_null_ptr(ret))
60  {
61  error("failed to read an Interfile image from file \"%s\"", filename.c_str());
62  }
63  return ret;
64  }
65 };
66 END_NAMESPACE_STIR
67 
68 #endif
bool is_interfile_signature(const char *const signature)
Checks if the signature corresponds to the start of an interfile header.
Definition: interfile.cxx:75
A class to read/store the file signature.
Definition: FileSignature.h:34
unique_ptr< data_type > read_from_file(const std::string &filename) const override
read data from a filename
Definition: InterfileImageInputFileFormat.h:56
This file declares various utility functions.
Declaration of class stir::InputFileFormat.
VoxelsOnCartesianGrid< float > * read_interfile_image(std::istream &input, const std::string &directory_for_data="")
This reads the first 3d image in an Interfile header file, given as a stream.
Definition: interfile.cxx:124
Declarations of functions which read/write Interfile data.
unique_ptr< data_type > read_from_file(std::istream &input) const override
read data from a stream
Definition: InterfileImageInputFileFormat.h:47
defines the stir::DiscretisedDensity class
Declaration of stir::error()
const char * get_signature() const
get access to the signature
Definition: FileSignature.h:52
Base-class for file-formats for reading.
Definition: InputFileFormat.h:39
Definition of stir::is_null_ptr functions.
Class for reading images in Interfile file-format.
Definition: InterfileImageInputFileFormat.h:35
void error(const char *const s,...)
Print error with format string a la printf and throw exception.
Definition: error.cxx:42
defines the stir::VoxelsOnCartesianGrid class