============================================================================ 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
| 79 | // alternatively, edges can also be: |
| 80 | // e u v wt |
| 81 | int 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; |
nothing calls this directly
no test coverage detected