Oh my gosh, Bill! Thanks so much for bothering to read through my code and making it work!! =D<br>Couldn&#39;t be more grateful! (Else I might be in panic attack, with less than an hour on hand...)<br><br>Yes, I needed to subtract one from my node numbers, since counting needs to start from 0, but my data&#39;s points started from1.<br>

I was wondering why even my small data file did not display as i intended, though i did not did an error. But now, both are working great.<br>Thanks so much Bill!!!<br><br>Helvin<br><br><div class="gmail_quote">On Mon, Aug 24, 2009 at 3:42 AM, Bill Lorensen <span dir="ltr">&lt;<a href="mailto:bill.lorensen@gmail.com">bill.lorensen@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">element_ID_list.InsertNextId(node_no) should be<br>
element_ID_list.InsertNextId(node_no-1)<br>
<div><div></div><div class="h5"><br>
On Sun, Aug 23, 2009 at 10:18 AM, Helvin Lui&lt;<a href="mailto:helvinlui@gmail.com">helvinlui@gmail.com</a>&gt; wrote:<br>
&gt; Hi everyone! :-)<br>
&gt; I have written a function that imports a mesh from a .txt file.<br>
&gt;<br>
&gt; def displayMesh(file_path):<br>
&gt;     import vtk<br>
&gt;     from vtk import vtkTriangle<br>
&gt;     VTK_TRIANGLE = vtkTriangle().GetCellType()<br>
&gt;<br>
&gt;     with open(file_path, &#39;r&#39;) as f:<br>
&gt;<br>
&gt;         aMeshGrid = vtk.vtkUnstructuredGrid()<br>
&gt;         aMeshGrid.Allocate(2, 180)<br>
&gt;<br>
&gt;         # Get number of mesh points<br>
&gt;         no_points = int(f.readline())<br>
&gt;<br>
&gt;         # Set number of points<br>
&gt;         meshPoints = vtk.vtkPoints()<br>
&gt;         meshPoints.SetNumberOfPoints(no_points)<br>
&gt;<br>
&gt;         # Iterate through point data<br>
&gt;         for i in range(no_points):<br>
&gt;             # Get coord info for each point<br>
&gt;             point_info = f.readline().split() # I need to split, before I<br>
&gt; assign to point_coord<br>
&gt;                                               # else the whole thing is<br>
&gt; split into single numbers<br>
&gt;             #print point_info # Check reading<br>
&gt;             point_ID = (int(point_info[0])-1) # -1 because the IDs need to<br>
&gt; start with 0.<br>
&gt;             point_x = float(point_info[1])<br>
&gt;             point_y = float(point_info[2])<br>
&gt;             point_z = float(point_info[3])<br>
&gt;             # Set coord info in mesh<br>
&gt;             meshPoints.InsertPoint(point_ID, point_x, point_y, point_z)<br>
&gt;<br>
&gt;         # Get number of elements<br>
&gt;         no_elements = int(f.readline())<br>
&gt;<br>
&gt;         # Set number of elements<br>
&gt;         for i in range(no_elements):<br>
&gt;             element_info = f.readline().split()<br>
&gt;             element_ID = (int(element_info[0])-1)<br>
&gt;             element_no_nodes = int(element_info[1])<br>
&gt;<br>
&gt;             element_ID_list = vtk.vtkIdList()<br>
&gt;             for j in range(element_no_nodes):<br>
&gt;                 node_no = int(element_info[j+2])<br>
&gt;                 element_ID_list.InsertNextId(node_no)<br>
&gt;                 print j, node_no<br>
&gt;             if element_no_nodes == 3: # a triangle<br>
&gt;                 cell_type = VTK_TRIANGLE<br>
&gt;<br>
&gt;             aMeshGrid.InsertNextCell(cell_type, element_ID_list)<br>
&gt;<br>
&gt;     aMeshGrid.SetPoints(meshPoints)<br>
&gt;<br>
&gt;     aMeshMapper = vtk.vtkDataSetMapper()<br>
&gt;     aMeshMapper.SetInput(aMeshGrid)<br>
&gt;<br>
&gt;     aMeshActor = vtk.vtkActor()<br>
&gt;     aMeshActor.SetMapper(aMeshMapper)<br>
&gt;     aMeshActor.GetProperty().SetDiffuseColor(1, 0, 0)<br>
&gt;<br>
&gt;     # Create the usual rendering stuff.<br>
&gt;     ren = vtk.vtkRenderer()<br>
&gt;     renWin = vtk.vtkRenderWindow()<br>
&gt;     renWin.AddRenderer(ren)<br>
&gt;     renWin.SetSize(300, 300)<br>
&gt;     iren = vtk.vtkRenderWindowInteractor()<br>
&gt;     iren.SetRenderWindow(renWin)<br>
&gt;<br>
&gt;     ren.AddActor(aMeshActor)<br>
&gt;<br>
&gt;     # Zoom, to see actor. (in case it was too small to see)<br>
&gt;     ren.ResetCamera()<br>
&gt; #<a href="http://www.vtk.org/doc/nightly/html/classvtkRenderer.html#b14d1aeb74a4990f2da819e09d028d65" target="_blank">http://www.vtk.org/doc/nightly/html/classvtkRenderer.html#b14d1aeb74a4990f2da819e09d028d65</a><br>


&gt;     cam1 = ren.GetActiveCamera()<br>
&gt;<br>
&gt;     ## Render the scene and start interaction.<br>
&gt;     iren.Initialize()<br>
&gt;     renWin.Render()<br>
&gt;     iren.Start()<br>
&gt;<br>
&gt; My goal is to display this particular file:<br>
&gt;     44<br>
&gt;      1      0.000000000      0.000000000      0.000000000<br>
&gt;      2      0.100000001      0.000000000      0.000000000<br>
&gt;      3      0.200000003      0.000000000      0.000000000<br>
&gt;      4      0.300000012      0.000000000      0.000000000<br>
&gt;      5      0.400000006      0.000000000      0.000000000<br>
&gt;      6      0.500000000      0.000000000      0.000000000<br>
&gt;      7      0.600000024      0.000000000      0.000000000<br>
&gt;      8      0.699999988      0.000000000      0.000000000<br>
&gt;      9      0.800000012      0.000000000      0.000000000<br>
&gt;     10      0.900000036      0.000000000      0.000000000<br>
&gt;     11      1.000000000      0.000000000      0.000000000<br>
&gt;     12      0.000000000      0.066666670      0.000000000<br>
&gt;     13      0.100000001      0.066666670      0.000000000<br>
&gt;     14      0.200000003      0.066666670      0.000000000<br>
&gt;     15      0.300000012      0.066666670      0.000000000<br>
&gt;     16      0.400000006      0.066666670      0.000000000<br>
&gt;     17      0.500000000      0.066666670      0.000000000<br>
&gt;     18      0.600000024      0.066666670      0.000000000<br>
&gt;     19      0.699999988      0.066666670      0.000000000<br>
&gt;     20      0.800000012      0.066666670      0.000000000<br>
&gt;     21      0.900000036      0.066666670      0.000000000<br>
&gt;     22      1.000000000      0.066666670      0.000000000<br>
&gt;     23      0.000000000      0.133333340      0.000000000<br>
&gt;     24      0.100000001      0.133333340      0.000000000<br>
&gt;     25      0.200000003      0.133333340      0.000000000<br>
&gt;     26      0.300000012      0.133333340      0.000000000<br>
&gt;     27      0.400000006      0.133333340      0.000000000<br>
&gt;     28      0.500000000      0.133333340      0.000000000<br>
&gt;     29      0.600000024      0.133333340      0.000000000<br>
&gt;     30      0.699999988      0.133333340      0.000000000<br>
&gt;     31      0.800000012      0.133333340      0.000000000<br>
&gt;     32      0.900000036      0.133333340      0.000000000<br>
&gt;     33      1.000000000      0.133333340      0.000000000<br>
&gt;     34      0.000000000      0.200000018      0.000000000<br>
&gt;     35      0.100000001      0.200000018      0.000000000<br>
&gt;     36      0.200000003      0.200000018      0.000000000<br>
&gt;     37      0.300000012      0.200000018      0.000000000<br>
&gt;     38      0.400000006      0.200000018      0.000000000<br>
&gt;     39      0.500000000      0.200000018      0.000000000<br>
&gt;     40      0.600000024      0.200000018      0.000000000<br>
&gt;     41      0.699999988      0.200000018      0.000000000<br>
&gt;     42      0.800000012      0.200000018      0.000000000<br>
&gt;     43      0.900000036      0.200000018      0.000000000<br>
&gt;     44      1.000000000      0.200000018      0.000000000<br>
&gt;     60<br>
&gt;      1      3      1      2     13      0      1         0.00500<br>
&gt;      2      3      2      3     14      0      1         0.00500<br>
&gt;      3      3      3      4     15      0      1         0.00500<br>
&gt;      4      3      4      5     16      0      1         0.00500<br>
&gt;      5      3      5      6     17      0      1         0.00500<br>
&gt;      6      3      6      7     18      0      1         0.00500<br>
&gt;      7      3      7      8     19      0      1         0.00500<br>
&gt;      8      3      8      9     20      0      1         0.00500<br>
&gt;      9      3      9     10     21      0      1         0.00500<br>
&gt;     10      3     10     11     22      0      1         0.00500<br>
&gt;     11      3      1     13     12      0      1         0.00500<br>
&gt;     12      3      2     14     13      0      1         0.00500<br>
&gt;     13      3      3     15     14      0      1         0.00500<br>
&gt;     14      3      4     16     15      0      1         0.00500<br>
&gt;     15      3      5     17     16      0      1         0.00500<br>
&gt;     16      3      6     18     17      0      1         0.00500<br>
&gt;     17      3      7     19     18      0      1         0.00500<br>
&gt;     18      3      8     20     19      0      1         0.00500<br>
&gt;     19      3      9     21     20      0      1         0.00500<br>
&gt;     20      3     10     22     21      0      1         0.00500<br>
&gt;     21      3     12     13     24      0      1         0.00500<br>
&gt;     22      3     13     14     25      0      1         0.00500<br>
&gt;     23      3     14     15     26      0      1         0.00500<br>
&gt;     24      3     15     16     27      0      1         0.00500<br>
&gt;     25      3     16     17     28      0      1         0.00500<br>
&gt;     26      3     17     18     29      0      1         0.00500<br>
&gt;     27      3     18     19     30      0      1         0.00500<br>
&gt;     28      3     19     20     31      0      1         0.00500<br>
&gt;     29      3     20     21     32      0      1         0.00500<br>
&gt;     30      3     21     22     33      0      1         0.00500<br>
&gt;     31      3     12     24     23      0      1         0.00500<br>
&gt;     32      3     13     25     24      0      1         0.00500<br>
&gt;     33      3     14     26     25      0      1         0.00500<br>
&gt;     34      3     15     27     26      0      1         0.00500<br>
&gt;     35      3     16     28     27      0      1         0.00500<br>
&gt;     36      3     17     29     28      0      1         0.00500<br>
&gt;     37      3     18     30     29      0      1         0.00500<br>
&gt;     38      3     19     31     30      0      1         0.00500<br>
&gt;     39      3     20     32     31      0      1         0.00500<br>
&gt;     40      3     21     33     32      0      1         0.00500<br>
&gt;     41      3     23     24     35      0      1         0.00500<br>
&gt;     42      3     24     25     36      0      1         0.00500<br>
&gt;     43      3     25     26     37      0      1         0.00500<br>
&gt;     44      3     26     27     38      0      1         0.00500<br>
&gt;     45      3     27     28     39      0      1         0.00500<br>
&gt;     46      3     28     29     40      0      1         0.00500<br>
&gt;     47      3     29     30     41      0      1         0.00500<br>
&gt;     48      3     30     31     42      0      1         0.00500<br>
&gt;     49      3     31     32     43      0      1         0.00500<br>
&gt;     50      3     32     33     44      0      1         0.00500<br>
&gt;     51      3     23     35     34      0      1         0.00500<br>
&gt;     52      3     24     36     35      0      1         0.00500<br>
&gt;     53      3     25     37     36      0      1         0.00500<br>
&gt;     54      3     26     38     37      0      1         0.00500<br>
&gt;     55      3     27     39     38      0      1         0.00500<br>
&gt;     56      3     28     40     39      0      1         0.00500<br>
&gt;     57      3     29     41     40      0      1         0.00500<br>
&gt;     58      3     30     42     41      0      1         0.00500<br>
&gt;     59      3     31     43     42      0      1         0.00500<br>
&gt;     60      3     32     44     43      0      1         0.00500<br>
&gt; This however, runs into no errors in command line, and the render window<br>
&gt; appears, but the actor is not displayed. A window pops up saying<br>
&gt; &quot;vtkpython.exe has stopped working, windows is checking for a solution to<br>
&gt; the problem.&quot;<br>
&gt; To better understand why this is happening, I wrote a simpler mesh file:<br>
&gt;     7<br>
&gt;     1       1.000000000       0.000000000       0.000000000<br>
&gt;     2       3.000000000       0.000000000       0.000000000<br>
&gt;     3       0.000000000       2.000000000       0.000000000<br>
&gt;     4       2.000000000       2.000000000       0.000000000<br>
&gt;     5       4.000000000       2.000000000       0.000000000<br>
&gt;     6       1.000000000       4.000000000       0.000000000<br>
&gt;     7       3.000000000       4.000000000       0.000000000<br>
&gt;     6<br>
&gt;     1       3       1       4       3      0      1         0.00500<br>
&gt;     2       3       1       2       4      0      1         0.00500<br>
&gt;     3       3       2       5       4      0      1         0.00500<br>
&gt;     4       3       3       4       6      0      1         0.00500<br>
&gt;     5       3       4       7       6      0      1         0.00500<br>
&gt;     6       3       4       5       7      0      1         0.00500<br>
&gt; When I run the code to display this mesh, it worked.<br>
&gt; Mystery. I wonder why? Do you know?<br>
&gt; Help much appreciated!  : )<br>
&gt; --<br>
&gt; Helvin<br>
&gt;<br>
&gt; &quot;Though the world may promise me more, I&#39;m just made to be filled with the<br>
&gt; Lord.&quot;<br>
&gt;<br>
</div></div>&gt; _______________________________________________<br>
&gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;<br>
&gt; Visit other Kitware open-source projects at<br>
&gt; <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
&gt;<br>
&gt; Please keep messages on-topic and check the VTK FAQ at:<br>
&gt; <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
&gt;<br>
&gt; Follow this link to subscribe/unsubscribe:<br>
&gt; <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
&gt;<br>
&gt;<br>
</blockquote></div><br><br clear="all"><br>-- <br>Helvin <br><br>&quot;Though the world may promise me more, I&#39;m just made to be filled with the Lord.&quot;<br>