[ismrmrd] 08/281: Improved HDF5 saving support

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Wed Jan 14 20:00:49 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to annotated tag ismrmrd0.5
in repository ismrmrd.

commit 8e37561afba3077c7381d38ed3382992f9a16c88
Author: Michael S. Hansen <michael.hansen at nih.gov>
Date:   Fri Aug 3 15:54:07 2012 -0400

    Improved HDF5 saving support
---
 CMakeLists.txt           |  1 +
 cmake/FindIsmrmrd.cmake  | 17 ++++++-------
 doc/README.rst           | 61 ++++++++++++++++++++++++++++++++++++++++++++++
 ismrmrd.h                | 63 ++++++++++++++++++++++++++++++++++++++++++++++--
 ismrmrd_hdf5.cpp         | 38 +++++++++++++++++++++++++++--
 ismrmrd_hdf5.h           |  1 +
 ismrmrd_hdf5_datatypes.h |  2 +-
 7 files changed, 169 insertions(+), 14 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index f3719cd..59fef28 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,7 @@
 cmake_minimum_required(VERSION 2.8)
 project(ISMRMRD)
 
+set(CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/ismrmrd)
 list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
 
 find_package(XSD REQUIRED)
diff --git a/cmake/FindIsmrmrd.cmake b/cmake/FindIsmrmrd.cmake
index 7120f31..0532731 100644
--- a/cmake/FindIsmrmrd.cmake
+++ b/cmake/FindIsmrmrd.cmake
@@ -1,18 +1,17 @@
 # - Find ISMRMRRD
-#   ISMRMRD_FOUND       - True if ISMRMRD found.
-#   ISMRMRD_INCLUDE_DIR - where to find ismrmrd.h, etc.
+#   ISMRMRD_FOUND        - True if ISMRMRD found.
+#   ISMRMRD_INCLUDE_DIR  - where to find ismrmrd.h, etc.
 #   ISMRMRD_LIBRARIES    - libismrmrd.so, etc.
+#   ISMRMRD_SCHEMA_DIR   - Where to find ismrmrd.xsd       
 
-MESSAGE("GADGETRON_HOME: $ENV{GADGETRON_HOME}")
-
-FIND_PATH( ISMRMRD_INCLUDE_DIR ismrmrd.h
-$ENV{GADGETRON_HOME}/include /usr/local/include)
+FIND_PATH( ISMRMRD_INCLUDE_DIR ismrmrd.h PATHS /usr/local/ /usr/include /usr/local/include PATH_SUFFIXES ismrmrd ismrmrd/include)
+FIND_PATH( ISMRMRD_SCHEMA_DIR  ismrmrd.xsd PATHS /usr/local/ /usr/include /usr/local/include PATH_SUFFIXES ismrmrd ismrmrd/schema)
 
 FIND_LIBRARY( ISMRMRD_LIBRARIES
               NAMES "ismrmrd"
-              PATHS  $ENV{GADGETRON_HOME}/lib /usr/local/lib)
+              PATHS  /usr/local/lib ${ISMRMRD_INCLUDE_DIR}/../lib /usr/lib )
 
 INCLUDE( "FindPackageHandleStandardArgs" )
-FIND_PACKAGE_HANDLE_STANDARD_ARGS( "Ismrmrd" DEFAULT_MSG ISMRMRD_INCLUDE_DIR ISMRMRD_LIBRARIES)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS( "Ismrmrd" DEFAULT_MSG ISMRMRD_INCLUDE_DIR ISMRMRD_LIBRARIES ISMRMRD_SCHEMA_DIR)
 
