Esempio n. 1
0
File: SOM.cs Progetto: zmarsel1/kmpo
        public SOM(int inputDims, int outputDims, int width = 10, int height = 10, double alpha = 0.9, double beta = 0.1)
        {
            InputDims  = inputDims;
            OutputDims = outputDims;
            Width      = width;
            Height     = height;
            Alpha      = alpha;
            Beta       = beta;
            Radius     = 4;

            _nodes = new Vector[width, height];
            for (int x = 0; x <= _nodes.GetUpperBound(0); x++)
            {
                for (int y = 0; y <= _nodes.GetUpperBound(1); y++)
                {
                    Random rnd  = new Random();
                    var    node = new Vector();
                    node.Input = new double[inputDims];
                    for (int i = 0; i < InputDims; i++)
                    {
                        node.Input[i] = rnd.NextDouble();
                    }
                    node.Output = new double[outputDims];
                    for (int i = 0; i < OutputDims; i++)
                    {
                        node.Output[i] = rnd.NextDouble();
                    }
                    _nodes[x, y] = node;
                }
            }
        }
Esempio n. 2
0
        public Filler8(int rank = 6)
        {
            this.rank      = rank;
            indexerToLevel = new int[rank];//~~~~~~~~~~~~~~~~~~~

            dinamicmainLL = new Vector[rank, 4096];
        }
Esempio n. 3
0
        //*/

        /*
         * public Vector[,] CreateSpatialMesh(Vector resolution)
         * {
         *  Vector[,] X = new Vector[(int)resolution.x, (int)resolution.y];
         *
         *  for (int i = 0; i < resolution.x; i++)
         *  {
         *      for (int j = 0; j < resolution.y; j++)
         *      {
         *          X[i, j] = new Vector();
         *          if (i == 0 || j == 0)
         *          {
         *              if (i == 0)
         *              {
         *                  X[0, j].x = min.x + j;
         *                  X[0, j].y = min.y;
         *              }
         *              if (j == 0)
         *              {
         *                  X[i, 0].y = min.y + i;
         *                  X[i, 0].x = min.x;
         *              }
         *          }
         *          else
         *          {
         *              X[i, j] = new Vector(
         *                  min.x + j,
         *                  min.y + i
         *              );
         *          }
         *      }
         *  }
         *
         *  return X;
         * }
         */

        /*
         * public void DiscretiseSpace(int resolution, Func<Vector, Bounds2D, double> PHI)
         * {
         *  this.resolution = resolution;
         *  this.thau = size / resolution;
         *  this.thau = new Vector(1, 1, 1);
         *
         *  X = new Vector[resolution, resolution];
         *  X = CreateSpatialMesh(resolution);
         *
         *
         *  double sum = 0;
         *  vPHI = new double[resolution + 1, resolution + 1];
         *  for (int i = 0; i < resolution; i++)
         *  {
         *      for (int j = 0; j < resolution; j++)
         *      {
         *          vPHI[i, j] = PHI(X[i, j], this);
         *          //sum += vPHI[i, j];
         *      }
         *  }
         *  //Console.WriteLine(sum);
         * }
         */

        public void DiscretiseSpace(Vector resolution, Func <Vector, Bounds2D, double> PHI)
        {
            this.resolution = resolution;
            //this.thau = size / resolution;
            //this.thau = new Vector();
            //this.thau.x = size.x / resolution.x;
            //this.thau.y = size.y / resolution.y;

            //Console.WriteLine("Resolution: " + resolution);

            this.thau = new Vector(1, 1);

            X = new Vector[(int)resolution.x, (int)resolution.y];
            X = CreateSpatialMesh(resolution);


            double sum = 0;

            vPHI = new double[(int)resolution.x + 1, (int)resolution.y + 1];
            for (int i = 0; i < resolution.x; i++)
            {
                for (int j = 0; j < resolution.y; j++)
                {
                    vPHI[i, j] = PHI(X[i, j], this);
                    //sum += vPHI[i, j];
                }
            }
            //Console.WriteLine(sum);
        }
