libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
crn::Block Class Reference

A block. More...

#include <CRNBlock.h>

+ Inheritance diagram for crn::Block:
+ Collaboration diagram for crn::Block:

Classes

class  masked_pixel_iterator
 Iterator on the pixels the block with BW buffer as mask. More...
 

Public Types

using pixel_iterator = Rect::iterator
 Iterator on the pixels the block. More...
 

Public Member Functions

virtual ~Block () override
 Destructor. More...
 
 Block (const Block &)=delete
 
Blockoperator= (const Block &)=delete
 
 Block (Block &&)=delete
 
Blockoperator= (Block &&)=delete
 
void SetFilename (const Path &nam)
 Sets the default filename of the block. More...
 
const RectGetAbsoluteBBox () const noexcept
 Gets the absolute bounding box of the block. More...
 
Rect GetRelativeBBox () const
 Gets the relative bounding box of the block. More...
 
void SetAbsoluteBBox (const Rect &newbox)
 Sets the absolute bounding box of the block. More...
 
void SetRelativeBBox (Rect newbox)
 Sets the absolute bounding box of the block. More...
 
WBlock GetParent ()
 Gets a reference to the parent of the block. More...
 
WCBlock GetParent () const
 Gets a reference to the parent of the block. More...
 
WBlock GetTop ()
 Gets a reference to the topmost parent of the block. More...
 
const StringGetParentTree () const noexcept
 Gets the name of the parent tree of the block. More...
 
bool IsParent (const Block &b) const
 Checks if a block is a parent of current. More...
 
SBlock AddChildAbsolute (const String &tree, Rect clip)
 Adds a child to current block. More...
 
SBlock AddChildAbsolute (const String &tree, Rect clip, const String &name)
 Adds a child to current block with a name. More...
 
SBlock AddChildAbsoluteAt (const String &tree, Rect clip, size_t pos)
 Adds a child to current block. More...
 
SBlock AddChildAbsoluteAt (const String &tree, Rect clip, const String &name, size_t pos)
 Adds a child to current block with a name. More...
 
SBlock AddChildRelative (const String &tree, Rect clip)
 Adds a child to current block. More...
 
SBlock AddChildRelative (const String &tree, Rect clip, const String &name)
 Adds a child to current block with a name. More...
 
SBlock AddChildRelativeAt (const String &tree, Rect clip, size_t pos)
 Adds a child to current block. More...
 
SBlock AddChildRelativeAt (const String &tree, Rect clip, const String &name, size_t pos)
 Adds a child to current block with a name. More...
 
size_t GetNbChildren (const String &tree) const
 Gets the number of blocks in a child tree. More...
 
SBlock GetChild (const String &tree, size_t num)
 Gets a block of a child tree. More...
 
SCBlock GetChild (const String &tree, size_t num) const
 Gets a block of a child tree. More...
 
SBlock GetChild (const String &tree, const String &name)
 Gets a block of a child tree. More...
 
SCBlock GetChild (const String &tree, const String &name) const
 Gets a block of a child tree. More...
 
void RemoveChild (const String &tree, size_t num)
 Removes a block of a child tree. More...
 
void RemoveChild (const String &tree, const String &name)
 Removes a block of a child tree. More...
 
void RemoveChild (const String &tree, SBlock b)
 Removes a block of a child tree. More...
 
void RemoveChildren (const String &tree, const std::set< SBlock > &toremove)
 Removes a set of blocks from a child tree. More...
 
std::vector< StringGetTreeNames () const
 Gets the list of the tree names. More...
 
bool HasTree (const String &tname) const
 Checks if a child tree exists. More...
 
void RemoveTree (const String &tname)
 Deletes a child tree. More...
 
bool Append (const Path &fname)
 Appends child trees from a file. More...
 
void Save (const Path &fname)
 Saves the child trees into a file. More...
 
void Save ()
 Saves the child trees into the default file. More...
 
SImageRGB GetRGB ()
 Returns a pointer to the local RGB buffer. More...
 
SImageGray GetGray (bool create=true)
 Returns a pointer to the local gray buffer. More...
 
SImageBW GetBW (bool create=true)
 Returns a pointer to the local b&w buffer. More...
 
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. More...
 
void ReloadImage ()
 Reloads the image. More...
 
void FlushAll (bool recursive=false)
 Frees the local buffers. More...
 
void FlushRGB (bool recursive=false)
 Frees the local RGB buffer. More...
 
void FlushGray (bool recursive=false)
 Frees the local gray buffer. More...
 
void FlushBW (bool recursive=false)
 Frees the local b&w buffer. More...
 
void FlushGradient (bool recursive=false)
 Frees the local gradient buffer. More...
 
void SubstituteRGB (const SImageRGB &img)
 Substitutes the RGB buffer with a new one. More...
 
void SubstituteGray (const SImageGray &img)
 Substitutes the Gray buffer with a new one. More...
 
void SubstituteBW (const SImageBW &img)
 Substitutes the BW buffer with a new one. More...
 
void SubstituteGradient (const SImageGradient &img)
 Substitutes the Gradient buffer with a new one. More...
 
UImageIntGray ExtractCC (const String &tree)
 Creates a child tree with connected components. More...
 
void FilterMinAnd (const String &tree, size_t minw, size_t minh)
 Filters a child tree. More...
 
