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