001package org.opencv.core; 002 003import java.util.Arrays; 004import java.util.List; 005 006public class MatOfDouble extends Mat { 007 // 64FC(x) 008 private static final int _depth = CvType.CV_64F; 009 private static final int _channels = 1; 010 011 public MatOfDouble() { 012 super(); 013 } 014 015 protected MatOfDouble(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 MatOfDouble fromNativeAddr(long addr) { 023 return new MatOfDouble(addr); 024 } 025 026 public MatOfDouble(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 MatOfDouble(double...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(double...a) { 044 if(a==null || a.length==0) 045 return; 046 int num = a.length / _channels; 047 alloc(num); 048 put(0, 0, a); //TODO: check ret val! 049 } 050 051 public double[] toArray() { 052 int num = checkVector(_channels, _depth); 053 if(num < 0) 054 throw new RuntimeException("Native Mat has unexpected type or size: " + toString()); 055 double[] a = new double[num * _channels]; 056 if(num == 0) 057 return a; 058 get(0, 0, a); //TODO: check ret val! 059 return a; 060 } 061 062 public void fromList(List<Double> lb) { 063 if(lb==null || lb.size()==0) 064 return; 065 Double ab[] = lb.toArray(new Double[0]); 066 double a[] = new double[ab.length]; 067 for(int i=0; i<ab.length; i++) 068 a[i] = ab[i]; 069 fromArray(a); 070 } 071 072 public List<Double> toList() { 073 double[] a = toArray(); 074 Double ab[] = new Double[a.length]; 075 for(int i=0; i<a.length; i++) 076 ab[i] = a[i]; 077 return Arrays.asList(ab); 078 } 079}