question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use wtk.js vtkXMLPolyDataReader class to load data from XML string

See original GitHub issue

Hello, I try to use the vtkXMLPolyDataReader in a javascript, but i don’t want to use a file, i receive a XML in a string : <?xml version="1.0"?><VTKFile type="PolyData" version="0.1" byte_order="LittleEndian" header_type="UInt32" compressor="vtkZLibDataCompressor"><PolyData><Piece NumberOfPoints="38496" NumberOfVerts="0" NumberOfLines="0" NumberOfStrips="0" NumberOfPolys="53488">...

How I can load this data in the vtkXMLPolyDataReader . I try vtkXMLPolyDataReader.loadData(xml_string); but it does not seem to work. Many thanks for your help.

Patrick

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
ZbindenJoelcommented, Jun 28, 2022

Hi @daker and thanks for pointing me in the right direction.

After some more research I figured as much from its name, but being rather new to JavaScript I needed some more time to understand it.

I tried to convert my string to an ArrayBuffer using encodedString = TextEncoder().encode(XMLString) as explained here on SO and calling parseAsArrayBuffer with encodedString.buffer, but got yet another error now stating Invalid data type null expecting PolyData

Am I creating my ArrayBuffer correctly? (edit: Yes!)

Edit: I did create my ArrayBuffer correctly. The error was due to a call to the XMLPolyDataReader.loadData() function that should not have been there.

For anyone struggling, here’s the lines of code to transform the XML string to a vtkActor with all its associated parts:

// get an actor and mapper
const actor = vtk.Rendering.Core.vtkActor.newInstance();
const mapper = vtk.Rendering.Core.vtkMapper.newInstance();
// instantiate the xml reader
const reader = vtk.IO.XML.vtkXMLPolyDataReader.newInstance();
// connect actor <-- mapper <-- reader
actor.setMapper(mapper);
mapper.setInputConnection(reader.getOutputPort());

// set source for reader and load data
mesh_xml_buffer = new TextEncoder("latin1").encode(mesh_xml_string).buffer;
reader.parseAsArrayBuffer(mesh_xml_buffer);
0reactions
dakercommented, Jun 28, 2022

@ZbindenJoel parseAsArrayBuffer needs an ArrayBuffer to work not a string

Read more comments on GitHub >

github_iconTop Results From Across the Web

XMLPolyDataReader | vtk.js - Kitware, Inc.
vtkXMLPolyDataReader is a source object that parses a VTK XML input file. ... import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData';
Read more >
vtkXMLPolyDataReader Class Reference - VTK
vtkXMLPolyDataReader reads the VTK XML PolyData file format. One polygonal data file can be read to produce one output. Streaming is supported. The...
Read more >
Loading a xml to a class with Javascript - Stack Overflow
In Safari a URL with the document is created and called through an XMLHTTPRequest. Like all XMLHttpRequests, you use the standard responseXml ......
Read more >
Using JAXB And StaxEventItemReader To Read XML Data
Here's the code for this new EmployeeContactXML class that will be used to map the XML file. Getters and setters have been removed...
Read more >
How to Convert XML to Java Object - JAXB Unmarshalling
Java Architecture for XML Binding (JAXB) is a Java standard that defines how Java objects are converted from and to XML. It uses...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found