maspack.geometry
Class CPD

java.lang.Object
  extended by maspack.geometry.CPD

public class CPD
extends java.lang.Object

Author:
antonio Coherent Point Drift implementation Point Set Registration: Coherent Point Drift, Andriy Myronenko and Xubo Song 2010

Field Summary
static int DEFAULT_MAX_ITERS
           
static boolean verbose
           
 
Constructor Summary
CPD()
           
 
Method Summary
static AffineTransform3d affine(Point3d[] X, Point3d[] Y, double w, double tol, int maxIters, Point3d[] TY)
          Uses the affine CPD algorithm to align a set of points
static AffineTransform3d affine(Point3d[] X, Point3d[] Y, double w, double tol, int maxIters, Point3d[] TY, AffineTransform3d trans, double[] sigma2Holder)
          Uses the affine CPD algorithm to align a set of points
static AffineTransform3d affine(PolygonalMesh meshRef, PolygonalMesh meshReg, double w, double tol, int maxIters)
          Uses the affine CPD algorithm to align two meshes
static void coherent(Point3d[] X, Point3d[] Y, double lambda, double beta2, double w, double tol, int maxIters, Point3d[] TY)
          Uses the coherent CPD algorithm to align a set of points
static void coherent(Point3d[] X, Point3d[] Y, double lambda, double beta2, double w, double tol, int maxIters, Point3d[] TY, double[] sigma2Holder)
          Uses the coherent CPD algorithm to align a set of points
static void coherent(PolygonalMesh meshRef, PolygonalMesh meshReg, double lambda, double beta2, double w, double tol, int maxIters, PolygonalMesh out)
          Uses the coherent CPD algorithm to align two meshes
static Point3d computeMean(Point3d[] pnts, double[] P, double Np, Point3d mean)
          Compute and return the weighted mean
static double computeP(Point3d[] X, Point3d[] TY, double sigma2, double w, double[][] P, double[] P1, double[] Pt1)
          Computes the CPD probability function P(m|n)
static double computeQ(Point3d[] X, Point3d[] TY, double[][] P, double Np, double sigma2)
          CPD Objective function
static double computeVariance(Point3d[] X, Point3d[] TY, double[][] P, double Np)
          Estimates the CPD variance
static ScaledRigidTransform3d rigid(Point3d[] X, Point3d[] Y, double w, double tol, int maxIters, boolean allowScaling, Point3d[] TY)
          Uses the rigid CPD algorithm to align a set of points
static ScaledRigidTransform3d rigid(Point3d[] X, Point3d[] Y, double w, double tol, int maxIters, boolean allowScaling, Point3d[] TY, ScaledRigidTransform3d trans, double[] sigma2Holder)
          Uses the rigid CPD algorithm to align a set of points
static ScaledRigidTransform3d rigid(PolygonalMesh meshRef, PolygonalMesh meshReg, double w, double tol, int maxIters, boolean allowScaling)
          Uses the rigid CPD algorithm to align two meshes
static void transformPoints(Point3d[] Y, AffineTransform3dBase trans, Point3d[] TY)
          Transforms a set of points
static void transformPoints(Point3d[] Y, double s, Matrix3d R, Vector3d t, Point3d[] TY)
          Transforms points based on rigid transform
static void transformPoints(Point3d[] Y, Matrix3d A, Vector3d t, Point3d[] TY)
          Transforms points based on affine transform
static void transformPoints(Point3d[] Y, MatrixNd G, MatrixNd W, Point3d[] TY)
           
static void transformPoints(Point3d[] Y, Point3d[] TY)
          Transforms a set of points by identity (copies points)
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MAX_ITERS

public static int DEFAULT_MAX_ITERS

verbose

public static boolean verbose
Constructor Detail

CPD

public CPD()
Method Detail

rigid

public static ScaledRigidTransform3d rigid(Point3d[] X,
                                           Point3d[] Y,
                                           double w,
                                           double tol,
                                           int maxIters,
                                           boolean allowScaling,
                                           Point3d[] TY,
                                           ScaledRigidTransform3d trans,
                                           double[] sigma2Holder)
