------------------------------------------------------------------------------
| 59 | |
| 60 | //------------------------------------------------------------------------------ |
| 61 | bool vtkUndirectedGraph::IsStructureValid(vtkGraph* g) |
| 62 | { |
| 63 | if (!g) |
| 64 | { |
| 65 | return false; |
| 66 | } |
| 67 | |
| 68 | if (vtkUndirectedGraph::SafeDownCast(g)) |
| 69 | { |
| 70 | return true; |
| 71 | } |
| 72 | |
| 73 | // Verify that there are no in edges and that each edge |
| 74 | // appears in exactly two edge lists. |
| 75 | // Loop edges should be in exactly one edge list. |
| 76 | std::vector<vtkIdType> place(g->GetNumberOfEdges(), -1); |
| 77 | std::vector<vtkIdType> count(g->GetNumberOfEdges(), 0); |
| 78 | vtkSmartPointer<vtkOutEdgeIterator> outIter = vtkSmartPointer<vtkOutEdgeIterator>::New(); |
| 79 | for (vtkIdType v = 0; v < g->GetNumberOfVertices(); ++v) |
| 80 | { |
| 81 | if (g->GetInDegree(v) > 0) |
| 82 | { |
| 83 | return false; |
| 84 | } |
| 85 | g->GetOutEdges(v, outIter); |
| 86 | while (outIter->HasNext()) |
| 87 | { |
| 88 | vtkOutEdgeType e = outIter->Next(); |
| 89 | if (place[e.Id] == v) |
| 90 | { |
| 91 | return false; |
| 92 | } |
| 93 | place[e.Id] = v; |
| 94 | count[e.Id]++; |
| 95 | // Count loops twice so they should all have count == 2 |
| 96 | if (v == e.Target) |
| 97 | { |
| 98 | count[e.Id]++; |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | for (vtkIdType i = 0; i < g->GetNumberOfEdges(); ++i) |
| 103 | { |
| 104 | if (count[i] != 2) |
| 105 | { |
| 106 | return false; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | return true; |
| 111 | } |
| 112 | |
| 113 | //------------------------------------------------------------------------------ |
| 114 | void vtkUndirectedGraph::PrintSelf(ostream& os, vtkIndent indent) |
nothing calls this directly
no test coverage detected