void FilterMinOr (const String &tree, size_t minw, size_t minh)
 Filters a child tree. More...
 
void FilterMaxAnd (const String &tree, size_t maxw, size_t maxh)
 Filters a child tree. More...
 
void FilterMaxOr (const String &tree, size_t maxw, size_t maxh)
 Filters a child tree. More...
 
void FilterBorders (const String &tree, size_t margin)
 Filters a child tree. More...
 
void FilterWidthRatio (const String &tree, double ratio)
 Filters a child tree. More...
 
void FilterHeightRatio (const String &tree, double ratio)
 Filters a child tree. More...
 
bool MergeChildren (const String &tree, double overlap, ImageIntGray *imap=nullptr)
 Merges overlapping children in a tree. More...
 
void MergeSiblings (const String &tree, size_t index1, size_t index2, ImageIntGray *imap=nullptr)
 Merges two subblocks. More...
 
void MergeSiblings (const String &tree, Block &sb1, Block &sb2, ImageIntGray *imap=nullptr)
 Merges two subblocks. More...
 
void GetTreeMeans (const String &tree, double *mwidth, double *mheight, double *marea) const
 Returns the mean width, height and area of the subblocks. More...
 
block_iterator BlockBegin (const String &tree)
 Returns an iterator on the first block of a tree. More...
 
block_iterator BlockEnd (const String &tree)
 Returns an iterator after the last block of a tree. More...
 
const_block_iterator BlockBegin (const String &tree) const
 Returns a const iterator on the first block of a tree. More...
 
const_block_iterator BlockEnd (const String &tree) const
 Returns a const iterator after the last block of a tree. More...
 
SVector GetTree (const String &name)
 Returns a list of children. Can be used with CRN_FOREACH. More...
 
SCVector GetTree (const String &name) const
 Returns a list of children. Can be used with CRN_FOREACH. More...
 
void SortTree (const String &name, Direction direction)
 Sorts a child tree. More...
 
pixel_iterator PixelBegin (const String &tree, size_t num) const
 Returns an iterator on the first pixel of the block. More...
 
pixel_iterator PixelBegin (const SBlock &b) const
 Returns an iterator on the first pixel of the block. More...
 
pixel_iterator PixelEnd (const String &tree, size_t num) const
 Returns an iterator after the last pixel of the block. More...
 
pixel_iterator PixelEnd (const SBlock &b) const
 Returns an iterator after the last pixel of the block. More...
 
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. More...
 
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. More...
 
masked_pixel_iterator MaskedPixelBegin (const SBlock &b, pixel::BW mask_value=pixel::BWBlack)
 Returns a masked iterator after the last pixel of the block. More...
 
masked_pixel_iterator MaskedPixelEnd (const SBlock &b, pixel::BW mask_value=pixel::BWBlack)
 Returns a masked iterator after the last pixel of the block. More...
 
- Public Member Functions inherited from crn::Savable
 Savable (const String &s=U"")
 Default constructor. More...
 
virtual ~Savable ()
 Destructor. More...
 
 Savable (const Savable &)=delete
 No copy construction allowed. More...
 
Savableoperator= (const Savable &)=delete
 No assignment allowed. More...
 
 Savable (Savable &&) noexcept
 
Savableoperator= (Savable &&c)
 
const StringGetName () const
 Returns the name of the object. More...
 
void SetName (const String &s)
 Sets the name of the object. More...
 
void SetName (String &&s) noexcept
 Sets the name of the object. More...
 
void SetUserData (const String &key, SObject value)
 Adds or replaces a user data. More...
 
bool IsUserData (const String &key) const
 Tests if a user data key exists. More...
 
SObject GetUserData (const String &key)
 Gets a user data by key. More...
 
String GetUserDataKey (const SObject &value) const
 Gets a user data key by value. More...
 
const SObject GetUserData (const String &key) const
 Gets a user data by key. More...
 
void DeleteUserData (const String &key)
 Deletes a user data entry and frees the value. More...
 
void ClearUserData ()
 Deletes all user data entries. More...
 
 Savable (const String &s, const Path &fname)
 Constructor from file name. More...
 
void Load (const Path &fname)
 Loads the object from an XML file (Safe) More...
 
void Save (const Path &fname)
 Saves the object to an XML file (Safe) More...
 
void Save ()
 Saves the object to an already set XML file. More...
 
const PathGetFilename () const noexcept
 Returns the file name of the object. More...
 
void deserialize_internal_data (xml::Element &el)
 Initializes some internal data from an XML element. More...
 
void serialize_internal_data (xml::Element &el) const
 Dumps some internal data to an XML element. More...
 
- Public Member Functions inherited from crn::Object
virtual ~Object ()=default
 

Static Public Member Functions

static SBlock New (const SImage &src, const String &nam=U"")
 Top block creator. More...
 
static SBlock New (const Path &ifname, const Path &xfname, const String &nam=U"")
 Constructor from filenames. More...
 

Additional Inherited Members

- Protected Member Functions inherited from crn::Savable
void setFilename (const Path &fname)
 Overwrites the filename. More...
 
void setFilename (Path &&fname) noexcept
 Overwrites the filename. More...
 
- Protected Attributes inherited from crn::Savable
std::unique_ptr< std::mutex > filelock
 