Uses the rigid CPD algorithm to align a set of points

Parameters:
X - reference input points
Y - points to register
w - weight, accounting to noise (w=0 --> no noise)
tol - will iterative until objective function changes by less than this
maxIters - maximum number of iterations
allowScaling - whether or not to allow scaling
TY - transformed points
trans - initial guess of scaled rigid transform
sigma2Holder - initial guess of variance
Returns:
the scaled rigid transform for registration

computeP

public static double computeP(Point3d[] X,
                              Point3d[] TY,
                              double sigma2,
                              double w,
                              double[][] P,
                              double[] P1,
                              double[] Pt1)
Computes the CPD probability function P(m|n)

Parameters:
X - Input points
TY - Transformed output points
sigma2 - variance
w - weight to account for noise/outliers
P - MxN probability matrix
P1 - Mx1 vector, P*1
Pt1 - Nx1 vector, trans(P)*1
Returns:
Np the sum of all entries in P

computeQ

public static double computeQ(Point3d[] X,
                              Point3d[] TY,
                              double[][] P,
                              double Np,
                              double sigma2)
CPD Objective function

Parameters:
X - reference points
TY - transformed input points
P - probability matrix
Np - sum of all probabilities
sigma2 - probability variance
Returns:
the objective function value

transformPoints

public static void transformPoints(Point3d[] Y,
                                   double s,
                                   Matrix3d R,
                                   Vector3d t,
                                   Point3d[] TY)
Transforms points based on rigid transform

Parameters:
Y - input points
s - scale
R - rotation
t - translation
TY - transformed points

transformPoints

public static void transformPoints(Point3d[] Y,
                                   AffineTransform3dBase trans,
                                   Point3d[] TY)
Transforms a set of points

Parameters:
Y - input points
trans - transform
TY - transformed points

transformPoints

public static void transformPoints(Point3d[] Y,
                                   Point3d[] TY)
Transforms a set of points by identity (copies points)

Parameters:
Y - input points
TY - transformed points

transformPoints

public static void transformPoints(Point3d[] Y,
                                   Matrix3d A,
                                   Vector3d t,
                                   Point3d[] TY)
Transforms points based on affine transform

Parameters:
Y - input points
A - affine transform
t - translation
TY - transformed points

transformPoints

public static void transformPoints(Point3d[] Y,
                                   MatrixNd G,
                                   MatrixNd W,
                                   Point3d[] TY)

computeVariance

public static double computeVariance(Point3d[] X,
                                     Point3d[] TY,
                                     double[][] P,
                                     double Np)
Estimates the CPD variance

Parameters:
X - N input points
TY - M transformed output points
P - probability matrix (if null, P(m,n) = 1/M)
Np - Total sum of entries in probability matrix
Returns:
the estimated variance

computeMean

public static Point3d computeMean(Point3d[] pnts,
                                  double[] P,
                                  double Np,
                                  Point3d mean)
Compute and return the weighted mean

Parameters:
pnts - set of points
P - vector of probabilities
Np - sum of probabilities
mean - mean to fill, if null, creates new
Returns:
the weighted mean

rigid

public static ScaledRigidTransform3d rigid(Point3d[] X,
                                           Point3d[] Y,
                                           double w,
                                           double tol,
                                           int maxIters,
                                           boolean allowScaling,
                                           Point3d[] TY)
Uses the rigid CPD algorithm to align a set of points

Parameters:
X - reference input points
Y - points to register
w - weight, accounting to noise (w=0 --> no noise)
tol - will iterative until objective function changes by less than this
maxIters - maximum number of iterations
allowScaling - whether or not to allow scaling
TY - transformed points
Returns:
the scaled rigid transform for registration

rigid

