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