Skip to content

Commit 6ff4b3b

Browse files
committed
Build c# examples at every build
1 parent 79f915e commit 6ff4b3b

File tree

9 files changed

+168
-91
lines changed

9 files changed

+168
-91
lines changed

.github/workflows/build-test-windows.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ jobs:
164164
- name: Build .NET
165165
if: matrix.runner == 'windows-2022'
166166
run: msbuild -m source\MeshLibDotNet.sln -p:Configuration=${{ matrix.config }}
167+
168+
- name: Build .NET examples
169+
if: matrix.runner == 'windows-2022'
170+
run: msbuild -m source\examples\c-sharp-examples\c-sharp-examples.sln -p:Configuration=${{ matrix.config }}
167171

168172
- name: Build MRBind
169173
if: ${{inputs.mrbind}}

examples/c--sharp-example/GlobalRegistration.dox.cs

Lines changed: 0 additions & 77 deletions
This file was deleted.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System.Reflection;
2+
using static MR.DotNet;
3+
4+
public class GlobalRegistrationExample
5+
{
6+
static void PrintStats(MultiwayICP icp)
7+
{
8+
int numActivePairs = icp.GetNumActivePairs();
9+
Console.WriteLine($"Number of samples: {icp.GetNumSamples()}");
10+
Console.WriteLine($"Number of active pairs: {numActivePairs}");
11+
12+
if (numActivePairs > 0)
13+
{
14+
double p2ptMetric = icp.GetMeanSqDistToPoint();
15+
double p2ptInaccuracy = icp.GetMeanSqDistToPoint(p2ptMetric);
16+
Console.WriteLine($"RMS point-to-point distance: {p2ptMetric} ± {p2ptInaccuracy}");
17+
18+
double p2plMetric = icp.GetMeanSqDistToPlane();
19+
double p2plInaccuracy = icp.GetMeanSqDistToPlane(p2ptMetric);
20+
Console.WriteLine($"RMS point-to-plane distance: {p2plMetric} ± {p2plInaccuracy}");
21+
}
22+
}
23+
public static void Run(string[] args)
24+
{
25+
if (args.Length < 4)
26+
{
27+
Console.WriteLine("Usage: {0} GlobalRegistrationExample INPUT1 INPUT2 [INPUTS...] OUTPUT", Assembly.GetExecutingAssembly().GetName().Name);
28+
return;
29+
}
30+
31+
try
32+
{
33+
int inputNum = args.Length - 2;
34+
List<MeshOrPointsXf> inputs = new List<MeshOrPointsXf>(inputNum);
35+
Box3f maxBBox = new Box3f();
36+
for (int i = 0; i < inputNum; ++i)
37+
{
38+
MeshOrPointsXf obj = new MeshOrPointsXf(PointCloud.FromAnySupportedFormat(args[i + 1]), new AffineXf3f());
39+
inputs.Add(obj);
40+
Box3f bbox = obj.obj.BoundingBox;
41+
if (!maxBBox.Valid() || bbox.Volume() > maxBBox.Volume())
42+
maxBBox = bbox;
43+
}
44+
45+
MultiwayICPSamplingParameters samplingParams = new MultiwayICPSamplingParameters();
46+
samplingParams.samplingVoxelSize = maxBBox.Diagonal() * 0.03f;
47+
48+
MultiwayICP icp = new MultiwayICP(inputs, samplingParams);
49+
ICPProperties iCPProperties = new ICPProperties();
50+
icp.SetParams(iCPProperties);
51+
icp.UpdateAllPointPairs();
52+
PrintStats(icp);
53+
54+
Console.WriteLine("Calculating transformations...");
55+
var xfs = icp.CalculateTransformations();
56+
PrintStats(icp);
57+
PointCloud output = new PointCloud();
58+
for (int i = 0; i < inputNum; ++i)
59+
{
60+
var xf = xfs[i];
61+
for (int j = 0; j < inputs[i].obj.Points.Count; j++)
62+
output.AddPoint(xf.Apply(inputs[i].obj.Points[j]));
63+
}
64+
65+
PointCloud.ToAnySupportedFormat(output, args[args.Length - 1]);
66+
}
67+
catch (Exception e)
68+
{
69+
Console.WriteLine("Error: {0}", e.Message);
70+
}
71+
}
72+
}

examples/c--sharp-example/MeshBoolean.dox.cs renamed to examples/c-sharp-examples/MeshBoolean.dox.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
using System;
21
using System.Reflection;
32
using static MR.DotNet;
43

