/** Creates a new matrix initialized to the specified values. */ public Matrix3( double m00, double m01, double m02, double m10, double m11, double m12, double m20, double m21, double m22) { mat = new DMatrix3x3(m00, m01, m02, m10, m11, m12, m20, m21, m22); }
/** * Extract row to provided array * * @param row * @param array */ public void getRow(int row, double[] array) { for (int i = 0; i < array.length; i++) { array[i] = mat.get(row, i); } }
public void setColumn(int column, double... values) { if (values.length != mat.getNumCols()) { throw new IllegalArgumentException( "Call setRow received an array of length " + values.length + ". " + "The dimensions of the matrix is " + mat.getNumRows() + " by " + mat.getNumCols() + "."); } for (int i = 0; i < values.length; i++) { mat.set(i, column, values[i]); } }
/** * Converts {@link DMatrixRMaj} into {@link DMatrix3x3} * * @param input Input matrix. * @param output Output matrix. If null a new matrix will be declared. * @return Converted matrix. */ public static DMatrix3x3 convert(DMatrixRMaj input , DMatrix3x3 output ) { if( output == null) output = new DMatrix3x3(); if( input.getNumRows() != output.getNumRows() ) throw new IllegalArgumentException("Number of rows do not match"); if( input.getNumCols() != output.getNumCols() ) throw new IllegalArgumentException("Number of columns do not match"); output.a11 = input.data[0]; output.a12 = input.data[1]; output.a13 = input.data[2]; output.a21 = input.data[3]; output.a22 = input.data[4]; output.a23 = input.data[5]; output.a31 = input.data[6]; output.a32 = input.data[7]; output.a33 = input.data[8]; return output; }
/** * Converts {@link DMatrix3x3} into {@link DMatrixRMaj}. * * @param input Input matrix. * @param output Output matrix. If null a new matrix will be declared. * @return Converted matrix. */ public static DMatrixRMaj convert(DMatrix3x3 input , DMatrixRMaj output ) { if( output == null) output = new DMatrixRMaj(3,3); output.reshape(input.getNumRows(),input.getNumCols()); output.data[0] = input.a11; output.data[1] = input.a12; output.data[2] = input.a13; output.data[3] = input.a21; output.data[4] = input.a22; output.data[5] = input.a23; output.data[6] = input.a31; output.data[7] = input.a32; output.data[8] = input.a33; return output; }
/** * Sets the value of the row, column position in the matrix. * * @param row * @param column * @param value */ @Override public void setElement(int row, int column, double value) { mat.set(row, column, value); }
@Override public double get(int row, int col) { return unsafe_get(row,col); }
/** * Decomposes the absolute dual quadratic into the following submatrices: Q=[w -w*p;-p'*w p'*w*p] * * @see DecomposeAbsoluteDualQuadratic * * @param Q (Input) Absolute quadratic. Typically found in auto calibration. Not modified. * @param w (Output) 3x3 symmetric matrix * @param p (Output) 3x1 vector * @return true if successful or false if it failed */ public static boolean decomposeAbsDualQuadratic( DMatrix4x4 Q , DMatrix3x3 w , DMatrix3 p ) { DecomposeAbsoluteDualQuadratic alg = new DecomposeAbsoluteDualQuadratic(); if( !alg.decompose(Q) ) return false; w.set(alg.getW()); p.set(alg.getP()); return true; }
/** Constructs a 3×3 matrix from the specified affine transform. */ public Matrix3(final AffineTransform transform) { mat = new DMatrix3x3(); setMatrix(transform); }
public void setRow(int row, double... values) { if (values.length != mat.getNumCols()) { throw new IllegalArgumentException( "Call setRow received an array of length " + values.length + ". " + "The dimensions of the matrix is " + mat.getNumRows() + " by " + mat.getNumCols() + "."); } for (int i = 0; i < values.length; i++) { mat.set(row, i, values[i]); } }
/** * Returns the value at the row, column position in the matrix. * * @param row * @param column * @return Matrix value at the given row and column. */ @Override public double getElement(int row, int column) { return mat.get(row, column); }
k.set(w_inv); k.a11 = Math.abs(k.a11); k.a22 = Math.abs(k.a22);
@Override public void mul(double scalar, Matrix matrix) { DMatrix3x3 ret = new DMatrix3x3(); CommonOps_DDF3.scale(scalar, internal(matrix), ret); mat = ret; }
/** * Extract col to provided array. * * @param col * @param array */ public void getColumn(int col, double[] array) { for (int j = 0; j < array.length; j++) { array[j] = mat.get(j, col); } }
@Override public void invert() { DMatrix3x3 ret = new DMatrix3x3(); boolean success = CommonOps_DDF3.invert(mat, ret); if (!success) { throw new SingularMatrixException("Could not invert, possible singular matrix?"); } mat = ret; }
/** * Computes the rectifying homography from the decomposed Q * * H = [K 0; -p'*K 1] see Pg 460 */ public boolean computeRectifyingHomography( DMatrixRMaj H ) { H.reshape(4,4); // insert the results into H // H = [K 0;-p'*K 1 ] H.zero(); for (int i = 0; i < 3; i++) { for (int j = i; j < 3; j++) { H.set(i,j,k.get(i,j)); } } // p and k have different scales, fix that H.set(3,0, -(p.a1*k.a11 + p.a2*k.a21 + p.a3*k.a31)); H.set(3,1, -(p.a1*k.a12 + p.a2*k.a22 + p.a3*k.a32)); H.set(3,2, -(p.a1*k.a13 + p.a2*k.a23 + p.a3*k.a33)); H.set(3,3,1); return true; }
/** * In-place multiply with provided matrix. * * @param matrix */ public final void mul(Matrix matrix) { DMatrix3x3 b = internal(matrix); DMatrix3x3 ret = new DMatrix3x3(); CommonOps_DDF3.mult(mat, b, ret); mat = ret; }
/** * In-place update from matrix1 * matrix2. * * @param matrix1 * @param matrix2 */ public void mul(Matrix matrix1, Matrix matrix2) { DMatrix3x3 a = internal(matrix1); DMatrix3x3 b = internal(matrix2); if (a == mat || b == mat) { mat = new DMatrix3x3(); } CommonOps_DDF3.mult(a, b, mat); }
/** * Creates a new matrix initialized to the same value than the specified one. The specified * matrix size must be {@value #SIZE}×{@value #SIZE}. */ public Matrix3(final Matrix matrix) { mat = new DMatrix3x3(); if (matrix.getNumRow() != SIZE || matrix.getNumCol() != SIZE) { throw new IllegalArgumentException(Errors.format(ErrorKeys.ILLEGAL_MATRIX_SIZE)); } for (int j = 0; j < SIZE; j++) { for (int i = 0; i < SIZE; i++) { setElement(j, i, matrix.getElement(j, i)); } } } /**
@Override public <T extends Matrix> T createLike() { return (T)new DMatrix3x3(); }