Detailed Description

A block.

A block is a container of other blocks. Each block refers to a source image and has a local copy of a part of it. A top block is typically a page or a double page.

Author
Yann Leydier
Date
16 August 2006
Version
0.1

Definition at line 52 of file CRNBlock.h.

Member Typedef Documentation

Iterator on the pixels the block.

Definition at line 228 of file CRNBlock.h.

Constructor & Destructor Documentation

Block::~Block ( )
overridevirtual

Destructor.

Destructor. Saves the changes on subblock trees.

Definition at line 516 of file CRNBlock.cpp.

crn::Block::Block ( const Block )
delete
crn::Block::Block ( Block &&  )
delete

Member Function Documentation

SBlock Block::AddChildAbsolute ( const String tree,
Rect  clip 
)

Adds a child to current block.

Creates and adds a child to the current block

Exceptions
ExceptionInvalidArgumentuninitialized rectangle
ExceptionDomainrectangle is out of bounds
Parameters
[in]treeThe name of the tree to add the subblock
[in]clipThe bounding box of the new block, given in absolute coordinates.
Returns
The newly created block.

Definition at line 548 of file CRNBlock.cpp.

SBlock Block::AddChildAbsolute ( const String tree,
Rect  clip,
const String name 
)

Adds a child to current block with a name.

Creates and adds a child to the current block with a name

Exceptions
ExceptionInvalidArgumentuninitialized rectangle
ExceptionDomainrectangle is out of bounds
Parameters
[in]treeThe name of the tree to add the subblock
[in]clipThe bounding box of the new block, given in absolute coordinates.
[in]nameThe name of the new subblock
Returns
The newly created block.

Definition at line 575 of file CRNBlock.cpp.

SBlock Block::AddChildAbsoluteAt ( const String tree,
Rect  clip,
size_t  pos 
)

Adds a child to current block.

Creates and adds a child to the current block at the specified position

Exceptions
ExceptionInvalidArgumentuninitialized rectangle
ExceptionDomainrectangle is out of bounds
Parameters
[in]treeThe name of the tree to add the subblock
[in]clipThe bounding box of the new block, given in absolute coordinates.
[in]posThe position of the newly created child
Returns
The newly created block.

Definition at line 602 of file CRNBlock.cpp.

SBlock Block::AddChildAbsoluteAt ( const String tree,
Rect  clip,
const String name,
size_t  pos 
)

Adds a child to current block with a name.

Creates and adds a child to the current block with a name at the specified position

Exceptions
ExceptionInvalidArgumentuninitialized rectangle
ExceptionDomainrectangle is out of bounds
Parameters
[in]treeThe name of the tree to add the subblock
[in]clipThe bounding box of the new block, given in absolute coordinates.
[in]nameThe name of the new subblock
[in]posThe position of the newly created child
Returns
The newly created block.

Definition at line 637 of file CRNBlock.cpp.

SBlock Block::AddChildRelative ( const String tree,
Rect  clip 
)

Adds a child to current block.

Creates and adds a child to the current block

Exceptions
ExceptionInvalidArgumentuninitialized rectangle
ExceptionDomainrectangle is out of bounds
Parameters
[in]treeThe name of the tree to add the subblock
[in]clipThe bounding box of the new block, given in relative coordinates.
Returns
The newly created block.

Definition at line 670 of file CRNBlock.cpp.

SBlock Block::AddChildRelative ( const String tree,
Rect  clip,
const String name 
)

Adds a child to current block with a name.

Creates and adds a child to the current block with a name

Exceptions
ExceptionInvalidArgumentuninitialized rectangle
ExceptionDomainrectangle is out of bounds
Parameters
[in]treeThe name of the tree to add the subblock
[in]clipThe bounding box of the new block, given in relative coordinates.
[in]nameThe name of the new subblock
Returns
The newly created block.

Definition at line 698 of file CRNBlock.cpp.

SBlock Block::AddChildRelativeAt ( const String tree,
Rect  clip,
size_t  pos 
)

Adds a child to current block.

Creates and adds a child to the current block at the specified position

Exceptions
ExceptionInvalidArgumentuninitialized rectangle
ExceptionDomainrectangle is out of bounds
Parameters
[in]treeThe name of the tree to add the subblock
[in]clipThe bounding box of the new block, given in relative coordinates.
[in]posThe position of the newly created child
Returns
The newly created block.

Definition at line 726 of file CRNBlock.cpp.

SBlock Block::AddChildRelativeAt ( const String tree,
Rect  clip,
const String name,
size_t  pos 
)

Adds a child to current block with a name.

Creates and adds a child to the current block with a name at the specified position

Exceptions
ExceptionInvalidArgumentuninitialized rectangle
ExceptionDomainrectangle is out of bounds
Parameters
[in]treeThe name of the tree to add the subblock
[in]clipThe bounding box of the new block, given in relative coordinates.
[in]nameThe name of the new subblock
[in]posThe position of the newly created child
Returns
The newly created block.

Definition at line 762 of file CRNBlock.cpp.

bool Block::Append ( const Path fname)

Appends child trees from a file.

Appends child trees from a file.

