Commit 56f1f110 authored by Allison Vacanti's avatar Allison Vacanti

Populate DataArraySelection objects for vtm files.

parent bc578bed
......@@ -53,6 +53,14 @@ struct vtkXMLCompositeDataReaderEntry
struct vtkXMLCompositeDataReaderInternals
{
vtkXMLCompositeDataReaderInternals()
{
this->Piece = 0;
this->NumPieces = 1;
this->NumDataSets = 1;
this->HasUpdateRestriction = false;
}
vtkSmartPointer<vtkXMLDataElement> Root;
typedef std::map<std::string, vtkSmartPointer<vtkXMLReader> > ReadersType;
ReadersType Readers;
......@@ -60,12 +68,6 @@ struct vtkXMLCompositeDataReaderInternals
unsigned int Piece;
unsigned int NumPieces;
unsigned int NumDataSets;
vtkXMLCompositeDataReaderInternals()
{
this->Piece = 0;
this->NumPieces = 1;
this->NumDataSets = 1;
}
std::set<int> UpdateIndices;
bool HasUpdateRestriction;
};
......@@ -131,6 +133,23 @@ vtkExecutive* vtkXMLCompositeDataReader::CreateDefaultExecutive()
return vtkCompositeDataPipeline::New();
}
//----------------------------------------------------------------------------
std::string vtkXMLCompositeDataReader::GetFilePath()
{
std::string filePath = this->FileName;
std::string::size_type pos = filePath.find_last_of("/\\");
if (pos != filePath.npos)
{
filePath = filePath.substr(0, pos);
}
else
{
filePath = "";
}
return filePath;
}
//----------------------------------------------------------------------------
vtkCompositeDataSet* vtkXMLCompositeDataReader::GetOutput()
{
......@@ -176,6 +195,31 @@ vtkXMLDataElement* vtkXMLCompositeDataReader::GetPrimaryElement()
return this->Internal->Root;
}
//----------------------------------------------------------------------------
std::string vtkXMLCompositeDataReader::GetFileNameFromXML(vtkXMLDataElement *xmlElem,
const std::string &filePath)
{
// Construct the name of the internal file.
const char* file = xmlElem->GetAttribute("file");
if (!file)
{
return std::string();
}
std::string fileName;
if (!(file[0] == '/' || file[1] == ':'))
{
fileName = filePath;
if (fileName.length())
{
fileName += "/";
}
}
fileName += file;
return fileName;
}
//----------------------------------------------------------------------------
vtkXMLReader* vtkXMLCompositeDataReader::GetReaderOfType(const char* type)
{
......@@ -238,6 +282,32 @@ vtkXMLReader* vtkXMLCompositeDataReader::GetReaderOfType(const char* type)
return reader;
}
//----------------------------------------------------------------------------
vtkXMLReader *vtkXMLCompositeDataReader::GetReaderForFile(const std::string &fileName)
{
// Get the file extension.
std::string ext = vtksys::SystemTools::GetFilenameLastExtension(fileName);
if (!ext.empty())
{
// remove "." from the extension.
ext.erase(0, 1);
}
// Search for the reader matching this extension.
const char* rname = nullptr;
for(const vtkXMLCompositeDataReaderEntry* readerEntry =
this->Internal->ReaderList;
!rname && readerEntry->extension; ++readerEntry)
{
if (ext == readerEntry->extension)
{
rname = readerEntry->name;
}
}
return this->GetReaderOfType(rname);
}
//----------------------------------------------------------------------------
unsigned int vtkXMLCompositeDataReader::CountLeaves(vtkXMLDataElement* elem)
{
......@@ -288,16 +358,7 @@ void vtkXMLCompositeDataReader::ReadXMLData()
// Find the path to this file in case the internal files are
// specified as relative paths.
std::string filePath = this->FileName;
std::string::size_type pos = filePath.find_last_of("/\\");
if (pos != filePath.npos)
{
filePath = filePath.substr(0, pos);
}
else
{
filePath = "";
}
std::string filePath = this->GetFilePath();
vtkInformation* outInfo = this->GetCurrentOutputInformation();
if (outInfo->Has(vtkCompositeDataPipeline::UPDATE_COMPOSITE_INDICES()))
......@@ -422,55 +483,22 @@ DataSetIsValidForInterleaveStrategy(unsigned int idx)
vtkDataObject* vtkXMLCompositeDataReader::ReadDataObject(vtkXMLDataElement* xmlElem,
const char* filePath)
{
// Construct the name of the internal file.
const char* file = xmlElem->GetAttribute("file");
if (!file)
{
// Get the reader for this file
std::string fileName = this->GetFileNameFromXML(xmlElem, filePath);
if (fileName.empty())
{ // No filename in XML element. Not neccessarily an error.
return nullptr;
}
std::string fileName;
if (!(file[0] == '/' || file[1] == ':'))
{
fileName = filePath;
if (fileName.length())
{
fileName += "/";
}
}
fileName += file;
// Get the file extension.
std::string ext = vtksys::SystemTools::GetFilenameLastExtension(fileName);
if (!ext.empty())
{
// remote "." from the extension.
ext = &(ext.c_str()[1]);
}
// Search for the reader matching this extension.
const char* rname = nullptr;
for(const vtkXMLCompositeDataReaderEntry* readerEntry =
this->Internal->ReaderList;
!rname && readerEntry->extension; ++readerEntry)
{
if (ext == readerEntry->extension)
{
rname = readerEntry->name;
}
}
vtkXMLReader* reader = this->GetReaderOfType(rname);
vtkXMLReader* reader = this->GetReaderForFile(fileName);
if (!reader)
{
vtkErrorMacro("Could not create reader for " << rname);
vtkErrorMacro("Could not create reader for " << fileName);
return nullptr;
}
reader->SetFileName(fileName.c_str());
// initialize array selection so we don't have any residual array selections
// from previous use of the reader.
reader->GetPointDataArraySelection()->RemoveAllArrays();
reader->GetCellDataArraySelection()->RemoveAllArrays();
reader->GetColumnArraySelection()->RemoveAllArrays();
reader->GetPointDataArraySelection()->CopySelections(this->PointDataArraySelection);
reader->GetCellDataArraySelection()->CopySelections(this->CellDataArraySelection);
reader->GetColumnArraySelection()->CopySelections(this->ColumnArraySelection);
reader->Update();
vtkDataObject* output = reader->GetOutputDataObject(0);
if (!output)
......@@ -506,6 +534,37 @@ int vtkXMLCompositeDataReader::RequestInformation(
return 1;
}
//----------------------------------------------------------------------------
void vtkXMLCompositeDataReader::SyncDataArraySelections(vtkXMLReader *accum,
vtkXMLDataElement *xmlElem,
const std::string& filePath)
{
// Get the reader for this file
std::string fileName = this->GetFileNameFromXML(xmlElem, filePath);
if (fileName.empty())
{ // No filename in XML element. Not neccessarily an error.
return;
}
vtkXMLReader* reader = this->GetReaderForFile(fileName);
if (!reader)
{
vtkErrorMacro("Could not create reader for " << fileName);
return;
}
reader->SetFileName(fileName.c_str());
// initialize array selection so we don't have any residual array selections
// from previous use of the reader.
reader->GetPointDataArraySelection()->RemoveAllArrays();
reader->GetCellDataArraySelection()->RemoveAllArrays();
reader->GetColumnArraySelection()->RemoveAllArrays();
reader->UpdateInformation();
// Merge the arrays:
accum->GetPointDataArraySelection()->Union(reader->GetPointDataArraySelection());
accum->GetCellDataArraySelection()->Union(reader->GetCellDataArraySelection());
accum->GetColumnArraySelection()->Union(reader->GetColumnArraySelection());
}
//----------------------------------------------------------------------------
const vtkXMLCompositeDataReaderEntry
vtkXMLCompositeDataReaderInternals::ReaderList[] =
......
......@@ -95,13 +95,23 @@ protected:
// Create a default executive.
vtkExecutive* CreateDefaultExecutive() override;
// Find the path to this file in case the internal files are
// specified as relative paths.
std::string GetFilePath();
std::string GetFileNameFromXML(vtkXMLDataElement *xmlElem,
const std::string &filePath);
vtkXMLReader* GetReaderOfType(const char* type);
vtkXMLReader* GetReaderForFile(const std::string &filename);
int RequestInformation(vtkInformation*,
vtkInformationVector**,
vtkInformationVector*) override;
void SyncDataArraySelections(vtkXMLReader *accum,
vtkXMLDataElement *xmlElem,
const std::string &filePath);
// Adds a child data object to the composite parent. childXML is the XML for
// the child data object need to obtain certain meta-data about the child.
......
......@@ -16,6 +16,7 @@
#include "vtkCompositeDataSet.h"
#include "vtkCompositeDataPipeline.h"
#include "vtkDataArraySelection.h"
#include "vtkDataSet.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
......@@ -217,6 +218,7 @@ namespace
//----------------------------------------------------------------------------
int vtkXMLMultiBlockDataReader::FillMetaData(vtkCompositeDataSet* metadata,
vtkXMLDataElement* element,
const std::string &filePath,
unsigned int &dataSetIndex)
{
vtkMultiBlockDataSet* mblock = vtkMultiBlockDataSet::SafeDownCast(metadata);
......@@ -270,6 +272,10 @@ int vtkXMLMultiBlockDataReader::FillMetaData(vtkCompositeDataSet* metadata,
extent, 6);
}
}
if (this->ShouldReadDataSet(dataSetIndex))
{
this->SyncDataArraySelections(this, childXML, filePath);
}
dataSetIndex++;
}
// Child is a multiblock dataset itself. Create it.
......@@ -277,7 +283,7 @@ int vtkXMLMultiBlockDataReader::FillMetaData(vtkCompositeDataSet* metadata,
&& strcmp(tagName, "Block") == 0)
{
vtkMultiBlockDataSet* childDS = vtkMultiBlockDataSet::New();
this->FillMetaData(childDS, childXML, dataSetIndex);
this->FillMetaData(childDS, childXML, filePath, dataSetIndex);
if (mblock)
{
mblock->SetBlock(index, childDS);
......@@ -294,7 +300,7 @@ int vtkXMLMultiBlockDataReader::FillMetaData(vtkCompositeDataSet* metadata,
&& strcmp(tagName, "Piece") == 0)
{
vtkMultiPieceDataSet* childDS = vtkMultiPieceDataSet::New();
this->FillMetaData(childDS, childXML, dataSetIndex);
this->FillMetaData(childDS, childXML, filePath, dataSetIndex);
mblock->SetBlock(index, childDS);
childDS->Delete();
int whole_extent[6];
......@@ -328,11 +334,12 @@ int vtkXMLMultiBlockDataReader::RequestInformation(
return 1;
}
const std::string filePath = this->GetFilePath();
vtkInformation* info = outputVector->GetInformationObject(0);
vtkSmartPointer<vtkMultiBlockDataSet> metadata =
vtkSmartPointer<vtkMultiBlockDataSet>::New();
unsigned int dataSetIndex = 0;
if (!this->FillMetaData(metadata, this->GetPrimaryElement(), dataSetIndex))
if (!this->FillMetaData(metadata, this->GetPrimaryElement(), filePath, dataSetIndex))
{
return 0;
}
......
......@@ -67,6 +67,7 @@ protected:
virtual int FillMetaData(vtkCompositeDataSet* metadata,
vtkXMLDataElement* element,
const std::string &filePath,
unsigned int& dataSetIndex);
private:
......
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