ifw-odp  2.0.0-alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions
clipm_priv_matrix.h File Reference
#include <cpl.h>

Go to the source code of this file.

Functions

cpl_matrix * clipm_priv_matrix_new_from_image_window (const cpl_image *image, const cpl_size window_xxyy[4], const int vflip)
 Extract an image window into a matrix, flip vertically. More...
 
cpl_error_code clipm_priv_matrix_round (cpl_matrix *matrix)
 Round the elements of a matrix to the nearest integer. More...
 
cpl_matrix * clipm_priv_matrix_get_median_rows (const cpl_matrix *matrix)
 Get the medians of the values in the matrix rows respectively. More...
 
cpl_matrix * clipm_priv_matrix_get_mean_rows (const cpl_matrix *matrix)
 Get the means of the values in the matrix rows respectively. More...
 
cpl_matrix * clipm_priv_matrix_select_cols (const cpl_matrix *matrix, const int *selection, int select_nonzero)
 Return selected columns in a new matrix. More...
 
cpl_error_code clipm_priv_matrix_copy_col_vector (cpl_matrix *matrix, const cpl_vector *in, cpl_size col, cpl_size start_row)
 Copy the content of a vector into a matrix column (or a part of it). More...
 
cpl_error_code clipm_priv_matrix_copy_vector_col (cpl_vector *in, const cpl_matrix *matrix, cpl_size col, cpl_size start_row)
 Copy the content of a matrix column (or a part of it) into a vector. More...
 
cpl_error_code clipm_priv_matrix_transform_create_rot2d (double angle, const double *centre_xy, cpl_matrix **transform, cpl_matrix **shift)
 
cpl_error_code clipm_priv_matrix_transform_invert (const cpl_matrix *transf, const cpl_matrix *shift, cpl_matrix **inv_transf, cpl_matrix **inv_shift)
 Compute the inverse transform. More...
 
cpl_matrix * clipm_priv_matrix_transform_points (const cpl_matrix *points, const cpl_matrix *transformation, const cpl_matrix *shift)
 Transform a pointlist. More...
 
cpl_matrix * clipm_priv_matrix_create_corners_rectangle (const double centre_xy[2], double angle, const double size_lw[2])
 Create a matrix containing the corner points of a rectangle. More...
 
void clipm_priv_matrix_null (cpl_matrix **m)
 Delete a CPL matrix object and set the pointer to NULL. More...
 

Function Documentation

cpl_error_code clipm_priv_matrix_copy_col_vector ( cpl_matrix *  matrix,
const cpl_vector *  vector,
cpl_size  col,
cpl_size  start_row 
)

Copy the content of a vector into a matrix column (or a part of it).

Parameters
matrixModified matrix
vectorInput vector
colMatrix column index
start_rowIndex of the starting matrix row
Returns
CPL error code
Principle:
A vector is copied into a column of the provided matrix, starting at the matrix row start_row. Only the number of vector elements is copied. start_row plus the vector's size must be less than or equal to the number of matrix rows.
Error Handling:
This function can return the following error codes:
  • CPL_ERROR_NULL_INPUT: matrix or vector is NULL
  • CPL_ERROR_ACCESS_OUT_OF_RANGE:
    • col < 0, or col >= the number of columns of the matrix, or
    • start_row < 0, or
    • start_row + the vector's size > the number of matrix rows
In the case of error, the matrix is not modified.
cpl_error_code clipm_priv_matrix_copy_vector_col ( cpl_vector *  vector,
const cpl_matrix *  matrix,
cpl_size  col,
cpl_size  start_row 
)

Copy the content of a matrix column (or a part of it) into a vector.