Exceptions
ExceptionInvalidArgumentempty file name
ExceptionIOfile exists but cannot be accessed or has invalid structure
ExceptionRuntimethe XML file does not fit the block's image
Parameters
[in]fnameThe file to load.
Returns
true if success, false if file not found.

Definition at line 1079 of file CRNBlock.cpp.

Block::block_iterator Block::BlockBegin ( const String tree)

Returns an iterator on the first block of a tree.

Returns an iterator on the first block of a tree

Exceptions
ExceptionInvalidArgumenttree not found
Parameters
[in]treethe name of the subblock tree
Returns
an iterator on the first block of the tree

Definition at line 334 of file CRNBlock.cpp.

Block::const_block_iterator Block::BlockBegin ( const String tree) const

Returns a const iterator on the first block of a tree.

Returns a const_iterator on the first block of a tree

Exceptions
ExceptionInvalidArgumenttree not found
Parameters
[in]treethe name of the subblock tree
Returns
a const_iterator on the first block of the tree

Definition at line 372 of file CRNBlock.cpp.

Block::block_iterator Block::BlockEnd ( const String tree)

Returns an iterator after the last block of a tree.

Returns an iterator after the last block of a tree

Exceptions
ExceptionInvalidArgumenttree not found
Parameters
[in]treethe name of the subblock tree
Returns
an iterator after the last block of the tree

Definition at line 354 of file CRNBlock.cpp.

Block::const_block_iterator Block::BlockEnd ( const String tree) const

Returns a const iterator after the last block of a tree.

Returns a const_iterator after the last block of a tree

Exceptions
ExceptionInvalidArgumenttree not found
Parameters
[in]treethe name of the subblock tree
Returns
a const_iterator after the last block of the tree

Definition at line 393 of file CRNBlock.cpp.

UImageIntGray Block::ExtractCC ( const String tree)

Creates a child tree with connected components.

Creates a child tree with connected components.

Each child block's name is the index of the connected component it represents.

Inspired from "Fast connected-component labeling" by Lifeng He, Yuyan Chao, Kenji Suzuki and Kesheng Wu.

Exceptions
ExceptionIOcannot open image
ExceptionRuntimeunsupported image format (not BW, Gray nor RGB)
Parameters
[in]treeThe tree name add the block to
Returns
a SImageIntGray containing the indexes of the connected components or nullptr if failed

Definition at line 1640 of file CRNBlock.cpp.

void Block::FilterBorders ( const String tree,
size_t  margin 
)

Filters a child tree.

Filters a child tree. Each child block within a margin close to the borders is removed

Exceptions
ExceptionNotFoundtree not found
Parameters
[in]treeThe tree name
[in]marginThe minimal distance to the border

Definition at line 2187 of file CRNBlock.cpp.

void Block::FilterHeightRatio ( const String tree,
double  ratio 
)

Filters a child tree.

Filters a child tree. Each child block with Height > ratio * Width is removed.

Exceptions
ExceptionNotFoundtree not found
ExceptionDomainratio is negative or null
Parameters
[in]treeThe tree name
[in]ratioThe maximal Height/Width ratio allowed (must be >0)

Definition at line 2244 of file CRNBlock.cpp.

void Block::FilterMaxAnd ( const String tree,
size_t  maxw,
size_t  maxh 
)

Filters a child tree.

Filters a child tree. Each child block with width and height greater than the min values is removed.

Exceptions
ExceptionNotFoundtree not found
Parameters
[in]treeThe tree name
[in]maxwThe maximal width
[in]maxhThe maximal height

Definition at line 2138 of file CRNBlock.cpp.

void Block::FilterMaxOr ( const String tree,
size_t  maxw,
size_t  maxh 
)

Filters a child tree.

Filters a child tree. Each child block with width or height greater than the min values is removed.

Exceptions
ExceptionNotFoundtree not found
Parameters
[in]treeThe tree name
[in]maxwThe maximal width
[in]maxhThe maximal height

Definition at line 2163 of file CRNBlock.cpp.

void Block::FilterMinAnd ( const String tree,
size_t  minw,
size_t  minh 
)

Filters a child tree.

Filters a child tree. Each child block with width and height lesser than the min values is removed.

Exceptions
ExceptionNotFoundtree not found
Parameters
[in]treeThe tree name
[in]minwThe minimal width
[in]minhThe minimal height

Definition at line 2080 of file CRNBlock.cpp.

void Block::FilterMinOr ( const String tree,
size_t  minw,
size_t  minh 
)

Filters a child tree.

Filters a child tree. Each child block with width or height lesser than the min values is removed.

Exceptions
ExceptionNotFoundtree not found
Parameters
[in]treeThe tree name
[in]minwThe minimal width
[in]minhThe minimal height

Definition at line 2113 of file CRNBlock.cpp.

void Block::FilterWidthRatio ( const String tree,
double  ratio 
)

Filters a child tree.

Filters a child tree. Each child block with Width > ratio * Height is removed.

Exceptions
ExceptionNotFoundtree not found
ExceptionDomainratio is negative or null
Parameters
[in]treeThe tree name
[in]ratioThe maximal Width/Height ratio allowed (must be >0).

Definition at line 2215 of file CRNBlock.cpp.

void Block::FlushAll ( bool  recursive = false)

Frees the local buffers.

Frees all buffers

Parameters
[in]recursiveshall childrens' buffer be flushed?

