Menu

Is there a way to Automate the Hausdorff Distance?

Users
2015-02-10
2015-09-13
  • Diego Araujo

    Diego Araujo - 2015-02-10

    Calculating the Hausdorff Distance in Meshlab requires a few steps:

    • align two meshes
    • freeze the matrix
    • calculate the HD by specifying some parameters

    Is there a way to optimize it to make the process automatic and allow calculation of a batch of models? Lets say I want to calculate the HD of 100 pairs of meshes.

    I know that would require some scripting, but I am seeking some advice on whether that script would be easier to achieve. I can see some problems with the alignment part.

    Regards

     
  • Melanie

    Melanie - 2015-07-28

    Hello Diego,

    I try to do the same thing as you.
    Did you manage to solve your problem?

    EDIT: my files are already align, I just need to apply the HD filter and export the two samples as .xyz files.

    Thanks in advance for your answer.

    Regards

     

    Last edit: Melanie 2015-07-28
  • Tim Ayres

    Tim Ayres - 2015-09-13

    Melanie,

    I'm going to do some shameless self promotion here and suggest you check out my bash meshlabserver scripting interface on github.

    At minimum you will need the file mlx.bsh under main/, and possibly measure.bsh as well. You will also need bash v>=4.2. For Windows install Cygwin; if you're on Linux or OS X you probably already have it.

    Here's a sample script that should do what you're asking:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    #!/bin/bash
    
    . ./mlx.bsh
    
    ml_IF="HD_0_target.obj" # Target mesh; ml_IF must be set before calling mlx_begin 
    ml_IF1="HD_1_sampled.obj" # Sampled mesh
    
    measure_all "$ml_IF1" # This is needed if you want to use the same defaults as
    #+ the MeshLab GUI for sample_num & maxdist (need vars AABB[diag] & num_V)
    
    # Output HausdorffClosestPoints.xyz (layer 3) 
    mlx_begin # Start writing mlx file; write opening tags
    mlx_hausdorff_distance saveSample="true" # can also set  sample_num= maxdist=
    mlx_end # Finish writing mlx file; write closing tag
    meshlabserver -l hd_log.txt -i "$ml_IF" -i "$ml_IF1" -o "HausdorffClosestPoints.xyz" -s "$ml_SF"
    
    # Re-run to output HausdorffSamplePoint.xyz (layer 2)
    mlx_begin
    mlx_hausdorff_distance saveSample="true"
    mlx_change_layer layerNum=2
    mlx_end
    
    meshlabserver -i "$ml_IF" -i "$ml_IF1" -o "HausdorffSamplePoint.xyz" -s "$ml_SF"
    

    A few notes:

    • If you plan to specify the number of samples and the max distance then you don't need measure.bsh or to run measure_all.
    • You can specify every option that is available in the gui; if blank then defaults will be used. Read mlx.bsh for details on option names, defaults, etc.
    • Since you can only output a single layer with -o this needs to run twice in order to save both layers as xyz. Another option would be to only run once and also output an mlp file, which saves all files. However, the samples would be in ply format and you would then have to convert to xyz.
    • The above will save to a log file for every operation; each run will append to this log.
    • The shell scripting to feed in your source files is left to you, as it is highly dependent on your naming scheme.

    Please let me know if you try it out, and especially if you run into any issues with my code.

    Thanks,
    Tim

     

Log in to post a comment.

MongoDB Logo MongoDB