Esempio n. 4
0
        public override void ApplyFilter(int[] pixels, int width, int height, Vector[,] field)
        {
            double minBrightness = Double.PositiveInfinity;
            double maxBrightness = Double.NegativeInfinity;

            for (int i = 0; i < pixels.Length; i++)
            {
                int x = i % width;
                int y = i / width;

                int argb       = pixels[i];
                var color      = HsbColor.FromArgb(argb);
                var brightness = color.Brightness;

                if (brightness < minBrightness)
                {
                    minBrightness = brightness;
                }
                if (brightness > maxBrightness)
                {
                    maxBrightness = brightness;
                }
            }

            for (int i = 0; i < pixels.Length; i++)
            {
                int argb       = pixels[i];
                var color      = HsbColor.FromArgb(argb);
                var brightness = color.Brightness;

                double ratio = (brightness - minBrightness) / (maxBrightness - minBrightness);
                color.Brightness = ratio;
                pixels[i]        = color.ToArgb();
            }
        }
        /// <summary>
        /// Averages a vector with itself and it's neighbors.  Sets the field values.
        /// </summary>
        /// <param name="randomVectors">Random field of vectors to use to make averages.  Shouldn't be the field.</param>
        /// <param name="i">Column of vector to set.</param>
        /// <param name="j">Row of vector set.</param>
        private void AverageVectorWithNeighbors(Vector[,] randomVectors, int i, int j)
        {
            const int VECTOR_AVERAGE_RANGE = 1;                 // Range of adjacent row or column to sweep through
            float     xSum, ySum;                               // Sum of non empty adjacent vector values
            float     numVectors;                               // Number of adjacent non-empty vectors
            int       rowStart, rowEnd, columnStart, columnEnd; // Range to average the vector values through

            // Set the bounds of vectors to average.
            rowStart    = i - VECTOR_AVERAGE_RANGE;
            rowEnd      = i + VECTOR_AVERAGE_RANGE;
            columnStart = j - VECTOR_AVERAGE_RANGE;
            columnEnd   = j + VECTOR_AVERAGE_RANGE;

            // Intersect average bounds with the randomVectors field
            if (rowStart < 0)
            {
                rowStart = 0;
            }
            if (rowEnd >= randomVectors.GetLength(ROW_DIMENSION))
            {
                rowEnd = randomVectors.GetLength(ROW_DIMENSION) - 1;
            }

            if (columnStart < 0)
            {
                columnStart = 0;
            }
            if (columnEnd >= randomVectors.GetLength(COLUMN_DIMENSION))
            {
                columnEnd = randomVectors.GetLength(COLUMN_DIMENSION) - 1;
            }

            // No vectors summed yet
            xSum       = 0;
            ySum       = 0;
            numVectors = 0;

            for (int row = rowStart; row <= rowEnd; row++)
            {
                for (int column = columnStart; column <= columnEnd; column++)
                {
                    xSum += randomVectors[row, column].x;
                    ySum += randomVectors[row, column].y;
                    numVectors++;
                }
            }

            // Get the average of the vectors
            xSum /= (short)numVectors;
            ySum /= (short)numVectors;

            // Make directionless vectors point one down
            if (Math.Abs(ySum) + Math.Abs(xSum) <= 0)
            {
                ySum = 1;
            }

            // Set the vector
            field[i, j] = new Vector(xSum, ySum);
        }
Esempio n. 6
0
        private static DataSource CreateVectorField(int width, int height, Vector[,] data)
        {
            double[] xs = Enumerable.Range(0, width).Select(i => (double)i).ToArray();
            double[] ys = Enumerable.Range(0, height).Select(i => (double)i).ToArray();

            return(new NonUniformDataSource2D <Vector>(xs, ys, data));
        }
Esempio n. 7
0
 public SurfacePreprocessor(SurfaceRenderer _renderer)
 {
     renderer    = _renderer;
     cacheWidth  = SurfaceRenderer.CACHE_WIDTH;
     cacheHeight = SurfaceRenderer.CACHE_HEIGHT;
     ColorCache  = new int?[cacheWidth, cacheHeight];
     VectorCache = new Vector[cacheWidth, cacheHeight];
 }
Esempio n. 8
0
 public override void Transform(double[,] TransformMatrix)
 {
     this.Points = TransformPoints(TransformMatrix, this.Points);
     if (this.Normals != null)
     {
         this.Normals = TransformPoints(TransformMatrix, this.Normals);
     }
 }
        public override int[] ApplyFilter(int[] pixels, int width, int height, Vector[,] field)
        {
            double maxLength = Double.NegativeInfinity;
            double minLength = Double.PositiveInfinity;

            // determine min and max length
            // this works faster than parallel enumerable version.
            for (int ix = 0; ix < width; ix++)
            {
                for (int iy = 0; iy < height; iy++)
                {
                    var length = field[ix, iy].Length;
                    if (length > maxLength)
                    {
                        maxLength = length;
                    }
                    if (length < minLength)
                    {
                        minLength = length;
                    }
                }
            }

            int[] resultPixels = new int[width * height];
            pixels.CopyTo(resultPixels, 0);

            // attempt to avoid exception on line
            // 'HsbColor color = HsbColor.FromArgb(pixels[i]);'
            if (pixels.Length == 0)
            {
                return(pixels);
            }

            Parallel.For(0, width * height, i =>
            {
                HsbColor color = HsbColor.FromArgb(pixels[i]);

                int ix     = i % width;
                int iy     = i / width;
                var length = field[ix, height - 1 - iy].Length;

                var ratio = (length - minLength) / (maxLength - minLength);
                if (ratio.IsNaN())
                {
                    ratio = 0;
                }

                var paletteColor = Palette.GetColor(ratio).ToHsbColor();

                color.Hue        = paletteColor.Hue;
                color.Saturation = paletteColor.Saturation;

                resultPixels[i] = color.ToArgb();
            });

            return(resultPixels);
        }
