private bool isSorted(ILArray <double> input, int dim, bool descending)
        {
            if (input.IsEmpty || input.IsScalar)
            {
                return(true);
            }
            ILIterator <double> it = input.CreateIterator(ILIteratorPositions.ILStart, dim);
            double tmpold          = it.Value;
            double tmpnew          = it.Increment();
            int    dimpos          = 1;

            while (!it.IsAtStart())
            {
                if (++dimpos % input.Dimensions[dim] != 1)
                {
                    if (descending)
                    {
                        if (tmpnew > tmpold)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (tmpnew < tmpold)
                        {
                            return(false);
                        }
                    }
                }
                tmpold = tmpnew;
                tmpnew = it.Increment();
            }
            return(true);
        }
Exemple #2
0
        public static BitmapSource ILArrayToBitmapSource(ILArray <double> surface)
        {
            // Define parameters used to create the BitmapSource.
            PixelFormat pf        = PixelFormats.Bgr32;
            int         width     = surface.Dimensions[0];
            int         height    = surface.Dimensions[1];
            int         bytes     = (pf.BitsPerPixel + 7) / 8;
            int         rawStride = (width * bytes);

            byte[]    rawImage  = new byte[rawStride * height];
            int       index     = 0;
            ColourMap ColourMap = new ColourMap(ColourMapType.Jet, 256);

            byte[,] cmap = ColourMap.ToByteArray();
            double           range     = surface.MaxValue - surface.MinValue;
            double           min       = surface.MinValue;
            int              magnitude = 0;
            ILArray <int>    scaled    = (ILArray <int>)ILMath.convert(NumericType.Int32, ILMath.floor((surface - min) * 256.0 / range));
            ILIterator <int> iterator  = scaled.CreateIterator();
            Stopwatch        sw        = Stopwatch.StartNew();

            sw.Reset();
            sw.Start();
            magnitude = iterator.Value;
            for (int y = 0; y < height; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    if (magnitude == 256)
                    {
                        magnitude = 255;
                    }
                    rawImage[index]     = cmap[magnitude, 3];
                    rawImage[index + 1] = cmap[magnitude, 2];
                    rawImage[index + 2] = cmap[magnitude, 1];
                    rawImage[index + 3] = cmap[magnitude, 0];
                    index    += bytes;
                    magnitude = iterator.Increment();
                }
            }
            sw.Stop();
            string result;

            result = "Elapsed time: " + sw.ElapsedMilliseconds.ToString() + " ms";
            // Create a BitmapSource.
            BitmapSource bitmap = BitmapSource.Create(width, height,
                                                      96, 96, pf, null,
                                                      rawImage, rawStride);

            return(bitmap);
        }
Exemple #3
0
// DO NOT EDIT INSIDE THIS REGION !! CHANGES WILL BE LOST !!
        /// <summary>
        /// real part of complex array
        /// </summary>
        /// <param name="X">complex input array</param>
        /// <returns>real part of complex array</returns>
        public static ILArray <float> real(ILArray <fcomplex> X)
        {
            int nrX = X.m_dimensions.NumberOfElements;

            float []              retArr = new  float [nrX];
            ILArray <float>       ret    = new  ILArray <float> (retArr, X.m_dimensions);
            ILIterator <fcomplex> it     = X.CreateIterator(ILIteratorPositions.ILEnd, 0);

            for (int i = 0; i < nrX; i++)
            {
                retArr[i] = it.Increment().real;
            }
            return(ret);
        }
Exemple #4
0
        /// <summary>
        /// real part of complex array
        /// </summary>
        /// <param name="X">complex input array</param>
        /// <returns>real part of complex array</returns>
        public static /*!HC:outCls1*/ ILArray <double> real(/*!HC:inCls1*/ ILArray <complex> X)
        {
            int nrX = X.m_dimensions.NumberOfElements;

            /*!HC:outArr1*/ double []           retArr = new /*!HC:outArr1*/ double [nrX];
            /*!HC:outCls1*/ ILArray <double>    ret    = new /*!HC:outCls1*/ ILArray <double> (retArr, X.m_dimensions);
            ILIterator </*!HC:inArr1*/ complex> it     = X.CreateIterator(ILIteratorPositions.ILEnd, 0);

            for (int i = 0; i < nrX; i++)
            {
                retArr[i] = it.Increment().real;
            }
            return(ret);
        }
