[ismrmrd] 09/177: Added some Image functionality.

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Wed Jan 14 20:01:56 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 13ee8bf71b3e160cfb46e80e6402d77c50ef145c
Author: Souheil Inati <souheil.inati at nih.gov>
Date:   Tue Jul 22 14:38:44 2014 -0400

    Added some Image functionality.
---
 ismrmrd.c                | 161 ++++++++++++++---------
 ismrmrd.cpp              | 332 ++++++++++++++++++++++++++++++++++++++++++++---
 ismrmrd.h                |  39 +++---
 ismrmrd.hpp              | 167 ++++++++++++++++++++++--
 tests/c++/basic_test.cpp |  14 +-
 5 files changed, 592 insertions(+), 121 deletions(-)

diff --git a/ismrmrd.c b/ismrmrd.c
index 1a9a241..950c31f 100644
--- a/ismrmrd.c
+++ b/ismrmrd.c
@@ -1,6 +1,19 @@
+/* Language and Cross platform section for defining types */
+#ifdef __cplusplus
+#include <cstring>
+#include <cstdlib>
+#include <cmath>
+#else
+/* C99 compiler */
+#include <string.h>
+#include <stdlib.h>
+#include <math.h>
+#endif /* __cplusplus */
+
 #include "ismrmrd.h"
 
 #ifdef __cplusplus