Esempio n. 10
0
 public void SovleNormalVector()
 {
     if (Points != null && Points.Length > 4)
     {
         Normals = new Vector[Points.GetLength(0), Points.GetLength(1)];
         double a = 0, b = 0, c = 0, m = 0, n = 0, l = 0;
         for (int i = 0; i < Points.GetLength(0); i++)
         {
             for (int j = 0; j < Points.GetLength(1); j++)
             {
                 if (i == Points.GetLength(0) - 1)
                 {
                     if (j == Points.GetLength(1) - 1)
                     {
                         a = Points[i, j].X - Points[i - 1, j].X;
                         b = Points[i, j].Y - Points[i - 1, j].Y;
                         c = Points[i, j].Z - Points[i - 1, j].Z;
                         m = Points[i, j].X - Points[i, j - 1].X;
                         n = Points[i, j].Y - Points[i, j - 1].Y;
                         l = Points[i, j].Z - Points[i, j - 1].Z;
                     }
                     else
                     {
                         a = Points[i, j].X - Points[i - 1, j].X;
                         b = Points[i, j].Y - Points[i - 1, j].Y;
                         c = Points[i, j].Z - Points[i - 1, j].Z;
                         m = Points[i, j + 1].X - Points[i, j].X;
                         n = Points[i, j + 1].Y - Points[i, j].Y;
                         l = Points[i, j + 1].Z - Points[i, j].Z;
                     }
                 }
                 else
                 {
                     if (j == Points.GetLength(1) - 1)
                     {
                         a = Points[i + 1, j].X - Points[i, j].X;
                         b = Points[i + 1, j].Y - Points[i, j].Y;
                         c = Points[i + 1, j].Z - Points[i, j].Z;
                         m = Points[i, j].X - Points[i, j - 1].X;
                         n = Points[i, j].Y - Points[i, j - 1].Y;
                         l = Points[i, j].Z - Points[i, j - 1].Z;
                     }
                     else
                     {
                         a = Points[i + 1, j].X - Points[i, j].X;
                         b = Points[i + 1, j].Y - Points[i, j].Y;
                         c = Points[i + 1, j].Z - Points[i, j].Z;
                         m = Points[i, j + 1].X - Points[i, j].X;
                         n = Points[i, j + 1].Y - Points[i, j].Y;
                         l = Points[i, j + 1].Z - Points[i, j].Z;
                     }
                 }
                 Normals[i, j] = Cross(new PointD(a, b, c), new PointD(m, n, l));
             }
         }
     }
 }
Esempio n. 11
0
            public Group(String name, Vector[,] lines)
            {
                this.name = name;

                this.sections = new List <Section>();
                for (int i = 0; i < lines.Length / 2; i++)
                {
                    this.sections.Add(new Section(lines[i, 0], lines[i, 1]));
                }
            }
Esempio n. 12
0
            public static Vector[] GetRow(Vector[,] a, int i)
            {
                int num = ColumnCount(a);

                Vector[] vectorArray = new Vector[num];
                for (int j = 0; j < num; j++)
                {
                    vectorArray[j] = a[i, j];
                }
                return(vectorArray);
            }
Esempio n. 13
0
            public static Vector[] GetColumn(Vector[,] a, int j)
            {
                int num = RowCount(a);

                Vector[] vectorArray = new Vector[num];
                for (int i = 0; i < num; i++)
                {
                    vectorArray[i] = a[i, j];
                }
                return(vectorArray);
            }
Esempio n. 14
0
        private void InitializeCollisionAssets()
        {
            this.collisionCollection = new Collision();

            this.colisionParser = new CollisionParser();
            //TEST

            for (int i = 0; i < mapSizeY; i++)
            {
                for (int j = 0; j < mapSizeX; j++)
                {
                    this.map[j, i] = 0;
                }
            }
            Vector temPosition = new Vector();

            for (int i = 0; i < mapSizeY; i++)
            {
                this.map[0, i]            = 1;
                this.map[i, 0]            = 1;
                this.map[mapSizeX - 1, i] = 1;
                this.map[i, mapSizeY - 1] = 1;
            }

            for (int i = 2; i < mapSizeY - 2; i++)
            {
                temPosition.Y = i;
                for (int j = 2; j < mapSizeX - 2; j++)
                {
                    temPosition.X = j;

                    if ((i % 2 == 0) && (j % 2 == 0))
                    {
                        this.map[i, j] = 2;
                    }
                }
            }


            for (int i = 0; i < mapSizeY; i++)
            {
                temPosition.Y = i;
                for (int j = 0; j < mapSizeX; j++)
                {
                    temPosition.X = j;

                    if (map[j, i] == 2 || map[j, i] == 1)
                    {
                        collisionCollection.addGroup("blokX:" + j + "Y:" + i, this.colisionParser.ParseRectangle(temPosition, 1));
                    }
                }
            }
            this.colSects = this.collisionCollection.giveMeSections();
        }
Esempio n. 15
0
 /// <summary>
 /// Gets the vector at position (a,b) if the a is less than b, otherwise, returns the inverse of the vector at (b,a).
 /// </summary>
 /// <param name="a">The first array dimension.</param>
 /// <param name="b">The second array dimension.</param>
 /// <param name="vectors">A multi-dimensional array of vectors.</param>
 /// <returns>The vector at position (a,b) if the a is less than b, otherwise, returns the inverse of the vector at (b,a).</returns>
 private static Vector GetVector(int a, int b, Vector[,] vectors)
 {
     if (a < b)
     {
         return(vectors[a, b]);
     }
     else
     {
         return(-vectors[b, a]);
     }
 }
        /// <summary>
        /// Creates a new vector field of the given width and heighth, to the nearest acceptable
        /// measure based on the given resolution.
        /// </summary>
        /// <param name="width">Width of the field.</param>
        /// <param name="height">Height of the field.</param>
        /// <param name="generalDirection">General direction of the wind force generated by this field.</param>
        /// <param name="variance">How much the field can vary from the general direction.</param>
        /// <param name="fieldResolution">
        /// Resolution of the field.  This is how many pixel units
        /// on the field are taken up by a single vector.
        /// </param>
        public WindField(int width, int height, Vector generalDirection, Vector variance, Size fieldResolution)
        {
            field = new Vector[(height + fieldResolution.Height - 1) / fieldResolution.Height,
                               (width + fieldResolution.Width - 1) / fieldResolution.Width];

            this.fieldResolution = fieldResolution;

            this.generalWind = generalDirection;

            this.SetFieldVariation(generalDirection, variance);
        }
        public KMeans(Vector[,] _vectors, int _numClusters, int _maxIterations)
        {
            vectors       = _vectors;
            numClusters   = _numClusters;
            maxIterations = _maxIterations;

            clusters = new List <Cluster>();

            vWidth  = vectors.GetLength(0);
            vHeight = vectors.GetLength(1);
        }
