6#ifndef iimg_CScanlineMask_included
7#define iimg_CScanlineMask_included
14#include <QtCore/QList>
188 void Erode(
int leftValue,
int rightValue,
int topValue,
int bottomValue);
194 void Dilate(
int leftValue,
int rightValue,
int topValue,
int bottomValue);
228 template <
typename PixelType>
239 mutable bool m_isBoundingBoxValid;
255 if (!m_isBoundingBoxValid) {
263template <
typename PixelType>
268 int linesCount = int(m_scanlines.size());
269 if (linesCount <= 0) {
275 m_rangesContainer.reserve(linesCount);
281 for (
int lineIndex = 0; lineIndex < linesCount; lineIndex++) {
284 PixelType* imageLinePtr = (PixelType*)bitmap.
GetLinePtr(lineIndex);
285 Q_ASSERT(imageLinePtr !=
nullptr);
290 for (
int x = 0; x < imageWidth; ++x) {
291 PixelType pixel = *(imageLinePtr + x);
292 if ((pixel > 0) && (left < 0)) {
296 if ((pixel == 0) && (left >= 0)) {
298 if (clipAreaPtr !=
nullptr) {
299 if (left < clipAreaPtr->GetLeft()) {
303 if (right > clipAreaPtr->
GetRight()) {
318 if ((left >= 0) && (right < 0)) {
323 m_rangesContainer.push_back(rangeList);
325 m_scanlines[lineIndex] = m_rangesContainer.size() - 1;
328 m_scanlines[lineIndex] = -1;
Definition of graphical annulus object.
Definition of graphical circle object.
Base class for 2D-objects implementing interface i2d::IObject2d.
Definition of the data model for a polygon.
Simple rectangle with integer bounds.
Definition of rectangle area orthogonal to axis of coordination system.
Definition of tube region based on polyline.
Definition of position or mathematical vector on 2D plane.
Common interface for describing the 2D-objects.
virtual CRectangle GetBoundingBox() const =0
Get bounding box of this shape.
Generic color implementation with variable number of color components.
Representation of a 2D-region as container of bitmap line scans.
icmm::CVarColor GetColorAt(const istd::CIndex2d &position) const override
Get color at specified pixel.
bool Serialize(iser::IArchive &archive) override
Load or store state of this object as a archive stream.
bool CopyFrom(const istd::IChangeable &object, CompatibilityMode mode=CM_WITHOUT_REFS) override
Copy this object from another one.
void CreateFromBitmap(const iimg::IBitmap &bitmap, const i2d::CRect *clipAreaPtr=nullptr)
Create 2D-region from a bitmap.
void GetTranslated(int dx, int dy, CScanlineMask &result) const
Calculate translated (moved) mask.
istd::CIndex2d GetImageSize() const override
Get size of this raster image.
void GetUnion(const CScanlineMask &mask, CScanlineMask &result) const
Get union of two masks.
void CalculateMaskFromBitmap(const iimg::IBitmap &bitmap, const i2d::CRect *clipAreaPtr=nullptr)
CScanlineMask GetUnion(const CScanlineMask &mask) const
Get union of two masks.
bool CreateFromGeometry(const i2d::IObject2d &geometry, const i2d::CRect *clipAreaPtr=nullptr)
Create 2D-region from some geometrical object.
std::vector< int > Scanlines
i2d::CObject2dBase BaseClass
void CreateFromPolygon(const i2d::CPolygon &polygon, const i2d::CRect *clipAreaPtr=nullptr)
Create 2D-region from polygon.
int GetSupportedOperations() const override
Get set of flags for supported operations.
void CreateFromCircle(const i2d::CCircle &circle, const i2d::CRect *clipAreaPtr=nullptr)
Create 2D-region from circle.
void ResetScanlines(const istd::CIntRange &verticalRange)
Set this mask to empty set for some vertical range.
void CalcBoundingBox() const
i2d::CRect GetBoundingRect() const
Get rectangle containing all active pixels.
void ResetImage() override
Reset this image.
void Dilate(int leftValue, int rightValue, int topValue, int bottomValue)
Calculate dilatation of this range list with rectangle structured element.
bool SetColorAt(const istd::CIndex2d &position, const icmm::CVarColor &color) override
Set color at specified pixel.
void GetIntersection(const CScanlineMask &mask, CScanlineMask &result) const
Get intersection of two masks.
bool IsEmpty() const override
Return true if this image is empty.
bool operator==(const CScanlineMask &mask) const
void Erode(int leftValue, int rightValue, int topValue, int bottomValue)
Calculate erosion of this range list with rectangle structured element.
bool IsBitmapRegionEmpty() const
Check if region is empty.
int GetComponentsCount() const override
Get number of color components.
const istd::CIntRanges * GetPixelRanges(int lineIndex) const
Get the list of pixel ranges per given line.
QList< istd::CIntRanges > RangesContainer
void Union(const CScanlineMask &mask)
Calculate union of this mask and the other one.
i2d::CVector2d GetCenter() const override
Returns center of this 2D-object.
void ClearImage() override
Cleat this image.
bool ResetData(CompatibilityMode mode=CM_WITHOUT_REFS) override
Reset data to its default state.
void MoveCenterTo(const i2d::CVector2d &position) override
Move object to position position.
void CreateFromRectangle(const i2d::CRectangle &rect, const i2d::CRect *clipAreaPtr=nullptr)
Create 2D-region from rectangle.
void CreateFromAnnulus(const i2d::CAnnulus &annulus, const i2d::CRect *clipAreaPtr=nullptr)
Create 2D-region from annulus.
CScanlineMask GetTranslated(int dx, int dy) const
Calculate translated (moved) mask.
void CreateFilled(const i2d::CRect &clipArea)
Create filled 2D-region clipped to rectangle area.
void Intersection(const CScanlineMask &mask)
Calculate intersection of this mask and the other one.
void GetInverted(const i2d::CRect &clipArea, CScanlineMask &result) const
Get inverted mask.
friend size_t qHash(const CScanlineMask &key, size_t seed)
bool operator!=(const CScanlineMask &mask) const
void EnsureBoundingBoxValid() const
void InitFromBoundingBox(const i2d::CRectangle &objectBoundingBox, const i2d::CRect *clipAreaPtr)
CScanlineMask GetIntersection(const CScanlineMask &mask) const
Get intersection of two masks.
void CreateFromTube(const i2d::CTubePolyline &tube, const i2d::CRect *clipAreaPtr=nullptr)
Create 2D-region from tube.
void Translate(int dx, int dy)
Translated (move) this mask.
void Invert(const i2d::CRect &clipArea)
Invert mask on place.
i2d::CRectangle GetBoundingBox() const override
Get bounding box of this shape.
Definition of single plane bitmap.
virtual const void * GetLinePtr(int positionY) const =0
Get pointer to buffer for single line.
General definition of image contains pixels in regular grid.
virtual istd::CIndex2d GetImageSize() const =0
Get size of this raster image.
Represent input/output persistence archive.
Index implementation for addressing elements in 2D-space.
Common interface for data model objects, which can be changed.
CompatibilityMode
Control how relationship betweeen objects are interpreted.
@ CM_WITHOUT_REFS
External references are simple ignored.
void InsertSwitchPoint(ValueType point)
Insert new switch point.
bool IsEmpty() const
Check if this set is empty.
Contains the system indenendent definitions of image and related themes.
size_t qHash(const CScanlineMask &key, size_t seed=0)