001package org.opencv.core;
002
003import java.util.Arrays;
004import java.util.List;
005
006import org.opencv.core.RotatedRect;
007
008
009
010public class MatOfRotatedRect extends Mat {
011    // 32FC5
012    private static final int _depth = CvType.CV_32F;
013    private static final int _channels = 5;
014
015    public MatOfRotatedRect() {
016        super();
017    }
018
019    protected MatOfRotatedRect(long addr) {
020        super(addr);
021        if( !empty() && checkVector(_channels, _depth) < 0 )
022            throw new IllegalArgumentException("Incompatible Mat");
023        //FIXME: do we need release() here?
024    }
025
026    public static MatOfRotatedRect fromNativeAddr(long addr) {
027        return new MatOfRotatedRect(addr);
028    }
029
030    public MatOfRotatedRect(Mat m) {
031        super(m, Range.all());
032        if( !empty() && checkVector(_channels, _depth) < 0 )
033            throw new IllegalArgumentException("Incompatible Mat");
034        //FIXME: do we need release() here?
035    }
036
037    public MatOfRotatedRect(RotatedRect...a) {
038        super();
039        fromArray(a);
040    }
041
042    public void alloc(int elemNumber) {
043        if(elemNumber>0)
044            super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
045    }
046
047    public void fromArray(RotatedRect...a) {
048        if(a==null || a.length==0)
049            return;
050        int num = a.length;
051        alloc(num);
052        float buff[] = new float[num * _channels];
053        for(int i=0; i<num; i++) {
054            RotatedRect r = a[i];
055            buff[_channels*i+0] = (float) r.center.x;
056            buff[_channels*i+1] = (float) r.center.y;
057            buff[_channels*i+2] = (float) r.size.width;
058            buff[_channels*i+3] = (float) r.size.height;
059            buff[_channels*i+4] = (float) r.angle;
060        }
061        put(0, 0, buff); //TODO: check ret val!
062    }
063
064    public RotatedRect[] toArray() {
065        int num = (int) total();
066        RotatedRect[] a = new RotatedRect[num];
067        if(num == 0)
068            return a;
069        float buff[] = new float[_channels];
070        for(int i=0; i<num; i++) {
071            get(i, 0, buff); //TODO: check ret val!
072            a[i] = new RotatedRect(new Point(buff[0],buff[1]),new Size(buff[2],buff[3]),buff[4]);
073        }
074        return a;
075    }
076
077    public void fromList(List<RotatedRect> lr) {
078        RotatedRect ap[] = lr.toArray(new RotatedRect[0]);
079        fromArray(ap);
080    }
081
082    public List<RotatedRect> toList() {
083        RotatedRect[] ar = toArray();
084        return Arrays.asList(ar);
085    }
086}