STIR  6.2.0
MultiParametricDiscretisedDensityInputFileFormat.h
Go to the documentation of this file.
1 //
2 //
3 #ifndef __stir_IO_MultiParametricDiscretisedDensityInputFileFormat_h__
4 #define __stir_IO_MultiParametricDiscretisedDensityInputFileFormat_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/read_from_file.h"
25 #include "stir/utilities.h"
27 #include "stir/error.h"
28 #include "stir/is_null_ptr.h"
32 #include <boost/format.hpp>
33 
34 START_NAMESPACE_STIR
35 
37 
40 class MultiParametricDiscretisedDensityInputFileFormat : public InputFileFormat<ParametricVoxelsOnCartesianGrid>
41 {
42 public:
43  const std::string get_name() const override { return "Multi"; }
44 
45 protected:
46  bool actual_can_read(const FileSignature& signature, std::istream&) const override
47  {
48  //. todo should check if it's an image
49  // checking for "multi :"
50  const char* pos_of_colon = strchr(signature.get_signature(), ':');
51  if (pos_of_colon == NULL)
52  return false;
53  std::string keyword(signature.get_signature(), pos_of_colon - signature.get_signature());
55  }
56 
57  unique_ptr<data_type> read_from_file(std::istream&) const override
58  {
59  // needs more arguments, so we just give up (TODO?)
60  unique_ptr<data_type> ret;
61  if (is_null_ptr(ret))
62  {
63  error("failed to read a Multi image from stream");
64  }
65  return ret;
66  }
67  unique_ptr<data_type> read_from_file(const std::string& filename) const override
68  {
69  MultipleDataSetHeader header;
70  if (header.parse(filename.c_str()) == false)
71  error("MultiParametricDiscretisedDensity:::read_from_file: Error parsing \"" + filename + '\"');
72  if (header.get_num_data_sets() != ParametricVoxelsOnCartesianGrid::get_num_params())
73  error("MultiParametricDiscretisedDensity:::read_from_file: "
74  "wrong number of images found in \""
75  + filename
76  + "\"\n"
77  "(expected "
78  + std::to_string(ParametricVoxelsOnCartesianGrid::get_num_params()) + ")");
79 
80  using SingleDiscretisedDensityType = ParametricVoxelsOnCartesianGrid::SingleDiscretisedDensityType;
81  auto t = stir::read_from_file<SingleDiscretisedDensityType>(header.get_filename(0));
83  par_disc_den_ptr->update_parametric_image(*t, 1);
84  for (std::size_t i = 2; i <= header.get_num_data_sets(); ++i)
85  {
86  t = stir::read_from_file<SingleDiscretisedDensityType>(header.get_filename(i - 1));
87  // TODO should check all time-frame info consistent
88  // exam_info.get_time_frame_definitions TODO.set_time_frame(i, start, end);
89  par_disc_den_ptr->update_parametric_image(*t, i);
90  }
91 
92  return unique_ptr<data_type>(par_disc_den_ptr);
93  }
94 };
95 END_NAMESPACE_STIR
96 
97 #endif
A class to read/store the file signature.
Definition: FileSignature.h:34
unique_ptr< data_type > read_from_file(std::istream &) const override
read data from a stream
Definition: MultiParametricDiscretisedDensityInputFileFormat.h:57
This file declares various utility functions.
Declaration of class stir::InputFileFormat.
Class to store parametric images.
Definition: ECAT7ParametricDensityOutputFileFormat.h:36
unique_ptr< data_type > read_from_file(const std::string &filename) const override
read data from a filename
Definition: MultiParametricDiscretisedDensityInputFileFormat.h:67
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.
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::ParametricDiscretisedDensity.
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
Class for reading images in Multi file-format.
Definition: MultiParametricDiscretisedDensityInputFileFormat.h:40
defines the stir::VoxelsOnCartesianGrid class
Declaration of stir::read_from_file functions (providing easy access to class stir::InputFileFormatRe...
ParametricDiscretisedDensity< ParametricVoxelsOnCartesianGridBaseType > ParametricVoxelsOnCartesianGrid
Convenience typedef for Cartesian Voxelised Parametric Images with just two parameters.
Definition: ParametricDiscretisedDensity.h:172