Esempio n. 18
0
 public VectorField(Vector[,] matrica, int sizex, int sizey)
 {
     this.sizex = sizex;
     this.sizey = sizey;
     for (int i = 0; i < sizex; i++)
     {
         for (int j = 0; j < sizey; j++)
         {
             this.field[i, j] = new Vector(Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()));
         }
     }
 }
Esempio n. 19
0
 public static Matrix FromVectorArray(Vector[,] blockvector)
 {
     Matrix[,] blockmatrix = new Matrix[blockvector.GetLength(0), blockvector.GetLength(1)];
     for (int c = 0; c < blockvector.GetLength(0); c++)
     {
         for (int r = 0; r < blockvector.GetLength(1); r++)
         {
             blockmatrix[c, r] = blockvector[c, r].ToColMatrix();
         }
     }
     return(FromMatrixArray(blockmatrix));
 }
Esempio n. 20
0
 private static Vector GetVector(int a, int b, int count, Vector[,] vectors)
 {
     Debug.Assert(a != b);
     if (a < b)
     {
         return(vectors[a, b]);
     }
     else
     {
         return(-vectors[b, a]);
     }
 }
Esempio n. 21
0
        public PerlinNoiseGenerator2D(int gridWidth, int gridHight)
        {
            _gridVectors = new Vector[gridWidth, gridHight];

            for (var x = 1; x < gridWidth; x++)
            {
                for (var y = 1; y < gridHight; y++)
                {
                    _gridVectors[x, y] = GenUnitVector();
                }
            }
        }
        public RaytraceRenderer(Scene scene, RenderingParameters rendParams)
        {
            this.scene = scene;
            this.renderingParameters = rendParams;
            this.width = rendParams.Width;
            this.height = rendParams.Height;
            this.buffer = new Vector[width, height];
            this.normals = new Vector[width, height];
            this.materials = new SceneMaterial[width, height];

            watch = new Stopwatch();
        }
Esempio n. 23
0
        public Form1()
        {
            InitializeComponent();
            cellSize = 20;
            columns  = pictureBox.Width / cellSize;
            rows     = pictureBox.Height / cellSize;
            points   = new Vector[columns + 1, rows + 1];
            spheres  = new List <Sphere>();

            CreatePoints();
            CreateStartingSpheres();
            timer.Start();
        }
Esempio n. 24
0
        public bool addGroup(String name, Vector[,] lines)
        {
            foreach (Group group in this.groups)
            {
                if (group.name == name)
                {
                    return(false);
                }
            }
            this.groups.Add(new Group(name, lines));

            return(true);
        }
Esempio n. 25
0
 public Analyzer3()
 {
     leftPosition  = new Vector[2, 5];
     rightPosition = new Vector[2, 5];
     for (int i = 0; i < 2; i++)
     {
         for (int j = 0; j < 5; j++)
         {
             leftPosition[i, j]  = new Vector(0, 0, 0);
             rightPosition[i, j] = new Vector(0, 0, 0);
         }
     }
 }
Esempio n. 26
0
        /// <summary>
        /// Create image based on size from stream
        /// </summary>
        /// <param name="infile"></param>
        public Image(int w , int h)
        {
            // read width and height
            Width = w;
            Height = h;

            // clamp width and height
            Width = Width < 1 ? 1 : (Width > 10000 ? 10000 : Width);
            Height = Height < 1 ? 1 : (Height > 10000 ? 10000 : Height);

            pixels = new Vector[Width, Height];
            for (int i = 0; i < Width; ++i)
                for (int j = 0; j < Height; ++j)
                    pixels[i, j] = new Vector();
        }
Esempio n. 27
0
        public static void WriteLine(Vector[,] myVectorArray, int paddedWidth = 20)
        {
            int length = myVectorArray.GetLength(0);
            int num2   = myVectorArray.GetLength(1);

            for (int i = 0; i < length; i++)
            {
                for (int j = 0; j < num2; j++)
                {
                    Vector vector = myVectorArray[i, j];
                    Write(vector.ToString().PadRight(paddedWidth));
                }
                Write("\n");
            }
        }
Esempio n. 28
0
        public static double[,] GetZ(Vector[,] vectors)
        {
            int length = vectors.GetLength(0);
            int num2   = vectors.GetLength(1);

            double[,] numArray = new double[length, num2];
            for (int i = 0; i < length; i++)
            {
                for (int j = 0; j < num2; j++)
                {
                    numArray[i, j] = vectors[i, j].Z;
                }
            }
            return(numArray);
        }
Esempio n. 29
0
        /// <summary>
        /// Create image based on size from stream
        /// </summary>
        /// <param name="infile"></param>
        public Image(StreamReader infile)
        {
            // read width and height
            Width = (int)infile.ReadFloat();
            Height = (int)infile.ReadFloat();

            // clamp width and height
            Width = Width < 1 ? 1 : (Width > 10000 ? 10000 : Width);
            Height = Height < 1 ? 1 : (Height > 10000 ? 10000 : Height);

            pixels = new Vector[Width, Height];
            for (int i = 0; i < Width; ++i)
                for (int j = 0; j < Height; ++j)
                    pixels[i, j] = new Vector();
        }
