コード例 #1
0
        /// <summary>
        /// Registers source points to target points. It only translates and rotates whole mesh.
        /// </summary>
        /// <param name="sourcePoints">Source points.</param>
        /// <param name="targetPoints">Target points.</param>
        /// <returns>Registered source points.</returns>
        public List <Vector <float> > ComputeRegistration(List <Vector <float> > sourcePoints, List <Vector <float> > targetPoints)
        {
            Log.Info("Computing registration.");
            Log.Info("Cloning the given source.");
            List <Vector <float> > copySourcePoints = new List <Vector <float> >();

            sourcePoints.ForEach(point => copySourcePoints.Add(point.Clone()));

            Matrix <float> transformationMatrix = this.ComputeRegistrationMatrix(sourcePoints, targetPoints);

            Transformation3D.ApplyTransformation(copySourcePoints, transformationMatrix);

            return(copySourcePoints);
        }
コード例 #2
0
        /// <summary>
        /// Registers source points to target points. It only translates and rotates whole mesh.
        /// </summary>
        /// <param name="sourcePoints">Source points.</param>
        /// <param name="targetPoints">Target points.</param>
        /// <returns>Transformation matrix.</returns>
        public Matrix <float> ComputeRegistrationMatrix(List <Vector <float> > sourcePoints, List <Vector <float> > targetPoints)
        {
            Log.Info("Computing registration matrix.");
            Log.Info("Cloning the given lists.");

            // Copy points.
            List <Vector <float> > copySourcePoints = new List <Vector <float> >();

            sourcePoints.ForEach(point => copySourcePoints.Add(point.Clone()));
            List <Vector <float> > copyTargetPoints = new List <Vector <float> >();

            targetPoints.ForEach(point => copyTargetPoints.Add(point.Clone()));

            int            iteration            = 0;
            Matrix <float> transformationMatrix = Matrix <float> .Build.DenseIdentity(4);

            List <Vector <float> > mappedSourcePoints;
            List <Vector <float> > mappedTargetPoints;
            Centroid mappedTargetCentroid;

            do
            {
                Log.Debug("Number of iterations: " + iteration);

                // Map points.
                this.pointMapping.MapPoints(copySourcePoints, copyTargetPoints, out mappedSourcePoints, out mappedTargetPoints);

                // Compute centroid of target points and translate them.
                mappedTargetCentroid = new Centroid(mappedTargetPoints);
                Transformation3D.Translate(copyTargetPoints, -mappedTargetCentroid.Value);

                // Compute centroid of source points, translate them and add translation to a transformation matrix.
                Centroid mappedSourceCentroid = new Centroid(mappedSourcePoints);
                Transformation3D.Translate(copySourcePoints, -mappedSourceCentroid.Value);
                transformationMatrix = Transformation3D.CreateTranslationMatrix(-mappedSourceCentroid.Value) * transformationMatrix;

                // Compute rotation matrix, apply it on source points and add it to the transformation matrix.
                Matrix <float> rotationMatrix = this.rotation.CalculateRotation(mappedSourcePoints, mappedTargetPoints);
                Transformation3D.ApplyTransformation(copySourcePoints, rotationMatrix);
                transformationMatrix = rotationMatrix * transformationMatrix;
            } while (!this.CheckDistance(mappedSourcePoints, mappedTargetPoints) && ++iteration < this.numberOfIterations);

            // Compute transformation from origin to a target position.
            Centroid targetCentroid     = new Centroid(targetPoints);
            Centroid copyTargetCentroid = new Centroid(copyTargetPoints);

            mappedTargetCentroid = new Centroid(mappedTargetPoints);
            return(Transformation3D.CreateTranslationMatrix(targetCentroid.Value - (copyTargetCentroid.Value - mappedTargetCentroid.Value)) * transformationMatrix);
        }