Definition at line 1327 of file CRNBlock.cpp.

void Block::FlushBW ( bool  recursive = false)

Frees the local b&w buffer.

Frees the local b&w buffer

Parameters
[in]recursiveshall childrens' buffer be flushed?

Definition at line 1385 of file CRNBlock.cpp.

void Block::FlushGradient ( bool  recursive = false)

Frees the local gradient buffer.

Frees the local gradient buffer

Parameters
[in]recursiveshall childrens' buffer be flushed?

Definition at line 1407 of file CRNBlock.cpp.

void Block::FlushGray ( bool  recursive = false)

Frees the local gray buffer.

Frees the local gray buffer

Parameters
[in]recursiveshall childrens' buffer be flushed?

Definition at line 1363 of file CRNBlock.cpp.

void Block::FlushRGB ( bool  recursive = false)

Frees the local RGB buffer.

Frees the local RGB buffer

Parameters
[in]recursiveshall childrens' buffer be flushed?

Definition at line 1341 of file CRNBlock.cpp.

const Rect& crn::Block::GetAbsoluteBBox ( ) const
inlinenoexcept

Gets the absolute bounding box of the block.

Definition at line 71 of file CRNBlock.h.

SImageBW Block::GetBW ( bool  create = true)

Returns a pointer to the local b&w buffer.

Returns a pointer to the local b&w buffer. Creates the buffer if non existent.

Exceptions
ExceptionIOcannot open image
ExceptionRuntimeunsupported image format (not BW, Gray nor RGB)
Parameters
[in]createShall the buffer be created from a rgb or gray one? default = true.
Returns
The b&w local buffer.

Definition at line 932 of file CRNBlock.cpp.

SBlock Block::GetChild ( const String tree,
size_t  num 
)

Gets a block of a child tree.

Gets a block of a child tree

Exceptions
ExceptionNotFoundtree not found
ExceptionDomainindex out of bounds
Parameters
[in]treeThe tree name
[in]numThe index of the subblock
Returns
A pointer to the block, nullptr if the tree does not exist or the number is erroneous

Definition at line 1897 of file CRNBlock.cpp.

SCBlock Block::GetChild ( const String tree,
size_t  num 
) const

Gets a block of a child tree.

Gets a block of a child tree

Exceptions
ExceptionNotFoundtree not found
ExceptionDomainindex out of bounds
Parameters
[in]treeThe tree name
[in]numThe index of the subblock
Returns
A pointer to the block, nullptr if the tree does not exist or the number is erroneous

Definition at line 1919 of file CRNBlock.cpp.

SBlock Block::GetChild ( const String tree,
const String name 
)

Gets a block of a child tree.

Gets a block of a child tree

Exceptions
ExceptionNotFoundtree or block not found
Parameters
[in]treeThe tree name
[in]nameThe name of the subblock
Returns
A pointer to the first block having that name, nullptr if the tree does not exist or the number is erroneous

Definition at line 1944 of file CRNBlock.cpp.

SCBlock Block::GetChild ( const String tree,
const String name 
) const

Gets a block of a child tree.

Gets a block of a child tree

Exceptions
ExceptionNotFoundtree or block not found
Parameters
[in]treeThe tree name
[in]nameThe name of the subblock
Returns
A pointer to the first block having that name, nullptr if the tree does not exist or the number is erroneous

Definition at line 1969 of file CRNBlock.cpp.

SImageGradient Block::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.

Returns a pointer to the local gradient buffer.

Exceptions
ExceptionIOcannot open image
ExceptionRuntimeunsupported image format (not BW, Gray nor RGB)
Parameters
[in]createShall the buffer be created from a gray or b&w one? default = true.
[in]sigmaThe standard deviation of the gaussian core used to apply the gradient. default = 0.5
[in]diffusemaxitermaximal number of iterations of the diffusion
[in]diffusemaxdivmaximal divergence to allow modification for each pixel during the diffusion
Returns
The gradient local buffer or nullptr

Definition at line 1205 of file CRNBlock.cpp.

SImageGray Block::GetGray ( bool  create = true)

Returns a pointer to the local gray buffer.

Returns a pointer to the local gray buffer. Creates the buffer if non existent.

Exceptions
ExceptionIOcannot open image
ExceptionRuntimeunsupported image format (not BW, Gray nor RGB)
Parameters
[in]createShall the buffer be created from a rgb one? default = true.
Returns
The gray local buffer.

Definition at line 862 of file CRNBlock.cpp.

size_t Block::GetNbChildren ( const String tree) const

Gets the number of blocks in a child tree.

Gets the number of blocks in a child tree

Exceptions
ExceptionInvalidArgumenttree not found
Parameters
[in]treeThe tree name
Returns
The number of children or -1 if the tree does not exist

Definition at line 1877 of file CRNBlock.cpp.

WBlock crn::Block::GetParent ( )
inline

Gets a reference to the parent of the block.

Definition at line 80 of file CRNBlock.h.

WCBlock crn::Block::GetParent ( ) const
inline

Gets a reference to the parent of the block.

Definition at line 82 of file CRNBlock.h.

const String& crn::Block::GetParentTree ( ) const
inlinenoexcept

Gets the name of the parent tree of the block.

Definition at line 86 of file CRNBlock.h.

Rect Block::GetRelativeBBox ( ) const

