Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STYLE: Replace thread_local path with internal MakePath function #70

Merged
Merged
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
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
Loading