GraphBase< NODE, EDGE > Class Template Reference

#include <graphbase.h>

Detailed Description

template<typename NODE, typename EDGE>
class maxon::GraphBase< NODE, EDGE >

Basic undirected graph template.

Template Parameters
NODEThe node type in the graph.
EDGEThe edge type in the graph.

Public Types

typedef GraphBase< NODE, EDGE > Super
 
typedef NODE NodeType
 
typedef EDGE EdgeType
 

Public Member Functions

 GraphBase ()
 
 ~GraphBase ()
 
 GraphBase (GraphBase &&src)
 
Result< void > CopyFrom (const GraphBase &src)
 
Result< void > AppendGraph (const GraphBase &src)
 
GRAPH_TYPE GetType () const
 
void SetType (GRAPH_TYPE type)
 
Int GetNodesCount (Bool subPoint=false) const
 
Int GetEdgesCount () const
 
NODE * GetFirstNode ()
 
NODE * GetLastNode ()
 
NODE * FindNodeByPosition (const Vector &position, Float tolerance=0.0)
 
const NODE * FindNodeByPosition (const Vector &position, Float tolerance=0.0) const
 
Result< NODE * > GetNode (Int idx)
 
Result< const NODE * > GetNode (Int idx) const
 
Result< NODE * > GetSuccessor (NODE *node)
 
Result< NODE * > GetPredecessor (NODE *node)
 
Result< EDGE * > GetSuccessorEdge (NODE *node)
 
Result< EDGE * > GetPredecessorEdge (NODE *node)
 
Int FindNode (NODE *node)
 
Result< EDGE * > GetEdge (Int idx)
 
Result< const EDGE * > GetEdge (Int idx) const
 
Int FindEdge (EDGE *edge)
 
Result< EDGE * > GetEdgeByPoints (NodeType *p1, NodeType *p2) const
 
Result< NODE * > AddNode (const NodeType &node, Int pos=NOTOK)
 
Result< EDGE * > AddEdge (NodeType *p1, NodeType *p2, Int pos=NOTOK)
 
Result< NODE * > SplitEdge (const NODE &node, EdgeType *edge)
 
Result< EDGE * > SplitEdge (NodeType *node, EdgeType *edge)
 
Result< void > DeleteNode (NodeType *node, Bool replaceEdge=true)
 
Result< void > DeleteNode (Int pos, Bool replaceEdge=true)
 
Result< void > DeleteEdge (EdgeType *edge, Bool nodes=false)
 
Result< void > DeleteEdge (Int pos, Bool nodes=false)
 
Result< void > WeldNodes (NodeType *p1, NodeType *p2)
 
Result< void > MeltEdge (EdgeType *edge)
 
Result< void > MeltEdge (Int pos)
 
void Reset ()
 

Protected Attributes

GRAPH_TYPE _type
 
PointerArray< NODE > _nodes
 
PointerArray< EDGE > _edges
 

Member Typedef Documentation

◆ Super

typedef GraphBase<NODE, EDGE> Super

◆ NodeType

typedef NODE NodeType

◆ EdgeType

typedef EDGE EdgeType

Constructor & Destructor Documentation

◆ GraphBase() [1/2]

GraphBase ( )
explicit

◆ ~GraphBase()

~GraphBase ( )

◆ GraphBase() [2/2]

GraphBase ( GraphBase< NODE, EDGE > &&  src)

Member Function Documentation

◆ CopyFrom()

Result<void> CopyFrom ( const GraphBase< NODE, EDGE > &  src)

◆ AppendGraph()

Result<void> AppendGraph ( const GraphBase< NODE, EDGE > &  src)

Append src graph t this graph, the existing graph is mantained.

Parameters
[in]srcThe graph to append.
Returns
OK on success.

◆ GetType()

GRAPH_TYPE GetType ( ) const

Get The graph type.

Returns
The graph type.

◆ SetType()

void SetType ( GRAPH_TYPE  type)

