[ismrmrd] 245/281: More work on XML interface
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Wed Jan 14 20:01:20 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 b641ca96e57d187348c1e5b384a7496503933bbb
Author: Michael S. Hansen <michael.hansen at nih.gov>
Date: Fri Aug 8 15:16:47 2014 -0400
More work on XML interface
---
xml/CMakeLists.txt | 27 ++++-
xml/ismrmrd_xml.cpp | 97 +++++++++++++++-
xml/ismrmrd_xml.h | 316 ++++++++++++++++++++++++++++++++++++++++++++++------
3 files changed, 403 insertions(+), 37 deletions(-)
diff --git a/xml/CMakeLists.txt b/xml/CMakeLists.txt
index a29b4b6..74e4d12 100644
--- a/xml/CMakeLists.txt
+++ b/xml/CMakeLists.txt
@@ -4,8 +4,31 @@ add_library(ismrmrd_xml SHARED
pugixml.cpp
)
+
+include_directories(${ISMRMRD_SOURCE_DIR})
+
+add_executable(dump_ismrmrd_header
+ dump_ismrmrd_header.cpp
+)
+
+target_link_libraries(dump_ismrmrd_header
+ ismrmrd
+ ismrmrd_xml)
+
+if(WIN32)
+ target_link_libraries(ismrmrd_xml optimized ${HDF5_hdf5_LIBRARY_RELEASE}
+ optimized ${HDF5_hdf5_cpp_LIBRARY_RELEASE})
+ target_link_libraries(ismrmrd_xml debug ${HDF5_hdf5_LIBRARY_DEBUG}
+ debug ${HDF5_hdf5_cpp_LIBRARY_DEBUG})
+ target_link_libraries(ismrmrd_xml ${Boost_LIBRARIES})
+else(WIN32)
+ target_link_libraries(ismrmrd_xml ${HDF5_LIBRARIES} ${Boost_THREAD_LIBRARY}
+ ${Boost_SYSTEM_LIBRARY})
+endif(WIN32)
+
install (FILES ismrmrd_xml.h
- DESTINATION include)
+ DESTINATION ${ISMRMRD_INSTALL_INCLUDE_DIR})
-install (TARGETS ismrmrd_xml DESTINATION lib)
+install (TARGETS ismrmrd_xml DESTINATION ${ISMRMRD_INSTALL_LIB_DIR})
+install (TARGETS dump_ismrmrd_header DESTINATION ${ISMRMRD_INSTALL_BIN_DIR})
diff --git a/xml/ismrmrd_xml.cpp b/xml/ismrmrd_xml.cpp
index 1d979ff..0f2c0f0 100644
--- a/xml/ismrmrd_xml.cpp
+++ b/xml/ismrmrd_xml.cpp
@@ -1,8 +1,103 @@
#include "ismrmrd_xml.h"
-
+#include "pugixml.hpp"
+#include <cstdlib>
namespace ISMRMRD
{
+ IsmrmrdHeaderProxy::IsmrmrdHeaderProxy(const char* xml)
+ {
+ deserialize(xml);
+ }
+
+ IsmrmrdHeaderProxy::IsmrmrdHeaderProxy(const std::string& xml)
+ {
+ deserialize(xml.c_str());
+ }
+
+ IsmrmrdHeaderProxy::IsmrmrdHeaderProxy()
+ {
+
+ }
+
+ IsmrmrdHeaderProxy::IsmrmrdHeaderProxy(const IsmrmrdHeader& h)
+ {
+ h_ = h;
+ }
+
+ IsmrmrdHeaderProxy& IsmrmrdHeaderProxy::operator=(const IsmrmrdHeader& h)
+ {
+ h_ = h;
+ return *this;
+ }
+
+ void IsmrmrdHeaderProxy::deserialize(const char* xml)
+ {
+ pugi::xml_document doc;
+ pugi::xml_parse_result result = doc.load(xml);
+
+ pugi::xml_node root = doc.child("ismrmrdHeader");
+
+ if (root) {
+ pugi::xml_node subjectInformation = root.child("subjectInformation");
+ pugi::xml_node studyInformation = root.child("studyInformation");
+ pugi::xml_node measurementInformation = root.child("measurementInformation");
+ pugi::xml_node acquisitionSystemInformation = root.child("acquisitionSystemInformation");
+ pugi::xml_node experimentalConditions = root.child("experimentalConditions");
+ pugi::xml_node encoding = root.child("encoding");
+ pugi::xml_node parallelImaging = root.child("parallelImaging");
+ pugi::xml_node sequenceParameters = root.child("sequenceParameters");
+ pugi::xml_node dicomeParameters = root.child("dicomParameters");
+ pugi::xml_node userParameters = root.child("userParameters");
+
+ //Parsing experimentalConditions
+ if (!experimentalConditions) {
+ throw std::runtime_error("experimentalConditions not defined in ismrmrdHeader");
+ } else {
+ ExperimentalConditions e;
+ e.H1resonanceFrequency_Hz = std::atoi(experimentalConditions.child_value("H1resonanceFrequency_Hz"));
+ h_.experimentalConditions = e;
+ }
+
+
+ //Parsing encoding section
+ if (!encoding) {
+ throw std::runtime_error("encoding section not found in ismrmrdHeader");
+ } else {
+ while (encoding) {
+
+ encoding = encoding.next_sibling("encoding");
+ }
+
+ }
+
+ if (subjectInformation) {
+
+ }
+
+ if (studyInformation) {
+
+ }
+
+ if (measurementInformation) {
+
+ }
+
+ if (acquisitionSystemInformation) {
+
+ }
+
+
+ } else {
+ throw std::runtime_error("Root node 'ismrmrdHeader' not found");
+ }
+
+ }
+
+
+ void serialize(std::ostream& o)
+ {
+
+ }
}
diff --git a/xml/ismrmrd_xml.h b/xml/ismrmrd_xml.h
index 395d9e0..8b60b9c 100644
--- a/xml/ismrmrd_xml.h
+++ b/xml/ismrmrd_xml.h
@@ -8,6 +8,16 @@
#include <string.h>
#include <iostream>
+
+/*
+ TODO LIST
+
+ - Add a date time class
+ - Add enumeration class
+
+ */
+
+
namespace ISMRMRD
{
@@ -50,7 +60,7 @@ namespace ISMRMRD
allocate(v.len_);
len_ = v.len_;
siz_ = v.siz_;
- copy(v_,v.v_,len_);
+ copy(v.v_,len_);
}
///Asignment operator
@@ -58,7 +68,7 @@ namespace ISMRMRD
allocate(v.len_);
len_ = v.len_;
siz_ = v.siz_;
- copy(v_,v.v_,len_);
+ copy(v.v_,len_);
}
@@ -122,13 +132,17 @@ namespace ISMRMRD
which can cause problems when exported from a DLL on Windows.
*/
- class EXPORTISMRMRDXML String : public Vector<char>
+ class String : public Vector<char>
{
typedef Vector<char> inherited;
public:
///Default constructor
- String();
+ String()
+ {
+ inherited();
+ }
+
///Construct taking null terminated string
String(const char* s)
@@ -174,23 +188,68 @@ namespace ISMRMRD
};
+ template <typename T> class Optional
+ {
+ public:
+ Optional()
+ : present_(false)
+ {
+
+ }
+
+ Optional(const T&v) {
+ present_ = true;
+ value_ = v;
+ }
+
+ const Optional& operator=(const T& v) {
+ present_ = true;
+ value_ = v;
+ }
+
+ bool is_present() {
+ return present_;
+ }
+
+ T& get() {
+ if (!present_) {
+ throw std::runtime_error("Access optional value, which has not been set");
+ }
+ return value_;
+ }
+
+ T& operator()() {
+ return get();
+ }
+
+ void set(const T& v) {
+ present_ = true;
+ value_ = v;
+ }
+
+ protected:
+ bool present_;
+ T value_;
+
+ };
+
struct EXPORTISMRMRDXML SubjectInformation
{
- String patientName;
- float patientWeight_kg;
- String patientID;
- String patientBirthDate;
- String patientGender;
+ Optional<String> patientName;
+ Optional<float> patientWeight_kg;
+ Optional<String> patientID;
+ Optional<String> patientBirthDate;
+ Optional<String> patientGender;
};
struct StudyInformation
{
- String studyDate;
- String studyTime;
- String studyID;
- long int accessionNumber;
- String referringPhysicianName;
- String studyDescription;
+ Optional<String> studyDate;
+ Optional<String> studyTime;
+ Optional<String> studyID;
+ Optional<long int> accessionNumber;
+ Optional<String> referringPhysicianName;
+ Optional<String> studyDescription;
};
struct MeasurementDependency
@@ -201,45 +260,234 @@ namespace ISMRMRD
struct MeasurementInformation
{
- String measurementID;
- String seriesDate;
- String seriesTime;
+ Optional<String> measurementID;
+ Optional<String> seriesDate;
+ Optional<String> seriesTime;
String patientPosition;
- long int initialSeriesNumber;
- String protocolName;
- String seriesDescription;
+ Optional<long int> initialSeriesNumber;
+ Optional<String> protocolName;
+ Optional<String> seriesDescription;
Vector<MeasurementDependency> measurementDepencency;
};
+ struct AcquisitionSystemInformation
+ {
+ Optional<String> systemVendor;
+ Optional<String> systemModel;
+ Optional<float> systemFieldStrength_T;
+ Optional<float> relativeReceiverNoiseBandwidth;
+ Optional<unsigned short> receiverChannels;
+ Optional<String> institutionName;
+ Optional<String> stationName;
+ };
+
+
+ struct ExperimentalConditions
+ {
+ long int H1resonanceFrequency_Hz;
+ };
+
+ struct MatrixSize
+ {
+ MatrixSize()
+ : x(1)
+ , y(1)
+ , z(1)
+ {
+
+ }
+ unsigned short x;
+ unsigned short y;
+ unsigned short z;
+ };
+
+ struct FieldOfView_mm
+ {
+ float x;
+ float y;
+ float z;
+ };
+
+ struct EncodingSpace
+ {
+ MatrixSize matrixSize;
+ FieldOfView_mm fieldOfView_mm;
+ };
+
+
+ struct Limit
+ {
+ Limit()
+ : minimum(0)
+ , maximum(0)
+ , center(0)
+ {
+
+ }
+
+ unsigned short minimum;
+ unsigned short maximum;
+ unsigned short center;
+ };
+
+ struct EncodingLimits
+ {
+ Optional<Limit> kspace_encoding_step_0;
+ Optional<Limit> kspace_encoding_step_1;
+ Optional<Limit> kspace_encoding_step_2;
+ Optional<Limit> average;
+ Optional<Limit> slice;
+ Optional<Limit> contrast;
+ Optional<Limit> phase;
+ Optional<Limit> repetition;
+ Optional<Limit> set;
+ Optional<Limit> segment;
+ };
+
+
+ struct UserParameterLong
+ {
+ String name;
+ long value;
+ };
+
+ struct UserParameterDouble
+ {
+ String name;
+ double value;
+ };
+
+ struct UserParameterString
+ {
+ String name;
+ String value;
+ };
+
+ struct UserParameterBase64
+ {
+ String name;
+ String value;
+ };
+
+ struct UserParameters
+ {
+ Vector<UserParameterLong> userParameterLong;
+ Vector<UserParameterDouble> userParameterDouble;
+ Vector<UserParameterString> userParameterString;
+ Vector<UserParameterBase64> userParameterBase64;
+ };
+
+ struct TrajectoryDescription
+ {
+ String identifier;
+ Vector<UserParameterLong> userParameterLong;
+ Vector<UserParameterDouble> userParameterDouble;
+ Optional<String> comment;
+ };
+
+ struct Encoding
+ {
+ EncodingSpace encodedSpace;
+ EncodingSpace reconSpace;
+ EncodingLimits encodingLimits;
+ String trajectory;
+ Optional<TrajectoryDescription> trajectoryDescription;
+ };
+
+ struct SequenceParameters
+ {
+ Vector<float> TR;
+ Vector<float> TE;
+ Vector<float> TI;
+ };
+
+ struct ReferencedImageSequence
+ {
+ String referencedSOPInstanceUID;
+ };
+
+
+ struct MRImageModule
+ {
+ Optional<String> imageType;
+ Optional<String> scanningSequence;
+ Optional<String> sequenceVartiant;
+ Optional<String> scanOptions;
+ Optional<String> mrAcquisitionType;
+ Optional<long> echoTrainLength;
+ Optional<float> triggerTime;
+ Optional<float> flipAngle_deg;
+ Optional<String> freqEncodingDirection;
+ };
+
+ struct DicomParameters
+ {
+ String studyInstanceUID;
+ Optional<String> seriesInstanceUIDRoot;
+ Optional<String> frameOfReference;
+ Vector<ReferencedImageSequence> referencedImageSequence;
+ Optional<MRImageModule> mrImageModule;
+ };
+
+
+ struct AccelerationFactor
+ {
+ unsigned short kspace_encoding_step_1;
+ unsigned short kspace_encoding_step_2;
+ };
+
+ struct ParallelImaging
+ {
+ AccelerationFactor accelerationFactor;
+ Optional<String> calibrationMode;
+ Optional<String> interleavingDimension;
+ };
+
+
+ struct IsmrmrdHeader
+ {
+ Optional<SubjectInformation> subjectInformation;
+ Optional<StudyInformation> studyInformation;
+ Optional<MeasurementInformation> measurementInformation;
+ Optional<AcquisitionSystemInformation> acquisitionSystemInformation;
+ Optional<ExperimentalConditions> experimentalConditions;
+ Vector<Encoding> encoding;
+ Optional<ParallelImaging> parallelImaging;
+ Optional<SequenceParameters> sequenceParameters;
+ Optional<DicomParameters> dicomParameters;
+ Optional<UserParameters> userParameters;
+ };
- /*
- //Should this actually be the name.
- //Xml in the name is bad but I wanted to avoid confusion with the AcquisitionHeader
- class IsmrmrdXmlHeader
+
+ class IsmrmrdHeaderProxy
{
public:
//Constructors
- IsmrmrdXmlHeader(const char* xml);
- IsmrmrdXmlHeader(const std::string& xml);
- IsmrmrdXmlHeader(); //Minimal Header
+ IsmrmrdHeaderProxy(const char* xml);
+ IsmrmrdHeaderProxy(const std::string& xml);
+ IsmrmrdHeaderProxy(); //Minimal Header
//Copy constructor
- IsmrmrdXmlHeader(const IsmrmrdXmlHeader& h);
+ IsmrmrdHeaderProxy(const IsmrmrdHeader& h);
//Assignment operator
- IsmrmrdXmlHeader& operator=(const IsmrmrdXmlHeader& h);
+ IsmrmrdHeaderProxy& operator=(const IsmrmrdHeader& h);
-
+ void deserialize(const char* xml);
+
+ void serialize(std::ostream& o);
+
+ IsmrmrdHeader& h() {
+ return h_;
+ }
protected:
-
-
+ IsmrmrdHeader 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