5-
class Program
4+
public class MeshBooleanExample
65
{
7-
static void Main(string[] args)
6+
public static void Run(string[] args)
87
{
9-
if (args.Length != 2)
10-
Console.WriteLine("Usage: {0} INPUT1 INPUT2", Assembly.GetExecutingAssembly().GetName().Name);
8+
if (args.Length != 3)
9+
{
10+
Console.WriteLine("Usage: {0} MeshBooleanExample INPUT1 INPUT2", Assembly.GetExecutingAssembly().GetName().Name);
11+
return;
12+
}
1113

1214
try
1315
{

examples/c--sharp-example/MeshDecimate.dox.cs renamed to examples/c-sharp-examples/MeshDecimate.dox.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
using System;
21
using static MR.DotNet;
32

4-
class Program
3+
public class MeshDecimateExample
54
{
6-
static void Main(string[] args)
5+
public static void Run(string[] args)
76
{
87
try
98
{

examples/c--sharp-example/Offset.dox.cs renamed to examples/c-sharp-examples/MeshOffset.dox.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
using System;
21
using System.Globalization;
32
using System.Reflection;
43
using static MR.DotNet;
54

6-
class Program
5+
public class MeshOffsetExample
76
{
8-
static void Main(string[] args)
7+
public static void Run(string[] args)
98
{
10-
if (args.Length != 2 && args.Length != 3)
9+
if (args.Length != 2)
1110
{
12-
Console.WriteLine("Usage: {0} OFFSET_VALUE", Assembly.GetExecutingAssembly().GetName().Name);
11+
Console.WriteLine("Usage: {0} MeshOffsetExample OFFSET_VALUE", Assembly.GetExecutingAssembly().GetName().Name);
1312
return;
1413
}
1514

1615
try
1716
{
18-
float offsetValue = float.Parse(args[0],
17+
float offsetValue = float.Parse(args[1],
1918
System.Globalization.NumberStyles.AllowThousands,
2019
CultureInfo.InvariantCulture);
2120

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System.Reflection;
2+
3+
internal class Program
4+
{
5+
static void Main(string[] args)
6+
{
7+
var assembly = Assembly.GetExecutingAssembly();
8+
var types = assembly.GetTypes();
9+
var exampleNames = types.Select(t => t.Name).Where(t => t.EndsWith("Example"));
10+
11+
if (args.Length < 1 || exampleNames.Contains(args[0]) == false )
12+
{
13+
Console.WriteLine("Usage: {0} EXAMPLE_NAME [ARGS...]", Assembly.GetExecutingAssembly().GetName().Name);
14+
Console.WriteLine("Available examples:");
15+
foreach (var exampleName in exampleNames)
16+
{
17+
Console.WriteLine("\t{0}", exampleName);
18+
}
19+
return;
20+
}
21+
22+
foreach (var type in types)
23+
{
24+
if (type.Name == args[0])
25+
{
26+
MethodInfo runMethod = type.GetMethod("Run", BindingFlags.Static | BindingFlags.Public);
27+
if (runMethod == null)
28+
{
29+
Console.WriteLine($"Run Method not found in {type.Name}.");
30+
return;
31+
}
32+
33+
runMethod.Invoke(null, new object[] { args });
34+
}
35+
}
36+
}
37+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>c_sharp_examples</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
<Platforms>AnyCPU;x64</Platforms>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="MeshLib" Version="3.0.1.251-beta" />
14+
</ItemGroup>
15+
16+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.11.35312.102
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "c-sharp-examples", "c-sharp-examples.csproj", "{AB3537AC-298A-4D0D-A16D-D8B9DA8ED241}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Release|x64 = Release|x64
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{AB3537AC-298A-4D0D-A16D-D8B9DA8ED241}.Debug|x64.ActiveCfg = Debug|x64
15+
{AB3537AC-298A-4D0D-A16D-D8B9DA8ED241}.Debug|x64.Build.0 = Debug|x64
16+
{AB3537AC-298A-4D0D-A16D-D8B9DA8ED241}.Release|x64.ActiveCfg = Release|x64
17+
{AB3537AC-298A-4D0D-A16D-D8B9DA8ED241}.Release|x64.Build.0 = Release|x64
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {25E8F8BE-4952-45AE-9E9E-271CAD8F4DA5}
24+
EndGlobalSection
25+
EndGlobal

0 commit comments

Comments
 (0)