[vtkusers] How to save gradients got form gradient filter as a vector vtk file?

Yunbai Wang ywang286 at sheffield.ac.uk
Thu Feb 8 07:48:49 EST 2018


Hi

I am just new to the VTK, and want to write the result of gradient filter
as a polydata by polydatawriter.

But I cannot passing the result of greadient filter to vtkDataArray
correctly. And the examples of image gradient and gradient filter don't
mention how save and write the gradient as vector to the vtk file.

Here is this part of my code :
// Compute the gradient of the data
vtkSmartPointer<vtkGradientFilter> gradientFilter =
vtkSmartPointer<vtkGradientFilter>::New();

gradientFilter->SetInputData(output_volume_distmap);
gradientFilter->Update()

//save gradient array
vtkSmartPointer<vtkDataArray> gradients =
vtkSmartPointer<vtkDataArray>::New();

gradients->SetNumberOfTuples(gradientFilter->GetOutput()->
GetNumberOfPoints());
gradients->SetName("gradients");

/******here is part that I don't konw how to pass the result of gradient
filter
          to the vtkDataArray*****/


//write vector to vtk file
vtkSmartPointer<vtkPolyData> vectors_gradient =
vtkSmartPointer<vtkPolyData>::New();

vector->GetPointData()->SetVectors(gradients);


vtkSmartPointer<vtkPolyDataWriter> writer_dirmap_o =
vtkSmartPointer<vtkPolyDataWriter>::New();

writer_dirmap_o->SetFileName(outname_dirmap_o.c_str());
writer_dirmap_o->SetInputData(vectors_gradient);
writer_dirmap_o->Write();

I may do it in wrong way or  there is another way to got a gradient vector
vtk file. Please feel free to give me some advices or helps.
Thank you so much for your helps.

Many thanks
Yun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://vtk.org/pipermail/vtkusers/attachments/20180208/d07fb42d/attachment.html>


More information about the vtkusers mailing list