Commit f4bbc019 authored by Berk Geveci's avatar Berk Geveci

Added support for reading/writing time as field data.

Added support to the parallel XML formats to read & write time
information as field data. Time value is stored and read from
a field array named TimeValue. This can then be leveraged by
readers that support file series.
parent 3b409f4d
......@@ -2,3 +2,6 @@ vtk_add_test_python_mpi(
testParallelXMLWriters.py,NO_VALID
testParallelMultiBlockWriter.py,NO_VALID
)
vtk_add_test_python(
TestPXMLTimeInField.py,NO_DATA,NO_VALID,NO_RT
)
#!/usr/bin/env python
import os
import vtk
from vtk.util.misc import vtkGetDataRoot
from vtk.util.misc import vtkGetTempDir
VTK_DATA_ROOT = vtkGetDataRoot()
VTK_TEMP_DIR = vtkGetTempDir()
rt = vtk.vtkRTAnalyticSource()
rt.Update()
inp = rt.GetOutput()
inp.GetInformation().Set(vtk.vtkDataObject.DATA_TIME_STEP(), 11)
file_root = VTK_TEMP_DIR + '/testpxmlfield'
file0 = file_root + ".pvti"
w = vtk.vtkXMLPImageDataWriter()
w.SetInputData(inp)
w.SetFileName(file0)
w.Write()
r = vtk.vtkXMLPImageDataReader()
r.SetFileName(file0)
r.UpdateInformation()
assert(r.GetOutputInformation(0).Get(vtk.vtkStreamingDemandDrivenPipeline.TIME_STEPS(), 0) == 11.0)
os.remove(file0)
os.remove(file_root+"_0.vti")
......@@ -16,7 +16,11 @@
#include "vtkCallbackCommand.h"
#include "vtkDataSet.h"
#include "vtkDoubleArray.h"
#include "vtkErrorCode.h"
#include "vtkFieldData.h"
#include "vtkInformation.h"
#include "vtkNew.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include <vtksys/SystemTools.hxx>
......@@ -37,6 +41,36 @@ void vtkXMLPDataWriter::PrintSelf(ostream& os, vtkIndent indent)
void vtkXMLPDataWriter::WritePData(vtkIndent indent)
{
vtkDataSet* input = this->GetInputAsDataSet();
// We want to avoid using appended data mode as it
// is not supported in meta formats.
int dataMode = this->DataMode;
if (dataMode == vtkXMLWriter::Appended)
{
this->DataMode = vtkXMLWriter::Binary;
}
vtkFieldData *fieldData = input->GetFieldData();
vtkInformation* meta = input->GetInformation();
bool hasTime = meta->Has(vtkDataObject::DATA_TIME_STEP()) ? true : false;
if ((fieldData && fieldData->GetNumberOfArrays()) || hasTime)
{
vtkNew<vtkFieldData> fieldDataCopy;
fieldDataCopy->ShallowCopy(fieldData);
if (hasTime)
{
vtkNew<vtkDoubleArray> time;
time->SetNumberOfTuples(1);
time->SetTypedComponent(0, 0, meta->Get(vtkDataObject::DATA_TIME_STEP()));
time->SetName("TimeValue");
fieldDataCopy->AddArray(time);
}
this->WriteFieldDataInline(fieldDataCopy, indent);
}
this->DataMode = dataMode;
this->WritePPointData(input->GetPointData(), indent);
if (this->ErrorCode == vtkErrorCode::OutOfDiskSpaceError)
{
......
......@@ -328,12 +328,10 @@ int vtkXMLCompositeDataWriter::WriteData()
this->Internal->Root->PrintXML(os, indent);
}
// We want to avoid using appended data mode as it
// is not supported in meta formats.
int dataMode = this->DataMode;
if (dataMode == vtkXMLWriter::Ascii)
{
this->DataMode = vtkXMLWriter::Ascii;
}
else
if (dataMode == vtkXMLWriter::Appended)
{
this->DataMode = vtkXMLWriter::Binary;
}
......
......@@ -224,6 +224,10 @@ int vtkXMLPDataReader::ReadPrimaryElement(vtkXMLDataElement* ePrimary)
{
this->PCellDataElement = eNested;
}
else if (strcmp(eNested->GetName(), "FieldData") == 0)
{
this->FieldDataElement = eNested;
}
}
this->SetupPieces(numPieces);
int piece = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment