#include <girl/girlToger.hpp>
Data Structures | |
class | directionIterator |
Base class of function object used to iterate on face boundaries or segments. More... | |
class | pointIterator |
Base class of function object used to iterate on region domain. More... | |
class | sameRegion |
Splitting functor. More... | |
Public Types | |
enum | neighbouringMode { NEIGHBOUR_NONE = 0, NEIGHBOUR_DIRECT = 1, NEIGHBOUR_INNER = 2, NEIGHBOUR_OUTER = 4, NEIGHBOUR_ANY = 7 } |
enum | markFlag { MARK_NONE = 0, MARK_0 = 1, MARK_1 = 2, MARK_2 = 4, MARK_3 = 8, MARK_4 = 16, MARK_5 = 32, MARK_6 = 64, MARK_7 = 128, MARK_ANY = 255 } |
typedef enum girl::toger::neighbouringMode | neighbouringMode |
typedef enum girl::toger::markFlag | markFlag |
typedef void(* | f1RegionHook )(girl::region r, void *userData) |
Type of call back function applied on one region. | |
typedef void(* | f2RegionsHook )(girl::region r1, girl::region r2, void *userData) |
Type of call back function applied on two regions. | |
Public Member Functions | |
toger (POINT_TYPE width=1, POINT_TYPE height=1) | |
Constructor. | |
POINT_TYPE | width () const |
POINT_TYPE | height () const |
void | splitRegion (girl::region r, girl::toger::sameRegion &same_r, girl::regionDeque ®s) |
Splits a given region r of representation, using same_r as a partition criterion. | |
girl::region | mergeRegions (girl::region r1, girl::region r2) |
Merges two regions r1 and r2, in representation. | |
bool | insertPaths (const girl::pathDeque &paths, girl::regionDeque &out_q) |
Inserts a set of paths paths in representation. | |
void | setNewRegionHook (girl::toger::f1RegionHook hook, void *userData) |
Sets callback function to be called just after a region creation. | |
void | setDeleteRegionHook (girl::toger::f1RegionHook hook, void *userData) |
Sets callback function to be called just after a region deletion. | |
void | setMergeRegionsHook (girl::toger::f2RegionsHook hook, void *userData) |
Sets callback function to be called when two regions are merged and before the delete hook. | |
void | setRenameRegionHook (girl::toger::f2RegionsHook hook, void *userData) |
Sets callback function to be called when a region is renammed. | |
bool | belongsTo (const girl::point &p, girl::region r) const |
Checks if a point p belongs to region r, according to representation. | |
girl::region | findRegion (const girl::point &p) const |
Returns the region containing the point p, according to representation. | |
void | findRegions (const girl::point &p1, const girl::point &p2, girl::regionDeque ®ions) const |
Returns regions containing the set of points in the box defined by p1 and p2, according to representation. | |
girl::dart | findDart (const girl::point &p) const |
Gives the dart at the right of point p. | |
girl::point | anyPoint (girl::region r) const |
Gives a point/pixel belonging to the region r. | |
void | regionDomain (girl::region r, std::vector< girl::point > &scan) const |
Gives the scanline of the regionr. | |
void | regionBoundary (girl::region r, girl::contourDeque &b) const |
Gives whole boundary of region r, that is both external and internal region boundaries. | |
void | regionOuterBoundary (girl::region r, girl::contour &c) const |
Gives external boundary of region r. | |
void | regionsCommonBoundary (girl::region r1, girl::region r2, pathDeque &commonSegments) const |
Gives the common boundary paths between regions r1 and r2. | |
void | segment (girl::dart d, girl::path &p) const |
Gives the path which describes the geometry of the segment associated with dart d. | |
size_t | segmentLength (girl::dart d) const |
Gives the length of path which describes the geometry of the segment associated with dart d. | |
girl::face | lambda (girl::dart d) const |
Gives face corresponding to dart b in representation. | |
girl::dart | beta (girl::face f) const |
Gives canonical dart corresponding to face f in representation. | |
girl::dart | alpha (girl::dart d) const |
Gives image by alpha of dart d in representation. | |
girl::dart | sigma (girl::dart d) const |
Gives image by sigma of dart d in representation. | |
girl::dart | phi (girl::dart d) const |
Gives image by phi of dart d in representation. | |
bool | isFaceInfinite (girl::face f) const |
Checks if the given face f is infinite. | |
girl::face | parent (girl::face f) const |
Gives the finite face containing the infinite face f. | |
girl::face | firstChild (girl::face f) const |
Gives the first face contained in f. | |
girl::face | nextSibling (girl::face fi) const |
Gives the next sibling of face fi in the inclusion tree. | |
girl::dart | getDart (const girl::point &pt, girl::direction dir) const |
Gives dart at geometrical node (pt, dir). | |
bool | areNeighbours (girl::region r1, girl::region r2, girl::toger::neighbouringModes mode, girl::toger::markFlags m) const |
Checks if two regions r1 and r2 are neighbours, according to neighbourhood mode mode and mark flags f, in the representation. | |
void | regionNeighbourhood (girl::region r, girl::toger::neighbouringModes mode, girl::toger::markFlags m, regionDeque ®s) const |
Gives all regions neighbour of a region r according to the given neighbouring mode kind and flags f, in the representation. | |
girl::region | anyRegionNeighbour (girl::region r, girl::toger::neighbouringModes mode, girl::toger::markFlags m) const |
Gives one region neighbour of a region r according to the given neighbouring mode kind and flags f, in the representation. | |
void | allRegions (regionDeque ®s) const |
Gives all regions of the representation. | |
size_t | numRegions () const |
Gives the number of regions in the representation. | |
void | innerRegions (girl::region r, regionDeque ®s) const |
Gives all regions touching the inner boundary of region r in representation. | |
void | iterateOnRegionDomain (girl::region r, girl::toger::pointIterator &fct) const |
Allows to iterate on pixels of region r. | |
void | iterateOnFaceBoundary (girl::face f, girl::toger::directionIterator &fct) const |
Allows to iterate on boundary of face f. | |
void | iterateOnSegment (girl::dart d, girl::toger::directionIterator &fct) const |
Allows to iterate on segment of dart d. | |
void | xMarkRegionBoundary (girl::region r, girl::toger::markFlags m) |
Inverts mark of region r's boundary, in representation, with mark f. | |
void | unmarkRegionBoundary (girl::region r, girl::toger::markFlags m) |
Unmarks region r's boundary, in representation, with mark f. | |
void | xMarkOuterBoundary (girl::region r, girl::toger::markFlags m) |
Inverts mark of region r's outer boundary only, in representation, with mark f. | |
void | unmarkOuterBoundary (girl::region r, girl::toger::markFlags m) |
Unmarks region r's outer boundary only, in representation, with mark f. | |
bool | isRegionMarked (girl::region r, girl::toger::markFlags m) const |
Tells if any dart of region r is marked with mark m. | |
bool | isRegionOuterBoundaryMarked (girl::region r, girl::toger::markFlags m) const |
Tells if any dart of outer boundary of region r is marked with mark m. | |
bool | isFaceMarked (girl::face f, girl::toger::markFlags m) const |
Tells if face f is marked with mark m. | |
void | markAllDarts (girl::toger::markFlags m) |
Marks all darts, in representation, with mark f. | |
void | unmarkAllDarts (girl::toger::markFlags m) |
Unmarks all darts, in representation, with mark f. | |
bool | isDartMarked (girl::dart d, girl::toger::markFlags m) const |
Checks if dart d is marked with mark f, in representation. | |
void | markCommonBoundary (girl::region r1, girl::region r2, girl::toger::markFlags m) |
Marks regions r1 and r2 common boundary, in representation, with mark f. | |
void | unmarkCommonBoundary (girl::region r1, girl::region r2, girl::toger::markFlags m) |
Unmarks regions r1 and r2 common boundary, in representation, with mark f. | |
void | saveBitmap (const std::string &f) const |
Save representation to file f. For debug purpose only. | |
bool | checkConsistency () const |
Check overall representation consistency. Will print found errors, if any, to stderr. | |
void | shrink () |
Shrink representation to use the less memory possible. | |
void | write (girl::io::Writer &w, girl::io::Type ioType) const |
Write toger with function fct. | |
bool | read (girl::io::Reader &r, girl::io::Type ioType) |
Read toger with function fct. | |
bool | swapable (const girl::point &p) const |
Tells if borders of pixel are swapable in geometric representation of toger. | |
void | swap (const girl::point &p) |
Swap pixel borders in geometric representation of toger. |
Region based topological and geometrical image representation.
typedef enum girl::toger::markFlag girl::toger::markFlag |
Marks used to mark darts.
Neighbourhing modes :
Marks used to mark darts.
Neighbourhing modes :
girl::toger::toger | ( | POINT_TYPE | width = 1 , |
|
POINT_TYPE | height = 1 | |||
) |
Constructor.
Initialize the representation with one region, labelled 1, that fill the box defined by width & height.
width and height are the size of the image.
void girl::toger::allRegions | ( | regionDeque & | regs | ) | const |
Gives all regions of the representation.
Gives regions in regs.
girl::point girl::toger::anyPoint | ( | girl::region | r | ) | const |
Gives a point/pixel belonging to the region r.
While there is no side effect on region r, the point is assured to stay the same.
girl::region girl::toger::anyRegionNeighbour | ( | girl::region | r, | |
girl::toger::neighbouringModes | mode, | |||
girl::toger::markFlags | m | |||
) | const |
Gives one region neighbour of a region r according to the given neighbouring mode kind and flags f, in the representation.
kind is an OR'ed combination of the neighbouring modes. m is an OR'ed combination of markFlag. If f is different than MARK_NONE, two regions, neighbours according to specified neighbouring mode m, are reported as neighbours only if their common boundary is NOT marked by f.
bool girl::toger::areNeighbours | ( | girl::region | r1, | |
girl::region | r2, | |||
girl::toger::neighbouringModes | mode, | |||
girl::toger::markFlags | m | |||
) | const |
Checks if two regions r1 and r2 are neighbours, according to neighbourhood mode mode and mark flags f, in the representation.
mode is an OR'ed combination of girl::toger::neighbouringMode values. m is an OR'ed combination of markFlag. If f is different than MARK_NONE, region r1 and r2, neighbours according to specified neighbouring mode m, are reported as neighbours only if their common boundary is NOT marked by f.
bool girl::toger::checkConsistency | ( | ) | const |
Check overall representation consistency. Will print found errors, if any, to stderr.
girl::dart girl::toger::findDart | ( | const girl::point & | p | ) | const |
girl::region girl::toger::findRegion | ( | const girl::point & | p | ) | const |
void girl::toger::findRegions | ( | const girl::point & | p1, | |
const girl::point & | p2, | |||
girl::regionDeque & | regions | |||
) | const |
Returns regions containing the set of points in the box defined by p1 and p2, according to representation.
girl::face girl::toger::firstChild | ( | girl::face | f | ) | const |
Gives the first face contained in f.
Allows to traverse children of a face with girlToger_nextSibling.
girl::dart girl::toger::getDart | ( | const girl::point & | pt, | |
girl::direction | dir | |||
) | const |
POINT_TYPE girl::toger::height | ( | ) | const |
void girl::toger::innerRegions | ( | girl::region | r, | |
regionDeque & | regs | |||
) | const |
Gives all regions touching the inner boundary of region r in representation.
Gives the regions in regs.
bool girl::toger::insertPaths | ( | const girl::pathDeque & | paths, | |
girl::regionDeque & | out_q | |||
) |
Inserts a set of paths paths in representation.
bool girl::toger::isDartMarked | ( | girl::dart | d, | |
girl::toger::markFlags | m | |||
) | const |
Checks if dart d is marked with mark f, in representation.
m is an OR'ed combination of markFlag.
bool girl::toger::isFaceMarked | ( | girl::face | f, | |
girl::toger::markFlags | m | |||
) | const |
Tells if face f is marked with mark m.
m is an OR'ed combination of markFlag.
do not take any eventual child of face f into account.
bool girl::toger::isRegionMarked | ( | girl::region | r, | |
girl::toger::markFlags | m | |||
) | const |
Tells if any dart of region r is marked with mark m.
m is an OR'ed combination of markFlag.
bool girl::toger::isRegionOuterBoundaryMarked | ( | girl::region | r, | |
girl::toger::markFlags | m | |||
) | const |
Tells if any dart of outer boundary of region r is marked with mark m.
m is an OR'ed combination of markFlag.
void girl::toger::iterateOnFaceBoundary | ( | girl::face | f, | |
girl::toger::directionIterator & | fct | |||
) | const |
Allows to iterate on boundary of face f.
This function allow to iterate on a face boundary with a limited number of allocations, and so decent performances.
processFirstPoint() of fct will be called on first point of boundary. processDirection() of fct will be called on each direction of contour of face f. processLastPoint() of fct will be called on last point of boundary (which is the same as the first for a closed contour).
void girl::toger::iterateOnRegionDomain | ( | girl::region | r, | |
girl::toger::pointIterator & | fct | |||
) | const |
Allows to iterate on pixels of region r.
processPoint() of fct will be called on each pixel of domain of region r. processLastPoint() of fct will not be called.
This function allow to iterate on domain of a region with a limited number of allocations, and so decent performances.
void girl::toger::iterateOnSegment | ( | girl::dart | d, | |
girl::toger::directionIterator & | fct | |||
) | const |
Allows to iterate on segment of dart d.
This function allow to iterate on a dart with a limited number of allocations, and so decent performances.
processFirstPoint() of fct will be called on first point of segment of dart d. processDirection() of fct will be called on each direction of segment of dart d. processLastPoint() of fct will be called on last point of segment of dart d.
process*() function of fct must not modify toger.
void girl::toger::markAllDarts | ( | girl::toger::markFlags | m | ) |
Marks all darts, in representation, with mark f.
m is an OR'ed combination of markFlag.
void girl::toger::markCommonBoundary | ( | girl::region | r1, | |
girl::region | r2, | |||
girl::toger::markFlags | m | |||
) |
Marks regions r1 and r2 common boundary, in representation, with mark f.
m is an OR'ed combination of markFlag.
girl::region girl::toger::mergeRegions | ( | girl::region | r1, | |
girl::region | r2 | |||
) |
Merges two regions r1 and r2, in representation.
If merge is possible, i.e., regions are neighbours, final region, result of the merge, will be labelled as one of the two incoming regions. The region label not reused will be freed.
Merge regions hook then delete region hook will be called if they have been set with, respectively, setMergeRegionsHook & setDeleteRegionHook. Merge regions hook, if set, will be called first with the kept region as first argument and the to-be-deleted region as second argument. Delete region hook, if set, will then be called, with the to-be-deleted region.
girl::face girl::toger::nextSibling | ( | girl::face | fi | ) | const |
Gives the next sibling of face fi in the inclusion tree.
size_t girl::toger::numRegions | ( | ) | const |
Gives the number of regions in the representation.
Complexity: O(N) (but no memory allocation).
girl::face girl::toger::parent | ( | girl::face | f | ) | const |
Gives the finite face containing the infinite face f.
regions all have 0 for mother ; infinite faces have a mother != 0.
bool girl::toger::read | ( | girl::io::Reader & | r, | |
girl::io::Type | ioType | |||
) |
Read toger with function fct.
user_data allows to pass a context to the read function. ioType is used to know if read is done from memory or disk, and so if portability as to be ensured.
void girl::toger::regionBoundary | ( | girl::region | r, | |
girl::contourDeque & | b | |||
) | const |
Gives whole boundary of region r, that is both external and internal region boundaries.
The first one is the external contour.
void girl::toger::regionDomain | ( | girl::region | r, | |
std::vector< girl::point > & | scan | |||
) | const |
Gives the scanline of the regionr.
return 2*N points, such as two consecutive points, 2*i and 2*i+1, are extremities of a line of the domain. We then have scan[2*i].x()<=scan[2*i+1].x() && scan[2*i].y()==scan[2*i+1].y(). Besides point are ordered in increasing x and y. Thus we have scan[2*i].y()<scan[2*i+2].y() or scan[2*i].y()==scan[2*i+2].y() && scan[2*i].x()<scan[2*i+2].x().
void girl::toger::regionNeighbourhood | ( | girl::region | r, | |
girl::toger::neighbouringModes | mode, | |||
girl::toger::markFlags | m, | |||
regionDeque & | regs | |||
) | const |
Gives all regions neighbour of a region r according to the given neighbouring mode kind and flags f, in the representation.
kind is an OR'ed combination of the neighbouring modes. m is an OR'ed combination of markFlag. If f is different than MARK_NONE, two regions, neighbours according to specified neighbouring mode m, are reported as neighbours only if their common boundary is NOT marked by f.
regs will hold the found regions
void girl::toger::regionOuterBoundary | ( | girl::region | r, | |
girl::contour & | c | |||
) | const |
Gives external boundary of region r.
c is filled with boundary of region r.
void girl::toger::regionsCommonBoundary | ( | girl::region | r1, | |
girl::region | r2, | |||
pathDeque & | commonSegments | |||
) | const |
Gives the common boundary paths between regions r1 and r2.
Paths are oriented from r1.
void girl::toger::segment | ( | girl::dart | d, | |
girl::path & | p | |||
) | const |
Gives the path which describes the geometry of the segment associated with dart d.
size_t girl::toger::segmentLength | ( | girl::dart | d | ) | const |
void girl::toger::setMergeRegionsHook | ( | girl::toger::f2RegionsHook | hook, | |
void * | userData | |||
) |
Sets callback function to be called when two regions are merged and before the delete hook.
The hook will be called with the kept region as first argument r1, and region to be deleted as second argument r2.
void girl::toger::setRenameRegionHook | ( | girl::toger::f2RegionsHook | hook, | |
void * | userData | |||
) |
Sets callback function to be called when a region is renammed.
The hook is called with old region for r1 and new region for r2.
We have the garantee that r1 <= r2 and hook will be called in increasing region order.
void girl::toger::shrink | ( | ) |
Shrink representation to use the less memory possible.
It may rename some regions.
void girl::toger::splitRegion | ( | girl::region | r, | |
girl::toger::sameRegion & | same_r, | |||
girl::regionDeque & | regs | |||
) |
Splits a given region r of representation, using same_r as a partition criterion.
Will call same() of same_r to decide if two neighbour pixels belong to the same region or not.
Gives the found regions in regs. Given region r is reused and will be the first region in regs. Returned regions are in no specific order (no geometrical or topological information should be inferred of regions order in regs)
New region hook will be called for each created region if it has been set with setNewRegionHook.
void girl::toger::swap | ( | const girl::point & | p | ) |
void girl::toger::unmarkAllDarts | ( | girl::toger::markFlags | m | ) |
Unmarks all darts, in representation, with mark f.
m is an OR'ed combination of markFlag.
void girl::toger::unmarkCommonBoundary | ( | girl::region | r1, | |
girl::region | r2, | |||
girl::toger::markFlags | m | |||
) |
Unmarks regions r1 and r2 common boundary, in representation, with mark f.
m is an OR'ed combination of markFlag.
void girl::toger::unmarkOuterBoundary | ( | girl::region | r, | |
girl::toger::markFlags | m | |||
) |
Unmarks region r's outer boundary only, in representation, with mark f.
m is an OR'ed combination of markFlag. Region boundary is symmetrically unmarked.
void girl::toger::unmarkRegionBoundary | ( | girl::region | r, | |
girl::toger::markFlags | m | |||
) |
Unmarks region r's boundary, in representation, with mark f.
m is an OR'ed combination of markFlag Region boundary is symmetrically unmarked.
POINT_TYPE girl::toger::width | ( | ) | const |
void girl::toger::write | ( | girl::io::Writer & | w, | |
girl::io::Type | ioType | |||
) | const |
Write toger with function fct.
user_data allows to pass a context to the write function. ioType is used to know if write is done to memory or disk, and so if portability as to be ensured.
void girl::toger::xMarkOuterBoundary | ( | girl::region | r, | |
girl::toger::markFlags | m | |||
) |
Inverts mark of region r's outer boundary only, in representation, with mark f.
m is an OR'ed combination of markFlag. Region boundary is symmetrically marked.
void girl::toger::xMarkRegionBoundary | ( | girl::region | r, | |
girl::toger::markFlags | m | |||
) |
Inverts mark of region r's boundary, in representation, with mark f.
m is an OR'ed combination of markFlag. Region boundary is symmetrically marked.