[vtkusers] serialize a vtk object to a xml string, not to save it to a file
Xiaoping Chen
xpchen5871 at gmail.com
Mon Aug 8 17:52:11 EDT 2011
Thank you so much, David, but we are currently using the following
class to get serialized vtk xml string in C++
vtkXMLPolyDataStreamWriter is derived from vtkXMLPolyDataWriter.
/////// c++ header file
#ifndef _VTKXMLPOLYDATASTREAMWRITER_H_INCLUDED_
#define _VTKXMLPOLYDATASTREAMWRITER_H_INCLUDED_
#include <ostream>
#include <vtkXMLPolyDataWriter.h>
class vtkXMLPolyDataStreamWriter : public vtkXMLPolyDataWriter
{
public:
static vtkXMLPolyDataStreamWriter* New();
virtual void SetUserStream(std::ostream& output_stream);
protected:
vtkXMLPolyDataStreamWriter();
~vtkXMLPolyDataStreamWriter();
virtual int WriteInternal();
};
#endif // _VTKXMLPOLYDATASTREAMWRITER_H_INCLUDED_
///----------------- c++ source file
#include "vtkXMLPolyDataStreamWriter.h"
#include <vtkOutputStream.h>
#include <vtkObjectFactory.h>
vtkStandardNewMacro(vtkXMLPolyDataStreamWriter);
vtkXMLPolyDataStreamWriter::vtkXMLPolyDataStreamWriter()
{
}
vtkXMLPolyDataStreamWriter::~vtkXMLPolyDataStreamWriter()
{
}
void vtkXMLPolyDataStreamWriter::SetUserStream(std::ostream& output_stream)
{
this->Stream = &output_stream;
this->Stream->precision(11);
this->DataStream->SetStream(this->Stream);
}
int vtkXMLPolyDataStreamWriter::WriteInternal()
{
(*this->Stream).imbue(vtkstd::locale::classic());
return this->WriteData();
}
//----------- call as the following
//-- serizlize vtk objects to vtkString
vtkSmartPointer<vtkXMLPolyDataStreamWriter> writer =
vtkXMLPolyDataStreamWriter::New();
std::ostringstream oss;
writer->SetUserStream(oss);
writer->SetInput(polyData);
writer->Update();
#ifdef _DEBUG
std::cout << "######## serialized points: " <<oss.str() <<std::endl;
#endif
//load serialized vtk xml to output parameter
sVTKXml = oss.str();
but I have trouble to do the same in vtk Java wrapper because I can't
find any equivalent calls for the following statements in Java
this->Stream = &output_stream;
this->Stream->precision(11);
this->DataStream->SetStream(this->Stream);
this->WriteData();
Any idea?
Thanks again.
Eric
On Mon, Aug 8, 2011 at 5:24 PM, David E DeMarle
<dave.demarle at kitware.com> wrote:
> I don't think the vtk XML readers/writers have a buffer IO feature,
> but the pure vtk readers/writers do. see
> vtkDataReader::SetReadFromInputString() in
> http://www.vtk.org/doc/nightly/html/classvtkDataReader.html
>
> David E DeMarle
> Kitware, Inc.
> R&D Engineer
> 28 Corporate Drive
> Clifton Park, NY 12065-8662
> Phone: 518-371-3971 x109
>
>
>
> On Mon, Aug 8, 2011 at 4:45 PM, Xiaoping Chen <xpchen5871 at gmail.com> wrote:
>> Could someone help on this issue (use a vtkXMLPolyDataWriter instance
>> to create a serialized vtk xml string)?
>>
>> On Thu, Jul 28, 2011 at 4:07 PM, Xiaoping Chen <xpchen5871 at gmail.com> wrote:
>>> Hello,
>>>
>>> I am creating a client-server application. The server will be
>>> Java-based, running in Linux and the client is C++-based, running in
>>> Windows.
>>>
>>> The server will map our internal data into the VTK objects and
>>> serialized them into the xml strings and then send to the client.
>>>
>>> I am able to do this in C++ but not able to do it in VTK Java wrapper.
>>> vtkXMLPolyDataWriter allows me to serialize the vtk object and save
>>> it to a file but NOT allow me to turn it into a xml string.
>>>
>>> Please help.
>>>
>>> Eric
>>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>>
>
More information about the vtkusers
mailing list