46 template <
typename ValueType>
class Image;
54 Axis () noexcept : size (1), spacing (std::numeric_limits<default_type>::quiet_NaN()), stride (0) { }
69 axes_ (std::move (
H.axes_)),
71 name_ (std::move (
H.name_)),
74 io (std::move (
H.io)),
82 axes_ = std::move (
H.axes_);
84 name_ = std::move (
H.name_);
87 io = std::move (
H.io);
106 offset_ (datatype().is_integer() ?
H.offset_ : 0.0),
107 scale_ (datatype().is_integer() ?
H.scale_ : 1.0),
114 Header (
const HeaderType& original) :
120 Header (
const HeaderType& original) :
122 name_ (original.name()),
125 datatype_ (DataType::from<typename HeaderType::value_type>()),
130 axes_.resize (original.ndim());
131 for (
size_t n = 0; n < original.ndim(); ++n) {
132 size(n) = original.size(n);
133 stride(n) = original.stride(n);
134 spacing(n) = original.spacing(n);
149 offset_ = datatype().is_integer() ?
H.offset_ : 0.0;
150 scale_ = datatype().is_integer() ?
H.scale_ : 1.0;
160 Header& operator= (
const HeaderType& original) {
161 return operator= (
static_cast<const Header&
> (original));
167 Header& operator= (
const HeaderType& original) {
168 axes_.resize (original.ndim());
169 for (
size_t n = 0; n < original.ndim(); ++n) {
170 size(n) = original.size(n);
171 stride(n) = original.stride(n);
172 spacing(n) = original.spacing(n);
175 name_ = original.name();
178 datatype_ = DataType::from<typename HeaderType::value_type>();
189 try {
io->close (*
this); }
196 bool valid ()
const {
return bool (
io); }
197 bool operator! ()
const {
return !valid(); }
200 const std::string& name ()
const {
return name_; }
202 std::string& name () {
return name_; }
205 const char* format ()
const {
return format_; }
213 void realignment (std::array<size_t, 3>& perm, std::array<bool, 3>& flip)
const { perm =
realign_perm_; flip =
realign_flip_; }
218 NDimProxy (NDimProxy&&) =
default;
219 NDimProxy (
const NDimProxy&) =
delete;
220 NDimProxy&
operator=(NDimProxy&&) =
delete;
221 NDimProxy&
operator=(
const NDimProxy&) =
delete;
223 operator size_t ()
const {
return axes.size(); }
224 size_t operator= (
size_t new_size) { axes.resize (new_size);
return new_size; }
225 friend std::ostream&
operator<< (std::ostream& stream,
const NDimProxy& proxy) {
226 stream << proxy.axes.size();
234 size_t ndim ()
const {
return axes_.size(); }
236 NDimProxy ndim () {
return {
axes_ }; }
239 const ssize_t& size (
size_t axis)
const;
241 ssize_t& size (
size_t axis);
249 const ssize_t& stride (
size_t axis)
const;
251 ssize_t& stride (
size_t axis);
256 DataTypeProxy (DataTypeProxy&&) =
default;
257 DataTypeProxy (
const DataTypeProxy&) =
delete;
258 DataTypeProxy& operator=(DataTypeProxy&&) =
delete;
259 DataTypeProxy& operator=(
const DataTypeProxy&) =
delete;
271 H.reset_intensity_scaling();
276 DataTypeProxy datatype () {
return { *
this }; }
297 if (!std::isfinite (scaling) || !std::isfinite (bias) || scaling == 0.0)
298 WARN (
"invalid scaling parameters (offset: " +
str(bias) +
", scale: " +
str(scaling) +
")");
303 void set_intensity_scaling (
const Header&
H) { set_intensity_scaling (
H.intensity_scale(),
H.intensity_offset()); }
305 void reset_intensity_scaling () { set_intensity_scaling (); }
307 bool is_file_backed ()
const {
return valid() ?
io->is_file_backed() :
false; }
311 DEBUG (
"sanitising image information...");
337 template <
typename ValueType>
345 void merge_keyval (
const Header&
H);
347 static Header open (
const std::string& image_name);
348 static Header create (
const std::string& image_name,
const Header& template_header,
bool add_to_command_history =
true);
349 static Header scratch (
const Header& template_header,
const std::string& label =
"scratch image");
353 static bool do_realign_transform;
356 std::string description (
bool print_all =
false)
const;
368 std::unique_ptr<ImageIO::Base>
io;
407 inline const ssize_t& Header::size (
size_t axis)
const {
return axes_[
axis].size; }
408 inline ssize_t& Header::size (
size_t axis) {
return axes_[
axis].size; }
413 inline const ssize_t& Header::stride (
size_t axis)
const {
return axes_[
axis].stride; }
414 inline ssize_t& Header::stride (
size_t axis) {
return axes_[
axis].stride; }
Array & operator=(const MR::Helper::ConstRow< ImageType > &row)
DataType & operator=(const DataType &) noexcept=default
void set_flag(uint8_t flag)
void set_byte_order_native()
void unset_flag(uint8_t flag)
uint8_t operator()() const
void display(int log_level=0) const
functions and classes related to image data input/output
VectorType::Scalar value(const VectorType &coefs, typename VectorType::Scalar cos_elevation, typename VectorType::Scalar cos_azimuth, typename VectorType::Scalar sin_azimuth, int lmax)
void actualise(HeaderType &header)
convert strides from symbolic to actual strides
void sanitise(HeaderType &header)
remove duplicate and invalid strides.
void set(HeaderType &header, const List &stride)
set the strides of header from a vector<ssize_t>
std::map< std::string, std::string > KeyValues
used in various places for storing key-value pairs
Header concatenate(const vector< Header > &headers, const size_t axis, const bool permit_datatype_mismatch)
double default_type
the default type used throughout MRtrix
std::string str(const T &value, int precision=0)
Eigen::Transform< default_type, 3, Eigen::AffineCompact > transform_type
the type for the affine transform of an image:
constexpr default_type NaN