Commit 45303991 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit
Browse files

Make histogram work correctly with composite datasets.

parent a73fd48a
#include "HistogramAnalysisAdaptor.h"
#include "vtkCompositeDataIterator.h"
#include "vtkCompositeDataSet.h"
#include "vtkDataObject.h"
#include "vtkFieldData.h"
#include "vtkInsituDataAdaptor.h"
#include "vtkObjectFactory.h"
#include "vtkSmartPointer.h"
#include "vtk_histogram.h"
......@@ -34,14 +37,38 @@ void HistogramAnalysisAdaptor::Initialize(
//-----------------------------------------------------------------------------
bool HistogramAnalysisAdaptor::Execute(vtkInsituDataAdaptor* data)
{
bool retval = false;
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))
if (vtkCompositeDataSet* cd = vtkCompositeDataSet::SafeDownCast(mesh))
{
vtk_histogram(this->Communicator, fd->GetArray(this->ArrayName.c_str()), this->Bins);
return true;
vtkSmartPointer<vtkCompositeDataIterator> iter;
iter.TakeReference(cd->NewIterator());
for (iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem())
{
retval = this->Execute(iter->GetCurrentDataObject()) || retval;
}
}
else
{
retval = this->Execute(mesh);
}
}
return retval;
}
//-----------------------------------------------------------------------------
bool HistogramAnalysisAdaptor::Execute(vtkDataObject* mesh)
{
if (vtkFieldData* fd = mesh->GetAttributesAsFieldData(this->Association))
{
if (vtkDataArray* da = fd->GetArray(this->ArrayName.c_str()))
{
vtk_histogram(this->Communicator, da, this->Bins);
}
return true;
}
return false;
}
......@@ -5,6 +5,7 @@
#include "vtkInsituAnalysisAdaptor.h"
#include <mpi.h>
class vtkDataObject;
/// HistogramAnalysisAdaptor is a vtkInsituAnalysisAdaptor specialization for
/// histogram analysis.
class HistogramAnalysisAdaptor : public vtkInsituAnalysisAdaptor
......@@ -22,6 +23,8 @@ protected:
HistogramAnalysisAdaptor();
virtual ~HistogramAnalysisAdaptor();
bool Execute(vtkDataObject* mesh);
MPI_Comm Communicator;
int Bins;
std::string ArrayName;
......
......@@ -82,7 +82,7 @@ void vtk_histogram(MPI_Comm comm, vtkDataArray* array, int bins)
MPI_Reduce(&worker.Histogram[0], &gHist[0], bins, MPI_UNSIGNED, MPI_SUM, 0, comm);
if (rank == 0)
{
std::cout << "Histogram (VTK):\n";
std::cout << "Histogram '" << array->GetName() << "' (VTK):\n";
double width = (g_range[1] - g_range[0]) / bins;
for (int i = 0; i < bins; ++i)
{
......
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