001package org.opencv.core; 002 003import java.util.Arrays; 004import java.util.List; 005 006public class MatOfFloat extends Mat { 007 // 32FC1 008 private static final int _depth = CvType.CV_32F; 009 private static final int _channels = 1; 010 011 public MatOfFloat() { 012 super(); 013 } 014 015 protected MatOfFloat(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 MatOfFloat fromNativeAddr(long addr) { 023 return new MatOfFloat(addr); 024 } 025 026 public MatOfFloat(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 MatOfFloat(float...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(float...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 float[] toArray() { 052 int num = checkVector(_channels, _depth); 053 if(num < 0) 054 throw new RuntimeException("Native Mat has unexpected type or size: " + toString()); 055 float[] a = new float[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<Float> lb) { 063 if(lb==null || lb.size()==0) 064 return; 065 Float ab[] = lb.toArray(new Float[0]); 066 float a[] = new float[ab.length]; 067 for(int i=0; i<ab.length; i++) 068 a[i] = ab[i]; 069 fromArray(a); 070 } 071 072 public List<Float> toList() { 073 float[] a = toArray(); 074 Float ab[] = new Float[a.length]; 075 for(int i=0; i<a.length; i++) 076 ab[i] = a[i]; 077 return Arrays.asList(ab); 078 } 079}