My code is exactly the same as @Z.Fatih has posted.
I have also used Key1.ply and Key2.ply as pointCloudModel.
Code I got from @Z.Fatih:
Cvb.Core.COMPOSITE pointCloudModel;
Cvb.Core.COMPOSITE pointCloud1;
Cvb.Core.COMPOSITE downsampledCloudModel;
Cvb.Core.COMPOSITE downsampledCloud1;
Cvb.Core.COMPOSITE transformedPointCloud1;
private void loadFile()
{
int success = Cvb.Core3D.LoadFile(@"C:\Program Files\STEMMER IMAGING\Common Vision Blox\Tutorial\Match3D\Images\Key1.ply", out pointCloudModel);
int success2 = Cvb.Core3D.LoadFile(@"C:\Program Files\STEMMER IMAGING\Common Vision Blox\Tutorial\Match3D\Images\Key2.ply", out pointCloud1);
_cvbDisplayModel.AddPointCloudVariable(pointCloudModel, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0);
_cvbDisplayModel.ResetCamera();
_cvbDisplayPart.AddPointCloudVariable(pointCloud1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0);
_cvbDisplayPart.ResetCamera();
cloudPointAllignment()
}
private void cloudPointAllignment()
{
//Checks the layout of the two pointclouds are valid
Cvb.Core3D.PointCloudLayout pointCloudModelLayout;
Cvb.Core3D.PointCloudAnalyzeLayout(pointCloudModel, out pointCloudModelLayout);
Cvb.Core3D.PointCloudLayout pointCloud1Layout;
Cvb.Core3D.PointCloudAnalyzeLayout(pointCloud1, out pointCloud1Layout);
//Downsamples both the model point cloud and the part point cloud
int success = Cvb.Core3D.CreateDownsampledPointCloud(pointCloudModel, Cvb.Core3D.DownsampleMode.CVC3DDownsampleByFactor, 10, out downsampledCloudModel);
success = Cvb.Core3D.CreateDownsampledPointCloud(pointCloud1, Cvb.Core3D.DownsampleMode.CVC3DDownsampleByFactor, 10, out downsampledCloud1);
//Sets the match paramenters to the defualt values
Cvb.Match3D.MatchParameters testParameter= Cvb.Match3D.MatchParameters.Default;
testParameter.MaxIterations = 20;
testParameter.DeltaRmsThreshold = 0.1;
testParameter.MaxStdDevDistance = 1e-006;
double finalRMS = 0.0;
int numIterationsNeeded = -1;
Cvb.Core3D.Transformation testTransform = new Cvb.Core3D.Transformation();
//Gets the number of points in the downsampled point cloud and then uses the match function to align the part and model
long maxDownsampledCloudModelPoints;
long maxDownsampledCloud1Points;
success = Cvb.Core3D.PointCloudGetNumPoints(downsampledCloudModel, out maxDownsampledCloudModelPoints);
success = Cvb.Core3D.PointCloudGetNumPoints(downsampledCloud1, out maxDownsampledCloud1Points); /*ERROR*/
success = Cvb.Match3D.MatchDownsampledPointClouds(downsampledCloudModel, maxDownsampledCloudModelPoints, downsampledCloud1, maxDownsampledCloud1Points,
testParameter, out finalRMS, out numIterationsNeeded, out testTransform);
//This is where the error occurs as the value of the testTransform.Matrix is returned as invalid
var val = testTransform.Matrix[0, 0];
success = Cvb.Core3D.CreateTransformedPointCloud(downsampledCloud1, testTransform, out transformedPointCloud1);
_cvbDisplayModelandPart.AddPointCloudVariable(transformedPointCloud1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0);
_cvbDisplayModelandPart.ResetCamera();
}