STIR  6.2.0
OutputFileFormat.h
Go to the documentation of this file.
1 //
2 //
3 /*
4  Copyright (C) 2003- 2007, Hammersmith Imanet Ltd
5  This file is part of STIR.
6  SPDX-License-Identifier: Apache-2.0
7 
8 
9  See STIR/LICENSE.txt for details
10 */
21 #ifndef __stir_IO_OutputFileFormat_H__
22 #define __stir_IO_OutputFileFormat_H__
23 
24 #include "stir/RegisteredObject.h"
25 #include "stir/NumericType.h"
26 #include "stir/ByteOrder.h"
27 #include <string>
28 
29 START_NAMESPACE_STIR
30 
31 class Succeeded;
32 
54 template <typename DataT>
55 class OutputFileFormat : public RegisteredObject<OutputFileFormat<DataT>>
56 {
57 public:
59  static shared_ptr<OutputFileFormat<DataT>> default_sptr();
60 
61  OutputFileFormat(const NumericType& = NumericType::FLOAT, const ByteOrder& = ByteOrder::native);
62 
64 
80  Succeeded write_to_file(std::string& filename, const DataT& data) const;
81 
83 
86  Succeeded write_to_file(const std::string& filename, const DataT& density) const;
87 
89  NumericType get_type_of_numbers() const;
91  ByteOrder get_byte_order();
93 
95  float get_scale_to_write_data() const;
96 
98 
103  virtual NumericType set_type_of_numbers(const NumericType&, const bool warn = false);
105 
110  virtual ByteOrder set_byte_order(const ByteOrder&, const bool warn = false);
112 
119  virtual void set_byte_order_and_type_of_numbers(ByteOrder&, NumericType&, const bool warn = false);
120 
122 
131  virtual float set_scale_to_write_data(const float new_scale_to_write_data, const bool warn = false);
132 
133 protected:
139 
142 
144 
152  virtual Succeeded actual_write_to_file(std::string& filename, const DataT& density) const = 0;
153 
154  // parsing stuff
155 
157 
158  void set_defaults() override;
160 
161  void initialise_keymap() override;
163 
164  bool post_processing() override;
166 
167  void set_key_values() override;
168 
169 private:
170  static shared_ptr<OutputFileFormat<DataT>> _default_sptr;
171  // Lists of possible values for some keywords
172  static ASCIIlist_type number_format_values;
173  static ASCIIlist_type byte_order_values;
174 
175  // Corresponding variables here
176 
177  int number_format_index;
178  int byte_order_index;
179  int bytes_per_pixel;
180 };
181 
182 END_NAMESPACE_STIR
183 
184 #endif
This file declares the stir::ByteOrder class.
NumericType type_of_numbers
type used for outputting numbers
Definition: OutputFileFormat.h:135
This class provides member functions to find out what byte-order your machine is and to swap numbers...
Definition: ByteOrder.h:99
float scale_to_write_data
scale to write the data
Definition: OutputFileFormat.h:141
std::string write_to_file(const std::string &filename, const DataT &data)
Function that writes data to file using the default OutputFileFormat.
Definition: write_to_file.h:47
Declaration of class stiir::RegisteredObject.
ByteOrder file_byte_order
byte order used for output
Definition: OutputFileFormat.h:137
Helper class to provide registry mechanisms to a Base classSuppose you have a hierarchy of classes wi...
Definition: RegisteredObject.h:95
provides names for some numeric types and methods for finding their properties.
Definition: NumericType.h:54
a class containing an enumeration type that can be used by functions to signal successful operation o...
Definition: Succeeded.h:43
Base class for classes that create output files.
Definition: OutputFileFormat.h:55
This file declares the stir::NumericType class.