Parameters
vectorModified vector
matrixInput matrix
colMatrix column index
start_rowIndex of the starting matrix row
Returns
CPL error code
Principle:
A matrix column, starting at row start_row, is copied into the provided vector. Only the number of vector elements is regarded. start_row plus the vector's size must be less than or equal to the number of matrix rows.
Error Handling:
This function can return the following error codes:
  • CPL_ERROR_NULL_INPUT: vector or matrix is NULL
  • CPL_ERROR_ACCESS_OUT_OF_RANGE:
    • col < 0, or col >= the number of columns of the matrix, or
    • start_row < 0, or
    • start_row + the vector's size > the number of matrix rows
In the case of error, the vector is not modified.
cpl_matrix* clipm_priv_matrix_create_corners_rectangle ( const double  centre_xy[2],
double  angle,
const double  size_lw[2] 
)

Create a matrix containing the corner points of a rectangle.

Parameters
centre_xyCentre coordinate as (x,y) tuple
angleOrientation
size_lwLength and width as a data tuple, the first entry (size_lw[0]) will point into the direction of angle
Returns
The matrix of size 2x4, NULL in the case of error

The output matrix will contain (x,y) tuples in 4 columns, respectively.

Error Handling:
  • CPL_ERROR_NULL_INPUT: if any input pointer is NULL
Todo:
  • implement unit test
cpl_matrix* clipm_priv_matrix_get_mean_rows ( const cpl_matrix *  matrix)

Get the means of the values in the matrix rows respectively.

Parameters
matrixN x M input matrix
Returns
N x 1 output matrix, NULL on error
Principle:
The output matrix has one column and the same number of rows as the input matrix, with each column containing the mean of all values in the same row in the input matrix.
Error Handling:
If matrix is NULL, CPL_ERROR_NULL_INPUT is set and NULL is returned.
cpl_matrix* clipm_priv_matrix_get_median_rows ( const cpl_matrix *  matrix)

Get the medians of the values in the matrix rows respectively.

Parameters
matrixN x M input matrix
Returns
N x 1 output matrix, NULL on error
Principle:
The output matrix has one column and the same number of rows as the input matrix, with each column containing the median of all values in the same row in the input matrix.
Error Handling:
If matrix is NULL, CPL_ERROR_NULL_INPUT is set and NULL is returned.
cpl_matrix* clipm_priv_matrix_new_from_image_window ( const cpl_image *  image,
const cpl_size  window_xxyy[4],
const int  vflip 
)

Extract an image window into a matrix, flip vertically.

Parameters
imageInput image (FITS convention)
window_xxyyCoordinate buffer (FITS) of the form {xa, xb, ya, yb}, can be NULL, minimum/maximum order is irrelevant
vflipFlag whether to vertically flip the data buffer
Returns
The matrix
Principle:
  • The image data (from a window) is copied into a matrix.
  • If vflip is not zero, then the data are flipped vertically (in terms of indexing) to respect the FITS convention.
  • Images can be of type CPL_TYPE_INT, CPL_TYPE_FLOAT or CPL_TYPE_DOUBLE.
Error Handling:
Possible error codes set in this function:
  • CPL_ERROR_NULL_INPUT if image is NULL
  • CPL_ERROR_INVALID_TYPE if the passed image type is not supported
  • CPL_ERROR_ACCESS_OUT_OF_RANGE if a coordinate is out of the image range
Example:
With vflip != 0, the following image content
column 1 2 3 4
row __________________
4 | A B C D
3 | E F G H
2 | I J K L
1 | M N O P
*
together with the window {2, 4, 2, 4} will result in the matrix:
column 0 1 2
row __________________
0 | B C D
1 | F G H
2 | J K L
*
Todo:
Remove when cpl_matrix_new_from_image_window() is available.
void clipm_priv_matrix_null ( cpl_matrix **  m)

Delete a CPL matrix object and set the pointer to NULL.

Parameters
mPointer to matrix pointer
Returns
Nothing

The following code is executed:

if (m != NULL)
{
cpl_matrix_delete(*m); // checks for NULL pointer
*m = NULL;
}
*
Error Handling:
No error can occur here.
cpl_error_code clipm_priv_matrix_round ( cpl_matrix *  matrix)

