Commit a8219fb9 authored by Berk Geveci's avatar Berk Geveci
Browse files

Added the ability to request individual blocks/datasets to the XML reader.

If available, the XML multi-block reader now reads meta-data for bounds and extents.
If a request for specific datasets is avaiable, the reader reads only those.
parent 2774002a
......@@ -87,6 +87,7 @@ vtkInformationKeyMacro(vtkCompositeDataPipeline,REQUIRES_TIME_DOWNSTREAM, Intege
vtkInformationKeyMacro(vtkCompositeDataPipeline, COMPOSITE_DATA_META_DATA, ObjectBase);
vtkInformationKeyMacro(vtkCompositeDataPipeline, UPDATE_COMPOSITE_INDICES, IntegerVector);
vtkInformationKeyMacro(vtkCompositeDataPipeline, COMPOSITE_INDICES, IntegerVector);
vtkInformationKeyMacro(vtkCompositeDataPipeline, COMPOSITE_INDEX, Integer);
//----------------------------------------------------------------------------
vtkCompositeDataPipeline::vtkCompositeDataPipeline()
......
......@@ -108,6 +108,14 @@ public:
// *** THIS IS AN EXPERIMENTAL FEATURE. IT MAY CHANGE WITHOUT NOTICE ***
static vtkInformationIntegerVectorKey* COMPOSITE_INDICES();
// Description:
// COMPOSITE_INDEX() is added to the leaf nodes of the meta-data composite
// dataset (COMPOSITE_DATA_META_DATA) during REQUEST_INFORMATION(). Filters
// downstream can use this index to request specific datasets when
// creating UPDATE_COMPOSITE_INDICES().
// *** THIS IS AN EXPERIMENTAL FEATURE. IT MAY CHANGE WITHOUT NOTICE ***
static vtkInformationIntegerKey* COMPOSITE_INDEX();
protected:
vtkCompositeDataPipeline();
~vtkCompositeDataPipeline();
......
......@@ -21,6 +21,8 @@
#include "vtkDataSet.h"
#include "vtkHierarchicalBoxDataSet.h"
#include "vtkInformation.h"
#include "vtkInformationIntegerKey.h"
#include "vtkInformationIntegerVectorKey.h"
#include "vtkInformationVector.h"
#include "vtkInstantiator.h"
#include "vtkMultiBlockDataSet.h"
......@@ -36,11 +38,11 @@
#include "vtkXMLUnstructuredGridReader.h"
#include <vtkstd/map>
#include <vtkstd/set>
#include <vtkstd/string>
#include <vtkstd/vector>
#include <vtksys/SystemTools.hxx>
struct vtkXMLCompositeDataReaderEntry
{
const char* extension;
......@@ -60,6 +62,8 @@ struct vtkXMLCompositeDataReaderInternals
this->MinDataset = 0;
this->MaxDataset = 0;
}
vtkstd::set<int> UpdateIndices;
bool HasUpdateRestriction;
};
//----------------------------------------------------------------------------
......@@ -269,6 +273,23 @@ void vtkXMLCompositeDataReader::ReadXMLData()
this->Internal->MaxDataset = this->Internal->MinDataset + numDatasetsPerPiece;
}
vtkInformation* outInfo = this->GetCurrentOutputInformation();
if (outInfo->Has(vtkCompositeDataPipeline::UPDATE_COMPOSITE_INDICES()))
{
this->Internal->HasUpdateRestriction = true;
this->Internal->UpdateIndices = vtkstd::set<int>();
int length = outInfo->Length(vtkCompositeDataPipeline::UPDATE_COMPOSITE_INDICES());
if (length > 0)
{
int* idx = outInfo->Get(vtkCompositeDataPipeline::UPDATE_COMPOSITE_INDICES());
this->Internal->UpdateIndices = vtkstd::set<int>(idx, idx+length);
}
}
else
{
this->Internal->HasUpdateRestriction = false;
}
// All process create the entire tree structure however, only each one only
// reads the datasets assigned to it.
unsigned int dataSetIndex=0;
......@@ -278,8 +299,19 @@ void vtkXMLCompositeDataReader::ReadXMLData()
//----------------------------------------------------------------------------
int vtkXMLCompositeDataReader::ShouldReadDataSet(unsigned int dataSetIndex)
{
return (dataSetIndex >= this->Internal->MinDataset &&
dataSetIndex < this->Internal->MaxDataset)? 1 : 0;
bool shouldRead =
(dataSetIndex >= this->Internal->MinDataset &&
dataSetIndex < this->Internal->MaxDataset);
if (shouldRead && this->Internal->HasUpdateRestriction)
{
if (this->Internal->UpdateIndices.find(dataSetIndex) ==
this->Internal->UpdateIndices.end())
{
shouldRead = false;
}
}
return shouldRead;
}
//----------------------------------------------------------------------------
......
......@@ -29,6 +29,8 @@
#include "vtkXMLReader.h"
class vtkCompositeDataSet;
class vtkInformationIntegerKey;
class vtkInformationIntegerVectorKey;
//BTX
struct vtkXMLCompositeDataReaderInternals;
//ETX
......
......@@ -17,6 +17,7 @@
#include "vtkCompositeDataPipeline.h"
#include "vtkDataSet.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkMultiPieceDataSet.h"
#include "vtkObjectFactory.h"
......@@ -193,3 +194,154 @@ void vtkXMLMultiBlockDataReader::ReadComposite(vtkXMLDataElement* element,
}
}
}
namespace
{
vtkInformation* CreateMetaDataIfNecessary(vtkMultiBlockDataSet* mblock,
vtkMultiPieceDataSet* mpiece,
int index)
{
vtkInformation* piece_metadata = 0;
if (mblock)
{
mblock->SetBlock(index, NULL);
piece_metadata = mblock->GetMetaData(index);
}
else if (mpiece)
{
mpiece->SetPiece(index, NULL);
piece_metadata = mpiece->GetMetaData(index);
}
return piece_metadata;
}
}
//----------------------------------------------------------------------------
int vtkXMLMultiBlockDataReader::FillMetaData(vtkCompositeDataSet* metadata,
vtkXMLDataElement* element,
unsigned int &dataSetIndex)
{
vtkMultiBlockDataSet* mblock = vtkMultiBlockDataSet::SafeDownCast(metadata);
vtkMultiPieceDataSet* mpiece = vtkMultiPieceDataSet::SafeDownCast(metadata);
unsigned int maxElems = element->GetNumberOfNestedElements();
for (unsigned int cc=0; cc < maxElems; ++cc)
{
vtkXMLDataElement* childXML = element->GetNestedElement(cc);
if (!childXML || !childXML->GetName())
{
continue;
}
int index = 0;
if (!childXML->GetScalarAttribute("index", index))
// if index not in the structure file, then
// set up to add at the end
{
if (mblock)
{
index = mblock->GetNumberOfBlocks();
}
else if (mpiece)
{
index = mpiece->GetNumberOfPieces();
}
}
// child is a leaf node, read and insert.
const char* tagName = childXML->GetName();
if (strcmp(tagName, "DataSet") == 0)
{
vtkInformation* piece_metadata = CreateMetaDataIfNecessary(mblock, mpiece, index);
double bounding_box[6];
if (childXML->GetVectorAttribute("bounding_box", 6, bounding_box) == 6)
{
if (piece_metadata)
{
piece_metadata->Set(
vtkStreamingDemandDrivenPipeline::PIECE_BOUNDING_BOX(),
bounding_box, 6);
}
}
int extent[6];
if (childXML->GetVectorAttribute("extent", 6, extent) == 6)
{
if (piece_metadata)
{
piece_metadata->Set(
vtkDataObject::PIECE_EXTENT(),
extent, 6);
}
}
piece_metadata->Set(vtkCompositeDataPipeline::COMPOSITE_INDEX(), dataSetIndex);
dataSetIndex++;
}
// Child is a multiblock dataset itself. Create it.
else if (mblock != 0
&& strcmp(tagName, "Block") == 0)
{
vtkMultiBlockDataSet* childDS = vtkMultiBlockDataSet::New();
this->FillMetaData(childDS, childXML, dataSetIndex);
if (mblock)
{
mblock->SetBlock(index, childDS);
}
else if (mpiece)
{
vtkErrorMacro("Multipiece data can't have composite children.");
return 0;
}
childDS->Delete();
}
// Child is a multipiece dataset. Create it.
else if (mblock!=0
&& strcmp(tagName, "Piece") == 0)
{
vtkMultiPieceDataSet* childDS = vtkMultiPieceDataSet::New();;
this->FillMetaData(childDS, childXML, dataSetIndex);
mblock->SetBlock(index, childDS);
childDS->Delete();
int whole_extent[6];
if (childXML->GetVectorAttribute("whole_extent", 6, whole_extent) == 6)
{
vtkInformation* piece_metadata = mblock->GetMetaData(index);
piece_metadata->Set(
vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(),
whole_extent, 6);
}
}
else
{
vtkErrorMacro("Syntax error in file.");
return 0;
}
}
return 1;
}
//----------------------------------------------------------------------------
int vtkXMLMultiBlockDataReader::RequestInformation(
vtkInformation *request,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
this->Superclass::RequestInformation(request, inputVector, outputVector);
if (this->GetFileMajorVersion() < 1)
{
return 1;
}
vtkInformation* info = outputVector->GetInformationObject(0);
vtkSmartPointer<vtkMultiBlockDataSet> metadata =
vtkSmartPointer<vtkMultiBlockDataSet>::New();
unsigned int dataSetIndex = 0;
if (!this->FillMetaData(metadata, this->GetPrimaryElement(), dataSetIndex))
{
return 0;
}
info->Set(vtkCompositeDataPipeline::COMPOSITE_DATA_META_DATA(),
metadata);
return 1;
}
......@@ -57,6 +57,14 @@ protected:
virtual int FillOutputPortInformation(int, vtkInformation* info);
virtual int RequestInformation(vtkInformation*,
vtkInformationVector**,
vtkInformationVector*);
virtual int FillMetaData(vtkCompositeDataSet* metadata,
vtkXMLDataElement* element,
unsigned int& dataSetIndex);
private:
vtkXMLMultiBlockDataReader(const vtkXMLMultiBlockDataReader&); // Not implemented.
void operator=(const vtkXMLMultiBlockDataReader&); // Not implemented.
......
Supports Markdown
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