VTK  9.0.20200927
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 -------------------------------------------------------------------------*/
210 #ifndef vtkGraph_h
211 #define vtkGraph_h
212 
213 #include "vtkCommonDataModelModule.h" // For export macro
214 #include "vtkDataObject.h"
215 
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 // Forward declare some boost stuff even if boost wrappers
235 // are turned off.
236 namespace boost
237 {
238 class vtk_edge_iterator;
239 class vtk_out_edge_pointer_iterator;
240 class vtk_in_edge_pointer_iterator;
241 }
242 
243 // Edge structures.
245 {
246  vtkEdgeBase() = default;
248  : Id(id)
249  {
250  }
252 };
253 
255 {
256  vtkOutEdgeType() = default;
258  : vtkEdgeBase(id)
259  , Target(t)
260  {
261  }
263 };
264 
266 {
267  vtkInEdgeType() = default;
269  : vtkEdgeBase(id)
270  , Source(s)
271  {
272  }
274 };
275 
277 {
278  vtkEdgeType() = default;
280  : vtkEdgeBase(id)
281  , Source(s)
282  , Target(t)
283  {
284  }
287 };
288 
289 class VTKCOMMONDATAMODEL_EXPORT vtkGraph : public vtkDataObject
290 {
291 public:
292  vtkTypeMacro(vtkGraph, vtkDataObject);
293  void PrintSelf(ostream& os, vtkIndent indent) override;
294 
296 
299  vtkGetObjectMacro(VertexData, vtkDataSetAttributes);
300  vtkGetObjectMacro(EdgeData, vtkDataSetAttributes);
302 
306  int GetDataObjectType() override { return VTK_GRAPH; }
307 
311  void Initialize() override;
312 
314 
320  double* GetPoint(vtkIdType ptId);
321  void GetPoint(vtkIdType ptId, double x[3]);
323 
325 
332  vtkPoints* GetPoints();
333  virtual void SetPoints(vtkPoints* points);
335 
340  void ComputeBounds();
341 
343 
348  double* GetBounds();
349  void GetBounds(double bounds[6]);
351 
355  vtkMTimeType GetMTime() override;
356 
363  virtual void GetOutEdges(vtkIdType v, vtkOutEdgeIterator* it);
364 
371  virtual vtkIdType GetDegree(vtkIdType v);
372 
378  virtual vtkIdType GetOutDegree(vtkIdType v);
379 
383  virtual vtkOutEdgeType GetOutEdge(vtkIdType v, vtkIdType index);
384 
391  virtual void GetOutEdge(vtkIdType v, vtkIdType index, vtkGraphEdge* e);
392 
399  virtual void GetInEdges(vtkIdType v, vtkInEdgeIterator* it);
400 
406  virtual vtkIdType GetInDegree(vtkIdType v);
407 
411  virtual vtkInEdgeType GetInEdge(vtkIdType v, vtkIdType index);
412 
419  virtual void GetInEdge(vtkIdType v, vtkIdType index, vtkGraphEdge* e);
420 
427  virtual void GetAdjacentVertices(vtkIdType v, vtkAdjacentVertexIterator* it);
428 
435  virtual void GetEdges(vtkEdgeListIterator* it);
436 
441  virtual vtkIdType GetNumberOfEdges();
442 
448  virtual void GetVertices(vtkVertexListIterator* it);
449 
454  virtual vtkIdType GetNumberOfVertices();
455 
461  void SetDistributedGraphHelper(vtkDistributedGraphHelper* helper);
462 
466  vtkDistributedGraphHelper* GetDistributedGraphHelper();
467 
476  vtkIdType FindVertex(const vtkVariant& pedigreeID);
477 
482  void ShallowCopy(vtkDataObject* obj) override;
483 
488  void DeepCopy(vtkDataObject* obj) override;
489 
494  virtual void CopyStructure(vtkGraph* g);
495 
501  virtual bool CheckedShallowCopy(vtkGraph* g);
502 
508  virtual bool CheckedDeepCopy(vtkGraph* g);
509 
513  virtual void Squeeze();
514 
522  unsigned long GetActualMemorySize() override;
523 
525 
529  static vtkGraph* GetData(vtkInformationVector* v, int i = 0);
531 
539  void ReorderOutVertices(vtkIdType v, vtkIdTypeArray* vertices);
540 
545  bool IsSameStructure(vtkGraph* other);
546 
548 
557  vtkIdType GetSourceVertex(vtkIdType e);
558  vtkIdType GetTargetVertex(vtkIdType e);
560 
562 
567  void SetEdgePoints(vtkIdType e, vtkIdType npts, const double pts[]) VTK_SIZEHINT(pts, 3 * npts);
568  void GetEdgePoints(vtkIdType e, vtkIdType& npts, double*& pts) VTK_SIZEHINT(pts, 3 * npts);
570 
574  vtkIdType GetNumberOfEdgePoints(vtkIdType e);
575 
579  double* GetEdgePoint(vtkIdType e, vtkIdType i) VTK_SIZEHINT(3);
580 
584  void ClearEdgePoints(vtkIdType e);
585 
591  void SetEdgePoint(vtkIdType e, vtkIdType i, const double x[3]);
592  void SetEdgePoint(vtkIdType e, vtkIdType i, double x, double y, double z)
593  {
594  double p[3] = { x, y, z };
595  this->SetEdgePoint(e, i, p);
596  }
597 
601  void AddEdgePoint(vtkIdType e, const double x[3]);
602  void AddEdgePoint(vtkIdType e, double x, double y, double z)
603  {
604  double p[3] = { x, y, z };
605  this->AddEdgePoint(e, p);
606  }
607 
609 
613  void ShallowCopyEdgePoints(vtkGraph* g);
614  void DeepCopyEdgePoints(vtkGraph* g);
616 
622  vtkGraphInternals* GetGraphInternals(bool modifying);
623 
628  void GetInducedEdges(vtkIdTypeArray* verts, vtkIdTypeArray* edges);
629 
637 
641  vtkIdType GetNumberOfElements(int type) override;
642 
646  void Dump();
647 
656  vtkIdType GetEdgeId(vtkIdType a, vtkIdType b);
657 
661  bool ToDirectedGraph(vtkDirectedGraph* g);
662 
666  bool ToUndirectedGraph(vtkUndirectedGraph* g);
667 
668 protected:
669  vtkGraph();
670  ~vtkGraph() override;
671 
679  void AddVertexInternal(vtkVariantArray* propertyArr = nullptr, vtkIdType* vertex = nullptr);
680 
687  void AddVertexInternal(const vtkVariant& pedigree, vtkIdType* vertex);
688 
690 
696  void AddEdgeInternal(
697  vtkIdType u, vtkIdType v, bool directed, vtkVariantArray* propertyArr, vtkEdgeType* edge);
698  void AddEdgeInternal(const vtkVariant& uPedigree, vtkIdType v, bool directed,
699  vtkVariantArray* propertyArr, vtkEdgeType* edge);
700  void AddEdgeInternal(vtkIdType u, const vtkVariant& vPedigree, bool directed,
701  vtkVariantArray* propertyArr, vtkEdgeType* edge);
702  void AddEdgeInternal(const vtkVariant& uPedigree, const vtkVariant& vPedigree, bool directed,
703  vtkVariantArray* propertyArr, vtkEdgeType* edge);
705 
710  void RemoveVertexInternal(vtkIdType v, bool directed);
711 
716  void RemoveEdgeInternal(vtkIdType e, bool directed);
717 
721  void RemoveVerticesInternal(vtkIdTypeArray* arr, bool directed);
722 
726  void RemoveEdgesInternal(vtkIdTypeArray* arr, bool directed);
727 
732  virtual bool IsStructureValid(vtkGraph* g) = 0;
733 
737  virtual void CopyInternal(vtkGraph* g, bool deep);
738 
743 
748 
752  void SetInternals(vtkGraphInternals* internals);
753 
757  vtkGraphEdgePoints* EdgePoints;
758 
762  void SetEdgePoints(vtkGraphEdgePoints* edgePoints);
763 
768  void ForceOwnership();
769 
771 
774  virtual void GetOutEdges(vtkIdType v, const vtkOutEdgeType*& edges, vtkIdType& nedges);
775  virtual void GetInEdges(vtkIdType v, const vtkInEdgeType*& edges, vtkIdType& nedges);
777 
781  void BuildEdgeList();
782 
784 
788  friend class vtkEdgeListIterator;
789  friend class vtkInEdgeIterator;
790  friend class vtkOutEdgeIterator;
795 
797 
803 
807  double Bounds[6];
808 
813 
815 
819  static double DefaultPoint[3];
821 
823 
826  vtkGetObjectMacro(EdgeList, vtkIdTypeArray);
827  virtual void SetEdgeList(vtkIdTypeArray* list);
830 
831 private:
832  vtkGraph(const vtkGraph&) = delete;
833  void operator=(const vtkGraph&) = delete;
834 };
835 
836 bool VTKCOMMONDATAMODEL_EXPORT operator==(vtkEdgeBase e1, vtkEdgeBase e2);
837 bool VTKCOMMONDATAMODEL_EXPORT operator!=(vtkEdgeBase e1, vtkEdgeBase e2);
838 VTKCOMMONDATAMODEL_EXPORT ostream& operator<<(ostream& out, vtkEdgeBase e);
839 
840 #endif
vtkPoints
represent and manipulate 3D points
Definition: vtkPoints.h:33
vtkInEdgeType::vtkInEdgeType
vtkInEdgeType(vtkIdType s, vtkIdType id)
Definition: vtkGraph.h:268
vtkGraph::AddEdgePoint
void AddEdgePoint(vtkIdType e, double x, double y, double z)
Definition: vtkGraph.h:602
vtkEdgeBase::Id
vtkIdType Id
Definition: vtkGraph.h:251
operator<<
VTKCOMMONDATAMODEL_EXPORT ostream & operator<<(ostream &out, vtkEdgeBase e)
vtkGraph::GetDataObjectType
int GetDataObjectType() override
Return what type of dataset this is.
Definition: vtkGraph.h:306
vtkDataObject::Initialize
virtual void Initialize()
Restore data object to initial state,.
vtkDistributedGraphHelper
helper for the vtkGraph class that allows the graph to be distributed across multiple memory spaces.
Definition: vtkDistributedGraphHelper.h:76
vtkGraph::Points
vtkPoints * Points
The vertex locations.
Definition: vtkGraph.h:818
vtkUndirectedGraph
An undirected graph.
Definition: vtkUndirectedGraph.h:48
vtkGraphInternals
Internal representation of vtkGraph.
Definition: vtkGraphInternals.h:51
vtkDataObject::GetAttributesAsFieldData
virtual vtkFieldData * GetAttributesAsFieldData(int type)
Returns the attributes of the data object as a vtkFieldData.
vtkX3D::type
Definition: vtkX3D.h:522
vtkIdType
int vtkIdType
Definition: vtkType.h:330
VTK_GRAPH
#define VTK_GRAPH
Definition: vtkType.h:97
vtkGraph::Internals
vtkGraphInternals * Internals
The adjacency list internals of this graph.
Definition: vtkGraph.h:742
vtkDataObject::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkGraph::ComputeTime
vtkTimeStamp ComputeTime
Time at which bounds were computed.
Definition: vtkGraph.h:812
vtkDataSetAttributes
represent and manipulate attribute data in a dataset
Definition: vtkDataSetAttributes.h:60
vtkInformationVector
Store zero or more vtkInformation instances.
Definition: vtkInformationVector.h:35
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:32
vtkOutEdgeType::vtkOutEdgeType
vtkOutEdgeType()=default
vtkEdgeBase::vtkEdgeBase
vtkEdgeBase(vtkIdType id)
Definition: vtkGraph.h:247
vtkDirectedGraph
A directed graph.
Definition: vtkDirectedGraph.h:44
boost
Forward declaration required for Boost serialization.
Definition: vtkVariantArray.h:41
vtkInEdgeIterator
Iterates through all incoming edges to a vertex.
Definition: vtkInEdgeIterator.h:45
vtkVariantArray
An array holding vtkVariants.
Definition: vtkVariantArray.h:49
vtkInEdgeType
Definition: vtkGraph.h:265
boost::vtk_out_edge_pointer_iterator
Definition: vtkBoostGraphAdapter.h:324
vtkDataObject::DeepCopy
virtual void DeepCopy(vtkDataObject *src)
GetPoint
void GetPoint(const int i, const int j, const int k, double pnt[3])
vtkOutEdgeType::Target
vtkIdType Target
Definition: vtkGraph.h:262
vtkEdgeType::Source
vtkIdType Source
Definition: vtkGraph.h:285
vtkEdgeBase::vtkEdgeBase
vtkEdgeBase()=default
vtkDataObject::GetMTime
vtkMTimeType GetMTime() override
Data objects are composite objects and need to check each part for MTime.
vtkFieldData
represent and manipulate fields of data
Definition: vtkFieldData.h:53
vtkDataObject::GetNumberOfElements
virtual vtkIdType GetNumberOfElements(int type)
Get the number of elements for a specific attribute type (POINT, CELL, etc.).
vtkGraph::VertexData
vtkDataSetAttributes * VertexData
The vertex and edge data.
Definition: vtkGraph.h:800
vtkEdgeType
Definition: vtkGraph.h:276
operator!=
bool VTKCOMMONDATAMODEL_EXPORT operator!=(vtkEdgeBase e1, vtkEdgeBase e2)
operator==
bool VTKCOMMONDATAMODEL_EXPORT operator==(vtkEdgeBase e1, vtkEdgeBase e2)
vtkX3D::points
Definition: vtkX3D.h:452
vtkGraph::EdgeList
vtkIdTypeArray * EdgeList
Definition: vtkGraph.h:828
VTK_SIZEHINT
#define VTK_SIZEHINT(...)
Definition: vtkWrappingHints.h:45
vtkOutEdgeType::vtkOutEdgeType
vtkOutEdgeType(vtkIdType t, vtkIdType id)
Definition: vtkGraph.h:257
vtkBlockSortHelper::GetBounds
void GetBounds(T a, double bds[6])
Definition: vtkBlockSortHelper.h:37
vtkGraphEdge
Representation of a single graph edge.
Definition: vtkGraphEdge.h:39
vtkEdgeType::Target
vtkIdType Target
Definition: vtkGraph.h:286
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkCellArray
object to represent cell connectivity
Definition: vtkCellArray.h:180
vtkVariant
A atomic type representing the union of many types.
Definition: vtkVariant.h:65
vtkEdgeListIterator
Iterates through all edges in a graph.
Definition: vtkEdgeListIterator.h:50
vtkOutEdgeIterator
Iterates through all outgoing edges from a vertex.
Definition: vtkOutEdgeIterator.h:45
boost::vtk_in_edge_pointer_iterator
Definition: vtkBoostGraphAdapter.h:381
vtkInEdgeType::Source
vtkIdType Source
Definition: vtkGraph.h:273
vtkGraph::EdgePoints
vtkGraphEdgePoints * EdgePoints
The structure for holding the edge points.
Definition: vtkGraph.h:757
vtkAdjacentVertexIterator
Iterates through adjacent vertices in a graph.
Definition: vtkAdjacentVertexIterator.h:44
vtkEdgeType::vtkEdgeType
vtkEdgeType(vtkIdType s, vtkIdType t, vtkIdType id)
Definition: vtkGraph.h:279
vtkDataObject::GetActualMemorySize
virtual unsigned long GetActualMemorySize()
Return the actual size of the data in kibibytes (1024 bytes).
vtkInformation
Store vtkAlgorithm input/output information.
Definition: vtkInformation.h:73
vtkGraph::EdgeData
vtkDataSetAttributes * EdgeData
Definition: vtkGraph.h:801
vtkEdgeBase
Definition: vtkGraph.h:244
vtkX3D::info
Definition: vtkX3D.h:382
vtkEdgeType::vtkEdgeType
vtkEdgeType()=default
vtkIdTypeArray
dynamic, self-adjusting array of vtkIdType
Definition: vtkIdTypeArray.h:35
vtkOutEdgeType
Definition: vtkGraph.h:254
vtkDataObject.h
vtkInEdgeType::vtkInEdgeType
vtkInEdgeType()=default
vtkGraph::SetEdgePoint
void SetEdgePoint(vtkIdType e, vtkIdType i, double x, double y, double z)
Definition: vtkGraph.h:592
edges
std::pair< boost::graph_traits< vtkGraph * >::edge_iterator, boost::graph_traits< vtkGraph * >::edge_iterator > edges(vtkGraph *g)
Definition: vtkBoostGraphAdapter.h:988
vtkGraph::DistributedHelper
vtkDistributedGraphHelper * DistributedHelper
The distributed graph helper.
Definition: vtkGraph.h:747
vtkVertexListIterator
Iterates all vertices in a graph.
Definition: vtkVertexListIterator.h:44
vertices
std::pair< boost::graph_traits< vtkGraph * >::vertex_iterator, boost::graph_traits< vtkGraph * >::vertex_iterator > vertices(vtkGraph *g)
Definition: vtkBoostGraphAdapter.h:973
boost::vtk_edge_iterator
Definition: vtkBoostGraphAdapter.h:175
vtkGraph
Base class for graph data types.
Definition: vtkGraph.h:289
vtkDataObject
general representation of visualization data
Definition: vtkDataObject.h:59
vtkX3D::index
Definition: vtkX3D.h:252
vtkDataObject::ShallowCopy
virtual void ShallowCopy(vtkDataObject *src)
Shallow and Deep copy.
vtkDataObject::GetData
static vtkDataObject * GetData(vtkInformation *info)
Retrieve an instance of this class from an information object.
vtkMTimeType
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:285