Home

Awesome

MeshEditor

A tool for editing and landmarking 3D meshes, written using pyvista.

<img src="./img/Recording_Landmark_mode.gif" width="40%"> <img src="./img/Recording_Edit_Mode.gif" width="40%">

Note

Due to a longstanding bug in vtk (https://github.com/pyvista/pyvista/issues/1033) that stops closing of pyvista plotters, there may be trouble on Mac OS. It seems to work on the latest MacOS (Ventura, at the time of writing) but not earlier.

Dependencies

Installation

Creating the conda environment from scratch

  1. Install anaconda or miniconda (https://docs.anaconda.com/anaconda/install/index.html)
  2. Create a new conda environment with python 3.10. In your anaconda prompt (Windows) or computer terminal (Mac/Linux)
conda create --name MeshEditing python=3.10
  1. Install MeshEditor by typing in the terminal/Anaconda prompt
conda activate MeshEditing
pip install MeshEditor

Try to run a demo script

conda activate MeshEditing
python path/to/demo/script.py

Demos

Check the demos folder for:

Overview

MeshEditor module

The MeshEditor module implements two classes:

Using the Mesh Editor

The different modes are 'edit' and 'landmark' and are specified by the second positional argument to the MeshEditor constructor

MeshEditor controls - 'edit' mode

Brush Selection

<img src="./img/Recording_Edit_Mode.gif" width="40%">

Geodesic Selection

<img src="./img/Geodesic_Selection.gif" width="40%">

Geodesic selection selects vertices within a given geodesic distance of the picked point

Other controls

Experimental (buggy) features

MeshEditor controls - 'landmark' mode

<img src="./img/Recording_Landmark_mode.gif" width="40%">

Using the BatchMeshEditor

Various attributes of the BatchMeshEditor object need to be set inside of the script:

Two methods of the Batch Mesheditor need to be run in sequence 'prepareFiles' (finds the files and preloads them if necessary) 'processFiles' strats the process of iterating through the files. For each file:

  1. The MeshEditor will open
  2. You edit or landmark the scan as needed
  3. You press 'a' to save the results. The background of the editor will go black if the file has been saved.
  4. Close the editor by pressing 'q' and the next file will open.

Note

If there are multiple files with tthe same filename in the source path (e.g. in different sub folders) only one will be processed. This is regardless of whether 'PreserveSubFolders' is true or not. A warning will be printed in the terminal. I don't recommend having files with the same filename in the source directory.

MIRC-specific instructions

This was deveoped as an in house tool for the Laboratory of Imaging Genetics at KU Leuven. The following instructions are mostly relevant to those working on the MIRC infrastructure.

Working in PyCharm with conda

The relevant conda environment (MeshEditing) is installed on micsd01 at the time of writing. Or you can create your own with the required dependencies. Contact Dominique or the MIRC Wiki for up-to-date instructions for how to create your own conda environment.

The simplest way to run the (e.g demo) scripts is to

  1. Modify the scripts to process the meshes that you want to process
  2. In the terminal run:
conda activate MeshEditing
python scriptName.py # change to the full or relative path to the script you are trying to run

Those who are more used to MATLAB might prefer work in an interactive IDE. With PyCharm it is very easy to set python interpreters per project and will give you excellent debugging features so I recommend that. You will first need to make a new pycharm project configured with the correct python interpreter. This interpreter only needs to correspond to a conda environment in which the relevant dependencies are installed and could be 'MeshEditing' or one you create yourself. To create a new project correctly configured. It is easiest if you first activate the conda environment and then start pycharm:

  1. Start pycharm by typing in ther terminal
conda activate MeshEditing
pycharm
  1. File>NewProject
    • Set the 'location' to where you want to keep your scripts
    • Check the 'PythonInterpreter' is 'Python 3.10 (MeshEditing)' # or whatever you are expecting it to be :p
    • Uncheck 'Create a main.py welcome script'
    • Click Create

Within this open project you can open (File>Open), edit and run scripts using the configured python interpreter. For anybody missing MATLAB's 'cell mode' ... there is a plugin for that:

  1. File>Settings>Plugins
  2. Search for 'pycharm cell mode' and install You can then make 'cells' in python scripts between double '##' Having created this project you can open it again at any point (File>Open) and run and edit scripts according to the required Python interpreter.

Integration with MATLAB BatchMapper