Gets the relative bounding box of the block.

Gets the relative bounding box of the block

Returns
the relative bounding box of the block

Definition at line 316 of file CRNBlock.cpp.

SImageRGB Block::GetRGB ( )

Returns a pointer to the local RGB buffer.

Returns a pointer to the local RGB buffer.

Exceptions
ExceptionIOcannot open image
ExceptionRuntimeunsupported image format (not BW, Gray nor RGB)
Returns
The RGB local buffer.

Definition at line 795 of file CRNBlock.cpp.

WBlock Block::GetTop ( )

Gets a reference to the topmost parent of the block.

Gets a reference to the topmost parent of the block

Returns
A reference to the topmost parent of the block

Definition at line 2480 of file CRNBlock.cpp.

SVector crn::Block::GetTree ( const String name)
inline

Returns a list of children. Can be used with CRN_FOREACH.

Definition at line 212 of file CRNBlock.h.

SCVector crn::Block::GetTree ( const String name) const
inline

Returns a list of children. Can be used with CRN_FOREACH.

Definition at line 218 of file CRNBlock.h.

void Block::GetTreeMeans ( const String tree,
double *  mwidth,
double *  mheight,
double *  marea 
) const

Returns the mean width, height and area of the subblocks.

Returns the mean width, height and area of the subblocks

Exceptions
ExceptionInvalidArgumenttree not found
Parameters
[in]treethe name of the block tree
[out]mwidththe mean width
[out]mheightthe mean height
[out]mareathe mean area
Returns
true if success, false else

Definition at line 1845 of file CRNBlock.cpp.

std::vector< String > Block::GetTreeNames ( ) const

Gets the list of the tree names.

Gets the list of the tree names

Returns
The list of the child trees' names

Definition at line 986 of file CRNBlock.cpp.

bool Block::HasTree ( const String tname) const

Checks if a child tree exists.

Checks if a child tree exists

Parameters
[in]tnameThe name of the tree to check
Returns
true if exists, false else.

Definition at line 1172 of file CRNBlock.cpp.

bool Block::IsParent ( const Block b) const

Checks if a block is a parent of current.

Checks ascendency between two blocks.

Parameters
[in]bthe candidate parent
Returns
true if b is a parent of the current bloc, false else

Definition at line 2495 of file CRNBlock.cpp.

Block::masked_pixel_iterator Block::MaskedPixelBegin ( const String tree,
size_t  num,
pixel::BW  mask_value = pixel::BWBlack 
)

Returns a masked iterator on the first pixel of the block.

Returns an iterator on the first pixel of the block

Exceptions
ExceptionInvalidArgumenttree not found
ExceptionDomainindex out of bounds
ExceptionIOcannot open bw image
ExceptionRuntimeunsupported image format (not BW, Gray nor RGB)
Parameters
[in]treethe name of the subblock tree
[in]numthe index tof the block to iterate
[in]mask_valuecrn::pixel::BWWhite or crn::pixel::BWBlack
Returns
an iterator, invalid if the tree does not exist or the index is out of range

Definition at line 2600 of file CRNBlock.cpp.

Block::masked_pixel_iterator Block::MaskedPixelBegin ( const SBlock &  b,
pixel::BW  mask_value = pixel::BWBlack 
)

Returns a masked iterator after the last pixel of the block.

Returns an iterator on the first pixel of the block

Exceptions
ExceptionInvalidArgumenttree not found
ExceptionIOcannot open bw image
ExceptionRuntimeunsupported image format (not BW, Gray nor RGB)
Parameters
[in]bthe subblock to iterate
[in]mask_valuecrn::pixel::BWWhite or crn::pixel::BWBlack
Returns
an iterator, invalid if the block is not a descendant

Definition at line 2627 of file CRNBlock.cpp.

Block::masked_pixel_iterator Block::MaskedPixelEnd ( const String tree,
size_t  num,
pixel::BW  mask_value = pixel::BWBlack 
)

Returns a masked iterator on the first pixel of the block.

Returns an iterator after the last pixel of the block

Exceptions
ExceptionInvalidArgumenttree not found
ExceptionDomainindex out of bounds
Parameters
[in]treethe name of the subblock tree
[in]numthe index tof the block to iterate
[in]mask_valuecrn::pixel::BWWhite or crn::pixel::BWBlack
Returns
an iterator, invalid if the tree does not exist or the index is out of range

Definition at line 2649 of file CRNBlock.cpp.

Block::masked_pixel_iterator Block::MaskedPixelEnd ( const SBlock &  b,
pixel::BW  mask_value = pixel::BWBlack 
)

Returns a masked iterator after the last pixel of the block.

Returns an iterator after the last pixel of the block

Exceptions
ExceptionInvalidArgumentnull block or block is not a child
Parameters
[in]bthe subblock to iterate
[in]mask_valuecrn::pixel::BWWhite or crn::pixel::BWBlack
Returns
an iterator, invalid if the block is not a descendant

Definition at line 2671 of file CRNBlock.cpp.

bool Block::MergeChildren ( const String tree,
double  overlap,
ImageIntGray imap = nullptr 
)

Merges overlapping children in a tree.

