@@ -457,22 +457,22 @@ def add_zero_z_coord(pt):
457457
458458 mesh .write (file )
459459
460- def writeToVtk (points , edges , file ):
460+ def writeToVtk (points , edges , filename ):
461461 """Writes a VTK mesh file from the given contour
462462 (points and edges)."""
463- def add_zero_z_coord ( pt ):
464- return np . concatenate (( pt , [ 0 ]))
465- points_z = []
466- for pt in points :
467- points_z . append ( add_zero_z_coord ( pt ))
468-
469- cells = [( "line" , edges )]
470-
471- mesh = meshio . Mesh ( points_z , cells )
472-
473- mesh . write ( file , binary = False )
474-
475-
463+ lines = [ '# vtk DataFile Version 3.0 \n ' ,
464+ f' { filename } written by compass/landice/mesh.py \n ' ,
465+ 'ASCII \n ' ,
466+ 'DATASET POLYDATA \n \n ' ,
467+ f'POINTS { len ( points [: - 1 ]) } float \n ' ]
468+
469+ for pt in points [: - 1 ]:
470+ lines . append ( f' { pt [ 0 ] } { pt [ 1 ] } 0.0 \n ' )
471+ lines . append ( f' \n LINES { len ( edges ) } { len ( edges ) * 3 } \n ' )
472+ for edge in edges :
473+ lines . append ( f'2 { edge [ 0 ] } { edge [ 1 ] } \n ' )
474+ with open ( filename , "w" ) as f :
475+ f . writelines ( lines )
476476
477477def remove_triangles (contour , name , debug = False ):
478478 """ find sequences of four points where the first
0 commit comments