[ismrmrd] 85/281: kv_storage initial push to integrate more inheritance and checks
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Wed Jan 14 20:01:00 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 1d3da9cd9f81d8fe388efa853a96ff09a673bb24
Author: kvahed <kaveh at vahedipour.de>
Date: Tue Jan 29 17:07:17 2013 +0100
kv_storage initial push to integrate more inheritance and checks
---
CMakeLists.txt | 3 +
doc/doxygen/CMakeLists.txt | 2 +-
examples/c++/CMakeLists.txt | 3 +
examples/c++/test_recon_dataset.cpp | 4 +-
ismrmrd.h | 54 ++++++++++---
ismrmrd_hdf5.cpp | 7 +-
tests/c++/CMakeLists.txt | 10 +++
tests/c++/t_image.cpp | 20 +++++
tests/c++/t_ndarraycontainer.cpp | 152 ++++++++++++++++++++++++++++++++++++
tests/c++/t_template.cpp | 20 +++++
10 files changed, 259 insertions(+), 16 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 382efee..775683c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 2.8)
project(ISMRMRD)
+enable_testing()
+
if (WIN32)
ADD_DEFINITIONS(-DWIN32 -D_WIN32 -D_WINDOWS)
ADD_DEFINITIONS(-DUNICODE -D_UNICODE)
@@ -66,3 +68,4 @@ INSTALL(FILES ${MatlabMFiles} DESTINATION matlab/+ismrmrd)
add_subdirectory(doc)
add_subdirectory(examples/c++)
+add_subdirectory(tests/c++)
diff --git a/doc/doxygen/CMakeLists.txt b/doc/doxygen/CMakeLists.txt
index caa1691..0ddffaa 100644
--- a/doc/doxygen/CMakeLists.txt
+++ b/doc/doxygen/CMakeLists.txt
@@ -5,4 +5,4 @@ if(DOXYGEN_FOUND)
COMMENT "Generating API documentation with Doxygen" VERBATIM)
else(DOXYGEN_FOUND)
MESSAGE("Doxygen not found. Will not be able to build documentation")
-endif(DOXYGEN_FOUND)
\ No newline at end of file
+endif(DOXYGEN_FOUND)
diff --git a/examples/c++/CMakeLists.txt b/examples/c++/CMakeLists.txt
index b15c565..6620624 100644
--- a/examples/c++/CMakeLists.txt
+++ b/examples/c++/CMakeLists.txt
@@ -8,6 +8,9 @@ IF(FFTW3_FOUND)
add_executable(ismrmrd_recon_dataset test_recon_dataset.cpp)
target_link_libraries(ismrmrd_recon_dataset ${XERCESC_LIBRARIES} ismrmrd ismrmrd_xsd ${FFTW3_LIBRARIES})
INSTALL(TARGETS ismrmrd_recon_dataset DESTINATION bin)
+ add_executable(read_timing_test read_timing_test.cpp)
+ target_link_libraries(read_timing_test ${XERCESC_LIBRARIES} ismrmrd ismrmrd_xsd ${FFTW3_LIBRARIES})
+ INSTALL(TARGETS read_timing_test DESTINATION bin)
ELSE(FFTW3_FOUND)
MESSAGE("FFTW3 NOT Found....cannot build test applications")
ENDIF(FFTW3_FOUND)
diff --git a/examples/c++/test_recon_dataset.cpp b/examples/c++/test_recon_dataset.cpp
index 6bf87e6..2067691 100644
--- a/examples/c++/test_recon_dataset.cpp
+++ b/examples/c++/test_recon_dataset.cpp
@@ -92,7 +92,7 @@ int main(int argc, char** argv)
ISMRMRD::NDArrayContainer< std::complex<float> > buffer;
buffer.dimensions_.push_back(e_space.matrixSize().x());
buffer.dimensions_.push_back(e_space.matrixSize().y());
- buffer.data_.resize(e_space.matrixSize().x()*e_space.matrixSize().y(), std::complex<float>(0.0,0.0));
+ buffer.resize(e_space.matrixSize().x()*e_space.matrixSize().y(), std::complex<float>(0.0,0.0));
//Now loop through and copy data
@@ -104,7 +104,7 @@ int main(int argc, char** argv)
//Copy data, we should probably be more careful here and do more tests....
//We are not considering multiple channels here.
unsigned int offset = acq->head_.idx.kspace_encode_step_1*buffer.dimensions_[0];
- memcpy(&buffer.data_[offset],&acq->data_[0],sizeof(float)*2*buffer.dimensions_[0]);
+ memcpy(&buffer[offset],&acq->data_[0],sizeof(float)*2*buffer.dimensions_[0]);
}
//Let's FFT the k-space to image
diff --git a/ismrmrd.h b/ismrmrd.h
index 6e3636f..bc69d42 100644
--- a/ismrmrd.h
+++ b/ismrmrd.h
@@ -32,6 +32,7 @@ typedef unsigned __int64 uint64_t;
#include <iostream>
#include <vector>
#include <valarray>
+#include <assert.h>
#endif
#pragma pack(push, 2) //Use 2 byte alignment
@@ -211,6 +212,7 @@ struct ImageHeader
float user_float[8]; /**< Free user parameters */
};
+#ifdef __cplusplus
/**
* Container for generic array. This structure is used through the HDF5 file interaction.
*/
@@ -222,7 +224,15 @@ public:
/**
* @brief Construct with dimensions and data
*/
- NDArrayContainer(const std::vector<unsigned int>& dimensions, T* d) {
+ NDArrayContainer(const std::vector<unsigned int>& dimensions) {
+ dimensions_ = dimensions;
+ data_.resize(elements());
+ }
+
+ /**
+ * @brief Construct with dimensions and data
+ */
+ NDArrayContainer(const std::vector<unsigned int>& dimensions, const T* d) {
dimensions_ = dimensions;
data_.resize(elements());
memcpy(&data_[0],d,sizeof(T)*elements());
@@ -231,7 +241,7 @@ public:
/**
* @brief Construct with dimensions and preset value
*/
- NDArrayContainer(const std::vector<unsigned int>& dimensions, T t = T(0)) {
+ NDArrayContainer(const std::vector<unsigned int>& dimensions, const T& t) {
dimensions_ = dimensions;
data_.resize(elements());
data_ = t;
@@ -261,6 +271,14 @@ public:
T operator[] (const size_t& p) const {
return data_[p];
}
+
+ void resize (const size_t& s) {
+ data_.resize(s);
+ }
+
+ void resize (const size_t& s, const T& t) {
+ data_.resize(s,t);
+ }
bool is_consistent() const {
return (elements() == data_.size());
@@ -275,27 +293,30 @@ public:
};
-#ifdef __cplusplus
/**
* Container for an image (header and data)
*/
template <typename T>
class Image : public NDArrayContainer<T> {
-
+
public:
- Image() {
+ Image() :
+ NDArrayContainer<T>() {
memset(&head_,0,sizeof(ImageHeader));
head_.version = ISMRMRD_VERSION;
}
- ~Image() {}
-
- bool isFlagSet(FlagBit& f) const {
- return f.isSet(head_.flags);
+ Image (const std::vector<unsigned int>& dimensions, T* d) :
+ NDArrayContainer<T> (dimensions, d) {
+ head_.matrix_size[0] = dimensions_[0];
+ head_.matrix_size[1] = dimensions_[1];
+ head_.matrix_size[2] = dimensions_[2];
+ head_.channels = dimensions_[3];
}
- void setFlag(FlagBit& f) {
- head_.flags |= f.bitmask_;
+ Image (const std::vector<unsigned int>& dimensions, T t = T(0)) :
+ NDArrayContainer<T> (dimensions, t) {
+ //allocate();
}
Image(const Image& a) { // copy constructor
@@ -313,6 +334,16 @@ public:
return *this;
}
+ ~Image() {}
+
+ bool isFlagSet(FlagBit& f) const {
+ return f.isSet(head_.flags);
+ }
+
+ void setFlag(FlagBit& f) {
+ head_.flags |= f.bitmask_;
+ }
+
size_t getNumberOfElements() const {
return head_.matrix_size[0]*
head_.matrix_size[1]*
@@ -321,6 +352,7 @@ public:
}
ImageHeader head_; /**< ImageHeader as defined above */
+ static const unsigned short MAX_IMAGE_DIMS;
};
diff --git a/ismrmrd_hdf5.cpp b/ismrmrd_hdf5.cpp
index 5cbaf73..1ee7812 100644
--- a/ismrmrd_hdf5.cpp
+++ b/ismrmrd_hdf5.cpp
@@ -171,7 +171,8 @@ template <typename T> int IsmrmrdDataset::appendArray(NDArrayContainer<T>& a, co
for (unsigned int i = 1; i < ddims.size(); i++) {
if (a.dimensions_[ddims.size()-1-i] != ddims[i]) {
std::cerr << "Error trying to write array to existing HDF5 file. Variable has wrong size." << std::endl;
- std::cerr << a.dimensions_[ddims.size()-1-i] << ", " << ddims[i] << std::endl;
+ std::cerr << a.dimensions_[ddims.size()-1-i] << ", " << ddims[i];
+ std::cerr << std::endl;
return -1;
}
dims.push_back(ddims[i]);
@@ -531,7 +532,9 @@ template <typename T> boost::shared_ptr< Image<T> > IsmrmrdDataset::readImage(co
boost::shared_ptr<NDArrayContainer<ImageHeader_with_data<T> > > tmp = readArray<ImageHeader_with_data<T> >(varname, index);
if (tmp->elements() != 1) {
- std::cerr << "IsmrmrdDataset::readImage(..): readArray returned an unexpected number of elements (" << tmp->elements() << "). Should be 1." << std::endl;
+ std::cerr << "IsmrmrdDataset::readImage(..): readArray returned an unexpected number of elements (";
+ std::cerr << tmp->elements() << "). Should be 1.";
+ std::cerr << std::endl;
return ret;
}
//We will copy the header
diff --git a/tests/c++/CMakeLists.txt b/tests/c++/CMakeLists.txt
new file mode 100644
index 0000000..465da23
--- /dev/null
+++ b/tests/c++/CMakeLists.txt
@@ -0,0 +1,10 @@
+enable_testing()
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../..)
+
+add_executable(t_ndarraycontainer t_ndarraycontainer.cpp)
+target_link_libraries(t_ndarraycontainer ${XERCESC_LIBRARIES} ismrmrd ismrmrd_xsd)
+add_test(t_ndarraycontainer ${CMAKE_CURRENT_BINARY_DIR}/t_ndarraycontainer)
+
+add_executable(t_image t_image.cpp)
+target_link_libraries(t_image ${XERCESC_LIBRARIES} ismrmrd ismrmrd_xsd)
+add_test(t_image ${CMAKE_CURRENT_BINARY_DIR}/t_image)
diff --git a/tests/c++/t_image.cpp b/tests/c++/t_image.cpp
new file mode 100644
index 0000000..67f7ab2
--- /dev/null
+++ b/tests/c++/t_image.cpp
@@ -0,0 +1,20 @@
+#include <iostream>
+#include "ismrmrd_hdf5.h"
+#include "ismrmrd.hxx"
+
+
+
+int main (int args, char** argv) {
+
+ using namespace ISMRMRD;
+
+ std::vector <unsigned> dims;
+ dims.push_back (32);
+ dims.push_back (64);
+
+ Image<std::complex<float> > img_s (dims);
+
+ return 0;
+
+
+}
diff --git a/tests/c++/t_ndarraycontainer.cpp b/tests/c++/t_ndarraycontainer.cpp
new file mode 100644
index 0000000..0b30314
--- /dev/null
+++ b/tests/c++/t_ndarraycontainer.cpp
@@ -0,0 +1,152 @@
+#include <iostream>
+#include "ismrmrd_hdf5.h"
+#include "ismrmrd.hxx"
+#include <time.h>
+#include <stdlib.h>
+#include <limits>
+
+using namespace ISMRMRD;
+
+template<class T>
+struct populate;
+
+template<> struct populate <float> {
+
+ typedef float type;
+
+ static void random (NDArrayContainer<type>& ndac) {
+ type mi = (type) std::numeric_limits<int>::max();
+ assert (ndac.is_consistent());
+ size_t i = ndac.elements();
+ size_t j = ndac.data_.size();
+ for (; i>=1; i--)
+ ndac[i] = 1.0 - 2.0 * (type)rand() / mi;
+ }
+
+};
+
+template<> struct populate <double> {
+
+ typedef double type;
+
+ static void random (NDArrayContainer<type>& ndac) {
+ type mi = (type) std::numeric_limits<int>::max();
+ assert (ndac.is_consistent());
+ size_t i = ndac.elements();
+ size_t j = ndac.data_.size();
+ for (; i>=1; i--)
+ ndac[i] = 1.0 - 2.0 * (type)rand() / mi;
+ }
+
+};
+
+template<> struct populate <std::complex<float> > {
+
+ typedef float rtype;
+ typedef std::complex<rtype> type;
+
+ static void random (NDArrayContainer<type>& ndac) {
+ rtype mi = std::numeric_limits<int>::max();
+ assert (ndac.is_consistent());
+ size_t i = ndac.elements();
+ size_t j = ndac.data_.size();
+ for (; i>=1; i--)
+ ndac[i] = type(1.0, 1.0) - type(2.0 * (rtype)rand() / mi, 2.0 * (rtype)rand() / mi);
+ }
+
+};
+
+template<> struct populate <std::complex<double> > {
+
+ typedef double rtype;
+ typedef std::complex<rtype> type;
+
+ static void random (NDArrayContainer<type>& ndac) {
+ rtype mi = std::numeric_limits<int>::max();
+ assert (ndac.is_consistent());
+ size_t i = ndac.elements();
+ size_t j = ndac.data_.size();
+ for (; i>=1; i--)
+ ndac[i] = type(1.0, 1.0) - type(2.0 * (rtype)rand() / mi, 2.0 * (rtype)rand() / mi);
+ }
+
+};
+
+template<> struct populate <int> {
+
+ typedef int type;
+
+ static void random (NDArrayContainer<type>& ndac) {
+ type mi = (type) std::numeric_limits<type>::max();
+ assert (ndac.is_consistent());
+ size_t i = ndac.elements();
+ size_t j = ndac.data_.size();
+ for (; i>=1; i--)
+ ndac[i] = rand();
+ }
+
+};
+
+template<> struct populate <short> {
+
+ typedef short type;
+
+ static void random (NDArrayContainer<type>& ndac) {
+ type mi = (type) std::numeric_limits<type>::max();
+ assert (ndac.is_consistent());
+ size_t i = ndac.elements();
+ size_t j = ndac.data_.size();
+ for (; i>=1; i--)
+ ndac[i] = rand();
+ }
+
+};
+
+template<> struct populate <long> {
+
+ typedef long type;
+
+ static void random (NDArrayContainer<type>& ndac) {
+ type mi = (type) std::numeric_limits<type>::max();
+ assert (ndac.is_consistent());
+ size_t i = ndac.elements();
+ size_t j = ndac.data_.size();
+ for (; i>=1; i--)
+ ndac[i] = rand();
+ }
+
+};
+
+int main (int args, char** argv) {
+
+ srand(time(NULL));
+
+ std::vector <unsigned> dims;
+ dims.push_back (10);
+ dims.push_back (8);
+ dims.push_back (7);
+
+ NDArrayContainer<float> ndac_s (dims);
+ populate<float>::random (ndac_s);
+
+ NDArrayContainer<double> ndac_d (dims);
+ populate<double>::random (ndac_d);
+
+ NDArrayContainer<std::complex<float> > ndac_c (dims);
+ populate<std::complex<float> >::random (ndac_c);
+
+ NDArrayContainer<std::complex<double> > ndac_z (dims);
+ populate<std::complex<double> >::random (ndac_z);
+
+ NDArrayContainer<int> ndac_i (dims);
+ populate<int>::random (ndac_i);
+
+ NDArrayContainer<short> ndac_si (dims);
+ populate<short>::random (ndac_si);
+
+ NDArrayContainer<long> ndac_li (dims);
+ populate<long>::random (ndac_li);
+
+ return 0;
+
+}
diff --git a/tests/c++/t_template.cpp b/tests/c++/t_template.cpp
new file mode 100644
index 0000000..444bc49
--- /dev/null
+++ b/tests/c++/t_template.cpp
@@ -0,0 +1,20 @@
+#include <iostream>
+#include "ismrmrd_hdf5.h"
+#include "ismrmrd.hxx"
+
+template <T> random_fill () {
+}
+
+int main (int args, char** argv) {
+
+ std::vector <unsigned> dims;
+ dims.push_back (10);
+ dims.push_back (8);
+ dims.push_back (7);
+
+ NDArrayContainer<float> ndcs (dims);
+
+ 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