Set The graph type.

Parameters
[in]typeThe new graph type.

◆ GetNodesCount()

Int GetNodesCount ( Bool  subPoint = false) const

Get All nodes count in the graph.

Returns
The main point count in the graph.

◆ GetEdgesCount()

Int GetEdgesCount ( ) const

Get All edge count in the graph.

Returns
The stroke count in the graph.

◆ GetFirstNode()

NODE* GetFirstNode ( )

Get a pointer to the first node.

Returns
A pointer to the first node.

◆ GetLastNode()

NODE* GetLastNode ( )

Get a pointer to the last node.

Returns
A pointer to the last node.

◆ FindNodeByPosition() [1/2]

NODE* FindNodeByPosition ( const Vector position,
Float  tolerance = 0.0 
)

Serch a node with at passed position.

Parameters
[in]positionThe 3d position where search the node.
[in]toleranceSearch can be tolerat if passed value is != 0.
Returns
A pointer to the node if found at position otherwise false.

◆ FindNodeByPosition() [2/2]

const NODE* FindNodeByPosition ( const Vector position,
Float  tolerance = 0.0 
) const

Serch a node with at passed position.

Parameters
[in]positionThe 3d position where search the node.
[in]toleranceSearch can be tolerat if passed value is != 0.
Returns
A pointer to the node if found at position otherwise false.

◆ GetNode() [1/2]

Result<NODE*> GetNode ( Int  idx)

Get a node in the list.

Parameters
[in]idxThe node index in the list.
Returns
A pointer to the entry in the list otherwise error.

◆ GetNode() [2/2]

Result<const NODE*> GetNode ( Int  idx) const

Get a node in the list.

Parameters
[in]idxThe node index in the list.
Returns
A pointer to the entry in the list otherwise error.

◆ GetSuccessor()

Result<NODE*> GetSuccessor ( NODE *  node)

Get the successor node, valid only in continuos graph case.

Parameters
[in]nodeThe node.
Returns
A pointer to the successor node otherwise an error.

◆ GetPredecessor()

Result<NODE*> GetPredecessor ( NODE *  node)

Get the predecessor node, valid only in continuos graph case.

Parameters
[in]nodeThe node.
Returns
A pointer to the Predecessor node otherwise an error.

◆ GetSuccessorEdge()

Result<EDGE*> GetSuccessorEdge ( NODE *  node)

Get the successor edge, valid only in continuos graph case.

Parameters
[in]nodeThe node.
Returns
A pointer to the successor edge otherwise an error.

◆ GetPredecessorEdge()

Result<EDGE*> GetPredecessorEdge ( NODE *  node)

Get the predecessor edge, valid only in continuos graph case.

Parameters
[in]nodeThe node.
Returns
A pointer to the Predecessor edge otherwise an error.

◆ FindNode()

Int FindNode ( NODE *  node)

Check if node exist in the node list and return the index.

Parameters
[in]nodeThe node to check for.
Returns
The node index if found or NOTOK if the node is not in to the list.

◆ GetEdge() [1/2]

Result<EDGE*> GetEdge ( Int  idx)

Get a edge at idx in the list.

Parameters
[in]idxThe edge index in the list.
Returns
A pointer to the entry in the list otherwise error.

◆ GetEdge() [2/2]

Result<const EDGE*> GetEdge ( Int  idx) const

Get a edge at idx in the list.

Parameters
[in]idxThe edge index in the list.
Returns
A pointer to the entry in the list otherwise error.

◆ FindEdge()

Int FindEdge ( EDGE *  edge)

Check if edge exist in the edge list and return the index.

Parameters
[in]edgeThe edge to check for.
Returns
The edge index if found or NOTOK if the edge is not in to the list.

◆ GetEdgeByPoints()

Result<EDGE*> GetEdgeByPoints ( NodeType p1,
NodeType p2 
) const

Check if exist a edge in between p1 and p2, if yes return the pointer.

