STIR 6.4.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
29START_NAMESPACE_STIR
30
32
35class InterfileImageInputFileFormat : public InputFileFormat<DiscretisedDensity<3, float>>
36{
37public:
38 const std::string get_name() const override { return "Interfile"; }
39
40protected:
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};
66END_NAMESPACE_STIR
67
68#endif
defines the stir::DiscretisedDensity class
Declaration of class stir::InputFileFormat.
defines the stir::VoxelsOnCartesianGrid class
A class to read/store the file signature.
Definition FileSignature.h:35
const char * get_signature() const
get access to the signature
Definition FileSignature.h:52
Base-class for file-formats for reading.
Definition InputFileFormat.h:40
Class for reading images in Interfile file-format.
Definition InterfileImageInputFileFormat.h:36
unique_ptr< data_type > read_from_file(std::istream &input) const override
read data from a stream
Definition InterfileImageInputFileFormat.h:47
unique_ptr< data_type > read_from_file(const std::string &filename) const override
read data from a filename
Definition InterfileImageInputFileFormat.h:56
Declaration of stir::error()
bool is_interfile_signature(const char *const signature)
Checks if the signature corresponds to the start of an interfile header.
Definition interfile.cxx:77
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:126
void error(const char *const s,...)
Print error with format string a la printf and throw exception.
Definition error.cxx:42
Declarations of functions which read/write Interfile data.
Definition of stir::is_null_ptr functions.
This file declares various utility functions.