001    /*----------------------------------------------------------------------------*/
002    /* Copyright (c) FIRST 2008-2012. All Rights Reserved.                        */
003    /* Open Source Software - may be modified and shared by FRC teams. The code   */
004    /* must be accompanied by the FIRST BSD license file in the root directory of */
005    /* the project.                                                               */
006    /*----------------------------------------------------------------------------*/
007    
008    package edu.wpi.first.wpilibj.image;
009    
010    import com.sun.cldc.jna.Pointer;
011    import com.sun.cldc.jna.Structure;
012    
013    /**
014     *
015     * @author dtjones
016     */
017    public class EllipseMatch {
018    
019        static final int ellipseMatchSize = 40;
020        public double m_xPos;
021        public double m_yPos;
022        public double m_rotation;
023        public double m_majorRadius;
024        public double m_minorRadius;
025        public double m_score;
026    
027        private class EllipseMatchStructure extends Structure {
028    
029            public EllipseMatchStructure(int address) {
030                useMemory(new Pointer(address, ellipseMatchSize));
031                read();
032            }
033    
034            public void read() {
035                m_xPos = backingNativeMemory.getFloat(0);
036                m_yPos = backingNativeMemory.getFloat(4);
037                m_rotation = backingNativeMemory.getDouble(8);
038                m_majorRadius = backingNativeMemory.getDouble(16);
039                m_minorRadius = backingNativeMemory.getDouble(24);
040                m_score = backingNativeMemory.getDouble(32);
041    
042            }
043    
044            public void write() {
045            }
046    
047            public int size() {
048                return ellipseMatchSize;
049            }
050        }
051    
052        EllipseMatch(int address) {
053            new EllipseMatchStructure(address);
054        }
055    
056        public String toString() {
057            return "Ellipse Match:\n" +
058                    "  Pos x: " + m_xPos + "  y: " + m_yPos + "\n" +
059                    "  Radius major: " + m_majorRadius + " minor: " + m_minorRadius + "\n" +
060                    "  Rotation: " + m_rotation + " Score: " + m_score + "\n";
061        }
062    
063        protected static EllipseMatch[] getMatchesFromMemory(int address, int number) {
064            if (address == 0) {
065                return new EllipseMatch[0];
066            }
067    
068            EllipseMatch[] toReturn = new EllipseMatch[number];
069            for (int i = 0; i < number; i++) {
070                toReturn[i] = new EllipseMatch(address + i * ellipseMatchSize);
071            }
072            return toReturn;
073        }
074    }