Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cpp/mrd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,3 @@ endif()

add_library(mrd_generated OBJECT ${Mrd_GENERATED_SOURCES})
target_link_libraries(mrd_generated ${Mrd_GENERATED_LINK_LIBRARIES})
target_compile_features(mrd_generated PUBLIC cxx_std_17)
32 changes: 28 additions & 4 deletions cpp/mrd/binary/protocols.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ struct IsTriviallySerializable<mrd::AcquisitionHeader> {
IsTriviallySerializable<decltype(__T__::idx)>::value &&
IsTriviallySerializable<decltype(__T__::measurement_uid)>::value &&
IsTriviallySerializable<decltype(__T__::scan_counter)>::value &&
IsTriviallySerializable<decltype(__T__::acquisition_center_frequency)>::value &&
IsTriviallySerializable<decltype(__T__::acquisition_time_stamp_ns)>::value &&
IsTriviallySerializable<decltype(__T__::physiology_time_stamp_ns)>::value &&
IsTriviallySerializable<decltype(__T__::channel_order)>::value &&
Expand All @@ -57,8 +58,8 @@ struct IsTriviallySerializable<mrd::AcquisitionHeader> {
IsTriviallySerializable<decltype(__T__::patient_table_position)>::value &&
IsTriviallySerializable<decltype(__T__::user_int)>::value &&
IsTriviallySerializable<decltype(__T__::user_float)>::value &&
(sizeof(__T__) == (sizeof(__T__::flags) + sizeof(__T__::idx) + sizeof(__T__::measurement_uid) + sizeof(__T__::scan_counter) + sizeof(__T__::acquisition_time_stamp_ns) + sizeof(__T__::physiology_time_stamp_ns) + sizeof(__T__::channel_order) + sizeof(__T__::discard_pre) + sizeof(__T__::discard_post) + sizeof(__T__::center_sample) + sizeof(__T__::encoding_space_ref) + sizeof(__T__::sample_time_ns) + sizeof(__T__::position) + sizeof(__T__::read_dir) + sizeof(__T__::phase_dir) + sizeof(__T__::slice_dir) + sizeof(__T__::patient_table_position) + sizeof(__T__::user_int) + sizeof(__T__::user_float))) &&
offsetof(__T__, flags) < offsetof(__T__, idx) && offsetof(__T__, idx) < offsetof(__T__, measurement_uid) && offsetof(__T__, measurement_uid) < offsetof(__T__, scan_counter) && offsetof(__T__, scan_counter) < offsetof(__T__, acquisition_time_stamp_ns) && offsetof(__T__, acquisition_time_stamp_ns) < offsetof(__T__, physiology_time_stamp_ns) && offsetof(__T__, physiology_time_stamp_ns) < offsetof(__T__, channel_order) && offsetof(__T__, channel_order) < offsetof(__T__, discard_pre) && offsetof(__T__, discard_pre) < offsetof(__T__, discard_post) && offsetof(__T__, discard_post) < offsetof(__T__, center_sample) && offsetof(__T__, center_sample) < offsetof(__T__, encoding_space_ref) && offsetof(__T__, encoding_space_ref) < offsetof(__T__, sample_time_ns) && offsetof(__T__, sample_time_ns) < offsetof(__T__, position) && offsetof(__T__, position) < offsetof(__T__, read_dir) && offsetof(__T__, read_dir) < offsetof(__T__, phase_dir) && offsetof(__T__, phase_dir) < offsetof(__T__, slice_dir) && offsetof(__T__, slice_dir) < offsetof(__T__, patient_table_position) && offsetof(__T__, patient_table_position) < offsetof(__T__, user_int) && offsetof(__T__, user_int) < offsetof(__T__, user_float);
(sizeof(__T__) == (sizeof(__T__::flags) + sizeof(__T__::idx) + sizeof(__T__::measurement_uid) + sizeof(__T__::scan_counter) + sizeof(__T__::acquisition_center_frequency) + sizeof(__T__::acquisition_time_stamp_ns) + sizeof(__T__::physiology_time_stamp_ns) + sizeof(__T__::channel_order) + sizeof(__T__::discard_pre) + sizeof(__T__::discard_post) + sizeof(__T__::center_sample) + sizeof(__T__::encoding_space_ref) + sizeof(__T__::sample_time_ns) + sizeof(__T__::position) + sizeof(__T__::read_dir) + sizeof(__T__::phase_dir) + sizeof(__T__::slice_dir) + sizeof(__T__::patient_table_position) + sizeof(__T__::user_int) + sizeof(__T__::user_float))) &&
offsetof(__T__, flags) < offsetof(__T__, idx) && offsetof(__T__, idx) < offsetof(__T__, measurement_uid) && offsetof(__T__, measurement_uid) < offsetof(__T__, scan_counter) && offsetof(__T__, scan_counter) < offsetof(__T__, acquisition_center_frequency) && offsetof(__T__, acquisition_center_frequency) < offsetof(__T__, acquisition_time_stamp_ns) && offsetof(__T__, acquisition_time_stamp_ns) < offsetof(__T__, physiology_time_stamp_ns) && offsetof(__T__, physiology_time_stamp_ns) < offsetof(__T__, channel_order) && offsetof(__T__, channel_order) < offsetof(__T__, discard_pre) && offsetof(__T__, discard_pre) < offsetof(__T__, discard_post) && offsetof(__T__, discard_post) < offsetof(__T__, center_sample) && offsetof(__T__, center_sample) < offsetof(__T__, encoding_space_ref) && offsetof(__T__, encoding_space_ref) < offsetof(__T__, sample_time_ns) && offsetof(__T__, sample_time_ns) < offsetof(__T__, position) && offsetof(__T__, position) < offsetof(__T__, read_dir) && offsetof(__T__, read_dir) < offsetof(__T__, phase_dir) && offsetof(__T__, phase_dir) < offsetof(__T__, slice_dir) && offsetof(__T__, slice_dir) < offsetof(__T__, patient_table_position) && offsetof(__T__, patient_table_position) < offsetof(__T__, user_int) && offsetof(__T__, user_int) < offsetof(__T__, user_float);
};

template <>
Expand All @@ -68,9 +69,10 @@ struct IsTriviallySerializable<mrd::Acquisition> {
std::is_standard_layout_v<__T__> &&
IsTriviallySerializable<decltype(__T__::head)>::value &&
IsTriviallySerializable<decltype(__T__::data)>::value &&
IsTriviallySerializable<decltype(__T__::phase)>::value &&
IsTriviallySerializable<decltype(__T__::trajectory)>::value &&
(sizeof(__T__) == (sizeof(__T__::head) + sizeof(__T__::data) + sizeof(__T__::trajectory))) &&
offsetof(__T__, head) < offsetof(__T__, data) && offsetof(__T__, data) < offsetof(__T__, trajectory);
(sizeof(__T__) == (sizeof(__T__::head) + sizeof(__T__::data) + sizeof(__T__::phase) + sizeof(__T__::trajectory))) &&
offsetof(__T__, head) < offsetof(__T__, data) && offsetof(__T__, data) < offsetof(__T__, phase) && offsetof(__T__, phase) < offsetof(__T__, trajectory);
};

template <>
Expand Down Expand Up @@ -1026,6 +1028,24 @@ namespace {
yardl::binary::ReadNDArray<std::complex<float>, yardl::binary::ReadFloatingPoint, 2>(stream, value);
}

[[maybe_unused]] void WriteAcquisitionPhase(yardl::binary::CodedOutputStream& stream, mrd::AcquisitionPhase const& value) {
if constexpr (yardl::binary::IsTriviallySerializable<mrd::AcquisitionPhase>::value) {
yardl::binary::WriteTriviallySerializable(stream, value);
return;
}

yardl::binary::WriteNDArray<float, yardl::binary::WriteFloatingPoint, 1>(stream, value);
}

[[maybe_unused]] void ReadAcquisitionPhase(yardl::binary::CodedInputStream& stream, mrd::AcquisitionPhase& value) {
if constexpr (yardl::binary::IsTriviallySerializable<mrd::AcquisitionPhase>::value) {
yardl::binary::ReadTriviallySerializable(stream, value);
return;
}

yardl::binary::ReadNDArray<float, yardl::binary::ReadFloatingPoint, 1>(stream, value);
}

[[maybe_unused]] void WriteTrajectoryData(yardl::binary::CodedOutputStream& stream, mrd::TrajectoryData const& value) {
if constexpr (yardl::binary::IsTriviallySerializable<mrd::TrajectoryData>::value) {
yardl::binary::WriteTriviallySerializable(stream, value);
Expand Down Expand Up @@ -1054,6 +1074,7 @@ namespace {
mrd::binary::WriteEncodingCounters(stream, value.idx);
yardl::binary::WriteInteger(stream, value.measurement_uid);
yardl::binary::WriteOptional<uint32_t, yardl::binary::WriteInteger>(stream, value.scan_counter);
yardl::binary::WriteOptional<uint64_t, yardl::binary::WriteInteger>(stream, value.acquisition_center_frequency);
yardl::binary::WriteOptional<uint64_t, yardl::binary::WriteInteger>(stream, value.acquisition_time_stamp_ns);
yardl::binary::WriteVector<uint64_t, yardl::binary::WriteInteger>(stream, value.physiology_time_stamp_ns);
yardl::binary::WriteVector<uint32_t, yardl::binary::WriteInteger>(stream, value.channel_order);
Expand Down Expand Up @@ -1081,6 +1102,7 @@ namespace {
mrd::binary::ReadEncodingCounters(stream, value.idx);
yardl::binary::ReadInteger(stream, value.measurement_uid);
yardl::binary::ReadOptional<uint32_t, yardl::binary::ReadInteger>(stream, value.scan_counter);
yardl::binary::ReadOptional<uint64_t, yardl::binary::ReadInteger>(stream, value.acquisition_center_frequency);
yardl::binary::ReadOptional<uint64_t, yardl::binary::ReadInteger>(stream, value.acquisition_time_stamp_ns);
yardl::binary::ReadVector<uint64_t, yardl::binary::ReadInteger>(stream, value.physiology_time_stamp_ns);
yardl::binary::ReadVector<uint32_t, yardl::binary::ReadInteger>(stream, value.channel_order);
Expand All @@ -1106,6 +1128,7 @@ namespace {

mrd::binary::WriteAcquisitionHeader(stream, value.head);
mrd::binary::WriteAcquisitionData(stream, value.data);
yardl::binary::WriteOptional<mrd::AcquisitionPhase, mrd::binary::WriteAcquisitionPhase>(stream, value.phase);
mrd::binary::WriteTrajectoryData(stream, value.trajectory);
}

Expand All @@ -1117,6 +1140,7 @@ namespace {

mrd::binary::ReadAcquisitionHeader(stream, value.head);
mrd::binary::ReadAcquisitionData(stream, value.data);
yardl::binary::ReadOptional<mrd::AcquisitionPhase, mrd::binary::ReadAcquisitionPhase>(stream, value.phase);
mrd::binary::ReadTrajectoryData(stream, value.trajectory);
}

Expand Down
8 changes: 8 additions & 0 deletions cpp/mrd/hdf5/protocols.cc
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@ struct _Inner_AcquisitionHeader {
idx(o.idx),
measurement_uid(o.measurement_uid),
scan_counter(o.scan_counter),
acquisition_center_frequency(o.acquisition_center_frequency),
acquisition_time_stamp_ns(o.acquisition_time_stamp_ns),
physiology_time_stamp_ns(o.physiology_time_stamp_ns),
channel_order(o.channel_order),
Expand All @@ -821,6 +822,7 @@ struct _Inner_AcquisitionHeader {
yardl::hdf5::ToOuter(idx, o.idx);
yardl::hdf5::ToOuter(measurement_uid, o.measurement_uid);
yardl::hdf5::ToOuter(scan_counter, o.scan_counter);
yardl::hdf5::ToOuter(acquisition_center_frequency, o.acquisition_center_frequency);
yardl::hdf5::ToOuter(acquisition_time_stamp_ns, o.acquisition_time_stamp_ns);
yardl::hdf5::ToOuter(physiology_time_stamp_ns, o.physiology_time_stamp_ns);
yardl::hdf5::ToOuter(channel_order, o.channel_order);
Expand All @@ -842,6 +844,7 @@ struct _Inner_AcquisitionHeader {
mrd::hdf5::_Inner_EncodingCounters idx;
uint32_t measurement_uid;
yardl::hdf5::InnerOptional<uint32_t, uint32_t> scan_counter;
yardl::hdf5::InnerOptional<uint64_t, uint64_t> acquisition_center_frequency;
yardl::hdf5::InnerOptional<uint64_t, uint64_t> acquisition_time_stamp_ns;
yardl::hdf5::InnerVlen<uint64_t, uint64_t> physiology_time_stamp_ns;
yardl::hdf5::InnerVlen<uint32_t, uint32_t> channel_order;
Expand All @@ -864,17 +867,20 @@ struct _Inner_Acquisition {
_Inner_Acquisition(mrd::Acquisition const& o)
: head(o.head),
data(o.data),
phase(o.phase),
trajectory(o.trajectory) {
}

void ToOuter (mrd::Acquisition& o) const {
yardl::hdf5::ToOuter(head, o.head);
yardl::hdf5::ToOuter(data, o.data);
yardl::hdf5::ToOuter(phase, o.phase);
yardl::hdf5::ToOuter(trajectory, o.trajectory);
}

mrd::hdf5::_Inner_AcquisitionHeader head;
yardl::hdf5::InnerNdArray<std::complex<float>, std::complex<float>, 2> data;
yardl::hdf5::InnerOptional<yardl::hdf5::InnerVlen<float, float>, mrd::AcquisitionPhase> phase;
yardl::hdf5::InnerNdArray<float, float, 2> trajectory;
};

Expand Down Expand Up @@ -1710,6 +1716,7 @@ struct _Inner_ImageArray {
t.insertMember("idx", HOFFSET(RecordType, idx), mrd::hdf5::GetEncodingCountersHdf5Ddl());
t.insertMember("measurementUid", HOFFSET(RecordType, measurement_uid), H5::PredType::NATIVE_UINT32);
t.insertMember("scanCounter", HOFFSET(RecordType, scan_counter), yardl::hdf5::OptionalTypeDdl<uint32_t, uint32_t>(H5::PredType::NATIVE_UINT32));
t.insertMember("acquisitionCenterFrequency", HOFFSET(RecordType, acquisition_center_frequency), yardl::hdf5::OptionalTypeDdl<uint64_t, uint64_t>(H5::PredType::NATIVE_UINT64));
t.insertMember("acquisitionTimeStampNs", HOFFSET(RecordType, acquisition_time_stamp_ns), yardl::hdf5::OptionalTypeDdl<uint64_t, uint64_t>(H5::PredType::NATIVE_UINT64));
t.insertMember("physiologyTimeStampNs", HOFFSET(RecordType, physiology_time_stamp_ns), yardl::hdf5::InnerVlenDdl(H5::PredType::NATIVE_UINT64));
t.insertMember("channelOrder", HOFFSET(RecordType, channel_order), yardl::hdf5::InnerVlenDdl(H5::PredType::NATIVE_UINT32));
Expand All @@ -1733,6 +1740,7 @@ struct _Inner_ImageArray {
H5::CompType t(sizeof(RecordType));
t.insertMember("head", HOFFSET(RecordType, head), mrd::hdf5::GetAcquisitionHeaderHdf5Ddl());
t.insertMember("data", HOFFSET(RecordType, data), yardl::hdf5::NDArrayDdl<std::complex<float>, std::complex<float>, 2>(yardl::hdf5::ComplexTypeDdl<float>()));
t.insertMember("phase", HOFFSET(RecordType, phase), yardl::hdf5::OptionalTypeDdl<yardl::hdf5::InnerVlen<float, float>, mrd::AcquisitionPhase>(yardl::hdf5::InnerVlenDdl(H5::PredType::NATIVE_FLOAT)));
t.insertMember("trajectory", HOFFSET(RecordType, trajectory), yardl::hdf5::NDArrayDdl<float, float, 2>(H5::PredType::NATIVE_FLOAT));
return t;
}
Expand Down
12 changes: 12 additions & 0 deletions cpp/mrd/ndjson/protocols.cc
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,9 @@ void to_json(ordered_json& j, mrd::AcquisitionHeader const& value) {
if (yardl::ndjson::ShouldSerializeFieldValue(value.scan_counter)) {
j.push_back({"scanCounter", value.scan_counter});
}
if (yardl::ndjson::ShouldSerializeFieldValue(value.acquisition_center_frequency)) {
j.push_back({"acquisitionCenterFrequency", value.acquisition_center_frequency});
}
if (yardl::ndjson::ShouldSerializeFieldValue(value.acquisition_time_stamp_ns)) {
j.push_back({"acquisitionTimeStampNs", value.acquisition_time_stamp_ns});
}
Expand Down Expand Up @@ -856,6 +859,9 @@ void from_json(ordered_json const& j, mrd::AcquisitionHeader& value) {
if (auto it = j.find("scanCounter"); it != j.end()) {
it->get_to(value.scan_counter);
}
if (auto it = j.find("acquisitionCenterFrequency"); it != j.end()) {
it->get_to(value.acquisition_center_frequency);
}
if (auto it = j.find("acquisitionTimeStampNs"); it != j.end()) {
it->get_to(value.acquisition_time_stamp_ns);
}
Expand Down Expand Up @@ -911,6 +917,9 @@ void to_json(ordered_json& j, mrd::Acquisition const& value) {
if (yardl::ndjson::ShouldSerializeFieldValue(value.data)) {
j.push_back({"data", value.data});
}
if (yardl::ndjson::ShouldSerializeFieldValue(value.phase)) {
j.push_back({"phase", value.phase});
}
if (yardl::ndjson::ShouldSerializeFieldValue(value.trajectory)) {
j.push_back({"trajectory", value.trajectory});
}
Expand All @@ -923,6 +932,9 @@ void from_json(ordered_json const& j, mrd::Acquisition& value) {
if (auto it = j.find("data"); it != j.end()) {
it->get_to(value.data);
}
if (auto it = j.find("phase"); it != j.end()) {
it->get_to(value.phase);
}
if (auto it = j.find("trajectory"); it != j.end()) {
it->get_to(value.trajectory);
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/mrd/protocols.cc

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions cpp/mrd/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ struct EncodingCounters {

using AcquisitionData = yardl::NDArray<std::complex<float>, 2>;

using AcquisitionPhase = yardl::NDArray<float, 1>;

using TrajectoryData = yardl::NDArray<float, 2>;

struct AcquisitionHeader {
Expand All @@ -99,6 +101,8 @@ struct AcquisitionHeader {
uint32_t measurement_uid{};
// Zero-indexed incrementing counter for readouts
std::optional<uint32_t> scan_counter{};
// Acquisition center frequency in Hz
std::optional<uint64_t> acquisition_center_frequency{};
// Clock time stamp (e.g. nanoseconds since midnight)
std::optional<uint64_t> acquisition_time_stamp_ns{};
// Time stamps relative to physiological triggering in nanoseconds
Expand Down Expand Up @@ -137,6 +141,7 @@ struct AcquisitionHeader {
idx == other.idx &&
measurement_uid == other.measurement_uid &&
scan_counter == other.scan_counter &&
acquisition_center_frequency == other.acquisition_center_frequency &&
acquisition_time_stamp_ns == other.acquisition_time_stamp_ns &&
physiology_time_stamp_ns == other.physiology_time_stamp_ns &&
channel_order == other.channel_order &&
Expand Down Expand Up @@ -164,6 +169,8 @@ struct Acquisition {
mrd::AcquisitionHeader head{};
// Raw k-space samples array
mrd::AcquisitionData data{};
// Phase offset array
std::optional<mrd::AcquisitionPhase> phase{};
// Trajectory array
mrd::TrajectoryData trajectory{};

Expand All @@ -190,6 +197,7 @@ struct Acquisition {
bool operator==(const Acquisition& other) const {
return head == other.head &&
data == other.data &&
phase == other.phase &&
trajectory == other.trajectory;
}

Expand Down
13 changes: 0 additions & 13 deletions cpp/mrd/yardl/detail/ndarray/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,10 @@

#include <utility>

#if __has_include(<xtensor/core/xtensor_config.hpp>)
#include <xtensor/core/xtensor_config.hpp>
#else
#include <xtensor/xtensor_config.hpp>
#endif

#if XTENSOR_VERSION_MAJOR == 0 && XTENSOR_VERSION_MINOR <= 25
#include <xtensor/xarray.hpp>
#include <xtensor/xfixed.hpp>
#include <xtensor/xio.hpp>
#include <xtensor/xtensor.hpp>
#else
#include <xtensor/containers/xarray.hpp>
#include <xtensor/containers/xfixed.hpp>
#include <xtensor/containers/xtensor.hpp>
#include <xtensor/io/xio.hpp>
#endif

namespace yardl {

Expand Down
Loading
Loading