VTKFIG  0.20.20181114
Easy VTK based in situ visualization
template<class V >
void vtkfig::DataSet::SetCellScalar ( const V &  f,
const std::string  name 
)
inline

Set data of a scalar function defined on the cells of the grid.

Template Parameters
VVector class counting from zero with member functions size() and operator[]. std::vector will work.
Parameters
fVector of function values
nameName of function

Definition at line 573 of file vtkfigDataSet.h.

574  {
575  assert(this->data!=NULL);
576  auto ncells=this->data->GetNumberOfCells();
577  assert(ncells==values.size());
578  vtkSmartPointer<vtkDoubleArray>gridvalues;
579 
580  if (this->data->GetPointData()->HasArray(name.c_str()))
581  gridvalues=vtkDoubleArray::SafeDownCast(this->data->GetPointData()->GetAbstractArray(name.c_str()));
582  else
583  {
584  gridvalues=vtkSmartPointer<vtkDoubleArray>::New();
585  gridvalues->SetNumberOfComponents(1);
586  gridvalues->SetNumberOfTuples(ncells);
587  gridvalues->SetName(name.c_str());
588  this->data->GetCellData()->AddArray(gridvalues);
589  }
590 
591 
592  for (int i=0;i<ncells; i++)
593  gridvalues->InsertComponent(i,0,values[i]);
594 
595  gridvalues->Modified();
596  }
vtkSmartPointer< vtkDataSet > data