-1

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?

AFPP
  • 1,494
  • 11
  • 23
  • 1
    You should post minimum, complete and verifiable example. Read https://stackoverflow.com/help/mcve . The details you've given aren't enough for us to help you. – Destructor Sep 07 '18 at 08:21

1 Answers1

1

vtkDataArray is an abstract class. You cannot create an object of an abstract class. So try using vtkFloatArray or vtkDoubleArray instead of vtkDataArray.