Parameters
[in]p1First edge point.
[in]p2Second edge point.
Returns
A pointer to the edge otherwise error.

◆ AddNode()

Result<NODE*> AddNode ( const NodeType node,
Int  pos = NOTOK 
)

Add a new node to the list.

Parameters
[in]nodeThe new pen node to add.
[in]posOptional position in to the array if NOTOK or not passed the point is added at the end of the list.
Returns
A pointer to the added entry otherwise error.

◆ AddEdge()

Result<EDGE*> AddEdge ( NodeType p1,
NodeType p2,
Int  pos = NOTOK 
)

Add a new edge in between p1 and p2 with type and initialize it. Automatically map the stoke to the points list.

Parameters
[in]p1First edge node.
[in]p2Second edge node.
[in]posIf not NOTOK new stroke will be inserted at pos in the list.
Returns
A pointer to the new stroke added to the list otherwise error.

◆ SplitEdge() [1/2]

Result<NODE*> SplitEdge ( const NODE &  node,
EdgeType edge 
)

Split edge in 2 parts by adding the new node.

Parameters
[in]nodeThe new node to insert in to the list.
[in]edgeThe edge to split.
Returns
A pointer to the new created node otherwise error.

◆ SplitEdge() [2/2]

Result<EDGE*> SplitEdge ( NodeType node,
EdgeType edge 
)

Split edge in 2 parts by attaching it to an existing node.

Parameters
[in]nodeThe node to attach the strokes.
[in]edgeThe edge to split.
Returns
The new added edge pointer otherwise error.

◆ DeleteNode() [1/2]

Result<void> DeleteNode ( NodeType node,
Bool  replaceEdge = true 
)

Remove node and the connected edges.

Parameters
[in]nodeThe node to be removed.
[in]replaceEdgeIf true a new edge will be added to fill the gap, just if the graph is not sparse (max 2 edges per node).
Returns
OK on success.

◆ DeleteNode() [2/2]

Result<void> DeleteNode ( Int  pos,
Bool  replaceEdge = true 
)

Remove node at pos and the connected edges.

Parameters
[in]posThe index position of node to be removed.
[in]replaceEdgeIf true a new edge will be added to fill the gap, just if the graph is not sparse (max 2 edges per node).
Returns
OK on success.

◆ DeleteEdge() [1/2]

Result<void> DeleteEdge ( EdgeType edge,
Bool  nodes = false 
)

Remove the edge and adjust the nodes<->edges mapping.

Parameters
[in]edgeThe edge to be removed.
[in]nodesIf True also node will be deleted if any other edge use it.
Returns
OK on success.

◆ DeleteEdge() [2/2]

Result<void> DeleteEdge ( Int  pos,
Bool  nodes = false 
)

Remove the edge and adjust the nodes<->edges mapping.

Parameters
[in]posThe position in to edge list.
[in]nodesIf True also nodes will be deleted if any other edge use it.
Returns
OK on success.

◆ WeldNodes()

Result<void> WeldNodes ( NodeType p1,
NodeType p2 
)

Weld disconnected nodes.

Parameters
[in]p1First node, this node will be stay alive.
[in]p2Second node.
Returns
OK on success.

◆ MeltEdge() [1/2]

Result<void> MeltEdge ( EdgeType edge)

Shrink edge to a single node and refresh the graph.

Parameters
[in]edgeThe edge to be removed.
Returns
OK on success.

◆ MeltEdge() [2/2]

Result<void> MeltEdge ( Int  pos)

Shrink edge at pos to a single node and refresh the graph.

Parameters
[in]posThe position in to edge list.
Returns
OK on success.

◆ Reset()

void Reset ( )

Free memory and reset all values.

Member Data Documentation

◆ _type

GRAPH_TYPE _type
protected

◆ _nodes

PointerArray<NODE> _nodes
protected

◆ _edges

PointerArray<EDGE> _edges
protected