-MARK_AS_ADVANCED( ISMRMRD_INCLUDE_DIR ISMRMRD_LIBRARIES)
\ No newline at end of file
+MARK_AS_ADVANCED( ISMRMRD_INCLUDE_DIR ISMRMRD_LIBRARIES ISMRMRD_SCHEMA_DIR)
diff --git a/doc/README.rst b/doc/README.rst
new file mode 100644
index 0000000..b1c41da
--- /dev/null
+++ b/doc/README.rst
@@ -0,0 +1,61 @@
+Magnetic Resonance Raw Data Standard
+*************************************
+
+DRAFT - Version 0.1 - July 2012
+
+TODO
+-------------------------
+
+* Make Example Datasets
+
+	- Cartesian 2D/3D
+	- Partial Fourier
+	- Spiral
+	- Radial
+	- Diffusion
+	- Phase contrast flow
+
+* Flag definitions.
+
+	- Do we need more flags?
+
+* Converters for vendor raw data 
+
+	- Siemens (Hansen)
+	- Philips (Kozerke? Boernert?)
+	- GE (Hargreaves?)
+	- Bruker (Hansen?)
+
+Change log
+----------
+
+August 2012 - First draft.
+
+Preamble
+---------
+
+A prerequisite for sharing magnetic resonance (imaging) reconstruction algorithms and code is a common raw data format. This document describes such a common raw data format and attempts to capture all the data fields that are require to describe enough details about the magnetic resonance experiment to reconstruct images from the data.
+
+This standard was developed by a subcommittee of the ISMRM Sedona 2013 workshop. Comments and requests for additions/modifications can be sent to:
+
+Michael S. Hansen, Chair (michael.hansen at nih.gov)
+Wally Block (wblock at cae.wisc.edu)
+Mark Griswold (mag46 at case.edu)
+Brian Hargreaves (bah at stanford.edu)
+Peter Boernert (peter.boernert at philips.com)
+
+
+Overview
+---------
+
+The raw data format combines a mix of flexible data structures (XML) and fixed structures (equivalent to C-structs). A raw data sey consist of 3 sections:
+
+1. A flexible XML format document that can contain an arbitrary number of fields and accomodate everything from simple values (b-values, etc.) to entire vendor protocols, etc. This purpose of this XML document is to provide parameters that may be meaningful for some experiments but not for others. 
+2. A fixed struct describing encoding limits. This is a C-struct which describes minimum, maximum, and center encoding indices for all encoded dimensions. 
+3. Raw data section. This section contains all the acquired data in the experiment. Each data item is preceeded by a C-struct with encoding number, etc. Following this data header is a channel header and data for each acquired channel.
+
+
+Fixed Data structures
+----------------------
+
+::
diff --git a/ismrmrd.h b/ismrmrd.h
index 04aaddf..4b10bbc 100644
--- a/ismrmrd.h
+++ b/ismrmrd.h
@@ -24,6 +24,8 @@ typedef unsigned __int64 uint64_t;
 
 #include <stdio.h>
 #include <string.h>
+#include <exception>
+#include <iostream>
 
 #pragma pack(push, 4) //Use 4 byte alignment
 
@@ -151,8 +153,7 @@ namespace ISMRMRD
      }
 
    ~Acquisition() {
-     if (traj_) delete [] traj_;
-     if (data_) delete [] data_;
+	   deleteData();
    }
 
    bool isFlagSet(FlagBit f) {
@@ -163,6 +164,58 @@ namespace ISMRMRD
 	   head_.flags |= f.bitmask_;
    }
 
+   Acquisition(const Acquisition& a) {   // copy constructor
+	   head_ = a.head_;
+	   if (head_.trajectory_dimensions > 0) {
+		   size_t trajectory_elements = head_.number_of_samples*head_.trajectory_dimensions;
+		   try {
+			   traj_ = new float[trajectory_elements];
+		   } catch (std::exception& e) {
+			   std::cerr << "Unable to allocate trajectory in ISMRMRD::Acquisition: " << e.what() << std::endl;
+		   }
+		   memcpy(traj_,a.traj_,sizeof(float)*trajectory_elements);
+	   } else {
+		   traj_ = 0;
+	   }
+
+	   size_t data_elements = head_.number_of_samples*head_.active_channels;
+	   if (data_elements > 0) {
+		   try {
+			   data_ = new float[data_elements*2]; //*2 for complex
+		   } catch (std::exception& e) {
+			   std::cerr << "Unable to allocate trajectory in ISMRMRD::Acquisition: " << e.what() << std::endl;
+		   }
+		   memcpy(data_,a.data_,sizeof(float)*2*data_elements);
+	   } else {
+		   data_ = 0;
+	   }
+   }
+
+   Acquisition& operator=(const Acquisition& a) {
+	   head_ = a.head_;
+	   deleteData();
+	   if (head_.trajectory_dimensions > 0) {
+		   size_t trajectory_elements = head_.number_of_samples*head_.trajectory_dimensions;
+		   try {
+			   traj_ = new float[trajectory_elements];
+		   } catch (std::exception& e) {
+			   std::cerr << "Unable to allocate trajectory in ISMRMRD::Acquisition: " << e.what() << std::endl;
+		   }
+		   memcpy(traj_,a.traj_,sizeof(float)*trajectory_elements);
+	   }
+
+	   size_t data_elements = head_.number_of_samples*head_.active_channels;
+	   if (data_elements > 0) {
+		   try {
+			   data_ = new float[data_elements*2]; //*2 for complex
+		   } catch (std::exception& e) {
+			   std::cerr << "Unable to allocate trajectory in ISMRMRD::Acquisition: " << e.what() << std::endl;
+		   }
+		   memcpy(data_,a.data_,sizeof(float)*2*data_elements);
+	   }
+	   return *this;
+   }
+
    AcquisitionHeader head_; //Header, see above
    
    float* traj_;            //Trajectory, elements = head_.trajectory_dimensions*head_.number_of_samples
