[ismrmrd] 27/177: Worked on ndarray

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Wed Jan 14 20:01:58 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 506c96d9eafaa5c63d7c1ec7ed9413788729f8b3
Author: Souheil Inati <souheil.inati at nih.gov>
Date:   Thu Aug 28 19:00:13 2014 -0400

    Worked on ndarray
---
 ismrmrd.c   | 17 ++++++++---
 ismrmrd.cpp | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 ismrmrd.h   | 39 ++++++++++++++----------
 3 files changed, 132 insertions(+), 23 deletions(-)

diff --git a/ismrmrd.c b/ismrmrd.c
index 5c2d930..e3200d2 100644
--- a/ismrmrd.c
+++ b/ismrmrd.c
@@ -207,6 +207,17 @@ size_t ismrmrd_size_of_image_attribute_string(const ISMRMRD_Image *im) {
 }
 
 /* NDArray functions */
+ISMRMRD_NDArray * ismrmrd_create_ndarray() {
+    ISMRMRD_NDArray *arr = (ISMRMRD_NDArray *) malloc(sizeof(ISMRMRD_NDArray));
+    ismrmrd_init_ndarray(arr);
+    return arr;
+}
+
+void ismrmrd_free_ndarray(ISMRMRD_NDArray *arr) {
+    free(arr->data);
+    free(arr);
+}
+
 void ismrmrd_init_ndarray(ISMRMRD_NDArray *arr) {
     arr->version = ISMRMRD_VERSION;
     arr->data_type = 0; // no default data type
@@ -214,12 +225,11 @@ void ismrmrd_init_ndarray(ISMRMRD_NDArray *arr) {
     for (int n = 0; n < ISMRMRD_NDARRAY_MAXDIM; n++) {
         arr->dims[n] = 1;
     }
-    arr->data = NULL;
+    ismrmrd_make_consistent_ndarray(arr);
 }
 
-void ismrmrd_free_ndarray(ISMRMRD_NDArray *arr) {
+void ismrmrd_cleanup_ndarray(ISMRMRD_NDArray *arr) {
     free(arr->data);
-    free(arr);
 }
 
 void ismrmrd_copy_ndarray(ISMRMRD_NDArray *arrdest, const ISMRMRD_NDArray *arrsource) {
@@ -243,7 +253,6 @@ int ismrmrd_make_consistent_ndarray(ISMRMRD_NDArray *arr) {
             return ISMRMRD_MEMORYERROR;
         }
     }
-
     return ISMRMRD_NOERROR;
 }
 
diff --git a/ismrmrd.cpp b/ismrmrd.cpp
index 7828ae6..1c202ee 100644
--- a/ismrmrd.cpp
+++ b/ismrmrd.cpp
@@ -112,15 +112,15 @@ float (&AcquisitionHeader::user_float()) [ISMRMRD_USER_FLOATS] {
 };
 
 // Flag methods
-bool AcquisitionHeader::isFlagSet(const uint64_t val) {
+bool AcquisitionHeader::isFlagSet(const ISMRMRD_AcquisitionFlags val) {
     return ismrmrd_is_flag_set(head_.flags, val);
 };
 
-void AcquisitionHeader::setFlag(const uint64_t val) {
+void AcquisitionHeader::setFlag(const ISMRMRD_AcquisitionFlags val) {
     ismrmrd_set_flag(&(head_.flags), val);
 };
 
-void AcquisitionHeader::clearFlag(const uint64_t val) {
+void AcquisitionHeader::clearFlag(const ISMRMRD_AcquisitionFlags val) {
     ismrmrd_clear_flag(&(head_.flags), val);
 };
 
@@ -605,4 +605,97 @@ void Image::clearAllFlags() {
     ismrmrd_clear_all_flags(&(image_.head.flags));
 };
 
+//
+// Array class Implementation
+//
+
+NDArray::NDArray()
+{
+    ismrmrd_init_ndarray(&arr_);
+}
+
+NDArray::NDArray(const ISMRMRD_DataTypes dtype, const uint16_t ndim, const uint16_t dims[ISMRMRD_NDARRAY_MAXDIM])
+{
+    ismrmrd_init_ndarray(&arr_);
+    setProperties(dtype, ndim, dims);
+}
+
+NDArray::NDArray(const ISMRMRD_DataTypes dtype, const std::vector<uint16_t> dimvec)
+{
+    ismrmrd_init_ndarray(&arr_);
+    setProperties(dtype, dimvec);    
+}
+
+NDArray::NDArray(const NDArray &other)
+{
+    ismrmrd_init_ndarray(&arr_);
+    ismrmrd_copy_ndarray(&arr_, &other.arr_);    
+}
+
+NDArray::NDArray(const ISMRMRD_NDArray *arr)
+{
+    ismrmrd_init_ndarray(&arr_);
+    ismrmrd_copy_ndarray(&arr_, arr);
+}
+
+NDArray::~NDArray()
+{
+    ismrmrd_cleanup_ndarray(&arr_);
+}
+
+NDArray & NDArray::operator= (const NDArray &other)
+{
+    // Assignment makes a copy
+    if (this != &other )
+    {
+        ismrmrd_init_ndarray(&arr_);
+        ismrmrd_copy_ndarray(&arr_, &other.arr_);
+    }
+    return *this;
+}
+
+const uint16_t NDArray::version() {
+    return arr_.version;
+};
+
+const ISMRMRD_DataTypes NDArray::data_type() {
+    return static_cast<ISMRMRD_DataTypes>( arr_.data_type );
+}
+
+const uint16_t NDArray::ndim() {
+    return  arr_.ndim;
+};
+    
+const uint16_t (&NDArray::dims())[ISMRMRD_NDARRAY_MAXDIM] {
+    return arr_.dims;
+};
+    
+int NDArray::setProperties(const ISMRMRD_DataTypes dtype, const uint16_t ndim, const uint16_t dims[ISMRMRD_NDARRAY_MAXDIM]) {
+    arr_.data_type = dtype;
+    arr_.ndim = ndim;
+    for (int n=0; n<ISMRMRD_NDARRAY_MAXDIM; n++) {
+        arr_.dims[n] = dims[n];
+    }
+    int status = ismrmrd_make_consistent_ndarray(&arr_);
+    return status;
+}
+
+int NDArray::setProperties(const ISMRMRD_DataTypes dtype, const std::vector<uint16_t> dimvec) {
+    if (dimvec.size() > ISMRMRD_NDARRAY_MAXDIM) {
+        // TODO throw exception
+        return ISMRMRD_MEMORYERROR;
+    }
+    arr_.data_type = dtype;
+    arr_.ndim = dimvec.size();
+    for (int n=0; n<arr_.ndim; n++) {
+        arr_.dims[n] = dimvec[n];
+    }
+    int status=ismrmrd_make_consistent_ndarray(&arr_);
+    return status;
+}
+
+void * NDArray::data() {
+    return arr_.data;
+}
+
 } // namespace ISMRMRD
diff --git a/ismrmrd.h b/ismrmrd.h
index e5c92ac..4df6931 100644
--- a/ismrmrd.h
+++ b/ismrmrd.h
@@ -29,6 +29,7 @@ typedef unsigned __int64 uint64_t;
 #include <complex>
 typedef std::complex<float> complex_float_t;
 typedef std::complex<double> complex_double_t;
+#include <vector>
 #else /* C99 compiler */
 #include <stdint.h>
 #include <complex.h>
@@ -288,8 +289,10 @@ typedef struct ISMRMRD_NDArray {
     void *data;                            /**< Pointer to data */
 } ISMRMRD_NDArray;
 
-void ismrmrd_init_ndarray(ISMRMRD_NDArray *arr);
+ISMRMRD_NDArray * ismrmrd_create_ndarray();
 void ismrmrd_free_ndarray(ISMRMRD_NDArray *arr);
+void ismrmrd_init_ndarray(ISMRMRD_NDArray *arr);
+void ismrmrd_cleanup_ndarray(ISMRMRD_NDArray *arr);
 void ismrmrd_copy_ndarray(ISMRMRD_NDArray *arrdest, const ISMRMRD_NDArray *arrsource);
 int ismrmrd_make_consistent_ndarray(ISMRMRD_NDArray *arr);
 size_t ismrmrd_size_of_ndarray_data(const ISMRMRD_NDArray *arr);
@@ -374,9 +377,9 @@ public:
     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);
+    bool isFlagSet(const ISMRMRD_AcquisitionFlags val);
+    void setFlag(const ISMRMRD_AcquisitionFlags val);
+    void clearFlag(const ISMRMRD_AcquisitionFlags val);
     void clearAllFlags();
 
     // Channel mask methods
@@ -549,25 +552,29 @@ protected:
 
 class NDArray {
 public:
-    // Constructors
+    // Constructors, destructor and copy
     NDArray();
-    NDArray(NDArray &arr);
-    NDArray(ISMRMRD_NDArray *arr);
+    NDArray(const ISMRMRD_DataTypes dtype, const uint16_t ndim, const uint16_t dims[ISMRMRD_NDARRAY_MAXDIM]);
+    NDArray(const ISMRMRD_DataTypes dtype, const std::vector<uint16_t> dimvec);
+    NDArray(const NDArray &other);
+    NDArray(const ISMRMRD_NDArray *arr);
+    ~NDArray();
+    NDArray & operator= (const NDArray &other);
 
     // Accessors and mutators
-    const uint16_t &version();
-    const uint16_t &data_type();
-    void data_type(const uint16_t dtype);
-    const uint16_t &ndim();
-    void ndim(const uint16_t numdim);
-    uint16_t dims[ISMRMRD_NDARRAY_MAXDIM];
-    void *data;
+    const uint16_t version();
+    const ISMRMRD_DataTypes data_type();
+    const uint16_t ndim();
+    const uint16_t (&dims())[ISMRMRD_NDARRAY_MAXDIM];
+    int setProperties(const ISMRMRD_DataTypes dtype, const uint16_t ndim, const uint16_t dims[ISMRMRD_NDARRAY_MAXDIM]);
+    int setProperties(const ISMRMRD_DataTypes dtype, const std::vector<uint16_t> dimvec);
+    void * data();
 
-    
 protected:
-    ISMRMRD_NDArray arr;
+    ISMRMRD_NDArray arr_;
 };
 
+
 } // namespace ISMRMRD
 #endif
 

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