All readers now support Fields before data (aka VisIt files).

This commit is contained in:
Robert Maynard 2016-01-20 15:58:41 -05:00
parent 10d59c176b
commit 33b20a8d18
6 changed files with 117 additions and 31 deletions

@ -223,10 +223,9 @@ public:
protected:
void ReadPoints()
{
std::string tag, dataType;
std::string dataType;
std::size_t numPoints;
this->DataFile->Stream >> tag >> numPoints >> dataType >> std::ws;
internal::parseAssert(tag == "POINTS");
this->DataFile->Stream >> numPoints >> dataType >> std::ws;
vtkm::cont::DynamicArrayHandle points;
this->DoReadDynamicArray(dataType, numPoints, 3, points);
@ -450,7 +449,6 @@ private:
std::string dataType, lookupTableName;
vtkm::IdComponent numComponents = 1;
this->DataFile->Stream >> dataName >> dataType;
std::string tag;
this->DataFile->Stream >> tag;
if (tag != "LOOKUP_TABLE")
@ -520,6 +518,9 @@ private:
this->DoReadDynamicArray(dataType, numElements, 9, data);
}
protected:
//ReadFields needs to be protected so that derived readers can skip
//VisIt header fields
void ReadFields(std::string &dataName)
{
std::cerr << "Support for FIELD is not implemented. Skipping."
@ -539,6 +540,7 @@ private:
}
}
private:
class SkipDynamicArray
{
public:
@ -579,7 +581,6 @@ private:
{
std::vector<T> buffer(this->NumElements);
this->Reader->ReadArray(buffer);
*this->Data = internal::CreateDynamicArrayHandle(buffer);
}
@ -595,6 +596,9 @@ private:
vtkm::cont::DynamicArrayHandle *Data;
};
//Make the Array parsing methods protected so that derived classes
//can call the methods.
protected:
void DoSkipDynamicArray(std::string dataType, std::size_t numElements,
vtkm::IdComponent numComponents)
{
@ -716,6 +720,7 @@ private:
this->DataFile->Stream >> std::ws;
}
private:
class PermuteCellData
{
public:

@ -74,7 +74,19 @@ private:
throw vtkm::io::ErrorIO("Incorrect DataSet type");
}
//We need to be able to handle VisIt files which dump Field data
//at the top of a VTK file
std::string tag;
this->DataFile->Stream >> tag;
internal::parseAssert(tag == "POINTS" || tag == "FIELD");
if(tag == "FIELD")
{
std::string name;
this->ReadFields(name);
this->DataFile->Stream >> tag;
internal::parseAssert(tag == "POINTS");
}
// Read the points
this->ReadPoints();

@ -43,10 +43,22 @@ private:
std::string tag;
//We need to be able to handle VisIt files which dump Field data
//at the top of a VTK file
this->DataFile->Stream >> tag;
internal::parseAssert(tag == "DIMENSIONS" || tag == "DIMENSIONS");
if(tag == "FIELD")
{
std::string name;
this->ReadFields(name);
this->DataFile->Stream >> tag;
}
// Read structured grid specific meta-data
vtkm::Id3 dim;
this->DataFile->Stream >> tag >> dim[0] >> dim[1] >> dim[2] >> std::ws;
internal::parseAssert(tag == "DIMENSIONS");
this->DataFile->Stream >> dim[0] >> dim[1] >> dim[2] >> std::ws;
vtkm::cont::CellSetStructured<3> cs("cells");
cs.SetPointDimensions(vtkm::make_Vec(dim[0], dim[1], dim[2]));

