SlideIO 2.10.0
Open-source library for reading of medical images
Loading...
Searching...
No Matches
svstiledscene.hpp
1// This file is part of slideio project.
2// It is subject to the license terms in the LICENSE file found in the top-level directory
3// of this distribution and at http://slideio.com/license.html.
4#pragma once
5
6#include "slideio/drivers/svs/svsscene.hpp"
7#include "slideio/imagetools/tifftools.hpp"
8#include "slideio/core/tools/tilecomposer.hpp"
9
10#if defined(_MSC_VER)
11#pragma warning( push )
12#pragma warning(disable: 4251)
13#endif
14
15namespace slideio
16{
17 class SLIDEIO_SVS_EXPORTS SVSTiledScene : public SVSScene, public Tiler
18 {
19 public:
20 // Constructs and initializes. A factory rather than a constructor call because
21 // initialize() reads the image description through a virtual method, and a
22 // virtual call made from a constructor does not reach a derived override.
23 static std::shared_ptr<SVSTiledScene> create(const std::string& filePath,
24 const std::string& driverId, const std::string& name,
25 const std::vector<slideio::TiffDirectory>& dirs);
26 static std::shared_ptr<SVSTiledScene> create(const std::string& filePath,
27 const std::string& driverId, libtiff::TIFF* hFile, const std::string& name,
28 const std::vector<slideio::TiffDirectory>& dirs);
29 int getNumChannels() const override;
30 cv::Rect getRect() const override;
31 void readResampledBlockChannelsEx(const cv::Rect& blockRect, const cv::Size& blockSize,
32 const std::vector<int>& channelIndices, int zSliceIndex, int tFrameIndex, cv::OutputArray output) override;
33 void readResampledLevelBlockChannelsEx(int level, const cv::Rect& levelRect,
34 const cv::Size& blockSize, const std::vector<int>& channelIndices,
35 int zSliceIndex, int tFrameIndex, cv::OutputArray output) override;
36 // Returns the index of the level serving a zoom, not the directory: the level index
37 // is what the level-addressed read path takes.
38 int findZoomLevelIndex(double zoom) const;
39 // Tiler methods
40 int getTileCount(void* userData) override;
41 bool getTileRect(int tileIndex, cv::Rect& tileRect, void* userData) override;
42 bool readTile(int tileIndex, const std::vector<int>& channelIndices, cv::OutputArray tileRaster,
43 void* userData) override;
44 protected:
45 // Protected rather than public: a caller constructing the scene directly, instead
46 // of through create(), would skip initialize() and silently get a scene with zero
47 // zoom levels and zero resolution. The factories are members, so they still reach
48 // these, and so does a derived class's own constructor.
49 SVSTiledScene(const std::string& filePath,
50 const std::string& driverId,
51 const std::string& name,
52 const std::vector<slideio::TiffDirectory>& dirs);
53 SVSTiledScene(const std::string& filePath,
54 const std::string& driverId,
55 libtiff::TIFF* hFile,
56 const std::string& name,
57 const std::vector<slideio::TiffDirectory>& dirs);
58 void initialize();
59 // Reads the format specific fields — resolution, magnification, raw metadata —
60 // out of the description of the base directory. Called by initialize().
61 virtual void processImageDescription();
62 void initializeBlock(const cv::Size& blockSize, const std::vector<int>& channelIndices, cv::OutputArray output) override;
66 ContextPool::Borrow acquireContext() { return m_contextPool.acquire(); }
67
68 std::vector<slideio::TiffDirectory> m_directories;
69 private:
70 // Declared last on purpose, and it must stay last. ~ContextPool blocks
71 // until every outstanding borrow is returned, but members are destroyed
72 // in reverse declaration order, so only a pool declared after
73 // m_directories is destroyed *before* the vector that readTile's
74 // userData points into. A pool declared any earlier -- in SVSScene, say
75 // -- would let an in-flight read dereference a freed directory.
76 // PHTIFFTiledScene derives from this class and adds only metadata that
77 // the read path never touches, so its members dying first is harmless.
78 ContextPool m_contextPool;
79 };
80}
81
82#if defined(_MSC_VER)
83#pragma warning( pop )
84#endif
Definition: converter.hpp:18