[ismrmrd] 120/177: Merged in exception throwing.

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Wed Jan 14 20:02:10 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 3060d02a94b84ba4a2fb5abb308906322852d88c
Merge: fa32dd5 e5b0878
Author: Souheil Inati <souheil.inati at nih.gov>
Date:   Tue Sep 30 12:15:05 2014 -0400

    Merged in exception throwing.

 cmake/FindIsmrmrd.cmake   |   4 +-
 include/ismrmrd/ismrmrd.h |   5 +-
 info/ismrmrd_info.cpp     |   2 +-
 info/ismrmrd_version.in   |   3 +-
 libsrc/dataset.c          |   8 +--
 libsrc/dataset.cpp        |  34 ++++++----
 libsrc/ismrmrd.cpp        | 167 ++++++++++++++++++++++++++++++++++++----------
 libsrc/meta.cpp           |   6 +-
 libsrc/xml.cpp            |   4 ++
 9 files changed, 172 insertions(+), 61 deletions(-)

diff --cc include/ismrmrd/ismrmrd.h
index f05849e,7a8fd3b..22859a2
--- a/include/ismrmrd/ismrmrd.h
+++ b/include/ismrmrd/ismrmrd.h
@@@ -707,7 -617,7 +710,7 @@@ public
      const uint16_t getNDim();
      const size_t (&getDims())[ISMRMRD_NDARRAY_MAXDIM];
      const size_t getDataSize();
--    int resize(const std::vector<size_t> dimvec);
++    void resize(const std::vector<size_t> dimvec);
      const size_t getNumberOfElements();
      T * getData();
  
diff --cc libsrc/dataset.cpp
index 2eda672,ad07fca..45b6e9b
--- a/libsrc/dataset.cpp
+++ b/libsrc/dataset.cpp
@@@ -85,21 -93,11 +93,21 @@@ int Dataset::appendImage(const std::str
      }
      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
+         throw std::runtime_error(build_exception_string());
      }
      return status;
  }
diff --cc libsrc/ismrmrd.cpp
index eb48d66,20c87ba..635eb79
--- a/libsrc/ismrmrd.cpp
+++ b/libsrc/ismrmrd.cpp
@@@ -5,6 -7,61 +7,18 @@@
  
  namespace ISMRMRD {
  
+ std::string build_exception_string(void)
+ {
+     char *file = NULL, *func = NULL, *msg = NULL;
+     int line = 0, code = 0;
+     std::stringstream stream;
+     while (ismrmrd_pop_error(&file, &line, &func, &code, &msg)) {
+         stream << "ISMRMRD " << ismrmrd_strerror(code) << " in " << func <<
+                 " (" << file << ":" << line << ": " << msg << std::endl;
+     }
+     return stream.str();
+ }
+ 
 -
 -// Internal function to control the allowed data types for NDArrays
 -template <typename T>  ISMRMRD_DataTypes get_data_type();
 -template <> ISMRMRD_DataTypes get_data_type<uint16_t>()
 -{
 -    return ISMRMRD_USHORT;
 -}
 -
 -template <> inline ISMRMRD_DataTypes get_data_type<int16_t>()
 -{
 -    return ISMRMRD_SHORT;
 -}
 -
 -template <> inline ISMRMRD_DataTypes get_data_type<uint32_t>()
 -{
 -    return ISMRMRD_UINT;
 -}
 -
 -template <> inline ISMRMRD_DataTypes get_data_type<int32_t>()
 -{
 -    return ISMRMRD_INT;
 -}
 -
 -template <> inline ISMRMRD_DataTypes get_data_type<float>()
 -{
 -    return ISMRMRD_FLOAT;
 -}
 -
 -template <> inline ISMRMRD_DataTypes get_data_type<double>()
 -{
 -    return ISMRMRD_DOUBLE;
 -}
 -
 -template <> inline ISMRMRD_DataTypes get_data_type<complex_float_t>()
 -{
 -    return ISMRMRD_CXFLOAT;
 -}
 -
 -template <> inline ISMRMRD_DataTypes get_data_type<complex_double_t>()
 -{
 -    return ISMRMRD_CXDOUBLE;
 -}
 -
  //
  // AcquisitionHeader class implementation
  //
@@@ -250,24 -337,27 +294,34 @@@ void ImageHeader::clearAllFlags() 
  //
  
  // Constructors
 -Image::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);
+     if (ismrmrd_init_image(this) != ISMRMRD_NOERROR) {
+         throw std::runtime_error(build_exception_string());
+     }
 -};
 +    this->head.data_type = get_data_type<T>();
 +    this->resize(matrix_size_x, matrix_size_y, matrix_size_z, channels);
 +}
  
 -Image::Image(const Image &other) {
 +template <typename T> Image<T>::Image(const Image<T> &other) {
+     int err = 0;
      // This is a deep copy
-     ismrmrd_init_image(this);
-     ismrmrd_copy_image(this, &other);
+     err = ismrmrd_init_image(this);
+     if (err) {
+         throw std::runtime_error(build_exception_string());
+     }
+     err = ismrmrd_copy_image(this, &other);
+     if (err) {
+         throw std::runtime_error(build_exception_string());
+     }
  }
  
 -Image & Image::operator= (const Image &other) {
 +template <typename T> Image<T> & Image<T>::operator= (const Image<T> &other)
 +{
+     int err = 0;
      // Assignment makes a copy
      if (this != &other )
      {
@@@ -277,328 -373,98 +337,341 @@@
      return *this;
  }
  
 -Image::~Image() {
 +template <typename T> Image<T>::~Image() {
-     ismrmrd_cleanup_image(this);
+     if (ismrmrd_cleanup_image(this) != ISMRMRD_NOERROR) {
+         throw std::runtime_error(build_exception_string());
+     }
  }
  
 -// Accessors and mutators
 -const uint16_t &Image::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);    
++    if (ismrmrd_make_consistent_image(this) != ISMRMRD_NOERROR) {
++        throw std::runtime_error(build_exception_string());
++    }
 +}
  
 -const uint16_t &Image::data_type() {
 -    return head.data_type;
 -};
 +template <typename T> uint16_t Image<T>::getMatrixSizeX() const
 +{
 +    return this->head.matrix_size[0];
 +}
  
 -void Image::data_type(uint16_t dtype) {
 -    // TODO function to check if type is valid
 -    head.data_type = dtype;
 +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);    
+     if (ismrmrd_make_consistent_image(this) != ISMRMRD_NOERROR) {
+         throw std::runtime_error(build_exception_string());
+     }
 -};
 +}
  
 -const uint64_t &Image::flags() {
 -    return head.flags;
 -};
 +template <typename T> uint16_t Image<T>::getMatrixSizeY() const
 +{
 +    return this->head.matrix_size[1];
 +}
  
 -uint32_t &Image::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);    