Esempio n. 30
0
        private void RandomizePoints(int min, int max)
        {
            Vector[,] randomPoints = points;

            for (int x = 0; x <= columns; ++x)
            {
                for (int y = 0; y <= rows; ++y)
                {
                    randomPoints[x, y] = new Vector(
                        (x * cellSize) + r.Next(min, max),
                        (y * cellSize) + r.Next(min, max));
                }
            }
            points = randomPoints;
        }
        public override int[] ApplyFilter(int[] pixels, int width, int height, Vector[,] field)
        {
            for (int i = 0; i < pixels.Length; i++)
            {
                int pixel           = pixels[i];
                int whiteNoizePixel = whiteNoize[i];

                if (pixel == whiteNoizePixel)
                {
                    pixels[i] = Colors.Transparent.ToArgb();
                }
            }

            return(pixels);
        }
        void setup_vectors(int width, int height)
        {
            grid = new Vector[width, height];
            Random random = new Random();

            Vector[] availableGradients = new Vector[] { new Vector(1, 0), new Vector(-1, 0),
                                                         new Vector(0, 1), new Vector(0, -1) };

            for (var i = 0; i < width; i++)
            {
                for (var j = 0; j < height; j++)
                {
                    grid[i, j] = availableGradients[random.Next(3)];
                }
            }
        }
Esempio n. 33
0
        public static Bitmap CreateNoiseMap(int width, int height, Color colorOne, Color colorTwo, int iterations = 1, double colorOneProbability = 0.5)
        {
            var noiseMap = new Bitmap(width, height);
            var rand     = new Random();

            Vectors = new Vector[width, height];


            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    var color = rand.NextDouble() <= colorOneProbability ? colorOne : colorTwo;
                    noiseMap.SetPixel(x, y, color);
                    var randXVector = rand.Next(-1, 2);
                    var randYVector = rand.Next(-1, 2);
                    Vectors[x, y] = new Vector {
                        X = randXVector, Y = randYVector
                    };
                }
            }

            for (var i = 0; i < iterations; i++)
            {
                for (var x = 0; x < width; x++)
                {
                    for (var y = 0; y < height; y++)
                    {
                        var vectorX = x + Vectors[x, y].X;
                        var vectorY = y + Vectors[x, y].Y;

                        if (vectorX < 0 || vectorX >= width || vectorY < 0 || vectorY >= height)
                        {
                            continue;
                        }

                        var newRed   = (noiseMap.GetPixel(x, y).R + noiseMap.GetPixel(vectorX, vectorY).R) / 2;
                        var newGreen = (noiseMap.GetPixel(x, y).G + noiseMap.GetPixel(vectorX, vectorY).G) / 2;
                        var newBlue  = (noiseMap.GetPixel(x, y).B + noiseMap.GetPixel(vectorX, vectorY).B) / 2;

                        noiseMap.SetPixel(vectorX, vectorY, Color.FromArgb(newRed, newGreen, newBlue));
                    }
                }
            }

            return(noiseMap);
        }
Esempio n. 34
0
        public linefeature(Feature feature1, Feature feature2, int no_of_points, int history)
        {
            marked_for_deletion = false;
            curr_index = 0;
            hits = 0;
            this.feature1 = feature1;
            this.feature2 = feature2;
            this.no_of_points = no_of_points;
            this.history = history;
            pixel_intensity = new Byte[no_of_points, history];
            feature_position = new Vector[history, 2];

            for (int i = 0; i < history; i++)
            {
                feature_position[i, 0] = new Vector(3);
                feature_position[i, 1] = new Vector(3);
            }
        }
        public List<Vector> FindPath(Vector s, Vector e, Entity o)
        {
            start = s;
            end = e;
            entity = o;

            int w = map.blocks.GetLength(0);
            int h = map.blocks.GetLength(1);
            gScore = new int[w, h];
            hScore = new int[w, h];
            fScore = new int[w, h];
            cameFrom = new Vector[w, h];

            List<Vector> open = new List<Vector>();
            List<Vector> closed = new List<Vector>();

            open.Add(start);
            gScore[start.x, start.y] = 0;
            hScore[start.x, start.y] = calculateHeuristic(start);
            fScore[start.x, start.y] = hScore[start.x, start.y];

            while(open.Count > 0) {
                Vector point = getLowestPointIn(open);
                if(point == end) return reconstructPath(cameFrom[point.x, point.y]);
                open.Remove(point);
                closed.Add(point);

                List<Vector> neighbours = getNeighbourPoints(point);
                foreach(Vector p in neighbours) {
                    if(closed.Contains(p)) continue;

                    int gPossible = gScore[point.x, point.y] + distanceBetween(p, point);

                    if(!open.Contains(p) || (open.Contains(p) && gPossible < gScore[p.x, p.y])) {
                        if(!open.Contains(p)) open.Add(p);
                        cameFrom[p.x, p.y] = point;
                        gScore[p.x, p.y] = gPossible;
                        hScore[p.x, p.y] = calculateHeuristic(p);
                        fScore[p.x, p.y] = gPossible + hScore[p.x, p.y];
                    }
                }
            }
            return null;
        }
