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.feature.local; 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.point.ScaleSpacePoint; 039 040/** 041 * ScaleSpaceLocation represents a {@link Location} in scale-space. 042 * ScaleSpaceLocations contain x, y and scale ordinates. 043 * 044 * @author Jonathon Hare (jsh2@ecs.soton.ac.uk) 045 * 046 */ 047public class ScaleSpaceLocation extends SpatialLocation implements ScaleSpacePoint, Cloneable { 048 private static final long serialVersionUID = 1L; 049 050 /** 051 * the scale 052 */ 053 public float scale; 054 055 /** 056 * Construct the ScaleSpaceLocation at 0, 0, 0. 057 */ 058 public ScaleSpaceLocation() { 059 super(0, 0); 060 } 061 062 /** 063 * Construct the ScaleSpaceLocation with the given x, y and 064 * scale coordinates. 065 * @param x the x-coordinate 066 * @param y the y-coordinate 067 * @param scale the scale coordinate 068 */ 069 public ScaleSpaceLocation(float x, float y, float scale) { 070 super(x, y); 071 this.scale = scale; 072 } 073 074 @Override 075 public void writeBinary(DataOutput out) throws IOException { 076 out.writeFloat(this.x); 077 out.writeFloat(this.y); 078 out.writeFloat(this.scale); 079 } 080 081 @Override 082 public void writeASCII(PrintWriter out) throws IOException { 083 //for legacy reasons ascii format writes y, x, scale 084 out.format("%4.2f %4.2f %4.2f", y, x, scale); 085 out.println(); 086 } 087 088 @Override 089 public void readBinary(DataInput in) throws IOException { 090 x = in.readFloat(); 091 y = in.readFloat(); 092 scale = in.readFloat(); 093 } 094 095 @Override 096 public void readASCII(Scanner in) throws IOException { 097 y = Float.parseFloat(in.next()); 098 x = Float.parseFloat(in.next()); 099 scale = Float.parseFloat(in.next()); 100 } 101 102 @Override 103 public byte[] binaryHeader() { 104 return "".getBytes(); 105 } 106 107 @Override 108 public String asciiHeader() { 109 return ""; 110 } 111 112 @Override 113 public Float getOrdinate(int dimension) { 114 float [] pos = {x, y, scale}; 115 return pos[dimension]; 116 } 117 118 @Override 119 public int getDimensions() { 120 return 3; 121 } 122 123 @Override 124 public float getScale() { 125 return scale; 126 } 127 128 @Override 129 public void setScale(float scale) { 130 this.scale = scale; 131 } 132 133 @Override 134 public ScaleSpaceLocation clone(){ 135 ScaleSpaceLocation l = (ScaleSpaceLocation) super.clone(); 136 l.scale = this.scale; 137 return l; 138 } 139}