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.keypoints.quantised;
031
032import org.openimaj.feature.local.quantised.QuantisedLocalFeature;
033import org.openimaj.image.feature.local.keypoints.Keypoint;
034import org.openimaj.image.feature.local.keypoints.KeypointLocation;
035import org.openimaj.math.geometry.point.Point2d;
036
037import Jama.Matrix;
038
039/**
040 * A {@link QuantisedKeypoint} is a {@link QuantisedLocalFeature} with its
041 * location described by a {@link KeypointLocation}. It is the quantised
042 * equivalent to a {@link Keypoint}, with the feature vector replaced by a
043 * single integer assignment.
044 *
045 * @author Jonathon Hare (jsh2@ecs.soton.ac.uk)
046 */
047public class QuantisedKeypoint extends QuantisedLocalFeature<KeypointLocation> implements Point2d {
048        /**
049         * Construct an empty {@link QuantisedKeypoint}, located at the origin with
050         * an id of 0.
051         */
052        public QuantisedKeypoint() {
053                super(new KeypointLocation(0, 0, 0, 0), 0);
054        }
055
056        /**
057         * Construct a {@link QuantisedKeypoint}, located at the given position with
058         * an id of 0.
059         *
060         * @param loc
061         *            the position
062         */
063        public QuantisedKeypoint(KeypointLocation loc) {
064                super(loc, 0);
065        }
066
067        /**
068         * Construct a {@link QuantisedKeypoint}, located at the given position and
069         * id.
070         *
071         * @param loc
072         *            the position
073         * @param id
074         *            the id
075         */
076        public QuantisedKeypoint(KeypointLocation loc, int id) {
077                super(loc, id);
078        }
079
080        @Override
081        public Float getOrdinate(int dimension) {
082                if (dimension == 0)
083                        return location.x;
084                if (dimension == 1)
085                        return location.y;
086                if (dimension == 2)
087                        return location.scale;
088                return null;
089        }
090
091        @Override
092        public void setOrdinate(int dimension, Number value) {
093                if (dimension == 0)
094                        location.x = value.floatValue();
095                if (dimension == 1)
096                        location.y = value.floatValue();
097                if (dimension == 2)
098                        location.scale = value.floatValue();
099        }
100
101        @Override
102        public int getDimensions() {
103                return 3;
104        }
105
106        @Override
107        public float getX() {
108                return location.x;
109        }
110
111        @Override
112        public float getY() {
113                return location.y;
114        }
115
116        @Override
117        public void setX(float x) {
118                this.location.x = x;
119        }
120
121        @Override
122        public void setY(float y) {
123                this.location.y = y;
124        }
125
126        @Override
127        public void copyFrom(Point2d p) {
128                location.copyFrom(p);
129        }
130
131        @Override
132        public Point2d copy() {
133                return location.copy();
134        }
135
136        @Override
137        public void translate(float x, float y) {
138                location.translate(x, y);
139        }
140
141        @Override
142        public Point2d transform(Matrix m) {
143                return location.transform(m);
144        }
145
146        @Override
147        public Point2d minus(Point2d a) {
148                return location.minus(a);
149        }
150
151        @Override
152        public void translate(Point2d v) {
153                location.translate(v);
154        }
155
156}