Search code examples
meshlab

How to set the parameters for Uniform Mesh Resampling in a meshlabserver .mlx script


I would like to apply the Uniform Mesh Resampling filter automatically to a set of meshes, each with different geometry. I obtained a .mlx script for this by saving the output from Filters:Show current filter script. However, the parameters in the script seem to be set for the specific geometry of the mesh I used:

<filter name="Uniform Mesh Resampling">
  <Param type="RichAbsPerc" value="1.1632" min="0" name="CellSize" max="232.648"/>
  <Param type="RichAbsPerc" value="0.93059" min="-46.5296" name="Offset" max="46.5296"/>
  <Param type="RichBool" value="true" name="mergeCloseVert"/>
  <Param type="RichBool" value="false" name="discretize"/>
  <Param type="RichBool" value="true" name="multisample"/>
  <Param type="RichBool" value="true" name="absDist"/>
 </filter>

What I would like is to set the Cell size to 0.5% and the Offset to 51%, and get Meshlab to figure min and max from the geometry of each of the meshes I'm processing. How could I do it?

Thanks in advance!


Solution

  • I found one solution: First, I'm using a command line that I wrote -- meshgeometry -- to get the size of the mesh (meshgeometry is available at https://github.com/r03ert0/meshgeometry). Then, I generate the meshlabserver script using bash like this:

    diag=$(meshgeometry -i $holes_surf -size|cut -d' ' -f 2|awk -F, '{print sqrt($1**2+$2**2+$3**2)}')
    diag5=$(echo $diag|awk '{print $1/5}');
    precision=$(echo $diag|awk '{print $1*0.005}');
    offset=$(echo $diag|awk '{print $1/5*2*0.01}');
    
    cat>"script.mlx"<<EOF
    <!DOCTYPE FilterScript>
    <FilterScript>
     <filter name="Uniform Mesh Resampling">
      <Param type="RichAbsPerc" value="$precision" min="0" name="CellSize" max="$diag"/>
      <Param type="RichAbsPerc" value="$offset" min="-$diag5" name="Offset" max="$diag5"/>
      <Param type="RichBool" value="false" name="mergeCloseVert"/>
      <Param type="RichBool" value="false" name="discretize"/>
      <Param type="RichBool" value="true" name="multisample"/>
      <Param type="RichBool" value="true" name="absDist"/>
     </filter>
    
    </FilterScript>
    EOF
    

    After that, I can call meshlabserver with my script.mlx file like this:

    meshlabserver -i source-mesh.ply -o dest-mesh.ply -s "script.mlx"