Esempio n. 36
0
        public void SovleNormalVector()
        {
            if (Points != null && Points.Length > 4)
            {
                Normals = new Vector[Points.GetLength(0), Points.GetLength(1)];
                double a = 0, b = 0, c = 0, m = 0, n = 0, l = 0;
                for (int i = 0; i < Points.GetLength(0); i++)
                {
                    for (int j = 0; j < Points.GetLength(1); j++)
                    {
                        if (i == Points.GetLength(0) - 1)
                        {
                            if (j == Points.GetLength(1) - 1)
                            {
                                a = Points[i, j].X - Points[i - 1, j].X;
                                b = Points[i, j].Y - Points[i - 1, j].Y;
                                c = Points[i, j].Z - Points[i - 1, j].Z;
                                m = Points[i, j].X - Points[i, j - 1].X;
                                n = Points[i, j].Y - Points[i, j - 1].Y;
                                l = Points[i, j].Z - Points[i, j - 1].Z;
                            }
                            else
                            {
                                a = Points[i, j].X - Points[i - 1, j].X;
                                b = Points[i, j].Y - Points[i - 1, j].Y;
                                c = Points[i, j].Z - Points[i - 1, j].Z;
                                m = Points[i, j + 1].X - Points[i, j].X;
                                n = Points[i, j + 1].Y - Points[i, j].Y;
                                l = Points[i, j + 1].Z - Points[i, j].Z;
                            }
                        }
                        else
                        {
                            if (j == Points.GetLength(1) - 1)
                            {
                                a = Points[i + 1, j].X - Points[i, j].X;
                                b = Points[i + 1, j].Y - Points[i, j].Y;
                                c = Points[i + 1, j].Z - Points[i, j].Z;
                                m = Points[i, j].X - Points[i, j - 1].X;
                                n = Points[i, j].Y - Points[i, j - 1].Y;
                                l = Points[i, j].Z - Points[i, j - 1].Z;
                            }
                            else
                            {
                                a = Points[i + 1, j].X - Points[i, j].X;
                                b = Points[i + 1, j].Y - Points[i, j].Y;
                                c = Points[i + 1, j].Z - Points[i, j].Z;
                                m = Points[i, j + 1].X - Points[i, j].X;
                                n = Points[i, j + 1].Y - Points[i, j].Y;
                                l = Points[i, j + 1].Z - Points[i, j].Z;
                            }
                        }
                        Normals[i, j] = Cross(new PointD(a, b, c), new PointD(m, n, l));
                    }
                }
            }

        }
