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