MeshLib
 
Loading...
Searching...
No Matches
Global Registration

///

Example of Global Registration

using System;
using System.Reflection;
using System.Collections.Generic;
namespace MR.DotNet.Sample
{
internal class Program
{
static void PrintStats( MultiwayICP icp )
{
int numActivePairs = icp.GetNumActivePairs();
Console.WriteLine($"Number of samples: {icp.GetNumSamples()}");
Console.WriteLine($"Number of active pairs: {numActivePairs}");
if ( numActivePairs > 0 )
{
double p2ptMetric = icp.GetMeanSqDistToPoint();
double p2ptInaccuracy = icp.GetMeanSqDistToPoint(p2ptMetric);
Console.WriteLine($"RMS point-to-point distance: {p2ptMetric} ± {p2ptInaccuracy}");
double p2plMetric = icp.GetMeanSqDistToPlane();
double p2plInaccuracy = icp.GetMeanSqDistToPlane(p2ptMetric);
Console.WriteLine($"RMS point-to-plane distance: {p2plMetric} ± {p2plInaccuracy}");
}
}
static void Main(string[] args)
{
if (args.Length < 3)
{
Console.WriteLine("Usage: {0} INPUT1 INPUT2 [INPUTS...] OUTPUT", Assembly.GetExecutingAssembly().GetName().Name);
return;
}
try
{
int inputNum = args.Length - 1;
List<MeshOrPointsXf> inputs = new List<MeshOrPointsXf>(inputNum);
Box3f maxBBox = new Box3f();
for (int i = 0; i < inputNum; ++i)
{
obj.obj = PointCloud.FromAnySupportedFormat(args[i]);
obj.xf = new AffineXf3f();
inputs.Add(obj);
Box3f bbox = obj.obj.BoundingBox;
if ( !maxBBox.Valid() || bbox.Volume() > maxBBox.Volume() )
maxBBox = bbox;
}
samplingParams.samplingVoxelSize = maxBBox.Diagonal() * 0.03f;
MultiwayICP icp = new MultiwayICP(inputs, samplingParams );
ICPProperties iCPProperties = new ICPProperties();
icp.SetParams( iCPProperties );
PrintStats(icp);
Console.WriteLine("Calculating transformations...");
var xfs = icp.CalculateTransformations();
PrintStats(icp);
PointCloud output = new PointCloud();
for (int i = 0; i < inputNum; ++i)
{
var xf = xfs[i];
for (int j = 0; j < inputs[i].obj.Points.Count; j++)
output.AddPoint( xf.Apply( inputs[i].obj.Points[j]) );
}
PointCloud.ToAnySupportedFormat( output , args[args.Length - 1] );
}
catch (Exception e)
{
Console.WriteLine("Error: {0}", e.Message);
}
}
}
}
affine transformation: y = A*x + b, where A in VxV, and b in V
Definition MRDotNet/MRAffineXf.h:8
Box given by its min- and max- corners.
Definition MRBox3.h:8
bool Valid()
true if the box contains at least one point
float Volume()
computes the volume of this box
float Diagonal()
computes length from min to max
Definition MRDotNet/MRMultiwayICP.h:28
int GetNumActivePairs()
computes the number of active point pairs
float GetMeanSqDistToPoint()
computes root-mean-square deviation between points
List< AffineXf3f^> CalculateTransformations()
void SetParams(ICPProperties^ props)
tune algorithm params before run calculateTransformations()
bool UpdateAllPointPairs()
float GetMeanSqDistToPlane()
computes root-mean-square deviation from points to target planes
represents a point cloud
Definition MRDotNet/MRPointCloud.h:7
static PointCloud FromAnySupportedFormat(System::String^ path)
loads point cloud from file of any supported format
void AddPoint(Vector3f^ point)
adds a point
static void ToAnySupportedFormat(PointCloud^ mesh, System::String^ path)
saves point cloud to file of any supported format
property Box3f BoundingBox
Definition MRDotNet/MRMeshOrPoints.h:16
Definition MRDotNet/MRICP.h:55
holds together mesh/point cloud and its transformation
Definition MRDotNet/MRMeshOrPoints.h:21
MeshOrPoints obj
Definition MRDotNet/MRMeshOrPoints.h:22
Parameters that are used for sampling of the MultiwayICP objects.
Definition MRDotNet/MRMultiwayICP.h:9