Esempio n. 37
0
 public static void GetColorMap(ref MapPackage map)
 {
     int cellWidth = Renderer.cellWidth;
     int cellHeight = Renderer.cellHeight;
     Vector[,,] normalPool = m_NormalPool;
     ArrayList[,] cells = map.cells;
     byte[,] flags = map.flags;
     byte num3 = 1;
     Vector[,] vertsPool = m_VertsPool;
     bool[,] calcPool = m_CalcPool;
     CheckStretchTable();
     if (normalPool == null)
     {
         normalPool = m_NormalPool = new Vector[cellWidth, cellHeight, 2];
     }
     if (vertsPool == null)
     {
         vertsPool = m_VertsPool = new Vector[cellWidth, cellHeight];
     }
     if (calcPool == null)
     {
         calcPool = m_CalcPool = new bool[cellWidth, cellHeight];
     }
     else
     {
         Array.Clear(calcPool, 0, cellWidth * cellHeight);
     }
     m_CalcVert_Verts = vertsPool;
     m_CalcVert_Tiles = map.landTiles;
     CalcVert(0, 0);
     calcPool[0, 0] = true;
     for (int i = 0; i < (cellWidth - 1); i++)
     {
         for (int k = 0; k < (cellHeight - 1); k++)
         {
             if (!calcPool[i + 1, k])
             {
                 CalcVert(i + 1, k);
                 calcPool[i + 1, k] = true;
             }
             CalcVert(i + 1, k + 1);
             calcPool[i + 1, k + 1] = true;
             if (!calcPool[i, k + 1])
             {
                 CalcVert(i, k + 1);
                 calcPool[i, k + 1] = true;
             }
             SurfaceNormal(normalPool, i, k, 0, *(vertsPool[i, k]), *(vertsPool[i + 1, k]), *(vertsPool[i, k + 1]));
             SurfaceNormal(normalPool, i, k, 1, *(vertsPool[i, k + 1]), *(vertsPool[i + 1, k]), *(vertsPool[i + 1, k + 1]));
         }
     }
     int[,] colorMap = m_ColorMap;
     if (colorMap == null)
     {
         colorMap = m_ColorMap = new int[cellWidth, cellHeight];
     }
     int[,] numArray2 = m_ColorMap2;
     if (numArray2 == null)
     {
         numArray2 = m_ColorMap2 = new int[cellWidth, cellHeight];
     }
     for (int j = 1; j < (cellWidth - 1); j++)
     {
         byte[,] buffer2;
         IntPtr ptr;
         IntPtr ptr2;
         int[,] numArray3;
         for (int m = 1; m < (cellHeight - 1); m++)
         {
             Vector vector = *(normalPool[j, m, 0]);
             Vector vector2 = *(normalPool[j - 1, m - 1, 1]);
             Vector vector3 = *(normalPool[j - 1, m, 0]);
             Vector vector4 = *(normalPool[j - 1, m, 1]);
             Vector vector5 = *(normalPool[j, m - 1, 0]);
             Vector vector6 = *(normalPool[j, m - 1, 1]);
             float num8 = ((((vector.m_X + vector2.m_X) + vector3.m_X) + vector4.m_X) + vector5.m_X) + vector6.m_X;
             float num9 = ((((vector.m_Y + vector2.m_Y) + vector3.m_Y) + vector4.m_Y) + vector5.m_Y) + vector6.m_Y;
             float num10 = ((((vector.m_Z + vector2.m_Z) + vector3.m_Z) + vector4.m_Z) + vector5.m_Z) + vector6.m_Z;
             num8 *= 0.1666667f;
             num9 *= 0.1666667f;
             num10 *= 0.1666667f;
             float num11 = (float) (1.0 / Math.Sqrt((double) (((num8 * num8) + (num9 * num9)) + (num10 * num10))));
             num8 *= num11;
             num9 *= num11;
             num10 *= num11;
             float num12 = ((num8 * vLight.m_X) + (num9 * vLight.m_Y)) + (num10 * vLight.m_Z);
             num12 += 0.2151413f;
             num12 += 0.8235294f;
             int num13 = (int) ((255f * num12) + 0.5f);
             if (num13 < 0x80)
             {
                 num13 = 0x80;
             }
             else if (num13 > 0xff)
             {
                 num13 = 0xff;
             }
             numArray2[j, m] = colorMap[j, m] = 0x10101 * num13;
             if (((!m_AlwaysStretch[m_CalcVert_Tiles[j - 1, m - 1].m_ID & 0x3fff] && (colorMap[j, m] == 0xd2d2d2)) && ((colorMap[j - 1, m] == 0xd2d2d2) && (colorMap[j - 1, m - 1] == 0xd2d2d2))) && (colorMap[j, m - 1] == 0xd2d2d2))
             {
                 int z = m_CalcVert_Tiles[j - 1, m - 1].m_Z;
                 int num15 = m_CalcVert_Tiles[j, m - 1].m_Z;
                 int num16 = m_CalcVert_Tiles[j, m].m_Z;
                 int num17 = m_CalcVert_Tiles[j - 1, m].m_Z;
                 if (((z == num15) && (z == num16)) && (z == num17))
                 {
                     (buffer2 = flags)[(int) (ptr = (IntPtr) (j - 1)), (int) (ptr2 = (IntPtr) (m - 1))] = (byte) (buffer2[(int) ptr, (int) ptr2] & ~num3);
                 }
                 else
                 {
                     (buffer2 = flags)[(int) (ptr = (IntPtr) (j - 1)), (int) (ptr2 = (IntPtr) (m - 1))] = (byte) (buffer2[(int) ptr, (int) ptr2] | num3);
                 }
             }
             else
             {
                 (buffer2 = flags)[(int) (ptr = (IntPtr) (j - 1)), (int) (ptr2 = (IntPtr) (m - 1))] = (byte) (buffer2[(int) ptr, (int) ptr2] | num3);
             }
         }
         (buffer2 = flags)[(int) (ptr = (IntPtr) j), 0] = (byte) (buffer2[(int) ptr, 0] | num3);
         (buffer2 = flags)[(int) (ptr = (IntPtr) j), (int) (ptr2 = (IntPtr) (cellHeight - 2))] = (byte) (buffer2[(int) ptr, (int) ptr2] | num3);
         (buffer2 = flags)[0, (int) (ptr = (IntPtr) j)] = (byte) (buffer2[0, (int) ptr] | num3);
         (buffer2 = flags)[(int) (ptr = (IntPtr) (cellWidth - 2)), (int) (ptr2 = (IntPtr) j)] = (byte) (buffer2[(int) ptr, (int) ptr2] | num3);
         numArray2[j, 0] = colorMap[j, 0] = 0;
         numArray2[j, cellHeight - 1] = colorMap[j, cellHeight - 1] = 0;
         numArray2[0, j] = (numArray3 = colorMap)[0, (int) (ptr = (IntPtr) j)] = numArray3[0, (int) ptr] | num3;
         numArray2[cellWidth - 1, j] = colorMap[cellWidth - 1, j] = 0;
     }
     map.colorMap = colorMap;
     map.realColors = colorMap;
     map.frameColors = numArray2;
     map.flags = flags;
 }
		public UniformFieldWrapper(Vector[,] field, int width, int height)
		{
			this.field = field;
			this.width = width;
			this.height = height;
		}
		public UniformField2DWrapper(Vector[,] field)
		{
			this.field = field;
			this.width = field.GetLength(0);
			this.height = field.GetLength(1);
		}
Esempio n. 40
0
 public override void Transform(double[,] TransformMatrix)
 {
     this.Points = TransformPoints(TransformMatrix, this.Points);
     if (this.Normals != null) this.Normals = TransformPoints(TransformMatrix, this.Normals);
 }