Merges overlapping children in a tree. Once it is done, it's possible that a merged block resulting from overlapping ones overlaps another merged block. In order to make sure that the result contains no overlapping blocks, this method should be run until it returns false (until the re is no more overlapping blocks).

Exceptions
ExceptionNotFoundtree not found
ExceptionDomainoverlap is negative
Parameters
[in]treeThe tree name
[in]overlapThe maximal overlapping to avoid merging. ie: overlap=0 means all overlapping children will be merged. overlap=1 means only fully overlaid children will be merged.
[in]imapthe map image to update (can be null)
Returns
true if some children were merged, false else

Definition at line 2279 of file CRNBlock.cpp.

void Block::MergeSiblings ( const String tree,
size_t  index1,
size_t  index2,
ImageIntGray imap = nullptr 
)

Merges two subblocks.

Merges two subblocks.

Exceptions
ExceptionNotFoundtree not found
ExceptionLogicidentical indexes
ExceptionDomainindex out of bounds
Parameters
[in]treethe name of the tree
[in]index1the index of the child that will be updated
[in]index2the index of the child that will be removed
[in]imapthe map image to update (can be nullptr)

Definition at line 2385 of file CRNBlock.cpp.

void Block::MergeSiblings ( const String tree,
Block sb1,
Block sb2,
ImageIntGray imap = nullptr 
)

Merges two subblocks.

Merges two subblocks.

Exceptions
ExceptionNotFoundtree or block not found
Parameters
[in]treethe name of the tree
[in]sb1
[in]sb2
[in]imapthe map image to update (can be nullptr)
Returns
true if success, false else

Definition at line 2446 of file CRNBlock.cpp.

SBlock Block::New ( const SImage src,
const String nam = U"" 
)
static

Top block creator.

Constructor for a top Block

Exceptions
ExceptionInvalidArgumentnull image or unsupported image type (BW, Gray nor RGB)
Parameters
[in]srcThe source image of the top block
[in]namthe name of the new block

Definition at line 46 of file CRNBlock.cpp.

SBlock Block::New ( const Path ifname,
const Path xfname,
const String nam = U"" 
)
static

Constructor from filenames.

Constructor from filenames

Exceptions
ExceptionIOXML file exists but cannot be accessed or has invalid structure
ExceptionRuntimethe XML file does not fit the block's image
ExceptionIOcannot open image
ExceptionRuntimeunsupported image format (not BW, Gray nor RGB)
Parameters
[in]ifnameimage filename
[in]xfnamexml filename
[in]namthe name of the new block

Definition at line 114 of file CRNBlock.cpp.

Block& crn::Block::operator= ( const Block )
delete
Block& crn::Block::operator= ( Block &&  )
delete
Block::pixel_iterator Block::PixelBegin ( const String tree,
size_t  num 
) const

Returns an iterator on the first pixel of the block.

Returns an iterator on the first pixel of the block

Exceptions
ExceptionInvalidArgumenttree not found
ExceptionDomainindex out of bounds
Parameters
[in]treethe name of the subblock tree
[in]numthe index of the block to iterate
Returns
an iterator, invalid if the tree does not exist or the index is out of range

Definition at line 2515 of file CRNBlock.cpp.

Block::pixel_iterator Block::PixelBegin ( const SBlock &  b) const

Returns an iterator on the first pixel of the block.

Returns an iterator on the first pixel of the block

Exceptions
ExceptionInvalidArgumentnull block or block is not a child
Parameters
[in]bthe subblock to iterate
Returns
an iterator, invalid if the block is not a descendant

Definition at line 2538 of file CRNBlock.cpp.

Block::pixel_iterator Block::PixelEnd ( const String tree,
size_t  num 
) const

Returns an iterator after the last pixel of the block.

Returns an iterator after the last pixel of the block

Exceptions
ExceptionInvalidArgumenttree not found
ExceptionDomainindex out of bounds
Parameters
[in]treethe name of the subblock tree
[in]numthe index tof the block to iterate
Returns
an iterator, invalid if the tree does not exist or the index is out of range

Definition at line 2558 of file CRNBlock.cpp.

Block::pixel_iterator Block::PixelEnd ( const SBlock &  b) const

Returns an iterator after the last pixel of the block.

Returns an iterator after the last pixel of the block

Exceptions
ExceptionInvalidArgumentnull block or block is not a child
Parameters
[in]bthe subblock to iterate
Returns
an iterator, invalid if the block is not a descendant

Definition at line 2578 of file CRNBlock.cpp.

void Block::ReloadImage ( )

Reloads the image.

Reloads the image

Exceptions
ExceptionIOcannot open image
ExceptionRuntimeunsupported image format (not BW, Gray nor RGB)

Definition at line 1304 of file CRNBlock.cpp.

void Block::RemoveChild ( const String tree,
size_t  num 
)

Removes a block of a child tree.

Removes a block of a child tree. The possible shared pointers remaining on the block should not be used after the removal.

Exceptions
ExceptionNotFoundtree not found
ExceptionDomainindex ouf of bounds
Parameters
[in]treeThe tree name
[in]numThe index of the subblock

Definition at line 1995 of file CRNBlock.cpp.

void Block::RemoveChild ( const String tree,
const String name 
)

Removes a block of a child tree.

Removes a block of a child tree. The possible shared pointers remaining on the block should not be used after the removal.

