HistogramAnalysisAdaptor.cxx 1.42 KB
Newer Older
1 2 3
#include "HistogramAnalysisAdaptor.h"

#include "vtkDataObject.h"
4
#include "vtkFieldData.h"
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#include "vtkInsituDataAdaptor.h"
#include "vtkObjectFactory.h"

#include "vtk_histogram.h"

vtkStandardNewMacro(HistogramAnalysisAdaptor);
//-----------------------------------------------------------------------------
HistogramAnalysisAdaptor::HistogramAnalysisAdaptor() :
  Communicator(MPI_COMM_WORLD),
  Bins(0),
  Association(vtkDataObject::FIELD_ASSOCIATION_POINTS)
{
}

//-----------------------------------------------------------------------------
HistogramAnalysisAdaptor::~HistogramAnalysisAdaptor()
{
}

//-----------------------------------------------------------------------------
void HistogramAnalysisAdaptor::Initialize(
  MPI_Comm comm, int bins, int association, const std::string& arrayname)
{
  this->Communicator = comm;
  this->Bins = bins;
  this->ArrayName = arrayname;
  this->Association = association;
}

//-----------------------------------------------------------------------------
bool HistogramAnalysisAdaptor::Execute(vtkInsituDataAdaptor* data)
{
37 38 39 40 41 42 43 44 45 46
  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;
47
}