1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkMutableDirectedGraph.cxx
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 -------------------------------------------------------------------------*/
20
21 #include "vtkMutableDirectedGraph.h"
22
23 #include "vtkDataSetAttributes.h"
24 #include "vtkGraphEdge.h"
25 #include "vtkGraphInternals.h"
26 #include "vtkObjectFactory.h"
27
28 //------------------------------------------------------------------------------
29 // class vtkMutableDirectedGraph
30 //------------------------------------------------------------------------------
31 vtkStandardNewMacro(vtkMutableDirectedGraph);
32 //------------------------------------------------------------------------------
vtkMutableDirectedGraph()33 vtkMutableDirectedGraph::vtkMutableDirectedGraph()
34 {
35 this->GraphEdge = vtkGraphEdge::New();
36 }
37
38 //------------------------------------------------------------------------------
~vtkMutableDirectedGraph()39 vtkMutableDirectedGraph::~vtkMutableDirectedGraph()
40 {
41 this->GraphEdge->Delete();
42 }
43
44 //------------------------------------------------------------------------------
SetNumberOfVertices(vtkIdType numVerts)45 vtkIdType vtkMutableDirectedGraph::SetNumberOfVertices(vtkIdType numVerts)
46 {
47 vtkIdType retval = -1;
48
49 if (this->GetDistributedGraphHelper())
50 {
51 vtkWarningMacro("SetNumberOfVertices will not work on distributed graphs.");
52 return retval;
53 }
54
55 retval = static_cast<vtkIdType>(this->Internals->Adjacency.size());
56 this->Internals->Adjacency.resize(numVerts);
57 return retval;
58 }
59
60 //------------------------------------------------------------------------------
AddVertex()61 vtkIdType vtkMutableDirectedGraph::AddVertex()
62 {
63 if (this->Internals->UsingPedigreeIds && this->GetDistributedGraphHelper() != nullptr)
64 {
65 vtkErrorMacro("Adding vertex without a pedigree ID into a distributed graph that uses pedigree "
66 "IDs to name vertices");
67 }
68
69 return this->AddVertex(nullptr);
70 }
71 //------------------------------------------------------------------------------
AddVertex(vtkVariantArray * propertyArr)72 vtkIdType vtkMutableDirectedGraph::AddVertex(vtkVariantArray* propertyArr)
73 {
74 if (this->GetVertexData()->GetPedigreeIds() != nullptr)
75 {
76 this->Internals->UsingPedigreeIds = true;
77 }
78
79 vtkIdType vertex;
80 this->AddVertexInternal(propertyArr, &vertex);
81 return vertex;
82 }
83
84 //------------------------------------------------------------------------------
AddVertex(const vtkVariant & pedigreeId)85 vtkIdType vtkMutableDirectedGraph::AddVertex(const vtkVariant& pedigreeId)
86 {
87 this->Internals->UsingPedigreeIds = true;
88
89 vtkIdType vertex;
90 this->AddVertexInternal(pedigreeId, &vertex);
91 return vertex;
92 }
93
94 //------------------------------------------------------------------------------
AddEdge(vtkIdType u,vtkIdType v)95 vtkEdgeType vtkMutableDirectedGraph::AddEdge(vtkIdType u, vtkIdType v)
96 {
97 return this->AddEdge(u, v, nullptr);
98 }
99
100 //------------------------------------------------------------------------------
AddEdge(vtkIdType u,vtkIdType v,vtkVariantArray * propertyArr)101 vtkEdgeType vtkMutableDirectedGraph::AddEdge(vtkIdType u, vtkIdType v, vtkVariantArray* propertyArr)
102 {
103 vtkEdgeType e;
104 this->AddEdgeInternal(u, v, true, propertyArr, &e);
105 return e;
106 }
107
108 //------------------------------------------------------------------------------
AddEdge(const vtkVariant & u,vtkIdType v,vtkVariantArray * propertyArr)109 vtkEdgeType vtkMutableDirectedGraph::AddEdge(
110 const vtkVariant& u, vtkIdType v, vtkVariantArray* propertyArr)
111 {
112 this->Internals->UsingPedigreeIds = true;
113
114 vtkEdgeType e;
115 this->AddEdgeInternal(u, v, true, propertyArr, &e);
116 return e;
117 }
118
119 //------------------------------------------------------------------------------
AddEdge(vtkIdType u,const vtkVariant & v,vtkVariantArray * propertyArr)120 vtkEdgeType vtkMutableDirectedGraph::AddEdge(
121 vtkIdType u, const vtkVariant& v, vtkVariantArray* propertyArr)
122 {
123 this->Internals->UsingPedigreeIds = true;
124
125 vtkEdgeType e;
126 this->AddEdgeInternal(u, v, true, propertyArr, &e);
127 return e;
128 }
129
130 //------------------------------------------------------------------------------
AddEdge(const vtkVariant & u,const vtkVariant & v,vtkVariantArray * propertyArr)131 vtkEdgeType vtkMutableDirectedGraph::AddEdge(
132 const vtkVariant& u, const vtkVariant& v, vtkVariantArray* propertyArr)
133 {
134 this->Internals->UsingPedigreeIds = true;
135
136 vtkEdgeType e;
137 this->AddEdgeInternal(u, v, true, propertyArr, &e);
138 return e;
139 }
140
141 //------------------------------------------------------------------------------
LazyAddVertex()142 void vtkMutableDirectedGraph::LazyAddVertex()
143 {
144 if (this->Internals->UsingPedigreeIds && this->GetDistributedGraphHelper() != nullptr)
145 {
146 vtkErrorMacro("Adding vertex without a pedigree ID into a distributed graph that uses pedigree "
147 "IDs to name vertices");
148 }
149
150 this->LazyAddVertex(nullptr);
151 }
152 //------------------------------------------------------------------------------
LazyAddVertex(vtkVariantArray * propertyArr)153 void vtkMutableDirectedGraph::LazyAddVertex(vtkVariantArray* propertyArr)
154 {
155 if (this->GetVertexData()->GetPedigreeIds() != nullptr)
156 {
157 this->Internals->UsingPedigreeIds = true;
158 }
159
160 this->AddVertexInternal(propertyArr, nullptr);
161 }
162
163 //------------------------------------------------------------------------------
LazyAddVertex(const vtkVariant & pedigreeId)164 void vtkMutableDirectedGraph::LazyAddVertex(const vtkVariant& pedigreeId)
165 {
166 this->Internals->UsingPedigreeIds = true;
167
168 this->AddVertexInternal(pedigreeId, nullptr);
169 }
170
171 //------------------------------------------------------------------------------
LazyAddEdge(vtkIdType u,vtkIdType v,vtkVariantArray * propertyArr)172 void vtkMutableDirectedGraph::LazyAddEdge(vtkIdType u, vtkIdType v, vtkVariantArray* propertyArr)
173 {
174 this->AddEdgeInternal(u, v, true, propertyArr, nullptr);
175 }
176
177 //------------------------------------------------------------------------------
LazyAddEdge(const vtkVariant & u,vtkIdType v,vtkVariantArray * propertyArr)178 void vtkMutableDirectedGraph::LazyAddEdge(
179 const vtkVariant& u, vtkIdType v, vtkVariantArray* propertyArr)
180 {
181 this->Internals->UsingPedigreeIds = true;
182
183 this->AddEdgeInternal(u, v, true, propertyArr, nullptr);
184 }
185
186 //------------------------------------------------------------------------------
LazyAddEdge(vtkIdType u,const vtkVariant & v,vtkVariantArray * propertyArr)187 void vtkMutableDirectedGraph::LazyAddEdge(
188 vtkIdType u, const vtkVariant& v, vtkVariantArray* propertyArr)
189 {
190 this->Internals->UsingPedigreeIds = true;
191
192 this->AddEdgeInternal(u, v, true, propertyArr, nullptr);
193 }
194
195 //------------------------------------------------------------------------------
LazyAddEdge(const vtkVariant & u,const vtkVariant & v,vtkVariantArray * propertyArr)196 void vtkMutableDirectedGraph::LazyAddEdge(
197 const vtkVariant& u, const vtkVariant& v, vtkVariantArray* propertyArr)
198 {
199 this->Internals->UsingPedigreeIds = true;
200
201 this->AddEdgeInternal(u, v, true, propertyArr, nullptr);
202 }
203
204 //------------------------------------------------------------------------------
AddGraphEdge(vtkIdType u,vtkIdType v)205 vtkGraphEdge* vtkMutableDirectedGraph::AddGraphEdge(vtkIdType u, vtkIdType v)
206 {
207 vtkEdgeType e = this->AddEdge(u, v);
208 this->GraphEdge->SetSource(e.Source);
209 this->GraphEdge->SetTarget(e.Target);
210 this->GraphEdge->SetId(e.Id);
211 return this->GraphEdge;
212 }
213
214 //------------------------------------------------------------------------------
AddChild(vtkIdType parent,vtkVariantArray * propertyArr)215 vtkIdType vtkMutableDirectedGraph::AddChild(vtkIdType parent, vtkVariantArray* propertyArr /* = 0*/)
216 {
217 vtkIdType v = this->AddVertex();
218 this->AddEdge(parent, v, propertyArr);
219 return v;
220 }
221
222 //------------------------------------------------------------------------------
RemoveVertex(vtkIdType v)223 void vtkMutableDirectedGraph::RemoveVertex(vtkIdType v)
224 {
225 this->RemoveVertexInternal(v, true);
226 }
227
228 //------------------------------------------------------------------------------
RemoveEdge(vtkIdType e)229 void vtkMutableDirectedGraph::RemoveEdge(vtkIdType e)
230 {
231 this->RemoveEdgeInternal(e, true);
232 }
233
234 //------------------------------------------------------------------------------
RemoveVertices(vtkIdTypeArray * arr)235 void vtkMutableDirectedGraph::RemoveVertices(vtkIdTypeArray* arr)
236 {
237 this->RemoveVerticesInternal(arr, true);
238 }
239
240 //------------------------------------------------------------------------------
RemoveEdges(vtkIdTypeArray * arr)241 void vtkMutableDirectedGraph::RemoveEdges(vtkIdTypeArray* arr)
242 {
243 this->RemoveEdgesInternal(arr, true);
244 }
245
246 //------------------------------------------------------------------------------
PrintSelf(ostream & os,vtkIndent indent)247 void vtkMutableDirectedGraph::PrintSelf(ostream& os, vtkIndent indent)
248 {
249 this->Superclass::PrintSelf(os, indent);
250 }
251