Exceptions
ExceptionNotFoundtree or block not found
Parameters
[in]treeThe tree name
[in]nameThe name of the subblock

Definition at line 2019 of file CRNBlock.cpp.

void Block::RemoveChild ( const String tree,
SBlock  b 
)

Removes a block of a child tree.

Removes the current block of a child tree. The possible shared pointers remaining on the block should not be used after the removal.

Exceptions
ExceptionNotFoundtree or block not found
Parameters
[in]treeThe tree name
[in]bThe block

Definition at line 2034 of file CRNBlock.cpp.

void Block::RemoveChildren ( const String tree,
const std::set< SBlock > &  toremove 
)

Removes a set of blocks from a child tree.

Removes a set of blocks from a child tree

Exceptions
ExceptionNotFoundtree not found
Parameters
[in]treethe tree to prune
[in]toremovethe list of blocks to remove

Definition at line 2058 of file CRNBlock.cpp.

void Block::RemoveTree ( const String tname)

Deletes a child tree.

Deletes a child tree

Exceptions
ExceptionNotFoundtree not found
Parameters
[in]tnameThe tree to erase

Definition at line 1187 of file CRNBlock.cpp.

void Block::Save ( const Path fname)

Saves the child trees into a file.

Saves the child trees into a file.

Exceptions
ExceptionInvalidArgumentempty file name
ExceptionIOcannot save XML file
ExceptionRuntimeerror creating the file
Parameters
[in]fnameThe file to create.

Definition at line 1004 of file CRNBlock.cpp.

void crn::Block::Save ( )
inline

Saves the child trees into the default file.

Saves the child trees into the default file

Exceptions
ExceptionInvalidArgumentempty file name
ExceptionIOcannot save XML file

Definition at line 143 of file CRNBlock.h.

void Block::SetAbsoluteBBox ( const Rect newbox)

Sets the absolute bounding box of the block.

Sets the absolute bounding box.

If it overflows the topmost parent's bounding box, we truncate the box. A topmost block's bounding box cannot be set.

Exceptions
ExceptionLogicthe block is the topmost block
ExceptionInvalidArgumentuninitialized bounding box
ExceptionDimensionbounding box is out of parent's bounding box
Parameters
[in]newboxthe new absolute bounding box

Definition at line 254 of file CRNBlock.cpp.

void crn::Block::SetFilename ( const Path nam)
inline

Sets the default filename of the block.

Definition at line 68 of file CRNBlock.h.

void Block::SetRelativeBBox ( Rect  newbox)

Sets the absolute bounding box of the block.

Sets the relative bounding box.

If it overflows the topmost parent's bounding box, we truncate the box. A topmost block's bounding box cannot be set.

Exceptions
ExceptionLogicthe block is the topmost block
ExceptionInvalidArgumentuninitialized bounding box
ExceptionDimensionbounding box is out of parent's bounding box
Parameters
[in]newboxthe new relative bounding box

Definition at line 300 of file CRNBlock.cpp.

void Block::SortTree ( const String name,
Direction  direction 
)

Sorts a child tree.

Sorts a child tree

Exceptions
ExceptionInvalidArgumenttree not found
ExceptionDomaininvalid direction
Parameters
[in]namethe name of the child tree to sort
[in]directionthe direction (Direction::LEFT for left to right, Direction::TOP for top to bottom, Direction::RIGHT for right to left or Direction::BOTTOM for bottom to top). Use only one direction at a time, don't try to combinate the directions with the | operator.
Returns
true if success, false else

Definition at line 2691 of file CRNBlock.cpp.

void Block::SubstituteBW ( const SImageBW &  img)

Substitutes the BW buffer with a new one.

Substitutes the BW buffer with a new image.

If a buffer exists, it will be freed.

If the substitution succeeds, the block will keep the reference to the new image and will free it himself.

Exceptions
ExceptionDimensionthe images do no have the same size
Parameters
[in]imgthe new image to use

Definition at line 1495 of file CRNBlock.cpp.

void Block::SubstituteGradient ( const SImageGradient &  img)

Substitutes the Gradient buffer with a new one.

Substitutes the Gradient buffer with a new image.

If a buffer exists, it will be freed.

If the substitution succeeds, the block will keep the reference to the new image and will free it himself.

Exceptions
ExceptionDimensionthe images do no have the same size
Parameters
[in]imgthe new image to use

Definition at line 1525 of file CRNBlock.cpp.

void Block::SubstituteGray ( const SImageGray &  img)

Substitutes the Gray buffer with a new one.

Substitutes the Gray buffer with a new image.

If a buffer exists, it will be freed.

If the substitution succeeds, the block will keep the reference to the new image and will free it himself.

Exceptions
ExceptionDimensionthe images do no have the same size
Parameters
[in]imgthe new image to use

Definition at line 1465 of file CRNBlock.cpp.

void Block::SubstituteRGB ( const SImageRGB &  img)

Substitutes the RGB buffer with a new one.

Substitutes the RGB buffer with a new image.

If a buffer exists, it will be freed.

If the substitution succeeds, the block will keep the reference to the new image and will free it himself.

Exceptions
ExceptionDimensionthe images do no have the same size
Parameters
[in]imgthe new image to use

Definition at line 1435 of file CRNBlock.cpp.


The documentation for this class was generated from the following files: