public void SetImageArray(object imageArray, int imageWidth, int imageHeight, SensorType sensorType)
        {
            this.imageArray = imageArray;
            this.imageWidth = imageWidth;
            this.imageHeight = imageHeight;
            this.sensorType = sensorType;

            objPixelArray = null;
            intPixelArray = null;
            intColourPixelArray = null;
            objColourPixelArray = null;

            if (sensorType == SensorType.Monochrome)
            {
                if (imageArray is int[,])
                {
                    intPixelArray = (int[,])imageArray;
                    isColumnMajor = intPixelArray.GetLength(0) == imageWidth;
                    isRowMajor = intPixelArray.GetLength(0) == imageHeight;
                    return;
                }
                else if (imageArray is object[,])
                {
                    objPixelArray = (object[,])imageArray;
                    isColumnMajor = objPixelArray.GetLength(0) == imageWidth;
                    isRowMajor = objPixelArray.GetLength(0) == imageHeight;
                    return;
                }
            }
            else
            {
                // Color sensor type is represented as 3-dimentional array that can be either: [3, height, width], [width, height, 3]
                if (imageArray is int[, ,])
                {
                    intColourPixelArray = (int[, ,])imageArray;
                    isColumnMajor = intColourPixelArray.GetLength(0) == imageWidth;
                    isRowMajor = intColourPixelArray.GetLength(0) == 3;
                    return;
                }
                else if (imageArray is object[, ,])
                {
                    objColourPixelArray = (object[, ,])imageArray;
                    isColumnMajor = objColourPixelArray.GetLength(0) == imageWidth;
                    isRowMajor = objColourPixelArray.GetLength(0) == 3;
                    return;
                }
            }

            throw new ArgumentException();
        }
Beispiel #2
0
 //Task 1.8 No Positive
 static void Array3DElementsToNull()
 {
     int[,,] array = Generate3DArray(2);
     Console.WriteLine("Task 1.8\nИзначальный массив:");
     Out3DArray(array);
     for (int i = 0; i < array.GetLength(0); i++)
     {
         for (int j = 0; j < array.GetLength(1); j++)
         {
             for (int k = 0; k < array.GetLength(2); k++)
             {
                 if (array[i, j, k] > 0)
                 {
                     array[i, j, k] = 0;
                 }
             }
         }
     }
     Console.WriteLine("\nМассив после обнуления положительных значений:");
     Out3DArray(array);
 }
Beispiel #3
0
        /// <summary>
        /// A function to calculate the Revenue
        /// </summary>
        /// <param name="Sij_t">An n by m matrix for time t. This is the sales
        ///     of item i in store j at time t.
        /// </param>
        /// <param name="pri">This is the market price of item i</param>
        /// <returns></returns>
        private static double CalcRev(int[,,] Sijt, double[] pri)
        {
            int n_items      = Sijt.GetLength(0);
            int m_stores     = Sijt.GetLength(1);
            int t_timebucket = Sijt.GetLength(2);

            double rev = 0;

            for (int t = 0; t < t_timebucket; t++)
            {
                for (int i = 0; i < n_items; i++)
                {
                    for (int j = 0; j < m_stores; j++)
                    {
                        rev = rev + Sijt[i, j, t] * pri[i];
                    }
                }
            }

            return(rev);
        }
        private static int FindSlicesByHeight(int[,,] cube, int sum)
        {
            long sliceSum       = 0;
            int  numberOfSlices = 0;

            for (int h = 0; h < cube.GetLength(1) - 1; h++)
            {
                for (int w = 0; w < cube.GetLength(0); w++)
                {
                    for (int d = 0; d < cube.GetLength(2); d++)
                    {
                        sliceSum += cube[w, h, d];
                    }
                }
                if (sliceSum == sum / 2)
                {
                    numberOfSlices++;
                }
            }
            return(numberOfSlices);
        }
Beispiel #5
0
 internal static void ReplacePositiveThreeDimensional(int[,,] array)
 {
     // For each index of the first dimension.
     for (int i = 0; i < array.GetLength(0); i++)
     {
         // For each index of the second dimension.
         for (int j = 0; j < array.GetLength(1); j++)
         {
             // For each index of the third dimension.
             for (int k = 0; k < array.GetLength(2); k++)
             {
                 if (array[i, j, k] > 0)
                 {
                     // Assign positive element to 0.
                     array[i, j, k] = 0;
                 }
             }
         }
     }
     Console.WriteLine("Modification has been completed.");
 }
Beispiel #6
0
        /// <summary>
        /// A function to calculate the purchase costs
        /// </summary>
        /// <param name="cu"></param>
        /// <param name="Qijt"></param>
        /// <returns></returns>
        private static double CalcPurchaseCost(double[] cu, int[,,] Qijt)
        {
            int n_items       = Qijt.GetLength(0);
            int m_stores      = Qijt.GetLength(1);
            int t_timebuckets = Qijt.GetLength(2);

            double totalPurchaseCost = 0;

            for (int i = 0; i < n_items; i++)
            {
                for (int j = 0; j < m_stores; j++)
                {
                    for (int t = 0; t < t_timebuckets; t++)
                    {
                        totalPurchaseCost += cu[i] * Qijt[i, j, t];
                    }
                }
            }

            return(totalPurchaseCost);
        }
Beispiel #7
0
 private static void noPositive(int[,,] arr)
 {
     for (int i = 0; i < arr.GetLength(0); i++)
     {
         Console.Write("Массив №{0}: ", i);
         for (int j = 0; j < arr.GetLength(1); j++)
         {
             for (int z = 0; z < arr.GetLength(2); z++)
             {
                 if (arr[i, j, z] < 0)
                 {
                     arr[i, j, z] = 0;
                 }
                 Console.Write(arr[i, j, z]);
                 Console.Write(", ");
             }
             Console.WriteLine();
         }
         Console.WriteLine();
     }
 }
Beispiel #8
0
            static int[,,] BubleSort(int[,,] a)
            {
                int s;

                for (int i = 0; i < a.GetLength(0) - 1; i++)
                {
                    for (int k = 0; k < a.GetLength(1) - 1; k++)
                    {
                        for (int n = 0; n < a.GetLength(2) - 1; n++)
                        {
                            if (a[i, k, n] > a[i, k, n + 1])
                            {
                                s = a[i, k, n + 1];
                                a[i, k, n + 1] = a[i, k, n];
                                a[i, k, n]     = s;
                            }
                        }
                    }
                }
                return(a);
            }
Beispiel #9
0
        private int[] CalPixelNum(int[,,] data)
        {
            int[] tmpArr = new int[256];

            //重置為0
            for (int i = 0; i < tmpArr.Length; i++)
            {
                tmpArr[i] = 0;
            }

            //計算每個色階出現的次數
            for (int i = 0; i < data.GetLength(1); i++)
            {
                for (int j = 0; j < data.GetLength(2); j++)
                {
                    tmpArr[data[0, i, j]] += 1;
                }
            }

            return(tmpArr);
        }
Beispiel #10
0
 //parse to 255 & 0
 private void ParseToZero(int[,,] data)
 {
     for (int j = 0; j < data.GetLength(1); j++)
     {
         for (int k = 0; k < data.GetLength(2); k++)
         {
             if (data[0, j, k] < 128)
             {
                 data[0, j, k] = 0;
                 data[1, j, k] = 0;
                 data[2, j, k] = 0;
             }
             else
             {
                 data[0, j, k] = 255;
                 data[1, j, k] = 255;
                 data[2, j, k] = 255;
             }
         }
     }
 }
Beispiel #11
0
 static void Task_1_8_NO_POSITIVE()
 {
     int[,,] Array = Create_3D_RandomArray(4, 4, 4, -100, 100);
     Print_3D_Array(Array);
     for (int i = 0; i < Array.GetLength(0); i++)
     {
         for (int j = 0; j < Array.GetLength(1); j++)
         {
             for (int n = 0; n < Array.GetLength(2); n++)
             {
                 if (Array[i, j, n] > 0)
                 {
                     Array[i, j, n] = 0;
                 }
             }
         }
     }
     Console.WriteLine("Все положительные числа заменяем на 0");
     Print_3D_Array(Array);
     Console.ReadLine();
 }
Beispiel #12
0
    private List <IntVector3> GetPointsFromShape(int[,,] slotShape)
    {
        List <IntVector3> slotPoints = new List <IntVector3>();

        for (int x = 0; x < slotShape.GetLength(2); x++)
        {
            for (int y = 0; y < slotShape.GetLength(1); y++)
            {
                for (int z = 0; z < slotShape.GetLength(0); z++)
                {
                    if (slotShape[z, y, x] > 0)
                    {
                        slotPoints.Add(new IntVector3(x, y, z));
                    }
                }
            }
        }


        return(slotPoints);
    }
Beispiel #13
0
        static void OutputArray(int[,,] array)
        {
            for (int i = 0; i < array.GetLength(0); i++)
            {
                int num = i + 1;
                Console.WriteLine("Матрица " + num + ":");

                for (int j = 0; j < array.GetLength(1); j++)
                {
                    for (int k = 0; k < array.GetLength(2); k++)
                    {
                        string str = array[i, j, k].ToString();
                        str = str.PadRight(6);
                        Console.Write(str);
                    }
                    Console.Write(Environment.NewLine);
                }

                Console.Write(Environment.NewLine);
            }
        }
Beispiel #14
0
 public void Draw(Graphics g)
 {
     for (int i = 0; i < ScorePegs.GetLength(0); i++)
     {
         for (int j = 0; j < ScorePegs.GetLength(1); j++)
         {
             for (int k = 0; k < ScorePegs.GetLength(2); k++)
             {
                 if (ScorePegs[i, j, k] == 0)
                 {
                     // draw the empty peg
                     g.DrawEllipse(Pens.Black, (i * TheSpacing) + TheMargin, j * TheSpacing + k * ROWSPACING + YMargin, SCOREPEG, SCOREPEG);
                 }
                 else if (ScorePegs[i, j, k] == 1)
                 {
                     // draw the empty peg
                     g.DrawEllipse(Pens.Black, (i * TheSpacing) + TheMargin, j * TheSpacing + k * ROWSPACING + YMargin, SCOREPEG, SCOREPEG);
                     g.FillEllipse(Brushes.Black, (i * TheSpacing) + TheMargin, j * TheSpacing + k * ROWSPACING + YMargin, SCOREPEG, SCOREPEG);
                 }
                 else if (ScorePegs[i, j, k] == 2)
                 {
                     // draw the empty peg
                     g.FillEllipse(Brushes.White, (i * TheSpacing) + TheMargin, j * TheSpacing + k * ROWSPACING + YMargin, SCOREPEG, SCOREPEG);
                     g.DrawEllipse(Pens.White, (i * TheSpacing) + TheMargin, j * TheSpacing + k * ROWSPACING + YMargin, SCOREPEG, SCOREPEG);
                 }
             }
         }
     }
 }
Beispiel #15
0
    /*
     * public int this[int i, int j, int k]
     * {
     *  get
     *  {
     *      // indexer
     *      return data[i, j, k];
     *  }
     *  set
     *  {
     *      data[i, j, k] = value;
     *  }
     *
     * }
     *
     * public int this[Vector3 idx]
     * {
     *  get
     *  {
     *      // indexer
     *      Triple i = imageToGrid(idx);
     *      return data[i.x, i.y, i.z];
     *  }
     *  set
     *  {
     *      Triple i = imageToGrid(idx);
     *      data[i.x, i.y, i.z] = value;
     *  }
     *
     * }
     */

    /**
     * WARNING: This copies only the reference, not the data array!
     **/
    public Grid3D2 getSubgrid(Vector3 p, int extend)
    {
        Triple  p_grid    = imageToGrid(p);
        Grid3D2 subgrid   = new Grid3D2(new Triple(extend, extend, extend), _cellSize);
        int     centerIdx = (extend - 1) / 2 + 1;

        for (int i = 0; i < extend; i++)
        {
            for (int j = 0; j < extend; j++)
            {
                for (int k = 0; k < extend; k++)
                {
                    int x = (int)p_grid.x + i - (extend - 1) / 2;
                    int y = (int)p_grid.y + j - (extend - 1) / 2;
                    int z = (int)p_grid.z + k - (extend - 1) / 2;
                    if (x >= 0 && x < data.GetLength(0) && y >= 0 && y < data.GetLength(1) && z >= 0 && z < data.GetLength(2))
                    {
                        subgrid.data[i, j, k] = data[x, y, z];
                    }
                    else
                    {
                        subgrid.data[i, j, k] = invalid;
                    }
                }
            }
        }

        return(subgrid);
    }
