~paparazzi-uav/paparazzi/v5.0-manual

« back to all changes in this revision

Viewing changes to sw/ext/opencv_bebop/opencv/modules/core/misc/java/src/java/core+MatOfPoint3f.java

  • Committer: Paparazzi buildbot
  • Date: 2016-05-18 15:00:29 UTC
  • Revision ID: felix.ruess+docbot@gmail.com-20160518150029-e8lgzi5kvb4p7un9
Manual import commit 4b8bbb730080dac23cf816b98908dacfabe2a8ec from v5.0 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.opencv.core;
 
2
 
 
3
import java.util.Arrays;
 
4
import java.util.List;
 
5
 
 
6
public class MatOfPoint3f extends Mat {
 
7
    // 32FC3
 
8
    private static final int _depth = CvType.CV_32F;
 
9
    private static final int _channels = 3;
 
10
 
 
11
    public MatOfPoint3f() {
 
12
        super();
 
13
    }
 
14
 
 
15
    protected MatOfPoint3f(long addr) {
 
16
        super(addr);
 
17
        if( !empty() && checkVector(_channels, _depth) < 0 )
 
18
            throw new IllegalArgumentException("Incompatible Mat");
 
19
        //FIXME: do we need release() here?
 
20
    }
 
21
 
 
22
    public static MatOfPoint3f fromNativeAddr(long addr) {
 
23
        return new MatOfPoint3f(addr);
 
24
    }
 
25
 
 
26
    public MatOfPoint3f(Mat m) {
 
27
        super(m, Range.all());
 
28
        if( !empty() && checkVector(_channels, _depth) < 0 )
 
29
            throw new IllegalArgumentException("Incompatible Mat");
 
30
        //FIXME: do we need release() here?
 
31
    }
 
32
 
 
33
    public MatOfPoint3f(Point3...a) {
 
34
        super();
 
35
        fromArray(a);
 
36
    }
 
37
 
 
38
    public void alloc(int elemNumber) {
 
39
        if(elemNumber>0)
 
40
            super.create(elemNumber, 1, CvType.makeType(_depth, _channels));
 
41
    }
 
42
 
 
43
    public void fromArray(Point3...a) {
 
44
        if(a==null || a.length==0)
 
45
            return;
 
46
        int num = a.length;
 
47
        alloc(num);
 
48
        float buff[] = new float[num * _channels];
 
49
        for(int i=0; i<num; i++) {
 
50
            Point3 p = a[i];
 
51
            buff[_channels*i+0] = (float) p.x;
 
52
            buff[_channels*i+1] = (float) p.y;
 
53
            buff[_channels*i+2] = (float) p.z;
 
54
        }
 
55
        put(0, 0, buff); //TODO: check ret val!
 
56
    }
 
57
 
 
58
    public Point3[] toArray() {
 
59
        int num = (int) total();
 
60
        Point3[] ap = new Point3[num];
 
61
        if(num == 0)
 
62
            return ap;
 
63
        float buff[] = new float[num * _channels];
 
64
        get(0, 0, buff); //TODO: check ret val!
 
65
        for(int i=0; i<num; i++)
 
66
            ap[i] = new Point3(buff[i*_channels], buff[i*_channels+1], buff[i*_channels+2]);
 
67
        return ap;
 
68
    }
 
69
 
 
70
    public void fromList(List<Point3> lp) {
 
71
        Point3 ap[] = lp.toArray(new Point3[0]);
 
72
        fromArray(ap);
 
73
    }
 
74
 
 
75
    public List<Point3> toList() {
 
76
        Point3[] ap = toArray();
 
77
        return Arrays.asList(ap);
 
78
    }
 
79
}