Skip to content

Commit

Permalink
STYLE: Replace thread_local path with internal MakePath function
Browse files Browse the repository at this point in the history
Aims to reduce "common coupling" between functions.
  • Loading branch information
N-Dekker authored and dzenanz committed Aug 27, 2024
1 parent c2ddc46 commit 1d0f131
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/itkOMEZarrNGFFImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ itkToTensorstoreComponentType(const IOComponentEnum itkComponentType)
}
}

std::string
MakePath(const int datasetIndex)
{
return 's' + std::to_string(datasetIndex);
}

// Returns TensorStore KvStore driver name appropriate for this path.
// Options are file, zip. TODO: http, gcs (GoogleCouldStorage), etc.
std::string
Expand Down Expand Up @@ -638,8 +644,6 @@ addCoordinateTransformations(OMEZarrNGFFImageIO * io, nlohmann::json ct)
}
}

thread_local std::string path; // initialized by ReadImageInformation

void
OMEZarrNGFFImageIO::ReadImageInformation()
{
Expand Down Expand Up @@ -715,11 +719,9 @@ OMEZarrNGFFImageIO::ReadImageInformation()
}
}

path = json.at("path").get<std::string>();

// TODO: parse stuff from "metadata" object into metadata dictionary

ReadArrayMetadata(std::string(this->GetFileName()) + "/" + path, driver);
ReadArrayMetadata(std::string(this->GetFileName()) + "/" + json.at("path").get<std::string>(), driver);
}

void
Expand Down Expand Up @@ -788,12 +790,10 @@ OMEZarrNGFFImageIO::WriteImageInformation()
spacing[d] = this->GetSpacing(dim - d - 1);
}

path = "s" + std::to_string(this->GetDatasetIndex());

nlohmann::json datasets = { { "coordinateTransformations",
{ { { "scale", spacing }, { "type", "scale" } },
{ { "translation", origin }, { "type", "translation" } } } },
{ "path", path } };
{ "path", MakePath(this->GetDatasetIndex()) } };

nlohmann::json multiscales = {
{ { "axes", axes }, { "datasets", { datasets } }, { "version", "0.4" } },
Expand Down Expand Up @@ -835,7 +835,14 @@ OMEZarrNGFFImageIO::Write(const void * buffer)
shape[shape.size() - 1 - d] = dSize; // convert IJK into KJI
}

if (!TryToWriteToStore(supportedPixelTypes, componentType, store, tsContext, m_FileName, path, shape, buffer))
if (!TryToWriteToStore(supportedPixelTypes,
componentType,
store,
tsContext,
m_FileName,
MakePath(this->GetDatasetIndex()),
shape,
buffer))
{
itkExceptionMacro("Unsupported component type: " << GetComponentTypeAsString(componentType));
}
Expand Down

0 comments on commit 1d0f131

Please sign in to comment.