The following tutorials show how to use Mesh2HRTF. If you are new to Mesh2HRTF it is recommended that you go through all of the tutorials before starting your own projects.
This tutorial covers the scattering from a rigid sphere due to a point source that radiates sound.

Add -> Mesh -> Ico Sphere).
Subdivisions: 6Radius: 0.1 mLocation: X 0, Y 0, Z 0Rotation: X 0°, Y 0°, Z 0°

If you are working on the 'Radiation' tutorial, go back.
Add a point source (Add -> Light -> Point).

Location: X 0 m, Y 0.2 m, Z 0 m

Once the Mesh2HRTF project is prepared in Blender it has to be exported for the numerical calculation as follows.
If you are currently doing the 'Scripting Blender' tutorial, go back.
Open the Mesh2HRTF Export Menu (File -> Export -> Mesh2HRTF). (If you cannot find the export option, go to the [Installation] section and just follow the 'Mesh2Input' section.)

Choose or create an export folder, e.g., /Users/JDoe/Simulations/RigidSpherePointSource.
CAUTION: Before you click on Export Mesh2HRTF you have to adjust the following settings accordingly!
Title: Scattering from a rigid sphere by a point sourceBEM Method: ML-FMM BEMSource Type: Point sourcePictures: FalseReference: FalseCompute HRIRs: FalseUnit: m c: 343.18rho: 1.1839Evaluation Grids Name: PlaneHorizontalMaterials Path(s): NoneMin. frequency: 1000Max. frequency: 16000Frequencies: Step sizeValue: 1000
Press Export Mesh2HRTF.
A detailed description of all export parameters can be found here.
A detailed description of the project folder structure that is created by the export can be found here.
If you are working on the 'Radiation' tutorial, go back.
In the folder /Users/JDoe/Simulations/RigidSpherePointSource/NumCalc/source_1 run the command NumCalc from a terminal.
>NumCalc.txt to the command creates an additional log file.2>NumCalcErr.txt to the command creates an additional error log file, i.e. NumCalc >NumCalc.txt 2>NumCalcErr.txt.Note: There are bash scripts that can be used or modified to run multiple projects and cores with a single command. See [NumCalc] for more information
Note: NumCalc saves the HRTFs in a bunch of text files. For a detailed description of the created files, see [Mesh2HRTF Project Folder]
python Output2HRTF.py in a terminal in your project folder. This executes output_to_hrtf from the mesh2hrtf Python package for your proejct.The following files are created in YourProjectFolder/Output2HRTF:
To generate VTK files for visualization in Paraview, you need to run export_to_vtk from the mesh2hrtf Python package in a next step.
The following files are created in YourProjectFolder/Output2HRTF/Reference_vtk:
If you are currently doing the 'Non-rigid boundary conditions' tutorial, go back.
Alternative: MATLAB Post-processing
Navigate to your project folder (/Users/JDoe/Simulations/RigidSpherePointSource).
Run Output2HRTF. The following files are created in YourProjectFolder/Output2HRTF:
The repository also contains a script Output2HRTF_RunAll.m located in mesh2hrtf-git/mesh2hrtf/Output2HRTF/Source. It allows you to run Output2HRTF in every NumCalc subfolder of your project if you ran calculations on multiple CPUs/cores. It also comes with an option of deleting the raw simulation data after processing, as it can be rather storage-intensive depending on your simulation.
If you are currently doing the 'Non-rigid boundary conditions' tutorial, go back.
If you are working on the 'HRTF' tutorial, go back.
Run Output2VTK to create VTK-files for visualization. (Make sure that you added the directory mesh2hrtf/PostProcessing/VisualizationForParaView(Matlab) in the source files to your Matlab path. Otherwise there might be an error!)
Apply the visualization should look like this:
This tutorial covers the usage of material definitions on a rigid sphere to define a sound source (vibrating element) its the surface and calculate the resulting sound pressure distribution on the sphere.



The complete materials list looks like this:

Switch the top panel to Edit mode (3D View: Object Mode -> Edit mode or Tab).

Define all elements as Skin and one single element as Left ear:

Title: Radiation from an active vibrating element in a sphereBEM Method: ML-FMM BEMSource Type: Left earPictures: FalseReference: FalseCompute HRIRs: FalseUnit: m c: 343.18rho: 1.1839Evaluation Grids Name: ARIMaterials Path(s): NoneMin. frequency: 1000Max. frequency: 16000Frequencies: Step sizeValue: 1000
Apply the visualization should look like this:
This tutorial introduces the use of materials to define admittance boundary conditions.
Follow the steps in the first tutorial to create an Icosphere and a Light Point source in Blender (remember to name them correctly!)
Similar to the Material definition of the second tutorial

