Commit f80249fb authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

Update vtkInsituDataAdaptor to support composite datasets.

Refactoring vtkInsituDataAdaptor API to support composite datasets.
parent b15eb5d1
......@@ -34,38 +34,77 @@ public:
vtkTypeMacro(vtkInsituDataAdaptor, vtkObjectBase);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Provides access to meta-data about the current data.
// This can provide all metadata necessary, including global extents, fields
// available, etc.
/// @brief Return the data object with appropriate structure.
///
/// This method will return a data object of the appropriate type. The data
/// object can be a vtkDataSet subclass or a vtkCompositeDataSet subclass.
/// If \c structure_only is set to true, then the geometry and topology
/// information will not be populated. For data adaptors that produce a
/// vtkCompositeDataSet subclass, passing \c structure_only will still produce
/// appropriate composite data hierarchy.
///
/// @param structure_only When set to true (default; false) the returned mesh
/// may not have any geometry or topology information.
virtual vtkDataObject* GetMesh(bool structure_only=false) = 0;
/// @brief Adds the specified field array to the mesh.
///
/// This method will add the requested array to the mesh, if available. If the
/// array was already added to the mesh, this will not add it again. The mesh
/// should not be expected to have geometry or topology information.
///
/// @param association field association; one of
/// vtkDataObject::FieldAssociations or vtkDataObject::AttributeTypes.
/// @return true if array was added (or already added), false is request array
/// is not available.
virtual bool AddArray(vtkDataObject* mesh, int association, const char* arrayname) = 0;
/// @brief Return the number of field arrays available.
///
/// This method will return the number of field arrays available. For data
/// adaptors producing composite datasets, this is a union of arrays available
/// on all parts of the composite dataset.
///
/// @param association field association; one of
/// vtkDataObject::FieldAssociations or vtkDataObject::AttributeTypes.
/// @return the number of arrays.
virtual unsigned int GetNumberOfArrays(int association) = 0;
/// @brief Return the name for a field array.
///
/// This method will return the name for a field array given its index.
///
/// @param association field association; one of
/// vtkDataObject::FieldAssociations or vtkDataObject::AttributeTypes.
/// @param index index for the array. Must be less than value returned
/// GetNumberOfArrays().
/// @return name of the array.
virtual const char* GetArrayName(int association, unsigned int index) = 0;
/// @brief Release data allocated for the current timestep.
///
/// Releases the data allocated for the current timestep. This is expected to
/// be called after each time iteration.
virtual void ReleaseData() = 0;
/// @brief Provides access to meta-data about the current data.
///
/// This method can provide all meta-data necessary, including global extents,
/// fields available, etc.
vtkInformation* GetInformation() { return this->Information; }
// Description:
// Convenience method to get the time information.
/// @brief Convenience method to get the time information.
double GetDataTime() { return this->GetDataTime(this->Information); }
/// @brief Convenience method to get the time information.
static double GetDataTime(vtkInformation*);
// Description:
// Convenience methods to set the time information.
/// @brief Convenience methods to set the time information.
void SetDataTime(double time) { this->SetDataTime(this->Information, time); }
static void SetDataTime(vtkInformation*, double time);
// Description:
// Subclasses should override this method to generate the mesh.
virtual vtkDataObject* GetMesh()=0;
// Description:
// Subclasses should override this method to provide field arrays.
virtual vtkAbstractArray* GetArray(int association, const char* name) = 0;
// Description:
// API to inquire about arrays.
virtual unsigned int GetNumberOfArrays(int association) = 0;
virtual const char* GetArrayName(int association, unsigned int index) = 0;
/// @brief Convenience methods to set the time information.
static void SetDataTime(vtkInformation*, double time);
// Description:
// Method called to release data and end of each execution iteration.
virtual void ReleaseData()=0;
protected:
vtkInsituDataAdaptor();
~vtkInsituDataAdaptor();
......
#include "HistogramAnalysisAdaptor.h"
#include "vtkDataArray.h"
#include "vtkDataObject.h"
#include "vtkFieldData.h"
#include "vtkInsituDataAdaptor.h"
#include "vtkObjectFactory.h"
......@@ -34,7 +34,14 @@ void HistogramAnalysisAdaptor::Initialize(
//-----------------------------------------------------------------------------
bool HistogramAnalysisAdaptor::Execute(vtkInsituDataAdaptor* data)
{
vtk_histogram(this->Communicator, vtkDataArray::SafeDownCast(
data->GetArray(this->Association, this->ArrayName.c_str())), this->Bins);
vtkDataObject* mesh = data->GetMesh(/*structure_only*/true);
if (mesh && data->AddArray(mesh, this->Association, this->ArrayName.c_str()))
{
if (vtkFieldData* fd = mesh->GetAttributesAsFieldData(this->Association))
{
vtk_histogram(this->Communicator, fd->GetArray(this->ArrayName.c_str()), this->Bins);
return true;
}
}
return false;
}
#include "DataAdaptor.h"
#include "vtkObjectFactory.h"
#include "vtkDataObject.h"
#include "vtkDoubleArray.h"
#include "vtkImageData.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
namespace parallel3d
{
......@@ -53,26 +55,28 @@ void DataAdaptor::ClearArrays()
}
//-----------------------------------------------------------------------------
vtkDataObject* DataAdaptor::GetMesh()
vtkDataObject* DataAdaptor::GetMesh(bool vtkNotUsed(structure_only))
{
// our analysis doesn't need a mesh so we punt on it for now.
// In theory, we'll create a new vtkImageData and return that.
vtkGenericWarningMacro("TODO: Not implemented currently.");
return NULL;
if (!this->Mesh)
{
this->Mesh = vtkSmartPointer<vtkImageData>::New();
this->Mesh->SetExtent(this->Extent);
}
return this->Mesh;
}
//-----------------------------------------------------------------------------
vtkAbstractArray* DataAdaptor::GetArray(int association, const char* name)
bool DataAdaptor::AddArray(vtkDataObject* mesh, int association, const char* name)
{
if (association != vtkDataObject::FIELD_ASSOCIATION_POINTS || name == NULL)
{
return NULL;
return false;
}
VariablesType::iterator iterV = this->Variables.find(name);
if (iterV == this->Variables.end())
{
return NULL;
return false;
}
ArraysType::iterator iterA = this->Arrays.find(iterV->first);
......@@ -81,17 +85,14 @@ vtkAbstractArray* DataAdaptor::GetArray(int association, const char* name)
vtkSmartPointer<vtkDoubleArray>& vtkarray = this->Arrays[iterV->first];
vtkarray = vtkSmartPointer<vtkDoubleArray>::New();
vtkarray->SetName(name);
const vtkIdType size = (this->Extent[1] - this->Extent[0] + 1) *
(this->Extent[3] - this->Extent[2] + 1) *
(this->Extent[5] - this->Extent[4] + 1);
vtkarray->SetArray(iterV->second, size, 1);
return vtkarray;
}
else
{
return iterA->second;
vtkImageData::SafeDownCast(mesh)->GetPointData()->SetScalars(vtkarray);
return true;
}
return true;
}
//-----------------------------------------------------------------------------
......@@ -124,6 +125,7 @@ const char* DataAdaptor::GetArrayName(int association, unsigned int index)
void DataAdaptor::ReleaseData()
{
this->ClearArrays();
this->Mesh = NULL;
}
}
......@@ -7,6 +7,7 @@
#include <string>
class vtkDoubleArray;
class vtkImageData;
namespace parallel3d
{
......@@ -33,19 +34,10 @@ public:
/// Clear all arrays.
void ClearArrays();
/// Return the topology/geometry for the simulation grid.
virtual vtkDataObject* GetMesh();
/// Return an array.
virtual vtkAbstractArray* GetArray(int association, const char* name);
/// Return number of arrays.
virtual vtkDataObject* GetMesh(bool structure_only=false);
virtual bool AddArray(vtkDataObject* mesh, int association, const char* arrayname);
virtual unsigned int GetNumberOfArrays(int association);
/// Returns an arrays name given the index.
virtual const char* GetArrayName(int association, unsigned int index);
/// Release all data.
virtual void ReleaseData();
protected:
......@@ -58,6 +50,7 @@ protected:
typedef std::map<std::string, vtkSmartPointer<vtkDoubleArray> > ArraysType;
ArraysType Arrays;
vtkSmartPointer<vtkImageData> Mesh;
int Extent[6];
private:
DataAdaptor(const DataAdaptor&); // 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