[vtkusers] extending VTK's XML file formats

Bryn Lloyd lloyd at itis.ethz.ch
Fri Jan 13 09:19:36 EST 2012


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?



More information about the vtkusers mailing list