Skip to content

Commit

Permalink
Untangle dependencies, fix iter bug
Browse files Browse the repository at this point in the history
  • Loading branch information
sameeul committed May 28, 2024
1 parent b44be95 commit ba79bd7
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 27 deletions.
7 changes: 5 additions & 2 deletions src/cpp/interface/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <tuple>
#include "../reader/tsreader.h"
#include "../reader/sequence.h"
#include "../reader/utilities.h"

namespace py = pybind11;
using bfiocpp::Seq;

Expand Down Expand Up @@ -79,8 +81,7 @@ PYBIND11_MODULE(libbfiocpp, m) {
.def("get_tile_depth", &bfiocpp::TsReaderCPP::GetTileDepth)
.def("get_channel_count", &bfiocpp::TsReaderCPP::GetChannelCount)
.def("get_tstep_count", &bfiocpp::TsReaderCPP::GetTstepCount)
.def("get_datatype", &bfiocpp::TsReaderCPP::GetDataType)
.def("get_ome_xml_metadata", &bfiocpp::TsReaderCPP::GetOmeXml)
.def("get_datatype", &bfiocpp::TsReaderCPP::GetDataType)
.def("get_tile_coordinate",
[](bfiocpp::TsReaderCPP& tl, std::int64_t y_start, std::int64_t x_start, std::int64_t row_stride, std::int64_t col_stride) {
auto row_index = static_cast<std::int64_t>(y_start/row_stride);
Expand Down Expand Up @@ -113,4 +114,6 @@ PYBIND11_MODULE(libbfiocpp, m) {
.value("OmeTiff", bfiocpp::FileType::OmeTiff)
.value("OmeZarr", bfiocpp::FileType::OmeZarr)
.export_values();

m.def("get_ome_xml", &bfiocpp::GetOmeXml);
}
18 changes: 2 additions & 16 deletions src/cpp/reader/tsreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "tsreader.h"
#include "utilities.h"
#include "type_info.h"
#include <tiffio.h>


using ::tensorstore::internal_zarr::ChooseBaseDType;
Expand Down Expand Up @@ -185,32 +184,19 @@ std::shared_ptr<image_data> TsReaderCPP::GetImageData(const Seq& rows, const Seq
}
}

std::string TsReaderCPP::GetOmeXml() const{
TIFF *tiff_file = TIFFOpen(_filename.c_str(), "r");
std::string OmeXmlInfo{""};
if (tiff_file != nullptr) {
char* infobuf;
TIFFGetField(tiff_file, TIFFTAG_IMAGEDESCRIPTION , &infobuf);
if (strlen(infobuf)>0){
OmeXmlInfo = std::string(infobuf);
}
}
TIFFClose(tiff_file);
return OmeXmlInfo;
}

void TsReaderCPP::SetIterReadRequests(std::int64_t const tile_width, std::int64_t const tile_height, std::int64_t const row_stride, std::int64_t const col_stride){
iter_request_list.clear();
for(std::int64_t t=0; t<_num_tsteps;++t){
for(std::int64_t c=0; c<_num_channels;++c){
for(std::int64_t z=0; z<_image_depth;++z){
for(std::int64_t y=0; y<=_image_height;y+=row_stride)
for(std::int64_t y=0; y<_image_height;y+=row_stride)
{
auto y_min = y;
auto y_max = y_min + row_stride - 1;
y_max = y_max < _image_height ? y_max : _image_height-1;

for(std::int64_t x=0; x<=_image_width;x+=col_stride){
for(std::int64_t x=0; x<_image_width;x+=col_stride){
auto x_min = x;
auto x_max = x_min + col_stride - 1;
x_max = x_max < _image_width ? x_max : _image_width-1;
Expand Down
1 change: 0 additions & 1 deletion src/cpp/reader/tsreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class TsReaderCPP{
std::int64_t GetTstepCount () const;
std::string GetDataType() const;
std::shared_ptr<image_data> GetImageData(const Seq& rows, const Seq& cols, const Seq& layers, const Seq& channels, const Seq& tsteps);
std::string GetOmeXml() const;
void SetIterReadRequests(std::int64_t const tile_width, std::int64_t const tile_height, std::int64_t const row_stride, std::int64_t const col_stride);
//tuple of (T,C,Z,Y_min, Y_max, X_min, X_max)
std::vector<iter_indicies> iter_request_list;
Expand Down
17 changes: 17 additions & 0 deletions src/cpp/reader/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <chrono>
#include "utilities.h"
#include <cassert>
#include <tiffio.h>

namespace bfiocpp {
tensorstore::Spec GetOmeTiffSpecToRead(const std::string& filename){
Expand Down Expand Up @@ -91,4 +92,20 @@ std::tuple<std::optional<int>, std::optional<int>, std::optional<int>>ParseMulti
}
return {t_index, c_index, z_index};
}


std::string GetOmeXml(const std::string& file_path){
TIFF *tiff_file = TIFFOpen(file_path.c_str(), "r");
std::string OmeXmlInfo{""};
if (tiff_file != nullptr) {
char* infobuf;
TIFFGetField(tiff_file, TIFFTAG_IMAGEDESCRIPTION , &infobuf);
if (strlen(infobuf)>0){
OmeXmlInfo = std::string(infobuf);
}
TIFFClose(tiff_file);
}
return OmeXmlInfo;
}

} // ns bfiocpp
1 change: 1 addition & 0 deletions src/cpp/reader/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ tensorstore::Spec GetZarrSpecToRead(const std::string& filename);

uint16_t GetDataTypeCode (std::string_view type_name);
std::string GetUTCString();
std::string GetOmeXml(const std::string& file_path);
std::tuple<std::optional<int>, std::optional<int>, std::optional<int>>ParseMultiscaleMetadata(const std::string& axes_list, int len);
} // ns bfiocpp
2 changes: 1 addition & 1 deletion src/python/bfiocpp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .tsreader import TSReader, Seq, FileType # NOQA: F401
from .tsreader import TSReader, Seq, FileType, get_ome_xml # NOQA: F401
from . import _version

__version__ = _version.get_versions()["version"]
8 changes: 1 addition & 7 deletions src/python/bfiocpp/tsreader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
from typing import Tuple
from .libbfiocpp import TsReaderCPP, Seq, FileType # NOQA: F401
from .libbfiocpp import TsReaderCPP, Seq, FileType, get_ome_xml # NOQA: F401


class TSReader:
Expand All @@ -22,12 +22,6 @@ def data(
) -> np.ndarray:
return self._image_reader.get_image_data(rows, cols, layers, channels, tsteps)

def get_ome_metadata(self) -> str:
if self._filetype == FileType.OmeTiff:
return self._image_reader.get_ome_xml_metadata()
else:
return ""

def send_iter_read_request(
self, tile_size: Tuple[int, int], tile_stride: Tuple[int, int]
) -> None:
Expand Down

0 comments on commit ba79bd7

Please sign in to comment.