22 #ifndef CRNBLOCK_HEADER
23 #define CRNBLOCK_HEADER
58 static SBlock
New(
const Path &ifname,
const Path &xfname,
const String &nam = U
"");
148 SImageGray
GetGray(
bool create =
true);
150 SImageBW
GetBW(
bool create =
true);
152 SImageGradient
GetGradient(
bool create =
true,
double sigma = -1,
size_t diffusemaxiter = 0,
double diffusemaxdiv = std::numeric_limits<double>::max());
156 void FlushAll(
bool recursive =
false);
158 void FlushRGB(
bool recursive =
false);
162 void FlushBW(
bool recursive =
false);
198 void GetTreeMeans(
const String &tree,
double *mwidth,
double *mheight,
double *marea)
const;
214 if (child->Find(name) == child->end())
return nullptr;
215 else return std::static_pointer_cast<
Vector>(child->Get(name));
220 if (child->Find(name) == child->end())
return nullptr;
221 else return std::static_pointer_cast<
const Vector>(child->Get(name));
246 pixel_iterator(it),mask(it.mask),offsetx(it.offsetx),offsety(it.offsety),value(it.value)
249 if (mask->At(
pos.
X - offsetx,
pos.
Y - offsety) != value)
256 if (mask->At(
pos.
X - offsetx,
pos.
Y - offsety) != value)
267 offsetx = it.offsetx;
268 offsety = it.offsety;
277 if (mask->At(
pos.
X - offsetx,
pos.
Y - offsety) == value)
285 int offsetx, offsety;
303 static SBlock create(
const WBlock &par,
const String &tree,
const Rect &clip,
const String &nam = U
"");
314 void openImage(
void);
316 void refreshSources();
320 SVector getChildList(
const String &name);
329 SImageRGB get_srcRGB(
void);
332 SImageGray get_srcGray(
void);
335 SImageBW get_srcBW(
void);
336 SImageGradient srcGradient;
338 SImageGradient get_srcGradient(
void);
343 SImageGradient buffGradient;
345 size_t grad_diffusemaxiter;
346 double grad_diffusemaxdiv;
block_iterator BlockBegin(const String &tree)
Returns an iterator on the first block of a tree.
bool Append(const Path &fname)
Appends child trees from a file.
virtual const iterator & operator++() noexcept
void Save()
Saves the child trees into the default file.
Abstract class for images.
SBlock AddChildRelativeAt(const String &tree, Rect clip, size_t pos)
Adds a child to current block.
virtual ~masked_pixel_iterator() override
Destructor.
SVector GetTree(const String &name)
Returns a list of children. Can be used with CRN_FOREACH.
void FilterMaxOr(const String &tree, size_t maxw, size_t maxh)
Filters a child tree.
void FilterHeightRatio(const String &tree, double ratio)
Filters a child tree.
void FlushGray(bool recursive=false)
Frees the local gray buffer.
SBlock AddChildRelative(const String &tree, Rect clip)
Adds a child to current block.
Iterator on the blocks of a child tree.
void RemoveChildren(const String &tree, const std::set< SBlock > &toremove)
Removes a set of blocks from a child tree.
void FilterBorders(const String &tree, size_t margin)
Filters a child tree.
iterator & operator=(const iterator &)=default
complex base abstract class
block_iterator BlockEnd(const String &tree)
Returns an iterator after the last block of a tree.
void FilterMinOr(const String &tree, size_t minw, size_t minh)
Filters a child tree.
void SetAbsoluteBBox(const Rect &newbox)
Sets the absolute bounding box of the block.
std::vector< String > GetTreeNames() const
Gets the list of the tree names.
WBlock GetTop()
Gets a reference to the topmost parent of the block.
void SetFilename(const Path &nam)
Sets the default filename of the block.
WBlock GetParent()
Gets a reference to the parent of the block.
void MergeSiblings(const String &tree, size_t index1, size_t index2, ImageIntGray *imap=nullptr)
Merges two subblocks.
Direction
An enumeration of directions.
virtual ~Block() override
Destructor.
void FilterMinAnd(const String &tree, size_t minw, size_t minh)
Filters a child tree.
bool IsParent(const Block &b) const
Checks if a block is a parent of current.
A UTF32 character string class.
SImageBW GetBW(bool create=true)
Returns a pointer to the local b&w buffer.
pixel_iterator PixelEnd(const String &tree, size_t num) const
Returns an iterator after the last pixel of the block.
bool MergeChildren(const String &tree, double overlap, ImageIntGray *imap=nullptr)
Merges overlapping children in a tree.
void SubstituteGradient(const SImageGradient &img)
Substitutes the Gradient buffer with a new one.
SImageGray GetGray(bool create=true)
Returns a pointer to the local gray buffer.
static SBlock New(const SImage &src, const String &nam=U"")
Top block creator.
virtual const masked_pixel_iterator & operator++() noexceptoverride
Go to next pixel in mask.
const Rect & GetAbsoluteBBox() const noexcept
Gets the absolute bounding box of the block.
A convenience class for file paths.
masked_pixel_iterator MaskedPixelBegin(const String &tree, size_t num, pixel::BW mask_value=pixel::BWBlack)
Returns a masked iterator on the first pixel of the block.
masked_pixel_iterator(const Rect &r, const SImageBW &ibw, int ox, int oy, pixel::BW val=pixel::BWBlack) noexcept
Constructor.
SBlock AddChildAbsoluteAt(const String &tree, Rect clip, size_t pos)
Adds a child to current block.
void SortTree(const String &name, Direction direction)
Sorts a child tree.
void FlushBW(bool recursive=false)
Frees the local b&w buffer.
Rect GetRelativeBBox() const
Gets the relative bounding box of the block.
SImageGradient GetGradient(bool create=true, double sigma=-1, size_t diffusemaxiter=0, double diffusemaxdiv=std::numeric_limits< double >::max())
Returns a pointer to the local gradient buffer.
const Path & GetFilename() const noexcept
Returns the file name of the object.
SBlock GetChild(const String &tree, size_t num)
Gets a block of a child tree.
void SubstituteBW(const SImageBW &img)
Substitutes the BW buffer with a new one.
void RemoveChild(const String &tree, size_t num)
Removes a block of a child tree.
void setFilename(const Path &fname)
Overwrites the filename.
void FlushGradient(bool recursive=false)
Frees the local gradient buffer.
void FilterMaxAnd(const String &tree, size_t maxw, size_t maxh)
Filters a child tree.
void GetTreeMeans(const String &tree, double *mwidth, double *mheight, double *marea) const
Returns the mean width, height and area of the subblocks.
bool HasTree(const String &tname) const
Checks if a child tree exists.
UImageIntGray ExtractCC(const String &tree)
Creates a child tree with connected components.
SCVector GetTree(const String &name) const
Returns a list of children. Can be used with CRN_FOREACH.
Block & operator=(const Block &)=delete
masked_pixel_iterator() noexcept
Invalid iterator constructor.
void FlushRGB(bool recursive=false)
Frees the local RGB buffer.
SImageRGB GetRGB()
Returns a pointer to the local RGB buffer.
void RemoveTree(const String &tname)
Deletes a child tree.
std::shared_ptr< ImageBase > SImage
SBlock AddChildAbsolute(const String &tree, Rect clip)
Adds a child to current block.
WCBlock GetParent() const
Gets a reference to the parent of the block.
void SubstituteRGB(const SImageRGB &img)
Substitutes the RGB buffer with a new one.
size_t GetNbChildren(const String &tree) const
Gets the number of blocks in a child tree.
void ReloadImage()
Reloads the image.
Iterator on the pixels the block with BW buffer as mask.
masked_pixel_iterator MaskedPixelEnd(const String &tree, size_t num, pixel::BW mask_value=pixel::BWBlack)
Returns a masked iterator on the first pixel of the block.
const Iterator on the blocks of a child tree
void FilterWidthRatio(const String &tree, double ratio)
Filters a child tree.
pixel_iterator PixelBegin(const String &tree, size_t num) const
Returns an iterator on the first pixel of the block.
Block(const Block &)=delete
void SubstituteGray(const SImageGray &img)
Substitutes the Gray buffer with a new one.
const String & GetParentTree() const noexcept
Gets the name of the parent tree of the block.
masked_pixel_iterator & operator=(const masked_pixel_iterator &it) noexcept
Copy operator.
masked_pixel_iterator(const masked_pixel_iterator &it)
Copy constructor.
void SetRelativeBBox(Rect newbox)
Sets the absolute bounding box of the block.
void FlushAll(bool recursive=false)
Frees the local buffers.