示例#1
0
        public Matrix(Array2DBase array)
        {
            if (array == null)
            {
                throw new ArgumentNullException(nameof(array));
            }

            array.ThrowIfDisposed();

            if (!TryParse(typeof(TElement), out var type))
            {
                throw new NotSupportedException($"{typeof(TElement).Name} does not support");
            }

            this._MatrixElementTypes = type;
            this._ElementType        = type.ToNativeMatrixElementType();
            var ret = NativeMethods.mat_matrix(array.ImageType.ToNativeArray2DType(),
                                               array.NativePtr,
                                               0,
                                               0,
                                               this._ElementType,
                                               out var ptr);

            switch (ret)
            {
            case ErrorType.MatrixElementTypeNotSupport:
                throw new ArgumentException($"{array.ImageType} can not convert to {type}.");
            }

            this.NativePtr = ptr;
            this._Indexer  = this.CreateIndexer(type);
        }
示例#2
0
        public Matrix()
        {
            if (!TryParse(typeof(TElement), out var type))
            {
                throw new NotSupportedException($"{typeof(TElement).Name} does not support");
            }

            this._MatrixElementTypes = type;
            this._ElementType        = type.ToNativeMatrixElementType();
            this.NativePtr           = NativeMethods.matrix_new(this._ElementType);

            this._Indexer = this.CreateIndexer(type);
        }
示例#3
0
文件: SurfPoint.cs 项目: TrojanOlx/AI
            internal SurfPointMatrix(IntPtr ptr, bool isEnableDispose)
                : base(ptr, 0, 0, isEnableDispose)
            {
                if (!SupportMatrixTypes.TryGetValue(typeof(T), out var matrixType))
                {
                    throw new NotSupportedException($"{typeof(T).Name} does not support");
                }

                this._MatrixElementType = matrixType.ToNativeMatrixElementType();

                this.NativePtr         = ptr;
                this.MatrixElementType = matrixType;
            }
示例#4
0
        public Matrix(byte[] array, int row, int column, int elementSize)
        {
            if (array == null)
            {
                throw new ArgumentNullException(nameof(array));
            }
            if (row < 0)
            {
                throw new ArgumentOutOfRangeException($"{nameof(row)}", $"{nameof(row)} should be positive value.");
            }
            if (column < 0)
            {
                throw new ArgumentOutOfRangeException($"{nameof(column)}", $"{nameof(column)} should be positive value.");
            }
            if (column < 1)
            {
                throw new ArgumentOutOfRangeException($"{nameof(elementSize)} should be more than 1");
            }
            if (array.Length != row * column * elementSize)
            {
                throw new ArgumentOutOfRangeException($"{nameof(array)}.Length should equalt to {nameof(column)}x{nameof(column)}*{nameof(elementSize)}.");
            }

            if (!TryParse(typeof(TElement), out var type))
            {
                throw new NotSupportedException($"{typeof(TElement).Name} does not support");
            }

            this._MatrixElementTypes = type;
            this._ElementType        = type.ToNativeMatrixElementType();

            var size = ElementSizeDictionary[this._ElementType];

            if (size != elementSize)
            {
                throw new ArgumentOutOfRangeException($"The size of {typeof(TElement).Name} does not equalt to {nameof(elementSize)}.");
            }

            unsafe
            {
                fixed(byte *src = &array[0])
                this.NativePtr = NativeMethods.matrix_new3(this._ElementType, row, column, src);
            }

            this._Indexer = this.CreateIndexer(type);
        }
示例#5
0
        internal Matrix(IntPtr ptr, int templateRows = 0, int templateColumns = 0, bool isEnabledDispose = true)
            : base(templateRows, templateColumns, isEnabledDispose)
        {
            if (ptr == IntPtr.Zero)
            {
                throw new ArgumentException("Can not pass IntPtr.Zero", nameof(ptr));
            }

            if (!TryParse(typeof(TElement), out var type))
            {
                throw new NotSupportedException($"{typeof(TElement).Name} does not support");
            }

            this.NativePtr           = ptr;
            this._MatrixElementTypes = type;
            this._ElementType        = type.ToNativeMatrixElementType();

            this._Indexer = this.CreateIndexer(type);
        }
示例#6
0
        public Matrix(int row, int column)
        {
            if (!TryParse(typeof(TElement), out var type))
            {
                throw new NotSupportedException($"{typeof(TElement).Name} does not support");
            }
            if (row < 0)
            {
                throw new ArgumentOutOfRangeException($"{nameof(row)}", $"{nameof(row)} should be positive value.");
            }
            if (column < 0)
            {
                throw new ArgumentOutOfRangeException($"{nameof(column)}", $"{nameof(column)} should be positive value.");
            }

            this._MatrixElementTypes = type;
            this._ElementType        = type.ToNativeMatrixElementType();
            this.NativePtr           = NativeMethods.matrix_new1(this._ElementType, row, column);

            this._Indexer = this.CreateIndexer(type);
        }
