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

Method WriteData

IO/Infovis/vtkDIMACSGraphWriter.cxx:21–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19vtkStandardNewMacro(vtkDIMACSGraphWriter);
20
21void vtkDIMACSGraphWriter::WriteData()
22{
23 vtkGraph* const input = this->GetInput();
24
25 vtkDebugMacro(<< "Writing vtk graph data...");
26
27 ostream* fp = this->OpenVTKFile();
28 if (!fp)
29 {
30 vtkErrorMacro("Failed to open output stream");
31 return;
32 }
33
34 *fp << "c vtkGraph as DIMACS format\n";
35
36 if (vtkDirectedGraph::SafeDownCast(input))
37 {
38 *fp << "c Graph stored as DIRECTED\n";
39 }
40 else
41 {
42 *fp << "c Graph stored as UNDIRECTED\n";
43 }
44
45 const vtkIdType vertex_count = input->GetNumberOfVertices();
46 const vtkIdType edge_count = input->GetNumberOfEdges();
47
48 // Output this 'special' line with the 'problem type' and then
49 // vertex and edge counts
50 *fp << "p graph " << vertex_count << " " << edge_count << "\n";
51
52 // See if the input has a "weight" array
53 vtkDataArray* weight = input->GetEdgeData()->GetArray("weight");
54
55 // Output either the weight array or just 1 if
56 // we have no weight array
57 VTK_CREATE(vtkEdgeListIterator, edges);
58 input->GetEdges(edges);
59 if (weight)
60 {
61 while (edges->HasNext())
62 {
63 vtkEdgeType e = edges->Next();
64 float value = weight->GetTuple1(e.Id);
65 *fp << "e " << e.Source + 1 << " " << e.Target + 1 << " " << value << "\n";
66 }
67 }
68 else
69 {
70 while (edges->HasNext())
71 {
72 vtkEdgeType e = edges->Next();
73 *fp << "e " << e.Source + 1 << " " << e.Target + 1 << " 1\n";
74 }
75 }
76
77 // NOTE: Vertices are incremented by 1 since DIMACS files number vertices
78 // from 1..n.

Callers

nothing calls this directly

Calls 11

GetInputMethod · 0.95
GetNumberOfVerticesMethod · 0.80
GetEdgeDataMethod · 0.80
GetTuple1Method · 0.80
OpenVTKFileMethod · 0.45
GetNumberOfEdgesMethod · 0.45
GetArrayMethod · 0.45
GetEdgesMethod · 0.45
HasNextMethod · 0.45
NextMethod · 0.45
CloseVTKFileMethod · 0.45

Tested by

no test coverage detected