VTK  9.7.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 #include "vtkNew.h" // For vtkNew
206 #include "vtkWrappingHints.h" // For VTK_MARSHALMANUAL
207 
208 // Forward declare some boost stuff even if boost wrappers
209 // are turned off.
210 namespace boost
211 {
212 class vtk_edge_iterator;
213 class vtk_out_edge_pointer_iterator;
214 class vtk_in_edge_pointer_iterator;
215 }
216 
217 VTK_ABI_NAMESPACE_BEGIN
219 class vtkCellArray;
220 class vtkEdgeListIterator;
222 class vtkDirectedGraph;
223 class vtkGraphEdge;
224 class vtkGraphEdgePoints;
226 class vtkGraphInternals;
227 class vtkIdTypeArray;
228 class vtkInEdgeIterator;
229 class vtkOutEdgeIterator;
230 class vtkPoints;
231 class vtkUndirectedGraph;
233 class vtkVariant;
234 class vtkVariantArray;
235 
236 // Edge structures.
238 {
239  vtkEdgeBase() = default;
241  : Id(id)
242  {
243  }
245 };
246 
248 {
249  vtkOutEdgeType() = default;
251  : vtkEdgeBase(id)
252  , Target(t)
253  {
254  }
256 };
257 
259 {
260  vtkInEdgeType() = default;
262  : vtkEdgeBase(id)
263  , Source(s)
264  {
265  }
267 };
268 
270 {
271  vtkEdgeType() = default;
273  : vtkEdgeBase(id)
274  , Source(s)
275  , Target(t)
276  {
277  }
280 };
281 
282 class VTKCOMMONDATAMODEL_EXPORT VTK_MARSHALMANUAL vtkGraph : public vtkDataObject
283 {
284 public:
285  vtkTypeMacro(vtkGraph, vtkDataObject);
286  void PrintSelf(ostream& os, vtkIndent indent) override;
287 
289 
292  vtkGetObjectMacro(VertexData, vtkDataSetAttributes);
293  vtkGetObjectMacro(EdgeData, vtkDataSetAttributes);
295 
299  int GetDataObjectType() VTK_FUTURE_CONST override { return VTK_GRAPH; }
300 
304  void Initialize() override;
305 
307 
313  double* GetPoint(vtkIdType ptId);
314  void GetPoint(vtkIdType ptId, double x[3]);
316 
318 
325  vtkPoints* GetPoints();
326  virtual void SetPoints(vtkPoints* points);
328 
333  void ComputeBounds();
334 
336 
341  double* GetBounds();
342  void GetBounds(double bounds[6]);
344 
348  vtkMTimeType GetMTime() override;
349 
356  virtual void GetOutEdges(vtkIdType v, vtkOutEdgeIterator* it);
357 
364  virtual vtkIdType GetDegree(vtkIdType v);
365 
371  virtual vtkIdType GetOutDegree(vtkIdType v);
372 
376  virtual vtkOutEdgeType GetOutEdge(vtkIdType v, vtkIdType index);
377 
384  virtual void GetOutEdge(vtkIdType v, vtkIdType index, vtkGraphEdge* e);
385 
392  virtual void GetInEdges(vtkIdType v, vtkInEdgeIterator* it);
393 
399  virtual vtkIdType GetInDegree(vtkIdType v);
400 
404  virtual vtkInEdgeType GetInEdge(vtkIdType v, vtkIdType index);
405 
412  virtual void GetInEdge(vtkIdType v, vtkIdType index, vtkGraphEdge* e);
413 
420  virtual void GetAdjacentVertices(vtkIdType v, vtkAdjacentVertexIterator* it);
421 
428  virtual void GetEdges(vtkEdgeListIterator* it);
429 
434  virtual vtkIdType GetNumberOfEdges();
435 
441  virtual void GetVertices(vtkVertexListIterator* it);
442 
447  virtual vtkIdType GetNumberOfVertices();
448 
454  void SetDistributedGraphHelper(vtkDistributedGraphHelper* helper);
455 
459  vtkDistributedGraphHelper* GetDistributedGraphHelper();
460 
469  vtkIdType FindVertex(const vtkVariant& pedigreeID);
470 
475  void ShallowCopy(vtkDataObject* obj) override;
476 
481  void DeepCopy(vtkDataObject* obj) override;
482 
487  virtual void CopyStructure(vtkGraph* g);
488 
494  virtual bool CheckedShallowCopy(vtkGraph* g);
495 
501  virtual bool CheckedDeepCopy(vtkGraph* g);
502 
506  virtual void Squeeze();
507 
515  unsigned long GetActualMemorySize() override;
516 
518 
522  static vtkGraph* GetData(vtkInformationVector* v, int i = 0);
524 
532  void ReorderOutVertices(vtkIdType v, vtkIdTypeArray* vertices);
533 
538  bool IsSameStructure(vtkGraph* other);
539 
541 
550  vtkIdType GetSourceVertex(vtkIdType e);
551  vtkIdType GetTargetVertex(vtkIdType e);
553 
555 
560  void SetEdgePoints(vtkIdType e, vtkIdType npts, const double pts[]) VTK_SIZEHINT(pts, 3 * npts);
561  void GetEdgePoints(vtkIdType e, vtkIdType& npts, double*& pts) VTK_SIZEHINT(pts, 3 * npts);
563 
567  vtkIdType GetNumberOfEdgePoints(vtkIdType e);
568 
572  double* GetEdgePoint(vtkIdType e, vtkIdType i) VTK_SIZEHINT(3);
573 
577  void ClearEdgePoints(vtkIdType e);
578 
584  void SetEdgePoint(vtkIdType e, vtkIdType i, const double x[3]);
585  void SetEdgePoint(vtkIdType e, vtkIdType i, double x, double y, double z)
586  {
587  double p[3] = { x, y, z };
588  this->SetEdgePoint(e, i, p);
589  }
590 
594  void AddEdgePoint(vtkIdType e, const double x[3]);
595  void AddEdgePoint(vtkIdType e, double x, double y, double z)
596  {
597  double p[3] = { x, y, z };
598  this->AddEdgePoint(e, p);
599  }
600 
602 
606  void ShallowCopyEdgePoints(vtkGraph* g);
607  void DeepCopyEdgePoints(vtkGraph* g);
609 
615  vtkGraphInternals* GetGraphInternals(bool modifying);
616 
621  void GetInducedEdges(vtkIdTypeArray* verts, vtkIdTypeArray* edges);
622 
630 
634  vtkIdType GetNumberOfElements(int type) override;
635 
639  void Dump();
640 
649  vtkIdType GetEdgeId(vtkIdType a, vtkIdType b);
650 
654  bool ToDirectedGraph(vtkDirectedGraph* g);
655 
659  bool ToUndirectedGraph(vtkUndirectedGraph* g);
660 
661 protected:
662  vtkGraph();
663  ~vtkGraph() override;
664 
672  void AddVertexInternal(vtkVariantArray* propertyArr = nullptr, vtkIdType* vertex = nullptr);
673 
680  void AddVertexInternal(const vtkVariant& pedigree, vtkIdType* vertex);
681 
683 
689  void AddEdgeInternal(
690  vtkIdType u, vtkIdType v, bool directed, vtkVariantArray* propertyArr, vtkEdgeType* edge);
691  void AddEdgeInternal(const vtkVariant& uPedigree, vtkIdType v, bool directed,
692  vtkVariantArray* propertyArr, vtkEdgeType* edge);
693  void AddEdgeInternal(vtkIdType u, const vtkVariant& vPedigree, bool directed,
694  vtkVariantArray* propertyArr, vtkEdgeType* edge);
695  void AddEdgeInternal(const vtkVariant& uPedigree, const vtkVariant& vPedigree, bool directed,
696  vtkVariantArray* propertyArr, vtkEdgeType* edge);
698 
703  void RemoveVertexInternal(vtkIdType v, bool directed);
704 
709  void RemoveEdgeInternal(vtkIdType e, bool directed);
710 
714  void RemoveVerticesInternal(vtkIdTypeArray* arr, bool directed);
715 
719  void RemoveEdgesInternal(vtkIdTypeArray* arr, bool directed);
720 
725  virtual bool IsStructureValid(vtkGraph* g) = 0;
726 
730  virtual void CopyInternal(vtkGraph* g, bool deep);
731 
736 
741 
745  void SetInternals(vtkGraphInternals* internals);
746 
750  vtkGraphEdgePoints* EdgePoints;
751 
755  void SetEdgePoints(vtkGraphEdgePoints* edgePoints);
756 
761  void ForceOwnership();
762 
764 
767  virtual void GetOutEdges(vtkIdType v, const vtkOutEdgeType*& edges, vtkIdType& nedges);
768  virtual void GetInEdges(vtkIdType v, const vtkInEdgeType*& edges, vtkIdType& nedges);
770 
774  void BuildEdgeList();
775 
777 
781  friend class vtkEdgeListIterator;
782  friend class vtkInEdgeIterator;
783  friend class vtkOutEdgeIterator;
788 
790 
796 
800  double Bounds[6];
801 
806 
808 
812  static double DefaultPoint[3];
814 
816 
819  vtkGetObjectMacro(EdgeList, vtkIdTypeArray);
820  virtual void SetEdgeList(vtkIdTypeArray* list);
823 
824 private:
825  vtkGraph(const vtkGraph&) = delete;
826  void operator=(const vtkGraph&) = delete;
827 };
828 
829 bool VTKCOMMONDATAMODEL_EXPORT operator==(vtkEdgeBase e1, vtkEdgeBase e2);
830 bool VTKCOMMONDATAMODEL_EXPORT operator!=(vtkEdgeBase e1, vtkEdgeBase e2);
831 VTKCOMMONDATAMODEL_EXPORT ostream& operator<<(ostream& out, vtkEdgeBase e);
832 
833 VTK_ABI_NAMESPACE_END
834 #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.
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:821
Store vtkAlgorithm input/output information.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:318
Iterates through adjacent vertices in a graph.
int GetDataObjectType() VTK_FUTURE_CONST override
Return what type of dataset this is.
Definition: vtkGraph.h:299
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
vtkNew< vtkDataSetAttributes > EdgeData
The vertex and edge data.
Definition: vtkGraph.h:794
vtkEdgeBase(vtkIdType id)
Definition: vtkGraph.h:240
virtual void Initialize()
Restore data object to initial state,.
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:363
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:740
vtkTimeStamp ComputeTime
Time at which bounds were computed.
Definition: vtkGraph.h:805
A type representing the union of many types.
Definition: vtkVariant.h:52
A directed graph.
Base class for graph data types.
Definition: vtkGraph.h:282
#define VTK_MARSHALMANUAL
bool VTKCOMMONDATAMODEL_EXPORT operator==(vtkEdgeBase e1, vtkEdgeBase e2)
vtkIdType Source
Definition: vtkGraph.h:278
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:750
void SetEdgePoint(vtkIdType e, vtkIdType i, double x, double y, double z)
Definition: vtkGraph.h:585
vtkNew< vtkDataSetAttributes > VertexData
The vertex and edge data.
Definition: vtkGraph.h:793
vtkEdgeType()=default
Iterates through all incoming edges to a vertex.
Internal representation of vtkGraph.
vtkIdType Id
Definition: vtkGraph.h:244
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:255
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:811
object to represent cell connectivity
Definition: vtkCellArray.h:177
void GetPoint(int i, int j, int k, double pnt[3])
vtkIdType Source
Definition: vtkGraph.h:266
Iterates all vertices in a graph.
vtkOutEdgeType(vtkIdType t, vtkIdType id)
Definition: vtkGraph.h:250
Store zero or more vtkInformation instances.
vtkGraphInternals * Internals
The adjacency list internals of this graph.
Definition: vtkGraph.h:735
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:55
vtkInEdgeType(vtkIdType s, vtkIdType id)
Definition: vtkGraph.h:261
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:272
vtkIdType Target
Definition: vtkGraph.h:279
represent and manipulate 3D points
Definition: vtkPoints.h:30
void AddEdgePoint(vtkIdType e, double x, double y, double z)
Definition: vtkGraph.h:595
virtual void ShallowCopy(vtkDataObject *src)
The goal of the method is to copy the data up to the array pointers only.
Represents and manipulates a collection of data arrays.
Definition: vtkFieldData.h:51
std::pair< boost::graph_traits< vtkGraph * >::edge_iterator, boost::graph_traits< vtkGraph * >::edge_iterator > edges(vtkGraph *g)