@ -63,34 +63,28 @@ private:
{ //visit way
vtkm::Vec< vtkm::Float32, 6 > bounds;
std::string fieldData; int numberOfFields;
this->DataFile->Stream >> fieldData >> numberOfFields >> std::ws;
internal::parseAssert(this->DataFile->Stream.good() && numberOfFields > 0);
std::string fieldData; int numArrays;
this->DataFile->Stream >> fieldData >> numArrays >> std::ws;
internal::parseAssert(this->DataFile->Stream.good() && numArrays > 0);
//parse all the fields, but only store the results of the avtOriginalBounds
//field
for(int i=0; i < numberOfFields; ++i)
for (vtkm::Id i = 0; i < numArrays; ++i)
{
std::string fieldName, dataType; int vec_size, num_elements;
this->DataFile->Stream >> fieldName >> vec_size >> num_elements >> dataType >> std::ws;
internal::parseAssert(this->DataFile->Stream.good());
std::size_t numTuples;
vtkm::IdComponent numComponents;
std::string arrayName, dataType;
this->DataFile->Stream >> arrayName >> numComponents >> numTuples
>> dataType >> std::ws;
if(fieldName == "avtOriginalBounds")
if(arrayName == "avtOriginalBounds")
{
internal::parseAssert(vec_size == 1 && num_elements == 6);
internal::parseAssert(numComponents == 1 && numTuples == 6);
//now we can parse the bounds
this->DataFile->Stream >> bounds[0] >> bounds[1] >> bounds[2]
>> bounds[3] >> bounds[4] >> bounds[5] >> std::ws;
}
else
{
//parse and throw away everything
double value;
for(int j = 0; j < (vec_size*num_elements); ++j)
{
this->DataFile->Stream >> value;
}
(void) value;
this->DoSkipDynamicArray(dataType, numTuples, numComponents);
}
}
internal::parseAssert(this->DataFile->Stream.good());

@ -41,7 +41,19 @@ private:
throw vtkm::io::ErrorIO("Incorrect DataSet type");
}
//We need to be able to handle VisIt files which dump Field data
//at the top of a VTK file
std::string tag;
this->DataFile->Stream >> tag;
internal::parseAssert(tag == "POINTS" || tag == "FIELD");
if(tag == "FIELD")
{
std::string name;
this->ReadFields(name);
this->DataFile->Stream >> tag;
internal::parseAssert(tag == "POINTS");
}
// Read the points
this->ReadPoints();
@ -53,6 +65,7 @@ private:
this->DataFile->Stream >> tag;
internal::parseAssert(tag == "CELLS");
this->ReadCells(connectivity, numIndices);
this->ReadShapes(shapes);

