Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.h hooks.style=clangformat
*.hxx hooks.style=clangformat
*.cxx hooks.style=clangformat
2 changes: 1 addition & 1 deletion .github/workflows/clang-format-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ jobs:

steps:
- uses: actions/checkout@v1
- uses: InsightSoftwareConsortium/ITKClangFormatLinterAction@master
- uses: InsightSoftwareConsortium/ITKClangFormatLinterAction@main
9 changes: 5 additions & 4 deletions src/itkOMEZarrNGFFImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ MakeKVStoreHTTPDriverSpec(nlohmann::json & spec, const std::string & fullPath)

// 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)
writeJson(nlohmann::json json, std::string path, std::string driver, tensorstore::Context & tsContext)
{
auto attrs_store = tensorstore::Open<nlohmann::json, 0>(
{ { "driver", "json" }, { "kvstore", { { "driver", driver }, { "path", path } } } },
Expand All @@ -395,7 +395,7 @@ writeJson(nlohmann::json json, std::string path, std::string driver, tensorstore

// JSON file path, e.g. "C:/Dev/ITKIOOMEZarrNGFF/v0.4/cyx.ome.zarr/.zattrs"
bool
jsonRead(const std::string path, nlohmann::json & result, std::string driver, tensorstore::Context& tsContext)
jsonRead(const std::string path, nlohmann::json & result, std::string driver, tensorstore::Context & tsContext)
{
// Reading JSON via TensorStore allows it to be in the cloud
nlohmann::json readSpec = { { "driver", "json" }, { "kvstore", { { "driver", driver }, { "path", path } } } };
Expand Down Expand Up @@ -584,7 +584,7 @@ OMEZarrNGFFImageIO::ReadArrayMetadata(std::string path, std::string driver)
ImageIORegion
OMEZarrNGFFImageIO::ConfigureTensorstoreIORegion(const ImageIORegion & ioRegion) const
{
const auto storeRank = m_TensorStoreData->store.rank();
const auto storeRank = m_TensorStoreData->store.rank();

// Set up IO region to match known store dimensions
itkAssertOrThrowMacro(m_StoreAxes.size() == storeRank, "Detected mismatch in axis count and store rank");
Expand Down Expand Up @@ -858,7 +858,8 @@ OMEZarrNGFFImageIO::Write(const void * buffer)
{
// Attempt to read a non-existent file from the in-memory zip to close the current one
nlohmann::json temp;
bool wasRead = jsonRead(m_EmptyZipFileName + "/non-existent.json", temp, "zip_memory", m_TensorStoreData->tsContext);
bool wasRead =
jsonRead(m_EmptyZipFileName + "/non-existent.json", temp, "zip_memory", m_TensorStoreData->tsContext);
assert(wasRead == false);
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/itkOMEZarrNGFFImageIOFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ namespace itk
{
OMEZarrNGFFImageIOFactory::OMEZarrNGFFImageIOFactory()
{
this->RegisterOverride(
"itkImageIOBase",
"itkOMEZarrNGFFImageIO",
"Open Microscopy Environment Zarr Next Generation File Format",
true,
CreateObjectFunction<OMEZarrNGFFImageIO>::New());
this->RegisterOverride("itkImageIOBase",
"itkOMEZarrNGFFImageIO",
"Open Microscopy Environment Zarr Next Generation File Format",
true,
CreateObjectFunction<OMEZarrNGFFImageIO>::New());
}

const char *
Expand All @@ -40,7 +39,8 @@ OMEZarrNGFFImageIOFactory::GetITKSourceVersion() const
const char *
OMEZarrNGFFImageIOFactory::GetDescription() const
{
return "OMEZarrNGFF ImageIO Factory, allows the loading of images in Open Microscopy Environment Zarr Next Generation File Format";
return "OMEZarrNGFF ImageIO Factory, allows the loading of images in Open Microscopy Environment Zarr Next "
"Generation File Format";
}

// Undocumented API used to register during static initialization.
Expand Down
10 changes: 5 additions & 5 deletions test/itkOMEZarrNGFFInMemoryTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ doTest(const char * inputFileName, const char * outputFileName)

// Copy zip data into memory
// Adapted from https://stackoverflow.com/a/18816228/276168
std::ifstream file(inputFileName, std::ios::binary | std::ios::ate);
std::ifstream file(inputFileName, std::ios::binary | std::ios::ate);
const std::streamsize inputBufferSize = file.tellg();
file.seekg(0, std::ios::beg);
std::vector<char> buffer(inputBufferSize);
Expand All @@ -63,8 +63,8 @@ doTest(const char * inputFileName, const char * outputFileName)

// Read the zip-compressed bitstream from memory into an ITK image
itk::OMEZarrNGFFImageIO::BufferInfo bufferInfo{ buffer.data(), buffer.size() };
const auto inputBufferPointer = buffer.data();
std::string memAddress = itk::OMEZarrNGFFImageIO::MakeMemoryFileName(bufferInfo);
const auto inputBufferPointer = buffer.data();
std::string memAddress = itk::OMEZarrNGFFImageIO::MakeMemoryFileName(bufferInfo);

typename ReaderType::Pointer memReader = ReaderType::New();
memReader->SetFileName(memAddress);
Expand All @@ -84,8 +84,8 @@ doTest(const char * inputFileName, const char * outputFileName)
}

// Verify a local copy of the buffer is maintained in the itk::Image
memImage->DisconnectPipeline(); // keep our local copy of the memory buffer
std::fill(buffer.begin(), buffer.end(), 0); // reset the memory buffer in place
memImage->DisconnectPipeline(); // keep our local copy of the memory buffer
std::fill(buffer.begin(), buffer.end(), 0); // reset the memory buffer in place
ITK_TRY_EXPECT_NO_EXCEPTION(comparer->Update()); // should not reflect buffer update
if (comparer->GetNumberOfPixelsWithDifferences() > 0)
{
Expand Down
129 changes: 64 additions & 65 deletions test/itkOMEZarrNGFFReadSliceTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
*
*=========================================================================*/

/// This test utility may be used to validate that an OME-Zarr image can be
/// read from disk or from an HTTP source.
///
/// No attempt is made to validate input data. A summary of the retrieved image
/// is printed to `std::cout`.
///
/// Does not currently support multichannel sources.
/// https://github.com/InsightSoftwareConsortium/ITKIOOMEZarrNGFF/issues/32
/// This test utility may be used to validate that an OME-Zarr image can be
/// read from disk or from an HTTP source.
///
/// No attempt is made to validate input data. A summary of the retrieved image
/// is printed to `std::cout`.
///
/// Does not currently support multichannel sources.
/// https://github.com/InsightSoftwareConsortium/ITKIOOMEZarrNGFF/issues/32

#include <fstream>
#include <string>
Expand All @@ -39,71 +39,70 @@

namespace
{
template <typename PixelType = unsigned char, size_t ImageDimension = 3>
void
doRead(const std::string& inputPath,
const std::string& outputPath,
const int timeIndex,
const int channelIndex,
const int datasetIndex)
{
using ImageType = itk::Image<PixelType, ImageDimension>;
auto imageReader = itk::ImageFileReader<ImageType>::New();
imageReader->SetFileName(inputPath);
template <typename PixelType = unsigned char, size_t ImageDimension = 3>
void
doRead(const std::string & inputPath,
const std::string & outputPath,
const int timeIndex,
const int channelIndex,
const int datasetIndex)
{
using ImageType = itk::Image<PixelType, ImageDimension>;
auto imageReader = itk::ImageFileReader<ImageType>::New();
imageReader->SetFileName(inputPath);

auto imageIO = itk::OMEZarrNGFFImageIO::New();
imageIO->SetDatasetIndex(datasetIndex);
imageIO->SetTimeIndex(timeIndex);
imageIO->SetChannelIndex(channelIndex);
imageReader->SetImageIO(imageIO);
auto imageIO = itk::OMEZarrNGFFImageIO::New();
imageIO->SetDatasetIndex(datasetIndex);
imageIO->SetTimeIndex(timeIndex);
imageIO->SetChannelIndex(channelIndex);
imageReader->SetImageIO(imageIO);

imageReader->UpdateOutputInformation();
auto output = imageReader->GetOutput();
output->Print(std::cout);
imageReader->UpdateOutputInformation();
auto output = imageReader->GetOutput();
output->Print(std::cout);

imageReader->Update();
output->Print(std::cout);
imageReader->Update();
output->Print(std::cout);

using WriterType = itk::ImageFileWriter<ImageType>;
auto writer = WriterType::New();
writer->SetInput(output);
writer->SetFileName(outputPath);
writer->SetUseCompression(true);
writer->Update();
}
using WriterType = itk::ImageFileWriter<ImageType>;
auto writer = WriterType::New();
writer->SetInput(output);
writer->SetFileName(outputPath);
writer->SetUseCompression(true);
writer->Update();
}
} // namespace

int
itkOMEZarrNGFFReadSliceTest(int argc, char* argv[])
itkOMEZarrNGFFReadSliceTest(int argc, char * argv[])
{
if (argc < 4)
{
std::cerr << "Missing parameters." << std::endl;
std::cerr << "Usage: " << std::endl;
std::cerr << itkNameOfTestExecutableMacro(argv)
<< " <Input> <Output> <ImageDimension> [timeIndex] [channelIndex] [datasetIndex]"
<< std::endl;
return EXIT_FAILURE;
}
const char* inputFileName = argv[1];
const char* outputFileName = argv[2];
const size_t imageDimension = std::atoi(argv[3]);
const size_t timeIndex = (argc > 4 ? std::atoi(argv[4]) : 0);
const size_t channelIndex = (argc > 5 ? std::atoi(argv[5]) : 0);
const size_t datasetIndex = (argc > 6 ? std::atoi(argv[6]) : 0);
if (argc < 4)
{
std::cerr << "Missing parameters." << std::endl;
std::cerr << "Usage: " << std::endl;
std::cerr << itkNameOfTestExecutableMacro(argv)
<< " <Input> <Output> <ImageDimension> [timeIndex] [channelIndex] [datasetIndex]" << std::endl;
return EXIT_FAILURE;
}
const char * inputFileName = argv[1];
const char * outputFileName = argv[2];
const size_t imageDimension = std::atoi(argv[3]);
const size_t timeIndex = (argc > 4 ? std::atoi(argv[4]) : 0);
const size_t channelIndex = (argc > 5 ? std::atoi(argv[5]) : 0);
const size_t datasetIndex = (argc > 6 ? std::atoi(argv[6]) : 0);

if (imageDimension == 2)
{
doRead<unsigned char, 2>(inputFileName, outputFileName, timeIndex, channelIndex, datasetIndex);
}
else if (imageDimension == 3)
{
doRead<unsigned char, 3>(inputFileName, outputFileName, timeIndex, channelIndex, datasetIndex);
}
else
{
throw std::invalid_argument("Received an invalid test case");
}
if (imageDimension == 2)
{
doRead<unsigned char, 2>(inputFileName, outputFileName, timeIndex, channelIndex, datasetIndex);
}
else if (imageDimension == 3)
{
doRead<unsigned char, 3>(inputFileName, outputFileName, timeIndex, channelIndex, datasetIndex);
}
else
{
throw std::invalid_argument("Received an invalid test case");
}

return EXIT_SUCCESS;
return EXIT_SUCCESS;
}
Loading