STIR  6.2.0
ECAT6ImageInputFileFormat.h
Go to the documentation of this file.
1 #ifndef __stir_IO_ECAT6ImageInputFileFormat_h__
2 #define __stir_IO_ECAT6ImageInputFileFormat_h__
3 /*
4  Copyright (C) 2006, Hammersmith Imanet Ltd
5  Copyright (C) 2013, University College London
6  This file is part of STIR.
7  SPDX-License-Identifier: Apache-2.0
8 
9  See STIR/LICENSE.txt for details
10 */
19 #include "stir/utilities.h"
21 #include <fstream>
22 #include <string>
23 #include "stir/error.h"
24 #include "stir/IO/stir_ecat6.h"
25 #include "stir/IO/ecat6_utils.h"
26 #include "stir/deprecated.h"
27 START_NAMESPACE_STIR
28 START_NAMESPACE_ECAT
29 START_NAMESPACE_ECAT6
31 
35 class STIR_DEPRECATED ECAT6ImageInputFileFormat : public InputFileFormat<DiscretisedDensity<3, float>>
36 {
37 public:
38  virtual const std::string get_name() const { return "ECAT6"; }
39 
40 protected:
41  virtual bool actual_can_read(const FileSignature& signature, std::istream& input) const { return false; }
42 
43  bool can_read(const FileSignature& signature, std::istream& input) const
44  {
45  return false; // cannot read from istream
46  }
47 
48  bool can_read(const FileSignature&, const std::string& filename) const { return is_ECAT6_image_file(filename); }
49 
50  virtual unique_ptr<data_type> read_from_file(std::istream& input) const
51  {
52  // TODO
53  error("read_from_file for ECAT6 with istream not implemented %s:%d. Sorry", __FILE__, __LINE__);
54  return unique_ptr<data_type>();
55  }
56  virtual unique_ptr<data_type> read_from_file(const std::string& filename) const
57  {
58  if (is_ECAT6_image_file(filename))
59  {
60  ECAT6_Main_header mhead;
61  FILE* cti_fptr = fopen(filename.c_str(), "rb");
62  if (cti_read_ECAT6_Main_header(cti_fptr, &mhead) != EXIT_SUCCESS)
63  {
64  if (cti_fptr != NULL)
65  fclose(cti_fptr);
66  error("error reading main header in ECAT 6 file %s\n", filename.c_str());
67  }
68 
69  warning("\nReading frame 1, gate 1, data 0, bed 0 from file %s\n", filename.c_str());
71  = ECAT6_to_VoxelsOnCartesianGrid(/*frame_num, gate_num, data_num, bed_num*/ 1, 1, 0, 0, cti_fptr, mhead);
72  fclose(cti_fptr);
73  return unique_ptr<data_type>(tmp);
74  }
75  else
76  {
77  error("ECAT6ImageInputFileFormat: file '%s' does not look like an ECAT6 image.", filename.c_str());
78  // add return to avoid compiler warnings
79  return unique_ptr<data_type>();
80  }
81  }
82 };
83 
84 END_NAMESPACE_ECAT
85 END_NAMESPACE_ECAT6
86 END_NAMESPACE_STIR
87 
88 #endif
This class is used to represent voxelised densities on a cuboid grid (3D).
Definition: FBP3DRPReconstruction.h:43
#define STIR_DEPRECATED
Deprecation macro.
Definition: deprecated.h:19
int cti_read_ECAT6_Main_header(FILE *fptr, ECAT6_Main_header *h)
Read header data from a file and place it into a ECAT6_Main_header struct. Returns EXIT_SUCCESS if no...
Definition: ecat6_utils.cxx:290
A class to read/store the file signature.
Definition: FileSignature.h:34
This file declares various utility functions.
Declaration of class stir::InputFileFormat.
This file declares a deprecation macro.
Declaration of routines which convert ECAT6 things into our building blocks and vice versa...
Declaration of ECAT 6 CTI functions to access data.
Declaration of stir::error()
virtual unique_ptr< data_type > read_from_file(const std::string &filename) const
read data from a filename
Definition: ECAT6ImageInputFileFormat.h:56
virtual unique_ptr< data_type > read_from_file(std::istream &input) const
read data from a stream
Definition: ECAT6ImageInputFileFormat.h:50
Base-class for file-formats for reading.
Definition: InputFileFormat.h:39
Class for reading images in ECAT6 file-format.
Definition: ECAT6ImageInputFileFormat.h:35
void warning(const char *const s,...)
Print warning with format string a la printf.
Definition: warning.cxx:41
bool is_ECAT6_image_file(const std::string &filename)
checks if the file is in ECAT6 format and if the file contains images
Definition: stir_ecat6.cxx:140
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