Exemple #5
0
        public static BitmapSource ILArrayToBitmapSourceReversed(ILArray <double> surface, ColourMap colourMap)
        {
            // Define parameters used to create the BitmapSource.
            PixelFormat pf        = PixelFormats.Bgr32;
            int         width     = surface.Dimensions[0];
            int         height    = surface.Dimensions[1];
            int         bytes     = (pf.BitsPerPixel + 7) / 8;
            int         rawStride = (width * bytes);

            byte[] rawImage = new byte[rawStride * height];
            int    index    = 0;

            byte[,] cmap = colourMap.ToByteArray();
            int              colourMapLength = colourMap.Length;
            double           range           = surface.MaxValue - surface.MinValue;
            double           min             = surface.MinValue;
            int              magnitude       = 0;
            ILArray <int>    scaled          = (ILArray <int>)ILMath.convert(NumericType.Int32, ILMath.floor((surface - min) * (double)(colourMapLength - 1) / range));
            ILIterator <int> iterator        = scaled.CreateIterator();

            magnitude = iterator.Value;
            for (int y = height - 1; y >= 0; --y)
            {
                index = y * rawStride;
                for (int x = 0; x < width; ++x)
                {
                    rawImage[index]     = cmap[magnitude, 3];
                    rawImage[index + 1] = cmap[magnitude, 2];
                    rawImage[index + 2] = cmap[magnitude, 1];
                    rawImage[index + 3] = cmap[magnitude, 0];
                    index    += bytes;
                    magnitude = iterator.Increment();
                }
            }
            // Create a BitmapSource.
            BitmapSource bitmap = BitmapSource.Create(width, height,
                                                      96, 96, pf, null,
                                                      rawImage, rawStride);

            return(bitmap);
        }
Exemple #6
0
        /// <summary>
        /// operate on elements of both storages by the given function -> relational operations
        /// </summary>
        /// <param name="inArray1">First storage array</param>
        /// <param name="inArray2">Second storage array</param>
        /// <param name="operation">operation to apply to the elements of inArray. This
        /// acts like a function pointer.</param>
        /// <returns>new ILLogicalArray with result of operation for corresponding
        /// elements of both arrays.</returns>
        /// <remarks>The values of inArray2 nor inArray2 will not be altered.The dimensions
        /// of both arrays must match.</remarks>
        private static ILArray <double> DoubleBinaryDoubleOperator(ILArray <double> inArray1, ILArray <double> inArray2,
                                                                   ILApplyDouble_DoubleDouble operation)
        {
            ILDimension inDim = inArray1.Dimensions;

            if (!inDim.IsSameSize(inArray2.Dimensions))
            {
                throw new Exception("Array dimensions must match.");
            }
            double[] retBoolArr;
            // build ILDimension
            int newLength = inDim.NumberOfElements;

            retBoolArr = new double[newLength];
            int leadDim    = 0;
            int leadDimLen = inDim[0];

            if (inArray1.IsReference || inArray2.IsReference)
            {
                // this will most probably be not very fast, but .... :|
                #region Reference storage
                // walk along the longest dimension (for performance reasons)
                for (int i = 1; i < inDim.NumberOfDimensions; i++)
                {
                    if (leadDimLen < inDim[i])
                    {
                        leadDimLen = inDim[i];
                        leadDim    = i;
                    }
                }
                ILIterator <double> it1 = inArray1.CreateIterator(ILIteratorPositions.ILEnd, leadDim);
                ILIterator <double> it2 = inArray2.CreateIterator(ILIteratorPositions.ILEnd, leadDim);
                unsafe
                {
                    fixed(double *pOutArr = retBoolArr)
                    {
                        double *poutarr = pOutArr;
                        double *outEnd  = poutarr + newLength;

                        while (poutarr < outEnd)
                        {
                            *poutarr++ = operation(it1.Increment(), it2.Increment());
                        }
                    }
                }
                // ==============================================================
                #endregion
            }
            else
            {
                // physical -> pointer arithmetic
                #region physical storage
                unsafe
                {
                    fixed(double *pInArr1 = inArray1.m_data,
                          pInArr2         = inArray2.m_data)
                    {
                        fixed(double *pOutArr = retBoolArr)
                        {
                            double *poutarr = pOutArr;
                            double *poutend = poutarr + newLength;
                            double *pIn1    = pInArr1;
                            double *pIn2    = pInArr2;

                            while (poutarr < poutend)
                            {
                                *poutarr++ = operation(*pIn1++, *pIn2++);
                            }
                        }
                    }
                }
                #endregion
            }
            return(new ILArray <double>(retBoolArr, inDim.ToIntArray()));
        }