[ismrmrd] 211/281: add image attrib support

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Wed Jan 14 20:01:16 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 cfe48a4377476f7d65ea88bc98062039e618d643
Author: xueh2 <hui.xue at nih.gov>
Date:   Tue Mar 11 11:19:09 2014 -0400

    add image attrib support
---
 CMakeLists.txt           | 14 +++++---
 ismrmrd_hdf5.cpp         | 88 ++++++++++++++++++++++++++++++++++++++++++++++++
 ismrmrd_hdf5.h           |  4 +++
 ismrmrd_hdf5_datatypes.h |  7 ++++
 4 files changed, 108 insertions(+), 5 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 49d1ba1..dbd2fe9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,11 +4,15 @@ project(ISMRMRD)
 enable_testing()
 
 if (WIN32)
-ADD_DEFINITIONS(-DWIN32 -D_WIN32 -D_WINDOWS)
-ADD_DEFINITIONS(-DUNICODE -D_UNICODE)
-ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
-SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
-SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3")
+    ADD_DEFINITIONS(-DWIN32 -D_WIN32 -D_WINDOWS)
+    ADD_DEFINITIONS(-DUNICODE -D_UNICODE)
+    ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
+    SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
+    SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3")
+    SET (CMAKE_EXE_LINKER_FLAGS_DEBUG "/debug /INCREMENTAL:NO")
+    SET (CMAKE_SHARED_LINKER_FLAGS_DEBUG "/debug /INCREMENTAL:NO")
+    SET (CMAKE_STATIC_LINKER_FLAGS_DEBUG "/debug /INCREMENTAL:NO")
+    SET (CMAKE_MODULE_LINKER_FLAGS_DEBUG "/debug /INCREMENTAL:NO")
 endif (WIN32)
 
 set(CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/ismrmrd)
diff --git a/ismrmrd_hdf5.cpp b/ismrmrd_hdf5.cpp
index 4786218..37654f7 100644
--- a/ismrmrd_hdf5.cpp
+++ b/ismrmrd_hdf5.cpp
@@ -578,6 +578,94 @@ template EXPORTISMRMRD boost::shared_ptr< Image<unsigned short> > IsmrmrdDataset
 template EXPORTISMRMRD boost::shared_ptr< Image< std::complex<float> > > IsmrmrdDataset::readImage(const char* varname, unsigned long index);
 template EXPORTISMRMRD boost::shared_ptr< Image< std::complex<double> > > IsmrmrdDataset::readImage(const char* varname, unsigned long index);
 
+int IsmrmrdDataset::appendImageAttrib(std::string& a, const char* varname)
+{
+	std::string data_path = groupname_ + std::string("/") + std::string(varname);
+
+	boost::shared_ptr<DataSet> dataset;
+    boost::shared_ptr<DataType> datatype = getIsmrmrdHDF5Type<std::string>();
+
+	std::vector<hsize_t> dims;
+	std::vector<hsize_t> max_dims;
+	if (!linkExists(data_path.c_str()))
+    {
+		std::vector<hsize_t> dims(1,1);
+		std::vector<hsize_t> max_dims(1,1);
+
+		try
+        {
+			if (createGroupForDataset(groupname_.c_str()) < 0)
+            {
+				std::cout << "Failed to create group in HDF 5 file." << std::endl;
+				return -1;
+			}
+
+			DataSpace mspace1( dims.size(), &dims[0], &max_dims[0]);
+
+			DSetCreatPropList cparms;
+			cparms.setChunk( dims.size(), &dims[0] );
+
+			dataset = boost::shared_ptr<DataSet>(new DataSet(file_->createDataSet( data_path.c_str(), *datatype, mspace1, cparms)));
+			mspace1 = dataset->getSpace();
+
+			DataSpace mspace2( dims.size(), &dims[0] );
+
+			std::vector<hsize_t> offset(dims.size());
+			mspace1.selectHyperslab(H5S_SELECT_SET, &dims[0], &offset[0]);
+			dataset->write( a, *datatype, mspace2, mspace1 );
+
+		} catch( Exception& e ) {
+			std::cerr << "Exception caught while creating HDF5 dataset" << std::endl;
+			std::cerr << e.getDetailMsg() << std::endl;
+			return -1;
+		}
+	}
+    else
+    {
+		try
+        {  // to determine if the dataset exists in the group
+			dataset = boost::shared_ptr<DataSet>(new DataSet(file_->openDataSet(data_path.c_str())));
+
+			DataType mtype = dataset->getDataType();
+			if (!(mtype == (*datatype))) {
+				std::cout << "Attempting to append data to HDF5 dataset with the wrong type" << std::endl;
+				return -1;
+			}
+
+			DataSpace mspace1 = dataset->getSpace();
+			int rank = mspace1.getSimpleExtentNdims();
+			std::vector<hsize_t> ddims(rank,0);
+			mspace1.getSimpleExtentDims(&ddims[0], NULL);
+
+			dims.push_back(1);
+			for (unsigned int i = 1; i < ddims.size(); i++)
+            {
+				dims.push_back(ddims[i]);
+			}
+
+			std::vector<hsize_t> offset(rank, 0);
+			offset[0] = ddims[0];
+
+			ddims[0]++;
+
+			dataset->extend(&ddims[0]);
+
+			DataSpace fspace2 = dataset->getSpace();
+			fspace2.selectHyperslab( H5S_SELECT_SET, &dims[0], &offset[0] );
+
+			DataSpace mspace2( rank, &dims[0] );
+
+			dataset->write( a, *datatype, mspace2, fspace2 );
+
+		 }
+		 catch( FileIException& not_found_error)
+		 {
+			 std::cout << "Dataset is not found. At this point, it should have been created!" << std::endl;
+			 return -1;
+		 }
+	}
+	return 0;
+}
 
 HDF5Lock* HDF5Lock::instance()
 {
diff --git a/ismrmrd_hdf5.h b/ismrmrd_hdf5.h
index 538eaba..c71c716 100644
--- a/ismrmrd_hdf5.h
+++ b/ismrmrd_hdf5.h
@@ -175,6 +175,10 @@ public:
 	template <typename T> boost::shared_ptr< NDArrayContainer<T> > readArray(const char* varname, unsigned long index = 0);
 
 
+    /**
+	 *  This function appends the meta attribute information to the data set. The meta attributes are stored as an xml file.
+	 */
+	int appendImageAttrib(std::string& a, const char* varname);
 
 protected:
 	int openHDF5File();
diff --git a/ismrmrd_hdf5_datatypes.h b/ismrmrd_hdf5_datatypes.h
index ea6e75f..27e4528 100644
--- a/ismrmrd_hdf5_datatypes.h
+++ b/ismrmrd_hdf5_datatypes.h
@@ -10,6 +10,7 @@
 
 #include <vector>
 #include <complex>
+#include <string>
 
 #ifndef H5_NO_NAMESPACE
 	using namespace H5;
@@ -334,6 +335,12 @@ template <> inline boost::shared_ptr<DataType> getIsmrmrdHDF5Type<ImageHeader_wi
 	return getIsmrmrdHDF5Type<ImageHeader_with_data<double_complex_t> >();
 }
 
+template <> inline boost::shared_ptr<DataType> getIsmrmrdHDF5Type<std::string>()
+{
+	boost::shared_ptr<DataType> ret(new StrType(0, H5T_VARIABLE));
+	return ret;
+}
+
 }
 
 #endif /* ISMRMRD_HDF5_DATATYPES_H_ */

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