Commit 84c0666e authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

Preserve composite-data names in legacy readers/writers.

vtkCompositeDataWriter/vtkCompositeDataReader didn't preserve composite data
block names. Fixed that.

Change-Id: Iad7c950bab05064f617e881f09cd7ff179398673
parent 2cda3ff7
......@@ -31,6 +31,7 @@
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkUniformGrid.h"
#include <vtksys/RegularExpression.hxx>
#include <vtksys/SystemTools.hxx>
#include <vtksys/ios/sstream>
......@@ -279,6 +280,13 @@ bool vtkCompositeDataReader::ReadCompositeData(vtkMultiBlockDataSet* mb)
}
// eat up the "\n" and other whitespace at the end of CHILD <type>.
this->ReadLine(line);
// if "line" has text enclosed in [] then that's the composite name.
vtksys::RegularExpression regEx("\\s*\\[(.*)\\]");
if (regEx.find(line))
{
std::string name = regEx.match(1);
mb->GetMetaData(cc)->Set(vtkCompositeDataSet::NAME(), name.c_str());
}
if (type != -1)
{
......@@ -526,6 +534,13 @@ bool vtkCompositeDataReader::ReadCompositeData(vtkMultiPieceDataSet* mp)
}
// eat up the "\n" and other whitespace at the end of CHILD <type>.
this->ReadLine(line);
// if "line" has text enclosed in [] then that's the composite name.
vtksys::RegularExpression regEx("\\s*\\[(.*)\\]");
if (regEx.find(line))
{
std::string name = regEx.match(1);
mp->GetMetaData(cc)->Set(vtkCompositeDataSet::NAME(), name.c_str());
}
if (type != -1)
{
......
......@@ -154,7 +154,15 @@ bool vtkCompositeDataWriter::WriteCompositeData(ostream* fp,
for (unsigned int cc=0; cc < mb->GetNumberOfBlocks(); cc++)
{
vtkDataObject* child = mb->GetBlock(cc);
*fp << "CHILD " << (child? child->GetDataObjectType() : -1) << "\n";
*fp << "CHILD " << (child? child->GetDataObjectType() : -1);
// add name if present.
if (mb->HasMetaData(cc) &&
mb->GetMetaData(cc)->Has(vtkCompositeDataSet::NAME()))
{
*fp << " [" << mb->GetMetaData(cc)->Get(vtkCompositeDataSet::NAME())
<< "]";
}
*fp << "\n";
if (child)
{
if (!this->WriteBlock(fp, child))
......@@ -176,7 +184,16 @@ bool vtkCompositeDataWriter::WriteCompositeData(ostream* fp,
for (unsigned int cc=0; cc < mp->GetNumberOfPieces(); cc++)
{
vtkDataObject* child = mp->GetPieceAsDataObject(cc);
*fp << "CHILD " << (child? child->GetDataObjectType() : -1) << "\n";
*fp << "CHILD " << (child? child->GetDataObjectType() : -1);
// add name if present.
if (mp->HasMetaData(cc) &&
mp->GetMetaData(cc)->Has(vtkCompositeDataSet::NAME()))
{
*fp << " [" << mp->GetMetaData(cc)->Get(vtkCompositeDataSet::NAME())
<< "]";
}
*fp << "\n";
if (child)
{
if (!this->WriteBlock(fp, child))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment