Skip to content

Commit

Permalink
Fixed bug in fbp preprocessing metadata handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arttu Ilari Miettinen committed Feb 1, 2024
1 parent 235bfd7 commit c56395c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
2 changes: 1 addition & 1 deletion itl2/imagemetadata.cpp
Expand Up @@ -318,7 +318,7 @@ namespace itl2

// List as vector of Vec2f
vector<Vec2c> def;
vector<Vec2c> vlist = data.getList<Vec2c>("vec2_list", def);
vector<Vec2c> vlist = data.getList<Vec2c>("vec2_list", def, false);
if (testAssert(vlist.size() == 3, "vec2 list size"))
{
testAssert(vlist[0] == Vec2c(vectorElement(0, 0), vectorElement(0, 1)), "element");
Expand Down
23 changes: 19 additions & 4 deletions itl2/imagemetadata.h
Expand Up @@ -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<typename T> std::vector<T> getList(const std::string& key, std::vector<T>& def) const
template<typename T> std::vector<T> getList(const std::string& key, std::vector<T>& def, bool squeeze) const
{
if (!contains(key))
return def;
Expand All @@ -240,12 +241,26 @@ namespace itl2
for(const std::vector<string>& row : mat)
{
if (row.size() == 1)
{
lst.push_back(fromString<T>(row[0]));
}
else
{
std::ostringstream str;
appendValueOrVector(str, row);
lst.push_back(fromString<T>(str.str()));
if (squeeze)
{
// Convert each element of the row to the output type.
for (const string& elem : row)
{
lst.push_back(fromString<T>(elem));
}
}
else
{
// Convert row of values to one value of output type.
std::ostringstream str;
appendValueOrVector(str, row);
lst.push_back(fromString<T>(str.str()));
}
}
}

Expand Down
22 changes: 15 additions & 7 deletions itl2/tomo/fbp.cpp
Expand Up @@ -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)
Expand All @@ -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);
Expand Down Expand Up @@ -211,13 +219,13 @@ namespace itl2
s.useShifts = meta.get("use_shifts", s.useShifts);

std::vector<float32_t> emptyV1;
s.angles = meta.getList<float32_t>("angles", emptyV1);
s.angles = meta.getList<float32_t>(anglesName, emptyV1, true);
std::vector<Vec2f> emptyV2;
std::vector<Vec3f> emptyV3;
s.sampleShifts = meta.getList<Vec3f>("sample_shifts", emptyV3);
s.sourceShifts = meta.getList<Vec3f>("source_shifts", emptyV3);
s.cameraShifts = meta.getList<Vec3f>("camera_shifts", emptyV3);
s.rotationAxisShifts = meta.getList<Vec3f>("rotation_axis_shifts", emptyV3);
s.sampleShifts = meta.getList<Vec3f>("sample_shifts", emptyV3, false);
s.sourceShifts = meta.getList<Vec3f>("source_shifts", emptyV3, false);
s.cameraShifts = meta.getList<Vec3f>("camera_shifts", emptyV3, false);
s.rotationAxisShifts = meta.getList<Vec3f>("rotation_axis_shifts", emptyV3, false);

// If there are no shifts supplied, set all shifts to zero.
if (s.sampleShifts.size() <= 0)
Expand Down

0 comments on commit c56395c

Please sign in to comment.