Commit e79f3a3f authored by Utkarsh Ayachit's avatar Utkarsh Ayachit Committed by Code Review

Merge topic 'fix_composite_data_names' into master

af508c83 Fix send/receive for composite datasets.
84c0666e Preserve composite-data names in legacy readers/writers.
parents 2cda3ff7 af508c83
......@@ -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))
......
......@@ -27,7 +27,6 @@
#include "vtkIdTypeArray.h"
#include "vtkImageData.h"
#include "vtkIntArray.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkMultiProcessController.h"
#include "vtkMultiProcessStream.h"
#include "vtkRectilinearGrid.h"
......@@ -207,40 +206,12 @@ int vtkCommunicator::Send(vtkDataObject* data, int remoteHandle,
case VTK_TABLE:
case VTK_TREE:
case VTK_UNSTRUCTURED_GRID:
return this->SendElementalDataObject(data, remoteHandle, tag);
//for composite types send type, structure, and then iterate
//over the internal dataobjects, sending each one (recursively)
case VTK_MULTIBLOCK_DATA_SET:
return this->SendMultiBlockDataSet(
vtkMultiBlockDataSet::SafeDownCast(data), remoteHandle, tag);
}
}
//----------------------------------------------------------------------------
int vtkCommunicator::SendMultiBlockDataSet(vtkMultiBlockDataSet* mbds,
int remoteHandle, int tag)
{
int returnCode = 1;
int numblocks = static_cast<int>(mbds->GetNumberOfBlocks());
// Tell the receiver the number of blocks to expect.
returnCode = this->Send(&numblocks, 1, remoteHandle, tag);
for (int cc=0; (cc < numblocks) && returnCode; cc++)
{
vtkDataObject* block = mbds->GetBlock(cc);
int dataType = (block? block->GetDataObjectType() : -1);
returnCode = returnCode && this->Send(&dataType, 1, remoteHandle, tag);
if (block)
{
// Now, send the actual block data.
returnCode = returnCode && this->Send(block, remoteHandle, tag);
}
case VTK_UNIFORM_GRID_AMR:
return this->SendElementalDataObject(data, remoteHandle, tag);
}
return returnCode;
}
//----------------------------------------------------------------------------
int vtkCommunicator::SendElementalDataObject(
vtkDataObject* data, int remoteHandle,
......@@ -429,39 +400,10 @@ int vtkCommunicator::ReceiveDataObject(vtkDataObject* data, int remoteHandle,
case VTK_TABLE:
case VTK_TREE:
case VTK_UNSTRUCTURED_GRID:
return this->ReceiveElementalDataObject(data, remoteHandle, tag);
//for composite types receive type, structure, and then iterate
//over the internal dataobjects, receiving each recursively as needed
case VTK_MULTIBLOCK_DATA_SET:
return this->ReceiveMultiBlockDataSet(
vtkMultiBlockDataSet::SafeDownCast(data), remoteHandle, tag);
}
}
//----------------------------------------------------------------------------
int vtkCommunicator::ReceiveMultiBlockDataSet(
vtkMultiBlockDataSet* mbds, int remoteHandle, int tag)
{
int returnCode = 1;
int numblocks = 0;
returnCode = this->Receive(&numblocks, 1, remoteHandle, tag);
mbds->SetNumberOfBlocks(numblocks);
for (int cc=0; (cc < numblocks) && returnCode; cc++)
{
int dataType = 0;
returnCode = returnCode && this->Receive(&dataType, 1, remoteHandle, tag);
if (dataType != -1) // 0 is a valid data type :).
{
vtkDataObject* dObj = vtkDataObjectTypes::NewDataObject(dataType);
returnCode = returnCode && this->Receive(dObj, remoteHandle, tag);
mbds->SetBlock(cc, dObj);
dObj->Delete();
}
case VTK_UNIFORM_GRID_AMR:
return this->ReceiveElementalDataObject(data, remoteHandle, tag);
}
return returnCode;
}
//----------------------------------------------------------------------------
......
......@@ -845,7 +845,6 @@ protected:
// Internal methods called by Send/Receive(vtkDataObject *... ) above.
int SendElementalDataObject(vtkDataObject* data, int remoteHandle, int tag);
int SendMultiBlockDataSet(vtkMultiBlockDataSet* data, int remoteHandle, int tag);
int ReceiveDataObject(vtkDataObject* data,
int remoteHandle, int tag, int type=-1);
int ReceiveElementalDataObject(vtkDataObject* data,
......
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