STIR  6.2.0
MultiDynamicDiscretisedDensityInputFileFormat.h
Go to the documentation of this file.
1 //
2 //
3 #ifndef __stir_IO_MultiDynamicDiscretisedDensityInputFileFormat_h__
4 #define __stir_IO_MultiDynamicDiscretisedDensityInputFileFormat_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,2020, 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"
31 #include <boost/format.hpp>
32 
33 START_NAMESPACE_STIR
34 
36 
39 class MultiDynamicDiscretisedDensityInputFileFormat : public InputFileFormat<DynamicDiscretisedDensity>
40 {
41 public:
42  const std::string get_name() const override { return "Multi"; }
43 
44 protected:
45  bool actual_can_read(const FileSignature& signature, std::istream&) const override
46  {
47  //. todo should check if it's an image
48  // checking for "multi :"
49  const char* pos_of_colon = strchr(signature.get_signature(), ':');
50  if (pos_of_colon == NULL)
51  return false;
52  std::string keyword(signature.get_signature(), pos_of_colon - signature.get_signature());
54  }
55 
56  unique_ptr<data_type> read_from_file(std::istream&) const override
57  {
58  // needs more arguments, so we just give up (TODO?)
59  unique_ptr<data_type> ret;
60  if (is_null_ptr(ret))
61  {
62  error("failed to read an Multi image from stream");
63  }
64  return ret;
65  }
66  unique_ptr<data_type> read_from_file(const std::string& filename) const override
67  {
68  MultipleDataSetHeader header;
69  if (header.parse(filename.c_str()) == false)
70  error("MultiDynamicDiscretisedDensity:::read_from_file: Error parsing %s", filename.c_str());
72  dyn_disc_den_ptr->set_num_densities(header.get_num_data_sets());
73  ExamInfo exam_info;
74  for (std::size_t i = 1U; i <= header.get_num_data_sets(); ++i)
75  {
76  unique_ptr<DiscretisedDensity<3, float>> t(DiscretisedDensity<3, float>::read_from_file(header.get_filename(i - 1)));
77 
78  // Check that there is time frame information
79  if (t->get_exam_info().get_time_frame_definitions().get_num_frames() != 1)
80  error(str(boost::format(
81  "The individual components of a dynamic image should contain 1 time frame, but image %1% contains %2%.")
82  % i % t->get_exam_info().get_time_frame_definitions().get_num_frames()));
83  double start = t->get_exam_info().get_time_frame_definitions().get_start_time(1);
84  double end = t->get_exam_info().get_time_frame_definitions().get_end_time(1);
85  // Set some info on the first frame
86  if (i == 1)
87  {
88  exam_info = t->get_exam_info();
89  exam_info.time_frame_definitions.set_num_time_frames(header.get_num_data_sets());
90  shared_ptr<Scanner> scanner_sptr(Scanner::get_scanner_from_name(exam_info.originating_system));
91  dyn_disc_den_ptr->set_scanner(*scanner_sptr);
92  }
93  exam_info.time_frame_definitions.set_time_frame(i, start, end);
94  dyn_disc_den_ptr->set_exam_info(exam_info); // need to update time-frame-info before calling set_density
95  dyn_disc_den_ptr->set_density(*t, i);
96  }
97  // Hard wire some stuff for now (TODO?)
98  dyn_disc_den_ptr->set_if_decay_corrected(1.);
99 
100  return unique_ptr<data_type>(dyn_disc_den_ptr);
101  }
102 };
103 END_NAMESPACE_STIR
104 
105 #endif
A class to read/store the file signature.
Definition: FileSignature.h:34
This file declares various utility functions.
Declaration of class stir::InputFileFormat.
unique_ptr< data_type > read_from_file(const std::string &filename) const override
read data from a filename
Definition: MultiDynamicDiscretisedDensityInputFileFormat.h:66
Declarations of functions which read/write Interfile data.
void set_time_frame(const int frame_num, const double start, const double end)
Set time frame.
Definition: TimeFrameDefinitions.cxx:256
defines the stir::DiscretisedDensity class
Declaration of stir::error()
Declaration of class stir::DynamicDiscretisedDensity.
const char * get_signature() const
get access to the signature
Definition: FileSignature.h:52
Class of multiple image frames, one for each time frame Each time frame is a DiscretisedDensity<3,float>
Definition: DynamicDiscretisedDensity.h:45
Base-class for file-formats for reading.
Definition: InputFileFormat.h:39
unique_ptr< data_type > read_from_file(std::istream &) const override
read data from a stream
Definition: MultiDynamicDiscretisedDensityInputFileFormat.h:56
Definition of stir::is_null_ptr functions.
string standardise_interfile_keyword(const string &keyword)
Put a (Interfile) keyword into a standard form.
Definition: interfile_keyword_functions.cxx:28
Declaration of class stir::MultipleDataSetHeader.
void error(const char *const s,...)
Print error with format string a la printf and throw exception.
Definition: error.cxx:42
a class for storing information about 1 exam (or scan)
Definition: ExamInfo.h:41
void set_num_time_frames(int num_time_frames)
Set number of time frames.
Definition: TimeFrameDefinitions.h:98
Class for reading images in Multi file-format.
Definition: MultiDynamicDiscretisedDensityInputFileFormat.h:39
This abstract class is the basis for all image representations.
Definition: FBP2DReconstruction.h:35