[vtkusers] extending VTK's XML file formats

Tim Hutton tim.hutton at gmail.com
Fri Jan 13 08:57:56 EST 2012


I've got things working as I wanted. I subclass from
vtkXMLImageDataReader and vtkXMLImageDataWriter. In my writer subclass
I override WritePrimaryElement() like this:

int WritePrimaryElement(ostream& os,vtkIndent indent)
{
    BuildSystemXML(this->system)->PrintXML(os,indent);
    return vtkXMLImageDataWriter::WritePrimaryElement(os,indent);
}

where BuildSystemXML() is our function, which provides the
vtkXMLDataElement that contains all our data. The element gets written
as the first nested node inside <VTKFile>, which doesn't stop the vti
file from being read by the normal VTK readers, including Paraview.

For reading, our subclass of vtkXMLImageDataReader simply has a new
function that does this:

vtkSmartPointer<vtkXMLDataElement> root = this->XMLParser->GetRootElement();
if(!root) throw runtime_error("No XML found in file");
vtkSmartPointer<vtkXMLDataElement> sd =
root->FindNestedElementWithName("sim_details");
if(!sd) throw runtime_error("sim_details node not found in file");

to access the vtkXMLDataElement that contains our data.

So it's all working. I'm not sure if it's the 'authorised' way to do
things. The big advantage from my point of view is not having to do
any of the parsing, since we can use VTK's XML parsing to give us the
node tree, attributes and content.


>>> On 1/10/2012 5:11 PM, Tim Hutton wrote:
>>>>
>>>> What is the accepted way of extending VTK's XML file formats? I would
>>>> like to be able to attach metadata to a vtkImageData file. Presumably
>>>> the right approach involves subclassing vtkXMLImageDataWriter and
>>>> vtkXMLImageDataReader but I'm not sure how to proceed. Is there an
>>>> example somewhere?

-- 
Tim Hutton - http://www.sq3.org.uk - http://profiles.google.com/tim.hutton/



More information about the vtkusers mailing list