001/******************************************************************************* 002 * This software is provided as a supplement to the authors' textbooks on digital 003 * image processing published by Springer-Verlag in various languages and editions. 004 * Permission to use and distribute this software is granted under the BSD 2-Clause 005 * "Simplified" License (see http://opensource.org/licenses/BSD-2-Clause). 006 * Copyright (c) 2006-2016 Wilhelm Burger, Mark J. Burge. All rights reserved. 007 * Visit http://imagingbook.com for additional details. 008 *******************************************************************************/ 009 010package imagingbook.pub.geometry.mappings.linear; 011 012import java.awt.geom.Point2D; 013 014 015public class Translation extends AffineMapping { 016 017 public Translation() { 018 super(); 019 } 020 021 public Translation(double dx, double dy){ 022 super(); 023 a02 = dx; 024 a12 = dy; 025 } 026 027 public Translation(Point2D p1, Point2D p2) { 028 this(p2.getX() - p1.getX(), p2.getY() - p1.getY()); 029 } 030 031 // for consistency: 032 public Translation(Point2D[] A, Point2D[] B) { 033 this(A[0], B[0]); 034 } 035 036 public Translation(LinearMapping t) { 037 super(); 038 this.a02 = t.a02; 039 this.a12 = t.a12; 040 } 041 042 public Translation invert() { 043 Translation t2 = new Translation(); 044 t2.a02 = -this.a02; 045 t2.a12 = -this.a12; 046 //return (Translation) super.invert(); 047 return t2; 048 } 049 050 @Override 051 public Translation duplicate() { 052 return new Translation(this); 053 } 054 055 // Warp parameter support ------------------------------------- 056 057 @Override 058 public int getWarpParameterCount() { 059 return 2; 060 } 061 062 @Override 063 public double[] getWarpParameters() { 064 double[] p = new double[] {a02, a12}; 065 return p; 066 } 067 068 @Override 069 public void setWarpParameters(double[] p) { 070 a02 = p[0]; 071 a12 = p[1]; 072 } 073 074 private final double[][] J = // this transformation has a constant Jacobian 075 {{1, 0}, 076 {0, 1}}; 077 078 @Override 079 public double[][] getWarpJacobian(double[] X) { 080 return J; 081 } 082 083}