VTK  9.2.5
vtkGraph.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkGraph.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 /*-------------------------------------------------------------------------
16  Copyright 2008 Sandia Corporation.
17  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
18  the U.S. Government retains certain rights in this software.
19 -------------------------------------------------------------------------*/
265 #ifndef vtkGraph_h
266 #define vtkGraph_h
267 
268 #include "vtkCommonDataModelModule.h" // For export macro
269 #include "vtkDataObject.h"
270 
272 class vtkCellArray;
273 class vtkEdgeListIterator;
275 class vtkDirectedGraph;
276 class vtkGraphEdge;
277 class vtkGraphEdgePoints;
279 class vtkGraphInternals;
280 class vtkIdTypeArray;
281 class vtkInEdgeIterator;
282 class vtkOutEdgeIterator;
283 class vtkPoints;
284 class vtkUndirectedGraph;
286 class vtkVariant;
287 class vtkVariantArray;
288 
289 // Forward declare some boost stuff even if boost wrappers
290 // are turned off.
291 namespace boost
292 {
293 class vtk_edge_iterator;
294 class vtk_out_edge_pointer_iterator;
295 class vtk_in_edge_pointer_iterator;
296 }
297 
298 // Edge structures.
300 {
301  vtkEdgeBase() = default;
303  : Id(id)
304  {
305  }
307 };
308 
310 {
311  vtkOutEdgeType() = default;
313  : vtkEdgeBase(id)
314  , Target(t)
315  {
316  }
318 };
319 
321 {
322  vtkInEdgeType() = default;
324  : vtkEdgeBase(id)
325  , Source(s)
326  {
327  }
329 };
330 
332 {
333  vtkEdgeType() = default;
335  : vtkEdgeBase(id)
336  , Source(s)
337  , Target(t)
338  {
339  }
342 };
343 
344 class VTKCOMMONDATAMODEL_EXPORT vtkGraph : public vtkDataObject
345 {
346 public:
347  vtkTypeMacro(vtkGraph, vtkDataObject);
348  void PrintSelf(ostream& os, vtkIndent indent) override;
349 
351 
354  vtkGetObjectMacro(VertexData, vtkDataSetAttributes);
355  vtkGetObjectMacro(EdgeData, vtkDataSetAttributes);
357 
361  int GetDataObjectType() override { return VTK_GRAPH; }
362 
366  void Initialize() override;
367 
369 
375  double* GetPoint(vtkIdType ptId);
376  void GetPoint(vtkIdType ptId, double x[3]);
378 
380 
388  virtual void SetPoints(vtkPoints* points);
390 
396 
398 
403  double* GetBounds();
404  void GetBounds(double bounds[6]);
406 
410  vtkMTimeType GetMTime() override;
411 
419 
427 
434 
439 
447 
454  virtual void GetInEdges(vtkIdType v, vtkInEdgeIterator* it);
455 
462 
467 
475 
483 
490  virtual void GetEdges(vtkEdgeListIterator* it);
491 
497 
504 
510 
517 
522 
531  vtkIdType FindVertex(const vtkVariant& pedigreeID);
532 
537  void ShallowCopy(vtkDataObject* obj) override;
538 
543  void DeepCopy(vtkDataObject* obj) override;
544 
549  virtual void CopyStructure(vtkGraph* g);
550 
556  virtual bool CheckedShallowCopy(vtkGraph* g);
557 
563  virtual bool CheckedDeepCopy(vtkGraph* g);
564 
568  virtual void Squeeze();
569 
577  unsigned long GetActualMemorySize() override;
578 
580 
584  static vtkGraph* GetData(vtkInformationVector* v, int i = 0);
586 
595 
600  bool IsSameStructure(vtkGraph* other);
601 
603 
615 
617 
622  void SetEdgePoints(vtkIdType e, vtkIdType npts, const double pts[]) VTK_SIZEHINT(pts, 3 * npts);
623  void GetEdgePoints(vtkIdType e, vtkIdType& npts, double*& pts) VTK_SIZEHINT(pts, 3 * npts);
625 
630 
635 
640 
646  void SetEdgePoint(vtkIdType e, vtkIdType i, const double x[3]);
647  void SetEdgePoint(vtkIdType e, vtkIdType i, double x, double y, double z)
648  {
649  double p[3] = { x, y, z };
650  this->SetEdgePoint(e, i, p);
651  }
652 
656  void AddEdgePoint(vtkIdType e, const double x[3]);
657  void AddEdgePoint(vtkIdType e, double x, double y, double z)
658  {
659  double p[3] = { x, y, z };
660  this->AddEdgePoint(e, p);
661  }
662 
664 
671 
678 
684 
692 
697 
701  void Dump();
702 
712 
717 
722 
723 protected:
725  ~vtkGraph() override;
726 
734  void AddVertexInternal(vtkVariantArray* propertyArr = nullptr, vtkIdType* vertex = nullptr);
735 
742  void AddVertexInternal(const vtkVariant& pedigree, vtkIdType* vertex);
743 
745 
752  vtkIdType u, vtkIdType v, bool directed, vtkVariantArray* propertyArr, vtkEdgeType* edge);
753  void AddEdgeInternal(const vtkVariant& uPedigree, vtkIdType v, bool directed,
754  vtkVariantArray* propertyArr, vtkEdgeType* edge);
755  void AddEdgeInternal(vtkIdType u, const vtkVariant& vPedigree, bool directed,
756  vtkVariantArray* propertyArr, vtkEdgeType* edge);
757  void AddEdgeInternal(const vtkVariant& uPedigree, const vtkVariant& vPedigree, bool directed,
758  vtkVariantArray* propertyArr, vtkEdgeType* edge);
760 
765  void RemoveVertexInternal(vtkIdType v, bool directed);
766 
771  void RemoveEdgeInternal(vtkIdType e, bool directed);
772 
776  void RemoveVerticesInternal(vtkIdTypeArray* arr, bool directed);
777 
781  void RemoveEdgesInternal(vtkIdTypeArray* arr, bool directed);
782 
787  virtual bool IsStructureValid(vtkGraph* g) = 0;
788 
792  virtual void CopyInternal(vtkGraph* g, bool deep);
793 
798 
803 
807  void SetInternals(vtkGraphInternals* internals);
808 
812  vtkGraphEdgePoints* EdgePoints;
813 
817  void SetEdgePoints(vtkGraphEdgePoints* edgePoints);
818 
824 
826 
829  virtual void GetOutEdges(vtkIdType v, const vtkOutEdgeType*& edges, vtkIdType& nedges);
830  virtual void GetInEdges(vtkIdType v, const vtkInEdgeType*& edges, vtkIdType& nedges);
832 
837 
839 
843  friend class vtkEdgeListIterator;
844  friend class vtkInEdgeIterator;
845  friend class vtkOutEdgeIterator;
850 
852 
858 
862  double Bounds[6];
863 
868 
870 
874  static double DefaultPoint[3];
876 
878 
881  vtkGetObjectMacro(EdgeList, vtkIdTypeArray);
882  virtual void SetEdgeList(vtkIdTypeArray* list);
885 
886 private:
887  vtkGraph(const vtkGraph&) = delete;
888  void operator=(const vtkGraph&) = delete;
889 };
890 
891 bool VTKCOMMONDATAMODEL_EXPORT operator==(vtkEdgeBase e1, vtkEdgeBase e2);
892 bool VTKCOMMONDATAMODEL_EXPORT operator!=(vtkEdgeBase e1, vtkEdgeBase e2);
893 VTKCOMMONDATAMODEL_EXPORT ostream& operator<<(ostream& out, vtkEdgeBase e);
894 
895 #endif
Iterates through adjacent vertices in a graph.
object to represent cell connectivity
Definition: vtkCellArray.h:296
general representation of visualization data
represent and manipulate attribute data in a dataset
A directed graph.
helper for the vtkGraph class that allows the graph to be distributed across multiple memory spaces.
Iterates through all edges in a graph.
represent and manipulate fields of data
Definition: vtkFieldData.h:172
Representation of a single graph edge.
Definition: vtkGraphEdge.h:40
Internal representation of vtkGraph.
Base class for graph data types.
Definition: vtkGraph.h:345
virtual vtkIdType GetOutDegree(vtkIdType v)
The number of outgoing edges from vertex v.
void SetEdgePoint(vtkIdType e, vtkIdType i, const double x[3])
Set an x,y,z location of a point along an edge.
vtkDistributedGraphHelper * GetDistributedGraphHelper()
Retrieves the distributed graph helper for this graph.
void SetEdgePoint(vtkIdType e, vtkIdType i, double x, double y, double z)
Definition: vtkGraph.h:647
void AddEdgePoint(vtkIdType e, double x, double y, double z)
Definition: vtkGraph.h:657
void ComputeBounds()
Compute the bounds of the graph.
void AddEdgePoint(vtkIdType e, const double x[3])
Adds a point to the end of the list of edge points for a certain edge.
virtual vtkIdType GetNumberOfVertices()
The number of vertices in the graph.
void BuildEdgeList()
Builds a mapping from edge id to source/target vertex id.
vtkTimeStamp ComputeTime
Time at which bounds were computed.
Definition: vtkGraph.h:867
virtual void GetInEdge(vtkIdType v, vtkIdType index, vtkGraphEdge *e)
Random-access method for retrieving incoming edges to vertex v.
void AddVertexInternal(vtkVariantArray *propertyArr=nullptr, vtkIdType *vertex=nullptr)
Protected method for adding vertices, optionally with properties, used by mutable subclasses.
void AddEdgeInternal(vtkIdType u, const vtkVariant &vPedigree, bool directed, vtkVariantArray *propertyArr, vtkEdgeType *edge)
Protected method for adding edges of a certain directedness used by mutable subclasses.
void AddVertexInternal(const vtkVariant &pedigree, vtkIdType *vertex)
Adds a vertex with the given pedigree ID to the graph.
void ForceOwnership()
If this instance does not own its internals, it makes a copy of the internals.
void SetDistributedGraphHelper(vtkDistributedGraphHelper *helper)
Sets the distributed graph helper of this graph, turning it into a distributed graph.
vtkIdType GetNumberOfEdgePoints(vtkIdType e)
Get the number of edge points associated with an edge.
~vtkGraph() override
virtual bool CheckedDeepCopy(vtkGraph *g)
Performs the same operation as DeepCopy(), but instead of reporting an error for an incompatible grap...
void RemoveVertexInternal(vtkIdType v, bool directed)
Removes a vertex from the graph, along with any adjacent edges.
void Initialize() override
Initialize to an empty graph.
vtkDataSetAttributes * VertexData
The vertex and edge data.
Definition: vtkGraph.h:855
virtual void GetAdjacentVertices(vtkIdType v, vtkAdjacentVertexIterator *it)
Initializes the adjacent vertex iterator to iterate over all outgoing vertices from vertex v.
void RemoveEdgesInternal(vtkIdTypeArray *arr, bool directed)
Removes a collection of edges from the graph.
virtual vtkInEdgeType GetInEdge(vtkIdType v, vtkIdType index)
Random-access method for retrieving incoming edges to vertex v.
vtkIdType FindVertex(const vtkVariant &pedigreeID)
Retrieve the vertex with the given pedigree ID.
void GetInducedEdges(vtkIdTypeArray *verts, vtkIdTypeArray *edges)
Fills a list of edge indices with the edges contained in the induced subgraph formed by the vertices ...
virtual void SetEdgeList(vtkIdTypeArray *list)
The optional mapping from edge id to source/target ids.
void SetEdgePoints(vtkIdType e, vtkIdType npts, const double pts[])
Get/Set the internal edge control points associated with each edge.
vtkIdTypeArray * EdgeList
The optional mapping from edge id to source/target ids.
Definition: vtkGraph.h:883
vtkGraphEdgePoints * EdgePoints
The structure for holding the edge points.
Definition: vtkGraph.h:812
vtkIdType GetTargetVertex(vtkIdType e)
Retrieve the source and target vertices for an edge id.
void RemoveEdgeInternal(vtkIdType e, bool directed)
Removes an edge from the graph.
bool IsSameStructure(vtkGraph *other)
Returns true if both graphs point to the same adjacency structure.
vtkMTimeType GetMTime() override
The modified time of the graph.
void RemoveVerticesInternal(vtkIdTypeArray *arr, bool directed)
Removes a collection of vertices from the graph, along with any adjacent edges.
bool ToUndirectedGraph(vtkUndirectedGraph *g)
Convert the graph to an undirected graph.
void AddEdgeInternal(const vtkVariant &uPedigree, const vtkVariant &vPedigree, bool directed, vtkVariantArray *propertyArr, vtkEdgeType *edge)
Protected method for adding edges of a certain directedness used by mutable subclasses.
double * GetBounds()
Return a pointer to the geometry bounding box in the form (xmin,xmax, ymin,ymax, zmin,...
void AddEdgeInternal(const vtkVariant &uPedigree, vtkIdType v, bool directed, vtkVariantArray *propertyArr, vtkEdgeType *edge)
Protected method for adding edges of a certain directedness used by mutable subclasses.
static vtkGraph * GetData(vtkInformation *info)
Retrieve a graph from an information vector.
virtual void CopyStructure(vtkGraph *g)
Does a shallow copy of the topological information, but not the associated attributes.
virtual void CopyInternal(vtkGraph *g, bool deep)
Copy internal data structure.
vtkPoints * GetPoints()
Returns the points array for this graph.
void GetBounds(double bounds[6])
Return a pointer to the geometry bounding box in the form (xmin,xmax, ymin,ymax, zmin,...
vtkIdType GetEdgeId(vtkIdType a, vtkIdType b)
Returns the Id of the edge between vertex a and vertex b.
vtkPoints * Points
The vertex locations.
Definition: vtkGraph.h:873
virtual bool CheckedShallowCopy(vtkGraph *g)
Performs the same operation as ShallowCopy(), but instead of reporting an error for an incompatible g...
vtkGraphInternals * GetGraphInternals(bool modifying)
Returns the internal representation of the graph.
void ShallowCopy(vtkDataObject *obj) override
Shallow copies the data object into this graph.
virtual void SetPoints(vtkPoints *points)
Returns the points array for this graph.
double * GetEdgePoint(vtkIdType e, vtkIdType i)
Get the x,y,z location of a point along edge e.
bool ToDirectedGraph(vtkDirectedGraph *g)
Convert the graph to a directed graph.
virtual void Squeeze()
Reclaim unused memory.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual void GetInEdges(vtkIdType v, vtkInEdgeIterator *it)
Initializes the in edge iterator to iterate over all incoming edges to vertex v.
vtkIdType GetSourceVertex(vtkIdType e)
Retrieve the source and target vertices for an edge id.
void DeepCopyEdgePoints(vtkGraph *g)
Copy the internal edge point data from another graph into this graph.
vtkDistributedGraphHelper * DistributedHelper
The distributed graph helper.
Definition: vtkGraph.h:802
virtual void GetOutEdges(vtkIdType v, vtkOutEdgeIterator *it)
Initializes the out edge iterator to iterate over all outgoing edges of vertex v.
virtual void GetInEdges(vtkIdType v, const vtkInEdgeType *&edges, vtkIdType &nedges)
Fast access functions for iterators.
void DeepCopy(vtkDataObject *obj) override
Deep copies the data object into this graph.
virtual void GetOutEdge(vtkIdType v, vtkIdType index, vtkGraphEdge *e)
Random-access method for retrieving outgoing edges from vertex v.
void ClearEdgePoints(vtkIdType e)
Clear all points associated with an edge.
double * GetPoint(vtkIdType ptId)
These methods return the point (0,0,0) until the points structure is created, when it returns the act...
int GetDataObjectType() override
Return what type of dataset this is.
Definition: vtkGraph.h:361
void AddEdgeInternal(vtkIdType u, vtkIdType v, bool directed, vtkVariantArray *propertyArr, vtkEdgeType *edge)
Protected method for adding edges of a certain directedness used by mutable subclasses.
void SetInternals(vtkGraphInternals *internals)
Private method for setting internals.
virtual void GetOutEdges(vtkIdType v, const vtkOutEdgeType *&edges, vtkIdType &nedges)
Fast access functions for iterators.
vtkGraphInternals * Internals
The adjacency list internals of this graph.
Definition: vtkGraph.h:797
virtual void GetEdges(vtkEdgeListIterator *it)
Initializes the edge list iterator to iterate over all edges in the graph.
unsigned long GetActualMemorySize() override
Return the actual size of the data in kibibytes (1024 bytes).
virtual vtkIdType GetNumberOfEdges()
The number of edges in the graph.
void ShallowCopyEdgePoints(vtkGraph *g)
Copy the internal edge point data from another graph into this graph.
void SetEdgePoints(vtkGraphEdgePoints *edgePoints)
Private method for setting edge points.
void Dump()
Dump the contents of the graph to standard output.
virtual vtkIdType GetInDegree(vtkIdType v)
The number of incoming edges to vertex v.
void GetEdgePoints(vtkIdType e, vtkIdType &npts, double *&pts)
Get/Set the internal edge control points associated with each edge.
static vtkGraph * GetData(vtkInformationVector *v, int i=0)
Retrieve a graph from an information vector.
vtkDataSetAttributes * EdgeData
The vertex and edge data.
Definition: vtkGraph.h:856
vtkFieldData * GetAttributesAsFieldData(int type) override
Returns the attributes of the data object as a vtkFieldData.
virtual vtkOutEdgeType GetOutEdge(vtkIdType v, vtkIdType index)
Random-access method for retrieving outgoing edges from vertex v.
void GetPoint(vtkIdType ptId, double x[3])
These methods return the point (0,0,0) until the points structure is created, when it returns the act...
void ReorderOutVertices(vtkIdType v, vtkIdTypeArray *vertices)
Reorder the outgoing vertices of a vertex.
vtkIdType GetNumberOfElements(int type) override
Get the number of elements for a specific attribute type (VERTEX, EDGE, etc.).
virtual void GetVertices(vtkVertexListIterator *it)
Initializes the vertex list iterator to iterate over all vertices in the graph.
virtual vtkIdType GetDegree(vtkIdType v)
The total of all incoming and outgoing vertices for vertex v.
virtual bool IsStructureValid(vtkGraph *g)=0
Subclasses override this method to accept the structure based on their requirements.
dynamic, self-adjusting array of vtkIdType
Iterates through all incoming edges to a vertex.
a simple class to control print indentation
Definition: vtkIndent.h:119
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
Iterates through all outgoing edges from a vertex.
represent and manipulate 3D points
Definition: vtkPoints.h:149
record modification and/or execution time
Definition: vtkTimeStamp.h:55
An undirected graph.
An array holding vtkVariants.
A atomic type representing the union of many types.
Definition: vtkVariant.h:159
Iterates all vertices in a graph.
Forward declaration required for Boost serialization.
@ points
Definition: vtkX3D.h:452
@ info
Definition: vtkX3D.h:382
@ type
Definition: vtkX3D.h:522
@ index
Definition: vtkX3D.h:252
vtkEdgeBase()=default
vtkIdType Id
Definition: vtkGraph.h:306
vtkEdgeBase(vtkIdType id)
Definition: vtkGraph.h:302
vtkEdgeType(vtkIdType s, vtkIdType t, vtkIdType id)
Definition: vtkGraph.h:334
vtkIdType Target
Definition: vtkGraph.h:341
vtkEdgeType()=default
vtkIdType Source
Definition: vtkGraph.h:340
vtkIdType Source
Definition: vtkGraph.h:328
vtkInEdgeType(vtkIdType s, vtkIdType id)
Definition: vtkGraph.h:323
vtkInEdgeType()=default
vtkIdType Target
Definition: vtkGraph.h:317
vtkOutEdgeType(vtkIdType t, vtkIdType id)
Definition: vtkGraph.h:312
vtkOutEdgeType()=default
std::pair< boost::graph_traits< vtkGraph * >::edge_iterator, boost::graph_traits< vtkGraph * >::edge_iterator > edges(vtkGraph *g)
std::pair< boost::graph_traits< vtkGraph * >::vertex_iterator, boost::graph_traits< vtkGraph * >::vertex_iterator > vertices(vtkGraph *g)
bool VTKCOMMONDATAMODEL_EXPORT operator==(vtkEdgeBase e1, vtkEdgeBase e2)
bool VTKCOMMONDATAMODEL_EXPORT operator!=(vtkEdgeBase e1, vtkEdgeBase e2)
VTKCOMMONDATAMODEL_EXPORT ostream & operator<<(ostream &out, vtkEdgeBase e)
int vtkIdType
Definition: vtkType.h:332
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:287
#define VTK_GRAPH
Definition: vtkType.h:97
#define VTK_SIZEHINT(...)