VTK  9.2.6
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 -------------------------------------------------------------------------*/
216 #ifndef vtkGraph_h
217 #define vtkGraph_h
218 
219 #include "vtkCommonDataModelModule.h" // For export macro
220 #include "vtkDataObject.h"
221 
223 class vtkCellArray;
224 class vtkEdgeListIterator;
226 class vtkDirectedGraph;
227 class vtkGraphEdge;
228 class vtkGraphEdgePoints;
230 class vtkGraphInternals;
231 class vtkIdTypeArray;
232 class vtkInEdgeIterator;
233 class vtkOutEdgeIterator;
234 class vtkPoints;
235 class vtkUndirectedGraph;
237 class vtkVariant;
238 class vtkVariantArray;
239 
240 // Forward declare some boost stuff even if boost wrappers
241 // are turned off.
242 namespace boost
243 {
244 class vtk_edge_iterator;
245 class vtk_out_edge_pointer_iterator;
246 class vtk_in_edge_pointer_iterator;
247 }
248 
249 // Edge structures.
251 {
252  vtkEdgeBase() = default;
254  : Id(id)
255  {
256  }
258 };
259 
261 {
262  vtkOutEdgeType() = default;
264  : vtkEdgeBase(id)
265  , Target(t)
266  {
267  }
269 };
270 
272 {
273  vtkInEdgeType() = default;
275  : vtkEdgeBase(id)
276  , Source(s)
277  {
278  }
280 };
281 
283 {
284  vtkEdgeType() = default;
286  : vtkEdgeBase(id)
287  , Source(s)
288  , Target(t)
289  {
290  }
293 };
294 
295 class VTKCOMMONDATAMODEL_EXPORT vtkGraph : public vtkDataObject
296 {
297 public:
298  vtkTypeMacro(vtkGraph, vtkDataObject);
299  void PrintSelf(ostream& os, vtkIndent indent) override;
300 
302 
305  vtkGetObjectMacro(VertexData, vtkDataSetAttributes);
306  vtkGetObjectMacro(EdgeData, vtkDataSetAttributes);
308 
312  int GetDataObjectType() override { return VTK_GRAPH; }
313 
317  void Initialize() override;
318 
320 
326  double* GetPoint(vtkIdType ptId);
327  void GetPoint(vtkIdType ptId, double x[3]);
329 
331 
338  vtkPoints* GetPoints();
339  virtual void SetPoints(vtkPoints* points);
341 
346  void ComputeBounds();
347 
349 
354  double* GetBounds();
355  void GetBounds(double bounds[6]);
357 
361  vtkMTimeType GetMTime() override;
362 
369  virtual void GetOutEdges(vtkIdType v, vtkOutEdgeIterator* it);
370 
377  virtual vtkIdType GetDegree(vtkIdType v);
378 
384  virtual vtkIdType GetOutDegree(vtkIdType v);
385 
389  virtual vtkOutEdgeType GetOutEdge(vtkIdType v, vtkIdType index);
390 
397  virtual void GetOutEdge(vtkIdType v, vtkIdType index, vtkGraphEdge* e);
398 
405  virtual void GetInEdges(vtkIdType v, vtkInEdgeIterator* it);
406 
412  virtual vtkIdType GetInDegree(vtkIdType v);
413 
417  virtual vtkInEdgeType GetInEdge(vtkIdType v, vtkIdType index);
418 
425  virtual void GetInEdge(vtkIdType v, vtkIdType index, vtkGraphEdge* e);
426 
433  virtual void GetAdjacentVertices(vtkIdType v, vtkAdjacentVertexIterator* it);
434 
441  virtual void GetEdges(vtkEdgeListIterator* it);
442 
447  virtual vtkIdType GetNumberOfEdges();
448 
454  virtual void GetVertices(vtkVertexListIterator* it);
455 
460  virtual vtkIdType GetNumberOfVertices();
461 
467  void SetDistributedGraphHelper(vtkDistributedGraphHelper* helper);
468 
472  vtkDistributedGraphHelper* GetDistributedGraphHelper();
473 
482  vtkIdType FindVertex(const vtkVariant& pedigreeID);
483 
488  void ShallowCopy(vtkDataObject* obj) override;
489 
494  void DeepCopy(vtkDataObject* obj) override;
495 
500  virtual void CopyStructure(vtkGraph* g);
501 
507  virtual bool CheckedShallowCopy(vtkGraph* g);
508 
514  virtual bool CheckedDeepCopy(vtkGraph* g);
515 
519  virtual void Squeeze();
520 
528  unsigned long GetActualMemorySize() override;
529 
531 
535  static vtkGraph* GetData(vtkInformationVector* v, int i = 0);
537 
545  void ReorderOutVertices(vtkIdType v, vtkIdTypeArray* vertices);
546 
551  bool IsSameStructure(vtkGraph* other);
552 
554 
563  vtkIdType GetSourceVertex(vtkIdType e);
564  vtkIdType GetTargetVertex(vtkIdType e);
566 
568 
573  void SetEdgePoints(vtkIdType e, vtkIdType npts, const double pts[]) VTK_SIZEHINT(pts, 3 * npts);
574  void GetEdgePoints(vtkIdType e, vtkIdType& npts, double*& pts) VTK_SIZEHINT(pts, 3 * npts);
576 
580  vtkIdType GetNumberOfEdgePoints(vtkIdType e);
581 
585  double* GetEdgePoint(vtkIdType e, vtkIdType i) VTK_SIZEHINT(3);
586 
590  void ClearEdgePoints(vtkIdType e);
591 
597  void SetEdgePoint(vtkIdType e, vtkIdType i, const double x[3]);
598  void SetEdgePoint(vtkIdType e, vtkIdType i, double x, double y, double z)
599  {
600  double p[3] = { x, y, z };
601  this->SetEdgePoint(e, i, p);
602  }
603 
607  void AddEdgePoint(vtkIdType e, const double x[3]);
608  void AddEdgePoint(vtkIdType e, double x, double y, double z)
609  {
610  double p[3] = { x, y, z };
611  this->AddEdgePoint(e, p);
612  }
613 
615 
619  void ShallowCopyEdgePoints(vtkGraph* g);
620  void DeepCopyEdgePoints(vtkGraph* g);
622 
628  vtkGraphInternals* GetGraphInternals(bool modifying);
629 
634  void GetInducedEdges(vtkIdTypeArray* verts, vtkIdTypeArray* edges);
635 
643 
647  vtkIdType GetNumberOfElements(int type) override;
648 
652  void Dump();
653 
662  vtkIdType GetEdgeId(vtkIdType a, vtkIdType b);
663 
667  bool ToDirectedGraph(vtkDirectedGraph* g);
668 
672  bool ToUndirectedGraph(vtkUndirectedGraph* g);
673 
674 protected:
675  vtkGraph();
676  ~vtkGraph() override;
677 
685  void AddVertexInternal(vtkVariantArray* propertyArr = nullptr, vtkIdType* vertex = nullptr);
686 
693  void AddVertexInternal(const vtkVariant& pedigree, vtkIdType* vertex);
694 
696 
702  void AddEdgeInternal(
703  vtkIdType u, vtkIdType v, bool directed, vtkVariantArray* propertyArr, vtkEdgeType* edge);
704  void AddEdgeInternal(const vtkVariant& uPedigree, vtkIdType v, bool directed,
705  vtkVariantArray* propertyArr, vtkEdgeType* edge);
706  void AddEdgeInternal(vtkIdType u, const vtkVariant& vPedigree, bool directed,
707  vtkVariantArray* propertyArr, vtkEdgeType* edge);
708  void AddEdgeInternal(const vtkVariant& uPedigree, const vtkVariant& vPedigree, bool directed,
709  vtkVariantArray* propertyArr, vtkEdgeType* edge);
711 
716  void RemoveVertexInternal(vtkIdType v, bool directed);
717 
722  void RemoveEdgeInternal(vtkIdType e, bool directed);
723 
727  void RemoveVerticesInternal(vtkIdTypeArray* arr, bool directed);
728 
732  void RemoveEdgesInternal(vtkIdTypeArray* arr, bool directed);
733 
738  virtual bool IsStructureValid(vtkGraph* g) = 0;
739 
743  virtual void CopyInternal(vtkGraph* g, bool deep);
744 
749 
754 
758  void SetInternals(vtkGraphInternals* internals);
759 
763  vtkGraphEdgePoints* EdgePoints;
764 
768  void SetEdgePoints(vtkGraphEdgePoints* edgePoints);
769 
774  void ForceOwnership();
775 
777 
780  virtual void GetOutEdges(vtkIdType v, const vtkOutEdgeType*& edges, vtkIdType& nedges);
781  virtual void GetInEdges(vtkIdType v, const vtkInEdgeType*& edges, vtkIdType& nedges);
783 
787  void BuildEdgeList();
788 
790 
794  friend class vtkEdgeListIterator;
795  friend class vtkInEdgeIterator;
796  friend class vtkOutEdgeIterator;
801 
803 
809 
813  double Bounds[6];
814 
819 
821 
825  static double DefaultPoint[3];
827 
829 
832  vtkGetObjectMacro(EdgeList, vtkIdTypeArray);
833  virtual void SetEdgeList(vtkIdTypeArray* list);
836 
837 private:
838  vtkGraph(const vtkGraph&) = delete;
839  void operator=(const vtkGraph&) = delete;
840 };
841 
842 bool VTKCOMMONDATAMODEL_EXPORT operator==(vtkEdgeBase e1, vtkEdgeBase e2);
843 bool VTKCOMMONDATAMODEL_EXPORT operator!=(vtkEdgeBase e1, vtkEdgeBase e2);
844 VTKCOMMONDATAMODEL_EXPORT ostream& operator<<(ostream& out, vtkEdgeBase e);
845 
846 #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:806
vtkDataSetAttributes * EdgeData
The vertex and edge data.
Definition: vtkGraph.h:807
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:834
Store vtkAlgorithm input/output information.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:287
Iterates through adjacent vertices in a graph.
bool VTKCOMMONDATAMODEL_EXPORT operator!=(vtkEdgeBase e1, vtkEdgeBase e2)
record modification and/or execution time
Definition: vtkTimeStamp.h:35
Iterates through all edges in a graph.
An undirected graph.
Representation of a single graph edge.
Definition: vtkGraphEdge.h:39
vtkEdgeBase(vtkIdType id)
Definition: vtkGraph.h:253
virtual void Initialize()
Restore data object to initial state,.
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:332
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:753
vtkTimeStamp ComputeTime
Time at which bounds were computed.
Definition: vtkGraph.h:818
void GetPoint(const int i, const int j, const int k, double pnt[3])
A atomic type representing the union of many types.
Definition: vtkVariant.h:69
A directed graph.
Base class for graph data types.
Definition: vtkGraph.h:295
bool VTKCOMMONDATAMODEL_EXPORT operator==(vtkEdgeBase e1, vtkEdgeBase e2)
vtkIdType Source
Definition: vtkGraph.h:291
a simple class to control print indentation
Definition: vtkIndent.h:39
VTKCOMMONDATAMODEL_EXPORT ostream & operator<<(ostream &out, vtkEdgeBase e)
vtkEdgeBase()=default
vtkGraphEdgePoints * EdgePoints
The structure for holding the edge points.
Definition: vtkGraph.h:763
void SetEdgePoint(vtkIdType e, vtkIdType i, double x, double y, double z)
Definition: vtkGraph.h:598
vtkEdgeType()=default
Iterates through all incoming edges to a vertex.
Internal representation of vtkGraph.
vtkIdType Id
Definition: vtkGraph.h:257
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:268
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:824
object to represent cell connectivity
Definition: vtkCellArray.h:186
vtkIdType Source
Definition: vtkGraph.h:279
Iterates all vertices in a graph.
vtkOutEdgeType(vtkIdType t, vtkIdType id)
Definition: vtkGraph.h:263
Store zero or more vtkInformation instances.
int GetDataObjectType() override
Return what type of dataset this is.
Definition: vtkGraph.h:312
vtkGraphInternals * Internals
The adjacency list internals of this graph.
Definition: vtkGraph.h:748
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:65
vtkInEdgeType(vtkIdType s, vtkIdType id)
Definition: vtkGraph.h:274
virtual void DeepCopy(vtkDataObject *src)
Shallow and Deep copy.
vtkEdgeType(vtkIdType s, vtkIdType t, vtkIdType id)
Definition: vtkGraph.h:285
vtkIdType Target
Definition: vtkGraph.h:292
represent and manipulate 3D points
Definition: vtkPoints.h:39
void AddEdgePoint(vtkIdType e, double x, double y, double z)
Definition: vtkGraph.h:608
#define VTK_GRAPH
Definition: vtkType.h:97
virtual void ShallowCopy(vtkDataObject *src)
Shallow and Deep copy.
represent and manipulate fields of data
Definition: vtkFieldData.h:62
std::pair< boost::graph_traits< vtkGraph * >::edge_iterator, boost::graph_traits< vtkGraph * >::edge_iterator > edges(vtkGraph *g)