Skip to content
Snippets Groups Projects
Commit a5c14981 authored by Owen Arnold's avatar Owen Arnold
Browse files

Various improvements to NexusGeometryParser

parent 90952630
No related branches found
No related tags found
No related merge requests found
......@@ -112,8 +112,6 @@ std::vector<ValueType> extractVector(const DataSet &data) {
values.resize(dataSpace.getSelectNpoints());
// Read data into vector
data.read(values.data(), data.getDataType(), dataSpace);
// Return the data vector
return values;
}
......@@ -121,7 +119,6 @@ std::vector<ValueType> extractVector(const DataSet &data) {
template <typename ValueType>
std::vector<ValueType> get1DDataset(const H5std_string &dataset,
const H5::Group &group) {
// Open data set
DataSet data = group.openDataSet(dataset);
return extractVector<ValueType>(data);
}
......@@ -218,7 +215,9 @@ Pixels getPixelOffsets(const Group &detectorGroup) {
// Initialise matrix
Pixels offsetData;
std::vector<double> xValues, yValues, zValues;
std::vector<double> xValues;
std::vector<double> yValues;
std::vector<double> zValues;
for (unsigned int i = 0; i < detectorGroup.getNumObjs(); i++) {
H5std_string objName = detectorGroup.getObjnameByIdx(i);
if (objName == X_PIXEL_OFFSET) {
......@@ -267,7 +266,7 @@ Pixels getPixelOffsets(const Group &detectorGroup) {
}
/**
* Creates a Homogemous transfomation for nexus groups
* Creates a Homogeneous transfomation for nexus groups
*
* Walks the chain of transformations described in the file where W1 is first
*transformation and Wn is last and assembles them as
......@@ -297,11 +296,8 @@ getTransformations(const H5File &file, const Group &detectorGroup) {
return Eigen::Transform<double, 3, Eigen::Affine>::Identity();
}
// Initialise transformation holder as zero-degree rotation
Eigen::Transform<double, 3, Eigen::Affine> transforms;
Eigen::Vector3d axis(1.0, 0.0, 0.0);
transforms = Eigen::AngleAxisd(0.0, axis);
// Initialise transformation holder as identity matrix
auto transforms = Eigen::Transform<double, 3, Eigen::Affine>::Identity();
// Breaks when no more dependencies (dependency = ".")
// Transformations must be applied in the order of direction of discovery
// (they are _passive_ transformations)
......@@ -365,15 +361,18 @@ getTransformations(const H5File &file, const Group &detectorGroup) {
}
Eigen::AngleAxisd rotation(angle, transformVector);
transforms = rotation * transforms;
} else {
throw std::runtime_error(
"Unknown Transform type in Nexus Geometry Parsing");
}
}
return transforms;
}
// Function to return the detector ids in the same order as the offsets
std::vector<int> getDetectorIds(const Group &detectorGroup) {
std::vector<Mantid::detid_t> getDetectorIds(const Group &detectorGroup) {
std::vector<int> detIds;
std::vector<Mantid::detid_t> detIds;
for (unsigned int i = 0; i < detectorGroup.getNumObjs(); ++i) {
H5std_string objName = detectorGroup.getObjnameByIdx(i);
......@@ -381,9 +380,10 @@ std::vector<int> getDetectorIds(const Group &detectorGroup) {
const auto data = detectorGroup.openDataSet(objName);
if (data.getDataType().getSize() == 8) {
// Note the narrowing here!
detIds = convertVector<int64_t, int32_t>(extractVector<int64_t>(data));
detIds = convertVector<int64_t, Mantid::detid_t>(
extractVector<int64_t>(data));
} else {
detIds = extractVector<int32_t>(data);
detIds = extractVector<Mantid::detid_t>(data);
}
}
}
......@@ -443,7 +443,7 @@ void extractFacesAndIDs(const std::vector<uint16_t> &detFaces,
detVerts.reserve(vertsPerFace);
detWinding.reserve(vertsPerFace);
for (size_t v = 0; v < vertsPerFace; ++v) {
auto vi = windingOrder[i + v] * vertStride;
const auto vi = windingOrder[i + v] * vertStride;
detVerts.emplace_back(vertices[vi], vertices[vi + 1], vertices[vi + 2]);
detWinding.push_back(static_cast<uint16_t>(detWinding.size()));
}
......@@ -590,8 +590,7 @@ void parseMonitors(const H5::Group &root, InstrumentBuilder &builder) {
for (auto &monitor : monitorGroups) {
auto detectorId = get1DDataset<int64_t>(DETECTOR_ID, monitor)[0];
bool proxy = false;
boost::shared_ptr<const Geometry::IObject> monitorShape =
parseNexusShape(monitor, proxy);
auto monitorShape = parseNexusShape(monitor, proxy);
builder.addMonitor(std::to_string(detectorId),
static_cast<int32_t>(detectorId),
Eigen::Vector3d{0, 0, 0}, monitorShape);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment