public static void writeArrayInFile(Number[,,] net)
        {
            StreamWriter streamwriter = File.CreateText(utils.Properties.currentPathToFile);
            //# vtk DataFile Version 2.0
            //Cube example
            //ASCII
            //DATASET STRUCTURED_POINTS
            //DIMENSIONS 100 100 100
            //ORIGIN 0 0 0
            //SPACING 4 4 4
            //POINT_DATA 1000000
            //VECTORS vectors double
            streamwriter.WriteLine("# vtk DataFile Version 2.0");
            streamwriter.WriteLine("Cube example");
            streamwriter.WriteLine("ASCII");
            streamwriter.WriteLine("DATASET STRUCTURED_POINTS");
            streamwriter.WriteLine("DIMENSIONS " + net.GetLength(0) + " " + net.GetLength(1) + " " + net.GetLength(2));
            streamwriter.WriteLine("ORIGIN " + originX + " " + originY + " " + originZ);
            streamwriter.WriteLine("SPACING " + spacingX + " " + spacingY + " " + spacingZ);
            streamwriter.WriteLine("POINT_DATA " + net.Length);
            streamwriter.WriteLine("VECTORS vectors double");

            int column = 0;
            string line = "";
            for (int z = 0; z < net.GetLength(2); z++)
            {
                for (int y = 0; y < net.GetLength(1); y++)
                {
                    for (int x = 0; x < net.GetLength(0); x++)
                    {
                        line += net[x, y, z].x.ToString().Replace(Constants.DECIMAL_SEPARATOR, ".") +
                                " " +
                                net[x, y, z].y.ToString().Replace(Constants.DECIMAL_SEPARATOR, ".") +
                                " " +
                                net[x, y, z].z.ToString().Replace(Constants.DECIMAL_SEPARATOR, ".");
                        column++;
                        if (column >= 5)
                        {
                            streamwriter.WriteLine(line);
                            line = "";
                            column = 0;
                        }
                        else
                        {
                            line += " ";
                        }
                    }
                }
            }

            if (line != "")
            {
                streamwriter.WriteLine(line);
            }

            streamwriter.Close();
        }
        private static Number[,,] waveForThirdCoordinate(Number[,,] net, int interpolateMethod)
        {
            for (int x = 0; x < net.GetLength(0); x++)
            {
                for (int y = 0; y < net.GetLength(1); y++)
                {
                    Number[] row = new Number[net.GetLength(2)];
                    bool hasNumbers = false;
                    for (int i = 0; i < net.GetLength(2); i++)
                    {
                        row[i] = net[x, y, i];
                        hasNumbers = hasNumbers || (net[x, y, i] != null);
                    }

                    if (hasNumbers)
                    {
                        IExportCalculation calculation = ExportCalculationFactory.getCalculation(interpolateMethod);
                        row = calculation.fillValues(row);
                    }

                    for (int i = 0; i < net.GetLength(2); i++)
                    {
                        net[x, y, i] = row[i];
                    }
                }
            }

            return net;
        }
        private static Number[,,] fillAnother(Number[,,] net)
        {
            for (int x = 0; x < net.GetLength(0); x++)
            {
                for (int y = 0; y < net.GetLength(1); y++)
                {
                    for (int z = 0; z < net.GetLength(2); z++)
                    {
                        if (net[x, y, z] == null)
                        {
                            net[x, y, z] = new Number(0, 0, 0);
                        }
                    }
                }
            }

            return net;
        }
        private static void copyDataGridToNet(DataGridView data, Number[, ,] result)
        {
            if (data != null)
            {
                int x;
                int y;
                int z;
                for (int i = 0; i < data.RowCount - 1; i++)
                {
                    x = Int32.Parse(data.Rows[i].Cells[0].Value.ToString()) - originX;
                    y = Int32.Parse(data.Rows[i].Cells[1].Value.ToString()) - originY;
                    z = Int32.Parse(data.Rows[i].Cells[2].Value.ToString()) - originZ;

                    int p = data.Rows[i].Cells.Count;

                    if (x % spacingX == 0)
                    {
                        x = x / spacingX;
                    }
                    else
                    {
                        break;
                    }

                    if (y % spacingY == 0)
                    {
                        y = y / spacingY;
                    }
                    else
                    {
                        break;
                    }

                    if (z % spacingZ == 0)
                    {
                        z = z / spacingZ;
                    }
                    else
                    {
                        break;
                    }

                    if ((x >= result.GetLength(0)) ||
                        (y >= result.GetLength(1)) ||
                        (z >= result.GetLength(2)))
                    {
                        break;
                    }

                    if (result[x, y, z] == null)
                    {
                        result[x, y, z] = new Number(0, 0, 0);
                    }

                    try
                    {
                        result[x, y, z].x =
                            Convert.ToDouble(
                                data.Rows[i].Cells[3].Value.ToString()
                                    .Replace(DiplomaV2._0.utils.Properties.currentDecimalSeparator,
                                        Constants.DECIMAL_SEPARATOR));
                        result[x, y, z].y =
                            Convert.ToDouble(
                                data.Rows[i].Cells[4].Value.ToString()
                                    .Replace(DiplomaV2._0.utils.Properties.currentDecimalSeparator,
                                        Constants.DECIMAL_SEPARATOR));
                        result[x, y, z].z =
                            Convert.ToDouble(
                                data.Rows[i].Cells[5].Value.ToString()
                                    .Replace(DiplomaV2._0.utils.Properties.currentDecimalSeparator,
                                        Constants.DECIMAL_SEPARATOR));
                    }
                    catch (NullReferenceException e)
                    {
                        //ignored
                    }
                }
            }
        }
Beispiel #5
0
 public static void writeInterpolatedDataToB(Number[,,] data, DataGridView table, int originX, int originY, int originZ, Form callForm)
 {
     for (int i = 0; i < table.Rows.Count - 1; i++)
     {
         int x = Convert.ToInt32(table.Rows[i].Cells[0].Value) - originX;
         int y = Convert.ToInt32(table.Rows[i].Cells[1].Value) - originY;
         int z = Convert.ToInt32(table.Rows[i].Cells[2].Value) - originZ;
         if ((x >= data.GetLength(0)) || (y >= data.GetLength(1)) || (z >= data.GetLength(2))
             || (x < 0) || (y < 0) || (z < 0))
         {
             callForm.Invoke(new ThreadStart(delegate
             {
                 table.Rows[i].Cells[3].Value = "#Index out of bounds";
                 table.Rows[i].Cells[4].Value = "#Index out of bounds";
                 table.Rows[i].Cells[5].Value = "#Index out of bounds";
             }));
         }
         else
         {
             callForm.Invoke(new ThreadStart(delegate
             {
                 table.Rows[i].Cells[3].Value = data[x, y, z].x;
                 table.Rows[i].Cells[4].Value = data[x, y, z].y;
                 table.Rows[i].Cells[5].Value = data[x, y, z].z;
             }));
         }
     }
 }
Beispiel #6
0
        // Get a random place for some number
        private TopLeft getRandomPosition(Number[,] arr, Random rnd)
        {
            int top = rnd.Next(0, arr.GetLength(0));
            int left = rnd.Next(0, arr.GetLength(1));

            if (!(arr[top, left].Equals(new Number(0))))
            {
                getRandomPosition(arr, rnd);
            }

            return new TopLeft((uint)top * (uint)(SizeInPixels / Size), (uint)left * (uint)(SizeInPixels / Size));
        }