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: Move three internal helper functions into the unnamed namespace #72

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
170 changes: 85 additions & 85 deletions src/itkOMEZarrNGFFImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -372,46 +372,6 @@ MakeKVStoreHTTPDriverSpec(nlohmann::json & spec, const std::string & fullPath)
spec["kvstore"]["path"] = fullPath.substr(fullPath.find_last_of("/") + 1);
}

} // namespace

struct OMEZarrNGFFImageIO::TensorStoreData
{
tensorstore::Context tsContext{ tensorstore::Context::Default() };
tensorstore::TensorStore<> store{};
};

OMEZarrNGFFImageIO::OMEZarrNGFFImageIO()
: m_TensorStoreData(std::make_unique<TensorStoreData>())
{
this->AddSupportedWriteExtension(".zarr");
this->AddSupportedWriteExtension(".zr2");
this->AddSupportedWriteExtension(".zr3");
this->AddSupportedWriteExtension(".zip");
this->AddSupportedWriteExtension(".memory");

this->AddSupportedReadExtension(".zarr");
this->AddSupportedReadExtension(".zr2");
this->AddSupportedReadExtension(".zr3");
this->AddSupportedReadExtension(".zip");
this->AddSupportedWriteExtension(".memory");

this->Self::SetCompressor("");
this->Self::SetMaximumCompressionLevel(9);
this->Self::SetCompressionLevel(2);
}

OMEZarrNGFFImageIO::~OMEZarrNGFFImageIO() = default;


void
OMEZarrNGFFImageIO::PrintSelf(std::ostream & os, Indent indent) const
{
Superclass::PrintSelf(os, indent);
os << indent << "DatasetIndex: " << m_DatasetIndex << std::endl;
os << indent << "TimeIndex: " << m_TimeIndex << std::endl;
os << indent << "ChannelIndex: " << m_ChannelIndex << std::endl;
}

// JSON file path, e.g. "C:/Dev/ITKIOOMEZarrNGFF/v0.4/cyx.ome.zarr/.zgroup"
void
writeJson(nlohmann::json json, std::string path, std::string driver, tensorstore::Context& tsContext)
Expand Down Expand Up @@ -466,6 +426,91 @@ jsonRead(const std::string path, nlohmann::json & result, std::string driver, te
}
}

void
addCoordinateTransformations(OMEZarrNGFFImageIO * io, nlohmann::json ct)
{
itkAssertOrThrowMacro(ct.is_array(), "Failed to parse coordinate transforms");
itkAssertOrThrowMacro(ct.size() >= 1, "Expected at least one coordinate transform");
itkAssertOrThrowMacro(ct[0].at("type") == "scale",
("Expected first transform to be \"scale\" but found " +
std::string(ct[0].at("type")))); // first transformation must be scale

nlohmann::json s = ct[0].at("scale");
itkAssertOrThrowMacro(s.is_array(), "Failed to parse scale transform");
unsigned dim = s.size();
itkAssertOrThrowMacro(dim == io->GetNumberOfDimensions(), "Found dimension mismatch in scale transform");

for (unsigned d = 0; d < dim; ++d)
{
double dS = s[dim - d - 1].get<double>(); // reverse indices KJI into IJK
io->SetSpacing(d, dS * io->GetSpacing(d));
io->SetOrigin(d, dS * io->GetOrigin(d)); // TODO: should we update origin like this?
}

if (ct.size() > 1) // there is also a translation
{
itkAssertOrThrowMacro(ct[1].at("type") == "translation",
("Expected second transform to be \"translation\" but found " +
std::string(ct[1].at("type")))); // first transformation must be scale
nlohmann::json tr = ct[1].at("translation");
itkAssertOrThrowMacro(tr.is_array(), "Failed to parse translation transform");
dim = tr.size();
itkAssertOrThrowMacro(dim == io->GetNumberOfDimensions(), "Found dimension mismatch in translation transform");

for (unsigned d = 0; d < dim; ++d)
{
double dOrigin = tr[dim - d - 1].get<double>(); // reverse indices KJI into IJK
io->SetOrigin(d, dOrigin + io->GetOrigin(d));
}
}

if (ct.size() > 2)
{
itkGenericOutputMacro(<< "A sequence of more than 2 transformations is specified in '" << io->GetFileName()
<< "'. This is currently not supported. Extra transformations are ignored.");
}
}

} // namespace

