001package net.gdface.sdk;
002
003import java.io.ByteArrayOutputStream;
004import java.io.PrintStream;
005import java.io.Serializable;
006
007/**
008 * 
009 * 人脸角度描述对象
010 * @author guyadong
011 *
012 */
013public class FAngle implements Serializable{
014        /**
015         * 
016         */
017        private static final long serialVersionUID = 1L;
018        private int   yaw;//angle of yaw,from -90 to +90,left is negative,right is postive
019        private int   pitch;//angle of pitch,from -90 to +90,up is negative,down is postive
020        private int   roll;//angle of roll,from -90 to +90,left is negative,right is postive
021        private float confidence;//confidence of face pose(from 0 to 1,0.6 is suggested threshold)
022        public FAngle() {
023                this(0,0,0,0f);
024        }
025        public FAngle(int yaw, int pitch, int roll,float confidence) {
026                this.yaw = yaw;
027                this.pitch = pitch;
028                this.roll = roll;
029                this.confidence=confidence;
030        }
031        /**
032         * @return yaw
033         */
034        public int getYaw() {
035                return yaw;
036        }
037        /**
038         * @param yaw 要设置的 yaw
039         */
040        public void setYaw(int yaw) {
041                this.yaw = yaw;
042        }
043        /**
044         * @return pitch
045         */
046        public int getPitch() {
047                return pitch;
048        }
049        /**
050         * @param pitch 要设置的 pitch
051         */
052        public void setPitch(int pitch) {
053                this.pitch = pitch;
054        }
055        /**
056         * @return roll
057         */
058        public int getRoll() {
059                return roll;
060        }
061        /**
062         * @param roll 要设置的 roll
063         */
064        public void setRoll(int roll) {
065                this.roll = roll;
066        }
067        /**
068         * @return confidence
069         */
070        public float getConfidence() {
071                return confidence;
072        }
073        /**
074         * @param confidence 要设置的 confidence
075         */
076        public void setConfidence(float confidence) {
077                this.confidence = confidence;
078        }
079        @Override
080        public String toString() {
081                ByteArrayOutputStream bo = new ByteArrayOutputStream();
082                toStream(new PrintStream(bo));
083                return bo.toString();
084        }
085        /**
086         * 以文本形式向{@link PrintStream}输出对象内容 
087         * @param stream
088         */
089        public void toStream(PrintStream stream) {
090                stream.printf("[yaw=%d,picth=%d,roll=%d,confidence=%f]",this.yaw,this.pitch,this.roll,this.confidence);
091        }
092        @Override
093        public int hashCode() {
094                final int prime = 31;
095                int result = 1;
096                result = prime * result + Float.floatToIntBits(confidence);
097                result = prime * result + pitch;
098                result = prime * result + roll;
099                result = prime * result + yaw;
100                return result;
101        }
102        @Override
103        public boolean equals(Object obj) {
104                if (this == obj) {
105                        return true;
106                }
107                if (obj == null) {
108                        return false;
109                }
110                if (!(obj instanceof FAngle)) {
111                        return false;
112                }
113                FAngle other = (FAngle) obj;
114                if (Float.floatToIntBits(confidence) != Float.floatToIntBits(other.confidence)) {
115                        return false;
116                }
117                if (pitch != other.pitch) {
118                        return false;
119                }
120                if (roll != other.roll) {
121                        return false;
122                }
123                if (yaw != other.yaw) {
124                        return false;
125                }
126                return true;
127        }
128}