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 -------------------------------------------------------------------------*/
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 {
254  Id(id) { }
256 };
257 
259 {
262  vtkEdgeBase(id),
263  Target(t) { }
265 };
266 
268 {
271  vtkEdgeBase(id),
272  Source(s) { }
274 };
275 
277 {
280  vtkEdgeBase(id),
281  Source(s),
282  Target(t) { }
285 };
286 
287 class VTKCOMMONDATAMODEL_EXPORT vtkGraph : public vtkDataObject
288 {
289 public:
290  vtkTypeMacro(vtkGraph, vtkDataObject);
291  void PrintSelf(ostream& os, vtkIndent indent) override;
292 
294 
297  vtkGetObjectMacro(VertexData, vtkDataSetAttributes);
298  vtkGetObjectMacro(EdgeData, vtkDataSetAttributes);
300 
304  int GetDataObjectType() override {return VTK_GRAPH;}
305 
309  void Initialize() override;
310 
312 
318  double *GetPoint(vtkIdType ptId);
319  void GetPoint(vtkIdType ptId, double x[3]);
321 
323 
330  vtkPoints* GetPoints();
331  virtual void SetPoints(vtkPoints *points);
333 
338  void ComputeBounds();
339 
341 
346  double *GetBounds();
347  void GetBounds(double bounds[6]);
349 
353  vtkMTimeType GetMTime() override;
354 
361  virtual void GetOutEdges(vtkIdType v, vtkOutEdgeIterator *it);
362 
369  virtual vtkIdType GetDegree(vtkIdType v);
370 
376  virtual vtkIdType GetOutDegree(vtkIdType v);
377 
381  virtual vtkOutEdgeType GetOutEdge(vtkIdType v, vtkIdType index);
382 
389  virtual void GetOutEdge(vtkIdType v, vtkIdType index, vtkGraphEdge* e);
390 
397  virtual void GetInEdges(vtkIdType v, vtkInEdgeIterator *it);
398 
404  virtual vtkIdType GetInDegree(vtkIdType v);
405 
409  virtual vtkInEdgeType GetInEdge(vtkIdType v, vtkIdType index);
410 
417  virtual void GetInEdge(vtkIdType v, vtkIdType index, vtkGraphEdge* e);
418 
425  virtual void GetAdjacentVertices(vtkIdType v, vtkAdjacentVertexIterator *it);
426 
433  virtual void GetEdges(vtkEdgeListIterator *it);
434 
439  virtual vtkIdType GetNumberOfEdges();
440 
446  virtual void GetVertices(vtkVertexListIterator *it);
447 
452  virtual vtkIdType GetNumberOfVertices();
453 
459  void SetDistributedGraphHelper(vtkDistributedGraphHelper *helper);
460 
464  vtkDistributedGraphHelper *GetDistributedGraphHelper();
465 
474  vtkIdType FindVertex(const vtkVariant& pedigreeID);
475 
480  void ShallowCopy(vtkDataObject *obj) override;
481 
486  void DeepCopy(vtkDataObject *obj) override;
487 
492  virtual void CopyStructure(vtkGraph *g);
493 
499  virtual bool CheckedShallowCopy(vtkGraph *g);
500 
506  virtual bool CheckedDeepCopy(vtkGraph *g);
507 
511  virtual void Squeeze();
512 
514 
518  static vtkGraph *GetData(vtkInformationVector *v, int i=0);
520 
528  void ReorderOutVertices(vtkIdType v, vtkIdTypeArray *vertices);
529 
534  bool IsSameStructure(vtkGraph *other);
535 
537 
546  vtkIdType GetSourceVertex(vtkIdType e);
547  vtkIdType GetTargetVertex(vtkIdType e);
549 
551 
556  void SetEdgePoints(vtkIdType e, vtkIdType npts, const double pts[]) VTK_SIZEHINT(pts, 3 * npts);
557  void GetEdgePoints(vtkIdType e, vtkIdType& npts, double*& pts) VTK_SIZEHINT(pts, 3 * npts);
559 
563  vtkIdType GetNumberOfEdgePoints(vtkIdType e);
564 
568  double* GetEdgePoint(vtkIdType e, vtkIdType i) VTK_SIZEHINT(3);
569 
573  void ClearEdgePoints(vtkIdType e);
574 
580  void SetEdgePoint(vtkIdType e, vtkIdType i, const double x[3]);
581  void SetEdgePoint(vtkIdType e, vtkIdType i, double x, double y, double z)
582  { double p[3] = {x, y, z}; this->SetEdgePoint(e, i, p); }
583 
587  void AddEdgePoint(vtkIdType e, const double x[3]);
588  void AddEdgePoint(vtkIdType e, double x, double y, double z)
589  { double p[3] = {x, y, z}; this->AddEdgePoint(e, p); }
590 
592 
596  void ShallowCopyEdgePoints(vtkGraph* g);
597  void DeepCopyEdgePoints(vtkGraph* g);
599 
605  vtkGraphInternals *GetGraphInternals(bool modifying);
606 
611  void GetInducedEdges(vtkIdTypeArray* verts, vtkIdTypeArray* edges);
612 
620 
624  vtkIdType GetNumberOfElements(int type) override;
625 
629  void Dump();
630 
639  vtkIdType GetEdgeId(vtkIdType a, vtkIdType b);
640 
644  bool ToDirectedGraph(vtkDirectedGraph* g);
645 
649  bool ToUndirectedGraph(vtkUndirectedGraph* g);
650 
651 protected:
652 
653  vtkGraph();
654  ~vtkGraph() override;
655 
663  void AddVertexInternal(vtkVariantArray *propertyArr = nullptr,
664  vtkIdType *vertex = nullptr);
665 
672  void AddVertexInternal(const vtkVariant& pedigree, vtkIdType *vertex);
673 
675 
681  void AddEdgeInternal(vtkIdType u, vtkIdType v, bool directed,
682  vtkVariantArray *propertyArr, vtkEdgeType *edge);
683  void AddEdgeInternal(const vtkVariant& uPedigree, vtkIdType v, bool directed,
684  vtkVariantArray *propertyArr, vtkEdgeType *edge);
685  void AddEdgeInternal(vtkIdType u, const vtkVariant& vPedigree, bool directed,
686  vtkVariantArray *propertyArr, vtkEdgeType *edge);
687  void AddEdgeInternal(const vtkVariant& uPedigree, const vtkVariant& vPedigree,
688  bool directed, vtkVariantArray *propertyArr,
689  vtkEdgeType *edge);
691 
696  void RemoveVertexInternal(vtkIdType v, bool directed);
697 
702  void RemoveEdgeInternal(vtkIdType e, bool directed);
703 
707  void RemoveVerticesInternal(vtkIdTypeArray* arr, bool directed);
708 
712  void RemoveEdgesInternal(vtkIdTypeArray* arr, bool directed);
713 
718  virtual bool IsStructureValid(vtkGraph *g) = 0;
719 
723  virtual void CopyInternal(vtkGraph *g, bool deep);
724 
729 
734 
738  void SetInternals(vtkGraphInternals* internals);
739 
743  vtkGraphEdgePoints *EdgePoints;
744 
748  void SetEdgePoints(vtkGraphEdgePoints* edgePoints);
749 
754  void ForceOwnership();
755 
757 
760  virtual void GetOutEdges(vtkIdType v, const vtkOutEdgeType *& edges, vtkIdType & nedges);
761  virtual void GetInEdges(vtkIdType v, const vtkInEdgeType *& edges, vtkIdType & nedges);
763 
767  void BuildEdgeList();
768 
770 
774  friend class vtkEdgeListIterator;
775  friend class vtkInEdgeIterator;
776  friend class vtkOutEdgeIterator;
781 
783 
789 
793  double Bounds[6];
794 
799 
801 
805  static double DefaultPoint[3];
807 
809 
812  vtkGetObjectMacro(EdgeList, vtkIdTypeArray);
813  virtual void SetEdgeList(vtkIdTypeArray* list);
816 
817 private:
818  vtkGraph(const vtkGraph&) = delete;
819  void operator=(const vtkGraph&) = delete;
820 };
821 
822 bool VTKCOMMONDATAMODEL_EXPORT operator==(vtkEdgeBase e1, vtkEdgeBase e2);
823 bool VTKCOMMONDATAMODEL_EXPORT operator!=(vtkEdgeBase e1, vtkEdgeBase e2);
824 VTKCOMMONDATAMODEL_EXPORT ostream& operator<<(ostream& out, vtkEdgeBase e);
825 
826 #endif
vtkPoints
represent and manipulate 3D points
Definition: vtkPoints.h:39
vtkInEdgeType::vtkInEdgeType
vtkInEdgeType(vtkIdType s, vtkIdType id)
Definition: vtkGraph.h:270
vtkGraph::AddEdgePoint
void AddEdgePoint(vtkIdType e, double x, double y, double z)
Definition: vtkGraph.h:588
vtkEdgeBase::Id
vtkIdType Id
Definition: vtkGraph.h:255
operator<<
VTKCOMMONDATAMODEL_EXPORT ostream & operator<<(ostream &out, vtkEdgeBase e)
vtkGraph::GetDataObjectType
int GetDataObjectType() override
Return what type of dataset this is.
Definition: vtkGraph.h:304
edges
std::pair< boost::graph_traits< vtkGraph * >::edge_iterator, boost::graph_traits< vtkGraph * >::edge_iterator > edges(vtkGraph *g)
Definition: vtkBoostGraphAdapter.h:859
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:77
vtkGraph::Points
vtkPoints * Points
The vertex locations.
Definition: vtkGraph.h:804
vtkUndirectedGraph
An undirected graph.
Definition: vtkUndirectedGraph.h:54
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:516
vtkIdType
int vtkIdType
Definition: vtkType.h:347
VTK_GRAPH
#define VTK_GRAPH
Definition: vtkType.h:111
vtkGraph::Internals
vtkGraphInternals * Internals
The adjacency list internals of this graph.
Definition: vtkGraph.h:728
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:798
vtkDataSetAttributes
represent and manipulate attribute data in a dataset
Definition: vtkDataSetAttributes.h:59
vtkInformationVector
Store zero or more vtkInformation instances.
Definition: vtkInformationVector.h:41
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:35
vtkEdgeBase::vtkEdgeBase
vtkEdgeBase(vtkIdType id)
Definition: vtkGraph.h:253
vtkDirectedGraph
A directed graph.
Definition: vtkDirectedGraph.h:47
boost
Forward declaration required for Boost serialization.
Definition: vtkVariantArray.h:44
vtkInEdgeIterator
Iterates through all incoming edges to a vertex.
Definition: vtkInEdgeIterator.h:48
vtkVariantArray
An array holding vtkVariants.
Definition: vtkVariantArray.h:46
vtkInEdgeType
Definition: vtkGraph.h:267
boost::vtk_out_edge_pointer_iterator
Definition: vtkBoostGraphAdapter.h:318
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:264
vtkEdgeType::Source
vtkIdType Source
Definition: vtkGraph.h:283
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:56
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:786
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:446
vtkGraph::EdgeList
vtkIdTypeArray * EdgeList
Definition: vtkGraph.h:814
vtkOutEdgeType::vtkOutEdgeType
vtkOutEdgeType()
Definition: vtkGraph.h:260
VTK_SIZEHINT
#define VTK_SIZEHINT(...)
Definition: vtkWrappingHints.h:42
vtkOutEdgeType::vtkOutEdgeType
vtkOutEdgeType(vtkIdType t, vtkIdType id)
Definition: vtkGraph.h:261
vtkGraphEdge
Representation of a single graph edge.
Definition: vtkGraphEdge.h:39
vertices
std::pair< boost::graph_traits< vtkGraph * >::vertex_iterator, boost::graph_traits< vtkGraph * >::vertex_iterator > vertices(vtkGraph *g)
Definition: vtkBoostGraphAdapter.h:841
vtkEdgeType::Target
vtkIdType Target
Definition: vtkGraph.h:284
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkCellArray
object to represent cell connectivity
Definition: vtkCellArray.h:50
vtkVariant
A atomic type representing the union of many types.
Definition: vtkVariant.h:71
vtkEdgeListIterator
Iterates through all edges in a graph.
Definition: vtkEdgeListIterator.h:56
vtkOutEdgeIterator
Iterates through all outgoing edges from a vertex.
Definition: vtkOutEdgeIterator.h:51
boost::vtk_in_edge_pointer_iterator
Definition: vtkBoostGraphAdapter.h:355
vtkInEdgeType::Source
vtkIdType Source
Definition: vtkGraph.h:273
vtkGraph::EdgePoints
vtkGraphEdgePoints * EdgePoints
The structure for holding the edge points.
Definition: vtkGraph.h:743
vtkAdjacentVertexIterator
Iterates through adjacent vertices in a graph.
Definition: vtkAdjacentVertexIterator.h:47
vtkEdgeType::vtkEdgeType
vtkEdgeType(vtkIdType s, vtkIdType t, vtkIdType id)
Definition: vtkGraph.h:279
vtkInformation
Store vtkAlgorithm input/output information.
Definition: vtkInformation.h:86
vtkGraph::EdgeData
vtkDataSetAttributes * EdgeData
Definition: vtkGraph.h:787
vtkEdgeBase
Definition: vtkGraph.h:250
vtkX3D::info
Definition: vtkX3D.h:376
vtkIdTypeArray
dynamic, self-adjusting array of vtkIdType
Definition: vtkIdTypeArray.h:41
vtkOutEdgeType
Definition: vtkGraph.h:258
vtkEdgeBase::vtkEdgeBase
vtkEdgeBase()
Definition: vtkGraph.h:252
vtkDataObject.h
vtkEdgeType::vtkEdgeType
vtkEdgeType()
Definition: vtkGraph.h:278
vtkGraph::SetEdgePoint
void SetEdgePoint(vtkIdType e, vtkIdType i, double x, double y, double z)
Definition: vtkGraph.h:581
vtkInEdgeType::vtkInEdgeType
vtkInEdgeType()
Definition: vtkGraph.h:269
vtkGraph::DistributedHelper
vtkDistributedGraphHelper * DistributedHelper
The distributed graph helper.
Definition: vtkGraph.h:733
vtkVertexListIterator
Iterates all vertices in a graph.
Definition: vtkVertexListIterator.h:47
boost::vtk_edge_iterator
Definition: vtkBoostGraphAdapter.h:182
vtkGraph
Base class for graph data types.
Definition: vtkGraph.h:287
vtkDataObject
general representation of visualization data
Definition: vtkDataObject.h:64
vtkX3D::index
Definition: vtkX3D.h:246
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:302