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

Method RequestData

Infovis/Core/vtkCollapseGraph.cxx:104–192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102}
103
104int vtkCollapseGraph::RequestData(vtkInformation* vtkNotUsed(request),
105 vtkInformationVector** inputVector, vtkInformationVector* outputVector)
106{
107 // Ensure we have valid inputs ...
108 vtkGraph* const input_graph = vtkGraph::GetData(inputVector[0]);
109 vtkGraph* const output_graph = vtkGraph::GetData(outputVector);
110
111 vtkSmartPointer<vtkIdTypeArray> input_indices = vtkSmartPointer<vtkIdTypeArray>::New();
112 vtkConvertSelection::GetSelectedVertices(
113 vtkSelection::GetData(inputVector[1]), input_graph, input_indices);
114
115 // Convert the input selection into an "expanding" array that contains "true" for each
116 // vertex that is expanding (i.e. its neighbors are collapsing into it)
117 std::vector<bool> expanding(input_graph->GetNumberOfVertices(), false);
118
119 for (vtkIdType i = 0; i != input_indices->GetNumberOfTuples(); ++i)
120 {
121 expanding[input_indices->GetValue(i)] = true;
122 }
123
124 // Create a mapping from each child vertex to its expanding neighbor (if any)
125 std::vector<vtkIdType> parent(input_graph->GetNumberOfVertices());
126 vtkSmartPointer<vtkInEdgeIterator> in_edge_iterator = vtkSmartPointer<vtkInEdgeIterator>::New();
127 for (vtkIdType vertex = 0; vertex != input_graph->GetNumberOfVertices(); ++vertex)
128 {
129 // By default, vertices map to themselves, i.e: they aren't collapsed
130 parent[vertex] = vertex;
131
132 if (expanding[vertex])
133 continue;
134
135 input_graph->GetInEdges(vertex, in_edge_iterator);
136 while (in_edge_iterator->HasNext())
137 {
138 const vtkIdType adjacent_vertex = in_edge_iterator->Next().Source;
139 if (expanding[adjacent_vertex])
140 {
141 parent[vertex] = adjacent_vertex;
142 break;
143 }
144 }
145 }
146
147 // Create a mapping from vertex IDs in the original graph to vertex IDs in the output graph
148 std::vector<vtkIdType> vertex_map(input_graph->GetNumberOfVertices(), -1);
149 for (vtkIdType old_vertex = 0, new_vertex = 0; old_vertex != input_graph->GetNumberOfVertices();
150 ++old_vertex)
151 {
152 if (parent[old_vertex] != old_vertex)
153 continue;
154
155 vertex_map[old_vertex] = new_vertex++;
156 }
157
158 // Create a new edge list, mapping each edge from children to parents, eliminating duplicates as
159 // we go
160 EdgeListT edge_list;
161

Callers

nothing calls this directly

Calls 10

GetNumberOfVerticesMethod · 0.80
GetDataFunction · 0.50
NewFunction · 0.50
GetNumberOfTuplesMethod · 0.45
GetValueMethod · 0.45
GetInEdgesMethod · 0.45
HasNextMethod · 0.45
NextMethod · 0.45
GetEdgesMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected