diff --git a/itl2/imagemetadata.cpp b/itl2/imagemetadata.cpp index 4f39cd5c..2845b6e5 100644 --- a/itl2/imagemetadata.cpp +++ b/itl2/imagemetadata.cpp @@ -318,7 +318,7 @@ namespace itl2 // List as vector of Vec2f vector def; - vector vlist = data.getList("vec2_list", def); + vector vlist = data.getList("vec2_list", def, false); if (testAssert(vlist.size() == 3, "vec2 list size")) { testAssert(vlist[0] == Vec2c(vectorElement(0, 0), vectorElement(0, 1)), "element"); diff --git a/itl2/imagemetadata.h b/itl2/imagemetadata.h index d7d45c15..277530ab 100644 --- a/itl2/imagemetadata.h +++ b/itl2/imagemetadata.h @@ -226,8 +226,9 @@ namespace itl2 /** Gets item as a list of values. + @param squeeze If set to true, returns list of all elements of the value matrix irrespective of its shape; use, e.g., to always return a list of N numbers despite it being stored either as 1xN or Nx1 matrix. If set to false, the elements in the returned list correspond to the first dimension of the value matrix. */ - template std::vector getList(const std::string& key, std::vector& def) const + template std::vector getList(const std::string& key, std::vector& def, bool squeeze) const { if (!contains(key)) return def; @@ -240,12 +241,26 @@ namespace itl2 for(const std::vector& row : mat) { if (row.size() == 1) + { lst.push_back(fromString(row[0])); + } else { - std::ostringstream str; - appendValueOrVector(str, row); - lst.push_back(fromString(str.str())); + if (squeeze) + { + // Convert each element of the row to the output type. + for (const string& elem : row) + { + lst.push_back(fromString(elem)); + } + } + else + { + // Convert row of values to one value of output type. + std::ostringstream str; + appendValueOrVector(str, row); + lst.push_back(fromString(str.str())); + } } } diff --git a/itl2/tomo/fbp.cpp b/itl2/tomo/fbp.cpp index 9de4d500..b20b52c0 100644 --- a/itl2/tomo/fbp.cpp +++ b/itl2/tomo/fbp.cpp @@ -162,7 +162,7 @@ namespace itl2 void checkMetaItem(const string& item, const ImageMetadata& meta) { if (!meta.contains(item)) - throw ITLException(item + " item is missing from image metadata."); + throw ITLException(string("'") + item + "' item is missing from image metadata."); } RecSettings RecSettings::fromMeta(ImageMetadata& meta) @@ -172,7 +172,15 @@ namespace itl2 // Check that essential metadata exists. checkMetaItem("source_to_ra", meta); - checkMetaItem("angles", meta); + + //checkMetaItem("angles", meta); + string anglesName; + if (meta.contains("angles")) + anglesName = "angles"; + else if (meta.contains("Angles [deg]")) + anglesName = "Angles [deg]"; + else + throw ITLException("'angles' item or 'Angles [deg]' item is missing from image metadata."); s.sourceToRA = meta.get("source_to_ra", s.sourceToRA); @@ -211,13 +219,13 @@ namespace itl2 s.useShifts = meta.get("use_shifts", s.useShifts); std::vector emptyV1; - s.angles = meta.getList("angles", emptyV1); + s.angles = meta.getList(anglesName, emptyV1, true); std::vector emptyV2; std::vector emptyV3; - s.sampleShifts = meta.getList("sample_shifts", emptyV3); - s.sourceShifts = meta.getList("source_shifts", emptyV3); - s.cameraShifts = meta.getList("camera_shifts", emptyV3); - s.rotationAxisShifts = meta.getList("rotation_axis_shifts", emptyV3); + s.sampleShifts = meta.getList("sample_shifts", emptyV3, false); + s.sourceShifts = meta.getList("source_shifts", emptyV3, false); + s.cameraShifts = meta.getList("camera_shifts", emptyV3, false); + s.rotationAxisShifts = meta.getList("rotation_axis_shifts", emptyV3, false); // If there are no shifts supplied, set all shifts to zero. if (s.sampleShifts.size() <= 0)