Skip to content

Commit 4efc937

Browse files
authored
Bugfix: support 2/3/4D zarr file (#21)
1 parent d570f99 commit 4efc937

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/cpp/reader/tsreader.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ std::shared_ptr<std::vector<T>> TsReaderCPP::GetImageDataTemplated(const Seq& ro
108108
const auto data_tsteps = tsteps.Stop() - tsteps.Start() + 1;
109109

110110
auto read_buffer = std::make_shared<std::vector<T>>(data_height*data_width*data_depth*data_num_channels*data_tsteps);
111-
auto array = tensorstore::Array(read_buffer->data(), {data_tsteps, data_num_channels, data_depth, data_height, data_width}, tensorstore::c_order);
112111
tensorstore::IndexTransform<> read_transform = tensorstore::IdentityTransform(source.domain());
113112

114113
if (_file_type == FileType::OmeTiff) {
@@ -117,31 +116,38 @@ std::shared_ptr<std::vector<T>> TsReaderCPP::GetImageDataTemplated(const Seq& ro
117116
tensorstore::Dims(2).ClosedInterval(layers.Start(), layers.Stop()) |
118117
tensorstore::Dims(3).ClosedInterval(rows.Start(), rows.Stop()) |
119118
tensorstore::Dims(4).ClosedInterval(cols.Start(), cols.Stop())).value();
119+
120+
auto array = tensorstore::Array(read_buffer->data(), {data_tsteps, data_num_channels, data_depth, data_height, data_width}, tensorstore::c_order);
121+
tensorstore::Read(source | read_transform, tensorstore::UnownedToShared(array)).value();
120122
} else {
121-
int x_index=1, y_index=0;
123+
std::vector<std::int64_t> array_shape;
124+
array_shape.reserve(5);
125+
auto source_shape = source.domain().shape();
126+
int x_index = static_cast<int>(source_shape.size()) - 1;
127+
int y_index = static_cast<int>(source_shape.size()) - 2;
128+
122129
if (_t_index.has_value()){
123130
read_transform = (std::move(read_transform) | tensorstore::Dims(_t_index.value()).ClosedInterval(tsteps.Start(), tsteps.Stop())).value();
124-
x_index++;
125-
y_index++;
131+
array_shape.push_back(data_tsteps);
126132
}
127133
if (_c_index.has_value()){
128134
read_transform = (std::move(read_transform) | tensorstore::Dims(_c_index.value()).ClosedInterval(channels.Start(), channels.Stop())).value();
129-
x_index++;
130-
y_index++;
135+
array_shape.push_back(data_num_channels);
131136
}
132137
if (_z_index.has_value()){
133138
read_transform = (std::move(read_transform) | tensorstore::Dims(_z_index.value()).ClosedInterval(layers.Start(), layers.Stop())).value();
134-
x_index++;
135-
y_index++;
139+
array_shape.push_back(data_depth);
136140
}
137141
read_transform = (std::move(read_transform) | tensorstore::Dims(y_index).ClosedInterval(rows.Start(), rows.Stop()) |
138142
tensorstore::Dims(x_index).ClosedInterval(cols.Start(), cols.Stop())).value();
139-
143+
144+
array_shape.push_back(data_height);
145+
array_shape.push_back(data_width);
146+
147+
auto array = tensorstore::Array(read_buffer->data(), array_shape, tensorstore::c_order);
148+
tensorstore::Read(source | read_transform, tensorstore::UnownedToShared(array)).value();
140149
}
141150

142-
143-
tensorstore::Read(source | read_transform, tensorstore::UnownedToShared(array)).value();
144-
145151
return read_buffer;
146152
}
147153

0 commit comments

Comments
 (0)