VTK  9.3.1
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
200 #ifndef vtkGraph_h
201 #define vtkGraph_h
202 
203 #include "vtkCommonDataModelModule.h" // For export macro
204 #include "vtkDataObject.h"
205 
206 // Forward declare some boost stuff even if boost wrappers
207 // are turned off.
208 namespace boost
209 {
210 class vtk_edge_iterator;
211 class vtk_out_edge_pointer_iterator;
212 class vtk_in_edge_pointer_iterator;
213 }
214 
215 VTK_ABI_NAMESPACE_BEGIN
217 class vtkCellArray;
218 class vtkEdgeListIterator;
220 class vtkDirectedGraph;
221 class vtkGraphEdge;
222 class vtkGraphEdgePoints;
224 class vtkGraphInternals;
225 class vtkIdTypeArray;
226 class vtkInEdgeIterator;
227 class vtkOutEdgeIterator;
228 class vtkPoints;
229 class vtkUndirectedGraph;
231 class vtkVariant;
232 class vtkVariantArray;
233 
234 // Edge structures.
236 {
237  vtkEdgeBase() = default;
239  : Id(id)
240  {
241  }
243 };
244 
246 {
247  vtkOutEdgeType() = default;
249  : vtkEdgeBase(id)
250  , Target(t)
251  {
252  }
254 };
255 
257 {
258  vtkInEdgeType() = default;
260  : vtkEdgeBase(id)
261  , Source(s)
262  {
263  }
265 };
266 
268 {
269  vtkEdgeType() = default;
271  : vtkEdgeBase(id)
272  , Source(s)
273  , Target(t)
274  {
275  }
278 };
279 
280 class VTKCOMMONDATAMODEL_EXPORT vtkGraph : public vtkDataObject
281 {
282 public:
283  vtkTypeMacro(vtkGraph, vtkDataObject);
284  void PrintSelf(ostream& os, vtkIndent indent) override;
285 
287 
290  vtkGetObjectMacro(VertexData, vtkDataSetAttributes);
291  vtkGetObjectMacro(EdgeData, vtkDataSetAttributes);
293 
297  int GetDataObjectType() override { return VTK_GRAPH; }
298 
302  void Initialize() override;
303 
305 
311  double* GetPoint(vtkIdType ptId);
312  void GetPoint(vtkIdType ptId, double x[3]);
314 
316 
323  vtkPoints* GetPoints();
324  virtual void SetPoints(vtkPoints* points);
326 
331  void ComputeBounds();
332 
334 
339  double* GetBounds();
340  void GetBounds(double bounds[6]);
342 
346  vtkMTimeType GetMTime() override;
347 
354  virtual void GetOutEdges(vtkIdType v, vtkOutEdgeIterator* it);
355 
362  virtual vtkIdType GetDegree(vtkIdType v);
363 
369  virtual vtkIdType GetOutDegree(vtkIdType v);
370 
374  virtual vtkOutEdgeType GetOutEdge(vtkIdType v, vtkIdType index);
375 
382  virtual void GetOutEdge(vtkIdType v, vtkIdType index, vtkGraphEdge* e);
383 
390  virtual void GetInEdges(vtkIdType v, vtkInEdgeIterator* it);
391 
397  virtual vtkIdType GetInDegree(vtkIdType v);
398 
402  virtual vtkInEdgeType GetInEdge(vtkIdType v, vtkIdType index);
403 
410  virtual void GetInEdge(vtkIdType v, vtkIdType index, vtkGraphEdge* e);
411 
418  virtual void GetAdjacentVertices(vtkIdType v, vtkAdjacentVertexIterator* it);
419 
426  virtual void GetEdges(vtkEdgeListIterator* it);
427 
432  virtual vtkIdType GetNumberOfEdges();
433 
439  virtual void GetVertices(vtkVertexListIterator* it);
440 
445  virtual vtkIdType GetNumberOfVertices();
446 
452  void SetDistributedGraphHelper(vtkDistributedGraphHelper* helper);
453 
457  vtkDistributedGraphHelper* GetDistributedGraphHelper();
458 
467  vtkIdType FindVertex(const vtkVariant& pedigreeID);
468 
473  void ShallowCopy(vtkDataObject* obj) override;
474 
479  void DeepCopy(vtkDataObject* obj) override;
480 
485  virtual void CopyStructure(vtkGraph* g);
486 
492  virtual bool CheckedShallowCopy(vtkGraph* g);
493 
499  virtual bool CheckedDeepCopy(vtkGraph* g);
500 
504  virtual void Squeeze();
505 
513  unsigned long GetActualMemorySize() override;
514 
516 
520  static vtkGraph* GetData(vtkInformationVector* v, int i = 0);
522 
530  void ReorderOutVertices(vtkIdType v, vtkIdTypeArray* vertices);
531 
536  bool IsSameStructure(vtkGraph* other);
537 
539 
548  vtkIdType GetSourceVertex(vtkIdType e);
549  vtkIdType GetTargetVertex(vtkIdType e);
551 
553 
558  void SetEdgePoints(vtkIdType e, vtkIdType npts, const double pts[]) VTK_SIZEHINT(pts, 3 * npts);
559  void GetEdgePoints(vtkIdType e, vtkIdType& npts, double*& pts) VTK_SIZEHINT(pts, 3 * npts);
561 
565  vtkIdType GetNumberOfEdgePoints(vtkIdType e);
566 
570  double* GetEdgePoint(vtkIdType e, vtkIdType i) VTK_SIZEHINT(3);
571 
575  void ClearEdgePoints(vtkIdType e);
576 
582  void SetEdgePoint(vtkIdType e, vtkIdType i, const double x[3]);
583  void SetEdgePoint(vtkIdType e, vtkIdType i, double x, double y, double z)
584  {
585  double p[3] = { x, y, z };
586  this->SetEdgePoint(e, i, p);
587  }
588 
592  void AddEdgePoint(vtkIdType e, const double x[3]);
593  void AddEdgePoint(vtkIdType e, double x, double y, double z)
594  {
595  double p[3] = { x, y, z };
596  this->AddEdgePoint(e, p);
597  }
598 
600 
604  void ShallowCopyEdgePoints(vtkGraph* g);
605  void DeepCopyEdgePoints(vtkGraph* g);
607 
613  vtkGraphInternals* GetGraphInternals(bool modifying);
614 
619  void GetInducedEdges(vtkIdTypeArray* verts, vtkIdTypeArray* edges);
620 
628 
632  vtkIdType GetNumberOfElements(int type) override;
633 
637  void Dump();
638 
647  vtkIdType GetEdgeId(vtkIdType a, vtkIdType b);
648 
652  bool ToDirectedGraph(vtkDirectedGraph* g);
653 
657  bool ToUndirectedGraph(vtkUndirectedGraph* g);
658 
659 protected:
660  vtkGraph();
661  ~vtkGraph() override;
662 
670  void AddVertexInternal(vtkVariantArray* propertyArr = nullptr, vtkIdType* vertex = nullptr);
671 
678  void AddVertexInternal(const vtkVariant& pedigree, vtkIdType* vertex);
679 
681 
687  void AddEdgeInternal(
688  vtkIdType u, vtkIdType v, bool directed, vtkVariantArray* propertyArr, vtkEdgeType* edge);
689  void AddEdgeInternal(const vtkVariant& uPedigree, vtkIdType v, bool directed,
690  vtkVariantArray* propertyArr, vtkEdgeType* edge);
691  void AddEdgeInternal(vtkIdType u, const vtkVariant& vPedigree, bool directed,
692  vtkVariantArray* propertyArr, vtkEdgeType* edge);
693  void AddEdgeInternal(const vtkVariant& uPedigree, const vtkVariant& vPedigree, bool directed,
694  vtkVariantArray* propertyArr, vtkEdgeType* edge);
696 
701  void RemoveVertexInternal(vtkIdType v, bool directed);
702 
707  void RemoveEdgeInternal(vtkIdType e, bool directed);
708 
712  void RemoveVerticesInternal(vtkIdTypeArray* arr, bool directed);
713 
717  void RemoveEdgesInternal(vtkIdTypeArray* arr, bool directed);
718 
723  virtual bool IsStructureValid(vtkGraph* g) = 0;
724 
728  virtual void CopyInternal(vtkGraph* g, bool deep);
729 
734 
739 
743  void SetInternals(vtkGraphInternals* internals);
744 
748  vtkGraphEdgePoints* EdgePoints;
749 
753  void SetEdgePoints(vtkGraphEdgePoints* edgePoints);
754 
759  void ForceOwnership();
760 
762 
765  virtual void GetOutEdges(vtkIdType v, const vtkOutEdgeType*& edges, vtkIdType& nedges);
766  virtual void GetInEdges(vtkIdType v, const vtkInEdgeType*& edges, vtkIdType& nedges);
768 
772  void BuildEdgeList();
773 
775 
779  friend class vtkEdgeListIterator;
780  friend class vtkInEdgeIterator;
781  friend class vtkOutEdgeIterator;
786 
788 
794 
798  double Bounds[6];
799 
804 
806 
810  static double DefaultPoint[3];
812 
814 
817  vtkGetObjectMacro(EdgeList, vtkIdTypeArray);
818  virtual void SetEdgeList(vtkIdTypeArray* list);
821 
822 private:
823  vtkGraph(const vtkGraph&) = delete;
824  void operator=(const vtkGraph&) = delete;
825 };
826 
827 bool VTKCOMMONDATAMODEL_EXPORT operator==(vtkEdgeBase e1, vtkEdgeBase e2);
828 bool VTKCOMMONDATAMODEL_EXPORT operator!=(vtkEdgeBase e1, vtkEdgeBase e2);
829 VTKCOMMONDATAMODEL_EXPORT ostream& operator<<(ostream& out, vtkEdgeBase e);
830 
831 VTK_ABI_NAMESPACE_END
832 #endif
helper for the vtkGraph class that allows the graph to be distributed across multiple memory spaces...
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static vtkDataObject * GetData(vtkInformation *info)
Retrieve an instance of this class from an information object.
vtkDataSetAttributes * VertexData
The vertex and edge data.
Definition: vtkGraph.h:791
vtkDataSetAttributes * EdgeData
The vertex and edge data.
Definition: vtkGraph.h:792
void GetBounds(T a, double bds[6])
virtual vtkFieldData * GetAttributesAsFieldData(int type)
Returns the attributes of the data object as a vtkFieldData.
vtkInEdgeType()=default
Forward declaration required for Boost serialization.
An array holding vtkVariants.
vtkIdTypeArray * EdgeList
The optional mapping from edge id to source/target ids.
Definition: vtkGraph.h:819
Store vtkAlgorithm input/output information.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:270
Iterates through adjacent vertices in a graph.
bool VTKCOMMONDATAMODEL_EXPORT operator!=(vtkEdgeBase e1, vtkEdgeBase e2)
record modification and/or execution time
Definition: vtkTimeStamp.h:24
Iterates through all edges in a graph.
An undirected graph.
Representation of a single graph edge.
Definition: vtkGraphEdge.h:24
vtkEdgeBase(vtkIdType id)
Definition: vtkGraph.h:238
virtual void Initialize()
Restore data object to initial state,.
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:315
std::pair< boost::graph_traits< vtkGraph * >::vertex_iterator, boost::graph_traits< vtkGraph * >::vertex_iterator > vertices(vtkGraph *g)
vtkOutEdgeType()=default
vtkDistributedGraphHelper * DistributedHelper
The distributed graph helper.
Definition: vtkGraph.h:738
vtkTimeStamp ComputeTime
Time at which bounds were computed.
Definition: vtkGraph.h:803
A type representing the union of many types.
Definition: vtkVariant.h:52
A directed graph.
Base class for graph data types.
Definition: vtkGraph.h:280
bool VTKCOMMONDATAMODEL_EXPORT operator==(vtkEdgeBase e1, vtkEdgeBase e2)
vtkIdType Source
Definition: vtkGraph.h:276
a simple class to control print indentation
Definition: vtkIndent.h:28
VTKCOMMONDATAMODEL_EXPORT ostream & operator<<(ostream &out, vtkEdgeBase e)
vtkEdgeBase()=default
vtkGraphEdgePoints * EdgePoints
The structure for holding the edge points.
Definition: vtkGraph.h:748
void SetEdgePoint(vtkIdType e, vtkIdType i, double x, double y, double z)
Definition: vtkGraph.h:583
vtkEdgeType()=default
Iterates through all incoming edges to a vertex.
Internal representation of vtkGraph.
vtkIdType Id
Definition: vtkGraph.h:242
represent and manipulate attribute data in a dataset
#define VTK_SIZEHINT(...)
virtual unsigned long GetActualMemorySize()
Return the actual size of the data in kibibytes (1024 bytes).
vtkIdType Target
Definition: vtkGraph.h:253
virtual vtkIdType GetNumberOfElements(int type)
Get the number of elements for a specific attribute type (POINT, CELL, etc.).
vtkPoints * Points
The vertex locations.
Definition: vtkGraph.h:809
object to represent cell connectivity
Definition: vtkCellArray.h:175
void GetPoint(int i, int j, int k, double pnt[3])
vtkIdType Source
Definition: vtkGraph.h:264
Iterates all vertices in a graph.
vtkOutEdgeType(vtkIdType t, vtkIdType id)
Definition: vtkGraph.h:248
Store zero or more vtkInformation instances.
int GetDataObjectType() override
Return what type of dataset this is.
Definition: vtkGraph.h:297
vtkGraphInternals * Internals
The adjacency list internals of this graph.
Definition: vtkGraph.h:733
Iterates through all outgoing edges from a vertex.
vtkMTimeType GetMTime() override
Data objects are composite objects and need to check each part for MTime.
general representation of visualization data
Definition: vtkDataObject.h:54
vtkInEdgeType(vtkIdType s, vtkIdType id)
Definition: vtkGraph.h:259
virtual void DeepCopy(vtkDataObject *src)
The goal of the method is to copy the complete data from src into this object.
vtkEdgeType(vtkIdType s, vtkIdType t, vtkIdType id)
Definition: vtkGraph.h:270
vtkIdType Target
Definition: vtkGraph.h:277
represent and manipulate 3D points
Definition: vtkPoints.h:28
void AddEdgePoint(vtkIdType e, double x, double y, double z)
Definition: vtkGraph.h:593
#define VTK_GRAPH
Definition: vtkType.h:85
virtual void ShallowCopy(vtkDataObject *src)
The goal of the method is to copy the data up to the array pointers only.
represent and manipulate fields of data
Definition: vtkFieldData.h:51
std::pair< boost::graph_traits< vtkGraph * >::edge_iterator, boost::graph_traits< vtkGraph * >::edge_iterator > edges(vtkGraph *g)