[vtkusers] how to convert vtk polydata to dif file format

Cory Quammen cory.quammen at kitware.com
Wed Oct 7 10:14:44 EDT 2015


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/20151007/124df3a1/attachment.html>


More information about the vtkusers mailing list