+namespace ISMRMRD {
 extern "C" {
 #endif
 
@@ -18,35 +31,54 @@ void ismrmrd_init_acquisition(ISMRMRD_Acquisition *acq) {
     acq->data = NULL;
 }
 
-void ismrmrd_copy_acquisition(ISMRMRD_Acquisition *acqdest, const ISMRMRD_Acquisition *acqsource) {
-    memcpy(&(acqdest->head), &(acqsource->head), sizeof(ISMRMRD_AcquisitionHeader));
-    ismrmrd_make_consistent_acquisition(acqdest);
-    memcpy(&(acqdest->traj), &(acqsource->traj), acqdest->head.number_of_samples * acqdest->head.trajectory_dimensions * sizeof(acqdest->traj));
-    memcpy(&(acqdest->data), &(acqsource->data), acqdest->head.number_of_samples * acqdest->head.active_channels * sizeof(acqdest->data));
-}
-
 void ismrmrd_free_acquisition(ISMRMRD_Acquisition *acq) {
     free(acq->data);
     free(acq->traj);
     free(acq);
 }
 
+void ismrmrd_copy_acquisition(ISMRMRD_Acquisition *acqdest, const ISMRMRD_Acquisition *acqsource) {
+    memcpy(&(acqdest->head), &(acqsource->head), sizeof(ISMRMRD_AcquisitionHeader));
+    ismrmrd_make_consistent_acquisition(acqdest);
+    memcpy(&(acqdest->traj), &(acqsource->traj), ismrmrd_size_of_acquisition_traj(acqdest));
+    memcpy(&(acqdest->data), &(acqsource->data), ismrmrd_size_of_acquisition_data(acqdest));
+}
+
 void ismrmrd_make_consistent_acquisition(ISMRMRD_Acquisition *acq) {
     if (acq->head.available_channels < acq->head.active_channels) {
         acq->head.available_channels = acq->head.active_channels;
     }
 
+    size_t traj_size = ismrmrd_size_of_acquisition_traj(acq);
+    if (traj_size > 0) {
+        acq->traj = (float *)realloc(acq->traj, traj_size);
+    }
+
+    size_t data_size = ismrmrd_size_of_acquisition_data(acq);
+    if (data_size > 0) {
+        acq->data = (complex_float_t *)realloc(acq->data, data_size);
+    }
+}
+
+size_t ismrmrd_size_of_acquisition_traj(const ISMRMRD_Acquisition *acq) {
+    size_t traj_size = 0;
     int num_traj = acq->head.number_of_samples * acq->head.trajectory_dimensions;
     if (num_traj > 0) {
-        acq->traj = (float *)realloc(acq->traj, num_traj * sizeof(acq->traj));
+        traj_size = num_traj * sizeof(acq->traj);
     }
+    return traj_size;
+}
 
+size_t ismrmrd_size_of_acquisition_data(const ISMRMRD_Acquisition *acq) {
+    size_t data_size = 0;
     int num_data = acq->head.number_of_samples * acq->head.active_channels;
     if (num_data > 0) {
-        acq->data = (complex_float_t *)realloc(acq->data, num_data * sizeof(acq->data));
+        data_size = num_data * sizeof(acq->data);
     }
+    return data_size;
 }
 
+/* ImageHeader functions */
 void ismrmrd_init_image_header(ISMRMRD_ImageHeader *hdr) {
     memset(hdr, 0, sizeof(ISMRMRD_ImageHeader));
     hdr->version = ISMRMRD_VERSION;
@@ -56,6 +88,7 @@ void ismrmrd_init_image_header(ISMRMRD_ImageHeader *hdr) {
     hdr->channels = 1;
 }
 
+/* Image functions */
 void ismrmrd_init_image(ISMRMRD_Image *im) {
     ismrmrd_init_image_header(&(im->head));
     im->attribute_string = NULL;
@@ -68,8 +101,32 @@ void ismrmrd_free_image(ISMRMRD_Image *im) {
     free(im);
 }
 
-int ismrmrd_size_of_image_data(const ISMRMRD_Image *im) {
-    int data_size = 0;
+void ismrmrd_copy_image(ISMRMRD_Image *imdest, const ISMRMRD_Image *imsource) {
+    memcpy(&(imdest->head), &(imsource->head), sizeof(ISMRMRD_ImageHeader));
+    ismrmrd_make_consistent_image(imdest);
+    size_t attr_size = ismrmrd_size_of_image_attribute_string(imdest);
+    if (attr_size > 0) {
+        memcpy(&(imdest->attribute_string), &(imsource->attribute_string), attr_size);
+    }
+    size_t data_size = ismrmrd_size_of_image_data(imdest);
+    if (data_size > 0) {
+        memcpy(&(imdest->data), &(imsource->data), data_size);
+    }
+}
+
+void ismrmrd_make_consistent_image(ISMRMRD_Image *im) {
+    size_t attr_size = ismrmrd_size_of_image_attribute_string(im);
+    if (attr_size > 0) {
+        im->attribute_string = (char *)realloc(im->attribute_string, attr_size);
+    }
+    size_t data_size = ismrmrd_size_of_image_data(im);
+    if (data_size > 0) {
+        im->data = realloc(im->data, data_size);
+    }
+}
+
+size_t ismrmrd_size_of_image_data(const ISMRMRD_Image *im) {
+    size_t data_size = 0;
     int num_data = im->head.matrix_size[0] * im->head.matrix_size[1] * im->head.matrix_size[2] * im->head.channels;
     if (num_data > 0) {
         switch (im->head.data_type) {
@@ -102,38 +159,15 @@ int ismrmrd_size_of_image_data(const ISMRMRD_Image *im) {
     return data_size;
 }
 
-int ismrmrd_size_of_image_attribute_string(const ISMRMRD_Image *im) {
-    int attribute_string_size = 0;
+size_t ismrmrd_size_of_image_attribute_string(const ISMRMRD_Image *im) {
+    size_t attribute_string_size = 0;
     if (im->head.attribute_string_len > 0) {
         attribute_string_size = im->head.attribute_string_len * sizeof(im->attribute_string);
     }
     return attribute_string_size;
 }
 
-void ismrmrd_make_consistent_image(ISMRMRD_Image *im) {
-    int attr_size = ismrmrd_size_of_image_attribute_string(im);
-    if (attr_size > 0) {
-        im->attribute_string = (char *)realloc(im->attribute_string, attr_size);
-    }
-    int data_size = ismrmrd_size_of_image_data(im);
-    if (data_size > 0) {
-        im->data = realloc(im->data, data_size);
-    }
-}
-
-void ismrmrd_copy_image(ISMRMRD_Image *imdest, const ISMRMRD_Image *imsource) {
-    memcpy(&(imdest->head), &(imsource->head), sizeof(ISMRMRD_ImageHeader));
-    ismrmrd_make_consistent_image(imdest);
-    int attr_size = ismrmrd_size_of_image_attribute_string(imdest);
-    if (attr_size > 0) {
-        memcpy(&(imdest->attribute_string), &(imsource->attribute_string), attr_size);
-    }
-    int data_size = ismrmrd_size_of_image_data(imdest);
-    if (data_size > 0) {
-        memcpy(&(imdest->data), &(imsource->data), data_size);
-    }
-}
-
+/* NDArray functions */
 void ismrmrd_init_ndarray(ISMRMRD_NDArray *arr) {
     arr->version = ISMRMRD_VERSION;
     arr->data_type = 0; // no default data type
@@ -149,8 +183,29 @@ void ismrmrd_free_ndarray(ISMRMRD_NDArray *arr) {
     free(arr);
 }
 
-int ismrmrd_size_of_ndarray_data(const ISMRMRD_NDArray *arr) {
-    int data_size = 0;
+void ismrmrd_copy_ndarray(ISMRMRD_NDArray *arrdest, const ISMRMRD_NDArray *arrsource) {
+    arrdest->version = arrsource->version;
+    arrdest->data_type = arrsource->data_type;
+    arrdest->ndim = arrsource->ndim;
+    for (int n = 0; n < ISMRMRD_NDARRAY_MAXDIM; n++) {
+        arrdest->dims[n] = arrsource->dims[n];
+    }
+    ismrmrd_make_consistent_ndarray(arrdest);
+    size_t data_size = ismrmrd_size_of_ndarray_data(arrdest);
+    if (data_size > 0) {
+        memcpy(&(arrdest->data), &(arrsource->data), ismrmrd_size_of_ndarray_data(arrdest));
+    }
+}
+
+void ismrmrd_make_consistent_ndarray(ISMRMRD_NDArray *arr) {
+    size_t data_size = ismrmrd_size_of_ndarray_data(arr);
+    if (data_size > 0) {
+        arr->data = realloc(arr->data, data_size);
+    }
+}
+
+size_t ismrmrd_size_of_ndarray_data(const ISMRMRD_NDArray *arr) {
+    size_t data_size = 0;
     int num_data = 1;
     for (int n = 0; n < ISMRMRD_NDARRAY_MAXDIM; n++) {
         num_data *= arr->dims[n];
@@ -186,27 +241,6 @@ int ismrmrd_size_of_ndarray_data(const ISMRMRD_NDArray *arr) {
     return data_size;
 }
 
-void ismrmrd_make_consistent_ndarray(ISMRMRD_NDArray *arr) {
-    int data_size = ismrmrd_size_of_ndarray_data(arr);
-    if (data_size > 0) {
-        arr->data = realloc(arr->data, data_size);
-    }
-}
-
-void ismrmrd_copy_ndarray(ISMRMRD_NDArray *arrdest, const ISMRMRD_NDArray *arrsource) {
-    arrdest->version = arrsource->version;
-    arrdest->data_type = arrsource->data_type;
-    arrdest->ndim = arrsource->ndim;
-    for (int n = 0; n < ISMRMRD_NDARRAY_MAXDIM; n++) {
-        arrdest->dims[n] = arrsource->dims[n];
-    }
-    ismrmrd_make_consistent_ndarray(arrdest);
-    int data_size = ismrmrd_size_of_ndarray_data(arrdest);
-    if (data_size > 0) {
-        memcpy(&(arrdest->data), &(arrsource->data), ismrmrd_size_of_ndarray_data(arrdest));
-    }
-}
-
 bool ismrmrd_is_flag_set(const uint64_t flags, const uint64_t val) {
     uint64_t bitmask = 1;
     bitmask = (bitmask << (val - 1));
@@ -276,8 +310,8 @@ void ismrmrd_directions_to_quaternion(float read_dir[3], float phase_dir[3],
         d = 0.25l * s;
     } else {
         /* trickier case...
-	     * determine which major diagonal element has
-	     * the greatest value... */
+		 * determine which major diagonal element has
+		 * the greatest value... */
         xd = 1.0 + r11 - (r22 + r33); /* 4**b**b */
         yd = 1.0 + r22 - (r11 + r33); /* 4**c**c */
         zd = 1.0 + r33 - (r11 + r22); /* 4**d**d */
@@ -338,5 +372,6 @@ void ismrmrd_quaternion_to_directions(float quat[4], float read_dir[3],
 }
 
 #ifdef __cplusplus
-} //End of extern C
+} // extern "C"
+} // namespace ISMRMRD
 #endif
diff --git a/ismrmrd.cpp b/ismrmrd.cpp
index 5473d4b..10083a4 100644
--- a/ismrmrd.cpp
+++ b/ismrmrd.cpp
@@ -2,68 +2,364 @@
 
 namespace ISMRMRD {
 
+//
+// AcquisitionHeader class implementation
+//
 AcquisitionHeader::AcquisitionHeader() {
-    ismrmrd_init_acquisition_header(this);
+    ismrmrd_init_acquisition_header(&(head_));
 };
 
+// Accessors and mutators
+const uint16_t &AcquisitionHeader::version() {
+    return head_.version;
+};
+const uint64_t &AcquisitionHeader::flags() {
+    return head_.flags;
+};
+uint32_t &AcquisitionHeader::measurement_uid() {
+    return head_.measurement_uid;
+};
+uint32_t &AcquisitionHeader::scan_counter() {
+    return head_.scan_counter;
+};
+uint32_t &AcquisitionHeader::acquisition_time_stamp() {
+    return head_.acquisition_time_stamp;
+};
+uint32_t (&AcquisitionHeader::physiology_time_stamp()) [ISMRMRD_PHYS_STAMPS] { return head_.physiology_time_stamp; };
+uint16_t &AcquisitionHeader::number_of_samples() {
+    return head_.number_of_samples;
+};
+uint16_t &AcquisitionHeader::available_channels() {
+    return head_.available_channels;
+};
+uint16_t &AcquisitionHeader::active_channels() {
+    return head_.active_channels;
+};
+const uint64_t (&AcquisitionHeader::channel_mask()) [ISMRMRD_CHANNEL_MASKS] { return head_.channel_mask; };
+uint16_t &AcquisitionHeader::discard_pre() {
+    return head_.discard_pre;
+};
+uint16_t &AcquisitionHeader::discard_post() {
+    return head_.discard_post;
+};
+uint16_t &AcquisitionHeader::center_sample() {
+    return head_.center_sample;
+};
+uint16_t &AcquisitionHeader::encoding_space_ref() {
+    return head_.encoding_space_ref;
+};
+uint16_t &AcquisitionHeader::trajectory_dimensions() {
+    return head_.trajectory_dimensions;
+};
+float &AcquisitionHeader::sample_time_us() {
+    return head_.sample_time_us;
+};
+float (&AcquisitionHeader::position()) [ISMRMRD_POSITION_LENGTH] { return head_.position; };
+float (&AcquisitionHeader::read_dir()) [ISMRMRD_DIRECTION_LENGTH] { return head_.read_dir; };
+float (&AcquisitionHeader::phase_dir()) [ISMRMRD_DIRECTION_LENGTH] { return head_.phase_dir; };
+float (&AcquisitionHeader::slice_dir()) [ISMRMRD_DIRECTION_LENGTH] { return head_.slice_dir; };
+float (&AcquisitionHeader::patient_table_position()) [ISMRMRD_POSITION_LENGTH] { return head_.patient_table_position; };
+ISMRMRD_EncodingCounters &AcquisitionHeader::idx() {
+    return head_.idx;
+};
+int32_t (&AcquisitionHeader::user_int()) [ISMRMRD_USER_INTS] { return head_.user_int; };
+float (&AcquisitionHeader::user_float()) [ISMRMRD_USER_FLOATS] { return head_.user_float; };
+
+// Flag methods
 bool AcquisitionHeader::isFlagSet(const uint64_t val) {
-    return ismrmrd_is_flag_set(this->flags, val);
+    return ismrmrd_is_flag_set(head_.flags, val);
 };
 
 void AcquisitionHeader::setFlag(const uint64_t val) {
-    ismrmrd_set_flag(&(this->flags), val);
+    ismrmrd_set_flag(&(head_.flags), val);
 };
 
 void AcquisitionHeader::clearFlag(const uint64_t val) {
-    ismrmrd_clear_flag(&(this->flags), val);
+    ismrmrd_clear_flag(&(head_.flags), val);
 };
 
 void AcquisitionHeader::clearAllFlags() {
-    ismrmrd_clear_all_flags(&(this->flags));
+    ismrmrd_clear_all_flags(&(head_.flags));
 };
 
+// TODO: Channel mask methods go here
+
+//
+// Acquisition class Implementation
+//
 Acquisition::Acquisition() {
-    ismrmrd_init_acquisition(this);
+    ismrmrd_init_acquisition(&acq_);
 };
 
+// Accessors and mutators
 const uint16_t &Acquisition::version() {
-    return (this->head.version);
+    return acq_.head.version;
+};
+const uint64_t &Acquisition::flags() {
+    return acq_.head.flags;
+};
+uint32_t &Acquisition::measurement_uid() {
+    return acq_.head.measurement_uid;
+};
+uint32_t &Acquisition::scan_counter() {
+    return acq_.head.scan_counter;
+};
+uint32_t &Acquisition::acquisition_time_stamp() {
+    return acq_.head.acquisition_time_stamp;
+};
+uint32_t (&Acquisition::physiology_time_stamp()) [ISMRMRD_PHYS_STAMPS] { return acq_.head.physiology_time_stamp; };
+
+const uint16_t &Acquisition::number_of_samples() {
+    return acq_.head.number_of_samples;
+};
+void Acquisition::number_of_samples(uint16_t num_samples) {
+    acq_.head.number_of_samples = num_samples;
+    ismrmrd_make_consistent_acquisition(&acq_);
+};
+
+uint16_t &Acquisition::available_channels() {
+    return acq_.head.available_channels;
+};
+
+const uint16_t &Acquisition::active_channels() {
+    return acq_.head.active_channels;
+};
+void Acquisition::active_channels(uint16_t num_channels) {
+    acq_.head.active_channels = num_channels;
+    ismrmrd_make_consistent_acquisition(&acq_);
+};
+
+const uint64_t (&Acquisition::channel_mask()) [ISMRMRD_CHANNEL_MASKS] { return acq_.head.channel_mask; };
+uint16_t &Acquisition::discard_pre() {
+    return acq_.head.discard_pre;
+};
+uint16_t &Acquisition::discard_post() {
+    return acq_.head.discard_post;
+};
+uint16_t &Acquisition::center_sample() {
+    return acq_.head.center_sample;
 };
-uint64_t &Acquisition::flags() {
-    return (this->head.flags);
+uint16_t &Acquisition::encoding_space_ref() {
+    return acq_.head.encoding_space_ref;
 };
+uint16_t &Acquisition::trajectory_dimensions() {
+    return acq_.head.trajectory_dimensions;
+};
+float &Acquisition::sample_time_us() {
+    return acq_.head.sample_time_us;
+};
+float (&Acquisition::position()) [ISMRMRD_POSITION_LENGTH] { return acq_.head.position; };
+float (&Acquisition::read_dir()) [ISMRMRD_DIRECTION_LENGTH] { return acq_.head.read_dir; };
+float (&Acquisition::phase_dir()) [ISMRMRD_DIRECTION_LENGTH] { return acq_.head.phase_dir; };
+float (&Acquisition::slice_dir()) [ISMRMRD_DIRECTION_LENGTH] { return acq_.head.slice_dir; };
+float (&Acquisition::patient_table_position()) [ISMRMRD_POSITION_LENGTH] { return acq_.head.patient_table_position; };
+ISMRMRD_EncodingCounters &Acquisition::idx() {
+    return acq_.head.idx;
+};
+int32_t (&Acquisition::user_int()) [ISMRMRD_USER_INTS] { return acq_.head.user_int; };
+float (&Acquisition::user_float()) [ISMRMRD_USER_FLOATS] { return acq_.head.user_float; };
 
+// Flag methods
 bool Acquisition::isFlagSet(const uint64_t val) {
-    return ismrmrd_is_flag_set((this->head.flags), val);
+    return ismrmrd_is_flag_set(acq_.head.flags, val);
 };
 void Acquisition::setFlag(const uint64_t val) {
-    ismrmrd_set_flag(&(this->head.flags), val);
+    ismrmrd_set_flag(&acq_.head.flags, val);
 };
 void Acquisition::clearFlag(const uint64_t val) {
-    ismrmrd_clear_flag(&(this->head.flags), val);
+    ismrmrd_clear_flag(&acq_.head.flags, val);
 };
 void Acquisition::clearAllFlags() {
-    ismrmrd_clear_all_flags(&(this->head.flags));
+    ismrmrd_clear_all_flags(&acq_.head.flags);
 };
 
+// TODO: Channel mask methods go here
+
+//
+// ImageHeader class Implementation
+//
+
+// Constructors
 ImageHeader::ImageHeader() {
-    ismrmrd_init_image_header(this);
+    ismrmrd_init_image_header(&head_);
 };
 
+// Accessors and mutators
+const uint16_t &ImageHeader::version() {
+    return head_.version;
+};
+const uint16_t &ImageHeader::data_type() {
+    return head_.data_type;
+};
+// TODO void ImageHeader::data_type(uint16_t dtype) { return head_.data_type; };
+const uint64_t &ImageHeader::flags() {
+    return head_.flags;
+};
+uint32_t &ImageHeader::measurement_uid() {
+    return head_.measurement_uid;
+};
+uint16_t (&ImageHeader::matrix_size())[3] {
+    return head_.matrix_size;
+};
+// TODO set matrix size
+float (&ImageHeader::field_of_view())[3] {
+    return head_.field_of_view;
+};
+// TODO set field of view
+uint16_t &ImageHeader::channels() {
+    return head_.channels;
+};
+float (&ImageHeader::position()) [ISMRMRD_POSITION_LENGTH] { return head_.position; };
+float (&ImageHeader::read_dir()) [ISMRMRD_DIRECTION_LENGTH] { return head_.read_dir; };
+float (&ImageHeader::phase_dir()) [ISMRMRD_DIRECTION_LENGTH] { return head_.phase_dir; };
+float (&ImageHeader::slice_dir()) [ISMRMRD_DIRECTION_LENGTH] { return head_.slice_dir; };
+float (&ImageHeader::patient_table_position()) [ISMRMRD_POSITION_LENGTH] { return head_.patient_table_position; };
+uint16_t &ImageHeader::average() {
+    return head_.average;
+};
+uint16_t &ImageHeader::slice() {
+    return head_.slice;
+};
+uint16_t &ImageHeader::contrast() {
+    return head_.contrast;
+};
+uint16_t &ImageHeader::phase() {
+    return head_.repetition;
+};
+uint16_t &ImageHeader::repetition() {
+    return head_.repetition;
+};
+uint16_t &ImageHeader::set() {
+    return head_.set;
+};
+uint32_t &ImageHeader::acquisition_time_stamp() {
+    return head_.acquisition_time_stamp;
+};
+uint32_t (&ImageHeader::physiology_time_stamp()) [ISMRMRD_PHYS_STAMPS] { return head_.physiology_time_stamp; };
+uint16_t &ImageHeader::image_type() {
+    return head_.image_type;
+};
+uint16_t &ImageHeader::image_index() {
+    return head_.image_index;
+};
+uint16_t &ImageHeader::image_series_index() {
+    return head_.image_series_index;
+};
+int32_t (&ImageHeader::user_int()) [ISMRMRD_USER_INTS] { return head_.user_int; };
+float (&ImageHeader::user_float()) [ISMRMRD_USER_FLOATS] { return head_.user_float; };
+const uint32_t &ImageHeader::attribute_string_len() {
+    return head_.attribute_string_len;
+};
+
+// Flag methods
 bool ImageHeader::isFlagSet(const uint64_t val) {
-    return ismrmrd_is_flag_set(this->flags, val);
+    return ismrmrd_is_flag_set(head_.flags, val);
 };
 
 void ImageHeader::setFlag(const uint64_t val) {
-    ismrmrd_set_flag(&(this->flags), val);
+    ismrmrd_set_flag(&(head_.flags), val);
 };
 
 void ImageHeader::clearFlag(const uint64_t val) {
-    ismrmrd_clear_flag(&(this->flags), val);
+    ismrmrd_clear_flag(&(head_.flags), val);
 };
 
 void ImageHeader::clearAllFlags() {
-    ismrmrd_clear_all_flags(&(this->flags));
+    ismrmrd_clear_all_flags(&(head_.flags));
+};
+
+//
+// Image class Implementation
+//
+
+// Constructors
+Image::Image() {
+    ismrmrd_init_image(&image_);
+};
+
+// Accessors and mutators
+const uint16_t &Image::version() {
+    return image_.head.version;
+};
+const uint16_t &Image::data_type() {
+    return image_.head.data_type;
+};
+// TODO void Image::data_type(uint16_t dtype) { return image_.head.data_type; };
+const uint64_t &Image::flags() {
+    return image_.head.flags;
+};
+uint32_t &Image::measurement_uid() {
+    return image_.head.measurement_uid;
+};
+const uint16_t (&Image::matrix_size())[3] {
+    return image_.head.matrix_size;
+};
+// TODO set matrix size
+const float (&Image::field_of_view())[3] {
+    return image_.head.field_of_view;
+};
+// TODO set field of view
+const uint16_t &Image::channels() {
+    return image_.head.channels;
+};
+// TODO set number of channels
+float (&Image::position()) [ISMRMRD_POSITION_LENGTH] { return image_.head.position; };
+float (&Image::read_dir()) [ISMRMRD_DIRECTION_LENGTH] { return image_.head.read_dir; };
+float (&Image::phase_dir()) [ISMRMRD_DIRECTION_LENGTH] { return image_.head.phase_dir; };
+float (&Image::slice_dir()) [ISMRMRD_DIRECTION_LENGTH] { return image_.head.slice_dir; };
+float (&Image::patient_table_position()) [ISMRMRD_POSITION_LENGTH] { return image_.head.patient_table_position; };
+uint16_t &Image::average() {
+    return image_.head.average;
+};
+uint16_t &Image::slice() {
+    return image_.head.slice;
+};
+uint16_t &Image::contrast() {
+    return image_.head.contrast;
+};
+uint16_t &Image::phase() {
+    return image_.head.repetition;
+};
+uint16_t &Image::repetition() {
+    return image_.head.repetition;
+};
+uint16_t &Image::set() {
+    return image_.head.set;
+};
+uint32_t &Image::acquisition_time_stamp() {
+    return image_.head.acquisition_time_stamp;
+};
+uint32_t (&Image::physiology_time_stamp()) [ISMRMRD_PHYS_STAMPS] { return image_.head.physiology_time_stamp; };
+uint16_t &Image::image_type() {
+    return image_.head.image_type;
+};
+uint16_t &Image::image_index() {
+    return image_.head.image_index;
+};
+uint16_t &Image::image_series_index() {
+    return image_.head.image_series_index;
+};
+int32_t (&Image::user_int()) [ISMRMRD_USER_INTS] { return image_.head.user_int; };
+float (&Image::user_float()) [ISMRMRD_USER_FLOATS] { return image_.head.user_float; };
+const uint32_t &Image::attribute_string_len() {
+    return image_.head.attribute_string_len;
+};
+
+// Flag methods
+bool Image::isFlagSet(const uint64_t val) {
+    return ismrmrd_is_flag_set(image_.head.flags, val);
+};
+
+void Image::setFlag(const uint64_t val) {
+    ismrmrd_set_flag(&(image_.head.flags), val);
+};
+
+void Image::clearFlag(const uint64_t val) {
+    ismrmrd_clear_flag(&(image_.head.flags), val);
+};
+
+void Image::clearAllFlags() {
+    ismrmrd_clear_all_flags(&(image_.head.flags));
 };
 
 } // namespace ISMRMRD
diff --git a/ismrmrd.h b/ismrmrd.h
index 33be490..4a2cbb3 100644
--- a/ismrmrd.h
+++ b/ismrmrd.h
@@ -13,46 +13,34 @@
 #ifndef ISMRMRD_H
 #define ISMRMRD_H
 
-/* Language and Cross platform section for defining types */
+/* Language and cross platform section for defining types */
 #ifdef __cplusplus
 
-#ifdef _MSC_VER
-/* MS C++ Compiler */
+#ifdef _MSC_VER /* MS C++ Compiler */
 typedef __int16 int16_t;
 typedef unsigned __int16 uint16_t;
 typedef __int32 int32_t;
 typedef unsigned __int32 uint32_t;
 typedef __int64 int64_t;
 typedef unsigned __int64 uint64_t;
-
-#else
-/* non MS C++ compiler */
+#else /* non MS C++ compiler */
 #include <cstdint>
 #endif
-
-#include <cstdlib>
-#include <cstring>
 #include <complex>
-#include <cmath>
 typedef std::complex<float> complex_float_t;
 typedef std::complex<double> complex_double_t;
-
-#else
-/* C99 compiler */
+#else /* C99 compiler */
 #include <stdint.h>
 #include <complex.h>
-#include <math.h>
-#include <string.h>
-#include <stdlib.h>
 #include <stdbool.h>
 typedef float complex complex_float_t;
 typedef double complex complex_double_t;
-
 #endif /* __cplusplus */
 
 #pragma pack(push, 2) /* Use 2 byte alignment */
 
 #ifdef __cplusplus
+namespace ISMRMRD {
 extern "C" {
 #endif
 
@@ -213,9 +201,11 @@ typedef struct ISMRMRD_Acquisition {
 } ISMRMRD_Acquisition;
 
 void ismrmrd_init_acquisition(ISMRMRD_Acquisition *acq);
-void ismrmrd_copy_acquisition(ISMRMRD_Acquisition *acqdest, const ISMRMRD_Acquisition *acqsource);
 void ismrmrd_free_acquisition(ISMRMRD_Acquisition *acq);
+void ismrmrd_copy_acquisition(ISMRMRD_Acquisition *acqdest, const ISMRMRD_Acquisition *acqsource);
 void ismrmrd_make_consistent_acquisition(ISMRMRD_Acquisition *acq);
+size_t ismrmrd_size_of_acquisition_traj(const ISMRMRD_Acquisition *acq);
+size_t ismrmrd_size_of_acquisition_data(const ISMRMRD_Acquisition *acq);
 
 /**********/
 /* Images */
@@ -265,11 +255,11 @@ typedef struct ISMRMRD_Image {
 } ISMRMRD_Image;
 
 void ismrmrd_init_image(ISMRMRD_Image *im);
-void ismrmrd_copy_image(ISMRMRD_Image *imdest, const ISMRMRD_Image *imsource);
 void ismrmrd_free_image(ISMRMRD_Image *im);
+void ismrmrd_copy_image(ISMRMRD_Image *imdest, const ISMRMRD_Image *imsource);
 void ismrmrd_make_consistent_image(ISMRMRD_Image *im);
-int ismrmrd_size_of_image_attribute_string(const ISMRMRD_Image *im);
-int ismrmrd_size_of_image_data(const ISMRMRD_Image *im);
+size_t ismrmrd_size_of_image_attribute_string(const ISMRMRD_Image *im);
+size_t ismrmrd_size_of_image_data(const ISMRMRD_Image *im);
 
 /************/
 /* NDArrays */
@@ -284,10 +274,10 @@ typedef struct ISMRMRD_NDArray {
 } ISMRMRD_NDArray;
 
 void ismrmrd_init_ndarray(ISMRMRD_NDArray *arr);
-void ismrmrd_copy_ndarray(ISMRMRD_NDArray *arrdest, const ISMRMRD_NDArray *arrsource);
 void ismrmrd_free_ndarray(ISMRMRD_NDArray *arr);
+void ismrmrd_copy_ndarray(ISMRMRD_NDArray *arrdest, const ISMRMRD_NDArray *arrsource);
 void ismrmrd_make_consistent_ndarray(ISMRMRD_NDArray *arr);
-int ismrmrd_size_of_ndarray_data(const ISMRMRD_NDArray *arr);
+size_t ismrmrd_size_of_ndarray_data(const ISMRMRD_NDArray *arr);
 
 /*********/
 /* Flags */
@@ -316,7 +306,8 @@ void ismrmrd_quaternion_to_directions(float quat[4], float read_dir[3], float ph
 #pragma pack(pop) // Restore old alignment
 
 #ifdef __cplusplus
-} //End of extern C
+} // extern "C"
+} // namespace ISMRMRD
 #endif
 
 #endif // ISMRMRD_H
diff --git a/ismrmrd.hpp b/ismrmrd.hpp
index 2e7de5d..0fdd212 100644
--- a/ismrmrd.hpp
+++ b/ismrmrd.hpp
@@ -10,45 +10,194 @@
 
 namespace ISMRMRD {
 
-class AcquisitionHeader : protected ISMRMRD_AcquisitionHeader {
+class AcquisitionHeader {
 public:
-    explicit AcquisitionHeader();
+    AcquisitionHeader();
 
     // Accessors and mutators
     const uint16_t &version();
-    uint64_t &flags();
+    const uint64_t &flags();
+    uint32_t &measurement_uid();
+    uint32_t &scan_counter();
+    uint32_t &acquisition_time_stamp();
+    uint32_t (&physiology_time_stamp())[ISMRMRD_PHYS_STAMPS];
+    uint16_t &number_of_samples();
+    uint16_t &available_channels();
+    uint16_t &active_channels();
+    const uint64_t (&channel_mask())[ISMRMRD_CHANNEL_MASKS];
+    uint16_t &discard_pre();
+    uint16_t &discard_post();
+    uint16_t &center_sample();
+    uint16_t &encoding_space_ref();
+    uint16_t &trajectory_dimensions();
+    float &sample_time_us();
+    float (&position())[ISMRMRD_POSITION_LENGTH];
+    float (&read_dir())[ISMRMRD_DIRECTION_LENGTH];
+    float (&phase_dir())[ISMRMRD_DIRECTION_LENGTH];
+    float (&slice_dir())[ISMRMRD_DIRECTION_LENGTH];
+    float (&patient_table_position())[ISMRMRD_POSITION_LENGTH];
+    ISMRMRD_EncodingCounters &idx();
+    int32_t (&user_int())[ISMRMRD_USER_INTS];
+    float (&user_float())[ISMRMRD_USER_FLOATS];
 
     // Flag methods
     bool isFlagSet(const uint64_t val);
     void setFlag(const uint64_t val);
     void clearFlag(const uint64_t val);
     void clearAllFlags();
+
+    // Channel mask methods
+    // TODO: need to add the functionality for these
+    //bool isChannelActive(uint16_t channel_id);
+    //void setChannelActive(uint16_t channel_id);
+    //void setChannelNotActive(uint16_t channel_id);
+    //void setAllChannelsNotActive();
+
+protected:
+    ISMRMRD_AcquisitionHeader head_;
 };
 
-class Acquisition : protected ISMRMRD_Acquisition {
+class Acquisition {
 public:
-    explicit Acquisition();
+    Acquisition();
 
     // Accessors and mutators
     const uint16_t &version();
-    uint64_t &flags();
+    const uint64_t &flags();
+    uint32_t &measurement_uid();
+    uint32_t &scan_counter();
+    uint32_t &acquisition_time_stamp();
+    uint32_t (&physiology_time_stamp())[ISMRMRD_PHYS_STAMPS];
+    const uint16_t &number_of_samples();
+    void number_of_samples(uint16_t num_samples);
+    uint16_t &available_channels();
+    const uint16_t &active_channels();
+    void active_channels(uint16_t num_active_channels);
+    const uint64_t (&channel_mask())[ISMRMRD_CHANNEL_MASKS];
+    uint16_t &discard_pre();
+    uint16_t &discard_post();
+    uint16_t &center_sample();
+    uint16_t &encoding_space_ref();
+    uint16_t &trajectory_dimensions();
+    float &sample_time_us();
+    float (&position())[ISMRMRD_POSITION_LENGTH];
+    float (&read_dir())[ISMRMRD_DIRECTION_LENGTH];
+    float (&phase_dir())[ISMRMRD_DIRECTION_LENGTH];
+    float (&slice_dir())[ISMRMRD_DIRECTION_LENGTH];
+    float (&patient_table_position())[ISMRMRD_POSITION_LENGTH];
+    ISMRMRD_EncodingCounters &idx();
+    int32_t (&user_int())[ISMRMRD_USER_INTS];
+    float (&user_float())[ISMRMRD_USER_FLOATS];
 
     // Flag methods
     bool isFlagSet(const uint64_t val);
     void setFlag(const uint64_t val);
     void clearFlag(const uint64_t val);
     void clearAllFlags();
+
+    // Channel mask methods
+    // TODO: need to add the functionality for these
+    //bool isChannelActive(uint16_t channel_id);
+    //void setChannelActive(uint16_t channel_id);
+    //void setChannelNotActive(uint16_t channel_id);
+    //void setAllChannelsNotActive();
+
+protected:
+    ISMRMRD_Acquisition acq_;
 };
 
-class ImageHeader : protected ISMRMRD_ImageHeader {
-    explicit ImageHeader();
+class ImageHeader {
+public:
+    // Constructors
+    ImageHeader();
+    ImageHeader(ImageHeader &hdr);
+    ImageHeader(ISMRMRD_ImageHeader *hdr);
+
+    // 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();
+    uint16_t (&matrix_size())[3];
+    float (&field_of_view())[3];
+    uint16_t &channels();
+    float (&position())[ISMRMRD_POSITION_LENGTH];
+    float (&read_dir())[ISMRMRD_DIRECTION_LENGTH];
+    float (&phase_dir())[ISMRMRD_DIRECTION_LENGTH];
+    float (&slice_dir())[ISMRMRD_DIRECTION_LENGTH];
+    float (&patient_table_position())[ISMRMRD_POSITION_LENGTH];
+    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();
+
+    // Flag methods
     bool isFlagSet(const uint64_t val);
     void setFlag(const uint64_t val);
     void clearFlag(const uint64_t val);
     void clearAllFlags();
+
+protected:
+    ISMRMRD_ImageHeader head_;
 };
 
-class Image : protected ISMRMRD_Image {
+class Image {
+public:
+    // Constructors
+    Image();
+    Image(Image &im);
+    Image(ISMRMRD_Image *im);
+
+    // Accessors and mutators
+    const uint16_t &version();
+    const uint16_t &data_type();
+    const uint64_t &flags();
+    uint32_t &measurement_uid();
+    const uint16_t (&matrix_size())[3];
+    // TODO set matrix size
+    const float (&field_of_view())[3];
+    // TODO set field of view
+    const uint16_t &channels();
+    void channels(uint16_t num_channels);
+    float (&position())[ISMRMRD_POSITION_LENGTH];
+    float (&read_dir())[ISMRMRD_DIRECTION_LENGTH];
+    float (&phase_dir())[ISMRMRD_DIRECTION_LENGTH];
+    float (&slice_dir())[ISMRMRD_DIRECTION_LENGTH];
+    float (&patient_table_position())[ISMRMRD_POSITION_LENGTH];
+    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();
+
+    // Flag methods
+    bool isFlagSet(const uint64_t val);
+    void setFlag(const uint64_t val);
+    void clearFlag(const uint64_t val);
+    void clearAllFlags();
+
+protected:
+    ISMRMRD_Image image_;
 };
 
 class NDArray : protected ISMRMRD_NDArray {
diff --git a/tests/c++/basic_test.cpp b/tests/c++/basic_test.cpp
index 3b46f4b..7c37ed4 100644
--- a/tests/c++/basic_test.cpp
+++ b/tests/c++/basic_test.cpp
@@ -6,14 +6,14 @@ int main (int args, char** argv) {
   using namespace ISMRMRD;
   
   AcquisitionHeader acqhdr;
-  std::cout << "Version: " << acqhdr.version << std::endl;
-  std::cout << "Flags 0: " << acqhdr.flags << std::endl;
+  std::cout << "Version: " << acqhdr.version() << std::endl;
+  std::cout << "Flags 0: " << acqhdr.flags() << std::endl;
   std::cout << "ACQ_FIRST_IN_SLICE: " << acqhdr.isFlagSet(ISMRMRD_ACQ_FIRST_IN_SLICE) << std::endl;
   acqhdr.setFlag(ISMRMRD_ACQ_FIRST_IN_SLICE);
-  std::cout << "Flags 1: " << acqhdr.flags << std::endl;
+  std::cout << "Flags 1: " << acqhdr.flags() << std::endl;
   std::cout << "ACQ_FIRST_IN_SLICE: " << acqhdr.isFlagSet(ISMRMRD_ACQ_FIRST_IN_SLICE) << std::endl;
   acqhdr.clearFlag(ISMRMRD_ACQ_FIRST_IN_SLICE);
-  std::cout << "Flags 2: " << acqhdr.flags << std::endl;
+  std::cout << "Flags 2: " << acqhdr.flags() << std::endl;
   std::cout << "ACQ_FIRST_IN_SLICE: " << acqhdr.isFlagSet(ISMRMRD_ACQ_FIRST_IN_SLICE) << std::endl;
 
   Acquisition acq;
@@ -26,9 +26,9 @@ int main (int args, char** argv) {
   acq.clearFlag(ISMRMRD_ACQ_FIRST_IN_SLICE);
   std::cout << "Flags 2: " << acq.flags() << std::endl;
   std::cout << "ACQ_FIRST_IN_SLICE: " << acq.isFlagSet(ISMRMRD_ACQ_FIRST_IN_SLICE) << std::endl;
-  acq.flags() = 64;
-  std::cout << "Flags 3: " << acq.flags() << std::endl;
-  std::cout << "ACQ_FIRST_IN_SLICE: " << acq.isFlagSet(ISMRMRD_ACQ_FIRST_IN_SLICE) << std::endl;
+  std::cout << "Number of samples: " << acq.number_of_samples() << std::endl;
+  acq.number_of_samples(64);
+  std::cout << "Number of samples: " << acq.number_of_samples() << std::endl;
   
 
   return 0;

-- 
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