The problem is that you used the incorrect method to set the input for vtkPLYReader
(note that the relevant methods are actually from a base class of vtkPLYReader
- vtkDataReader
).
The function you used:
void vtkDataReader::SetInputString(const char * in);
expects a null-terminated string for it's input parameter (const char * in
).
As you can see in the link it is an array of char
s terminated by an element with value 0.
This works well for text because there is no text character with value 0.
A binary buffer however may (and probably will if it is big enough) contain bytes with value 0.
Instead you should use one of the following:
void vtkDataReader::SetInputString(const char * in, int len);
// Or:
void vtkDataReader::SetBinaryInputString(const char* , int len);
At first I thought SetBinaryInputString
is the only one that can handle a binary buffer,
but as you can see in the documentation link below, both have actually the same description:
Specify the InputString for use when reading from a character array. Optionally include the length for binary strings. Note that a copy of the string is made and stored. If this causes exceedingly large memory consumption, consider using InputArray instead.
You can try both of them and verify you got the proper result.
Notes:
- If
data
is a std::string
, make sure you initialize it with the proper constructor that accepts a count
parameter and supports characters with value 0 (see here: Can a std::string contain embedded nulls?).
- Make sure that you pass the entrire length of the binary buffer in the
len
parameter. I mean that you shouldn't measure the length by using a function that assumes a null-termination like strlen
. If it's indeed a std::string
you can use std::string::length()
safely.
- A binary buffer is not really a string. I prefer to keep such buffers in a
std::vector<char>
. You can use the data()
and size()
methods of std::vector
to pass as agruments to SetInputString
/ SetBinaryInputString
.
See documentation for vtkDataReader
, which is the base class of vtkPLYReader
and implements the methods mentioned above.