@@ -172,6 +225,12 @@ namespace ISMRMRD
    float* data_;            //Actual data, elements = head_.number_of_samples*head_.active_channels*2 
                             //   [re,im,re,im,.....,re,im,re,im,.....,re,im,re,im,.....]
                             //    ---channel 1-------channel 2---------channel 3-----
+
+ protected:
+   void deleteData() {
+	 if (traj_) {delete [] traj_; traj_ = 0;}
+	 if (data_) {delete [] data_; data_ = 0;}
+   }
  };
 
 } //End of ISMRMRD namespace
diff --git a/ismrmrd_hdf5.cpp b/ismrmrd_hdf5.cpp
index 865d7c2..00d1ecc 100644
--- a/ismrmrd_hdf5.cpp
+++ b/ismrmrd_hdf5.cpp
@@ -46,7 +46,7 @@ bool IsmrmrdDataset::linkExists(const char* name)
 {
 	if (!file_open_) {
 		std::cerr << "IsmrmrdDataset::linkExists: file not open." << std::endl;
-		return -1;
+		return false;
 	}
 	std::vector<std::string> name_elements;
 	std::string splitstr("/");
@@ -163,6 +163,40 @@ int IsmrmrdDataset::appendAcquisition(Acquisition* a)
 	return 0;
 }
 
+unsigned long IsmrmrdDataset::getNumberOfAcquisitions()
+{
+	unsigned long ret = 0;
+
+	if (!linkExists(data_path_.c_str())) {
+		std::cerr << "Data path (" << data_path_ << ") does not exist in HDF5 dataset" << std::endl;
+		return ret;
+	}
+
+	if (!dataset_open_) {
+		try{
+			dataset_ = boost::shared_ptr<DataSet>(new DataSet(file_->openDataSet(data_path_.c_str())));
+			dataset_open_ = true;
+		} catch( Exception& e ) {
+			std::cout << "Exception caught while opening HDF5 dataset" << std::endl;
+			std::cout << e.getDetailMsg() << std::endl;
+			return ret;
+		}
+	}
+
+	try {
+		DataSpace dataspace = dataset_->getSpace();
+		int rank = dataspace.getSimpleExtentNdims();
+		std::vector<hsize_t> dims(rank,0);
+		dataspace.getSimpleExtentDims(&dims[0]);
+		ret = dims[0];
+	} catch (...) {
+		std::cout << "Error caught while attempting to access the number of elements in HDF5 file" << std::endl;
+		return ret;
+	}
+
+	return ret;
+}
+
 boost::shared_ptr< Acquisition > IsmrmrdDataset::readAcquisition(unsigned long int index)
 {
 	boost::shared_ptr<Acquisition> ret;
@@ -202,7 +236,7 @@ boost::shared_ptr< Acquisition > IsmrmrdDataset::readAcquisition(unsigned long i
 			return ret;
 		}
 
-		std::vector<hsize_t> slice_dims(rank,0);
+		std::vector<hsize_t> slice_dims(rank,1);
 		std::vector<hsize_t> offset(rank,0);
 
 		slice_dims[0] = 1;
diff --git a/ismrmrd_hdf5.h b/ismrmrd_hdf5.h
index f8c992d..3630198 100644
--- a/ismrmrd_hdf5.h
+++ b/ismrmrd_hdf5.h
@@ -51,6 +51,7 @@ public:
 
 	boost::shared_ptr<std::string> readHeader();
 	boost::shared_ptr<Acquisition> readAcquisition(unsigned long index = 0);
+	unsigned long getNumberOfAcquisitions();
 
 protected:
 	int openHDF5File();
diff --git a/ismrmrd_hdf5_datatypes.h b/ismrmrd_hdf5_datatypes.h
index 22865fb..a3f07fa 100644
--- a/ismrmrd_hdf5_datatypes.h
+++ b/ismrmrd_hdf5_datatypes.h
@@ -122,7 +122,7 @@ template <> boost::shared_ptr<DataType> getIsmrmrdHDF5Type<AcquisitionHeader_wit
 
 
 	ret->insertMember( "head",  HOFFSET(AcquisitionHeader_with_data,head),   	*head_type);
-	ret->insertMember( "traj", HOFFSET(AcquisitionHeader_with_data,traj),  		*cxvdatatype);
+	ret->insertMember( "traj", HOFFSET(AcquisitionHeader_with_data,traj),  		*realvdatatype);
 	ret->insertMember( "data", HOFFSET(AcquisitionHeader_with_data,data),  		*cxvdatatype);
 	return ret;
 }

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