Oh my gosh, Bill! Thanks so much for bothering to read through my code and making it work!! =D<br>Couldn'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'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"><<a href="mailto:bill.lorensen@gmail.com">bill.lorensen@gmail.com</a>></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<<a href="mailto:helvinlui@gmail.com">helvinlui@gmail.com</a>> wrote:<br>
> Hi everyone! :-)<br>
> I have written a function that imports a mesh from a .txt file.<br>
><br>
> def displayMesh(file_path):<br>
> import vtk<br>
> from vtk import vtkTriangle<br>
> VTK_TRIANGLE = vtkTriangle().GetCellType()<br>
><br>
> with open(file_path, 'r') as f:<br>
><br>
> aMeshGrid = vtk.vtkUnstructuredGrid()<br>
> aMeshGrid.Allocate(2, 180)<br>
><br>
> # Get number of mesh points<br>
> no_points = int(f.readline())<br>
><br>
> # Set number of points<br>
> meshPoints = vtk.vtkPoints()<br>
> meshPoints.SetNumberOfPoints(no_points)<br>
><br>
> # Iterate through point data<br>
> for i in range(no_points):<br>
> # Get coord info for each point<br>
> point_info = f.readline().split() # I need to split, before I<br>
> assign to point_coord<br>
> # else the whole thing is<br>
> split into single numbers<br>
> #print point_info # Check reading<br>
> point_ID = (int(point_info[0])-1) # -1 because the IDs need to<br>
> start with 0.<br>
> point_x = float(point_info[1])<br>
> point_y = float(point_info[2])<br>
> point_z = float(point_info[3])<br>
> # Set coord info in mesh<br>
> meshPoints.InsertPoint(point_ID, point_x, point_y, point_z)<br>
><br>
> # Get number of elements<br>
> no_elements = int(f.readline())<br>
><br>
> # Set number of elements<br>
> for i in range(no_elements):<br>
> element_info = f.readline().split()<br>
> element_ID = (int(element_info[0])-1)<br>
> element_no_nodes = int(element_info[1])<br>
><br>
> element_ID_list = vtk.vtkIdList()<br>
> for j in range(element_no_nodes):<br>
> node_no = int(element_info[j+2])<br>
> element_ID_list.InsertNextId(node_no)<br>
> print j, node_no<br>
> if element_no_nodes == 3: # a triangle<br>
> cell_type = VTK_TRIANGLE<br>
><br>
> aMeshGrid.InsertNextCell(cell_type, element_ID_list)<br>
><br>
> aMeshGrid.SetPoints(meshPoints)<br>
><br>
> aMeshMapper = vtk.vtkDataSetMapper()<br>
> aMeshMapper.SetInput(aMeshGrid)<br>
><br>
> aMeshActor = vtk.vtkActor()<br>
> aMeshActor.SetMapper(aMeshMapper)<br>
> aMeshActor.GetProperty().SetDiffuseColor(1, 0, 0)<br>
><br>
> # Create the usual rendering stuff.<br>
> ren = vtk.vtkRenderer()<br>
> renWin = vtk.vtkRenderWindow()<br>
> renWin.AddRenderer(ren)<br>
> renWin.SetSize(300, 300)<br>
> iren = vtk.vtkRenderWindowInteractor()<br>
> iren.SetRenderWindow(renWin)<br>
><br>
> ren.AddActor(aMeshActor)<br>
><br>
> # Zoom, to see actor. (in case it was too small to see)<br>
> ren.ResetCamera()<br>
> #<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>
> cam1 = ren.GetActiveCamera()<br>
><br>
> ## Render the scene and start interaction.<br>
> iren.Initialize()<br>
> renWin.Render()<br>
> iren.Start()<br>
><br>
> My goal is to display this particular file:<br>
> 44<br>
> 1 0.000000000 0.000000000 0.000000000<br>
> 2 0.100000001 0.000000000 0.000000000<br>
> 3 0.200000003 0.000000000 0.000000000<br>
> 4 0.300000012 0.000000000 0.000000000<br>
> 5 0.400000006 0.000000000 0.000000000<br>
> 6 0.500000000 0.000000000 0.000000000<br>
> 7 0.600000024 0.000000000 0.000000000<br>
> 8 0.699999988 0.000000000 0.000000000<br>
> 9 0.800000012 0.000000000 0.000000000<br>
> 10 0.900000036 0.000000000 0.000000000<br>
> 11 1.000000000 0.000000000 0.000000000<br>
> 12 0.000000000 0.066666670 0.000000000<br>
> 13 0.100000001 0.066666670 0.000000000<br>
> 14 0.200000003 0.066666670 0.000000000<br>
> 15 0.300000012 0.066666670 0.000000000<br>
> 16 0.400000006 0.066666670 0.000000000<br>
> 17 0.500000000 0.066666670 0.000000000<br>
> 18 0.600000024 0.066666670 0.000000000<br>
> 19 0.699999988 0.066666670 0.000000000<br>
> 20 0.800000012 0.066666670 0.000000000<br>
> 21 0.900000036 0.066666670 0.000000000<br>
> 22 1.000000000 0.066666670 0.000000000<br>
> 23 0.000000000 0.133333340 0.000000000<br>
> 24 0.100000001 0.133333340 0.000000000<br>
> 25 0.200000003 0.133333340 0.000000000<br>
> 26 0.300000012 0.133333340 0.000000000<br>
> 27 0.400000006 0.133333340 0.000000000<br>
> 28 0.500000000 0.133333340 0.000000000<br>
> 29 0.600000024 0.133333340 0.000000000<br>
> 30 0.699999988 0.133333340 0.000000000<br>
> 31 0.800000012 0.133333340 0.000000000<br>
> 32 0.900000036 0.133333340 0.000000000<br>
> 33 1.000000000 0.133333340 0.000000000<br>
> 34 0.000000000 0.200000018 0.000000000<br>
> 35 0.100000001 0.200000018 0.000000000<br>
> 36 0.200000003 0.200000018 0.000000000<br>
> 37 0.300000012 0.200000018 0.000000000<br>
> 38 0.400000006 0.200000018 0.000000000<br>
> 39 0.500000000 0.200000018 0.000000000<br>
> 40 0.600000024 0.200000018 0.000000000<br>
> 41 0.699999988 0.200000018 0.000000000<br>
> 42 0.800000012 0.200000018 0.000000000<br>
> 43 0.900000036 0.200000018 0.000000000<br>
> 44 1.000000000 0.200000018 0.000000000<br>
> 60<br>
> 1 3 1 2 13 0 1 0.00500<br>
> 2 3 2 3 14 0 1 0.00500<br>
> 3 3 3 4 15 0 1 0.00500<br>
> 4 3 4 5 16 0 1 0.00500<br>
> 5 3 5 6 17 0 1 0.00500<br>
> 6 3 6 7 18 0 1 0.00500<br>
> 7 3 7 8 19 0 1 0.00500<br>
> 8 3 8 9 20 0 1 0.00500<br>
> 9 3 9 10 21 0 1 0.00500<br>
> 10 3 10 11 22 0 1 0.00500<br>
> 11 3 1 13 12 0 1 0.00500<br>
> 12 3 2 14 13 0 1 0.00500<br>
> 13 3 3 15 14 0 1 0.00500<br>
> 14 3 4 16 15 0 1 0.00500<br>
> 15 3 5 17 16 0 1 0.00500<br>
> 16 3 6 18 17 0 1 0.00500<br>
> 17 3 7 19 18 0 1 0.00500<br>
> 18 3 8 20 19 0 1 0.00500<br>
> 19 3 9 21 20 0 1 0.00500<br>
> 20 3 10 22 21 0 1 0.00500<br>
> 21 3 12 13 24 0 1 0.00500<br>
> 22 3 13 14 25 0 1 0.00500<br>
> 23 3 14 15 26 0 1 0.00500<br>
> 24 3 15 16 27 0 1 0.00500<br>
> 25 3 16 17 28 0 1 0.00500<br>
> 26 3 17 18 29 0 1 0.00500<br>
> 27 3 18 19 30 0 1 0.00500<br>
> 28 3 19 20 31 0 1 0.00500<br>
> 29 3 20 21 32 0 1 0.00500<br>
> 30 3 21 22 33 0 1 0.00500<br>
> 31 3 12 24 23 0 1 0.00500<br>
> 32 3 13 25 24 0 1 0.00500<br>
> 33 3 14 26 25 0 1 0.00500<br>
> 34 3 15 27 26 0 1 0.00500<br>
> 35 3 16 28 27 0 1 0.00500<br>
> 36 3 17 29 28 0 1 0.00500<br>
> 37 3 18 30 29 0 1 0.00500<br>
> 38 3 19 31 30 0 1 0.00500<br>
> 39 3 20 32 31 0 1 0.00500<br>
> 40 3 21 33 32 0 1 0.00500<br>
> 41 3 23 24 35 0 1 0.00500<br>
> 42 3 24 25 36 0 1 0.00500<br>
> 43 3 25 26 37 0 1 0.00500<br>
> 44 3 26 27 38 0 1 0.00500<br>
> 45 3 27 28 39 0 1 0.00500<br>
> 46 3 28 29 40 0 1 0.00500<br>
> 47 3 29 30 41 0 1 0.00500<br>
> 48 3 30 31 42 0 1 0.00500<br>
> 49 3 31 32 43 0 1 0.00500<br>
> 50 3 32 33 44 0 1 0.00500<br>
> 51 3 23 35 34 0 1 0.00500<br>
> 52 3 24 36 35 0 1 0.00500<br>
> 53 3 25 37 36 0 1 0.00500<br>
> 54 3 26 38 37 0 1 0.00500<br>
> 55 3 27 39 38 0 1 0.00500<br>
> 56 3 28 40 39 0 1 0.00500<br>
> 57 3 29 41 40 0 1 0.00500<br>
> 58 3 30 42 41 0 1 0.00500<br>
> 59 3 31 43 42 0 1 0.00500<br>
> 60 3 32 44 43 0 1 0.00500<br>
> This however, runs into no errors in command line, and the render window<br>
> appears, but the actor is not displayed. A window pops up saying<br>
> "vtkpython.exe has stopped working, windows is checking for a solution to<br>
> the problem."<br>
> To better understand why this is happening, I wrote a simpler mesh file:<br>
> 7<br>
> 1 1.000000000 0.000000000 0.000000000<br>
> 2 3.000000000 0.000000000 0.000000000<br>
> 3 0.000000000 2.000000000 0.000000000<br>
> 4 2.000000000 2.000000000 0.000000000<br>
> 5 4.000000000 2.000000000 0.000000000<br>
> 6 1.000000000 4.000000000 0.000000000<br>
> 7 3.000000000 4.000000000 0.000000000<br>
> 6<br>
> 1 3 1 4 3 0 1 0.00500<br>
> 2 3 1 2 4 0 1 0.00500<br>
> 3 3 2 5 4 0 1 0.00500<br>
> 4 3 3 4 6 0 1 0.00500<br>
> 5 3 4 7 6 0 1 0.00500<br>
> 6 3 4 5 7 0 1 0.00500<br>
> When I run the code to display this mesh, it worked.<br>
> Mystery. I wonder why? Do you know?<br>
> Help much appreciated! : )<br>
> --<br>
> Helvin<br>
><br>
> "Though the world may promise me more, I'm just made to be filled with the<br>
> Lord."<br>
><br>
</div></div>> _______________________________________________<br>
> Powered by <a href="http://www.kitware.com" 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" 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" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
><br>
><br>
</blockquote></div><br><br clear="all"><br>-- <br>Helvin <br><br>"Though the world may promise me more, I'm just made to be filled with the Lord."<br>