Skip to content

Commit a2d8727

Browse files
authored
Update C# examples and documentation (#4482)
* added more examples for C# * improved documentations * added c# example for triangulation
1 parent ebe9e8d commit a2d8727

File tree

8 files changed

+112
-2
lines changed

8 files changed

+112
-2
lines changed

doxygen/examples/GlobalRegistration.dox

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ Example of Global Registration
77

88
- <b class="tab-title">C++</b>
99
\include GlobalRegistration.dox.cpp
10+
- <b class="tab-title">Python</b>
11+
\include GlobalRegistration.dox.py
1012
- <b class="tab-title">C</b>
1113
\include GlobalRegistration.dox.c
1214
- <b class="tab-title">C#</b>
1315
\include GlobalRegistration.dox.cs
14-
- <b class="tab-title">Python</b>
15-
\include GlobalRegistration.dox.py
1616

1717
</div>
1818

doxygen/examples/MeshExport.dox

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ See a more relevant example \ref ExampleNumpy
1414
- <b class="tab-title">C</b>
1515
\include MeshExport.dox.c
1616

17+
- <b class="tab-title">C#</b>
18+
\include MeshExport.dox.cs
19+
1720
</div>
1821

1922
*/

doxygen/examples/MeshFillHole.dox

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Example of filling holes
1111
\include MeshFillHole.dox.py
1212
- <b class="tab-title">C</b>
1313
\include MeshFillHole.dox.c
14+
- <b class="tab-title">C#</b>
15+
\include MeshFillHole.dox.cs
1416

1517
</div>
1618

doxygen/examples/MeshICP.dox

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Example of mesh ICP (finding transformation to match objects)
1111
\include MeshICP.dox.py
1212
- <b class="tab-title">C</b>
1313
\include MeshICP.dox.c
14+
- <b class="tab-title">C#</b>
15+
\include MeshICP.dox.cs
1416

1517
</div>
1618

doxygen/examples/MeshLoadSave.dox

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ Further examples won't check return values for sake of clarity
1717
- <b class="tab-title">C</b>
1818
\include MeshLoadSave.dox.c
1919

20+
- <b class="tab-title">C#</b>
21+
\include MeshLoadSave.dox.cs
22+
2023
</div>
2124

2225
*/

doxygen/layout_templates/base_struct.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
<tab type="user" url="__BEGIN_URL__ExamplePlotly__END_URL__" title="Plotly Visualization"/>
4545
<tab type="user" url="__BEGIN_URL__ExampleNumpy__END_URL__" title="Using Numpy"/>
4646
<tab type="user" url="__BEGIN_URL__ExampleNumpyTriangulation__END_URL__" title="Numpy Triangulation"/>
47+
<tab type="user" url="__BEGIN_URL__ExampleCudaOffset__END_URL__" title="Offset with Cuda"/>
48+
<tab type="user" url="__BEGIN_URL__ExampleDicomFiles__END_URL__" title="Open Dicom Files"/>
4749
</tab>
4850
</tab>
4951
<tab type="usergroup" url="__BEGIN_URL__PackageOverview__END_URL__" title="Package Overview">
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System.Reflection;
2+
using static MR.DotNet;
3+
4+
public class MeshICPExample
5+
{
6+
public static void Run()
7+
{
8+
try
9+
{
10+
// Load meshes
11+
12+
Mesh meshFloating = MeshLoad.FromAnySupportedFormat("meshA.stl");
13+
MeshOrPointsXf meshXfFloating = new MeshOrPointsXf(meshFloating, new AffineXf3f());
14+
MeshOrPointsXf meshXfFixed = new MeshOrPointsXf(MeshLoad.FromAnySupportedFormat("meshB.stl"), new AffineXf3f());
15+
16+
// Prepare ICP parameters
17+
float diagonal = meshXfFixed.obj.BoundingBox.Diagonal();
18+
float icpSamplingVoxelSize = diagonal * 0.01f; // To sample points from object
19+
ICPProperties icpParams = new ICPProperties();
20+
icpParams.distThresholdSq = diagonal * diagonal * 0.01f; // Use points pairs with maximum distance specified
21+
icpParams.exitVal = diagonal * 0.003f; // Stop when distance reached
22+
23+
// Calculate transformation
24+
ICP icp = new ICP(meshXfFloating, meshXfFixed, icpSamplingVoxelSize);
25+
icp.SetParams( icpParams );
26+
AffineXf3f xf = icp.CalculateTransformation();
27+
28+
// Transform floating mesh
29+
meshFloating.Transform(xf);
30+
31+
// Output information string
32+
Console.WriteLine("info {0}", icp.GetStatusInfo());
33+
34+
// Save result
35+
MeshSave.ToAnySupportedFormat( meshFloating, "meshA_icp.stl");
36+
}
37+
catch (Exception e)
38+
{
39+
Console.WriteLine("Error: {0}", e.Message);
40+
}
41+
}
42+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System.Reflection;
2+
using static MR.DotNet;
3+
4+
public class TriangulationExample
5+
{
6+
public static void Run()
7+
{
8+
try
9+
{
10+
// Generate point cloud
11+
Vector3f[] points = new Vector3f[9900];
12+
13+
const float uConst = MathF.PI * 2 / 100;
14+
const float vConst = MathF.PI / 101;
15+
for (int i = 0; i < 100; ++i)
16+
{
17+
float u = uConst * i;
18+
for (int j = 1; j < 100; ++j)
19+
{
20+
float v = vConst * j;
21+
22+
points[i * 99 + j - 1] = new Vector3f(
23+
MathF.Cos(u) * MathF.Sin(v),
24+
MathF.Sin(u) * MathF.Sin(v),
25+
MathF.Cos(v)
26+
);
27+
}
28+
}
29+
30+
PointCloud pc = PointCloud.FromPoints(points);
31+
32+
33+
// Triangulate it
34+
TriangulationParameters parameters = new TriangulationParameters();
35+
Mesh? triangulated = TriangulatePointCloud(pc, parameters);
36+
if ( triangulated == null)
37+
{
38+
Console.WriteLine("Error during triangulation");
39+
return;
40+
}
41+
42+
// Fix possible issues
43+
OffsetParameters offsetParameters = new OffsetParameters();
44+
MeshPart mp = new MeshPart(triangulated);
45+
offsetParameters.voxelSize = Offset.SuggestVoxelSize( mp, 5e+6f);
46+
Mesh mesh = Offset.OffsetMesh(mp, 0f, offsetParameters);
47+
48+
// Save result
49+
MeshSave.ToAnySupportedFormat(mp.mesh, "meshA_icp.stl");
50+
}
51+
catch (Exception e)
52+
{
53+
Console.WriteLine("Error: {0}", e.Message);
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)