[vtkusers] get vtkImage data from vtkPolyData
Mathieu Malaterre
Mathieu.Malaterre at creatis.insa-lyon.fr
Thu Sep 11 05:54:47 EDT 2003
Michel,
Here is what I use in a python script:
import vtk
from vtk.util.misc import vtkGetDataRoot
# Get the location of the data.
VTK_DATA_ROOT = vtkGetDataRoot()
ima = vtk.vtkImageData()
ima.SetOrigin( 120,80,220 );
ima.SetSpacing( 1,1,1 )
ima.SetDimensions( 40,20,10 )
ima.SetScalarTypeToUnsignedChar ()
ima.AllocateScalars()
reader = vtk.vtkSTLReader()
reader.SetFileName(VTK_DATA_ROOT + "/Data/42400-IDGH.stl")
dataToStencil = vtk.vtkPolyDataToImageStencil ()
dataToStencil .SetInput (reader.GetOutput())
stencil = vtk.vtkImageStencil ()
stencil .SetInput (ima)
stencil .SetStencil (dataToStencil .GetOutput())
stencil .ReverseStencilOff()
stencil .SetBackgroundValue (50)
stencil .Update()
writer = vtk.vtkStructuredPointsWriter()
writer.SetFileName("michel.vtk" )
writer.SetInput( stencil.GetOutput())
writer.Write()
HTH
mathieu
mcornetd at student.fsa.ucl.ac.be wrote:
> Hello!
>
> I discovering vtk and can't manage to get vtkImageData
> from a vtkPolyData. I apologize for asking stupid
> questions.
> Is there a methode you advise me to use?
>
> I tried to go through a
> vtkPolyDataToImageStencil and then an ImageStencil
> but I get a black Image as output.
>
> Thank you for having taken the time to read about my
> problem. I hope to get news from you soon.
>
> Michel Cornet d'Elzius
>
> ==========================================
> Here is my code:
>
> vtkPolyData* P= fileToPolyData(path);
> ...
> //Change to ImageData
> vtkPolyDataToImageStencil*
> fil1=vtkPolyDataToImageStencil::New();
> fil1->SetInput(P);
> fil1->Update();
>
> vtkImageStencil* fil2=vtkImageStencil::New();
> fil2->SetStencil(fil1->GetOutput(););
> fil2->Update();
>
>
> //Obtenir la carte de disparité
> vtkImageEuclideanDistance*
> dist=vtkImageEuclideanDistance::New();
> dist->SetInput(fil2->GetOutput());
> ...
> =============================================
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
--
Mathieu Malaterre
CREATIS
28 Avenue du Doyen LEPINE
B.P. Lyon-Montchat
69394 Lyon Cedex 03
http://www.creatis.insa-lyon.fr/~malaterre/
More information about the vtkusers
mailing list