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

Method IsStructureValid

Common/DataModel/vtkUndirectedGraph.cxx:61–111  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

59
60//------------------------------------------------------------------------------
61bool 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//------------------------------------------------------------------------------
114void vtkUndirectedGraph::PrintSelf(ostream& os, vtkIndent indent)

Callers

nothing calls this directly

Calls 7

GetNumberOfVerticesMethod · 0.80
GetOutEdgesMethod · 0.80
NewFunction · 0.50
GetNumberOfEdgesMethod · 0.45
GetInDegreeMethod · 0.45
HasNextMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected