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