@ -124,11 +124,11 @@ const char structuredPointsVisItAscii[] =
"ASCII\n"
"DATASET STRUCTURED_POINTS\n"
"FIELD FieldData 3\n"
"Nek_SpectralElementData 1 4 inte\n"
"Nek_SpectralElementData 1 4 int\n"
"8 8 8 68826 \n"
"avtOriginalBounds 1 6 double\n"
"-2 2 -2 2 -2 2 \n"
"FakeData 2 4 inte\n"
"FakeData 2 4 int\n"
"81 80 89 68826 \n"
"-81 80 65 6226 \n"
"SPACING 1 1 1\n"
@ -186,6 +186,34 @@ const char unsturctureGridAscii[] =
"1 0 0 1 1 0 0 2 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1\n"
"0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1\n";
const char unsturctureGridVisItAscii[] =
"# vtk DataFile Version 3.0\n"
"Unstructured Grid Example\n"
"ASCII\n"
"DATASET UNSTRUCTURED_GRID\n"
"FIELD FieldData 1\n"
"Nek_SpectralElementData 1 4 int\n"
"8 8 8 68826 \n"
"POINTS 26 float\n"
"0 0 0 1 0 0 2 0 0 0 1 0 1 1 0 2 1 0 0 0 1 1 0 1 2 0 1\n"
"0 1 1 1 1 1 2 1 1 0.5 1.7 0.5 1.5 1.7 0.5 0 1 2 1 1 2 2 1 2\n"
"0 1 3 1 1 3 2 1 3 0 1 4 1 1 4 2 1 4 0 1 5 1 1 5 2 1 5\n"
"CELLS 12 64\n"
"8 0 1 4 3 6 7 10 9 6 1 7 2 4 10 5 6 2 7 8 5 10 11 5 4 3 9 10 12\n"
"4 5 4 10 13 4 5 10 11 13 6 17 14 18 15 19 16 4 21 22 19 18\n"
"3 20 21 17 3 21 18 17 2 25 24 1 23\n"
"CELL_TYPES 12\n"
"12 13 13 14 10 10 6 9 5 5 3 1\n"
"POINT_DATA 26\n"
"SCALARS scalars float 1\n"
"LOOKUP_TABLE default\n"
"0 1 2 3 4 5 6 7 8 9 10 11 12\n"
"13 14 15 16 17 18 19 20 21 22 23 24 25\n"
"VECTORS vectors float\n"
"1 0 0 1 1 0 0 2 0 1 0 0 1 1 0 0 2 0 1 0 0 1 1 0 0 2 0\n"
"1 0 0 1 1 0 0 2 0 0 1 0 0 1 0 0 0 1 0 0 1 4 5 6\n"
"9 0 1 8 0 1 7 0 1 6 0 1 5 0 1 4 0 1 3 0 1 2 0 1 1 0 1\n";
const char unsturctureGridBin[] =
"# vtk DataFile Version 4.0\n"
"Unstructured Grid Example\n"
@ -331,7 +359,7 @@ void TestReadingStructuredPoints(Format format)
void TestReadingStructuredPointsVisIt(Format format)
{
if (format == FORMAT_ASCII)
{
{
createFile(structuredPointsVisItAscii, sizeof(structuredPointsVisItAscii), testFileName);
vtkm::cont::DataSet ds = readVTKDataSet(testFileName);
@ -344,7 +372,7 @@ void TestReadingStructuredPointsVisIt(Format format)
"Incorrect number of cells");
VTKM_TEST_ASSERT(ds.GetCellSet().IsType(vtkm::cont::CellSetStructured<3>()),
"Incorrect cellset type");
}
}
}
@ -366,6 +394,25 @@ void TestReadingUnstructuredGrid(Format format)
"Incorrect cellset type");
}
void TestReadingUnstructuredGridVisIt(Format format)
{
if (format == FORMAT_ASCII)
{
createFile(unsturctureGridVisItAscii, sizeof(unsturctureGridVisItAscii), testFileName);
vtkm::cont::DataSet ds = readVTKDataSet(testFileName);
VTKM_TEST_ASSERT(ds.GetNumberOfFields() == 2,
"Incorrect number of fields");
VTKM_TEST_ASSERT(ds.GetCoordinateSystem().GetData().GetNumberOfValues() == 26,
"Incorrect number of points");
VTKM_TEST_ASSERT(ds.GetCellSet().GetCellSet().GetNumberOfCells() == 15,
"Incorrect number of cells");
VTKM_TEST_ASSERT(ds.GetCellSet().IsType(vtkm::cont::CellSetExplicit<>()),
"Incorrect cellset type");
}
}
void TestReadingVTKDataSet()
{
std::cout << "Test reading VTK Polydata file in ASCII" << std::endl;
@ -374,8 +421,6 @@ void TestReadingVTKDataSet()
TestReadingPolyData(FORMAT_BINARY);
std::cout << "Test reading VTK StructuredPoints file in ASCII" << std::endl;
TestReadingStructuredPoints(FORMAT_ASCII);
std::cout << "Test reading VTK/VisIt StructuredPoints file in ASCII" << std::endl;
TestReadingStructuredPointsVisIt(FORMAT_ASCII);
std::cout << "Test reading VTK StructuredPoints file in BINARY" << std::endl;
TestReadingStructuredPoints(FORMAT_BINARY);
@ -383,6 +428,11 @@ void TestReadingVTKDataSet()
TestReadingUnstructuredGrid(FORMAT_ASCII);
std::cout << "Test reading VTK UnstructuredGrid file in BINARY" << std::endl;
TestReadingUnstructuredGrid(FORMAT_BINARY);
std::cout << "Test reading VTK/VisIt StructuredPoints file in ASCII" << std::endl;
TestReadingStructuredPointsVisIt(FORMAT_ASCII);
std::cout << "Test reading VTK/VisIt UnstructuredGrid file in ASCII" << std::endl;
TestReadingUnstructuredGridVisIt(FORMAT_ASCII);
}
int UnitTestVTKDataSetReader(int, char *[])