MCPcopy Create free account
hub / github.com/Kitware/VTK / ExtendGraph

Method ExtendGraph

Infovis/Core/vtkMergeGraphs.cxx:156–252  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

154
155//------------------------------------------------------------------------------
156int vtkMergeGraphs::ExtendGraph(vtkMutableGraphHelper* builder, vtkGraph* graph2)
157{
158 vtkAbstractArray* ped_ids1 = builder->GetGraph()->GetVertexData()->GetPedigreeIds();
159 if (!ped_ids1)
160 {
161 vtkErrorMacro("First graph must have pedigree ids");
162 return 0;
163 }
164
165 vtkAbstractArray* ped_ids2 = graph2->GetVertexData()->GetPedigreeIds();
166 if (!ped_ids1)
167 {
168 vtkErrorMacro("Second graph must have pedigree ids");
169 return 0;
170 }
171
172 // Find matching vertex arrays
173 std::map<vtkAbstractArray*, vtkAbstractArray*> vert_array_map;
174 vtkDataSetAttributes* vert_data1 = builder->GetGraph()->GetVertexData();
175 vtkMergeGraphsCreateArrayMapping(vert_array_map, vert_data1, graph2->GetVertexData());
176
177 // Find graph1 vertices matching graph2's pedigree ids
178 vtkIdType n2 = graph2->GetNumberOfVertices();
179 std::vector<vtkIdType> graph2_to_graph1(n2);
180 for (vtkIdType vert2 = 0; vert2 < n2; ++vert2)
181 {
182 vtkIdType vert1 = ped_ids1->LookupValue(ped_ids2->GetVariantValue(vert2));
183 if (vert1 == -1)
184 {
185 vert1 = builder->AddVertex();
186 vtkMergeGraphsAddRow(vert_data1, vert2, vert_array_map);
187 }
188 graph2_to_graph1[vert2] = vert1;
189 }
190
191 // Find matching edge arrays
192 std::map<vtkAbstractArray*, vtkAbstractArray*> edge_array_map;
193 vtkDataSetAttributes* edge_data1 = builder->GetGraph()->GetEdgeData();
194 vtkMergeGraphsCreateArrayMapping(edge_array_map, edge_data1, graph2->GetEdgeData());
195
196 // For each edge in graph2, add it to the output
197 vtkSmartPointer<vtkEdgeListIterator> it = vtkSmartPointer<vtkEdgeListIterator>::New();
198 graph2->GetEdges(it);
199 while (it->HasNext())
200 {
201 vtkEdgeType e = it->Next();
202 vtkIdType source = graph2_to_graph1[e.Source];
203 vtkIdType target = graph2_to_graph1[e.Target];
204 if (source != -1 && target != -1)
205 {
206 builder->AddEdge(source, target);
207 vtkMergeGraphsAddRow(edge_data1, e.Id, edge_array_map);
208 }
209 }
210
211 // Remove edges if using an edge window.
212 if (this->UseEdgeWindow)
213 {

Callers 2

RequestDataMethod · 0.95
RequestDataMethod · 0.80

Calls 15

vtkMergeGraphsAddRowFunction · 0.85
GetPedigreeIdsMethod · 0.80
GetVertexDataMethod · 0.80
GetGraphMethod · 0.80
GetNumberOfVerticesMethod · 0.80
GetEdgeDataMethod · 0.80
GetAbstractArrayMethod · 0.80
GetTuple1Method · 0.80
NewFunction · 0.50
minFunction · 0.50
maxFunction · 0.50

Tested by

no test coverage detected