struct OMEZarrNGFFImageIO::TensorStoreData
{
tensorstore::Context tsContext{ tensorstore::Context::Default() };
tensorstore::TensorStore<> store{};
};

OMEZarrNGFFImageIO::OMEZarrNGFFImageIO()
: m_TensorStoreData(std::make_unique<TensorStoreData>())
{
this->AddSupportedWriteExtension(".zarr");
this->AddSupportedWriteExtension(".zr2");
this->AddSupportedWriteExtension(".zr3");
this->AddSupportedWriteExtension(".zip");
this->AddSupportedWriteExtension(".memory");

this->AddSupportedReadExtension(".zarr");
this->AddSupportedReadExtension(".zr2");
this->AddSupportedReadExtension(".zr3");
this->AddSupportedReadExtension(".zip");
this->AddSupportedWriteExtension(".memory");

this->Self::SetCompressor("");
this->Self::SetMaximumCompressionLevel(9);
this->Self::SetCompressionLevel(2);
}

OMEZarrNGFFImageIO::~OMEZarrNGFFImageIO() = default;


void
OMEZarrNGFFImageIO::PrintSelf(std::ostream & os, Indent indent) const
{
Superclass::PrintSelf(os, indent);
os << indent << "DatasetIndex: " << m_DatasetIndex << std::endl;
os << indent << "TimeIndex: " << m_TimeIndex << std::endl;
os << indent << "ChannelIndex: " << m_ChannelIndex << std::endl;
}

bool
OMEZarrNGFFImageIO::CanReadFile(const char * filename)
{
Expand Down Expand Up @@ -606,51 +651,6 @@ OMEZarrNGFFImageIO::ConfigureTensorstoreIORegion(const ImageIORegion & ioRegion)
return storeRegion;
}

void
addCoordinateTransformations(OMEZarrNGFFImageIO * io, nlohmann::json ct)
{
itkAssertOrThrowMacro(ct.is_array(), "Failed to parse coordinate transforms");
itkAssertOrThrowMacro(ct.size() >= 1, "Expected at least one coordinate transform");
itkAssertOrThrowMacro(ct[0].at("type") == "scale",
("Expected first transform to be \"scale\" but found " +
std::string(ct[0].at("type")))); // first transformation must be scale

nlohmann::json s = ct[0].at("scale");
itkAssertOrThrowMacro(s.is_array(), "Failed to parse scale transform");
unsigned dim = s.size();
itkAssertOrThrowMacro(dim == io->GetNumberOfDimensions(), "Found dimension mismatch in scale transform");

for (unsigned d = 0; d < dim; ++d)
{
double dS = s[dim - d - 1].get<double>(); // reverse indices KJI into IJK
io->SetSpacing(d, dS * io->GetSpacing(d));
io->SetOrigin(d, dS * io->GetOrigin(d)); // TODO: should we update origin like this?
}

if (ct.size() > 1) // there is also a translation
{
itkAssertOrThrowMacro(ct[1].at("type") == "translation",
("Expected second transform to be \"translation\" but found " +
std::string(ct[1].at("type")))); // first transformation must be scale
nlohmann::json tr = ct[1].at("translation");
itkAssertOrThrowMacro(tr.is_array(), "Failed to parse translation transform");
dim = tr.size();
itkAssertOrThrowMacro(dim == io->GetNumberOfDimensions(), "Found dimension mismatch in translation transform");

for (unsigned d = 0; d < dim; ++d)
{
double dOrigin = tr[dim - d - 1].get<double>(); // reverse indices KJI into IJK
io->SetOrigin(d, dOrigin + io->GetOrigin(d));
}
}

if (ct.size() > 2)
{
itkGenericOutputMacro(<< "A sequence of more than 2 transformations is specified in '" << io->GetFileName()
<< "'. This is currently not supported. Extra transformations are ignored.");
}
}

void
OMEZarrNGFFImageIO::ReadImageInformation()
{
Expand Down
Loading