[vtkusers] extending VTK's XML file formats

Tim Hutton tim.hutton at gmail.com
Fri Jan 13 10:38:00 EST 2012


Yes, it works fine with the plain vtkXMLImageDataReader. In general,
XML readers tend to ignore any nodes or attributes they don't
recognise. Paraview loads my files (and presumably is using
vtkXMLImageDataReader).

But I'm not sure if this is the usual approach to extending VTK XML
files. In particular, I'm not completely happy that my XML node is
inside the <VTKFile> node. But I don't even know if that's wrong so
I'm going with it for now until I learn otherwise.

On 13 January 2012 14:19, Bryn Lloyd <lloyd at itis.ethz.ch> wrote:
> Can you read this data also with a standard vtkXMLImageDataReader or will
> this cause an error/warning?
>
>
>
>
> On 1/13/2012 2:57 PM, Tim Hutton wrote:
>>
>> 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