[vtkusers] How to save gradients got form gradient filter as a vector vtk file?
Yunbai Wang
ywang286 at sheffield.ac.uk
Fri Feb 9 12:51:17 EST 2018
Hi
Just update my problem.
Now I change the way to get the gradient, but I could not write correct
file of gradien.
I pass the array to polydata, but there is no point in polydata. I have no
idea why this happen.
And how can I write a vector image by vtk that the ITK(Elastix) could use?
Many thanks
Yun
here is my code:
vtkSmartPointer<vtkFloatArray> gradients =
vtkSmartPointer<vtkFloatArray>::New();
gradients->SetNumberOfComponents(3);
gradients->SetNumberOfTuples(output_volume_distmap->GetNumberOfPoints());
gradients->SetName("gradients");
int counter = 0;
for (unsigned int i = 0; i < phi_grid.ni; ++i) {
for (unsigned int j = 0; j < phi_grid.nj; ++j) {
for (unsigned int k = 0; k < phi_grid.nk; ++k) {
double g[3];
output_volume_distmap->GetPointGradient(i, j, k, distance, g);
gradients->InsertTuple3(counter, g[0], g[1], g[2]);
counter++;
}
}
}
vtkSmartPointer<vtkPolyData> vectorG =
vtkSmartPointer<vtkPolyData>::New();
vectorG->GetPointData()->SetVectors(gradients);
vtkSmartPointer<vtkPolyDataWriter> writer_dirmap_o =
vtkSmartPointer<vtkPolyDataWriter>::New();
writer_dirmap_o->SetFileName(outname_dirmap_o.c_str());
writer_dirmap_o->SetInputData(vectorG);
writer_dirmap_o->Write();
On 8 February 2018 at 12:48, Yunbai Wang <ywang286 at sheffield.ac.uk> wrote:
> 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()->Ge
> tNumberOfPoints());
> 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/20180209/de7959c8/attachment.html>
More information about the vtkusers
mailing list