/usr/share/vtk/IO/Cxx/DumpXMLFile.cxx is in vtk-examples 5.8.0-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | //
// DumpXMLFile - report on the contents of an XML or legacy vtk file
// Usage: DumpXMLFile XMLFile1 XMLFile2 ...
// where
// XMLFile is a vtk XML file of type .vtu, .vtp, .vts, .vtr,
// .vti, .vto
//
#include <vtkSmartPointer.h>
#include <vtkXMLReader.h>
#include <vtkXMLUnstructuredGridReader.h>
#include <vtkXMLPolyDataReader.h>
#include <vtkXMLStructuredGridReader.h>
#include <vtkXMLRectilinearGridReader.h>
#include <vtkXMLHyperOctreeReader.h>
#include <vtkXMLCompositeDataReader.h>
#include <vtkXMLStructuredGridReader.h>
#include <vtkXMLImageDataReader.h>
#include <vtkDataSetReader.h>
#include <vtkDataSet.h>
#include <vtkUnstructuredGrid.h>
#include <vtkRectilinearGrid.h>
#include <vtkHyperOctree.h>
#include <vtkImageData.h>
#include <vtkPolyData.h>
#include <vtkStructuredGrid.h>
#include <vtkPointData.h>
#include <vtkCellData.h>
#include <vtkFieldData.h>
#include <vtkCellTypes.h>
#include <vtksys/SystemTools.hxx>
#include <vtkstd/map>
template<class TReader> vtkDataSet *ReadAnXMLFile(const char*fileName)
{
vtkSmartPointer<TReader> reader =
vtkSmartPointer<TReader>::New();
reader->SetFileName(fileName);
reader->Update();
reader->GetOutput()->Register(reader);
return vtkDataSet::SafeDownCast(reader->GetOutput());
}
int main (int argc, char *argv[])
{
if (argc < 2)
{
std::cerr << "Usage: " << argv[0] << " XMLFile1 XMLFile2 ..." << std::endl;
}
// Process each file on the command line
int f = 1;
while (f < argc)
{
vtkDataSet *dataSet;
std::string extension =
vtksys::SystemTools::GetFilenameLastExtension(argv[f]);
// Dispatch based on the file extension
if (extension == ".vtu")
{
dataSet = ReadAnXMLFile<vtkXMLUnstructuredGridReader> (argv[f]);
}
else if (extension == ".vtp")
{
dataSet = ReadAnXMLFile<vtkXMLPolyDataReader> (argv[f]);
}
else if (extension == ".vts")
{
dataSet = ReadAnXMLFile<vtkXMLStructuredGridReader> (argv[f]);
}
else if (extension == ".vtr")
{
dataSet = ReadAnXMLFile<vtkXMLRectilinearGridReader> (argv[f]);
}
else if (extension == ".vti")
{
dataSet = ReadAnXMLFile<vtkXMLImageDataReader> (argv[f]);
}
else if (extension == ".vto")
{
dataSet = ReadAnXMLFile<vtkXMLHyperOctreeReader> (argv[f]);
}
else if (extension == ".vtk")
{
dataSet = ReadAnXMLFile<vtkDataSetReader> (argv[f]);
}
else
{
std::cerr << argv[0] << " Unknown extenstion: " << extension << std::endl;
return EXIT_FAILURE;
}
int numberOfCells = dataSet->GetNumberOfCells();
int numberOfPoints = dataSet->GetNumberOfPoints();
// Generate a report
std::cout << "------------------------" << std::endl;
std::cout << argv[f] << std::endl
<< " contains a " << std::endl
<< dataSet->GetClassName()
<< " that has " << numberOfCells << " cells"
<< " and " << numberOfPoints << " points." << std::endl;
typedef vtkstd::map<int,int> CellContainer;
CellContainer cellMap;
for (int i = 0; i < numberOfCells; i++)
{
cellMap[dataSet->GetCellType(i)]++;
}
CellContainer::const_iterator it = cellMap.begin();
while (it != cellMap.end())
{
std::cout << "\tCell type "
<< vtkCellTypes::GetClassNameFromTypeId(it->first)
<< " occurs " << it->second << " times." << std::endl;
++it;
}
// Now check for point data
vtkPointData *pd = dataSet->GetPointData();
if (pd)
{
std::cout << " contains point data with "
<< pd->GetNumberOfArrays()
<< " arrays." << std::endl;
for (int i = 0; i < pd->GetNumberOfArrays(); i++)
{
std::cout << "\tArray " << i
<< " is named "
<< (pd->GetArrayName(i) ? pd->GetArrayName(i) : "NULL")
<< std::endl;
}
}
// Now check for cell data
vtkCellData *cd = dataSet->GetCellData();
if (cd)
{
std::cout << " contains cell data with "
<< cd->GetNumberOfArrays()
<< " arrays." << std::endl;
for (int i = 0; i < cd->GetNumberOfArrays(); i++)
{
std::cout << "\tArray " << i
<< " is named "
<< (cd->GetArrayName(i) ? cd->GetArrayName(i) : "NULL")
<< std::endl;
}
}
// Now check for field data
if (dataSet->GetFieldData())
{
std::cout << " contains field data with "
<< dataSet->GetFieldData()->GetNumberOfArrays()
<< " arrays." << std::endl;
for (int i = 0; i < dataSet->GetFieldData()->GetNumberOfArrays(); i++)
{
std::cout << "\tArray " << i
<< " is named " << dataSet->GetFieldData()->GetArray(i)->GetName()
<< std::endl;
}
}
dataSet->Delete();
f++;
}
return EXIT_SUCCESS;
}
|