Given the following data:
The Cartesian co-ordinates of the vertices in the surface mesh: n vertices x 3
The vertex indices of each face in the surface mesh: n faces x 3
I’m trying to make some 3D file that I can readily import to
3D Slicer for registration against a 2nd VTK file.
339,263,314340,315,263340,293,315368,314,313368,339,314369,263,33936 - Pastebin.com
Vertices: 16.215,13.236,126.06516.149,14.237,125.70816.843,13.707,125.85115.178,14.2 - Pastebin.com
I have been trying various packages/libraries etc.
Trimesh in Python and am running into issues probably due to my poor Python ability. I’m opening a Stackoverflow question about that separately. I’ve used vtkwrite but the “Precision” option is broken in the package and it’s doing some odd-rounding that is changing the original data too much.
supporting data formats page, it seems like I want something other than VTK that will preserve orientation.
How are ya’ll overcoming this?
I’m no expert but I’ve seen this done with vtkPolydata - if anyone else weighs in I’d defer to them! You can see an example of it here:
This file has been truncated.
def CreateMesh(self, modelNode, arrayVertices, arrayVertexNormals, arrayTriangles, labelsScalars, arrayScalars):
# based on https://vtk.org/Wiki/VTK/Examples/Python/DataManipulation/Cube.py
# modelNode : a vtkMRMLModelNode in the Slicer scene which will hold the mesh
# arrayVertices : list of triples [[x1,y1,z2], [x2,y2,z2], ... ,[xn,yn,zn]] of vertex coordinates
# arrayVertexNormals : list of triples [[nx1,ny1,nz2], [nx2,ny2,nz2], ... ] of vertex normals
# arrayTriangles : list of triples of 0-based indices defining triangles
# labelsScalars : list of strings such as ["bipolar", "unipolar"] to label the individual scalars data sets
# arrayScalars : list of n m-tuples for n vertices and m individual scalar sets
# create the building blocks of polydata including data attributes.
mesh = vtk.vtkPolyData()
points = vtk.vtkPoints()
normals = vtk.vtkFloatArray()
polys = vtk.vtkCellArray()
# load the array data into the respective VTK data structures
#self.addLog(" Initializing vertices.")
for i in range(len(arrayVertices)):
In this example, a scalar value is assigned to each vertex but I don’t think that’s required for polydata. I’m not sure if you’ll face the same rounding issues you’re having with Trimesh.
Ah back to SlicerEAMapReader, I have a ticket open on that Git due to some issues with the latest version (4.13) and Slicer 5.0.3. Nontheless, the script is helpful, thanks! Looking forward to more input.