示例#7
0
        public Matrix(TElement[] array, int row, int column)
        {
            if (array == null)
            {
                throw new ArgumentNullException(nameof(array));
            }
            if (row < 0)
            {
                throw new ArgumentOutOfRangeException($"{nameof(row)}", $"{nameof(row)} should be positive value.");
            }
            if (column < 0)
            {
                throw new ArgumentOutOfRangeException($"{nameof(column)}", $"{nameof(column)} should be positive value.");
            }
            if (array.Length != row * column)
            {
                throw new ArgumentOutOfRangeException($"{nameof(array)}.Length should equalt to {nameof(column)}x{nameof(column)}.");
            }

            if (!TryParse(typeof(TElement), out var type))
            {
                throw new NotSupportedException($"{typeof(TElement).Name} does not support");
            }

            this._MatrixElementTypes = type;
            this._ElementType        = type.ToNativeMatrixElementType();

            unsafe
            {
                switch (this._ElementType)
                {
                case NativeMethods.MatrixElementType.UInt8:
                {
                    var tmp = array as byte[];

                    fixed(byte *src = &tmp[0])
                    this.NativePtr = NativeMethods.matrix_new2(this._ElementType, row, column, (IntPtr)src);
                }
                break;

                case NativeMethods.MatrixElementType.UInt16:
                {
                    var tmp = array as ushort[];

                    fixed(ushort *src = &tmp[0])
                    this.NativePtr = NativeMethods.matrix_new2(this._ElementType, row, column, (IntPtr)src);
                }
                break;

                case NativeMethods.MatrixElementType.UInt32:
                {
                    var tmp = array as uint[];

                    fixed(uint *src = &tmp[0])
                    this.NativePtr = NativeMethods.matrix_new2(this._ElementType, row, column, (IntPtr)src);
                }
                break;

                case NativeMethods.MatrixElementType.Int8:
                {
                    var tmp = array as sbyte[];

                    fixed(sbyte *src = &tmp[0])
                    this.NativePtr = NativeMethods.matrix_new2(this._ElementType, row, column, (IntPtr)src);
                }
                break;

                case NativeMethods.MatrixElementType.Int16:
                {
                    var tmp = array as short[];

                    fixed(short *src = &tmp[0])
                    this.NativePtr = NativeMethods.matrix_new2(this._ElementType, row, column, (IntPtr)src);
                }
                break;

                case NativeMethods.MatrixElementType.Int32:
                {
                    var tmp = array as int[];

                    fixed(int *src = &tmp[0])
                    this.NativePtr = NativeMethods.matrix_new2(this._ElementType, row, column, (IntPtr)src);
                }
                break;

                case NativeMethods.MatrixElementType.Float:
                {
                    var tmp = array as float[];

                    fixed(float *src = &tmp[0])
                    this.NativePtr = NativeMethods.matrix_new2(this._ElementType, row, column, (IntPtr)src);
                }
                break;

                case NativeMethods.MatrixElementType.Double:
                {
                    var tmp = array as double[];

                    fixed(double *src = &tmp[0])
                    this.NativePtr = NativeMethods.matrix_new2(this._ElementType, row, column, (IntPtr)src);
                }
                break;

                case NativeMethods.MatrixElementType.RgbPixel:
                {
                    var tmp = array as RgbPixel[];

                    fixed(RgbPixel *src = &tmp[0])
                    this.NativePtr = NativeMethods.matrix_new2(this._ElementType, row, column, (IntPtr)src);
                }
                break;

                case NativeMethods.MatrixElementType.RgbAlphaPixel:
                {
                    var tmp = array as RgbAlphaPixel[];

                    fixed(RgbAlphaPixel *src = &tmp[0])
                    this.NativePtr = NativeMethods.matrix_new2(this._ElementType, row, column, (IntPtr)src);
                }
                break;

                case NativeMethods.MatrixElementType.HsiPixel:
                {
                    var tmp = array as HsiPixel[];

                    fixed(HsiPixel *src = &tmp[0])
                    this.NativePtr = NativeMethods.matrix_new2(this._ElementType, row, column, (IntPtr)src);
                }
                break;
                }
            }

            this._Indexer = this.CreateIndexer(type);
        }
示例#8
0
 private void PushBackMatrixItem(MatrixElementType type, IDlibObject item)
 {
     item.ThrowIfDisposed();
     NativeMethods.array_matrix_pushback(type, this.NativePtr, item.NativePtr);
 }