[vtkusers] Writing an Unstructured data to a VTK file

Bill Lorensen bill.lorensen at gmail.com
Fri Dec 22 07:52:22 EST 2017


What version of VTK are you using?


On Fri, Dec 22, 2017 at 7:20 AM, the lily <the.1.lily at hotmail.com> wrote:
> Hello,
>
> I have some arrays storing the values of the data and I want to write it as
> a vtk file, the data is unstructured tetrahedrons
>
> - Three arrays (X, Y, and Z) storing the coordinates
> - An array (data) storing scalar field
> - An array (ptIds) storing cell connectivity
>
> I'm trying to pass the scalar field to vtkUnstructuredGrid but I get an
> error:
>
> error: no member named 'SetInputData' in
>       'vtkUnstructuredGrid'
>
> This is the code I'm using
>
> vtkSmartPointer< vtkPoints > points = vtkSmartPointer< vtkPoints > :: New();
>
> vtkSmartPointer< vtkFloatArray > val = vtkSmartPointer< vtkFloatArray > ::
> New();
>
> val->SetNumberOfComponents(1);
>
>
> for(int i=0; i < npts; i++)
>
> {
>
>     points->InsertNextPoint(X[i], Y[i], Z[i]);
>     val->InsertTuple1(i, data[i]);
>
> }
>
> vtkSmartPointer<vtkUnstructuredGrid> unstructuredGrid =
> vtkSmartPointer<vtkUnstructuredGrid>::New();
>  unstructuredGrid->SetPoints(points);
> unstructuredGrid->GetPointData()->SetScalars(val);
>
> for(int i=0; i< ntets; i++)
>       unstructuredGrid->InsertNextCell(VTK_TETRA, 4, ptIds[i]);
>
> vtkDataSetWriter *w = vtkDataSetWriter::New();
> w->SetFileTypeToASCII();
> w->SetInputData(unstructuredGrid);
>  w->SetFileName("data.vtk");
>  w->Write();
>
>
> What is the correct way to pass the scalar field?
>
>
>
> -Thanks
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> https://vtk.org/mailman/listinfo/vtkusers
>



-- 
Unpaid intern in BillsBasement at noware dot com


More information about the vtkusers mailing list