Exemple #1
0
 public static double[] Array(object convertible)
 {
     if (convertible is double[])
     {
         return(convertible as double[]);
     }
     else if (convertible is DateTime[])
     {
         return((convertible as DateTime[]).Select(t => t.ToOADate()).ToArray());
     }
     else if (convertible is IEnumerable <double> )
     {
         return((convertible as IEnumerable <double>).ToArray());
     }
     else if (convertible is IEnumerable <DateTime> )
     {
         return((convertible as IEnumerable <DateTime>).Select(t => t.ToOADate()).ToArray());
     }
     else if ((convertible is IEnumerable <object>) || (convertible is IEnumerable))
     {
         System.Array array = GeneralArray.ToDoubleArray(convertible);
         if (array.Rank == 1)
         {
             return(array as double[]);
         }
         else
         {
             throw new Exception("Array must be one dimensional.");
         }
     }
     else
     {
         throw new Exception("Unknown array type.");
     }
 }
Exemple #2
0
        public FalseColourImage(IEnumerable <object> underlyingData)
        {
            Array array = GeneralArray.ToDoubleArray(underlyingData);

            this.underlyingData = ((double[, ])array).ArrayEnumerator(EnumerationOrder2D.ColumnMajor);
            width  = array.GetLength(0);
            height = array.GetLength(1);
            Initialize(true);
        }
Exemple #3
0
        /// <summary>
        /// Create an enumerator suitable for constructing images (i.e. travels along the first dimension,
        /// then the second). If not 2D, first element is null.
        /// </summary>
        /// <param name="enumerable"></param>
        /// <returns></returns>
        public static IEnumerable <double> ToImageEnumerator(IEnumerable <object> enumerable, out int xLength, out int yLength)
        {
            int[] dimensions = GeneralArray.GetDimensions(enumerable);
            xLength = dimensions[0];
            yLength = 0;
            if (dimensions.Length > 2)
            {
                return(null);
            }

            // If this is a list of lists, then create enumerator, otherwise convert to a rectangular array first.
            // This gives better performance if not indexable or if this is a Numpy array.

            Type arrayType = enumerable.GetType();

            if (dimensions.Length == 2 && arrayType.Name != "ndarray" && IsIListOfILists(enumerable))
            {
                List <int> dimensionList = new List <int>();
                IList      parent = enumerable as IList;
                int        minLength = int.MaxValue; int maxLength = int.MinValue;
                int        count = parent.FastCount();

                for (int i = 0; i < count; ++i)
                {
                    IList child = parent[i] as IList;
                    if (child == null)
                    {
                        minLength = 0;
                    }
                    else
                    {
                        minLength = Math.Min(minLength, child.Count);
                        maxLength = Math.Max(maxLength, child.Count);
                    }
                }
                yLength = maxLength;
                if (minLength == 0)
                {
                    return(null);
                }
                else
                {
                    return(Jagged2DImageEnumerable(parent, minLength, maxLength));
                }
            }
            else if (dimensions.Length == 1)
            {
                return(Enumerable1D(enumerable));
            }
            else
            {
                double[,] array = (double[, ])GeneralArray.ToDoubleArray(enumerable);
                yLength         = dimensions[1];
                return(array.ArrayEnumerator(EnumerationOrder2D.ColumnMajor));
            }
        }
Exemple #4
0
        internal FalseColourImage(Rect bounds, IEnumerable <object> underlyingData, bool newColourBar)
        {
            Array array = GeneralArray.ToDoubleArray(underlyingData);

            this.underlyingData = ((double[, ])array).ArrayEnumerator(EnumerationOrder2D.ColumnMajor);
            width  = array.GetLength(0);
            height = array.GetLength(1);
            Initialize(newColourBar);
            Bounds = bounds;
        }