28#include <boost/iterator/transform_iterator.hpp>
29#include <boost/shared_ptr.hpp>
30#include <boost/function.hpp>
67friend class SaveTreeData;
68friend class LoadTreeData;
89 Graph(
const Graph& g,
const std::vector<const VesselNode*> &
roots,
bool reorder=
false );
95#ifdef VESSELGRAPH_USE_MPIF
96 Graph* deepCopy()
const {
return new Graph(*
this); };
133 std::map<const VesselNode*, VesselNode*>
nodeMapping;
134 std::map<const VesselEdge*, VesselEdge*>
edgeMapping;
135 std::map<const VesselNode*, VesselNode*>
rootMapping;
149 void copyParts(
const std::vector<const VesselNode*>&
nodes,
const std::vector<const VesselEdge*>& edges,
const std::vector<const VesselNode*>&
roots) {
150 std::map<const VesselNode*, VesselNode*>
nodeMapping;
151 std::map<const VesselEdge*, VesselEdge*>
edgeMapping;
152 std::map<const VesselNode*, VesselNode*>
rootMapping;
159 void copyParts(
const std::vector<const VesselNode*>&
nodes,
const std::vector<const VesselEdge*>& edges,
const std::vector<const VesselNode*>&
roots, std::map<const VesselNode*, VesselNode*>&
nodeMapping, std::map<const VesselEdge*, VesselEdge*>&
edgeMapping, std::map<const VesselNode*, VesselNode*>&
rootMapping);
183 typedef boost::function<
VesselNode* (
const NodeMap::value_type &) > NodeAccess;
185 typedef boost::function<
const VesselNode* (
const NodeMap::value_type &) > ConstNodeAccess;
187 typedef boost::transform_iterator<NodeAccess, NodeMap::iterator>
NodeIterator;
194 typedef boost::function<
VesselEdge* (
const EdgeMap::value_type &) > EdgeAccess;
196 typedef boost::function<
const VesselEdge* (
const EdgeMap::value_type &) > ConstEdgeAccess;
198 typedef boost::transform_iterator<EdgeAccess, EdgeMap::iterator>
EdgeIterator;
415 template <
typename ResultType,
typename ParameterType>
416 static ResultType
getSecond(
const ParameterType& p) {
return p.second; }
437 MLint nextNodeId() {
return _nodes.empty() ? 1 : _nodes.rbegin()->first + 1; };
438 MLint nextEdgeId() {
return _edges.empty() ? 1 : _edges.rbegin()->first + 1; };
439 MLint nextRootId() {
return _roots.empty() ? 1 : _roots.rbegin()->first + 1; };
489#ifndef GRAPH_NO_BINARY_PERSISTENCE
568#ifndef GRAPH_NO_BINARY_PERSISTENCE
569 bool _useBinaryPersistence;
Defines the GraphAction class.
Defines the basic Graph class which holds sets of nodes, edges and roots to model tubular structures ...
const VesselNode * getRoot(size_t index) const
Get root via index position.
Graph(const Graph &g, const std::vector< const VesselNode * > &roots, bool reorder=false)
Construct graph from trees in g.
void closeSkeletonGaps()
Closes gaps in the skeletons between the first or last skeleton of a VesselEdge and the closest node.
const VesselNode * getNode(size_t index) const
Get node via index position.
ConstNodeIterator beginNode() const
Provide const iterator access to the begin of the node map.
size_t numEdges() const
Returns the number edges in this graph.
VesselNode * getNode(Vector3 pos)
Get the node with minimal distance to \cpos. Uses method distance() of node classes.
VesselEdge * getIdEdge(MLint id)
Get edge with id id.
bool mergeEdges(VesselEdge *parent, VesselEdge *child)
void fromBinaryData(const std::string &data)
Reconstructs the graph using the binary data.
std::map< MLint, VesselNode * > _roots
VesselNode * getRoot(Vector3 pos)
Get the root node with minimal distance to \cpos.
void worldVoxelConvert()
Convert all graph coordinates from the current coordinate system to the opposite.
bool isWorld() const
Return whether element coordinates are given in voxel or world coordinates.
ActionType getActionValue(void) const
void purifyGraph()
Removes orphan nodes and unsets false cyclic edges (edges with a leaf node that are marked as cyclic)...
MLint splitEdge(MLint edgeID, size_t skeletonIndex)
Splits edge with id edgeID at skeleton index skeletonIndex and returns the ID of the additionally cre...
void setToWorldMatrix(const Matrix4 *m)
Set the conversion matrix for conversions from voxel to world coordinate.
Graph * deepCopy() const override
Implement generic deepCopy functionality using copy constructor.
const VesselNode * getIdNode(MLint id) const
Get node with id id;.
void addGraph(const Graph &g)
Add an entire graph to the current graph.
Graph(Graph &g, int clusterId, bool reorder=false)
Construct graph from subgraph of g, defined by clusterId in g.
VesselEdge * getEdge(size_t index)
Get edge via index position.
Matrix4 _toWorldMatrix
Matrix transform to get from voxel to world coordinates.
void setVersion(int version)
Set version.
std::map< MLint, VesselNode * > _nodes
Maps of graph items.
void setAction(ActionType action, std::string sender)
boost::transform_iterator< NodeAccess, NodeMap::iterator > NodeIterator
Iterator used to traverse nodes in a node map (returns data elements of the map instead of tuples).
PropertyManager::ConstPointer getEdgePropertyManager() const
void removeOrphanNodes()
Remove nodes with no edges attached.
void getToWorldMatrix(float *mat) const
Get the conversion matrix for conversions from voxel to world coordinate.
PropertyManager::Pointer getEdgePropertyManager()
Get access to the GraphPropertyManager for edges.
void clearRoots()
Remove all roots that have been defined.
void setActionCallBack(GraphAction *cbObj)
void insertRoot(VesselNode *node)
Insert a node to the list of root nodes.
PropertyManager::ConstPointer getSkeletonPropertyManager() const
Graph(const Graph &g, bool reorder=false)
Default copy constructor.
bool _isWorld
Is the graph in world coordinates? Default is true.
int getVersion(void)
Get graph's version.
ImageVector _imgExt
Extension of the image the graph is compiled from.
int getNumCluster() const
void stripCycles()
Strip cyclic edges from the graph.
void addGraph(const Graph &g, std::map< const VesselNode *, VesselNode * > &nodeMapping, std::map< const VesselEdge *, VesselEdge * > &edgeMapping, std::map< const VesselNode *, VesselNode * > &rootMapping)
Add an entire graph to this graph.
NodeIterator beginNode()
Provide iterator access to the begin of the node map.
void setVoxelExt(Vector3 v)
NodeIterator beginRoot()
Provide iterator access to the begin of the root map.
void transform(const Matrix4 &m)
VesselEdge * createEdge(MLint predNodeId, MLint succNodeId, MLint useId=-1)
Create a VesselEdge with unique id, add it to the Graph and Nodes identified by the respective IDs an...
Graph(const Graph &g, const VesselNode *root, bool reorder=false)
Construct graph from tree in g.
void setImgExt(ImageVector v)
size_t getIndex(const VesselEdge *edge) const
Return the index of VesselEdge edge in the edgeMap or numEdges() if edge was not found.
Vector3 _voxelExt
Extension of a voxel of the image the graph is compiled from.
VesselNode * getNode(size_t index)
Get node via index position.
Vector3 getVoxelExt() const
static double MIN_SKELETON_LABEL
std::map< MLint, VesselEdge * > EdgeMap
Internal edge storage.
EdgeIterator beginEdge()
Provide iterator access to the begin of the edge map.
NodeIterator endNode()
Provide iterator access to the end of the node map.
ImageVector getImgExt() const
void setToWorld(void)
Define all element coordinates to be in world coordinates (no conversion takes place).
SubImageBoxd getBoundingBox() const
Calculate graph's bounding box from edge-bounding-boxes.
ML_SET_ADDSTATE_VERSION(3)
Set current addStateToTree() version number:
ConstEdgeIterator endEdge() const
Provide const iterator access to the end of the edge map.
bool directGraph(double FloodThresh)
Build a rooted, directed graph.
void setCurrentVersion(void)
Set graph's version to persistent version number.
ConstEdgeIterator beginEdge() const
Provide const iterator access to the begin of the edge map.
static double getMinSkeletonLabel(void)
int separateGraph()
Separate graph into clusters of connected edges.
bool removeNode(VesselNode *node)
Remove a node from the graph.
void setRootIdToAllChildren()
Descends recursively from all roots to the leaves in the trees and sets the rootId of the according r...
bool _isContainedInImageExtent(const Vector3 &pos, const Matrix4 &toVoxelMatrix)
void convertToWorld(void)
Convert all coordinates to world coordinates.
NodeIterator endRoot()
Provide iterator access to the end of the root map.
GraphAction * _actionCBObject
void removeRoot(VesselNode *r)
Remove a root from the graph.
const VesselEdge * getIdEdge(MLint id) const
Get edge with id id.
VesselNode * createNode(const Vector3 &pos=Vector3(0), MLint useId=-1)
Create a VesselNode with unique id, add it to the Graph and return a pointer to it.
const VesselNode * getRoot(Vector3 pos) const
Get the root node with minimal distance to \cpos.
ActionType
Graph modification modes. Ordered from minor to mayor modifications.
VesselEdge * createEdge(VesselNode *predNode, VesselNode *succNode, MLint useId=-1)
Create a VesselEdge with unique id, add it to the Graph and Nodes and return a pointer to it.
~Graph() override
Destructor.
const Matrix4 * getToWorldMatrix() const
Get the conversion matrix for conversions from voxel to world coordinate.
boost::transform_iterator< ConstEdgeAccess, EdgeMap::const_iterator > ConstEdgeIterator
Iterator used to traverse const edges in a edge map (returns data elements of the map instead of tupl...
static double getMaxSkeletonLabel(void)
void readStateFromTree(TreeNode *parent) override
Reads the object state from the children of the given parent node.
bool getUseBinaryPersistence()
VesselNode * createNode(const ImageVector &pos, MLint useId=-1)
Create a VesselNode with unique id, add it to the Graph and return a pointer to it.
void addSubtrees(const std::vector< const VesselNode * > &roots)
Add subtrees rooted at nodes roots to this graph.
void _setRootIdToChildren(int rootId, VesselNode *node, VesselEdge *predEdge)
Sets the given root id to the given node and its child edges and calls itself recursively until the n...
void setToVoxel(void)
Define all element coordinates to be in voxels coordinates (no conversion takes place).
PropertyManager::Pointer getNodePropertyManager()
VesselNode * getRoot(size_t index)
Get root via index position.
ConstNodeIterator beginRoot() const
Provide const iterator access to the begin of the root map.
void useBinaryPersistence(bool use)
Set whether to use binary persistence instead of textual representation (text being the default).
size_t numNodes() const
Returns the number nodes in this graph.
Matrix4 getToVoxelMatrix() const
Get the conversion matrix for conversions from world to voxel coordinate.
const VesselEdge * getEdge(size_t index) const
Get edge via index position.
void copyParts(const std::vector< const VesselNode * > &nodes, const std::vector< const VesselEdge * > &edges, const std::vector< const VesselNode * > &roots)
Copy a collection of nodes, edges and roots from a different graph to this graph.
bool removeEdge(VesselEdge *edge, bool removeEmptyNodes=true)
Remove an edge from the graph.
size_t getIndex(const VesselNode *node) const
Return the index of VesselNode node in the nodeMap or numNodes() if node was not found.
void convertToVoxel(void)
Convert all coordinates to voxel coordinates.
boost::transform_iterator< ConstNodeAccess, NodeMap::const_iterator > ConstNodeIterator
Iterator used to traverse const nodes in a node map (returns data elements of the map instead of tupl...
void clearGraph()
Remove all elements from the graph.
const VesselNode * getNode(Vector3 pos) const
Get the node with minimal distance to \cpos. Uses method distance() of node classes.
void setToWorldMatrix(const Matrix4 &m)
Set the conversion matrix for conversions from voxel to world coordinate.
int _numCluster
Number of non-connected edge-clusters.
ConstNodeIterator endNode() const
Provide const iterator access to the end of the node map.
std::string toBinaryData() const
Returns string containing binary representation of all data necessary to reconstruct the graph.
static double MAX_SKELETON_LABEL
static ResultType getSecond(const ParameterType &p)
Graph()
Default constructor.
VesselNode * getIdNode(MLint id)
Get node with id id;.
void copyParts(const std::vector< const VesselNode * > &nodes, const std::vector< const VesselEdge * > &edges, const std::vector< const VesselNode * > &roots, std::map< const VesselNode *, VesselNode * > &nodeMapping, std::map< const VesselEdge *, VesselEdge * > &edgeMapping, std::map< const VesselNode *, VesselNode * > &rootMapping)
Copy a collection of nodes, edges and roots from a different graph to this graph.
std::map< MLint, VesselEdge * > _edges
const VesselEdge * getEdge(Vector3 pos) const
Get the edge with minimal distance to \cpos. Uses method distance() of edge classes.
boost::transform_iterator< EdgeAccess, EdgeMap::iterator > EdgeIterator
Iterator used to traverse edges in a edge map (returns data elements of the map instead of tuples).
std::map< MLint, VesselNode * > NodeMap
Internal node storage.
EdgeIterator endEdge()
Provide iterator access to the end of the edge map.
size_t numRoots() const
Returns the number roots in this graph.
void setActionValue(ActionType action)
VesselEdge * getEdge(Vector3 pos)
Get the edge with minimal distance to \cpos. Uses method distance() of edge classes.
void addStateToTree(TreeNode *parent) const override
Overload base-methods: Attaches the object state as children of the given parent node.
Graph * newGraph(bool unusedDeprecated=true) const
Allocate new graph with same properties as this (slowly).
ConstNodeIterator endRoot() const
Provide const iterator access to the end of the root map.
PropertyManager::ConstPointer getNodePropertyManager() const
PropertyManager::Pointer getSkeletonPropertyManager()
Get access to the GraphPropertyManager for skeletons.
bool _bFlag
Flag for diverse usage.
boost::intrusive_ptr< const type > ConstPointer
boost::intrusive_ptr< type > Pointer
VesselNode is derived from GraphNode, hence it can be stored as node item in a class Graph object.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
#define ML_CLASS_HEADER(className)
Same like ML_CLASS_HEADER_EXPORTED with a non existing export symbol.
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
#define VESSELGRAPH_END_NAMESPACE
#define VESSELGRAPH_EXPORT
Definiert systemspezifische Macros, die f"ur diese DLL gelten sollen.
#define VESSELGRAPH_BEGIN_NAMESPACE