[ismrmrd] 119/177: WIP C++ API changes.
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Wed Jan 14 20:02:09 UTC 2015
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to annotated tag v1.1.0.beta.1
in repository ismrmrd.
commit fa32dd5202087e800aa555b4a1923be01210fbde
Author: Souheil Inati <souheil.inati at nih.gov>
Date: Tue Sep 30 11:58:20 2014 -0400
WIP C++ API changes.
---
include/ismrmrd/dataset.h | 4 +-
include/ismrmrd/ismrmrd.h | 174 ++++++++++++----
libsrc/dataset.cpp | 15 +-
libsrc/ismrmrd.cpp | 425 ++++++++++++++++++++++++++++++---------
utilities/recon_cartesian_2d.cpp | 23 +--
5 files changed, 489 insertions(+), 152 deletions(-)
diff --git a/include/ismrmrd/dataset.h b/include/ismrmrd/dataset.h
index e96b2a8..174abd1 100644
--- a/include/ismrmrd/dataset.h
+++ b/include/ismrmrd/dataset.h
@@ -171,9 +171,9 @@ public:
int readAcquisition(uint32_t index, Acquisition &acq);
uint32_t getNumberOfAcquisitions();
// Images
- int appendImage(const std::string &var, const ISMRMRD_BlockModes blockmode, const Image &im);
+ template <typename T> int appendImage(const std::string &var, const ISMRMRD_BlockModes blockmode, const Image<T> &im);
int appendImage(const std::string &var, const ISMRMRD_BlockModes blockmode, const ISMRMRD_Image *im);
- int readImage(const std::string &var, uint32_t index, Image &im);
+ template <typename T> int readImage(const std::string &var, uint32_t index, Image<T> &im);
uint32_t getNumberOfImages(const std::string &var);
// NDArrays
template <typename T> int appendNDArray(const std::string &var, const ISMRMRD_BlockModes blockmode, const NDArray<T> &arr);
diff --git a/include/ismrmrd/ismrmrd.h b/include/ismrmrd/ismrmrd.h
index 58a73c9..f05849e 100644
--- a/include/ismrmrd/ismrmrd.h
+++ b/include/ismrmrd/ismrmrd.h
@@ -546,58 +546,148 @@ public:
};
/// MR Image type
-class EXPORTISMRMRD Image : protected ISMRMRD_Image {
+template <typename T> class EXPORTISMRMRD Image : protected ISMRMRD_Image {
public:
// Constructors
- Image();
+ Image(uint16_t matrix_size_x = 0, uint16_t matrix_size_y = 1,
+ uint16_t matrix_size_z = 1, uint16_t channels = 1);
Image(const Image &other);
Image & operator= (const Image &other);
~Image();
- // Accessors and mutators
- const uint16_t &version();
- const uint16_t &data_type();
- void data_type(uint16_t dtype);
- const uint64_t &flags();
- uint32_t &measurement_uid();
- const uint16_t (&matrix_size())[3];
- void matrix_size(const uint16_t msize[3]);
- float (&field_of_view())[3];
- const uint16_t &channels();
- void channels(const uint16_t num_channels);
- float (&position())[3];
- float (&read_dir())[3];
- float (&phase_dir())[3];
- float (&slice_dir())[3];
- float (&patient_table_position())[3];
- uint16_t &average();
- uint16_t &slice();
- uint16_t &contrast();
- uint16_t &phase();
- uint16_t &repetition();
- uint16_t &set();
- uint32_t &acquisition_time_stamp();
- uint32_t (&physiology_time_stamp())[ISMRMRD_PHYS_STAMPS];
- uint16_t &image_type();
- uint16_t &image_index();
- uint16_t &image_series_index();
- int32_t (&user_int())[ISMRMRD_USER_INTS];
- float (&user_float())[ISMRMRD_USER_FLOATS];
- const uint32_t &attribute_string_len();
-
- // Header and data accessors
- ImageHeader &getHead();
- void setHead(const ImageHeader other);
- void getAttributeString(std::string &atrr);
- void setAttributeString(const std::string attr);
- void *getData();
- size_t getDataSize();
-
- // Flag methods
+ // Image dimensions
+ void resize(uint16_t matrix_size_x, uint16_t matrix_size_y, uint16_t matrix_size_z, uint16_t channels);
+ uint16_t getMatrixSizeX() const;
+ void setMatrixSizeX(uint16_t matrix_size_x);
+ uint16_t getMatrixSizeY() const;
+ void setMatrixSizeY(uint16_t matrix_size_y);
+ uint16_t getMatrixSizeZ() const;
+ void setMatrixSizeZ(uint16_t matrix_size_z);
+ uint16_t getNumberOfChannels() const;
+ void setNumberOfChannels(uint16_t channels);
+
+ // Field of view
+ void setFieldOfView(float fov_x, float fov_y, float fov_z);
+ float getFieldOfViewX() const;
+ void setFieldOfViewX(float f);
+ float getFieldOfViewY() const;
+ void setFieldOfViewY(float f);
+ float getFieldOfViewZ() const;
+ void setFieldOfViewZ(float f);
+
+ // Positions and orientations
+ void setPosition(float x, float y, float z);
+ float getPositionX() const;
+ void setPositionX(float x);
+ float getPositionY() const;
+ void setPositionY(float y);
+ float getPositionZ() const;
+ void setPositionZ(float z);
+
+ void setReadDirection(float x, float y, float z);
+ float getReadDirectionX() const;
+ void setReadDirectionX(float x);
+ float getReadDirectionY() const;
+ void setReadDirectionY(float y);
+ float getReadDirectionZ() const;
+ void setReadDirectionZ(float z);
+
+ void setPhaseDirection(float x, float y, float z);
+ float getPhaseDirectionX() const;
+ void setPhaseDirectionX(float x);
+ float getPhaseDirectionY() const;
+ void setPhaseDirectionY(float y);
+ float getPhaseDirectionZ() const;
+ void setPhaseDirectionZ(float z);
+
+ void setSliceDirection(float x, float y, float z);
+ float getSliceDirectionX() const;
+ void setSliceDirectionX(float x);
+ float getSliceDirectionY() const;
+ void setSliceDirectionY(float y);
+ float getSliceDirectionZ() const;
+ void setSliceDirectionZ(float z);
+
+ void setPatientTablePosition(float x, float y, float z);
+ float getPatientTablePositionX() const;
+ void setPatientTablePositionX(float x);
+ float getPatientTablePositionY() const;
+ void setPatientTablePositionY(float y);
+ float getPatientTablePositionZ() const;
+ void setPatientTablePositionZ(float z);
+
+
+ // Attributes
+ const uint16_t getVersion() const;
+ const uint16_t getDataType() const;
+
+ // Counters and labels
+ uint32_t getMeasurementUid() const;
+ void setMeasurementUid(uint32_t measurement_uid);
+
+ uint16_t getAverage() const;
+ void setAverage(uint16_t average);
+
+ uint16_t getSlice() const;
+ void setSlice(uint16_t slice);
+
+ uint16_t getContrast() const;
+ void setContrast(uint16_t contrast);
+
+ uint16_t getPhase() const;
+ void setPhase(uint16_t phase);
+
+ uint16_t getRepetition() const;
+ void setRepetition(uint16_t repetition);
+
+ uint16_t getSet() const;
+ void setSet(uint16_t set);
+
+ uint32_t getAcquisitionTimeStamp() const;
+ void setAcquisitionTimeStamp(uint32_t acquisition_time_stamp);
+
+ uint32_t getPhysiologyTimeStamp(unsigned int stamp_id) const;
+ void setPhysiologyTimeStamp(unsigned int stamp_id, uint32_t value);
+
+ uint16_t getImageType() const;
+ void setImageType(uint16_t image_type);
+
+ uint16_t getImageIndex() const;
+ void setImageIndex(uint16_t image_index);
+
+ uint16_t getImageSeriesIndex() const;
+ void setImageSeriesIndex(uint16_t image_series_index);
+
+ // User parameters
+ float getUserFloat(unsigned int index) const;
+ void setUserFloat(unsigned int index, float value);
+
+ int32_t getUserInt(unsigned int index) const;
+ void setUserInt(unsigned int index, int32_t value);
+
+ // Flags
+ uint64_t getFlags() const;
+ void setFlags(const uint64_t flags);
bool isFlagSet(const uint64_t val);
void setFlag(const uint64_t val);
void clearFlag(const uint64_t val);
void clearAllFlags();
+
+ // Header
+ const ImageHeader & getHead() const;
+ void setHead(const ImageHeader& head);
+
+ // Attribute string
+ char const * getAttributString() const;
+ void setAttributString(const char * attr);
+ void getAttributeString(std::string &atrr) const;
+ void setAttributeString(const std::string attr);
+ const size_t getAttributeStringLength();
+
+ // Data
+ T * const getData() const;
+ const size_t getNumberOfDataElements() const;
+ const size_t getDataSize() const;
};
/// N-Dimensional array type
diff --git a/libsrc/dataset.cpp b/libsrc/dataset.cpp
index 7ff576c..2eda672 100644
--- a/libsrc/dataset.cpp
+++ b/libsrc/dataset.cpp
@@ -68,7 +68,7 @@ uint32_t Dataset::getNumberOfAcquisitions()
}
// Images
-int Dataset::appendImage(const std::string &var, const ISMRMRD_BlockModes blockmode, const Image &im)
+template <typename T>int Dataset::appendImage(const std::string &var, const ISMRMRD_BlockModes blockmode, const Image<T> &im)
{
int status = ismrmrd_append_image(&dset_, var.c_str(), blockmode, reinterpret_cast<const ISMRMRD_Image*>(&im));
if (status != ISMRMRD_NOERROR) {
@@ -85,8 +85,18 @@ int Dataset::appendImage(const std::string &var, const ISMRMRD_BlockModes blockm
}
return status;
}
+// Specific instantiations
+template EXPORTISMRMRD int Dataset::appendImage(const std::string &var, const ISMRMRD_BlockModes blockmode, const Image<uint16_t> &im);
+template EXPORTISMRMRD int Dataset::appendImage(const std::string &var, const ISMRMRD_BlockModes blockmode, const Image<int16_t> &im);
+template EXPORTISMRMRD int Dataset::appendImage(const std::string &var, const ISMRMRD_BlockModes blockmode, const Image<uint32_t> &im);
+template EXPORTISMRMRD int Dataset::appendImage(const std::string &var, const ISMRMRD_BlockModes blockmode, const Image<int32_t> &im);
+template EXPORTISMRMRD int Dataset::appendImage(const std::string &var, const ISMRMRD_BlockModes blockmode, const Image<float> &im);
+template EXPORTISMRMRD int Dataset::appendImage(const std::string &var, const ISMRMRD_BlockModes blockmode, const Image<double> &im);
+template EXPORTISMRMRD int Dataset::appendImage(const std::string &var, const ISMRMRD_BlockModes blockmode, const Image<complex_float_t> &im);
+template EXPORTISMRMRD int Dataset::appendImage(const std::string &var, const ISMRMRD_BlockModes blockmode, const Image<complex_double_t> &im);
+
-int Dataset::readImage(const std::string &var, uint32_t index, Image &im) {
+template <typename T> int Dataset::readImage(const std::string &var, uint32_t index, Image<T> &im) {
int status = ismrmrd_read_image(&dset_, var.c_str(), index, reinterpret_cast<ISMRMRD_Image*>(&im));
if (status != ISMRMRD_NOERROR) {
//TODO throw an exception
@@ -110,6 +120,7 @@ template <typename T> int Dataset::appendNDArray(const std::string &var, const I
}
return status;
}
+
// Specific instantiations
template EXPORTISMRMRD int Dataset::appendNDArray(const std::string &var, const ISMRMRD_BlockModes blockmode, const NDArray<uint16_t> &arr);
template EXPORTISMRMRD int Dataset::appendNDArray(const std::string &var, const ISMRMRD_BlockModes blockmode, const NDArray<int16_t> &arr);
diff --git a/libsrc/ismrmrd.cpp b/libsrc/ismrmrd.cpp
index 337e2ef..eb48d66 100644
--- a/libsrc/ismrmrd.cpp
+++ b/libsrc/ismrmrd.cpp
@@ -250,11 +250,15 @@ void ImageHeader::clearAllFlags() {
//
// Constructors
-template <typename T> Image<T>::Image()
+template <typename T> Image<T>::Image(uint16_t matrix_size_x,
+ uint16_t matrix_size_y,
+ uint16_t matrix_size_z,
+ uint16_t channels)
{
ismrmrd_init_image(this);
- data_type = get_data_type<T>();
-};
+ this->head.data_type = get_data_type<T>();
+ this->resize(matrix_size_x, matrix_size_y, matrix_size_z, channels);
+}
template <typename T> Image<T>::Image(const Image<T> &other) {
// This is a deep copy
@@ -277,83 +281,321 @@ template <typename T> Image<T>::~Image() {
ismrmrd_cleanup_image(this);
}
-// Accessors and mutators
-template <typename T> const uint16_t & Image<T>::version() {
- return head.version;
-};
+// Image dimensions
+template <typename T> void Image<T>::resize(uint16_t matrix_size_x,
+ uint16_t matrix_size_y,
+ uint16_t matrix_size_z,
+ uint16_t channels)
+{
+ // TODO what if matrix_size_x = 0?
+ if (matrix_size_y == 0) {
+ matrix_size_y = 1;
+ }
+ if (matrix_size_z == 0) {
+ matrix_size_z = 1;
+ }
+ if (channels == 0) {
+ channels = 1;
+ }
+
+ this->head.matrix_size[0] = matrix_size_x;
+ this->head.matrix_size[1] = matrix_size_y;
+ this->head.matrix_size[2] = matrix_size_z;
+ this->head.channels = channels;
+ ismrmrd_make_consistent_image(this);
+}
-template <typename T> const uint16_t &Image<T>::data_type() {
- return head.data_type;
-};
+template <typename T> uint16_t Image<T>::getMatrixSizeX() const
+{
+ return this->head.matrix_size[0];
+}
-template <typename T> void Image<T>::data_type(uint16_t dtype) {
- // TODO function to check if type is valid
- head.data_type = dtype;
- ismrmrd_make_consistent_image(this);
-};
+template <typename T> void Image<T>::setMatrixSizeX(uint16_t matrix_size_x)
+{
+ // TODO what if matrix_size_x = 0?
+ this->head.matrix_size[0] = matrix_size_x;
+ ismrmrd_make_consistent_image(this);
+}
-template <typename T> const uint64_t &Image<T>::flags() {
- return head.flags;
-};
+template <typename T> uint16_t Image<T>::getMatrixSizeY() const
+{
+ return this->head.matrix_size[1];
+}
-template <typename T> uint32_t &Image<T>::measurement_uid() {
- return head.measurement_uid;
-};
+template <typename T> void Image<T>::setMatrixSizeY(uint16_t matrix_size_y)
+{
+ if (matrix_size_y == 0) {
+ matrix_size_y = 1;
+ }
+ this->head.matrix_size[1] = matrix_size_y;
+ ismrmrd_make_consistent_image(this);
+}
-template <typename T> const uint16_t (&Image<T>::matrix_size())[3] {
- return head.matrix_size;
-};
+template <typename T> uint16_t Image<T>::getMatrixSizeZ() const
+{
+ return this->head.matrix_size[2];
+}
-template <typename T> void Image<T>::matrix_size(const uint16_t msize[3]) {
- head.matrix_size[0] = msize[0];
- if (msize[1] > 1) {
- head.matrix_size[1] = msize[1];
- } else {
- head.matrix_size[1] = 1;
+template <typename T> void Image<T>::setMatrixSizeZ(uint16_t matrix_size_z)
+{
+ if (matrix_size_z == 0) {
+ matrix_size_z = 1;
}
- if (msize[2] > 0) {
- head.matrix_size[2] = msize[2];
- } else {
- head.matrix_size[2] = 1;
+ this->head.matrix_size[2] = matrix_size_z;
+ ismrmrd_make_consistent_image(this);
+}
+
+template <typename T> uint16_t Image<T>::getNumberOfChannels() const
+{
+ return this->head.channels;
+}
+
+template <typename T> void Image<T>::setNumberOfChannels(uint16_t channels)
+{
+ if (channels == 0) {
+ channels = 1;
}
- ismrmrd_make_consistent_image(this);
-};
+ this->head.channels = channels;
+ ismrmrd_make_consistent_image(this);
+}
-template <typename T> float (&Image<T>::field_of_view())[3] {
- return head.field_of_view;
-};
-template <typename T> const uint16_t &Image<T>::channels() {
- return head.channels;
-};
+template <typename T> void Image<T>::setFieldOfView(float fov_x, float fov_y, float fov_z)
+{
+ this->head.field_of_view[0] = fov_x;
+ this->head.field_of_view[1] = fov_y;
+ this->head.field_of_view[2] = fov_z;
+}
-template <typename T> void Image<T>::channels(const uint16_t num_channels) {
- if (num_channels > 1) {
- head.channels = num_channels;
- } else {
- head.channels = 1;
- }
- ismrmrd_make_consistent_image(this);
-};
+template <typename T> void Image<T>::setFieldOfViewX(float fov_x)
+{
+ this->head.field_of_view[0] = fov_x;
+}
-template <typename T> float (&Image<T>::position())[3] {
- return head.position;
-};
+template <typename T> float Image<T>::getFieldOfViewX() const
+{
+ return this->head.field_of_view[0];
+}
-template <typename T> float (&Image<T>::read_dir())[3] {
- return head.read_dir;
-};
+template <typename T> void Image<T>::setFieldOfViewY(float fov_y)
+{
+ this->head.field_of_view[1] = fov_y;
+}
-template <typename T> float (&Image<T>::phase_dir())[3] {
- return head.phase_dir;
-};
+template <typename T> float Image<T>::getFieldOfViewY() const
+{
+ return this->head.field_of_view[1];
+}
-template <typename T> float (&Image<T>::slice_dir())[3] {
- return head.slice_dir;
+template <typename T> void Image<T>::setFieldOfViewZ(float fov_z)
+{
+ this->head.field_of_view[2] = fov_z;
+}
+
+template <typename T> float Image<T>::getFieldOfViewZ() const
+{
+ return this->head.field_of_view[2];
+}
+
+
+// Positions and orientations
+template <typename T> void Image<T>::setPosition(float x, float y, float z)
+{
+ this->head.position[0] = x;
+ this->head.position[1] = y;
+ this->head.position[2] = z;
+}
+
+template <typename T> float Image<T>::getPositionX() const
+{
+ return this->head.position[0];
+}
+
+template <typename T> void Image<T>::setPositionX(float x)
+{
+ this->head.position[0] = x;
+}
+
+template <typename T> float Image<T>::getPositionY() const
+{
+ return this->head.position[1];
+}
+
+template <typename T> void Image<T>::setPositionY(float y)
+{
+ this->head.position[1] = y;
+}
+
+template <typename T> float Image<T>::getPositionZ() const
+{
+ return this->head.position[2];
+}
+
+template <typename T> void Image<T>::setPositionZ(float z)
+{
+ this->head.position[2] = z;
+}
+
+
+template <typename T> void Image<T>::setReadDirection(float x, float y, float z)
+{
+ this->head.read_dir[0] = x;
+ this->head.read_dir[1] = y;
+ this->head.read_dir[2] = z;
+}
+
+template <typename T> float Image<T>::getReadDirectionX() const
+{
+ return this->head.read_dir[0];
+}
+
+template <typename T> void Image<T>::setReadDirectionX(float x)
+{
+ this->head.read_dir[0] = x;
+}
+
+template <typename T> float Image<T>::getReadDirectionY() const
+{
+ return this->head.read_dir[1];
+}
+
+template <typename T> void Image<T>::setReadDirectionY(float y)
+{
+ this->head.read_dir[1] = y;
+}
+
+template <typename T> float Image<T>::getReadDirectionZ() const
+{
+ return this->head.read_dir[2];
+}
+
+template <typename T> void Image<T>::setReadDirectionZ(float z)
+{
+ this->head.read_dir[2] = z;
+}
+
+
+template <typename T> void Image<T>::setPhaseDirection(float x, float y, float z)
+{
+ this->head.phase_dir[0] = x;
+ this->head.phase_dir[1] = y;
+ this->head.phase_dir[2] = z;
+}
+
+template <typename T> float Image<T>::getPhaseDirectionX() const
+{
+ return this->head.phase_dir[0];
+}
+
+template <typename T> void Image<T>::setPhaseDirectionX(float x)
+{
+ this->head.phase_dir[0] = x;
+}
+
+template <typename T> float Image<T>::getPhaseDirectionY() const
+{
+ return this->head.phase_dir[1];
+}
+
+template <typename T> void Image<T>::setPhaseDirectionY(float y)
+{
+ this->head.phase_dir[1] = y;
+}
+
+template <typename T> float Image<T>::getPhaseDirectionZ() const
+{
+ return this->head.phase_dir[2];
+}
+
+template <typename T> void Image<T>::setPhaseDirectionZ(float z)
+{
+ this->head.phase_dir[2] = z;
+}
+
+template <typename T> void Image<T>::setSliceDirection(float x, float y, float z)
+{
+ this->head.slice_dir[0] = x;
+ this->head.slice_dir[1] = y;
+ this->head.slice_dir[2] = z;
+}
+
+template <typename T> float Image<T>::getSliceDirectionX() const
+{
+ return this->head.slice_dir[0];
+}
+
+template <typename T> void Image<T>::setSliceDirectionX(float x)
+{
+ this->head.slice_dir[0] = x;
+}
+
+template <typename T> float Image<T>::getSliceDirectionY() const
+{
+ return this->head.slice_dir[1];
+}
+
+template <typename T> void Image<T>::setSliceDirectionY(float y)
+{
+ this->head.slice_dir[1] = y;
+}
+
+template <typename T> float Image<T>::getSliceDirectionZ() const
+{
+ return this->head.slice_dir[2];
+}
+
+template <typename T> void Image<T>::setSliceDirectionZ(float z)
+{
+ this->head.slice_dir[2] = z;
+}
+
+template <typename T> void Image<T>::setPatientTablePosition(float x, float y, float z)
+{
+ this->head.patient_table_position[0] = x;
+ this->head.patient_table_position[1] = y;
+ this->head.patient_table_position[2] = z;
+}
+
+template <typename T> float Image<T>::getPatientTablePositionX() const
+{
+ return this->head.patient_table_position[0];
+}
+
+template <typename T> void Image<T>::setPatientTablePositionX(float x)
+{
+ this->head.patient_table_position[0] = x;
+}
+
+template <typename T> float Image<T>::getPatientTablePositionY() const
+{
+ return this->head.patient_table_position[1];
+}
+
+template <typename T> void Image<T>::setPatientTablePositionY(float y)
+{
+ this->head.patient_table_position[1] = y;
+}
+
+template <typename T> float Image<T>::getPatientTablePositionZ() const
+{
+ return this->head.patient_table_position[2];
+}
+
+template <typename T> void Image<T>::setPatientTablePositionZ(float z)
+{
+ this->head.patient_table_position[2] = z;
+}
+
+
+#ifdef YOMAMA
+
+// Accessors and mutators
+template <typename T> const uint64_t &Image<T>::flags() {
+ return head.flags;
};
-template <typename T> float (&Image<T>::patient_table_position())[3] {
- return head.patient_table_position;
+template <typename T> uint32_t &Image<T>::measurement_uid() {
+ return head.measurement_uid;
};
template <typename T> uint16_t &Image<T>::average() {
@@ -368,96 +610,99 @@ template <typename T> uint16_t &Image<T>::contrast() {
return head.contrast;
};
-######YOU ARE HERE ########
-uint16_t &Image::phase() {
+template <typename T> uint16_t &Image<T>::phase() {
return head.repetition;
};
-uint16_t &Image::repetition() {
+template <typename T> uint16_t &Image<T>::repetition() {
return head.repetition;
};
-uint16_t &Image::set() {
+template <typename T> uint16_t &Image<T>::set() {
return head.set;
};
-uint32_t &Image::acquisition_time_stamp() {
+template <typename T> uint32_t &Image<T>::acquisition_time_stamp() {
return head.acquisition_time_stamp;
};
-uint32_t (&Image::physiology_time_stamp()) [ISMRMRD_PHYS_STAMPS] {
+template <typename T> uint32_t (&Image<T>::physiology_time_stamp()) [ISMRMRD_PHYS_STAMPS] {
return head.physiology_time_stamp;
};
-uint16_t &Image::image_type() {
+template <typename T> uint16_t &Image<T>::image_type() {
return head.image_type;
};
-uint16_t &Image::image_index() {
+template <typename T> uint16_t &Image<T>::image_index() {
return head.image_index;
};
-uint16_t &Image::image_series_index() {
+template <typename T> uint16_t &Image<T>::image_series_index() {
return head.image_series_index;
};
-int32_t (&Image::user_int()) [ISMRMRD_USER_INTS] {
+template <typename T> int32_t (&Image<T>::user_int()) [ISMRMRD_USER_INTS] {
return head.user_int;
};
-float (&Image::user_float()) [ISMRMRD_USER_FLOATS] {
+template <typename T> float (&Image<T>::user_float()) [ISMRMRD_USER_FLOATS] {
return head.user_float;
};
-const uint32_t &Image::attribute_string_len() {
+template <typename T> const uint32_t &Image<T>::attribute_string_len() {
return head.attribute_string_len;
};
// Header and data accessors
-ImageHeader &Image::getHead() {
+template <typename T> ImageHeader &Image<T>::getHead() {
// This returns a reference
return *static_cast<ImageHeader *>(&head);
}
-void Image::setHead(const ImageHeader other) {
+template <typename T> void Image::setHead<T>(const ImageHeader other) {
memcpy(&head, &other, sizeof(ImageHeader));
ismrmrd_make_consistent_image(this);
}
-void Image::setAttributeString(std::string attr) {
+template <typename T> void Image<T>::setAttributeString(std::string attr) {
head.attribute_string_len = attr.length();
attribute_string = (char *)realloc(attribute_string, attr.length()+1);
strcpy(attribute_string, attr.c_str());
}
-void Image::getAttributeString(std::string &attr) {
+template <typename T> void Image<T>::getAttributeString(std::string &attr) {
attr = std::string(attribute_string);
}
-void *Image::getData() {
- return data;
+template <typename T> T * const Image<T>::getData() {
+ return static_cast<T*>(data);
}
-size_t Image::getDataSize() {
+template <typename T> size_t Image<T>::getDataSize() {
return ismrmrd_size_of_image_data(this);
}
+#endif // YOMAMA
+
+
// Flag methods
-bool Image::isFlagSet(const uint64_t val) {
+template <typename T> bool Image<T>::isFlagSet(const uint64_t val) {
return ismrmrd_is_flag_set(head.flags, val);
-};
+}
-void Image::setFlag(const uint64_t val) {
+template <typename T> void Image<T>::setFlag(const uint64_t val) {
ismrmrd_set_flag(&(head.flags), val);
-};
+}
-void Image::clearFlag(const uint64_t val) {
+template <typename T> void Image<T>::clearFlag(const uint64_t val) {
ismrmrd_clear_flag(&(head.flags), val);
-};
+}
-void Image::clearAllFlags() {
+template <typename T> void Image<T>::clearAllFlags() {
ismrmrd_clear_all_flags(&(head.flags));
-};
+}
+
//
// Array class Implementation
diff --git a/utilities/recon_cartesian_2d.cpp b/utilities/recon_cartesian_2d.cpp
index f6b45d0..9dd7d79 100644
--- a/utilities/recon_cartesian_2d.cpp
+++ b/utilities/recon_cartesian_2d.cpp
@@ -116,31 +116,22 @@ int main(int argc, char** argv)
fftwf_free(tmp);
//Allocate an image
- ISMRMRD::Image img_out;
- img_out.data_type(ISMRMRD::ISMRMRD_FLOAT);
- uint16_t matrix_size[3];
- matrix_size[0] = r_space.matrixSize.x;
- matrix_size[1] = r_space.matrixSize.y;
- matrix_size[2] = 1;
- img_out.matrix_size(matrix_size);
- img_out.channels(1);
+ ISMRMRD::Image<float> img_out(r_space.matrixSize.x, r_space.matrixSize.y, 1, 1);
//f there is oversampling in the readout direction remove it
//Take the magnitude
size_t offset = ((e_space.matrixSize.x - r_space.matrixSize.x)>>1);
- for (unsigned int y = 0; y < matrix_size[1]; y++) {
- for (unsigned int x = 0; x < matrix_size[0]; x++) {
- static_cast<float*>(img_out.getData())[y*matrix_size[0]+x] =
+ for (unsigned int y = 0; y < r_space.matrixSize.y; y++) {
+ for (unsigned int x = 0; x < r_space.matrixSize.x; x++) {
+ static_cast<float*>(img_out.getData())[y*r_space.matrixSize.x+x] =
std::abs(buffer.getData()[y*dims[0] + x + offset]);
}
}
// The following are extra guidance we can put in the image header
- img_out.image_type() = ISMRMRD::ISMRMRD_IMTYPE_MAGNITUDE;
- img_out.slice() = 0;
- img_out.field_of_view()[0] = r_space.fieldOfView_mm.x;
- img_out.field_of_view()[1] = r_space.fieldOfView_mm.y;
- img_out.field_of_view()[2] = r_space.fieldOfView_mm.z;
+ img_out.setImageType(ISMRMRD::ISMRMRD_IMTYPE_MAGNITUDE);
+ img_out.setSlice(0);
+ img_out.setFieldOfView(r_space.fieldOfView_mm.x, r_space.fieldOfView_mm.y, r_space.fieldOfView_mm.z);
//And so on
//Let's write the reconstructed image into the same data file
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/ismrmrd.git
More information about the debian-science-commits
mailing list