STIR  6.2.0
InterfileDynamicDiscretisedDensityInputFileFormat.h
Go to the documentation of this file.
1 //
2 //
3 #ifndef __stir_IO_InterfileDynamicDiscretisedDensityInputFileFormat_h__
4 #define __stir_IO_InterfileDynamicDiscretisedDensityInputFileFormat_h__
5 /*
6  Copyright (C) 2006 - 2007-10-08, Hammersmith Imanet Ltd
7  Copyright (C) 2013-01-01 - 2013, Kris Thielemans
8  Copyight (C) 2018, University College London
9  This file is part of STIR.
10  SPDX-License-Identifier: Apache-2.0
11 
12  See STIR/LICENSE.txt for details
13 */
24 #include "stir/IO/interfile.h"
25 #include "stir/utilities.h"
27 #include "stir/error.h"
28 #include "stir/is_null_ptr.h"
29 
30 START_NAMESPACE_STIR
31 
33 
36 class InterfileDynamicDiscretisedDensityInputFileFormat : public InputFileFormat<DynamicDiscretisedDensity>
37 {
38 public:
39  const std::string get_name() const override { return "Interfile"; }
40 
41 protected:
42  bool actual_can_read(const FileSignature& signature, std::istream&) const override
43  {
44  //. todo should check if it's an image
45  return is_interfile_signature(signature.get_signature());
46  }
47 
48  unique_ptr<data_type> read_from_file(std::istream&) const override
49  {
50  // needs more arguments, so we just give up (TODO?)
51  unique_ptr<data_type> ret; //(read_interfile_dynamic_image(input));
52  if (is_null_ptr(ret))
53  {
54  error("failed to read an Interfile image from stream");
55  }
56  return ret;
57  }
58  unique_ptr<data_type> read_from_file(const std::string& filename) const override
59  {
60  unique_ptr<data_type> ret(read_interfile_dynamic_image(filename));
61  if (is_null_ptr(ret))
62  {
63  error("failed to read an Interfile image from file \"%s\"", filename.c_str());
64  }
65  return ret;
66  }
67 };
68 END_NAMESPACE_STIR
69 
70 #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
This file declares various utility functions.
Declaration of class stir::InputFileFormat.
Declarations of functions which read/write Interfile data.
DynamicDiscretisedDensity * read_interfile_dynamic_image(std::istream &input, const std::string &directory_for_data)
Read dynamic image.
Definition: interfile.cxx:167
Declaration of stir::error()
Declaration of class stir::DynamicDiscretisedDensity.
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: InterfileDynamicDiscretisedDensityInputFileFormat.h:36
void error(const char *const s,...)
Print error with format string a la printf and throw exception.
Definition: error.cxx:42
unique_ptr< data_type > read_from_file(std::istream &) const override
read data from a stream
Definition: InterfileDynamicDiscretisedDensityInputFileFormat.h:48
unique_ptr< data_type > read_from_file(const std::string &filename) const override
read data from a filename
Definition: InterfileDynamicDiscretisedDensityInputFileFormat.h:58