4#ifndef OPENCV_slideio_tools_HPP
5#define OPENCV_slideio_tools_HPP
14#include "slideio/core/slideio_core_def.hpp"
19#include <opencv2/core.hpp>
20#include "slideio/base/slideio_enums.hpp"
21#include "slideio/base/slideio_structs.hpp"
25 class SLIDEIO_CORE_EXPORTS Tools
29 void operator()(std::FILE* file)
const {
35 static bool matchPattern(
const std::string& path,
const std::string& pattern);
36 static std::vector<int> completeChannelList(
const std::vector<int>& orgChannelList,
int numChannels)
38 std::vector<int> channelList(orgChannelList);
39 if(channelList.empty())
41 channelList.resize(numChannels);
42 for(
int channel=0; channel<numChannels; ++channel)
44 channelList[channel] = channel;
49 template <
typename Functor>
50 static int findZoomLevel(
double zoom,
int numLevels, Functor zoomFunction)
55 const double baseZoom = zoomFunction(0);
60 int goodLevelIndex = -1;
61 double lastZoom = baseZoom;
62 for (
int levelIndex = 1; levelIndex < numLevels; levelIndex++)
64 const double currentZoom = zoomFunction(levelIndex);
65 const double absDif = std::abs(currentZoom - zoom);
66 const double relDif = absDif / currentZoom;
69 goodLevelIndex = levelIndex;
72 if (zoom <= lastZoom && zoom > currentZoom)
74 goodLevelIndex = levelIndex - 1;
77 lastZoom = currentZoom;
79 if (goodLevelIndex < 0)
81 goodLevelIndex = numLevels - 1;
83 return goodLevelIndex;
85 static void convert12BitsTo16Bits(
const uint8_t* source, uint16_t* target,
int targetLen);
86 static void scaleRect(
const cv::Rect& srcRect,
const cv::Size& newSize, cv::Rect& trgRect);
87 static void scaleRect(
const cv::Rect& srcRect,
double scaleX,
double scaleY, cv::Rect& trgRect);
88 static bool isCompleteChannelList(
const std::vector<int>& channelIndices,
const int numChannels)
90 bool allChannels = channelIndices.empty();
92 if (channelIndices.size() == numChannels) {
94 for (
int channel = 0; channel < channelIndices.size(); ++channel) {
95 if (channelIndices[channel] != channel) {
105 static std::wstring toWstring(
const std::string&
string);
108 static std::string fromUnicode16(
const std::u16string& u16string);
109 static void throwIfPathNotExist(
const std::string& path,
const std::string label);
110 static std::list<std::string> findFilesWithExtension(
const std::string& directory,
const std::string& extension);
111 static void extractChannels(
const cv::Mat& sourceRaster,
const std::vector<int>& channels, cv::OutputArray output);
112 static FILE* openFile(
const std::string& filePath,
const char* mode);
113 static uint64_t getFilePos(FILE* file);
114 static int setFilePos(FILE* file, uint64_t pos,
int origin);
115 static uint64_t getFileSize(FILE* file);
116 static int dataTypeSize(slideio::DataType dt);
117 static Size cvSizeToSize(
const cv::Size& cvSize) {
118 return {cvSize.width, cvSize.height};
120 static Rect cvRectToRect(
const cv::Rect& cvRect) {
121 return {cvRect.x, cvRect.y, cvRect.width, cvRect.height};
123 static void replaceAll(std::string& str,
const std::string& from,
const std::string& to);
124 static std::vector<std::string> split(
const std::string& value,
char delimiter);
Definition: exceptions.hpp:15