VTK
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 {
248  Id(id) { }
250 };
251 
253 {
256  vtkEdgeBase(id),
257  Target(t) { }
259 };
260 
262 {
265  vtkEdgeBase(id),
266  Source(s) { }
268 };
269 
271 {
274  vtkEdgeBase(id),
275  Source(s),
276  Target(t) { }
279 };
280 
281 class VTKCOMMONDATAMODEL_EXPORT vtkGraph : public vtkDataObject
282 {
283 public:
284  vtkTypeMacro(vtkGraph, vtkDataObject);
285  void PrintSelf(ostream& os, vtkIndent indent) override;
286 
288 
291  vtkGetObjectMacro(VertexData, vtkDataSetAttributes);
292  vtkGetObjectMacro(EdgeData, vtkDataSetAttributes);
294 
298  int GetDataObjectType() override {return VTK_GRAPH;}
299 
303  void Initialize() override;
304 
306 
312  double *GetPoint(vtkIdType ptId);
313  void GetPoint(vtkIdType ptId, double x[3]);
315 
317 
324  vtkPoints* GetPoints();
325  virtual void SetPoints(vtkPoints *points);
327 
332  void ComputeBounds();
333 
335 
340  double *GetBounds();
341  void GetBounds(double bounds[6]);
343 
347  vtkMTimeType GetMTime() override;
348 
355  virtual void GetOutEdges(vtkIdType v, vtkOutEdgeIterator *it);
356 
363  virtual vtkIdType GetDegree(vtkIdType v);
364 
370  virtual vtkIdType GetOutDegree(vtkIdType v);
371 
375  virtual vtkOutEdgeType GetOutEdge(vtkIdType v, vtkIdType index);
376 
383  virtual void GetOutEdge(vtkIdType v, vtkIdType index, vtkGraphEdge* e);
384 
391  virtual void GetInEdges(vtkIdType v, vtkInEdgeIterator *it);
392 
398  virtual vtkIdType GetInDegree(vtkIdType v);
399 
403  virtual vtkInEdgeType GetInEdge(vtkIdType v, vtkIdType index);
404 
411  virtual void GetInEdge(vtkIdType v, vtkIdType index, vtkGraphEdge* e);
412 
419  virtual void GetAdjacentVertices(vtkIdType v, vtkAdjacentVertexIterator *it);
420 
427  virtual void GetEdges(vtkEdgeListIterator *it);
428 
433  virtual vtkIdType GetNumberOfEdges();
434 
440  virtual void GetVertices(vtkVertexListIterator *it);
441 
446  virtual vtkIdType GetNumberOfVertices();
447 
453  void SetDistributedGraphHelper(vtkDistributedGraphHelper *helper);
454 
458  vtkDistributedGraphHelper *GetDistributedGraphHelper();
459 
468  vtkIdType FindVertex(const vtkVariant& pedigreeID);
469 
474  void ShallowCopy(vtkDataObject *obj) override;
475 
480  void DeepCopy(vtkDataObject *obj) override;
481 
486  virtual void CopyStructure(vtkGraph *g);
487 
493  virtual bool CheckedShallowCopy(vtkGraph *g);
494 
500  virtual bool CheckedDeepCopy(vtkGraph *g);
501 
505  virtual void Squeeze();
506 
508 
512  static vtkGraph *GetData(vtkInformationVector *v, int i=0);
514 
522  void ReorderOutVertices(vtkIdType v, vtkIdTypeArray *vertices);
523 
528  bool IsSameStructure(vtkGraph *other);
529 
531 
540  vtkIdType GetSourceVertex(vtkIdType e);
541  vtkIdType GetTargetVertex(vtkIdType e);
543 
545 
550  void SetEdgePoints(vtkIdType e, vtkIdType npts, double* pts);
551  void GetEdgePoints(vtkIdType e, vtkIdType& npts, double*& pts);
553 
557  vtkIdType GetNumberOfEdgePoints(vtkIdType e);
558 
562  double* GetEdgePoint(vtkIdType e, vtkIdType i) VTK_SIZEHINT(3);
563 
567  void ClearEdgePoints(vtkIdType e);
568 
574  void SetEdgePoint(vtkIdType e, vtkIdType i, double x[3]);
575  void SetEdgePoint(vtkIdType e, vtkIdType i, double x, double y, double z)
576  { double p[3] = {x, y, z}; this->SetEdgePoint(e, i, p); }
577 
581  void AddEdgePoint(vtkIdType e, double x[3]);
582  void AddEdgePoint(vtkIdType e, double x, double y, double z)
583  { double p[3] = {x, y, z}; this->AddEdgePoint(e, p); }
584 
586 
590  void ShallowCopyEdgePoints(vtkGraph* g);
591  void DeepCopyEdgePoints(vtkGraph* g);
593 
599  vtkGraphInternals *GetGraphInternals(bool modifying);
600 
605  void GetInducedEdges(vtkIdTypeArray* verts, vtkIdTypeArray* edges);
606 
614 
618  vtkIdType GetNumberOfElements(int type) override;
619 
623  void Dump();
624 
633  vtkIdType GetEdgeId(vtkIdType a, vtkIdType b);
634 
638  bool ToDirectedGraph(vtkDirectedGraph* g);
639 
643  bool ToUndirectedGraph(vtkUndirectedGraph* g);
644 
645 protected:
646 
647  vtkGraph();
648  ~vtkGraph() override;
649 
657  void AddVertexInternal(vtkVariantArray *propertyArr = nullptr,
658  vtkIdType *vertex = nullptr);
659 
666  void AddVertexInternal(const vtkVariant& pedigree, vtkIdType *vertex);
667 
669 
675  void AddEdgeInternal(vtkIdType u, vtkIdType v, bool directed,
676  vtkVariantArray *propertyArr, vtkEdgeType *edge);
677  void AddEdgeInternal(const vtkVariant& uPedigree, vtkIdType v, bool directed,
678  vtkVariantArray *propertyArr, vtkEdgeType *edge);
679  void AddEdgeInternal(vtkIdType u, const vtkVariant& vPedigree, bool directed,
680  vtkVariantArray *propertyArr, vtkEdgeType *edge);
681  void AddEdgeInternal(const vtkVariant& uPedigree, const vtkVariant& vPedigree,
682  bool directed, vtkVariantArray *propertyArr,
683  vtkEdgeType *edge);
685 
690  void RemoveVertexInternal(vtkIdType v, bool directed);
691 
696  void RemoveEdgeInternal(vtkIdType e, bool directed);
697 
701  void RemoveVerticesInternal(vtkIdTypeArray* arr, bool directed);
702 
706  void RemoveEdgesInternal(vtkIdTypeArray* arr, bool directed);
707 
712  virtual bool IsStructureValid(vtkGraph *g) = 0;
713 
717  virtual void CopyInternal(vtkGraph *g, bool deep);
718 
723 
728 
732  void SetInternals(vtkGraphInternals* internals);
733 
737  vtkGraphEdgePoints *EdgePoints;
738 
742  void SetEdgePoints(vtkGraphEdgePoints* edgePoints);
743 
748  void ForceOwnership();
749 
751 
754  virtual void GetOutEdges(vtkIdType v, const vtkOutEdgeType *& edges, vtkIdType & nedges);
755  virtual void GetInEdges(vtkIdType v, const vtkInEdgeType *& edges, vtkIdType & nedges);
757 
761  void BuildEdgeList();
762 
764 
768  friend class vtkEdgeListIterator;
769  friend class vtkInEdgeIterator;
770  friend class vtkOutEdgeIterator;
775 
777 
783 
787  double Bounds[6];
788 
793 
795 
799  static double DefaultPoint[3];
801 
803 
806  vtkGetObjectMacro(EdgeList, vtkIdTypeArray);
807  virtual void SetEdgeList(vtkIdTypeArray* list);
810 
811 private:
812  vtkGraph(const vtkGraph&) = delete;
813  void operator=(const vtkGraph&) = delete;
814 };
815 
816 bool VTKCOMMONDATAMODEL_EXPORT operator==(vtkEdgeBase e1, vtkEdgeBase e2);
817 bool VTKCOMMONDATAMODEL_EXPORT operator!=(vtkEdgeBase e1, vtkEdgeBase e2);
818 VTKCOMMONDATAMODEL_EXPORT ostream& operator<<(ostream& out, vtkEdgeBase e);
819 
820 #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:780
vtkDataSetAttributes * EdgeData
The vertex and edge data.
Definition: vtkGraph.h:781
virtual vtkFieldData * GetAttributesAsFieldData(int type)
Returns the attributes of the data object as a vtkFieldData.
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:808
Store vtkAlgorithm input/output information.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:300
Iterates through adjacent vertices in a graph.
bool VTKCOMMONDATAMODEL_EXPORT operator!=(vtkEdgeBase e1, vtkEdgeBase e2)
record modification and/or execution time
Definition: vtkTimeStamp.h:32
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:247
virtual void Initialize()
Restore data object to initial state,.
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:345
vtkDistributedGraphHelper * DistributedHelper
The distributed graph helper.
Definition: vtkGraph.h:727
vtkTimeStamp ComputeTime
Time at which bounds were computed.
Definition: vtkGraph.h:792
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:65
A directed graph.
Base class for graph data types.
Definition: vtkGraph.h:281
bool VTKCOMMONDATAMODEL_EXPORT operator==(vtkEdgeBase e1, vtkEdgeBase e2)
vtkIdType Source
Definition: vtkGraph.h:277
a simple class to control print indentation
Definition: vtkIndent.h:33
VTKCOMMONDATAMODEL_EXPORT ostream & operator<<(ostream &out, vtkEdgeBase e)
vtkGraphEdgePoints * EdgePoints
The structure for holding the edge points.
Definition: vtkGraph.h:737
void SetEdgePoint(vtkIdType e, vtkIdType i, double x, double y, double z)
Definition: vtkGraph.h:575
std::pair< boost::graph_traits< vtkGraph *>::vertex_iterator, boost::graph_traits< vtkGraph *>::vertex_iterator > vertices(vtkGraph *g)
Iterates through all incoming edges to a vertex.
Internal representation of vtkGraph.
vtkIdType Id
Definition: vtkGraph.h:249
represent and manipulate attribute data in a dataset
#define VTK_SIZEHINT(...)
vtkIdType Target
Definition: vtkGraph.h:258
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:798
object to represent cell connectivity
Definition: vtkCellArray.h:44
vtkIdType Source
Definition: vtkGraph.h:267
Iterates all vertices in a graph.
vtkOutEdgeType(vtkIdType t, vtkIdType id)
Definition: vtkGraph.h:255
Store zero or more vtkInformation instances.
int GetDataObjectType() override
Return what type of dataset this is.
Definition: vtkGraph.h:298
vtkGraphInternals * Internals
The adjacency list internals of this graph.
Definition: vtkGraph.h:722
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:58
vtkInEdgeType(vtkIdType s, vtkIdType id)
Definition: vtkGraph.h:264
virtual void DeepCopy(vtkDataObject *src)
Shallow and Deep copy.
vtkEdgeType(vtkIdType s, vtkIdType t, vtkIdType id)
Definition: vtkGraph.h:273
vtkIdType Target
Definition: vtkGraph.h:278
represent and manipulate 3D points
Definition: vtkPoints.h:33
void AddEdgePoint(vtkIdType e, double x, double y, double z)
Definition: vtkGraph.h:582
std::pair< boost::graph_traits< vtkGraph *>::edge_iterator, boost::graph_traits< vtkGraph *>::edge_iterator > edges(vtkGraph *g)
#define VTK_GRAPH
Definition: vtkType.h:111
virtual void ShallowCopy(vtkDataObject *src)
Shallow and Deep copy.
represent and manipulate fields of data
Definition: vtkFieldData.h:53