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

Method buildGenericGraph

IO/Infovis/vtkDIMACSGraphReader.cxx:81–188  ·  view source on GitHub ↗

============================================================================ Generic DIMACS file format, which covers many 'DIMACS' style input files. This is the default reader if we don't have a special case file. Graphs are undirected. node lines (optional) have a weight value and are formatted as: n id wt Though, technically, some DIMACS formats (i.e., shortest paths) don't specify node-attrib

Source from the content-addressed store, hash-verified

79// alternatively, edges can also be:
80// e u v wt
81int vtkDIMACSGraphReader::buildGenericGraph(vtkGraph* output,
82 vtkStdString& defaultVertexAttrArrayName, vtkStdString& defaultEdgeAttrArrayName)
83{
84 std::string S;
85 int iEdgeU, iEdgeV, iVertexID;
86 int currentEdgeId = 0;
87
88 VTK_CREATE(vtkMutableUndirectedGraph, builder);
89 VTK_CREATE(vtkIntArray, ArrayVertexAttributes);
90 VTK_CREATE(vtkIntArray, ArrayEdgeAttributes);
91
92 VTK_CREATE(vtkIntArray, vertexPedigreeIds);
93 VTK_CREATE(vtkIntArray, edgePedigreeIds);
94
95 // Set up vertex attribute array for vertex-weights.
96 if (this->VertexAttributeArrayName)
97 {
98 ArrayVertexAttributes->SetName(this->VertexAttributeArrayName);
99 }
100 else
101 {
102 ArrayVertexAttributes->SetName(defaultVertexAttrArrayName.c_str());
103 }
104 ArrayVertexAttributes->SetNumberOfTuples(this->numVerts);
105
106 // Set up Edge attribute array for edge-weights.
107 if (this->EdgeAttributeArrayName)
108 {
109 ArrayEdgeAttributes->SetName(this->EdgeAttributeArrayName);
110 }
111 else
112 {
113 ArrayEdgeAttributes->SetName(defaultEdgeAttrArrayName.c_str());
114 }
115 ArrayEdgeAttributes->SetNumberOfTuples(this->numEdges);
116
117 // Set up Pedigree-IDs arrays.
118 vertexPedigreeIds->SetName("vertex id");
119 vertexPedigreeIds->SetNumberOfTuples(this->numVerts);
120 edgePedigreeIds->SetName("edge id");
121 edgePedigreeIds->SetNumberOfTuples(this->numEdges);
122
123 // Allocate Vertices in the graph builder
124 for (int i = 0; i < this->numVerts; i++)
125 {
126 builder->AddVertex();
127 vertexPedigreeIds->SetValue(i, i + 1);
128 }
129
130 // set starting edge id number.
131 int baseEdgeId = 1;
132
133 vtksys::ifstream IFP(this->FileName);
134 if (IFP.is_open())
135 {
136 while (vtksys::SystemTools::GetLineFromStream(IFP, S))
137 {
138 int value;

Callers

nothing calls this directly

Calls 13

GetLineFromStreamFunction · 0.85
is_openMethod · 0.80
SetPedigreeIdsMethod · 0.80
GetVertexDataMethod · 0.80
GetEdgeDataMethod · 0.80
SetNameMethod · 0.45
c_strMethod · 0.45
SetNumberOfTuplesMethod · 0.45
AddVertexMethod · 0.45
SetValueMethod · 0.45
AddEdgeMethod · 0.45
AddArrayMethod · 0.45

Tested by

no test coverage detected