Author Topic: VTK export format  (Read 36 times)

csbrasnett

  • Newbie
  • *
  • Posts: 2
VTK export format
« on: November 28, 2018, 01:47:37 PM »
I'm generating surfaces using the surface mesh generation tool, and exporting these to a vtk file for further analysis. However, I'm trying to work out what the POINT_DATA and CELL_DATA sections of the vtk file are relating to. I suspect that they have something to do with whether a point is on a surface cap or not, and whether there is a the triangle described by the CELLS section of the file has an edge, or is on a cap, etc. but I'm not sure, and was wondering if this could please be confirmed? My problem comes from the fact that the zeros and ones in the files do not actually appear to link up with the points in the manner I would expect: points which are labelled as '0' in the vtk file are actually on the boundary of the box, and the list of points labelled '1' doesn't actually begin until much later.

Related to this is the difference between version 2.9 and 3.0 - the latter exports the caps, whilst the former doesn't, and so the POINT_DATA and CELL_DATA sections do not appear in the vtk file - hence my suspicion as to what the lists relate to.

Alexander Stukowski

  • Administrator
  • Hero Member
  • *****
  • Posts: 512
Re: VTK export format
« Reply #1 on: November 28, 2018, 04:15:53 PM »
Internally, Ovito operates with two separate triangle meshes: one for the actual surfaces and one for the "cap" polygons, which are generated at the intersections of the surface with the periodic cell boundaries. Each triangle mesh consists of a set of vertices ("POINTS") and a set of triangles ("CELLS") that connect these vertices.

During export to a VTK file, Ovito 3.0.0-dev (!) fuses the two meshes into a single output mesh by combining the points list and the cells list of the surface and cap meshes. However, the code is very lazy: It doesn't check for duplicate vertices that are shared by the surface mesh and the cap mesh. It simply outputs these vertices twice. In fact, you will find two copies of a vertex in the VTK file if it is located exactly on a periodic cell boundary.

As you mentioned, the VTK file contains two sections, POINT_DATA and CELL_DATA, which indicate for each vertex and for each triangle cell whether it originally was part of the surface mesh or the cap mesh using 0's and 1's. What might have confused you is the existence of the two vertex copies. One of them is marked as belonging to the surface mesh (0) while the other copy, coming later in the list, is marked as belonging to the cap mesh (1).

All these statements apply to the current development version (3.0.0-dev) of Ovito. If you are interest in further details, you can take a look at the source code of the routine that writes the VTK files:

https://gitlab.com/stuko/ovito/blob/master/src/plugins/mesh/io/VTKTriangleMeshExporter.cpp#L79-139

-Alex

csbrasnett

  • Newbie
  • *
  • Posts: 2
Re: VTK export format
« Reply #2 on: November 28, 2018, 05:27:38 PM »
Hi Alex,

Thanks for the quick response, it definitely clarified what I suspected might be going on with the files.

I can manually sort through the points and remove the intersections of points, but having had a look, I think that in the Ovitos scripting interface, the mesh data access (get_vertices(), get_faces(), get_face_adjacency()) methods will just get the data for the surface, and not the cap. Is this correct? The number of points is definitely lower, and approximately the same value as for when do a set difference point removal in my own python script.


Alexander Stukowski

  • Administrator
  • Hero Member
  • *****
  • Posts: 512
Re: VTK export format
« Reply #3 on: November 28, 2018, 07:15:35 PM »
Yes, the Python API gives you access to the surface mesh only. In fact, the SurfaceMesh data structure represents the original periodic mesh, which is still embedded in the periodic simulation domain and which has not been cut open at the simulation cell boundaries yet.

The cutting only happens during export to a VTK file or when the surface mesh is rendered. Then triangles that cross a periodic cell boundary get split into several truncated pieces, and that's also when the cap polygons are computed. The periodic mesh typically has fewer vertices than the non-periodic version that is exported to the VTK file, because extra vertices must be created at the intersections with the simulation box boundaries. 
« Last Edit: November 28, 2018, 07:17:21 PM by Alexander Stukowski »