Esempio n. 41
0
        private void compositionTarget_rendering(object sender, EventArgs args)
        {
            Debug.Assert(_nodePresenters != null);

            if (_springForces == null)
            {
                _springForces = SetupForceVertors(_nodePresenters.Count);
            }
            else if (_springForces.GetLowerBound(0) != _nodePresenters.Count)
            {
                _springForces = SetupForceVertors(_nodePresenters.Count);
            }

            bool _somethingInvalid = false;
            if (_measureInvalidated || _stillMoving)
            {
                if (_measureInvalidated)
                {
                    _ticksOfLastMeasureUpdate = DateTime.Now.Ticks;
                }

                #region CenterObject
                if (_centerObjectPresenter != null)
                {
                    if (_centerObjectPresenter.New)
                    {
                        _centerObjectPresenter.ParentCenter = _controlCenter;
                        _centerObjectPresenter.New = false;
                        _somethingInvalid = true;
                    }
                    else
                    {
                        Vector forceVector = GetAttractionForce(
                            ensureNonzeroVector((Vector)_centerObjectPresenter.Location));

                        if (updateGraphCP(_centerObjectPresenter, forceVector, CoefficientOfDampening, FrameRate, _controlCenter))
                        {
                            _somethingInvalid = true;
                        }
                    }
                }
                #endregion

                GraphContentPresenter gcp;
                for (int i = 0; i < _nodePresenters.Count; i++)
                {
                    gcp = _nodePresenters[i];

                    if (gcp.New)
                    {
                        gcp.New = false;
                        _somethingInvalid = true;
                    }

                    for (int j = (i + 1); j < _nodePresenters.Count; j++)
                    {
                        Vector distance = ensureNonzeroVector(gcp.Location - _nodePresenters[j].Location);

                        Vector repulsiveForce = GetRepulsiveForce(distance);//GetSpringForce(distance, gcp.Velocity - _nodePresenters[j].Velocity);
                        _springForces[i, j] = repulsiveForce;
                    }
                }

                Point centerLocationToUse = (_centerObjectPresenter != null) ? _centerObjectPresenter.Location : new Point();

                for (int i = 0; i < _nodePresenters.Count; i++)
                {
                    Vector forceVector = new Vector();
                    forceVector += GetVectorSum(i, _nodePresenters.Count, _springForces);
                    forceVector += GetSpringForce(ensureNonzeroVector(_nodePresenters[i].Location - centerLocationToUse));
                    forceVector += GetWallForce(this.RenderSize, _nodePresenters[i].Location);

                    if (updateGraphCP(_nodePresenters[i], forceVector, CoefficientOfDampening, FrameRate, _controlCenter))
                    {
                        _somethingInvalid = true;
                    }
                }

                #region animate all of the fading ones away
                for (int i = 0; i < _fadingGCPList.Count; i++)
                {
                    if (!_fadingGCPList[i].WasCenter)
                    {
                        Vector centerDiff = ensureNonzeroVector(_fadingGCPList[i].Location - centerLocationToUse);
                        centerDiff.Normalize();
                        centerDiff *= 20;
                        if (updateGraphCP(_fadingGCPList[i], centerDiff, CoefficientOfDampening, FrameRate, _controlCenter))
                        {
                            _somethingInvalid = true;
                        }
                    }
                }

                #endregion

                if (_somethingInvalid && belowMaxSettleTime())
                {
                    _stillMoving = true;
                    InvalidateVisual();
                }
                else
                {
                    _stillMoving = false;
                    unwireFrameTick();
                }
                _measureInvalidated = false;

            }
        }
Esempio n. 42
0
        private void compositionTarget_rendering(object sender, EventArgs args)
        {
            Debug.Assert(_nodePresenters != null);

            if (_springForces == null)
            {
                _springForces = new Vector[_nodePresenters.Count, _nodePresenters.Count];
            }
            else if (_springForces.GetUpperBound(0) + 1 < _nodePresenters.Count)
            {
                _springForces = new Vector[_nodePresenters.Count, _nodePresenters.Count];
            }

            bool _somethingInvalid = false;
            if (_measureInvalidated || _stillMoving)
            {
                if (_measureInvalidated)
                {
                    m_milliseconds = Environment.TickCount;
                }

                #region CenterObject
                if (m_centerGraphContentPresenter != null)
                {
                    if (m_centerGraphContentPresenter.New)
                    {
                        m_centerGraphContentPresenter.ParentCenter = m_controlCenterPoint;
                        m_centerGraphContentPresenter.New = false;
                        _somethingInvalid = true;
                    }
                    else
                    {
                        Vector forceVector = GetAttractionForce(
                            ensureNonzeroVector((Vector)m_centerGraphContentPresenter.Location));

                        if (updateGraphCP(m_centerGraphContentPresenter, forceVector, Dampening, Attraction, m_controlCenterPoint))
                        {
                            _somethingInvalid = true;
                        }
                    }
                }
                #endregion

                GraphContentPresenter gcp;
                for (int i = 0; i < _nodePresenters.Count; i++)
                {
                    gcp = _nodePresenters[i];

                    if (gcp.New)
                    {
                        gcp.New = false;
                        _somethingInvalid = true;
                    }

                    for (int j = (i + 1); j < _nodePresenters.Count; j++)
                    {
                        Vector distance = ensureNonzeroVector(gcp.Location - _nodePresenters[j].Location);

                        Vector repulsiveForce = GetRepulsiveForce(distance);

                        _springForces[i, j] = repulsiveForce;
                    }
                }

                Point centerLocationToUse = (m_centerGraphContentPresenter != null) ? m_centerGraphContentPresenter.Location : new Point();

                for (int i = 0; i < _nodePresenters.Count; i++)
                {
                    Vector forceVector = new Vector();
                    forceVector += GetVectorSum(i, _nodePresenters.Count, _springForces);
                    forceVector += GetSpringForce(ensureNonzeroVector(_nodePresenters[i].Location - centerLocationToUse));
                    forceVector += GetWallForce(this.RenderSize, _nodePresenters[i].Location);

                    if (updateGraphCP(_nodePresenters[i], forceVector, Dampening, Attraction, m_controlCenterPoint))
                    {
                        _somethingInvalid = true;
                    }
                }

                #region animate all of the fading ones away
                for (int i = 0; i < _fadingGCPList.Count; i++)
                {
                    if (!_fadingGCPList[i].WasCenter)
                    {
                        Vector centerDiff = ensureNonzeroVector(_fadingGCPList[i].Location - centerLocationToUse);
                        centerDiff.Normalize();
                        centerDiff *= 20;
                        if (updateGraphCP(_fadingGCPList[i], centerDiff, Dampening, Attraction, m_controlCenterPoint))
                        {
                            _somethingInvalid = true;
                        }
                    }
                }

                #endregion

                if (_somethingInvalid && belowMaxSettleTime())
                {
                    _stillMoving = true;
                    InvalidateVisual();
                }
                else
                {
                    _stillMoving = false;
                    m_listener.StopListening();
                }
                _measureInvalidated = false;

            }
        }