++    if (ismrmrd_make_consistent_image(this) != ISMRMRD_NOERROR) {
++        throw std::runtime_error(build_exception_string());
++    }
 +}
  
 -const uint16_t (&Image::matrix_size())[3] {
 -    return head.matrix_size;
 -};
 +template <typename T> uint16_t Image<T>::getMatrixSizeZ() const
 +{
 +    return this->head.matrix_size[2];
 +}
  
 -void Image::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;
 -    }
 -    if (msize[2] > 0) {
 -        head.matrix_size[2] = msize[2];
 -    } else {
 -        head.matrix_size[2] = 1;
 +template <typename T> void Image<T>::setMatrixSizeZ(uint16_t matrix_size_z)
 +{
 +    if (matrix_size_z == 0) {
 +        matrix_size_z = 1;
      }
 +    this->head.matrix_size[2] = matrix_size_z;
-     ismrmrd_make_consistent_image(this);    
+     if (ismrmrd_make_consistent_image(this) != ISMRMRD_NOERROR) {
+         throw std::runtime_error(build_exception_string());
+     }
 -};
 -
 -float (&Image::field_of_view())[3] {
 -    return head.field_of_view;
 -};
 +}
  
 -const uint16_t &Image::channels() {
 -    return head.channels;
 -};
 +template <typename T> uint16_t Image<T>::getNumberOfChannels() const
 +{
 +    return this->head.channels;
 +}
  
 -void Image::channels(const uint16_t num_channels) {
 -    if (num_channels > 1) {
 -        head.channels = num_channels;
 -    } else {
 -        head.channels = 1;
 +template <typename T> void Image<T>::setNumberOfChannels(uint16_t channels)
 +{
 +    if (channels == 0) {
 +        channels = 1;
      }
++
 +    this->head.channels = channels;
-     ismrmrd_make_consistent_image(this);    
+     if (ismrmrd_make_consistent_image(this) != ISMRMRD_NOERROR) {
+         throw std::runtime_error(build_exception_string());
+     }
 -};
 +}
  
 -float (&Image::position())[3] {
 -    return head.position;
 -};
  
 -float (&Image::read_dir())[3] {
 -    return head.read_dir;
 -};
 +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;
 +}
  
 -float (&Image::phase_dir())[3] {
 -    return head.phase_dir;
 -};
 +template <typename T> void Image<T>::setFieldOfViewX(float fov_x)
 +{
 +    this->head.field_of_view[0] = fov_x;
 +}
  
 -float (&Image::slice_dir())[3] {
 -    return head.slice_dir;
 +template <typename T> float Image<T>::getFieldOfViewX() const
 +{
 +    return this->head.field_of_view[0];
 +}
 +
 +template <typename T> void Image<T>::setFieldOfViewY(float fov_y)
 +{
 +    this->head.field_of_view[1] = fov_y;
 +}
 +
 +template <typename T> float Image<T>::getFieldOfViewY() const
 +{
 +    return this->head.field_of_view[1];
 +}
 +
 +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;
  };
  
 -float (&Image::patient_table_position())[3] {
 -    return head.patient_table_position;
 +template <typename T> uint32_t &Image<T>::measurement_uid() {
 +    return head.measurement_uid;
  };
  
 -uint16_t &Image::average() {
 +template <typename T> uint16_t &Image<T>::average() {
      return head.average;
  };
  
@@@ -660,12 -526,14 +733,14 @@@ template <typename T> ImageHeader &Imag
      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);
+     if (ismrmrd_make_consistent_image(this) != ISMRMRD_NOERROR) {
+         throw std::runtime_error(build_exception_string());
+     }
  }
  
 -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());
@@@ -758,17 -642,17 +853,17 @@@ template <typename T> const size_t (&ND
      return dims;
  };
  
--template <typename T> int NDArray<T>::resize(const std::vector<size_t> dimvec) {
++template <typename T> void NDArray<T>::resize(const std::vector<size_t> dimvec) {
      if (dimvec.size() > ISMRMRD_NDARRAY_MAXDIM) {
--        // TODO throw exception
--        return ISMRMRD_MEMORYERROR;
++        throw std::runtime_error("Input vector dimvec is too long.");
      }
      ndim = dimvec.size();
      for (int n=0; n<ndim; n++) {
          dims[n] = dimvec[n];
      }
--    int status=ismrmrd_make_consistent_ndarray(this);
--    return status;
++    if (ismrmrd_make_consistent_ndarray(this) != ISMRMRD_NOERROR) {
++        throw std::runtime_error(build_exception_string());
++    }
  }
  
  template <typename T> T * NDArray<T>::getData() {

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