From 8322d3d49c7af6559078621f26770d01866e48d1 Mon Sep 17 00:00:00 2001 From: ptahmose Date: Wed, 11 Dec 2024 06:48:02 +0100 Subject: [PATCH] Refactor Get methods and update documentation - Updated `Get` methods in `CSingleChannelScalingTileAccessor` and `libCZI::ISingleChannelScalingTileAccessor` to use `IntRectAndFrameOfReference` instead of `IntRect`. - Added overloads to handle `IntRect` by converting to `IntRectAndFrameOfReference`. - Modified `InternalCalcSize` to use the transformed rectangle in the raw sub-block coordinate system. - Corrected typo in `Options` struct documentation ("back ground color" to "background color"). - Updated `SingleChannelScalingTileAccessorHandler` in `test_TileAccessorCoverageOptimization.cpp` to use a shared pointer to `ISingleChannelScalingTileAccessor`. - Added documentation to `libCZI::ISingleChannelScalingTileAccessor` interface for new `Get` methods and their parameters. --- .../SingleChannelScalingTileAccessor.cpp | 18 ++++--- Src/libCZI/SingleChannelScalingTileAccessor.h | 6 +-- Src/libCZI/libCZI_Compositor.h | 51 ++++++++++++++++--- .../test_TileAccessorCoverageOptimization.cpp | 2 +- 4 files changed, 59 insertions(+), 18 deletions(-) diff --git a/Src/libCZI/SingleChannelScalingTileAccessor.cpp b/Src/libCZI/SingleChannelScalingTileAccessor.cpp index 95df5de3..6891ada8 100644 --- a/Src/libCZI/SingleChannelScalingTileAccessor.cpp +++ b/Src/libCZI/SingleChannelScalingTileAccessor.cpp @@ -20,7 +20,7 @@ CSingleChannelScalingTileAccessor::CSingleChannelScalingTileAccessor(const std:: return InternalCalcSize(roi, zoom); } -/*virtual*/ std::shared_ptr CSingleChannelScalingTileAccessor::Get(const libCZI::IntRect& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) +/*virtual*/ std::shared_ptr CSingleChannelScalingTileAccessor::Get(const libCZI::IntRectAndFrameOfReference& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) { if (pOptions == nullptr) { @@ -38,7 +38,7 @@ CSingleChannelScalingTileAccessor::CSingleChannelScalingTileAccessor(const std:: return this->Get(pixelType, roi, planeCoordinate, zoom, pOptions); } -/*virtual*/std::shared_ptr CSingleChannelScalingTileAccessor::Get(libCZI::PixelType pixeltype, const libCZI::IntRect& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) +/*virtual*/std::shared_ptr CSingleChannelScalingTileAccessor::Get(libCZI::PixelType pixeltype, const libCZI::IntRectAndFrameOfReference& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) { if (pOptions == nullptr) { @@ -46,13 +46,14 @@ CSingleChannelScalingTileAccessor::CSingleChannelScalingTileAccessor(const std:: return this->Get(pixeltype, roi, planeCoordinate, zoom, &opt); } - const IntSize sizeOfBitmap = InternalCalcSize(roi, zoom); + const IntRect roi_raw_sub_block_cs = this->sbBlkRepository->TransformRectangle(roi, CZIFrameOfReference::RawSubBlockCoordinateSystem).rectangle; + const IntSize sizeOfBitmap = InternalCalcSize(roi_raw_sub_block_cs, zoom); auto bmDest = GetSite()->CreateBitmap(pixeltype, sizeOfBitmap.w, sizeOfBitmap.h); - this->InternalGet(bmDest.get(), roi, planeCoordinate, zoom, *pOptions); + this->InternalGet(bmDest.get(), roi_raw_sub_block_cs, planeCoordinate, zoom, *pOptions); return bmDest; } -/*virtual*/void CSingleChannelScalingTileAccessor::Get(libCZI::IBitmapData* pDest, const libCZI::IntRect& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) +/*virtual*/void CSingleChannelScalingTileAccessor::Get(libCZI::IBitmapData* pDest, const libCZI::IntRectAndFrameOfReference& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) { if (pOptions == nullptr) { @@ -60,7 +61,8 @@ CSingleChannelScalingTileAccessor::CSingleChannelScalingTileAccessor(const std:: return this->Get(pDest, roi, planeCoordinate, zoom, &opt); } - const IntSize sizeOfBitmap = InternalCalcSize(roi, zoom); + const IntRect roi_raw_sub_block_cs = this->sbBlkRepository->TransformRectangle(roi, CZIFrameOfReference::RawSubBlockCoordinateSystem).rectangle; + const IntSize sizeOfBitmap = InternalCalcSize(roi_raw_sub_block_cs, zoom); if (sizeOfBitmap.w != pDest->GetWidth() || sizeOfBitmap.h != pDest->GetHeight()) { stringstream ss; @@ -68,7 +70,7 @@ CSingleChannelScalingTileAccessor::CSingleChannelScalingTileAccessor(const std:: throw invalid_argument(ss.str().c_str()); } - this->InternalGet(pDest, roi, planeCoordinate, zoom, *pOptions); + this->InternalGet(pDest, roi_raw_sub_block_cs, planeCoordinate, zoom, *pOptions); } // ---------------------------------------------------------------------------------------------------------------------- @@ -164,7 +166,7 @@ int CSingleChannelScalingTileAccessor::GetIdxOf1stSubBlockWithZoomGreater(const } /// -/// Create an vector with indices (into the specified vector with SubBlock-infos) so that the indices give +/// Create a vector with indices (into the specified vector with SubBlock-infos) so that the indices give /// the items sorted by their "zoom"-factor. (A zoom of "1" means that the subblock is on layer-0). Subblocks of /// a higher pyramid-layer are at the end of the list. /// diff --git a/Src/libCZI/SingleChannelScalingTileAccessor.h b/Src/libCZI/SingleChannelScalingTileAccessor.h index 5c852e88..7c0fbfc0 100644 --- a/Src/libCZI/SingleChannelScalingTileAccessor.h +++ b/Src/libCZI/SingleChannelScalingTileAccessor.h @@ -29,9 +29,9 @@ class CSingleChannelScalingTileAccessor : public CSingleChannelAccessorBase, pub public: // interface ISingleChannelScalingTileAccessor libCZI::IntSize CalcSize(const libCZI::IntRect& roi, float zoom) const override; - std::shared_ptr Get(const libCZI::IntRect& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) override; - std::shared_ptr Get(libCZI::PixelType pixeltype, const libCZI::IntRect& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) override; - void Get(libCZI::IBitmapData* pDest, const libCZI::IntRect& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) override; + std::shared_ptr Get(const libCZI::IntRectAndFrameOfReference& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) override; + std::shared_ptr Get(libCZI::PixelType pixeltype, const libCZI::IntRectAndFrameOfReference& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) override; + void Get(libCZI::IBitmapData* pDest, const libCZI::IntRectAndFrameOfReference& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) override; private: static libCZI::IntSize InternalCalcSize(const libCZI::IntRect& roi, float zoom); diff --git a/Src/libCZI/libCZI_Compositor.h b/Src/libCZI/libCZI_Compositor.h index ba248239..585479ab 100644 --- a/Src/libCZI/libCZI_Compositor.h +++ b/Src/libCZI/libCZI_Compositor.h @@ -423,8 +423,8 @@ namespace libCZI /// Options used for this accessor. struct Options { - /// The back ground color. If the destination bitmap is a grayscale-type, then the mean from R, G and B is calculated and multiplied - /// with the maximum pixel value (of the specific pixeltype). If it is a RGB-color type, then R, G and B are separately multiplied with + /// The background color. If the destination bitmap is a grayscale-type, then the mean from R, G and B is calculated and multiplied + /// with the maximum pixel value (of the specific pixeltype). If it is an RGB-color type, then R, G and B are separately multiplied with /// the maximum pixel value. /// If any of R, G or B is NaN, then the background is not cleared. RgbFloatColor backGroundColor; @@ -471,11 +471,41 @@ namespace libCZI /// Calculates the size a bitmap will have (when created by this accessor) for the specified ROI and the specified Zoom. /// Since the exact size if subject to rounding errors, one should always use this method if the exact size must be known beforehand. /// The Get-method which operates on a pre-allocated bitmap will only work if the size (of the bitmap passed in) exactly matches. - /// \param roi The ROI (given in _raw-subblock-coordinate-system_, c.f. @ref coordinatesystems). + /// \param roi The ROI (since only the size is relevant here currently, the coordinate system it is given in does not matter). /// \param zoom The zoom factor. /// \return The size of the composite created by this accessor (for these parameters). virtual libCZI::IntSize CalcSize(const libCZI::IntRect& roi, float zoom) const = 0; + /// Gets the scaled tile composite of the specified plane and the specified ROI with the specified zoom factor.\n + /// The pixeltype is determined by examining the first subblock found in the + /// specified plane (which is an arbitrary subblock). A newly allocated + /// bitmap is returned. + /// \param roi The ROI and the coordinate system it is defined in. + /// \param planeCoordinate The plane coordinate. + /// \param zoom The zoom. + /// \param pOptions Options for controlling the operation (may be nullptr). + /// \return A `std::shared_ptr` containing the composite. + virtual std::shared_ptr Get(const libCZI::IntRectAndFrameOfReference& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) = 0; + + /// Gets the scaled tile composite of the specified plane and the specified ROI with the specified zoom factor. + /// \param pixeltype The pixeltype (of the destination bitmap). + /// \param roi The ROI and the coordinate system it is defined in. + /// \param planeCoordinate The plane coordinate. + /// \param zoom The zoom factor. + /// \param pOptions Options for controlling the operation (may be nullptr). + /// \return A `std::shared_ptr` containing the composite. + virtual std::shared_ptr Get(libCZI::PixelType pixeltype, const libCZI::IntRectAndFrameOfReference& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) = 0; + + /// Copy the composite to the specified bitmap. + /// The size of the bitmap must exactly match the size reported by the method "CalcSize" (for the same ROI and zoom), + /// otherwise an invalid_argument-exception is thrown. + /// \param [in,out] pDest The destination bitmap. + /// \param roi The ROI and the coordinate system it is defined in. + /// \param planeCoordinate The plane coordinate. + /// \param zoom The zoom factor. + /// \param pOptions Options controlling the operation. May be nullptr. + virtual void Get(libCZI::IBitmapData* pDest, const libCZI::IntRectAndFrameOfReference& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) = 0; + /// Gets the scaled tile composite of the specified plane and the specified ROI with the specified zoom factor.\n /// The pixeltype is determined by examining the first subblock found in the /// specified plane (which is an arbitrary subblock). A newly allocated @@ -485,7 +515,10 @@ namespace libCZI /// \param zoom The zoom. /// \param pOptions Options for controlling the operation (may be nullptr). /// \return A `std::shared_ptr` containing the composite. - virtual std::shared_ptr Get(const libCZI::IntRect& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) = 0; + std::shared_ptr Get(const libCZI::IntRect& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) + { + return this->Get(libCZI::IntRectAndFrameOfReference{ libCZI::CZIFrameOfReference::RawSubBlockCoordinateSystem, roi }, planeCoordinate, zoom, pOptions); + } /// Gets the scaled tile composite of the specified plane and the specified ROI with the specified zoom factor. /// \param pixeltype The pixeltype (of the destination bitmap). @@ -494,7 +527,10 @@ namespace libCZI /// \param zoom The zoom factor. /// \param pOptions Options for controlling the operation (may be nullptr). /// \return A `std::shared_ptr` containing the composite. - virtual std::shared_ptr Get(libCZI::PixelType pixeltype, const libCZI::IntRect& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) = 0; + std::shared_ptr Get(libCZI::PixelType pixeltype, const libCZI::IntRect& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) + { + return this->Get(pixeltype, libCZI::IntRectAndFrameOfReference{ libCZI::CZIFrameOfReference::RawSubBlockCoordinateSystem, roi }, planeCoordinate, zoom, pOptions); + } /// Copy the composite to the specified bitmap. /// The size of the bitmap must exactly match the size reported by the method "CalcSize" (for the same ROI and zoom), @@ -504,7 +540,10 @@ namespace libCZI /// \param planeCoordinate The plane coordinate. /// \param zoom The zoom factor. /// \param pOptions Options controlling the operation. May be nullptr. - virtual void Get(libCZI::IBitmapData* pDest, const libCZI::IntRect& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) = 0; + void Get(libCZI::IBitmapData* pDest, const libCZI::IntRect& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) + { + this->Get(pDest, libCZI::IntRectAndFrameOfReference{ libCZI::CZIFrameOfReference::RawSubBlockCoordinateSystem, roi }, planeCoordinate, zoom, pOptions); + } }; /// Composition operations are found in this class: multi-tile compositor and multi-channel compositor. diff --git a/Src/libCZI_UnitTests/test_TileAccessorCoverageOptimization.cpp b/Src/libCZI_UnitTests/test_TileAccessorCoverageOptimization.cpp index 2ddf5772..ecea65f6 100644 --- a/Src/libCZI_UnitTests/test_TileAccessorCoverageOptimization.cpp +++ b/Src/libCZI_UnitTests/test_TileAccessorCoverageOptimization.cpp @@ -310,7 +310,7 @@ class SingleChannelTileAccessorHandler class SingleChannelScalingTileAccessorHandler { - shared_ptr accessor_; + shared_ptr accessor_; bool sort_by_m_; public: explicit SingleChannelScalingTileAccessorHandler(bool sortByM = true) : sort_by_m_(sortByM)