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;
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.feature.OrientedFeatureVector;
039import org.openimaj.image.feature.local.interest.InterestPointData;
040
041/**
042 * An oriented feature with at a location defined by an
043 * {@link InterestPointData}.
044 * 
045 * @author Sina Samangooei (ss@ecs.soton.ac.uk)
046 * 
047 * @param <T>
048 *            The type of {@link InterestPointData}
049 */
050public abstract class InterestPointKeypoint<T extends InterestPointData> extends Keypoint {
051        /**
052         * 
053         */
054        private static final long serialVersionUID = 1L;
055        /**
056         * The feature location
057         */
058        public T location;
059
060        /**
061         * Construct with a <code>null</code> location and default length feature
062         */
063        public InterestPointKeypoint() {
064        }
065
066        /**
067         * Construct with a <code>null</code> location and feature of the given
068         * length
069         * 
070         * @param length
071         *            the feature length
072         */
073        public InterestPointKeypoint(int length) {
074                super(length);
075        }
076
077        /**
078         * @param featureVector
079         *            the feature vector containing orientation and the byte[]
080         * @param point
081         *            the location and shape of the interest point
082         */
083        public InterestPointKeypoint(OrientedFeatureVector featureVector, T point) {
084                this.ivec = featureVector.values.clone();
085                this.location = point;
086                this.x = this.location.x;
087                this.y = this.location.y;
088                this.scale = this.location.scale;
089                this.ori = featureVector.orientation;
090        }
091
092        /**
093         * @return create a new {@link InterestPointData} compatible with this
094         *         feature
095         */
096        public abstract T createEmptyLocation();
097
098        @Override
099        public void readBinary(DataInput in) throws IOException {
100                super.readBinary(in);
101                location = createEmptyLocation();
102                location.readBinary(in);
103        }
104
105        @Override
106        public void readASCII(Scanner in) throws IOException {
107                super.readASCII(in);
108                location = createEmptyLocation();
109                location.readASCII(in);
110        }
111
112        @Override
113        public byte[] binaryHeader() {
114                return super.binaryHeader();
115        }
116
117        @Override
118        public String asciiHeader() {
119                return super.asciiHeader();
120        }
121
122        @Override
123        public void writeBinary(DataOutput out) throws IOException {
124                super.writeBinary(out);
125                this.location.writeBinary(out);
126
127        }
128
129        @Override
130        public void writeASCII(PrintWriter out) throws IOException {
131                super.writeASCII(out);
132                this.location.writeASCII(out);
133        }
134}