Skip to content

Commit

Permalink
Refactor Get methods and update documentation
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
ptahmose committed Dec 11, 2024
1 parent 265e58f commit 8322d3d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 18 deletions.
18 changes: 10 additions & 8 deletions Src/libCZI/SingleChannelScalingTileAccessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ CSingleChannelScalingTileAccessor::CSingleChannelScalingTileAccessor(const std::
return InternalCalcSize(roi, zoom);
}

/*virtual*/ std::shared_ptr<libCZI::IBitmapData> CSingleChannelScalingTileAccessor::Get(const libCZI::IntRect& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions)
/*virtual*/ std::shared_ptr<libCZI::IBitmapData> CSingleChannelScalingTileAccessor::Get(const libCZI::IntRectAndFrameOfReference& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions)
{
if (pOptions == nullptr)
{
Expand All @@ -38,37 +38,39 @@ CSingleChannelScalingTileAccessor::CSingleChannelScalingTileAccessor(const std::
return this->Get(pixelType, roi, planeCoordinate, zoom, pOptions);
}

/*virtual*/std::shared_ptr<libCZI::IBitmapData> CSingleChannelScalingTileAccessor::Get(libCZI::PixelType pixeltype, const libCZI::IntRect& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions)
/*virtual*/std::shared_ptr<libCZI::IBitmapData> CSingleChannelScalingTileAccessor::Get(libCZI::PixelType pixeltype, const libCZI::IntRectAndFrameOfReference& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions)
{
if (pOptions == nullptr)
{
Options opt; opt.Clear();
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)
{
Options opt; opt.Clear();
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);

Check warning on line 65 in Src/libCZI/SingleChannelScalingTileAccessor.cpp

View check run for this annotation

Codecov / codecov/patch

Src/libCZI/SingleChannelScalingTileAccessor.cpp#L64-L65

Added lines #L64 - L65 were not covered by tests
if (sizeOfBitmap.w != pDest->GetWidth() || sizeOfBitmap.h != pDest->GetHeight())
{
stringstream ss;
ss << "The specified bitmap has a size of " << pDest->GetWidth() << "*" << pDest->GetHeight() << ", whereas the expected size is " << sizeOfBitmap.w << "*" << sizeOfBitmap.h << ".";
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);

Check warning on line 73 in Src/libCZI/SingleChannelScalingTileAccessor.cpp

View check run for this annotation

Codecov / codecov/patch

Src/libCZI/SingleChannelScalingTileAccessor.cpp#L73

Added line #L73 was not covered by tests
}

// ----------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -164,7 +166,7 @@ int CSingleChannelScalingTileAccessor::GetIdxOf1stSubBlockWithZoomGreater(const
}

/// <summary>
/// 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.
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions Src/libCZI/SingleChannelScalingTileAccessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<libCZI::IBitmapData> Get(const libCZI::IntRect& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) override;
std::shared_ptr<libCZI::IBitmapData> 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<libCZI::IBitmapData> Get(const libCZI::IntRectAndFrameOfReference& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) override;
std::shared_ptr<libCZI::IBitmapData> 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);

Expand Down
51 changes: 45 additions & 6 deletions Src/libCZI/libCZI_Compositor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<libCZI::IBitmapData>` containing the composite.
virtual std::shared_ptr<libCZI::IBitmapData> 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<libCZI::IBitmapData>` containing the composite.
virtual std::shared_ptr<libCZI::IBitmapData> 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
Expand All @@ -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<libCZI::IBitmapData>` containing the composite.
virtual std::shared_ptr<libCZI::IBitmapData> Get(const libCZI::IntRect& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) = 0;
std::shared_ptr<libCZI::IBitmapData> 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).
Expand All @@ -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<libCZI::IBitmapData>` containing the composite.
virtual std::shared_ptr<libCZI::IBitmapData> Get(libCZI::PixelType pixeltype, const libCZI::IntRect& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) = 0;
std::shared_ptr<libCZI::IBitmapData> 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),
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class SingleChannelTileAccessorHandler

class SingleChannelScalingTileAccessorHandler
{
shared_ptr<CSingleChannelScalingTileAccessor> accessor_;
shared_ptr<ISingleChannelScalingTileAccessor> accessor_;
bool sort_by_m_;
public:
explicit SingleChannelScalingTileAccessorHandler(bool sortByM = true) : sort_by_m_(sortByM)
Expand Down

0 comments on commit 8322d3d

Please sign in to comment.