DataAdaptor.cxx 3.74 KB
Newer Older
1 2 3 4
#include "DataAdaptor.h"

#include "vtkDataObject.h"
#include "vtkDoubleArray.h"
5 6 7
#include "vtkImageData.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

namespace parallel3d
{
vtkStandardNewMacro(DataAdaptor);
//-----------------------------------------------------------------------------
DataAdaptor::DataAdaptor()
{
}

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

//-----------------------------------------------------------------------------
void DataAdaptor::Initialize(
  int g_x, int g_y, int g_z,
  int l_x, int l_y, int l_z,
  uint64_t start_extents_x, uint64_t start_extents_y, uint64_t start_extents_z,
  int tot_blocks_x, int tot_blocks_y, int tot_blocks_z,
  int block_id_x, int block_id_y, int block_id_z)
{
  // we only really need to save the local extents for our current example. So
  // we'll just save that.
  this->Extent[0] = start_extents_x;
  this->Extent[1] = start_extents_x + l_x - 1;
  this->Extent[2] = start_extents_y;
  this->Extent[3] = start_extents_y + l_y - 1;
  this->Extent[4] = start_extents_z;
  this->Extent[5] = start_extents_z + l_z - 1;
}

//-----------------------------------------------------------------------------
void DataAdaptor::AddArray(const std::string& name, double* data)
{
  if (this->Variables[name] != data)
    {
    this->Variables[name] = data;
    this->Arrays.erase(name);
    }
}

//-----------------------------------------------------------------------------
void DataAdaptor::ClearArrays()
{
  this->Variables.clear();
  this->Arrays.clear();
}

//-----------------------------------------------------------------------------
58
vtkDataObject* DataAdaptor::GetMesh(bool vtkNotUsed(structure_only))
59
{
60 61 62 63 64 65
  if (!this->Mesh)
    {
    this->Mesh = vtkSmartPointer<vtkImageData>::New();
    this->Mesh->SetExtent(this->Extent);
    }
  return this->Mesh;
66 67 68
}

//-----------------------------------------------------------------------------
69
bool DataAdaptor::AddArray(vtkDataObject* mesh, int association, const char* name)
70 71 72
{
  if (association != vtkDataObject::FIELD_ASSOCIATION_POINTS || name == NULL)
    {
73
    return false;
74 75 76 77 78
    }

  VariablesType::iterator iterV = this->Variables.find(name);
  if (iterV == this->Variables.end())
    {
79
    return false;
80 81 82 83 84 85 86 87 88 89 90 91
    }

  ArraysType::iterator iterA = this->Arrays.find(iterV->first);
  if (iterA == this->Arrays.end())
    {
    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);
92 93
    vtkImageData::SafeDownCast(mesh)->GetPointData()->SetScalars(vtkarray);
    return true;
94
    }
95
  return true;
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
}

//-----------------------------------------------------------------------------
unsigned int DataAdaptor::GetNumberOfArrays(int association)
{
  return (association == vtkDataObject::FIELD_ASSOCIATION_POINTS)?
    static_cast<unsigned int>(this->Variables.size()): 0;
}

//-----------------------------------------------------------------------------
const char* DataAdaptor::GetArrayName(int association, unsigned int index)
{
  if (association != vtkDataObject::FIELD_ASSOCIATION_POINTS)
    {
    return NULL;
    }
  unsigned int count = 0;
  for (VariablesType::iterator iter=this->Variables.begin(), max=this->Variables.end();
    iter != max; ++iter, ++count)
    {
    if (count==index)
      {
      return iter->first.c_str();
      }
    }
  return NULL;
}

//-----------------------------------------------------------------------------
void DataAdaptor::ReleaseData()
{
  this->ClearArrays();
128
  this->Mesh = NULL;
129 130 131
}

}