I am trying to store a scalar field in a vtkUnstructuredGrid
using vtkDataArray
in VTK 8.1, and ultimately write it to a file. I am compiling my code by Visual Studio 2017 Community edition. However, the compiler is not happy about the following line:
// Add a scalar field to the unstructured grid
vtkSmartPointer<vtkDataArray> data_array = vtkSmartPointer<vtkDataArray>::New();
I get the following error:
Error C2440 '<function-style-cast>': cannot convert from 'initializer list' to 'vtkSmartPointer<vtkDataArray>' mycode c:\vtk\src\common\core\vtksmartpointer.h 155
I think I have the required headers:
#include "vtkCellArray.h"
#include "vtkCellData.h"
#include "vtkDataSet.h"
#include "vtkPoints.h"
#include <vtkPointData.h>
#include <vtkCellData.h>
#include <vtkDoubleArray.h>
#include <vtkDataArray.h>
#include <vtkUnstructuredGrid.h>
#include <vtkXMLUnstructuredGridWriter.h>
My research online found out that the declaration line for data_array
should work but I have no idea why the compiler does not like it.
Could someone please help me? Is there any other way of storing a scalar field in a vtkUnstructuredGrid
and skip using vtkDataArray
?