text: Before you start!¶
  - This notebook assumes that shapeworks conda environment has been activated using
  conda activate shapeworkson the terminal.
  - See Setting Up ShapeWorks Environment to learn how to set up your environment to start using shapeworks library. Please note, the prerequisite steps will use the same code to setup the environment for this notebook and import
  shapeworkslibrary.
  - Note example output was generated on Linux/Mac environment and may look different on Windows.
  In this notebook, you will learn:¶
  - How to define your dataset location and explore what is available in it
  - How to load a single mesh
  - How to convert
  shapeworksmesh to
  vtkmesh for visualization
  - How to visualize a surface mesh.
  This notebook assumes that you have downloaded
  ellipsoid_1mode and you have placed the unzipped folder
  ellipsoid_1modein
  Examples/Python/Data. Feel free to use your own dataset.
  import os # for paths and mkdir # dataset name is the folder name for your dataset datasetName = 'ellipsoid_1mode' # path to the dataset where we can find shape data # here we assume shape data are given as surface meshes shapeDir = '../../Data/' + datasetName + '/meshes/' print('Dataset Name: ' + datasetName) print('Shape Directory: ' + shapeDir)
  import glob # for paths and file-directory search from pathlib import Path # for generating robust paths irrespective of the platform:Win/Linux/Mac # file extension for the shape data shapeExtention = '.vtk' # let's get a list of files for available meshes)
  # select a shape by setting the shape index (in the filenames list) shapeIdx = 0 # the filename for the selected shape shapeFilename = shapeFilenames[shapeIdx] # use shapeworks Mesh class to load it print('Loading: ' + shapeFilename) shapeMesh = sw.Mesh(shapeFilename) # let's print out header information of this mesh - TODO: #828 print('Header information: ') print(shapeMesh)
  # convert shapeworks mesh to a vtk mesh shapeMesh_vtk = sw.sw2vtkMesh(shapeMesh)
  4. Visualizing surface mesh using
  pyvista¶
  pyvista is a python library for 3D visualization and analysis. It.
  # to have an interactive visualization, # click r to reset the view after zooming # click w to show wireframe and s to return back to sur notebook = False # True sets the figure inline in the notebook. shapeMesh_vtk.plot(notebook = notebook)
  5. Visualizing multiple meshes¶
  When exploring datasets and results of different grooming (data preprocessing) steps, it is important to simultaneously visualize multiple shape samples. Here, we visualize two meshes side-by-side and link their views using
  pyvista. This linking is useful to make all rendering windows share the same camera view.
  # select a shape by setting the shape index (in the filenames list) shapeIdx2 = 1 # the filename for the selected shape shapeFilename2 = shapeFilenames[shapeIdx2] # use shapeworks Mesh class to load it print('Loading: ' + shapeFilename2) shapeMesh2 = sw.Mesh(shapeFilename2) # let's print out header information of this mesh print('Header information: ') print(shapeMesh2)
  Now we can view the two meshes side by side using the ShapeWorks plot_meshes() function. To view the meshes in a side-by-side view, we set the use_same_window parameter to False. To view the meshes in the same window, we set the use_same_window parameter to True.
  meshList = [shapeMesh, shapeMesh2] # View meshes side-by-side sw.plot_meshes(meshList, use_same_window=False, notebook=notebook)
  # View meshes in the same window sw.plot_meshes(meshList, use_same_window=True, notebook=notebook)
  