Commit 9d8aed3f authored by Utkarsh Ayachit's avatar Utkarsh Ayachit
Browse files

BUG: XdmfReader was not working correctly when loading state. The issue was that

any statuses could only be set after RequestInformation() which does not happen
when loading state. Fixed by using a cache until RequestInformation() happens.
parent 556d364e
......@@ -88,7 +88,7 @@ private:
vtkStandardNewMacro(vtkXdmfReaderTester);
vtkStandardNewMacro(vtkXdmfReader);
vtkCxxRevisionMacro(vtkXdmfReader, "1.73");
vtkCxxRevisionMacro(vtkXdmfReader, "1.74");
//----------------------------------------------------------------------------
vtkXdmfReader::vtkXdmfReader()
{
......@@ -97,6 +97,11 @@ vtkXdmfReader::vtkXdmfReader()
this->XdmfDocument = new vtkXdmfDocument();
this->LastTimeIndex = 0;
this->SILUpdateStamp = 0;
this->PointArraysCache = new vtkXdmfArraySelection;
this->CellArraysCache = new vtkXdmfArraySelection;
this->GridsCache = new vtkXdmfArraySelection;
this->SetsCache = new vtkXdmfArraySelection;
}
//----------------------------------------------------------------------------
......@@ -105,6 +110,11 @@ vtkXdmfReader::~vtkXdmfReader()
this->SetDomainName(0);
delete this->XdmfDocument;
this->XdmfDocument = 0;
delete this->PointArraysCache;
delete this->CellArraysCache;
delete this->GridsCache;
delete this->SetsCache;
}
//----------------------------------------------------------------------------
......@@ -255,6 +265,9 @@ int vtkXdmfReader::RequestInformation(vtkInformation *, vtkInformationVector **,
return 0;
}
// Pass any cached user-selections to the active domain.
this->PassCachedSelections();
vtkInformation* outInfo = outputVector->GetInformationObject(0);
vtkXdmfDomain* domain = this->XdmfDocument->GetActiveDomain();
......@@ -413,126 +426,156 @@ int vtkXdmfReader::ChooseTimeStep(vtkInformation* outInfo)
return this->LastTimeIndex;
}
//----------------------------------------------------------------------------
vtkXdmfArraySelection* vtkXdmfReader::GetPointArraySelection()
{
return this->XdmfDocument->GetActiveDomain()?
this->XdmfDocument->GetActiveDomain()->GetPointArraySelection() :
this->PointArraysCache;
}
//----------------------------------------------------------------------------
vtkXdmfArraySelection* vtkXdmfReader::GetCellArraySelection()
{
return this->XdmfDocument->GetActiveDomain()?
this->XdmfDocument->GetActiveDomain()->GetCellArraySelection() :
this->CellArraysCache;
}
//----------------------------------------------------------------------------
vtkXdmfArraySelection* vtkXdmfReader::GetGridSelection()
{
return this->XdmfDocument->GetActiveDomain()?
this->XdmfDocument->GetActiveDomain()->GetGridSelection() :
this->GridsCache;
}
//----------------------------------------------------------------------------
vtkXdmfArraySelection* vtkXdmfReader::GetSetsSelection()
{
return this->XdmfDocument->GetActiveDomain()?
this->XdmfDocument->GetActiveDomain()->GetSetsSelection() :
this->SetsCache;
}
//----------------------------------------------------------------------------
int vtkXdmfReader::GetNumberOfGrids()
{
return
this->XdmfDocument->GetActiveDomain()->GetGridSelection()->
GetNumberOfArrays();
return this->GetGridSelection()->GetNumberOfArrays();
}
//----------------------------------------------------------------------------
void vtkXdmfReader::SetGridStatus(const char* gridname, int status)
{
this->XdmfDocument->GetActiveDomain()->GetGridSelection()->SetArrayStatus(
gridname, status !=0);
this->GetGridSelection()->SetArrayStatus(gridname, status !=0);
this->Modified();
}
//----------------------------------------------------------------------------
int vtkXdmfReader::GetGridStatus(const char* arrayname)
{
return this->XdmfDocument->GetActiveDomain()->GetGridSelection()->
GetArraySetting(arrayname);
return this->GetGridSelection()->GetArraySetting(arrayname);
}
//----------------------------------------------------------------------------
const char* vtkXdmfReader::GetGridName(int index)
{
return this->XdmfDocument->GetActiveDomain()->GetGridSelection()->
GetArrayName(index);
return this->GetGridSelection()->GetArrayName(index);
}
//----------------------------------------------------------------------------
int vtkXdmfReader::GetNumberOfPointArrays()
{
return
this->XdmfDocument->GetActiveDomain()->GetPointArraySelection()->
GetNumberOfArrays();
return this->GetPointArraySelection()->GetNumberOfArrays();
}
//----------------------------------------------------------------------------
void vtkXdmfReader::SetPointArrayStatus(const char* arrayname, int status)
{
this->XdmfDocument->GetActiveDomain()->GetPointArraySelection()->
SetArrayStatus(arrayname, status != 0);
this->GetPointArraySelection()->SetArrayStatus(arrayname, status != 0);
this->Modified();
}
//----------------------------------------------------------------------------
int vtkXdmfReader::GetPointArrayStatus(const char* arrayname)
{
return this->XdmfDocument->GetActiveDomain()->GetPointArraySelection()->
GetArraySetting(arrayname);
return this->GetPointArraySelection()->GetArraySetting(arrayname);
}
//----------------------------------------------------------------------------
const char* vtkXdmfReader::GetPointArrayName(int index)
{
return this->XdmfDocument->GetActiveDomain()->GetPointArraySelection()->
GetArrayName(index);
return this->GetPointArraySelection()->GetArrayName(index);
}
//----------------------------------------------------------------------------
int vtkXdmfReader::GetNumberOfCellArrays()
{
return
this->XdmfDocument->GetActiveDomain()->GetCellArraySelection()->
GetNumberOfArrays();
return this->GetCellArraySelection()->GetNumberOfArrays();
}
//----------------------------------------------------------------------------
void vtkXdmfReader::SetCellArrayStatus(const char* arrayname, int status)
{
this->XdmfDocument->GetActiveDomain()->GetCellArraySelection()->
SetArrayStatus(arrayname, status != 0);
this->GetCellArraySelection()->SetArrayStatus(arrayname, status != 0);
this->Modified();
}
//----------------------------------------------------------------------------
int vtkXdmfReader::GetCellArrayStatus(const char* arrayname)
{
return this->XdmfDocument->GetActiveDomain()->GetCellArraySelection()->
GetArraySetting(arrayname);
return this->GetCellArraySelection()->GetArraySetting(arrayname);
}
//----------------------------------------------------------------------------
const char* vtkXdmfReader::GetCellArrayName(int index)
{
return this->XdmfDocument->GetActiveDomain()->GetCellArraySelection()->
GetArrayName(index);
return this->GetCellArraySelection()->GetArrayName(index);
}
//----------------------------------------------------------------------------
int vtkXdmfReader::GetNumberOfSets()
{
return
this->XdmfDocument->GetActiveDomain()->GetSetsSelection()->
GetNumberOfArrays();
return this->GetSetsSelection()->GetNumberOfArrays();
}
//----------------------------------------------------------------------------
void vtkXdmfReader::SetSetStatus(const char* arrayname, int status)
{
this->XdmfDocument->GetActiveDomain()->GetSetsSelection()->
SetArrayStatus(arrayname, status != 0);
this->GetSetsSelection()->SetArrayStatus(arrayname, status != 0);
this->Modified();
}
//----------------------------------------------------------------------------
int vtkXdmfReader::GetSetStatus(const char* arrayname)
{
return this->XdmfDocument->GetActiveDomain()->GetSetsSelection()->
GetArraySetting(arrayname);
return this->GetSetsSelection()->GetArraySetting(arrayname);
}
//----------------------------------------------------------------------------
const char* vtkXdmfReader::GetSetName(int index)
{
return this->XdmfDocument->GetActiveDomain()->GetSetsSelection()->
GetArrayName(index);
return this->GetSetsSelection()->GetArrayName(index);
}
//----------------------------------------------------------------------------
void vtkXdmfReader::PassCachedSelections()
{
if (!this->XdmfDocument->GetActiveDomain())
{
return;
}
this->GetPointArraySelection()->Merge(*this->PointArraysCache);
this->GetCellArraySelection()->Merge(*this->CellArraysCache);
this->GetGridSelection()->Merge(*this->GridsCache);
this->GetSetsSelection()->Merge(*this->SetsCache);
// Clear the cache.
this->PointArraysCache->clear();
this->CellArraysCache->clear();
this->GridsCache->clear();
this->SetsCache->clear();
}
//----------------------------------------------------------------------------
......
......@@ -35,6 +35,7 @@
#include "vtkDataReader.h"
class vtkXdmfArraySelection;
class vtkXdmfDocument;
class VTK_EXPORT vtkXdmfReader : public vtkDataReader
......@@ -146,7 +147,12 @@ protected:
vtkInformationVector *);
virtual int FillOutputPortInformation(int port, vtkInformation *info);
vtkXdmfArraySelection* GetPointArraySelection();
vtkXdmfArraySelection* GetCellArraySelection();
vtkXdmfArraySelection* GetGridSelection();
vtkXdmfArraySelection* GetSetsSelection();
void PassCachedSelections();
char* DomainName;
// char* ActiveDomainName;
int Stride[3];
......@@ -154,6 +160,20 @@ protected:
vtkXdmfDocument* XdmfDocument;
// Until RequestInformation() is called, the active domain is not set
// correctly. If SetGridStatus() etc. are called before that happens, then we
// have no place to save the user choices. So we cache them in these temporary
// caches. These are passed on to the actual vtkXdmfArraySelection instances
// used by the active vtkXdmfDomain in RequestInformation().
// Note that these are only used until the first domain is setup, once that
// happens, the information set in these is passed to the domain and these
// are cleared an no longer used, until the active domain becomes invalid
// again.
vtkXdmfArraySelection* PointArraysCache;
vtkXdmfArraySelection* CellArraysCache;
vtkXdmfArraySelection* GridsCache;
vtkXdmfArraySelection* SetsCache;
int SILUpdateStamp;
private:
// Description:
......
......@@ -108,6 +108,15 @@ private:
class vtkXdmfArraySelection : public vtkstd::map<vtkstd::string, bool>
{
public:
void Merge(const vtkXdmfArraySelection& other)
{
vtkXdmfArraySelection::const_iterator iter = other.begin();
for (; iter != other.end(); ++iter)
{
(*this)[iter->first] = iter->second;
}
}
void AddArray(const char* name, bool status=true)
{
(*this)[name] = status;
......
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