001/** 002 * Copyright (c) 2011, The University of Southampton and the individual contributors. 003 * All rights reserved. 004 * 005 * Redistribution and use in source and binary forms, with or without modification, 006 * are permitted provided that the following conditions are met: 007 * 008 * * Redistributions of source code must retain the above copyright notice, 009 * this list of conditions and the following disclaimer. 010 * 011 * * Redistributions in binary form must reproduce the above copyright notice, 012 * this list of conditions and the following disclaimer in the documentation 013 * and/or other materials provided with the distribution. 014 * 015 * * Neither the name of the University of Southampton nor the names of its 016 * contributors may be used to endorse or promote products derived from this 017 * software without specific prior written permission. 018 * 019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 020 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 022 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 023 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 026 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 029 */ 030package org.openimaj.image.feature.local.interest; 031 032import java.io.DataInput; 033import java.io.DataOutput; 034import java.io.IOException; 035import java.io.PrintWriter; 036import java.util.Scanner; 037 038import org.openimaj.math.geometry.shape.Ellipse; 039import org.openimaj.math.geometry.shape.EllipseUtilities; 040 041import Jama.Matrix; 042 043public class EllipticInterestPointData extends InterestPointData { 044 045 /** 046 * 047 */ 048 private static final long serialVersionUID = 3442580574124477236L; 049 050 public Matrix transform; 051 052 053 public void setTransform(Matrix transform) { 054 this.transform = transform; 055 } 056 057 @Override 058 public Matrix getTransform(){ 059 Matrix m = new Matrix(3,3); 060 m.setMatrix(0, 1, 0,1,this.transform); 061 m.set(0, 2, 0); 062 m.set(1, 2, 0); 063 m.set(2, 2, 1); 064 return m; 065 } 066 067 @Override 068 public Ellipse getEllipse() { 069 return EllipseUtilities.fromTransformMatrix2x2(transform, x, y, scale); 070 } 071 072 @Override 073 public void writeBinary(DataOutput out) throws IOException { 074 super.writeBinary(out); 075 out.writeFloat((float) transform.get(0,0)); 076 out.writeFloat((float) transform.get(0,1)); 077 out.writeFloat((float) transform.get(1,0)); 078 out.writeFloat((float) transform.get(1,1)); 079 } 080 081 @Override 082 public void writeASCII(PrintWriter out) throws IOException { 083 super.writeASCII(out); 084 out.format(" %4.2f %4.2f %4.2f %4.2f", (float) transform.get(0,0),(float) transform.get(0,1),(float) transform.get(1,0),(float) transform.get(1,1)); 085 } 086 087 @Override 088 public void readBinary(DataInput in) throws IOException { 089 super.readBinary(in); 090 this.transform = new Matrix(2,2); 091 this.transform.set(0, 0, in.readFloat()); 092 this.transform.set(0, 1, in.readFloat()); 093 this.transform.set(1, 0, in.readFloat()); 094 this.transform.set(1, 1, in.readFloat()); 095 this.setTransform(this.transform); 096 } 097 098 @Override 099 public void readASCII(Scanner in) throws IOException { 100 super.readASCII(in); 101 this.transform = new Matrix(2,2); 102 this.transform.set(0, 0, in.nextFloat()); 103 this.transform.set(0, 1, in.nextFloat()); 104 this.transform.set(1, 0, in.nextFloat()); 105 this.transform.set(1, 1, in.nextFloat()); 106 this.setTransform(this.transform); 107 } 108 109 @Override 110 public EllipticInterestPointData clone() { 111 EllipticInterestPointData d = (EllipticInterestPointData) super.clone(); 112 d.transform = this.transform.copy(); 113 return d; 114 } 115}