Beispiel #16
0
    void AssignEdgeNodeX(int x, int y, int z, int[,,] map, float cubeSize)
    {
        Vector3 pos      = new Vector3(x * cubeSize + 0.5f, y * cubeSize, z * cubeSize);
        Node    edgeNode = new Node(pos);

        if (x != map.GetLength(0))
        {
            if (y != map.GetLength(1) && z != map.GetLength(2))
            {
                if (cubes[x, y, z].edgeNodes[0] == null)
                {
                    cubes[x, y, z].edgeNodes[0] = edgeNode;
                }
            }

            if (y != 0 && z != map.GetLength(2))
            {
                if (cubes[x, y - 1, z].edgeNodes[2] == null)
                {
                    cubes[x, y - 1, z].edgeNodes[2] = edgeNode;
                }
            }

            if (z != 0 && y != map.GetLength(1))
            {
                if (cubes[x, y, z - 1].edgeNodes[4] == null)
                {
                    cubes[x, y, z - 1].edgeNodes[4] = edgeNode;
                }
            }

            if (y != 0 && z != 0)
            {
                if (cubes[x, y - 1, z - 1].edgeNodes[6] == null)
                {
                    cubes[x, y - 1, z - 1].edgeNodes[6] = edgeNode;
                }
            }
        }
    }
        public static Bitmap Diff(Bitmap bitmap1, Bitmap bitmap2)
        {
            Bitmap bitOut = new Bitmap(bitmap1.Width, bitmap1.Height);

            if (bitmap1.Size == bitmap2.Size)
            {
                int[,,] colorMap = new int[bitmap1.Width, bitmap1.Height, 3];
                int max = -255, min = 255;

                for (int i = 0; i < bitmap1.Height; i++)
                {
                    for (int j = 0; j < bitmap1.Width; j++)
                    {
                        colorMap[j, i, 0] = bitmap1.GetPixel(j, i).R - bitmap2.GetPixel(j, i).R;
                        colorMap[j, i, 1] = bitmap1.GetPixel(j, i).G - bitmap2.GetPixel(j, i).G;
                        colorMap[j, i, 2] = bitmap1.GetPixel(j, i).B - bitmap2.GetPixel(j, i).B;

                        min = Math.Min(min, colorMap[j, i, 0]);
                        min = Math.Min(min, colorMap[j, i, 1]);
                        min = Math.Min(min, colorMap[j, i, 2]);

                        max = Math.Max(max, colorMap[j, i, 0]);
                        max = Math.Max(max, colorMap[j, i, 1]);
                        max = Math.Max(max, colorMap[j, i, 2]);
                    }
                }
                int[,,] colorMapOut = TupleScale(colorMap, 0, 255, min, max);


                for (int i = 0; i < colorMapOut.GetLength(1); i++)
                {
                    for (int j = 0; j < colorMapOut.GetLength(0); j++)
                    {
                        Color color = Color.FromArgb(255, colorMapOut[j, i, 0], colorMapOut[j, i, 1], colorMapOut[j, i, 2]);
                        bitOut.SetPixel(j, i, color);
                    }
                }
            }
            return(bitOut);
        }
Beispiel #18
0
 public BaseMap(int[,,] inArr)
 {
     layerNow = 0;
     array    = new Square[inArr.GetLength(0), inArr.GetLength(1), inArr.GetLength(2)];
     for (int l = 0; l < inArr.GetLength(0); l++)
     {
         for (int i = 0; i < inArr.GetLength(1); i++)
         {
             for (int j = 0; j < inArr.GetLength(2); j++)
             {
                 if ((inArr[l, i, j] & 8) == 8)
                 {
                     array[l, i, j].aboveWall = true;
                 }
                 if ((inArr[l, i, j] & 4) == 4)
                 {
                     array[l, i, j].belowWall = true;
                 }
                 if ((inArr[l, i, j] & 2) == 2)
                 {
                     array[l, i, j].leftWall = true;
                 }
                 if ((inArr[l, i, j] & 1) == 1)
                 {
                     array[l, i, j].rightWall = true;
                 }
             }
         }
     }
 }
Beispiel #19
0
        private static void getArr(int[,,] arr, Random random)
        {
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    for (int z = 0; z < arr.GetLength(2); z++)
                    {
                        arr[i, j, z] = random.Next(-100, 100);
                    }
                }
            }

            for (int i = 0; i < arr.GetLength(0); i++)
            {
                Console.Write("Массив №{0}: ", i);
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    for (int z = 0; z < arr.GetLength(2); z++)
                    {
                        Console.Write(arr[i, j, z]);
                        Console.Write(", ");
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
        }
Beispiel #20
0
    void AssignEdgeNodeZ(int x, int y, int z, int[,,] map, float cubeSize)
    {
        Vector3 pos      = new Vector3(x * cubeSize, y * cubeSize, z * cubeSize + 0.5f);
        Node    edgeNode = new Node(pos);

        if (z != map.GetLength(2))
        {
            if (x != map.GetLength(0) && y != map.GetLength(1))
            {
                if (cubes[x, y, z].edgeNodes[8] == null)
                {
                    cubes[x, y, z].edgeNodes[8] = edgeNode;
                }
            }

            if (x != 0 && y != map.GetLength(1))
            {
                if (cubes[x - 1, y, z].edgeNodes[9] == null)
                {
                    cubes[x - 1, y, z].edgeNodes[9] = edgeNode;
                }
            }

            if (y != 0 && x != map.GetLength(0))
            {
                if (cubes[x, y - 1, z].edgeNodes[10] == null)
                {
                    cubes[x, y - 1, z].edgeNodes[10] = edgeNode;
                }
            }

            if (x != 0 && y != 0)
            {
                if (cubes[x - 1, y - 1, z].edgeNodes[11] == null)
                {
                    cubes[x - 1, y - 1, z].edgeNodes[11] = edgeNode;
                }
            }
        }
    }