public static ScaledRigidTransform3d rigid(PolygonalMesh meshRef,
                                           PolygonalMesh meshReg,
                                           double w,
                                           double tol,
                                           int maxIters,
                                           boolean allowScaling)
Uses the rigid CPD algorithm to align two meshes

Parameters:
meshRef - reference mesh
meshReg - mesh to register
w - weight, accounting to noise (w=0 --> no noise)
tol - will iterative until objective function changes by less than this
maxIters - maximum number of iterations
allowScaling - whether or not to allow scaling
Returns:
the scaled rigid transform for registration

affine

public static AffineTransform3d affine(Point3d[] X,
                                       Point3d[] Y,
                                       double w,
                                       double tol,
                                       int maxIters,
                                       Point3d[] TY,
                                       AffineTransform3d trans,
                                       double[] sigma2Holder)
Uses the affine CPD algorithm to align a set of points

Parameters:
X - reference input points
Y - points to register
w - weight, accounting to noise (w=0 --> no noise)
tol - will iterative until objective function changes by less than this
maxIters - maximum number of iterations
TY - transformed points
trans - initial guess of scaled rigid transform
sigma2Holder - initial guess of variance
Returns:
the scaled rigid transform for registration

affine

public static AffineTransform3d affine(Point3d[] X,
                                       Point3d[] Y,
                                       double w,
                                       double tol,
                                       int maxIters,
                                       Point3d[] TY)
Uses the affine CPD algorithm to align a set of points

Parameters:
X - reference input points
Y - points to register
w - weight, accounting to noise (w=0 --> no noise)
tol - will iterative until objective function changes by less than this
maxIters - maximum number of iterations
TY - transformed points
Returns:
the scaled rigid transform for registration

affine

public static AffineTransform3d affine(PolygonalMesh meshRef,
                                       PolygonalMesh meshReg,
                                       double w,
                                       double tol,
                                       int maxIters)
Uses the affine CPD algorithm to align two meshes

Parameters:
meshRef - reference mesh
meshReg - mesh to register
w - weight, accounting to noise (w=0 --> no noise)
tol - will iterative until objective function changes by less than this
maxIters - maximum number of iterations
Returns:
the scaled rigid transform for registration

coherent

public static void coherent(Point3d[] X,
                            Point3d[] Y,
                            double lambda,
                            double beta2,
                            double w,
                            double tol,
                            int maxIters,
                            Point3d[] TY,
                            double[] sigma2Holder)
Uses the coherent CPD algorithm to align a set of points

Parameters:
X - reference input points
Y - points to register
lambda - weight factor for regularization term (> 0)
beta2 - coherence factor, beta^2 (> 0)
w - weight, accounting to noise (w=0 --> no noise)
tol - will iterative until objective function changes by less than this
maxIters - maximum number of iterations
TY - transformed points
sigma2Holder - initial variance estimate

coherent

public static void coherent(Point3d[] X,
                            Point3d[] Y,
                            double lambda,
                            double beta2,
                            double w,
                            double tol,
                            int maxIters,
                            Point3d[] TY)
Uses the coherent CPD algorithm to align a set of points

Parameters:
X - reference input points
Y - points to register
lambda - weight factor for regularization term (> 0)
beta2 - coherence factor, beta^2 (> 0)
w - weight, accounting to noise (w=0 --> no noise)
tol - will iterative until objective function changes by less than this
maxIters - maximum number of iterations
TY - transformed points

coherent

public static void coherent(PolygonalMesh meshRef,
                            PolygonalMesh meshReg,
                            double lambda,
                            double beta2,
                            double w,
                            double tol,
                            int maxIters,
                            PolygonalMesh out)
Uses the coherent CPD algorithm to align two meshes

Parameters:
meshRef - reference mesh
meshReg - mesh to register
lambda - weight factor for regularization term (> 0)
beta2 - coherence factor, beta^2 (> 0)
w - weight, accounting to noise (w=0 --> no noise)
tol - will iterative until objective function changes by less than this
maxIters - maximum number of iterations
out - transformed mesh