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: ...@@ -34,38 +34,77 @@ public:
vtkTypeMacro(vtkInsituDataAdaptor, vtkObjectBase); vtkTypeMacro(vtkInsituDataAdaptor, vtkObjectBase);
void PrintSelf(ostream& os, vtkIndent indent); void PrintSelf(ostream& os, vtkIndent indent);
// Description: /// @brief Return the data object with appropriate structure.
// Provides access to meta-data about the current data. ///
// This can provide all metadata necessary, including global extents, fields /// This method will return a data object of the appropriate type. The data
// available, etc. /// 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; } vtkInformation* GetInformation() { return this->Information; }
// Description: /// @brief Convenience method to get the time information.
// Convenience method to get the time information.
double GetDataTime() { return this->GetDataTime(this->Information); } double GetDataTime() { return this->GetDataTime(this->Information); }
/// @brief Convenience method to get the time information.
static double GetDataTime(vtkInformation*); static double GetDataTime(vtkInformation*);
// Description: /// @brief Convenience methods to set the time information.
// Convenience methods to set the time information.
void SetDataTime(double time) { this->SetDataTime(this->Information, time); } 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: /// @brief Convenience methods to set the time information.
// API to inquire about arrays. static void SetDataTime(vtkInformation*, double time);
virtual unsigned int GetNumberOfArrays(int association) = 0;
virtual const char* GetArrayName(int association, unsigned int index) = 0;
// Description:
// Method called to release data and end of each execution iteration.
virtual void ReleaseData()=0;
protected: protected:
vtkInsituDataAdaptor(); vtkInsituDataAdaptor();
~vtkInsituDataAdaptor(); ~vtkInsituDataAdaptor();
......
#include "HistogramAnalysisAdaptor.h" #include "HistogramAnalysisAdaptor.h"
#include "vtkDataArray.h"
#include "vtkDataObject.h" #include "vtkDataObject.h"
#include "vtkFieldData.h"
#include "vtkInsituDataAdaptor.h" #include "vtkInsituDataAdaptor.h"
#include "vtkObjectFactory.h" #include "vtkObjectFactory.h"
...@@ -34,7 +34,14 @@ void HistogramAnalysisAdaptor::Initialize( ...@@ -34,7 +34,14 @@ void HistogramAnalysisAdaptor::Initialize(
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool HistogramAnalysisAdaptor::Execute(vtkInsituDataAdaptor* data) bool HistogramAnalysisAdaptor::Execute(vtkInsituDataAdaptor* data)
{ {
vtk_histogram(this->Communicator, vtkDataArray::SafeDownCast( vtkDataObject* mesh = data->GetMesh(/*structure_only*/true);
data->GetArray(this->Association, this->ArrayName.c_str())), this->Bins); if (mesh && data->AddArray(mesh, this->Association, this->ArrayName.c_str()))
return true; {
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 "DataAdaptor.h"
#include "vtkObjectFactory.h"
#include "vtkDataObject.h" #include "vtkDataObject.h"
#include "vtkDoubleArray.h" #include "vtkDoubleArray.h"
#include "vtkImageData.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
namespace parallel3d namespace parallel3d
{ {
...@@ -53,26 +55,28 @@ void DataAdaptor::ClearArrays() ...@@ -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. if (!this->Mesh)
// In theory, we'll create a new vtkImageData and return that. {
vtkGenericWarningMacro("TODO: Not implemented currently."); this->Mesh = vtkSmartPointer<vtkImageData>::New();
return NULL; 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) if (association != vtkDataObject::FIELD_ASSOCIATION_POINTS || name == NULL)
{ {
return NULL; return false;
} }
VariablesType::iterator iterV = this->Variables.find(name); VariablesType::iterator iterV = this->Variables.find(name);
if (iterV == this->Variables.end()) if (iterV == this->Variables.end())
{ {
return NULL; return false;
} }
ArraysType::iterator iterA = this->Arrays.find(iterV->first); ArraysType::iterator iterA = this->Arrays.find(iterV->first);
...@@ -81,17 +85,14 @@ vtkAbstractArray* DataAdaptor::GetArray(int association, const char* name) ...@@ -81,17 +85,14 @@ vtkAbstractArray* DataAdaptor::GetArray(int association, const char* name)
vtkSmartPointer<vtkDoubleArray>& vtkarray = this->Arrays[iterV->first]; vtkSmartPointer<vtkDoubleArray>& vtkarray = this->Arrays[iterV->first];
vtkarray = vtkSmartPointer<vtkDoubleArray>::New(); vtkarray = vtkSmartPointer<vtkDoubleArray>::New();
vtkarray->SetName(name); vtkarray->SetName(name);
const vtkIdType size = (this->Extent[1] - this->Extent[0] + 1) * const vtkIdType size = (this->Extent[1] - this->Extent[0] + 1) *
(this->Extent[3] - this->Extent[2] + 1) * (this->Extent[3] - this->Extent[2] + 1) *
(this->Extent[5] - this->Extent[4] + 1); (this->Extent[5] - this->Extent[4] + 1);
vtkarray->SetArray(iterV->second, size, 1); vtkarray->SetArray(iterV->second, size, 1);
return vtkarray; vtkImageData::SafeDownCast(mesh)->GetPointData()->SetScalars(vtkarray);
} return true;
else
{
return iterA->second;
} }
return true;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -124,6 +125,7 @@ const char* DataAdaptor::GetArrayName(int association, unsigned int index) ...@@ -124,6 +125,7 @@ const char* DataAdaptor::GetArrayName(int association, unsigned int index)
void DataAdaptor::ReleaseData() void DataAdaptor::ReleaseData()
{ {
this->ClearArrays(); this->ClearArrays();
this->Mesh = NULL;
} }
} }
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <string> #include <string>
class vtkDoubleArray; class vtkDoubleArray;
class vtkImageData;
namespace parallel3d namespace parallel3d
{ {
...@@ -33,19 +34,10 @@ public: ...@@ -33,19 +34,10 @@ public:
/// Clear all arrays. /// Clear all arrays.
void ClearArrays(); void ClearArrays();
/// Return the topology/geometry for the simulation grid. virtual vtkDataObject* GetMesh(bool structure_only=false);
virtual vtkDataObject* GetMesh(); virtual bool AddArray(vtkDataObject* mesh, int association, const char* arrayname);
/// Return an array.
virtual vtkAbstractArray* GetArray(int association, const char* name);
/// Return number of arrays.
virtual unsigned int GetNumberOfArrays(int association); virtual unsigned int GetNumberOfArrays(int association);
/// Returns an arrays name given the index.
virtual const char* GetArrayName(int association, unsigned int index); virtual const char* GetArrayName(int association, unsigned int index);
/// Release all data.
virtual void ReleaseData(); virtual void ReleaseData();
protected: protected:
...@@ -58,6 +50,7 @@ protected: ...@@ -58,6 +50,7 @@ protected:
typedef std::map<std::string, vtkSmartPointer<vtkDoubleArray> > ArraysType; typedef std::map<std::string, vtkSmartPointer<vtkDoubleArray> > ArraysType;
ArraysType Arrays; ArraysType Arrays;
vtkSmartPointer<vtkImageData> Mesh;
int Extent[6]; int Extent[6];
private: private:
DataAdaptor(const DataAdaptor&); // not implemented. 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