Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
wip: fix czi reader
Browse files Browse the repository at this point in the history
  • Loading branch information
takashi310 committed Jun 3, 2021
1 parent d7603bc commit 507a436
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 14 deletions.
5 changes: 4 additions & 1 deletion fluorender/FluoRender/FLIVR/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,10 @@ namespace FLIVR
int numc, int* numb)
{
bool force_pow2 = false;
int max_texture_size = 65535;

int max_texture_size = 65535;
if (TextureRenderer::m_vulkan && TextureRenderer::m_vulkan->devices.size() > 0)
max_texture_size = TextureRenderer::m_vulkan->devices[0]->properties.limits.maxImageDimension3D;

//further determine the max texture size
if (TextureRenderer::get_mem_swap())
Expand Down
83 changes: 70 additions & 13 deletions fluorender/FluoRender/Formats/czi_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,31 @@ void CZIReader::SetFile(wstring &file)

void CZIReader::Preprocess()
{
FILE* pfile = 0;
auto stream = libCZI::CreateStreamFromFile(m_path_name.c_str());
auto cziReader = libCZI::CreateCZIReader();
cziReader->Open(stream);

cziReader->EnumerateSubBlocks( [&](int idx, const libCZI::SubBlockInfo& info)
{
cout << "Index " << idx << ": " << libCZI::Utils::DimCoordinateToString(&info.coordinate) << " Rect=" << info.logicalRect << endl;

if (idx == 0)
{
auto sbBlk = cziReader->ReadSubBlock(idx);
auto bitmap = sbBlk->CreateBitmap();
auto lockinfo = bitmap->Lock();
cout << "bitmap size: " << lockinfo.size << endl;
unsigned char *data = (unsigned char *)(lockinfo.ptrData);
cout << "first: " << (int)data[0] << endl;
cout << "last: " << (int)data[lockinfo.size - 1] << endl;
}

return true;
});

auto stats = cziReader->GetStatistics();
auto sbd = stats.sceneBoundingBoxes[0];
cout << "BD " << sbd.boundingBox << " BD0: " << sbd.boundingBoxLayer0 << endl;
m_slice_min = 0;
m_slice_num = 1;
m_chan_min = 0;
Expand Down Expand Up @@ -160,7 +179,7 @@ void CZIReader::Preprocess()
else
m_valid_spc = false;

//auto meta_xml = md->GetXml();
auto meta_xml = md->GetXml();

cout << "Z " << m_slice_min << " " << m_slice_num << " " << stats.boundingBox << " " << libCZI::Utils::PixelTypeToInformalString(pxtype) << endl;
//cout << meta_xml << endl;
Expand Down Expand Up @@ -301,11 +320,30 @@ Nrrd* CZIReader::Convert_ThreadSafe(int t, int c, bool get_max)

auto slice_bd = libCZI::IntRect{m_x_min, m_y_min, m_x_size, m_y_size};

libCZI::CDimCoordinate planeCoord{
{ libCZI::DimensionIndex::Z, m_slice_min },
{ libCZI::DimensionIndex::C, c+m_chan_min },
{ libCZI::DimensionIndex::T, t+m_time_min }
};
libCZI::CDimCoordinate planeCoord;

auto stats = cziReader->GetStatistics();
stats.dimBounds.EnumValidDimensions(
[this, &planeCoord, c, t](libCZI::DimensionIndex idx, int start, int size)
{
switch(idx)
{
case libCZI::DimensionIndex::Z:
planeCoord.Set(idx, m_slice_min);
break;
case libCZI::DimensionIndex::C:
planeCoord.Set(idx, c+m_chan_min);
break;
case libCZI::DimensionIndex::T:
planeCoord.Set(idx, t+m_time_min);
break;
default:
planeCoord.Set(idx, start);
break;
}
return true;
}
);

int slice_max = m_slice_min + m_slice_num;
size_t slice_size = (unsigned long long)m_x_size * (unsigned long long)m_y_size;
Expand Down Expand Up @@ -337,13 +375,32 @@ Nrrd* CZIReader::Convert_ThreadSafe(int t, int c, bool get_max)
auto accessor = cziReader->CreateSingleChannelTileAccessor();

auto slice_bd = libCZI::IntRect{m_x_min, m_y_min, m_x_size, m_y_size};

libCZI::CDimCoordinate planeCoord;

libCZI::CDimCoordinate planeCoord{
{ libCZI::DimensionIndex::Z, m_slice_min },
{ libCZI::DimensionIndex::C, c+m_chan_min },
{ libCZI::DimensionIndex::T, t+m_time_min }
};

auto stats = cziReader->GetStatistics();
stats.dimBounds.EnumValidDimensions(
[this, &planeCoord, c, t](libCZI::DimensionIndex idx, int start, int size)
{
switch(idx)
{
case libCZI::DimensionIndex::Z:
planeCoord.Set(idx, m_slice_min);
break;
case libCZI::DimensionIndex::C:
planeCoord.Set(idx, c+m_chan_min);
break;
case libCZI::DimensionIndex::T:
planeCoord.Set(idx, t+m_time_min);
break;
default:
planeCoord.Set(idx, start);
break;
}
return true;
}
);

int slice_max = m_slice_min + m_slice_num;
size_t slice_size = (unsigned long long)m_x_size * (unsigned long long)m_y_size * 2ULL;
for (size_t i = m_slice_min; i < slice_max; i++)
Expand Down

0 comments on commit 507a436

Please sign in to comment.