Round the elements of a matrix to the nearest integer.

Parameters
matrixThe matrix
Returns
CPL error code
Principle:
Element by element, the elements are rounded.
Error Handling:
If matrix is NULL, CPL_ERROR_NULL_INPUT is returned.
Todo:
: Remove when cpl_matrix_round() is available.
cpl_matrix* clipm_priv_matrix_select_cols ( const cpl_matrix *  matrix,
const int *  selection,
int  select_nonzero 
)

Return selected columns in a new matrix.

Parameters
matrixN x M input matrix
selectionInteger buffer of size M containing the selection flags
select_nonzeroFlag to either select columns with a selection flag equal to zero or different from zero
Returns
N x nselected output matrix, NULL on error
Principle:
If select_nonzeros is 0, then all columns with selection[column]==0 are selected, otherwise all columns with selection[column]!=0 are selected.
Error Handling:
The following error cases may occur, and the corresponding error codes set:
  • CPL_ERROR_NULL_INPUT: matrix is NULL
  • CPL_ERROR_DATA_NOT_FOUND: no columns are selected
In the case of error, NULL is returned.
cpl_error_code clipm_priv_matrix_transform_create_rot2d ( double  angle,
const double *  centre_xy,
cpl_matrix **  transform,
cpl_matrix **  shift 
)
cpl_error_code clipm_priv_matrix_transform_invert ( const cpl_matrix *  transf,
const cpl_matrix *  shift,
cpl_matrix **  inv_transf,
cpl_matrix **  inv_shift 
)

Compute the inverse transform.

Parameters
transfInput transformation matrix
shiftInput shift vector
inv_transfOutput transformation matrix
inv_shiftOutput shift vector
Returns
CPL error code
Principle:
The following expression "out = transf * in + shift" is inverted so that "in = inv_transf * out + inv_shift".
Error Handling:
The following error codes can be set and returned:
  • CPL_ERROR_NULL_INPUT: any input is NULL
  • CPL_ERROR_ILLEGAL_INPUT: transf is not a square matrix
  • CPL_ERROR_SINGULAR_MATRIX: transf cannot be inverted
  • CPL_ERROR_INCOMPATIBLE_INPUT: the number of columns of transf is not equal to the number of rows of shift
Todo:
  • implement unit test
cpl_matrix* clipm_priv_matrix_transform_points ( const cpl_matrix *  points,
const cpl_matrix *  transformation,
const cpl_matrix *  shift 
)

Transform a pointlist.

Parameters
pointsND x NP (number of dimensions, times number of points) matrix containing the point coordinates
transformationThe ND x ND square transformation matrix, can be NULL
shiftThe ND x 1 shift matrix (vector), can be NULL
Returns
The transformed points, NULL on error
Transformation:
The transformation is done by the following formula (where K denotes the column of points):

\[ point_K' = transformation \times point_K + shift \]

Parameter Details:
  • The matrices points and shift are expected in the following forms:
    $ points = \left( \begin{array}{lllc} x_0 & x_1 & \cdots & x_{NP-1} \\ y_0 & y_1 & \cdots & y_{NP-1} \\ z_0 & z_1 & \cdots & z_{NP-1} \\ \vdots & \vdots & & \vdots \end{array} \right) $, and $shift = \left( \begin{array}{c} s_x\\ s_y\\ s_z\\ \vdots \end{array} \right)$.
Constraints:
  • The number of dimensions (ND) can be any > 0.
  • The number of points (NP) can be any > 0.
  • The transformation matrix must be square (ND x ND)
  • The shift matrix represents a vector and must be of size ND x 1
  • If transformation and shift are both NULL, then points is just copied.
Error Handling:
  • CPL_ERROR_NULL_INPUT if points is NULL
  • CPL_ERROR_INCOMPATIBLE_INPUT if the sizes of the input parameters do not fit together
  • CPL_ERROR_ILLEGAL_INPUT:
    • if shift has more than one column
    • if transformation is not square