Title: Non-rigid boundary conditionsBEM Method: ML-FMM BEMSource Type: Point sourcePictures: FalseReference: FalseCompute HRIRs: FalseUnit: m c: 343.18rho: 1.1839Evaluation Grids Name: PlaneHorizontalMaterials Path(s): NoneMin. frequency: 2000Max. frequency: 2001Frequencies: Step sizeValue: 1
Apply the visualization should look like this:
This tutorial covers the calculation of a head-related transfer function based on a head-shaped mesh and a point source placed directly next to one of the ears.
File -> Open or File -> Import -> ply). For the tutorial we use this .blend file mesh (sourceforge.net) from Ziegelwanger et al (2015). Cite this paper when using this mesh.
0 and Scale set to 1.

Rename the object to "Reference".

Add three materials, switch to Edit mode, assign the Skin material to all elements and switch to Face Select as in the second tutorial.
Assign the materials Left ear and Right ear to elements within the ear canal. These will represent the microphones.


Switch back to Object Mode (3D View: Edit mode -> Object Mode or Tab).
Add -> Light -> Point).




Title: Uniform HRTF CalculationBEM Method: ML-FMM BEMSource Type: Point SourcePictures: FalseReference: TrueCompute HRIRs: Truec: 343.18rho: 1.1839Unit: mmEvaluation Grids: ARIMaterials Path(s): NoneMin. frequency: 100Max. frequency: 16000Frequencies: Step sizeValue: 100
inspect_sofa_files function in the mesh2hrtf package to plot HRTFs for different anglesimport mesh2hrtf
folder = '/path/to/your/project/folder'
mesh2hrtf.inspect_sofa_files(folder, pattern=None, atol=0.1, plot=None, savedir=None)
Alternative: Post-processing in MATLAB
[TBD] Please try if your_variable = SOFAload('HRIR_ARI.sofa'); works as well. Using the HRTFs results in time reversed HRIRs.
a) your_variable = SOFAload('HRTF_ARI.sofa');
b) SOFAplotHRTF(your_variable, 'mode');
'mode' being chosen from the following to display the HRTF:
- 'EtcHorizontal' energy-time curve in the horizontal plane (+/- 5 deg)
- 'EtcMedian' energy-time curve in the median plane (+/- 2 deg)
- 'MagHorizontal' magnitude spectra in the horizontal plane (+/- 5 deg)
- 'MagMedian' magnitude spectra in the median plane (+/- 2 deg)
- 'magspectrum' single magnitude spectrum for direction DIR in COLOR
The following image shows the energy time curve in the horzontal pane (mode = EtcHorizontal):

WARNING: Using 'HRTF_ARI.sofa' with SOFAplotHRTF and SOFAconvertConventions results in time reversed HRIRs. We recommend to use the Compute HRIRs option during the project export in Blender and directly pass 'HRIR_ARI.sofa' to these functions.
Additionally to the GUI-based use of Blender for preparing the Mesh2HRTF simulations, there is the option of scripting both the export and the generation of the geometries with Blender's built-in Python IDE.




New at the top of the text editor to open an empty text console.Edit -> Preferences -> Interface -> Display).

As an example, do the first tutorial up to project export.
Now, instead of using the export window, you can copy and adjust the following script into the text editor.
import bpy
# save Mesh2HRTF project ----------------------------------
bpy.ops.export_mesh2hrtf.inp(
filepath="/path/to/project_folder", # change this path to your export folder
programPath="/path/to/mesh2hrtf-git/mesh2hrtf", # change this to the location of Mesh2HRTF
materialSearchPaths='None',
title="Scattering from a rigid sphere by a point source",
method="ML-FMM BEM",
sourceType = "Point source",
pictures=False,
reference=False,
computeHRIRs=False,
unit="m",
speedOfSound="343.18",
densityOfMedium="1.1839",
evaluationGrids="PlaneHorizontal",
minFrequency=1000,
maxFrequency=16000,
frequencyVectorType="Step size",
frequencyVectorValue=1000)

Press the "Play" button at the top of the text editor to execute the script. This alternative method triggers the exact same export routine described in the first tutorial .
Please note! The variables speedOfSound and densityOfMedium are string representations of the numbers. This was done in order to avoid rounding errors due to limited precision in Blender. The strings are written into the NC.inp text file where they are then correctly used for the numerical calculation.
Apart from the Export Mesh2HRTF routine, you can script almost any other operation in Blender and in this way hard code your pre-processing steps. For instance you could loop over several iterations with small changes in your setup or export parameters easily. For more information on scripting Blender, refer to the Blender documentation.