An Area is described by 1 or more curves. More...
#include <Area.h>
Public Member Functions | |
Area (Graph *owner) | |
Creates a new Area. | |
virtual | ~Area () |
Deletes this Area. | |
void | print () const |
Displays the content of the area. | |
virtual AreaId | getId () const |
Returns this area's Id. | |
virtual AreaPtr | getParent () const |
Returns the parent Area of this area. | |
virtual AreaId | getParentId () const |
Returns the parent Area's id. | |
AreaPtr | getAncestor () |
Returns this area's Ancestor Area (The furthest parent). | |
int | getInfo () const |
Returns the info of this Area. | |
virtual int | getCurveCount () const |
Returns the number of curves forming this area. | |
virtual CurvePtr | getCurve (int i) const |
Returns a curve. | |
virtual CurvePtr | getCurve (int i, int &orientation) const |
Returns a curve. | |
GraphPtr | getSubgraph () const |
Returns the Graph contained in this area if any. | |
box2d | getBounds () const |
Returns the bounding box of this area. | |
bool | isInside (const vec2d &p) const |
Returns true if the given point is inside this area. | |
Curve::position | getRectanglePosition (const box2d &r) const |
Returns the position of the given rectangle relatively to this area. | |
Curve::position | getTrianglePosition (const vec2d *t) const |
Returns the position of the given triangle relatively to this area. | |
bool | equals (set< CurveId > curveList) |
Checks if the given curve list corresponds to this area. | |
bool | equals (Area *a, set< CurveId > &visitedCurves, set< NodeId > &visitedNodes) |
Checks if two areas are equals. | |
virtual void | setOrientation (int i, int orientation) |
Sets orientation for a given curve. | |
void | setInfo (int info) |
Sets info. | |
virtual void | invertCurve (CurveId cid) |
Inverts a given curve in this area. | |
void | check () |
Checks if this area is well defined. | |
virtual void | setParent (AreaPtr a) |
Sets the parent area. | |
virtual void | addCurve (CurveId id, int orientation) |
Adds a curve to this area. | |
virtual void | setSubgraph (Graph *g) |
Sets this area's subgraph. | |
bool | isDirect () const |
Returns true if the area is oriented in clockwise order. | |
Static Public Member Functions | |
static bool | clip (vector< CurvePart * > &cpaths, const box2d &clip, vector< CurvePart * > &result) |
Clips an area given as a list of curve parts. | |
static bool | isDirect (const vector< Vertex > &points, int start, int end) |
Returns true if the given list of points are oriented in clockwise order. | |
Private Member Functions | |
virtual void | setParentId (AreaId id) |
Sets the parent Id. | |
virtual void | switchCurves (int curve1, int curve2) |
Switch 2 curves of this area. | |
virtual void | removeCurve (int index) |
Removes a curve from the curves list. | |
void | resetBounds () const |
Resets the the value of the variable bounds. | |
void | build () |
If necessary, reorders the curves to order them counter-clockwise, consistently with their orientations. | |
bool | build (const CurvePtr p, NodePtr start, NodePtr cur, const set< CurveId > &excludedCurves, set< CurvePtr > &visited, set< CurvePtr > &visitedr) |
Tries to create a valid area from a starting curve. | |
Private Attributes | |
AreaId | id |
This area's ID (NULL_ID if it's a Basic Area, and a non-null positive int if this is a Lazy Area). | |
Graph * | owner |
The graph containing this area. | |
AreaPtr | parent |
The parent area. | |
int | info |
Info about this area. | |
vector< pair< CurvePtr, int > > | curves |
The list of the curves forming this area. | |
GraphPtr | subgraph |
Area's subgraph. | |
box2d * | bounds |
Bounds of the area : x and y limits (max and min for each). |
An Area is described by 1 or more curves.
It may contain a subgraph. This is used to describe pastures, lakes...
proland::Area::Area | ( | Graph * | owner | ) |
virtual proland::Area::~Area | ( | ) | [virtual] |
Deletes this Area.
virtual void proland::Area::addCurve | ( | CurveId | id, | |
int | orientation | |||
) | [virtual] |
Adds a curve to this area.
id | the added curve's Id. | |
orientation | the orientation to add the curve. |
Reimplemented in proland::LazyArea.
bool proland::Area::build | ( | const CurvePtr | p, | |
NodePtr | start, | |||
NodePtr | cur, | |||
const set< CurveId > & | excludedCurves, | |||
set< CurvePtr > & | visited, | |||
set< CurvePtr > & | visitedr | |||
) | [private] |
Tries to create a valid area from a starting curve.
a "valid area" is a list of curves that forms a loop, counter-clockwise ordered.
p | starting curve. | |
start | starting node in P. | |
cur | a second node. Will determine the orientation of the search. | |
excludedCurves | curves we don't want to be part of the area. Can also contains curves that cannot form any area. | |
visited | the curves that were added to this area with their orientation = 0. | |
visitedr | the curves that were added to this area with their orientation = 1. |
void proland::Area::build | ( | ) | [private] |
If necessary, reorders the curves to order them counter-clockwise, consistently with their orientations.
void proland::Area::check | ( | ) |
Checks if this area is well defined.
In other words, it checks if the curves are oriented correctly, and in a correct order, forming a loop.
static bool proland::Area::clip | ( | vector< CurvePart * > & | cpaths, | |
const box2d & | clip, | |||
vector< CurvePart * > & | result | |||
) | [static] |
Clips an area given as a list of curve parts.
The given curve parts must form a closed loop oriented in counter clockwise order, and their orientations must be consistent with this order. The result is a new area also described with a list of curve parts (it can be empty).
cpaths | the area to be clipped. | |
clip | the clip region. This region must be an infinite horizontal or vertical slab. | |
result | where the clipped area must be stored. |
bool proland::Area::equals | ( | Area * | a, | |
set< CurveId > & | visitedCurves, | |||
set< NodeId > & | visitedNodes | |||
) |
Checks if two areas are equals.
Used for unit tests when comparing graphs.
a | another area | |
visitedCurves | curves that were already checked (+ those checked in this function). | |
visitedNodes | nodes that were already checked (+ those checked in this function). |
bool proland::Area::equals | ( | set< CurveId > | curveList | ) |
Checks if the given curve list corresponds to this area.
curveList | a set of curveIds. |
AreaPtr proland::Area::getAncestor | ( | ) |
Returns this area's Ancestor Area (The furthest parent).
This corresponds to the area in the root graph. See getParent().
box2d proland::Area::getBounds | ( | ) | const |
Returns the bounding box of this area.
This box does NOT take the curve widths into account.
virtual CurvePtr proland::Area::getCurve | ( | int | i, | |
int & | orientation | |||
) | const [virtual] |
Returns a curve.
i | the rank of the curve to be returned. | |
orientation | will contain the orientation of the i'th curve in this area. |
Reimplemented in proland::LazyArea.
virtual CurvePtr proland::Area::getCurve | ( | int | i | ) | const [virtual] |
Returns a curve.
i | the rank of the curve to be returned. |
Reimplemented in proland::LazyArea.
virtual int proland::Area::getCurveCount | ( | ) | const [virtual] |
Returns the number of curves forming this area.
Reimplemented in proland::LazyArea.
virtual AreaId proland::Area::getId | ( | ) | const [virtual] |
Returns this area's Id.
For Area, an AreaId is a direct reference to the Area, (in opposition to LazyAreas, for which Ids are a unique integer).
Reimplemented in proland::LazyArea.
int proland::Area::getInfo | ( | ) | const |
Returns the info of this Area.
Info is a randomly generated number.
virtual AreaPtr proland::Area::getParent | ( | ) | const [virtual] |
Returns the parent Area of this area.
The parent area is the area from which this area was created by clipping, or NULL is this area was not created by clipping (e.g. inside the root graph tile in a GraphProducer).
Reimplemented in proland::LazyArea.
virtual AreaId proland::Area::getParentId | ( | ) | const [virtual] |
Returns the parent Area's id.
See getParent() and getId().
Curve::position proland::Area::getRectanglePosition | ( | const box2d & | r | ) | const |
Returns the position of the given rectangle relatively to this area.
Note that this computation is NOT based on the limit curves, but on the polylines based on the control points of the curves that form this area. The curve widths are not taken into account.
r | a rectangle. |
GraphPtr proland::Area::getSubgraph | ( | ) | const |
Returns the Graph contained in this area if any.
Null otherwise.
Curve::position proland::Area::getTrianglePosition | ( | const vec2d * | t | ) | const |
Returns the position of the given triangle relatively to this area.
Note that this computation is NOT based on the limit curves, but on the polylines based on the control points of the curves that form this area. The curve widths are not taken into account.
t | points the 3 summits of the triangle. |
virtual void proland::Area::invertCurve | ( | CurveId | cid | ) | [virtual] |
Inverts a given curve in this area.
cid | the curveId of the curve to invert. |
Reimplemented in proland::LazyArea.
static bool proland::Area::isDirect | ( | const vector< Vertex > & | points, | |
int | start, | |||
int | end | |||
) | [static] |
Returns true if the given list of points are oriented in clockwise order.
points | a vector of points. | |
start | rank of the starting point. | |
end | rank of the end point. |
bool proland::Area::isDirect | ( | ) | const |
Returns true if the area is oriented in clockwise order.
bool proland::Area::isInside | ( | const vec2d & | p | ) | const |
Returns true if the given point is inside this area.
Note that this computation is NOT based on the limit curves, but on the polylines based on the control points of the curves that form this area.
p | a point. The curve widths are not taken into account. |
void proland::Area::print | ( | ) | const |
Displays the content of the area.
Debug only.
virtual void proland::Area::removeCurve | ( | int | index | ) | [private, virtual] |
Removes a curve from the curves list.
the | index of the curve to remove. |
Reimplemented in proland::LazyArea.
void proland::Area::resetBounds | ( | ) | const [private] |
Resets the the value of the variable bounds.
void proland::Area::setInfo | ( | int | info | ) |
Sets info.
info | the new info. |
virtual void proland::Area::setOrientation | ( | int | i, | |
int | orientation | |||
) | [virtual] |
Sets orientation for a given curve.
i | rank of the curve to modify. | |
orientation | the new orientation of the curve. |
Reimplemented in proland::LazyArea.
virtual void proland::Area::setParent | ( | AreaPtr | a | ) | [virtual] |
Sets the parent area.
The parent area is the area from which this area was created by clipping, or NULL is this area was not created by clipping (e.g. inside the root graph tile in a GraphProducer).
a | the new parent Area. |
virtual void proland::Area::setParentId | ( | AreaId | id | ) | [private, virtual] |
Sets the parent Id.
Basic Area version : only sets parent to id.ref. See setParent().
id | the new parent's Id. |
Reimplemented in proland::LazyArea.
virtual void proland::Area::setSubgraph | ( | Graph * | g | ) | [virtual] |
Sets this area's subgraph.
g | a Graph. |
virtual void proland::Area::switchCurves | ( | int | curve1, | |
int | curve2 | |||
) | [private, virtual] |
Switch 2 curves of this area.
id1 | the first curve's id. | |
id2 | the second curve's id. |
Reimplemented in proland::LazyArea.
box2d* proland::Area::bounds [mutable, private] |
Bounds of the area : x and y limits (max and min for each).
This helps to determine if the area will be clipped by a box or not. Caution : this is only updated & used for clipping. It needs to be recomputed before using it. See getBounds().
vector<pair<CurvePtr, int> > proland::Area::curves [mutable, private] |
The list of the curves forming this area.
AreaId proland::Area::id [private] |
int proland::Area::info [private] |
Info about this area.
Graph* proland::Area::owner [private] |
The graph containing this area.
AreaPtr proland::Area::parent [private] |
The parent area.
The parent area is the area from which this area was created by clipping, or NULL is this area was not created by clipping (e.g. inside the root graph tile in a GraphProducer).
GraphPtr proland::Area::subgraph [private] |
Area's subgraph.
A BasicGraph, containing it's own nodes, curves and areas, and possibly other subgraphs.