The Parametric Pseudo-Manifold (PPS) Library 1.0
|
This class represents a rectangular Bézier patch in 3D. More...
#include <bezier.h>
Public Member Functions | |
Bezier (double *param_pts, double *image_pts, unsigned np, unsigned m, unsigned n, double rx, double sx, double ry, double sy) | |
Creates an instance of this Bezier class by solving a least squares fitting problem. In particular, the control points of the patch are computed as the solution of a linear system of normal equations. To set up this system, the method receives a set of parameter points and their corresponding image points in 3D. The patch is built so that it approximates the latter points. | |
Bezier (const Bezier &bz) | |
Clones an instance of this Bezier class (through a deep copy). | |
~Bezier () | |
Destroys an instance of this class. | |
unsigned | get_bidegree_1st_index () const |
Returns the first index of the bi-degree of this patch. | |
unsigned | get_bidegree_2nd_index () const |
Returns the second index of the bi-degree of this patch. | |
double | get_aff_1st_point_x_coord () const |
Returns the first Cartesian coordinate of the first point of the affine frame with respect to which this patch is defined. | |
double | get_aff_1st_point_y_coord () const |
Returns the second Cartesian coordinate of the first point of the affine frame with respect to which this patch is defined. | |
double | get_aff_2nd_point_x_coord () const |
Returns the first Cartesian coordinate of the second point of the affine frame with respect to which this patch is defined. | |
double | get_aff_2nd_point_y_coord () const |
Returns the second Cartesian coordinate of the second point of the affine frame with respect to which this patch is defined. | |
void | b (unsigned i, unsigned j, double &x, double &y, double &z) const |
Get a specific control point defining this Bezier patch. | |
void | point (double, double, double &x, double &y, double &z) const |
Compute a point on this rectangular Bezier patch. | |
Private Member Functions | |
void | set_bidegree_1st_index (unsigned m) |
Assigns a value to the first index of the bi-degree of this patch. | |
void | set_bidegree_2nd_index (unsigned n) |
Assigns a value to the second index of the bi-degree of this patch. | |
void | set_aff_1st_point_x_coord (double rx) |
Assigns a value to the first Cartesian coordinate of the first point of the affine frame with respect to which this patch is defined. | |
void | set_aff_1st_point_y_coord (double ry) |
Assigns a value to the second Cartesian coordinate of the first point of the affine frame with respect to which this patch is defined. | |
void | set_aff_2nd_point_x_coord (double sx) |
Assigns a value to the first Cartesian coordinate of the second point of the affine frame with respect to which this patch is defined. | |
void | set_aff_2nd_point_y_coord (double sy) |
Assigns a value to the second Cartesian coordinate of the second point of the affine frame with respect to which this patch is defined. | |
unsigned | index (unsigned i, unsigned j) const |
Computes the "linear" index of a control point. | |
double | bernstein (unsigned, unsigned, double) const |
Computes the value of i-th Bernstein polynomial of degree n (B_(n,i)) at a given parameter value with respect to the affine frame [0,1]. | |
void | all_bernstein (unsigned n, double u, std::vector< double > &b) const |
Computes the value of all Bernstein polynomials of degree n at a given parameter value with respect to the affine frame [0,1]. | |
void | comp_bpoly_matrix (double **&a, double *param_pts, unsigned np) const |
Computes the pairwise product of all Bernstein polynomials of two degrees at a given set of parameters points. The two degrees are the the first and second index of the bi-degree of this patch. | |
void | comp_matrix_ata (double **a, unsigned n, unsigned p, double **&ata) const |
Computes the product of the transpose of a given matrix with the matrix itself. | |
void | comp_matrix_atb (double **a, double *b, unsigned n, unsigned p, double **&atb) const |
Computes the product of the transpose of a given ( n x p ) matrix "a" and a ( n x 3 ) matrix "b". The result is a ( p x 3 ) matrix. | |
Private Attributes | |
unsigned | _m |
First bi-degree index. | |
unsigned | _n |
Second bi-degree index. | |
double | _rx |
First Cartesian coordinate of the first point of the affine frame. | |
double | _sx |
Second Cartesian coordinate of the first point of the affine frame. | |
double | _ry |
First Cartesian coordinate of the second point of the affine frame. | |
double | _sy |
Second Cartesian coordinate of the second point of the affine frame. | |
double ** | _ctrl_pts |
Matrix of control points. |
pps::Bezier::Bezier | ( | double * | param_pts, |
double * | image_pts, | ||
unsigned | np, | ||
unsigned | m, | ||
unsigned | n, | ||
double | rx, | ||
double | sx, | ||
double | ry, | ||
double | sy | ||
) |
Creates an instance of this Bezier class by solving a least squares fitting problem. In particular, the control points of the patch are computed as the solution of a linear system of normal equations. To set up this system, the method receives a set of parameter points and their corresponding image points in 3D. The patch is built so that it approximates the latter points.
param_pts | an array with the 2D coordinates of a set of parameter points. |
image_pts | An array with the 3D coordinates of a set of 3D points, which are the image of the paramenter points under a possibly unknown function. |
np | The number of parameter points. |
m | The first degree of this rectangular Bezier patch. |
n | The second degree of this rectangular Bezier patch. |
rx | The first Cartesian coordinate of the first point of the affine frame w.r.t. which this surface patch is defined. |
sx | The second coordinate of the first point of the affine frame w.r.t. which this surface patch is defined. |
ry | The first Cartesian coordinate of the second point of the affine frame w.r.t. which this surface patch is defined. |
sy | The second Cartesian coordinate of the second point of the affine frame w.r.t. which this surface patch is defined. |
param_pts | an array with the 2D coordinates of a set of parameter points. |
image_pts | An array with the 3D coordinates of a set of 3D points, which are the image of the paramenter points under a possibly unknown function. |
np | The number of parameter points. |
m | The first degree of this rectangular Bezier patch. |
n | The second degree of this rectangular Bezier patch. |
rx | The first Cartesian coordinate of the first point of the affine frame w.r.t. which this surface patch is defined. |
ry | The second coordinate of the first point of the affine frame w.r.t. which this surface patch is defined. |
sx | The first Cartesian coordinate of the second point of the affine frame w.r.t. which this surface patch is defined. |
sy | The second Cartesian coordinate of the second point of the affine frame w.r.t. which this surface patch is defined. |
Check consistency of the input parameters.
Initialize private attributes.
Allocate memory for the control points.
Compute a (np x ncp) matrix "A" with all Bernstein polynomials of order "_m + _n" at the parameter points given in the input vector "param_pts".
Compute the product "At x A", where "At" is the transpose of "A".
Compute the product "At x B", where "At" is the transpose of "A".
Solve the linear system "AtA Y = AtB[i]", where "AtB[i]" is the i-th column of "AtB", for i=0,1,2. This is done by using LU decomposition.
Compute the LU decomposition of AtA.
Allocate memory for the solution vector, "Y", of the linear system "AtA Y = AtB[i].
Solve the linear system AtA Y = AtB[i].
Store the solution in the i-th column of the matrix "_ctrl_pts[j]".
Release memory
Definition at line 78 of file bezier.cpp.
References _ctrl_pts, comp_bpoly_matrix(), comp_matrix_ata(), comp_matrix_atb(), get_bidegree_1st_index(), get_bidegree_2nd_index(), set_aff_1st_point_x_coord(), set_aff_1st_point_y_coord(), set_aff_2nd_point_x_coord(), set_aff_2nd_point_y_coord(), set_bidegree_1st_index(), set_bidegree_2nd_index(), and pps::LUdcmp::solve().
{ assert( m > 0 ) ; assert( n > 0 ) ; assert( rx < sx ) ; assert( ry < sy ) ; assert( ( 2 * ( n + 1 ) * ( m + 1 ) ) <= np ) ; set_bidegree_1st_index( m ) ; set_bidegree_2nd_index( n ) ; set_aff_1st_point_x_coord( rx ) ; set_aff_1st_point_y_coord( ry ) ; set_aff_2nd_point_x_coord( sx ) ; set_aff_2nd_point_y_coord( sy ) ; unsigned ncp = ( get_bidegree_1st_index() + 1 ) * ( get_bidegree_2nd_index() + 1 ) ; _ctrl_pts = new double*[ ncp ] ; for ( unsigned i = 0 ; i < ncp ; i++ ) { _ctrl_pts[ i ] = new double[ 3 ] ; } double** A = new double*[ np ] ; for ( unsigned i = 0 ; i < np ; i++ ) { A[ i ] = new double[ ncp ] ; } comp_bpoly_matrix( A , param_pts , np ) ; double** AtA = new double*[ ncp ] ; for ( unsigned i = 0 ; i < ncp ; i++ ) { AtA[ i ] = new double[ ncp ] ; } comp_matrix_ata( A , np , ncp , AtA ) ; double** AtB = new double*[ ncp ] ; for ( unsigned i = 0 ; i < ncp ; i++ ) { AtB[ i ] = new double[ 3 ] ; } comp_matrix_atb( A , image_pts , np , ncp , AtB ) ; LUdcmp LU( AtA , ncp ); double* Y = new double[ ncp ] ; for ( unsigned i = 0 ; i < 3 ; i++ ) { for ( unsigned j = 0 ; j < ncp ; j++ ) { Y[ j ] = AtB[ j ][ i ] ; } LU.solve( Y , ncp ) ; for ( unsigned j = 0 ; j < ncp ; j++ ) { _ctrl_pts[ j ][ i ] = Y[ j ] ; } } if (A != 0) { for ( unsigned i = 0 ; i < np ; i++ ) { if ( A[ i ] != 0 ) { delete[] A[ i ] ; } } delete A; } if ( AtA != 0 ) { for ( unsigned i = 0 ; i < ncp ; i++ ) { if ( AtA[ i ] != 0 ) { delete[] AtA[ i ] ; } } delete AtA ; } if ( AtB != 0 ) { for ( unsigned i = 0 ; i < ncp ; i++ ) { if ( AtB[ i ] != 0 ) { delete[] AtB[ i ] ; } } delete AtB ; } delete[] Y ; return ; }
pps::Bezier::Bezier | ( | const Bezier & | bz | ) |
Clones an instance of this Bezier class (through a deep copy).
bz | The instance of the Bezier class to be cloned. |
Initialize private attributes.
Allocate memory for the control points.
Definition at line 247 of file bezier.cpp.
References _ctrl_pts, get_aff_1st_point_x_coord(), get_aff_1st_point_y_coord(), get_aff_2nd_point_x_coord(), get_aff_2nd_point_y_coord(), get_bidegree_1st_index(), get_bidegree_2nd_index(), set_aff_1st_point_x_coord(), set_aff_1st_point_y_coord(), set_aff_2nd_point_x_coord(), set_aff_2nd_point_y_coord(), set_bidegree_1st_index(), and set_bidegree_2nd_index().
{ set_bidegree_1st_index( bz.get_bidegree_1st_index() ) ; set_bidegree_2nd_index( bz.get_bidegree_2nd_index() ) ; set_aff_1st_point_x_coord( bz.get_aff_1st_point_x_coord() ) ; set_aff_1st_point_y_coord( bz.get_aff_1st_point_y_coord() ) ; set_aff_2nd_point_x_coord( bz.get_aff_2nd_point_x_coord() ) ; set_aff_2nd_point_y_coord( bz.get_aff_2nd_point_y_coord() ) ; unsigned ncp = ( get_bidegree_1st_index() + 1 ) * ( get_bidegree_2nd_index() + 1 ) ; _ctrl_pts = new double*[ ( get_bidegree_1st_index() + 1 ) * ( get_bidegree_2nd_index() + 1 ) ] ; for ( unsigned i = 0 ; i < ncp ; i++ ) { _ctrl_pts[ i ] = new double[ 3 ] ; for ( unsigned j = 0 ; j < 3 ; j++ ) { _ctrl_pts[ i ][ j ] = bz._ctrl_pts[ i ][ j ] ; } } return ; }
void pps::Bezier::all_bernstein | ( | unsigned | n, |
double | u, | ||
std::vector< double > & | b | ||
) | const [private] |
Computes the value of all Bernstein polynomials of degree n at a given parameter value with respect to the affine frame [0,1].
Computes the value of all Bernstein polynomials at a given parameter value with respect to the affine frame [0,1].
n | The degree of the Bernstein polynomials. |
u | A parameter value. |
b | An array with the value of all Bernstein polynomials at the given parameter value. |
void Bezier::all_bernstein( unsigned n , double u , std::vector< double >& b ) const
n | The degree of the Bernstein polynomial. |
u | A parameter value. |
b | An array with the value of all Bernstein polynomials at the given parameter value. |
Definition at line 489 of file bezier.cpp.
Referenced by comp_bpoly_matrix(), and point().
void pps::Bezier::b | ( | unsigned | i, |
unsigned | j, | ||
double & | x, | ||
double & | y, | ||
double & | z | ||
) | const |
Get a specific control point defining this Bezier patch.
i | First index of the control point. |
j | Second index of the control point. |
x | First Cartesian coordinate of the control point. |
y | Second Caresian coordinate of the control point. |
z | Third Cartesian coordinate of the control point. |
Definition at line 323 of file bezier.cpp.
References _ctrl_pts, get_bidegree_1st_index(), get_bidegree_2nd_index(), and index().
Referenced by point().
{ assert( ( i <= get_bidegree_1st_index() ) && ( j <= get_bidegree_2nd_index() ) ) ; unsigned l = index( j , i ) ; x = _ctrl_pts[ l ][ 0 ] ; y = _ctrl_pts[ l ][ 1 ] ; z = _ctrl_pts[ l ][ 2 ] ; return ; }
double pps::Bezier::bernstein | ( | unsigned | n, |
unsigned | i, | ||
double | u | ||
) | const [private] |
Computes the value of i-th Bernstein polynomial of degree n (B_(n,i)) at a given parameter value with respect to the affine frame [0,1].
Computes the value of i-th Bernstein polynomial od degree n (B_(n,i)) at a given parameter value with respect to the affine frame [0,1].
n | The degree of the Bernstein polynomial. |
i | The index identifying the Bernstein polynomial. |
u | A parameter value. |
Definition at line 448 of file bezier.cpp.
{ assert( i <= n ) ; std::vector< double > temp( n + 1 ) ; for ( unsigned j = 0 ; j <= n ; j++ ) { temp[ j ] = 0 ; } temp[ n - i ] = 1 ; double u1 = 1 - u ; for ( unsigned k = 1 ; k <= n ; k++ ) { for ( unsigned j = n ; j >= k ; j-- ) { temp[ j ] = ( u1 * temp[ j ] ) + ( u * temp[ j - 1 ] ) ; } } return temp[ n ] ; }
void pps::Bezier::comp_bpoly_matrix | ( | double **& | a, |
double * | param_pts, | ||
unsigned | np | ||
) | const [private] |
Computes the pairwise product of all Bernstein polynomials of two degrees at a given set of parameters points. The two degrees are the the first and second index of the bi-degree of this patch.
a | A (np x (( m + 1) x ( n + 1)) matrix such that ( m , n ) is the bi-degree of this patch and each element of the matrix is a product of two Bernstein polynomials at a given parameter point. |
param_pts | An array of 2D coordinates of parameter points. |
np | The number of parameter points. |
a | A (np x (( m + 1) * ( n + 1)) matrix such that ( m , n ) is the bi-degree of this patch and each element of the matrix is a product of two Bernstein polynomials at a given parameter point. |
param_pts | An array of 2D coordinates of parameter points. |
np | The number of parameter points. |
Compute the value of the Bernstein polynomials at the parameter points.
Definition at line 529 of file bezier.cpp.
References all_bernstein(), get_aff_1st_point_x_coord(), get_aff_1st_point_y_coord(), get_aff_2nd_point_x_coord(), get_aff_2nd_point_y_coord(), get_bidegree_1st_index(), get_bidegree_2nd_index(), and index().
Referenced by Bezier().
{ double rx = get_aff_1st_point_x_coord() ; double ry = get_aff_1st_point_y_coord() ; double sx = get_aff_2nd_point_x_coord() ; double sy = get_aff_2nd_point_y_coord() ; for ( unsigned i = 0 ; i < np ; i++ ) { double x = ( param_pts[ ( i << 1 ) ] - rx ) / ( sx - rx ) ; double y = ( param_pts[ ( i << 1 ) + 1 ] - ry ) / ( sy - ry ) ; unsigned m = get_bidegree_1st_index() ; unsigned n = get_bidegree_2nd_index() ; std::vector< double > bu( m + 1 ) ; std::vector< double > bv( n + 1 ) ; all_bernstein( m , x , bu ) ; all_bernstein( n , y , bv ) ; for ( unsigned k = 0 ; k <= n ; ++k ) { for ( unsigned j = 0 ; j <= m ; ++j ) { unsigned l = index( k , j ) ; a[ i ][ l ] = bu[ j ] * bv[ k ] ; } } } return ; }
void pps::Bezier::comp_matrix_ata | ( | double ** | a, |
unsigned | n, | ||
unsigned | p, | ||
double **& | ata | ||
) | const [private] |
Computes the product of the transpose of a given matrix with the matrix itself.
a | A (n x p) matrix. |
n | The number of rows of parameter a. |
p | The number of columns of parameter a. |
ata | A matrix equal to the product of the transpose of the matrix in parameter a with a itself ( ![]() |
Definition at line 586 of file bezier.cpp.
Referenced by Bezier().
{ for ( unsigned i = 0 ; i < p ; i++ ) { for ( unsigned k = 0 ; k < p ; k++ ) { ata[ i ][ k ] = 0 ; for ( unsigned j = 0 ; j < n ; j++ ) { ata[ i ][ k ] += a[ j ][ i ] * a[ j ][ k ] ; } } } return ; }
void pps::Bezier::comp_matrix_atb | ( | double ** | a, |
double * | b, | ||
unsigned | n, | ||
unsigned | p, | ||
double **& | atb | ||
) | const [private] |
Computes the product of the transpose of a given ( n x p ) matrix "a" and a ( n x 3 ) matrix "b". The result is a ( p x 3 ) matrix.
a | The first matrix. |
b | The second matrix. |
n | The number of rows of the given matrices. |
p | The number of columns of the first matrix. |
atb | The matrix resulting from the multiplication of the transpose of the first matrix by the second matrix. |
Compute the product , where
is the transpose of
.
Definition at line 622 of file bezier.cpp.
Referenced by Bezier().
{ for ( unsigned i = 0 ; i < p ; i++ ) { atb[ i ] = new double[ 3 ] ; for ( unsigned k = 0 ; k < 3 ; k++ ) { atb[ i ][ k ] = 0 ; for ( unsigned j = 0 ; j < n ; j++ ) { atb[ i ][ k ] += a[ j ][ i ] * b[ ( 3 * j ) + k ] ; } } } return ; }
double pps::Bezier::get_aff_1st_point_x_coord | ( | ) | const [inline] |
Returns the first Cartesian coordinate of the first point of the affine frame with respect to which this patch is defined.
Definition at line 160 of file bezier.h.
References _rx.
Referenced by Bezier(), comp_bpoly_matrix(), and point().
{ return _rx ; }
unsigned pps::Bezier::get_aff_1st_point_y_coord | ( | ) | const [inline] |
Returns the second Cartesian coordinate of the first point of the affine frame with respect to which this patch is defined.
Definition at line 176 of file bezier.h.
References _ry.
Referenced by Bezier(), comp_bpoly_matrix(), and point().
{ return _ry ; }
unsigned pps::Bezier::get_aff_2nd_point_x_coord | ( | ) | const [inline] |
Returns the first Cartesian coordinate of the second point of the affine frame with respect to which this patch is defined.
Definition at line 192 of file bezier.h.
References _sx.
Referenced by Bezier(), comp_bpoly_matrix(), and point().
{ return _sx ; }
double pps::Bezier::get_aff_2nd_point_y_coord | ( | ) | const [inline] |
Returns the second Cartesian coordinate of the second point of the affine frame with respect to which this patch is defined.
Definition at line 208 of file bezier.h.
References _sy.
Referenced by Bezier(), comp_bpoly_matrix(), and point().
{ return _sy ; }
unsigned pps::Bezier::get_bidegree_1st_index | ( | ) | const [inline] |
unsigned pps::Bezier::get_bidegree_2nd_index | ( | ) | const [inline] |
unsigned pps::Bezier::index | ( | unsigned | i, |
unsigned | j | ||
) | const [inline, private] |
Computes the "linear" index of a control point.
i | First index of the control point. |
j | Second index of the control point. |
Definition at line 364 of file bezier.h.
References _m.
Referenced by b(), and comp_bpoly_matrix().
{ return ( i * ( _m + 1 ) ) + j ; }
void pps::Bezier::point | ( | double | u, |
double | v, | ||
double & | x, | ||
double & | y, | ||
double & | z | ||
) | const |
Compute a point on this rectangular Bezier patch.
u | First Cartesian coordinate of the parameter point. |
v | Second Cartesian coordinate of the parameter point. |
x | First Cartesian coordinate of the point on the patch. |
y | Second Caresian coordinate of the point on the patch. |
z | Third Cartesian coordinate of the point on the patch. |
Map the point to the affine frame [0,1].
Compute all Bernstein polynomials of degree
Definition at line 359 of file bezier.cpp.
References all_bernstein(), b(), get_aff_1st_point_x_coord(), get_aff_1st_point_y_coord(), get_aff_2nd_point_x_coord(), get_aff_2nd_point_y_coord(), get_bidegree_1st_index(), and get_bidegree_2nd_index().
Referenced by pps::PPS< Mesh >::compute_pdomain_contribution(), and pps::PPS< Mesh >::eval_pps().
void pps::Bezier::set_aff_1st_point_x_coord | ( | double | rx | ) | [inline, private] |
Assigns a value to the first Cartesian coordinate of the first point of the affine frame with respect to which this patch is defined.
rx | Value to be assigned to the first Cartesian coordinate of the first point of the affine frame with respect to which this patch is defined. |
Definition at line 297 of file bezier.h.
References _rx.
Referenced by Bezier().
{ _rx = rx ; }
void pps::Bezier::set_aff_1st_point_y_coord | ( | double | ry | ) | [inline, private] |
Assigns a value to the second Cartesian coordinate of the first point of the affine frame with respect to which this patch is defined.
ry | Value to be assigned to the second Cartesian coordinate of the first point of the affine frame with respect to which this patch is defined. |
Definition at line 314 of file bezier.h.
References _ry.
Referenced by Bezier().
{ _ry = ry ; }
void pps::Bezier::set_aff_2nd_point_x_coord | ( | double | sx | ) | [inline, private] |
Assigns a value to the first Cartesian coordinate of the second point of the affine frame with respect to which this patch is defined.
Definition at line 331 of file bezier.h.
References _sx.
Referenced by Bezier().
{ _sx = sx ; }
void pps::Bezier::set_aff_2nd_point_y_coord | ( | double | sy | ) | [inline, private] |
Assigns a value to the second Cartesian coordinate of the second point of the affine frame with respect to which this patch is defined.
sy | Value to be assigned to the second Cartesian coordinate of the second point of the affine frame with respect to which this patch is defined. |
Definition at line 348 of file bezier.h.
References _sy.
Referenced by Bezier().
{ _sy = sy ; }
void pps::Bezier::set_bidegree_1st_index | ( | unsigned | m | ) | [inline, private] |
void pps::Bezier::set_bidegree_2nd_index | ( | unsigned | n | ) | [inline, private] |
double** pps::Bezier::_ctrl_pts [private] |
pps::Bezier::_m [private] |
First bi-degree index.
Bi-degree of the Bezier patch.
Compute all Bernstein polynomials of degree
Definition at line 463 of file bezier.h.
Referenced by get_bidegree_1st_index(), index(), and set_bidegree_1st_index().
double pps::Bezier::_rx [private] |
First Cartesian coordinate of the first point of the affine frame.
Affine frame with respect to which this surface patch is defined.
Definition at line 471 of file bezier.h.
Referenced by get_aff_1st_point_x_coord(), and set_aff_1st_point_x_coord().