A Curve is made of 2 nodes (start and end points) and a set of vertices. More...
#include <Curve.h>
Public Types | |
enum | position { INSIDE, OUTSIDE, INTERSECT } |
Position of a rectangle relatively to this curve. More... | |
Public Member Functions | |
Curve (Graph *owner) | |
Creates a new Curve. | |
Curve (Graph *owner, CurvePtr c, NodePtr s, NodePtr e) | |
Creates a new Curve, with parameters copied from another Curve. | |
virtual | ~Curve () |
Deletes this Curve. | |
virtual void | print () const |
Display method. | |
virtual CurveId | getId () const |
Returns this curve's Id For Curve, a CurveId is a direct reference to the Curve, (in opposition to LazyCurves, for which Ids are a unique integer). | |
virtual CurvePtr | getParent () const |
Returns this curve's parent. | |
CurvePtr | getAncestor () const |
Returns this curve's ancestor (the furthest parent). | |
virtual CurveId | getParentId () const |
Returns the parent curve's id. | |
int | getType () const |
Returns the type of this curve. | |
float | getWidth () const |
Returns the width of this curve. | |
int | getSize () const |
Returns the number of vertices (including the start and end nodes). | |
Vertex | getVertex (int i) const |
Returns a Vertex. | |
int | getVertex (vec2d p) const |
Returns the rank of the Vertex that has coordinates P in this curve. | |
vec2d | getXY (int i) const |
Returns the coordinates of a given Vertex. | |
bool | getIsControl (int i) const |
Checks if a given Vertex is a control vertex. | |
bool | getIsSmooth (int i, vec2d &a, vec2d &b) const |
Checks if a given Vertex is "smoothed". | |
float | getS0 () const |
Returns the pseudo curvilinear coordinate at the start node. | |
float | getS1 () const |
Returns the pseudo curvilinear coordinate of the end node. | |
float | getS (int i) const |
Returns the pseudo curvilinear coordinate of a selected vertex. | |
float | getL (int i) const |
Returns the real curvilinear coordinate of a selected vertex. | |
box2d | getBounds () const |
Returns the bounds of the curve (min and max coords amongst all its vertices). | |
Vertex | getVertex (NodePtr start, int offset) const |
Returns a Vertex. | |
vec2d | getXY (NodePtr start, int offset) const |
Returns the coords of a given Vertex. | |
bool | getIsControl (NodePtr start, int offset) const |
Checks if a given vertex is a control or regular vertex. | |
float | getS (NodePtr start, int offset) const |
Returns the pseudo curvilinear coordinate of a given vertex. | |
float | getL (NodePtr start, int offset) const |
Returns the real curvilinear coordinate of a given vertex. | |
virtual NodePtr | getStart () const |
Returns the starting Node. | |
virtual NodePtr | getEnd () const |
Returns the ending Node. | |
AreaPtr | getArea1 () const |
Returns this curve's first area. | |
AreaPtr | getArea2 () const |
Returns this curve's second area. | |
virtual void | addVertex (NodeId id, bool isEnd=1) |
Adds a vertex to the curve. | |
virtual void | addVertex (double x, double y, float s, bool isControl) |
Adds a vertex to the curve. | |
virtual void | addVertex (vec2d pt, int rank, bool isControl) |
Adds a vertex to the curve. | |
virtual void | addVertex (const vec2d &p, float s, float l, bool isControl) |
Adds a vertex to the curve. | |
virtual void | addVertex (const Vertex &pt) |
Adds a vertex to the curve. | |
virtual void | addVertices (const vector< vec2d > &v) |
Adds a list of vertex to the curve. | |
virtual void | removeVertex (int i) |
Remove the i'th vertex from the list. | |
void | decimate (float minDistance) |
Merge vertices in Curves which are too near from one another. | |
NodePtr | getOpposite (const NodePtr n) const |
Returns the opposite of the given extremity. | |
CurvePtr | getNext (const NodePtr n, const std::set< CurveId > &excludedCurves, bool reverse=false) const |
Returns the next curve after this one at the given node, in clockwise order. | |
float | getCurvilinearLength (float s, vec2d *p, vec2d *n) const |
Computes the curvilinear length corresponding to the given s coordinate. | |
float | getCurvilinearCoordinate (float l, vec2d *p, vec2d *n) const |
Computes the pseudo curvilinear coordinate corresponding to the given l coordinate. | |
position | getRectanglePosition (float width, float cap, const box2d &r, double *coords) const |
Returns the position of the given rectangle relatively to this curve. | |
position | getTrianglePosition (float width, float cap, const vec2d *t, const box2d &r, double *coords) const |
Returns the position of the given triangle relatively to this curve. | |
bool | isInside (const vec2d &p) const |
Returns true if the given point is inside this curve. | |
bool | isDirect () const |
Returns true if this curve is clockwise ordered. | |
virtual void | setIsControl (int i, bool c) |
Sets the state of a Vertex. | |
virtual void | setS (int i, float s) |
Changes the S coordinate of a Vertex. | |
virtual void | setXY (int i, const vec2d &p) |
Sets the XY coords of a vertex. | |
virtual void | setWidth (float width) |
Sets this curve's width. | |
virtual void | setType (int type) |
Sets this curve's type. | |
virtual void | flatten (float squareFlatness) |
Subdivides this curve where necessary to satisfy the given maximum error bound. | |
void | computeCurvilinearCoordinates () |
Computes the Vertex::s coordinates for every Vertex of this curve. | |
float | computeCurvilinearLength () |
Computes the Vertex::l coordinates for every Vertex of this curve. | |
bool | equals (Curve *c, set< NodeId > &visited) const |
Checks if two curves are identicals. | |
virtual void | clear () |
Removes the references to this curve from its nodes. | |
virtual void | invert () |
Changes the orientation of this curve. | |
void | setOwner (Graph *owner) |
Sets the owner Graph value. | |
void | setParent (CurvePtr c) |
Sets the parent curve. | |
virtual void | addArea (AreaId a) |
Adds an area to the curve. | |
void | check () |
Basic runtime checking of the integrity of the Curve. | |
void | removeDuplicateVertices () |
Remove duplicate vertices (coming from bad sources). | |
Protected Member Functions | |
void | setParentId (CurveId id) |
Sets the parent Id. | |
void | resetBounds () const |
Resets bounds. | |
void | removeArea (AreaId a) |
Removes an area from the curve. | |
Protected Attributes | |
CurveId | id |
This curve's id. | |
Graph * | owner |
The graph containing this curve. | |
CurvePtr | parent |
The parent curve. | |
int | type |
Type of the curve. | |
float | width |
Width of the curve. | |
float | s0 |
Pseudo curvilinear coordinate at rank 0. | |
float | s1 |
Pseudo curvilinear coordinate at end point. | |
float | l |
Length of the curve (== number of nodes). | |
NodePtr | start |
Start node. | |
NodePtr | end |
End node. | |
vector< Vertex > * | vertices |
List of vertices describing the curve. | |
box2d * | bounds |
The XY min & max values of this curve. | |
AreaId | area1 |
First area. | |
AreaId | area2 |
Second area. |
A Curve is made of 2 nodes (start and end points) and a set of vertices.
It may be used to represent Areas, but can also be used independently.
Position of a rectangle relatively to this curve.
See getRectanglePosition.
proland::Curve::Curve | ( | Graph * | owner | ) |
Creates a new Curve.
owner | the graph containing this curve. |
proland::Curve::Curve | ( | Graph * | owner, | |
CurvePtr | c, | |||
NodePtr | s, | |||
NodePtr | e | |||
) |
virtual proland::Curve::~Curve | ( | ) | [virtual] |
Deletes this Curve.
virtual void proland::Curve::addArea | ( | AreaId | a | ) | [virtual] |
Adds an area to the curve.
2 Areas can be stored (one for each side of the curve).
a | the id of the area to add. |
Reimplemented in proland::LazyCurve.
virtual void proland::Curve::addVertex | ( | const Vertex & | pt | ) | [virtual] |
Adds a vertex to the curve.
pt | a model Vertex, from which the values will be copied. |
Reimplemented in proland::LazyCurve.
virtual void proland::Curve::addVertex | ( | const vec2d & | p, | |
float | s, | |||
float | l, | |||
bool | isControl | |||
) | [virtual] |
Adds a vertex to the curve.
p | a vector containing the x&y coordinates of the vertex. | |
s | the s coordinate. | |
l | the l coordinate. | |
isControl | if true, the vertex will be a control vertex of this curve. |
Reimplemented in proland::LazyCurve.
virtual void proland::Curve::addVertex | ( | vec2d | pt, | |
int | rank, | |||
bool | isControl | |||
) | [virtual] |
Adds a vertex to the curve.
rank | where to insert the Vertex. | |
x | Xcoord. | |
y | Ycoord. | |
s | pseudo curvilinear value. | |
isControl | if true, the vertex will be a control vertex of this curve. |
Reimplemented in proland::LazyCurve.
virtual void proland::Curve::addVertex | ( | double | x, | |
double | y, | |||
float | s, | |||
bool | isControl | |||
) | [virtual] |
Adds a vertex to the curve.
x | Xcoord. | |
y | Ycoord. | |
s | pseudo curvilinear value. | |
isControl | if true, the vertex will be a control vertex of this curve. |
Reimplemented in proland::LazyCurve.
virtual void proland::Curve::addVertex | ( | NodeId | id, | |
bool | isEnd = 1 | |||
) | [virtual] |
Adds a vertex to the curve.
id | a NodeId. Will be stored in start if start == NULL, else in end. | |
isEnd | determines if the node is the end node. if false, it will change this->start; if true && start != NULL, this->end. Default is true. |
Reimplemented in proland::LazyCurve.
virtual void proland::Curve::addVertices | ( | const vector< vec2d > & | v | ) | [virtual] |
Adds a list of vertex to the curve.
v | the list of vertices. |
Reimplemented in proland::LazyCurve.
void proland::Curve::check | ( | ) |
Basic runtime checking of the integrity of the Curve.
Currently: verify that each point is different from itsd neighbours.
virtual void proland::Curve::clear | ( | ) | [virtual] |
Removes the references to this curve from its nodes.
Reimplemented in proland::LazyCurve.
void proland::Curve::computeCurvilinearCoordinates | ( | ) |
float proland::Curve::computeCurvilinearLength | ( | ) |
void proland::Curve::decimate | ( | float | minDistance | ) |
Merge vertices in Curves which are too near from one another.
Checks if two curves are identicals.
Used for comparing graphs.
c | another curve. | |
visited | List of nodes that were already checked + those checked during this call. |
virtual void proland::Curve::flatten | ( | float | squareFlatness | ) | [virtual] |
Subdivides this curve where necessary to satisfy the given maximum error bound.
The extremities are not changed, but the intermediate points are replaced with new points, computed by subdividing the Bezier arcs recursively, until the distance between the limit curve and the actual curve is less than sqrt(squareFlatness). The s coordinate of the new points is automatically computed, but their l coordinate is reset to -1.
squareFlatness | square of the maximum allowed distance between the limit curve and its polyline approximation. |
CurvePtr proland::Curve::getAncestor | ( | ) | const |
Returns this curve's ancestor (the furthest parent).
AreaPtr proland::Curve::getArea1 | ( | ) | const |
Returns this curve's first area.
AreaPtr proland::Curve::getArea2 | ( | ) | const |
Returns this curve's second area.
box2d proland::Curve::getBounds | ( | ) | const |
Returns the bounds of the curve (min and max coords amongst all its vertices).
float proland::Curve::getCurvilinearCoordinate | ( | float | l, | |
vec2d * | p, | |||
vec2d * | n | |||
) | const |
Computes the pseudo curvilinear coordinate corresponding to the given l coordinate.
l | a curvilinear coordinate (see Vertex::l). | |
p | where to store the x,y coordinates corresponding to l, or NULL if these coordinates are not needed. | |
n | where to store the normal to the curve at l, or NULL if this normal is not needed. |
float proland::Curve::getCurvilinearLength | ( | float | s, | |
vec2d * | p, | |||
vec2d * | n | |||
) | const |
Computes the curvilinear length corresponding to the given s coordinate.
s | a pseudo curvilinear coordinate (see Vertex::s). | |
p | where to store the x,y coordinates corresponding to s, or NULL if these coordinates are not needed. | |
n | where to store the normal to the curve at s, or NULL if this normal is not needed. |
virtual NodePtr proland::Curve::getEnd | ( | ) | const [virtual] |
Returns the ending Node.
Reimplemented in proland::LazyCurve.
virtual CurveId proland::Curve::getId | ( | ) | const [virtual] |
Returns this curve's Id For Curve, a CurveId is a direct reference to the Curve, (in opposition to LazyCurves, for which Ids are a unique integer).
Reimplemented in proland::LazyCurve.
bool proland::Curve::getIsControl | ( | NodePtr | start, | |
int | offset | |||
) | const |
bool proland::Curve::getIsControl | ( | int | i | ) | const |
Checks if a given Vertex is a control vertex.
i | the rank of the vertex to return. |
bool proland::Curve::getIsSmooth | ( | int | i, | |
vec2d & | a, | |||
vec2d & | b | |||
) | const |
Checks if a given Vertex is "smoothed".
i.e. if the two vertices around it are Control vertices and if they are aligned. Also returns the two points that would smooth it if return value is false.
float proland::Curve::getL | ( | NodePtr | start, | |
int | offset | |||
) | const |
Returns the real curvilinear coordinate of a given vertex.
start | : the starting node (can be either start or end Node). | |
offset | rank of the vertex to return. |
float proland::Curve::getL | ( | int | i | ) | const |
Returns the real curvilinear coordinate of a selected vertex.
i | rank of the vertex to return. |
CurvePtr proland::Curve::getNext | ( | const NodePtr | n, | |
const std::set< CurveId > & | excludedCurves, | |||
bool | reverse = false | |||
) | const |
Returns the next curve after this one at the given node, in clockwise order.
The curves connected to the given node (and that are in the given set of curves) are ordered by using their first control point after this node to compute an angle (relatively to this curve), which is then used to order them.
n | the start or end of this curve. | |
excludedCurves | the curves that must NOT be taken into account. | |
rerverse | determines in which order the curve must be selected. Default value is false, which means clockwise order. |
NodePtr proland::Curve::getOpposite | ( | const NodePtr | n | ) | const |
Returns the opposite of the given extremity.
If the given extremity is the start of the curve, returns the end, and vice versa.
n | the start or end of this curve. |
virtual CurvePtr proland::Curve::getParent | ( | ) | const [virtual] |
Returns this curve's parent.
The parent curve is the curve from which this curve was created by clipping, or NULL is this curve was not created by clipping (e.g. inside the root graph tile in a GraphProducer).
Reimplemented in proland::LazyCurve.
virtual CurveId proland::Curve::getParentId | ( | ) | const [virtual] |
Returns the parent curve's id.
See getParent() and getId().
position proland::Curve::getRectanglePosition | ( | float | width, | |
float | cap, | |||
const box2d & | r, | |||
double * | coords | |||
) | const |
Returns the position of the given rectangle relatively to this curve.
The given width and cap parameters are used to define a stroked curve, i.e., an area. This area is then used to compute the position of the given rectangle (inside, outside or intersecting this area). Note that these computations are NOT based on the limit curve, but on the polyline defined by the curve control points.
width | the width to be used to define the stroked curve. | |
cap | the length that must be removed at both extremities to define the stroked curve (the cap style is always "butt"). | |
r | the rectangle whose position must be computed. | |
coords | where to put the precise position of r, or NULL is this information is not needed. If not NULL, coords must point to an array of six floats. If r is inside the curve, then these floats are set with the coordinates of the curve segment (a,b) inside which r resides, as follows: a.x, a.y, b.x-a.x, b.y-a.y, a.s, b.s. |
float proland::Curve::getS | ( | NodePtr | start, | |
int | offset | |||
) | const |
Returns the pseudo curvilinear coordinate of a given vertex.
start | : the starting node (can be either start or end Node). | |
offset | rank of the vertex to return. |
float proland::Curve::getS | ( | int | i | ) | const |
Returns the pseudo curvilinear coordinate of a selected vertex.
i | rank of the vertex to return. |
float proland::Curve::getS0 | ( | ) | const [inline] |
Returns the pseudo curvilinear coordinate at the start node.
float proland::Curve::getS1 | ( | ) | const [inline] |
Returns the pseudo curvilinear coordinate of the end node.
int proland::Curve::getSize | ( | ) | const [inline] |
Returns the number of vertices (including the start and end nodes).
virtual NodePtr proland::Curve::getStart | ( | ) | const [virtual] |
Returns the starting Node.
Reimplemented in proland::LazyCurve.
position proland::Curve::getTrianglePosition | ( | float | width, | |
float | cap, | |||
const vec2d * | t, | |||
const box2d & | r, | |||
double * | coords | |||
) | const |
Returns the position of the given triangle relatively to this curve.
The given width and cap parameters are used to define a stroked curve, i.e., an area. This area is then used to compute the position of the given triangle (inside, outside or intersecting this area). Note that these computations are NOT based on the limit curve, but on the polyline defined by the curve control points.
width | the width to be used to define the stroked curve. | |
cap | the length that must be removed at both extremities to define the stroked curve (the cap style is always "butt"). | |
t | the triangle whose position must be computed. | |
r | a bounding rectangle for coarse detection. | |
coords | where to put the precise position of t, or NULL is this information is not needed. If not NULL, coords must point to an array of six floats. If t is inside the curve, then these floats are set with the coordinates of the curve segment (a,b) inside which t resides, as follows: a.x, a.y, b.x-a.x, b.y-a.y, a.s, b.s. |
int proland::Curve::getType | ( | ) | const [inline] |
Returns the type of this curve.
Vertex proland::Curve::getVertex | ( | NodePtr | start, | |
int | offset | |||
) | const |
int proland::Curve::getVertex | ( | vec2d | p | ) | const |
Vertex proland::Curve::getVertex | ( | int | i | ) | const |
float proland::Curve::getWidth | ( | ) | const [inline] |
Returns the width of this curve.
vec2d proland::Curve::getXY | ( | NodePtr | start, | |
int | offset | |||
) | const |
vec2d proland::Curve::getXY | ( | int | i | ) | const |
Returns the coordinates of a given Vertex.
i | the rank of the vertex to return. |
virtual void proland::Curve::invert | ( | ) | [virtual] |
Changes the orientation of this curve.
Reimplemented in proland::LazyCurve.
bool proland::Curve::isDirect | ( | ) | const |
Returns true if this curve is clockwise ordered.
bool proland::Curve::isInside | ( | const vec2d & | p | ) | const |
Returns true if the given point is inside this curve.
Note that this computation is NOT based on the limit curves, but on the polyline defined by the curve control points.
p | the point to check. |
virtual void proland::Curve::print | ( | ) | const [virtual] |
Display method.
For debug only.
void proland::Curve::removeArea | ( | AreaId | a | ) | [protected] |
Removes an area from the curve.
a | the id of the area to remove. |
Reimplemented in proland::LazyCurve.
void proland::Curve::removeDuplicateVertices | ( | ) |
Remove duplicate vertices (coming from bad sources).
virtual void proland::Curve::removeVertex | ( | int | i | ) | [virtual] |
Remove the i'th vertex from the list.
i | the rank of the vertex to remove. |
Reimplemented in proland::LazyCurve.
void proland::Curve::resetBounds | ( | ) | const [protected] |
Resets bounds.
virtual void proland::Curve::setIsControl | ( | int | i, | |
bool | c | |||
) | [virtual] |
Sets the state of a Vertex.
i | the rank of the vertex to change. | |
c | whether the vertex must be a control or regular vertex. |
Reimplemented in proland::LazyCurve.
void proland::Curve::setParent | ( | CurvePtr | c | ) | [inline] |
Sets the parent curve.
The parent curve is the curve from which this curve was created by clipping, or NULL is this curve was not created by clipping (e.g. inside the root graph tile in a GraphProducer).
c | the new parent Curve. |
void proland::Curve::setParentId | ( | CurveId | id | ) | [inline, protected] |
Sets the parent Id.
Basic Curve version : only sets parent to id.ref. See setParent().
id | a curve's Id. |
Reimplemented in proland::LazyCurve.
virtual void proland::Curve::setS | ( | int | i, | |
float | s | |||
) | [virtual] |
Changes the S coordinate of a Vertex.
i | the rank of the vertex to edit. | |
s | the new S coordinate. |
Reimplemented in proland::LazyCurve.
virtual void proland::Curve::setType | ( | int | type | ) | [virtual] |
virtual void proland::Curve::setWidth | ( | float | width | ) | [virtual] |
virtual void proland::Curve::setXY | ( | int | i, | |
const vec2d & | p | |||
) | [virtual] |
Sets the XY coords of a vertex.
i | the rank of the vertex to move. | |
p | the new positions. |
Reimplemented in proland::LazyCurve.
AreaId proland::Curve::area1 [mutable, protected] |
First area.
AreaId proland::Curve::area2 [mutable, protected] |
Second area.
box2d* proland::Curve::bounds [mutable, protected] |
The XY min & max values of this curve.
Used for clipping.
NodePtr proland::Curve::end [mutable, protected] |
End node.
CurveId proland::Curve::id [protected] |
This curve's id.
NULL_ID if this Curve is not a lazycurve.
float proland::Curve::l [protected] |
Length of the curve (== number of nodes).
Graph* proland::Curve::owner [protected] |
The graph containing this curve.
CurvePtr proland::Curve::parent [protected] |
The parent curve.
float proland::Curve::s0 [protected] |
Pseudo curvilinear coordinate at rank 0.
float proland::Curve::s1 [protected] |
Pseudo curvilinear coordinate at end point.
NodePtr proland::Curve::start [mutable, protected] |
Start node.
int proland::Curve::type [protected] |
Type of the curve.
vector<Vertex>* proland::Curve::vertices [protected] |
List of vertices describing the curve.
float proland::Curve::width [protected] |
Width of the curve.