[vtkusers] how to convert vtk polydata to dif file format
Cory Quammen
cory.quammen at kitware.com
Mon Oct 12 13:07:34 EDT 2015
Sebastian,
Glad to be of help,
Cory
On Sat, Oct 10, 2015 at 7:24 PM, Sebastian Hilbert <
sebastian.hilbert at gmx.net> wrote:
> Hi,
>
> Thanks for all your help. I finally got it done.
>
> Sebastian
>
> Am Donnerstag, 8. Oktober 2015, 09:32:20 schrieben Sie:
> > Sebastian,
> >
> > I have found that STL files do not have normal information, though I
> > haven't bothered to look up whether the format prevents the inclusion of
> > normals.
> >
> > You can use vtkPolyDataNormals to generate normals [1].
> >
> > normalsGenerator = vtk.vtkPolyDataNormals()
> > normalsGenerator .SetInputConnection(reader.GetOutputPort())
> > normalsGenerator .Update()
> >
> > pd = normalsGenerator.GetOutput()
> > ...
> >
> > HTH,
> > Cory
> >
> > [1] http://www.vtk.org/doc/nightly/html/classvtkPolyDataNormals.html
> >
> > On Wed, Oct 7, 2015 at 5:16 PM, Sebastian Hilbert <
> sebastian.hilbert at gmx.net
> > > wrote:
> > >
> > > Hi Cory,
> > >
> > > Thanks for your help. I tried your code and found that my vtk file does
> > > not
> > > seem to contain nomal information. I guess I need to find a way to
> compile
> > > them.
> > >
> > > Does that make sense ?
> > >
> > > Regards,
> > > Sebastian
> > >
> > > Am Mittwoch, 7. Oktober 2015, 10:14:44 schrieben Sie:
> > > > Hi Sebastian,
> > > >
> > > > Probably the easiest way to do this is to use VTK readers to read in
> the
> > > > VTK and STL files to load the surface data, then write out the DIF
> file
> > > > with standard Python ASCII file writing.
> > > >
> > > > Here's a sketch you can use to get started:
> > > >
> > > > import vtk
> > > >
> > > > reader = vtk.vtkPolyDataReader()
> > > > reader.SetFileName('/path/to/file.vtk')
> > > > reader.Update()
> > > >
> > > > pd = reader.GetOutput()
> > > >
> > > > print 'Vertices'
> > > >
> > > > for i in xrange(pd.GetNumberOfPoints()):
> > > > print pd.GetPoint(i)
> > > >
> > > > print 'Normals'
> > > > normals = pd.GetPointData().GetArray("Normals")
> > > >
> > > > print '---', pd.GetNumberOfPoints(), normals.GetNumberOfTuples()
> > > >
> > > > for i in xrange(normals.GetNumberOfTuples()):
> > > > print normals.GetValue(3*i), normals.GetValue(3*i + 1),
> > > >
> > > > normals.GetValue(3*i + 2)
> > > >
> > > > print 'Polygons'
> > > >
> > > > for i in xrange(pd.GetNumberOfPolys()):
> > > > cell = pd.GetCell(i)
> > > > pointIds = cell.GetPointIds()
> > > >
> > > > for j in xrange(pointIds.GetNumberOfIds()):
> > > > print pointIds.GetId(j)
> > > >
> > > > HTH,
> > > > Cory
> > > >
> > > >
> > > > On Sun, Oct 4, 2015 at 8:13 PM, Sebastian Hilbert <
> > >
> > > sebastian.hilbert at gmx.net
> > >
> > > > > wrote:
> > > > >
> > > > > Hi,
> > > > >
> > > > > I am trying to convert a model of the heart which is available as
> > >
> > > either
> > >
> > > > > stl
> > > > > or vtk polydata to a new file format called diffusion image format
> > >
> > > (dif)
> > >
> > > > > All files are provided below. The main question is. How do I
> construct
> > >
> > > the
> > >
> > > > > dif
> > > > > file when I have only vtk and stl file available ?
> > > > >
> > > > > dif is a format used by the medical software Ensite from St. Jude
> and
> > > > > looking
> > > > > at the spec for the dif format it seems related to what vtk can
> > >
> > > provide.
> > >
> > > > > It seems to work with vertices , normals and polygons.
> > > > >
> > > > > I wonder if anyone has some advice on how to map data obtained
> from an
> > >
> > > stl
> > >
> > > > > file or vtk polydata file to data used in the dif format. How do I
> > >
> > > extract
> > >
> > > > > vertices, normals and polygons from either stl and/or vtk ?
> > > > >
> > > > > The target format is like this:
> > > > > <DIFBody>
> > > > >
> > > > > <Volumes number="1">
> > > > >
> > > > > <Volume name="Left Atrium" color="eae0b2">
> > > > >
> > > > > <Vertices number="3984">
> > > > >
> > > > > 32.4603 6.0825 -40.3249
> > > > > 13.9858 7.9016 -41.0501
> > > > > 16.6287 7.6514 -40.4356
> > > > > 30.7806 7.9503 -41.1414
> > > > >
> > > > > </Vertices>
> > > > > <Normals number="3984">
> > > > >
> > > > > 0.220882 -0.586701 -0.779098
> > > > > -0.082953 -0.169572 -0.982021
> > > > > 0.393210 -0.647443 -0.652842
> > > > > -0.106461 -0.248735 -0.962703
> > > > >
> > > > > </Normals>
> > > > > <Polygons number="7968">
> > > > >
> > > > > 3 40 8
> > > > > 17 10 13
> > > > > 41 13 42
> > > > > 4 36 43
> > > > > </Polygons>
> > > > >
> > > > > </Volume>
> > > > >
> > > > > </Volumes>
> > > > > <Labels number="0">
> > > > > </Labels>
> > > > >
> > > > > </DIFBody>
> > > > >
> > > > > </DIF>
> > > > >
> > > > > Looking at the vtk file the polygons are different from the ones in
> > > > > the
> > > > > xml
> > > > > (dif) file. Looking at the stl file (ascii) I can see some vertex
> > > > > lines
> > > > > that
> > > > > match a line in the vertices section of the xml (dif) file but
> there
> > >
> > > are a
> > >
> > > > > lot
> > > > > more vertex lines in the stl file then there are in the xml (dif
> > > > > file).
> > > > >
> > > > > I would prefer to use python if that is an option.
> > > > >
> > > > > If anyone wants to have a look here are the correspondig files
> > > > >
> > > > > vtk: https://146.0.105.21/owncloud/index.php/s/NZqGwdQQSramk1w
> > > > > stl: https://146.0.105.21/owncloud/index.php/s/tWv7yKttA15hdoL
> > > > > dif: https://146.0.105.21/owncloud/index.php/s/3R8oKRxXK2oR5DD
> > > > >
> > > > > Any help is appreciated.
> > > > >
> > > > > Sebastian
> > > > > _______________________________________________
> > > > > 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:
> > > > > http://public.kitware.com/mailman/listinfo/vtkusers
>
>
--
Cory Quammen
R&D Engineer
Kitware, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151012/e1dfdf54/attachment.html>
More information about the vtkusers
mailing list