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

ENH: Added support to read image data instead of uniform grid. Image data is...

ENH: Added support to read image data instead of uniform grid. Image data is now converted to uniform grid internally
parent 45580a35
......@@ -23,17 +23,26 @@
#include "vtkUniformGrid.h"
#include "vtkXMLDataElement.h"
vtkCxxRevisionMacro(vtkXMLHierarchicalBoxDataReader, "1.4");
#include <vtkstd/vector>
vtkCxxRevisionMacro(vtkXMLHierarchicalBoxDataReader, "1.5");
vtkStandardNewMacro(vtkXMLHierarchicalBoxDataReader);
struct vtkXMLHierarchicalBoxDataReaderInternals
{
vtkstd::vector<vtkXMLDataElement*> Refinements;
};
//----------------------------------------------------------------------------
vtkXMLHierarchicalBoxDataReader::vtkXMLHierarchicalBoxDataReader()
{
this->Internal = new vtkXMLHierarchicalBoxDataReaderInternals;
}
//----------------------------------------------------------------------------
vtkXMLHierarchicalBoxDataReader::~vtkXMLHierarchicalBoxDataReader()
{
delete this->Internal;
}
//----------------------------------------------------------------------------
......@@ -75,26 +84,71 @@ void vtkXMLHierarchicalBoxDataReader::ReadXMLData()
return;
}
vtkstd::vector<vtkXMLDataElement*>::iterator d;
for(d=this->Internal->Refinements.begin();
d != this->Internal->Refinements.end(); ++d)
{
vtkXMLDataElement* ds = *d;
int level = 0;
int refinement = 0;
if (!ds->GetScalarAttribute("level", level))
{
continue;
}
if (ds->GetScalarAttribute("refinement", refinement))
{
hb->SetRefinementRatio(level, refinement);
}
}
hb->GenerateVisibilityArrays();
}
//----------------------------------------------------------------------------
int vtkXMLHierarchicalBoxDataReader::ReadPrimaryElement(
vtkXMLDataElement* ePrimary)
{
if(!this->Superclass::ReadPrimaryElement(ePrimary)) { return 0; }
int numNested = ePrimary->GetNumberOfNestedElements();
int i;
this->Internal->Refinements.clear();
for(i=0; i < numNested; ++i)
{
vtkXMLDataElement* eNested = ePrimary->GetNestedElement(i);
if(strcmp(eNested->GetName(), "RefinementRatio") == 0)
{
this->Internal->Refinements.push_back(eNested);
}
}
return 1;
}
//----------------------------------------------------------------------------
void vtkXMLHierarchicalBoxDataReader::HandleDataSet(vtkXMLDataElement* ds,
int level, int dsId,
vtkMultiGroupDataSet* output,
vtkDataSet* data)
{
vtkUniformGrid* ugrid = 0;
vtkImageData* image = 0;
if (data)
{
ugrid = vtkUniformGrid::SafeDownCast(data);
if (!ugrid)
image = vtkImageData::SafeDownCast(data);
if (!image)
{
vtkErrorMacro("HierarchicalBoxDataSet can only contain uniform grids."
vtkErrorMacro("HierarchicalBoxDataSet can only contain image data."
<< " The file contains: " << data->GetClassName()
<< ". Ignoring dataset.");
}
}
vtkUniformGrid* ugrid = vtkUniformGrid::New();
ugrid->ShallowCopy(image);
int box[6];
if (ds->GetVectorAttribute("amr_box", 6, box))
{
......@@ -113,5 +167,7 @@ void vtkXMLHierarchicalBoxDataReader::HandleDataSet(vtkXMLDataElement* ds,
{
output->SetDataSet(level, dsId, data);
}
ugrid->Delete();
}
......@@ -21,14 +21,17 @@
// the number of processors, some processors will not have any sub-blocks
// for that level. If the number of sub-blocks is larger than the
// number of processors, each processor will possibly have more than
// 1 sub-block. This reader does not yet work since there is no reader
// for vtkUniformGrid yet.
// 1 sub-block.
#ifndef __vtkXMLHierarchicalBoxDataReader_h
#define __vtkXMLHierarchicalBoxDataReader_h
#include "vtkXMLHierarchicalDataReader.h"
//BTX
struct vtkXMLHierarchicalBoxDataReaderInternals;
//ETX
class VTK_IO_EXPORT vtkXMLHierarchicalBoxDataReader : public vtkXMLHierarchicalDataReader
{
public:
......@@ -44,6 +47,7 @@ protected:
virtual const char* GetDataSetName();
virtual void ReadXMLData();
virtual int ReadPrimaryElement(vtkXMLDataElement* ePrimary);
virtual int FillOutputPortInformation(int, vtkInformation* info);
virtual void HandleDataSet(
......@@ -51,6 +55,8 @@ protected:
vtkMultiGroupDataSet* output, vtkDataSet* data);
private:
vtkXMLHierarchicalBoxDataReaderInternals* Internal;
vtkXMLHierarchicalBoxDataReader(const vtkXMLHierarchicalBoxDataReader&); // Not implemented.
void operator=(const vtkXMLHierarchicalBoxDataReader&); // Not implemented.
......
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