2

I am trying to apply a smoothing algorithm on a .STL file.

I use Eyeshot from DevDept to load and manipulate STL files.

There is no built-in method in Eyeshot.

To apply a smoothing algorithm, I try to convert the Eyeshot entity to an entity in Geometry3DSharp because there is a built-in smoothing method but, the conversion is not possible. But the result is not as expected.

Any suggestion on how to apply a smoothing algorithm on a 3D object, please?

Here is what I try to smooth the object using Geometry3DSharp :

DMesh3 mesh = load_my_mesh_somehow();
Remesher r = new Remesher(mesh);
r.PreventNormalFlips = true;
r.SetTargetEdgeLength(0.5);
for ( int k = 0; k < 20; ++k )
    r.BasicRemeshPass();
user213305
  • 402
  • 2
  • 10
  • This is better to do with Matlab. You can call a Matlab dll from c# : https://www.mathworks.com/help/pde/ug/stl-file-import.html?force_isolation=true – jdweng Apr 22 '21 at 16:37
  • I am very surprised that there is no smoothing option directly integrated in `Eyeshot`. Did you even asked the support about it ? I mean there is demo showing curve face being tessellated live so I am pretty certain there is a way to achieve this. – Franck Apr 22 '21 at 18:59
  • Actually, if the mesh structure of Eyeshot can be easily convertible to unity mesh, it would be great. Then, we can use some unity linked libraries. – Fatih ÖZEN Apr 23 '21 at 09:27
  • @FatihÖZEN I do convert eyeshot mesh to obj then load in Unity without any issues. – Franck Apr 27 '21 at 17:40
  • @Franck I already use similar manner. Im writing mesh as stl file. But, successive writing and reading is not logical because it takes seconds based on their length of vertices. If we can create a fast solution, it would be great! And not wrapped to directly eyeshot to dynamically editing mesh files. – Fatih ÖZEN Apr 28 '21 at 17:02
  • @FatihÖZEN Well you can always implement the Laplacian algorithm yourself. But again I am surprise there isn't the SimplifyMesh feature. Did they told you if they were already working or implementing it or if they ever will ? – Franck Apr 28 '21 at 17:09
  • @Franck I did not make any contact. Im just like you. :) – Fatih ÖZEN Apr 29 '21 at 18:10
  • @FatihÖZEN well not at all. If I don't find a feature I ask them first as I might have overlooked the feature as it's names something else. They have the best support I have ever dealt with. – Franck Apr 29 '21 at 18:25

2 Answers2

1

There are several smoothing algorithm. Laplacian smoothing is one of the best solutions.

Applying your own laplacian smoothing algorithme can be laborious. Instead you can use MeshlabServer to apply a perfect laplacian smoothing.

You should have necessary meshlab dlls. For that, you can install the Meshlab on the PC. When you install the Meshlab on a PC, you have all necessary dlls in the installation folder. But if you want to take only the dlls that you need for the filtering method that you want to use, you can put them in your installation folder. In this case, you should install visual C++ redistribuables (Microsoft Visual C++ 2015-2019 Redistributable (x64) - 14.26.2872) on the pc that you want to call MeshlabServer's fonctions.

Finally, you should define your .mlx file to tell to the Meshlab server which filter to apply.

Here is the content of the .mlx file for a laplacian smoothing of 6 steps :

 <FilterScript>
  <filter name="Laplacian Smooth">
    <Param name="stepSmoothNum" tooltip="" description="" isxmlparam="0" value="6" 
    type="RichInt"/>
    <Param name="selection" tooltip="" description="" isxmlparam="0" value="false" 
    type="RichBool"/>
    <Param name="boundarySmooth" tooltip="" description="" isxmlparam="0" value="true" 
    type="RichBool"/>
    <Param name="cotangentWeight" tooltip="" description="" isxmlparam="0" value="true" 
    type="RichBool"/>
 </filter>    
</FilterScript>

And the C# method to call the filtering function :

    /// <summary>
    /// Applies a laplacian smoothing filter to the given 3D object.
    /// </summary>
    /// <param name="input">The path of the source 3D object</param>
    /// <param name="output">The path to save the smoothed result.</param>
    /// <param name="meshlabRoot">The path of the Meshlab dlls folder</param>
    /// <returns></returns>
    public static bool LaplacianSmoothing(string input, string output, string meshlabRoot)
    {
        bool retVal = true;
        try
        {
            string strCmdText;
            string mlxPath = meshlabRoot + "LaplacianFilter.mlx";
            strCmdText = "/C " + meshlabRoot +
                @"meshlabserver " +
                @"-i " + input + " " +
                @"-o " + output + " -s " +
                mlxPath;

            System.Diagnostics.Process process = new System.Diagnostics.Process();
            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
            startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            startInfo.FileName = "cmd.exe";
            startInfo.Arguments = strCmdText;
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            process.StartInfo = startInfo;


            process.Start();


            process.WaitForExit();
        }
        catch (Exception ex)
        {
            UserMethods.ParseError(ex, "SmoothFile");
            retVal = false;
        }

        return retVal;
Coskun Ozogul
  • 2,389
  • 1
  • 20
  • 32
1

You can check to ensure you are using smooth index triangles on your mesh.

Mesh mesh = new Mesh();

Mesh smoothMesh = (Mesh)mesh.Clone();
for (int i = 0; i < smoothMesh.Triangles.Count(); i++)
{
    SmoothTriangle tST = new SmoothTriangle(smoothMesh.Triangles[i].V1, smoothMesh.Triangles[i].V2, smoothMesh.Triangles[i].V3);
    smoothMesh.Triangles[i] = tST;
}

Mesh flatMesh = (Mesh)mesh.Clone();
for (int i = 0; i < flatMesh.Triangles.Count(); i++)
{
    IndexTriangle tIT = new IndexTriangle(flatMesh.Triangles[i].V1, flatMesh.Triangles[i].V2, flatMesh.Triangles[i].V3);
    flatMesh.Triangles[i] = tIT;
}
Daniel Lord
  • 754
  • 5
  • 18