VTK  9.5.20250806
vtkGraph.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-FileCopyrightText: Copyright 2008 Sandia Corporation
3// SPDX-License-Identifier: LicenseRef-BSD-3-Clause-Sandia-USGov
259#ifndef vtkGraph_h
260#define vtkGraph_h
261
262#include "vtkCommonDataModelModule.h" // For export macro
263#include "vtkDataObject.h"
264#include "vtkNew.h" // For vtkNew
265#include "vtkWrappingHints.h" // For VTK_MARSHALMANUAL
266
267// Forward declare some boost stuff even if boost wrappers
268// are turned off.
269namespace boost
270{
271class vtk_edge_iterator;
272class vtk_out_edge_pointer_iterator;
273class vtk_in_edge_pointer_iterator;
274}
275
276VTK_ABI_NAMESPACE_BEGIN
278class vtkCellArray;
281class vtkDirectedGraph;
282class vtkGraphEdge;
283class vtkGraphEdgePoints;
286class vtkIdTypeArray;
289class vtkPoints;
292class vtkVariant;
293class vtkVariantArray;
294
295// Edge structures.
297{
298 vtkEdgeBase() = default;
300 : Id(id)
301 {
302 }
304};
305
307{
308 vtkOutEdgeType() = default;
310 : vtkEdgeBase(id)
311 , Target(t)
312 {
313 }
315};
316
318{
319 vtkInEdgeType() = default;
321 : vtkEdgeBase(id)
322 , Source(s)
323 {
324 }
326};
327
329{
330 vtkEdgeType() = default;
332 : vtkEdgeBase(id)
333 , Source(s)
334 , Target(t)
335 {
336 }
339};
340
341class VTKCOMMONDATAMODEL_EXPORT VTK_MARSHALMANUAL vtkGraph : public vtkDataObject
342{
343public:
344 vtkTypeMacro(vtkGraph, vtkDataObject);
345 void PrintSelf(ostream& os, vtkIndent indent) override;
346
348
351 vtkGetObjectMacro(VertexData, vtkDataSetAttributes);
352 vtkGetObjectMacro(EdgeData, vtkDataSetAttributes);
354
358 int GetDataObjectType() VTK_FUTURE_CONST override { return VTK_GRAPH; }
359
363 void Initialize() override;
364
366
372 double* GetPoint(vtkIdType ptId);
373 void GetPoint(vtkIdType ptId, double x[3]);
375
377
385 virtual void SetPoints(vtkPoints* points);
387
393
395
400 double* GetBounds();
401 void GetBounds(double bounds[6]);
403
408
416
424
431
436
443 virtual void GetOutEdge(vtkIdType v, vtkIdType index, vtkGraphEdge* e);
444
452
459
464
471 virtual void GetInEdge(vtkIdType v, vtkIdType index, vtkGraphEdge* e);
472
480
487 virtual void GetEdges(vtkEdgeListIterator* it);
488
494
501
507
514
519
528 vtkIdType FindVertex(const vtkVariant& pedigreeID);
529
534 void ShallowCopy(vtkDataObject* obj) override;
535
540 void DeepCopy(vtkDataObject* obj) override;
541
546 virtual void CopyStructure(vtkGraph* g);
547
553 virtual bool CheckedShallowCopy(vtkGraph* g);
554
560 virtual bool CheckedDeepCopy(vtkGraph* g);
561
565 virtual void Squeeze();
566
574 unsigned long GetActualMemorySize() override;
575
577
581 static vtkGraph* GetData(vtkInformationVector* v, int i = 0);
583
592
598
600
612
614
619 void SetEdgePoints(vtkIdType e, vtkIdType npts, const double pts[]) VTK_SIZEHINT(pts, 3 * npts);
620 void GetEdgePoints(vtkIdType e, vtkIdType& npts, double*& pts) VTK_SIZEHINT(pts, 3 * npts);
622
627
632
637
643 void SetEdgePoint(vtkIdType e, vtkIdType i, const double x[3]);
644 void SetEdgePoint(vtkIdType e, vtkIdType i, double x, double y, double z)
645 {
646 double p[3] = { x, y, z };
647 this->SetEdgePoint(e, i, p);
648 }
649
653 void AddEdgePoint(vtkIdType e, const double x[3]);
654 void AddEdgePoint(vtkIdType e, double x, double y, double z)
655 {
656 double p[3] = { x, y, z };
657 this->AddEdgePoint(e, p);
658 }
659
661
668
675
681
689
693 vtkIdType GetNumberOfElements(int type) override;
694
698 void Dump();
699
709
714
719
720protected:
722 ~vtkGraph() override;
723
731 void AddVertexInternal(vtkVariantArray* propertyArr = nullptr, vtkIdType* vertex = nullptr);
732
739 void AddVertexInternal(const vtkVariant& pedigree, vtkIdType* vertex);
740
742
749 vtkIdType u, vtkIdType v, bool directed, vtkVariantArray* propertyArr, vtkEdgeType* edge);
750 void AddEdgeInternal(const vtkVariant& uPedigree, vtkIdType v, bool directed,
751 vtkVariantArray* propertyArr, vtkEdgeType* edge);
752 void AddEdgeInternal(vtkIdType u, const vtkVariant& vPedigree, bool directed,
753 vtkVariantArray* propertyArr, vtkEdgeType* edge);
754 void AddEdgeInternal(const vtkVariant& uPedigree, const vtkVariant& vPedigree, bool directed,
755 vtkVariantArray* propertyArr, vtkEdgeType* edge);
757
762 void RemoveVertexInternal(vtkIdType v, bool directed);
763
768 void RemoveEdgeInternal(vtkIdType e, bool directed);
769
773 void RemoveVerticesInternal(vtkIdTypeArray* arr, bool directed);
774
778 void RemoveEdgesInternal(vtkIdTypeArray* arr, bool directed);
779
784 virtual bool IsStructureValid(vtkGraph* g) = 0;
785
789 virtual void CopyInternal(vtkGraph* g, bool deep);
790
795
800
805
809 vtkGraphEdgePoints* EdgePoints;
810
814 void SetEdgePoints(vtkGraphEdgePoints* edgePoints);
815
821
823
826 virtual void GetOutEdges(vtkIdType v, const vtkOutEdgeType*& edges, vtkIdType& nedges);
827 virtual void GetInEdges(vtkIdType v, const vtkInEdgeType*& edges, vtkIdType& nedges);
829
834
836
841 friend class vtkInEdgeIterator;
842 friend class vtkOutEdgeIterator;
847
849
855
859 double Bounds[6];
860
865
867
871 static double DefaultPoint[3];
873
875
878 vtkGetObjectMacro(EdgeList, vtkIdTypeArray);
879 virtual void SetEdgeList(vtkIdTypeArray* list);
882
883private:
884 vtkGraph(const vtkGraph&) = delete;
885 void operator=(const vtkGraph&) = delete;
886};
887
888bool VTKCOMMONDATAMODEL_EXPORT operator==(vtkEdgeBase e1, vtkEdgeBase e2);
889bool VTKCOMMONDATAMODEL_EXPORT operator!=(vtkEdgeBase e1, vtkEdgeBase e2);
890VTKCOMMONDATAMODEL_EXPORT ostream& operator<<(ostream& out, vtkEdgeBase e);
891
892VTK_ABI_NAMESPACE_END
893#endif
Iterates through adjacent vertices in a graph.
object to represent cell connectivity
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.
Represents and manipulates a collection of data arrays.
Representation of a single graph edge.
Internal representation of vtkGraph.
Base class for graph data types.
Definition vtkGraph.h:342
static vtkGraph * GetData(vtkInformationVector *v, int i=0)
Retrieve a graph from an information vector.
double * GetBounds()
Return a pointer to the geometry bounding box in the form (xmin,xmax, ymin,ymax, zmin,...
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.
void SetEdgePoint(vtkIdType e, vtkIdType i, double x, double y, double z)
Definition vtkGraph.h:644
void AddEdgePoint(vtkIdType e, double x, double y, double z)
Definition vtkGraph.h:654
vtkPoints * GetPoints()
Returns the points array for this graph.
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.
static vtkGraph * GetData(vtkInformation *info)
Retrieve a graph from an information vector.
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:864
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.
double * GetPoint(vtkIdType ptId)
These methods return the point (0,0,0) until the points structure is created, when it returns the act...
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.
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.
double * GetEdgePoint(vtkIdType e, vtkIdType i)
Get the x,y,z location of a point along edge e.
vtkIdType FindVertex(const vtkVariant &pedigreeID)
Retrieve the vertex with the given pedigree ID.
vtkNew< vtkDataSetAttributes > VertexData
The vertex and edge data.
Definition vtkGraph.h:852
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:880
vtkGraphEdgePoints * EdgePoints
The structure for holding the edge points.
Definition vtkGraph.h:809
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.
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.
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.
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:870
int GetDataObjectType() VTK_FUTURE_CONST override
Return what type of dataset this is.
Definition vtkGraph.h:358
virtual bool CheckedShallowCopy(vtkGraph *g)
Performs the same operation as ShallowCopy(), but instead of reporting an error for an incompatible g...
void ShallowCopy(vtkDataObject *obj) override
Shallow copies the data object into this graph.
vtkNew< vtkDataSetAttributes > EdgeData
The vertex and edge data.
Definition vtkGraph.h:853
virtual void SetPoints(vtkPoints *points)
Returns the points array for this graph.
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:799
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.
vtkFieldData * GetAttributesAsFieldData(int type) override
Returns the attributes of the data object as a vtkFieldData.
virtual void GetOutEdge(vtkIdType v, vtkIdType index, vtkGraphEdge *e)
Random-access method for retrieving outgoing edges from vertex v.
vtkDistributedGraphHelper * GetDistributedGraphHelper()
Retrieves the distributed graph helper for this graph.
void ClearEdgePoints(vtkIdType e)
Clear all points associated with an edge.
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:794
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.
vtkGraphInternals * GetGraphInternals(bool modifying)
Returns the internal representation of 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.
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:108
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
Allocate and hold a VTK object.
Definition vtkNew.h:167
Iterates through all outgoing edges from a vertex.
represent and manipulate 3D points
Definition vtkPoints.h:139
record modification and/or execution time
An undirected graph.
An array holding vtkVariants.
A type representing the union of many types.
Definition vtkVariant.h:162
Iterates all vertices in a graph.
Forward declaration required for Boost serialization.
vtkEdgeBase()=default
vtkIdType Id
Definition vtkGraph.h:303
vtkEdgeBase(vtkIdType id)
Definition vtkGraph.h:299
vtkEdgeType(vtkIdType s, vtkIdType t, vtkIdType id)
Definition vtkGraph.h:331
vtkIdType Target
Definition vtkGraph.h:338
vtkEdgeType()=default
vtkIdType Source
Definition vtkGraph.h:337
vtkIdType Source
Definition vtkGraph.h:325
vtkInEdgeType(vtkIdType s, vtkIdType id)
Definition vtkGraph.h:320
vtkInEdgeType()=default
vtkIdType Target
Definition vtkGraph.h:314
vtkOutEdgeType(vtkIdType t, vtkIdType id)
Definition vtkGraph.h:309
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)
VTKCOMMONDATAMODEL_EXPORT ostream & operator<<(ostream &out, vtkEdgeBase e)
bool VTKCOMMONDATAMODEL_EXPORT operator!=(vtkEdgeBase e1, vtkEdgeBase e2)
int vtkIdType
Definition vtkType.h:332
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:287
@ VTK_GRAPH
Definition vtkType.h:100
#define VTK_SIZEHINT(...)
#define VTK_MARSHALMANUAL