# Need help making a 3D mesh given co-ordinates of the vertices and vertex indices of each face for 3D Slicer - trimesh/vtkwrite/etc

**URL:** https://discourse.slicer.org/t/need-help-making-a-3d-mesh-given-co-ordinates-of-the-vertices-and-vertex-indices-of-each-face-for-3d-slicer-trimesh-vtkwrite-etc/24536
**Category:** Support
**Tags:** vtk, python, matlab, 3d-model, meshing
**Created:** [July 28, 2022, 4:27am UTC](https://discourse.slicer.org/t/need-help-making-a-3d-mesh-given-co-ordinates-of-the-vertices-and-vertex-indices-of-each-face-for-3d-slicer-trimesh-vtkwrite-etc/24536 "2022-07-28T04:27:13Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jsalas424](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@jsalas424](https://discourse.slicer.org/u/jsalas424)
#### Post date: [July 28, 2022, 4:27am UTC](https://discourse.slicer.org/t/need-help-making-a-3d-mesh-given-co-ordinates-of-the-vertices-and-vertex-indices-of-each-face-for-3d-slicer-trimesh-vtkwrite-etc/24536/1 "2022-07-28T04:27:13Z")

</div>

Hi all,

Given the following data:

1. The Cartesian co-ordinates of the vertices in the surface mesh: n vertices x 3
2. 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](https://www.slicer.org/) for registration against a 2nd VTK file.

Faces: [339,263,314340,315,263340,293,315368,314,313368,339,314369,263,33936 - Pastebin.com](https://pastebin.com/qWq7aiEs)  
Vertices: [16.215,13.236,126.06516.149,14.237,125.70816.843,13.707,125.85115.178,14.2 - Pastebin.com](https://pastebin.com/VxsxsdcM)

I have been trying various packages/libraries etc.

I’ve tried [Trimesh in Python](https://pythonawesome.com/python-library-for-loading-and-using-triangular-meshes/) and am running into issues probably due to my poor Python ability. I’m opening a [Stackoverflow question about that separately](https://stackoverflow.com/questions/73147271/need-help-making-a-3d-mesh-given-co-ordinates-of-the-vertices-and-vertex-indices). I’ve used [vtkwrite](https://www.mathworks.com/matlabcentral/fileexchange/47814-vtkwrite-exports-various-2d-3d-data-to-paraview-in-vtk-file-format) but the “Precision” option is broken in the package and it’s doing some odd-rounding that is changing the original data too much.

From the [supporting data formats](https://slicer.readthedocs.io/en/latest/user_guide/data_loading_and_saving.html#supported-data-formats) page, it seems like I want something other than VTK that will preserve orientation.

How are ya’ll overcoming this?

---

<div class="post-metadata">

### Author: ![connorh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/connorh/32/79802_2.png) [@connorh](https://discourse.slicer.org/u/connorh)
#### Post date: [July 28, 2022, 2:01pm UTC](https://discourse.slicer.org/t/need-help-making-a-3d-mesh-given-co-ordinates-of-the-vertices-and-vertex-indices-of-each-face-for-3d-slicer-trimesh-vtkwrite-etc/24536/2 "2022-07-28T14:01:29Z")

</div>

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:

> <https://github.com/stephan1312/SlicerEAMapReader/blob/2798100fe2aebf482a83b347c1cef18135f2df87/EAMapReader-Slicer-4.11/lib/Slicer-4.11/qt-scripted-modules/EAMapReader.py#L218-L290>

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.

---

<div class="post-metadata">

### Author: ![jsalas424](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@jsalas424](https://discourse.slicer.org/u/jsalas424)
#### Post date: [July 28, 2022, 3:19pm UTC](https://discourse.slicer.org/t/need-help-making-a-3d-mesh-given-co-ordinates-of-the-vertices-and-vertex-indices-of-each-face-for-3d-slicer-trimesh-vtkwrite-etc/24536/3 "2022-07-28T15:19:45Z")

</div>

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.
