コード例 #1
0
 protected ReferencePointBasedTransform(MappingGridVector2[] points, GridRectangle mappedBounds, GridRectangle controlBounds, TransformInfo info)
     : base(info)
 {
     this.MapPoints = points;
     this.MappedBounds = mappedBounds;
     this.ControlBounds = controlBounds;
 }
コード例 #2
0
        public void TestEdgeAndInterior()
        {
            var r = new GridRectangle(0, 0, 4, 3);

            Assert.Equal(10, r.Edge.Count());
            Assert.Equal(12, r.Interior.Count());
        }
コード例 #3
0
        public void BoudingRectangle_ReturnsBoundingBox()
        {
            {
                var p = GridPolygon.GetRectangle(2, 4);

                var boundingRectangle = p.BoundingRectangle;
                var expected          = new GridRectangle(new IntVector2(0, 0), new IntVector2(2, 4));

                Assert.AreEqual(expected, boundingRectangle);
            }

            {
                var p = new GridPolygonBuilder()
                        .AddPoint(0, 0)
                        .AddPoint(0, 6)
                        .AddPoint(3, 6)
                        .AddPoint(3, 3)
                        .AddPoint(7, 3)
                        .AddPoint(7, 0)
                        .Build();

                var boundingRectangle = p.BoundingRectangle;
                var expected          = new GridRectangle(new IntVector2(0, 0), new IntVector2(7, 6));

                Assert.AreEqual(expected, boundingRectangle);
            }
        }
コード例 #4
0
        /// <summary>
        /// Computes the overlap along a line of a given moving rectangle and a fixed rectangle.
        /// </summary>
        /// <param name="movingRectangle"></param>
        /// <param name="fixedRectangle"></param>
        /// <param name="line"></param>
        /// <param name="movingRectangleOffset"></param>
        /// <returns></returns>
        protected List <Tuple <IntVector2, bool> > OverlapAlongLine(GridRectangle movingRectangle, GridRectangle fixedRectangle, OrthogonalLine line, int movingRectangleOffset = 0)
        {
            if (line.GetDirection() != OrthogonalLine.Direction.Right)
            {
                throw new ArgumentException();
            }

            // The smallest rectangle that covers both the first and the last position on the line of the moving rectangle
            var boundingRectangle = new GridRectangle(movingRectangle.A + line.From, movingRectangle.B + line.To);

            // They cannot overlap if the bounding rectangle does not overlap with the fixed one
            if (!DoOverlap(boundingRectangle, fixedRectangle))
            {
                return(new List <Tuple <IntVector2, bool> >());
            }

            var events = new List <Tuple <IntVector2, bool> >();

            if (fixedRectangle.A.X - movingRectangle.Width - movingRectangleOffset <= line.From.X)
            {
                events.Add(Tuple.Create(line.From, true));
            }

            if (fixedRectangle.A.X > line.From.X + movingRectangle.Width + movingRectangleOffset)
            {
                events.Add(Tuple.Create(new IntVector2(fixedRectangle.A.X - movingRectangle.Width + 1 - movingRectangleOffset, line.From.Y), true));
            }

            if (fixedRectangle.B.X - movingRectangleOffset < line.To.X)
            {
                events.Add(Tuple.Create(new IntVector2(fixedRectangle.B.X - movingRectangleOffset, line.From.Y), false));
            }

            return(events);
        }
コード例 #5
0
        public void TestRotation()
        {
            var r = new GridRectangle(0, 0, 2, 1);

            Assert.Equal(0, r.MinX);
            Assert.Equal(0, r.MinY);
            Assert.Equal(1, r.MaxX);
            Assert.Equal(0, r.MaxY);
            r.Rotate(new GridRotation(1));
            Assert.Equal(0, r.MinX);
            Assert.Equal(0, r.MinY);
            Assert.Equal(0, r.MaxX);
            Assert.Equal(1, r.MaxY);
            r.Rotate(new GridRotation(1));
            Assert.Equal(-1, r.MinX);
            Assert.Equal(0, r.MinY);
            Assert.Equal(0, r.MaxX);
            Assert.Equal(0, r.MaxY);
            r.Rotate(new GridRotation(1));
            Assert.Equal(-1, r.MinX);
            Assert.Equal(0, r.MinY);
            Assert.Equal(-1, r.MaxX);
            Assert.Equal(1, r.MaxY);
            r.Rotate(new GridRotation(1, true));
            Assert.Equal(-1, r.MinX);
            Assert.Equal(0, r.MinY);
            Assert.Equal(0, r.MaxX);
            Assert.Equal(0, r.MaxY);
        }
コード例 #6
0
        protected bool DoTouch(GridRectangle rectangle1, GridRectangle rectangle2, int minimumLength)
        {
            var overlapX = Math.Max(-1, Math.Min(rectangle1.B.X, rectangle2.B.X) - Math.Max(rectangle1.A.X, rectangle2.A.X));
            var overlapY = Math.Max(-1, Math.Min(rectangle1.B.Y, rectangle2.B.Y) - Math.Max(rectangle1.A.Y, rectangle2.A.Y));

            if ((overlapX == 0 && overlapY >= minimumLength) || (overlapY == 0 && overlapX >= minimumLength))
            {
                return(true);
            }

            return(false);
        }
コード例 #7
0
            /// <summary>
            /// Returns a GridRectangle for each quarter of this GridRectangle
            /// </summary>
            public GridRectangle[] SplitIntoFour()
            {
                double halfWidth  = _width * 0.5;
                double halfHeight = _height * 0.5;

                var topLeftRect     = new GridRectangle(_x, _y, halfWidth, halfHeight);
                var topRightRect    = new GridRectangle(_x + halfWidth, _y, halfWidth, halfHeight);
                var bottomLeftRect  = new GridRectangle(_x, _y + halfHeight, halfWidth, halfHeight);
                var bottomRightRect = new GridRectangle(_x + halfWidth, _y + halfHeight, halfWidth, halfHeight);

                return(new[] { topLeftRect, topRightRect, bottomLeftRect, bottomRightRect });
            }
コード例 #8
0
ファイル: GridRectangle.cs プロジェクト: abordt/Viking
        public void TestGridRectangle()
        {
            GridRectangle rectA = new GridRectangle(10, 50, 20, 40);

            bool success = rectA.Contains(new GridVector2(10, 20));
            Debug.Assert(success);

            success = rectA.Contains(new GridVector2(50, 40));
            Debug.Assert(success);

            success = rectA.Contains(rectA.Center);
            Debug.Assert(success);

            GridRectangle rectBOverlaps = new GridRectangle(5, 15, 10, 21);
            success = rectA.Intersects(rectBOverlaps);
            Debug.Assert(success);

            success = rectA.Contains(rectBOverlaps);
            Debug.Assert(false == success);

            GridRectangle rectCNoOverlap = new GridRectangle(5, 15, 10, 19);
            success = rectA.Intersects(rectCNoOverlap);
            Debug.Assert(false == success);

            success = rectA.Contains(rectBOverlaps);
            Debug.Assert(false == success);

            GridRectangle rectDContained = new GridRectangle(15, 45, 25, 35);
            success = rectA.Intersects(rectDContained);
            Debug.Assert(success);

            success = rectA.Contains(rectDContained);
            Debug.Assert(success);

            /*Scale the rectangle and test again*/
            rectA.Scale(2);

            Debug.Assert(-10.0 == rectA.Left &&
                         70 == rectA.Right &&
                         10 == rectA.Bottom &&
                         50 == rectA.Top);

            /*Scale the rectangle and test again*/
            rectA.Scale(0.5);

            Debug.Assert(10.0 == rectA.Left &&
                         50 == rectA.Right &&
                         20 == rectA.Bottom &&
                         40 == rectA.Top);
        }
コード例 #9
0
        /// <summary>
        /// Creates increasingly smaller grids by splitting each GridRectangle into four each time
        /// Then returns the central points for each rectangle
        /// </summary>
        /// <param name="iterations"></param>
        private GridRectangle[] GenerateRecursiveRectangles(int iterations)
        {
            var wholeGrid = new GridRectangle(0, 0, 1, 1);

            var rectanglesToSplit = new[] { wholeGrid };

            for (int i = 0; i < iterations; i++)
            {
                var quarters = SplitRectanglesInFour(rectanglesToSplit);
                rectanglesToSplit = quarters;
            }

            return(rectanglesToSplit);
        }
コード例 #10
0
        private List <Vector2Int> GetAllPoints(GridRectangle rectangle)
        {
            var points = new List <Vector2Int>();

            for (int i = 0; i < rectangle.Width; i++)
            {
                for (int j = 0; j < rectangle.Height; j++)
                {
                    points.Add((Vector2Int)(rectangle.A + new IntVector2(i, j)).ToUnityIntVector3());
                }
            }

            return(points);
        }
コード例 #11
0
        public void DoOverlap_IdenticalRectangles_ReturnsTrue()
        {
            {
                // Identical squares
                var r1 = new GridRectangle(new IntVector2(0, 0), new IntVector2(2, 2));
                Assert.AreEqual(true, polygonOverlap.DoOverlap(r1, r1));
            }

            {
                // Identical rectangles
                var r1 = new GridRectangle(new IntVector2(0, 0), new IntVector2(4, 2));
                Assert.AreEqual(true, polygonOverlap.DoOverlap(r1, r1));
            }
        }
コード例 #12
0
        public void DoOverlap_TouchingRectangles_ReturnsFalse()
        {
            {
                // Side-touching squares
                var r1 = new GridRectangle(new IntVector2(0, 0), new IntVector2(2, 2));
                var r2 = r1 + new IntVector2(0, 2);
                Assert.AreEqual(false, polygonOverlap.DoOverlap(r1, r2));
            }

            {
                // Vertex-touching rectangles
                var r1 = new GridRectangle(new IntVector2(0, 0), new IntVector2(6, 3));
                var r2 = new GridRectangle(new IntVector2(6, 3), new IntVector2(10, 6));
                Assert.AreEqual(false, polygonOverlap.DoOverlap(r1, r2));
            }
        }
コード例 #13
0
ファイル: GridTransform.cs プロジェクト: abordt/Viking
        public GridTransform(MappingGridVector2[] points, GridRectangle mappedBounds, int gridSizeX, int gridSizeY, TransformInfo info)
            : base(points, mappedBounds, info)
        {
            GridSizeX = gridSizeX;
            GridSizeY = gridSizeY;

            Array.Sort(points);

            Debug.Assert(points.Length == gridSizeX * gridSizeY, "Invalid argument to GridTransform constructor.  Number of points incorrect");
            if (points.Length != gridSizeX * gridSizeY)
            {
                throw new ArgumentException("GridTransform constructor. Number of points incorrect");
            }

            _TriangleIndicies = GridTransformHelper.TrianglesForGrid(GridSizeX, GridSizeY);
        }
コード例 #14
0
        public void DoOverlap_NonOverlappingRectangles_ReturnsFalse()
        {
            {
                // Non-overlapping squares
                var r1 = new GridRectangle(new IntVector2(0, 0), new IntVector2(2, 2));
                var r2 = r1 + new IntVector2(6, 0);
                Assert.AreEqual(false, polygonOverlap.DoOverlap(r1, r2));
            }

            {
                // Non-overlapping rectangles
                var r1 = new GridRectangle(new IntVector2(0, 0), new IntVector2(6, 3));
                var r2 = new GridRectangle(new IntVector2(7, 4), new IntVector2(10, 6));
                Assert.AreEqual(false, polygonOverlap.DoOverlap(r1, r2));
            }
        }
コード例 #15
0
        /// <summary>
        /// Computes the overlap along a line of a given moving rectangle and a set o fixed rectangles.
        /// </summary>
        /// <param name="movingRectangle"></param>
        /// <param name="fixedRectangles"></param>
        /// <param name="line"></param>
        /// <param name="movingRectangleOffset">Specifies the X-axis offset of a given moving rectangle.</param>
        /// <returns></returns>
        protected List <Tuple <IntVector2, bool> > OverlapAlongLine(GridRectangle movingRectangle, IList <GridRectangle> fixedRectangles, OrthogonalLine line, int movingRectangleOffset = 0)
        {
            if (line.GetDirection() != OrthogonalLine.Direction.Right)
            {
                throw new ArgumentException();
            }

            var events = new List <Tuple <IntVector2, bool> >();

            foreach (var fixedRectangle in fixedRectangles)
            {
                var newEvents = OverlapAlongLine(movingRectangle, fixedRectangle, line, movingRectangleOffset);
                events = MergeEvents(events, newEvents, line);
            }

            return(events);
        }
コード例 #16
0
        public void DoOverlap_OverlappingRectangles_ReturnsTrue()
        {
            {
                // Overlapping squares
                var r1 = new GridRectangle(new IntVector2(0, 0), new IntVector2(2, 2));
                var r2 = r1 + new IntVector2(1, 0);
                Assert.AreEqual(true, polygonOverlap.DoOverlap(r1, r2));
            }

            {
                // Overlapping rectangles
                var r1 = new GridRectangle(new IntVector2(4, 5), new IntVector2(10, 7));
                var r2 = new GridRectangle(new IntVector2(5, 6), new IntVector2(12, 10));
                Assert.AreEqual(true, polygonOverlap.DoOverlap(r1, r2));
            }

            {
                // A rectangle inside another rectangle
                var r1 = new GridRectangle(new IntVector2(1, 1), new IntVector2(5, 6));
                var r2 = new GridRectangle(new IntVector2(2, 2), new IntVector2(4, 5));
                Assert.AreEqual(true, polygonOverlap.DoOverlap(r1, r2));
            }
        }
コード例 #17
0
ファイル: TransfromFactory.cs プロジェクト: abordt/Viking
        /// <summary>
        /// This code was reverse engineered from original stos polynomial transform source
        /// </summary>
        /// <param name="parts"></param>
        /// <param name="pixelSpacing"></param>
        /// <param name="iFixedParameters"></param>
        /// <param name="iVariableParameters"></param>
        /// <param name="MappedBounds"></param>
        /// <returns></returns>
        public static List<MappingGridVector2> ParsePolyTransform(TransformParameters transform , float pixelSpacing, int iFixedParameters, int iVariableParameters, GridRectangle MappedBounds)
        {
            if (transform == null)
                throw new ArgumentNullException();

            List<MappingGridVector2> mappings = new List<MappingGridVector2>();

            float MappedWidth = (float)MappedBounds.Width;
            float MappedHeight = (float)MappedBounds.Height;

            int numParams = transform.variableParameters.Length;

            double uc = transform.fixedParameters[0];
            double vc = transform.fixedParameters[1];
            double xmax = transform.fixedParameters[2];
            double ymax = transform.fixedParameters[3];

            uc = xmax / 2.0;
            vc = ymax / 2.0;

            int gridHeight = 5;
            int gridWidth = 5;

            int NumPts = (int)(gridHeight * gridWidth);

            GridVector2[] Points = new GridVector2[NumPts];

            for (int iY = 0; iY < gridHeight; iY++)
            {
                for (int iX = 0; iX < gridWidth; iX++)
                {
                    double u = (xmax / (double)(gridWidth-1)) * (double)iX;
                    double v = (ymax / (double)(gridHeight-1)) * (double)iY;

                    double A = (u - uc) / xmax;
                    double B = (v - vc) / ymax;

                    //For some reason I am off by a factor of two:
                    A *= 2;
                    B *= 2;

                    double[] P = new double[Dimensions + 1];
                    double[] Q = new double[Dimensions + 1];

                    for (int i = 0; i <= Dimensions; i++)
                    {
                        P[i] = Legendre.P[i](A);
                        Q[i] = Legendre.P[i](B);
                    }

                    double Sa = 0.0;
                    double Sb = 0.0;

                    for (int i = 0; i <= Dimensions; i++)
                    {
                        for (int j = 0; j <= i; j++)
                        {
                            int k = i - j;
                            double PjQk = P[j] * Q[k];
                            Sa += transform.variableParameters[index_a(j, k)] * PjQk;
                            Sb += transform.variableParameters[index_b(j, k)] * PjQk;
                        }
                    }

                    Points[(iY * gridWidth) + iX] = new GridVector2((xmax * Sa * pixelSpacing), (ymax * Sb * pixelSpacing));
                }
            }

            for (int y = 0; y < gridHeight; y++)
            {
                for (int x = 0; x < gridWidth; x++)
                {
                    int i = x + (y * gridWidth);
                    GridVector2 controlPoint = Points[i];
                    GridVector2 mappedPoint = GridTransform.CoordinateFromGridPos(x, y, gridWidth, gridHeight, MappedWidth, MappedHeight);

                    mappings.Add(new MappingGridVector2(controlPoint, mappedPoint));
                }
            }

            return mappings;
        }
コード例 #18
0
 protected bool IsInGrid()
 {
     return(GridRectangle.Contains(Range));
 }
コード例 #19
0
ファイル: GridTransform.cs プロジェクト: abordt/Viking
        public static MappingGridTriangle TriangleForPoint(int GridSizeX, int GridSizeY, GridRectangle Bounds, MappingGridVector2[] points, int[] TriIndicies, GridVector2 Point)
        {
            //Having a smaller epsilon caused false positives.
            //We just want to know if we are close enough to check with the more time consuming math
            double epsilon = 5;

            if (Point.X < Bounds.Left - epsilon)
                return null;
            if (Point.X > Bounds.Right + epsilon)
                return null;
            if (Point.Y > Bounds.Top + epsilon)
                return null;
            if (Point.Y < Bounds.Bottom - epsilon)
                return null;

            double OffsetX = Point.X - Bounds.Left;
            double OffsetY = Point.Y - Bounds.Bottom;

            double X = (OffsetX / Bounds.Width) * (GridSizeX-1);
            double Y = (OffsetY / Bounds.Height) * (GridSizeY-1);

            int iX = (int)X;
            int iY = (int)Y;

            //This gives us the grid coordinates which contains two triangles, however there are two triangles.  If the fractional parts add up to a number greater than one it is the upper triangle.
            bool IsUpper = (X - iX) + (Y - iY) > 1;

            //Check edge case where point is exactly on the right edge of the boundary
            if (OffsetX + double.Epsilon >= Bounds.Width )
            {
                IsUpper = true;
                iX--;
            }
            else if (OffsetY + double.Epsilon >= Bounds.Height)
            {
                IsUpper = true;
                iY--;
            }
            else
            {
                IsUpper = (X - iX) + (Y - iY) > 1;
            }

            int iTri = (iY * 2) + ((GridSizeY-1) * 2 * iX);
            //int iTri = (iX * 2) + ((GridSizeX-1) * 2 * iY);
            iTri += IsUpper ? 1:0;
            iTri *= 3;//Multiply by three to get the triangle offset

            MappingGridTriangle mapTri = new MappingGridTriangle(points, TriIndicies[iTri], TriIndicies[iTri + 1], TriIndicies[iTri + 2]);

            Debug.Assert(mapTri.IntersectsMapped(Point), "Calculated GridTransform does not intersect requested point");
            return mapTri;
        }
コード例 #20
0
ファイル: TransfromFactory.cs プロジェクト: abordt/Viking
        public static TransformBase ParseStos(Stream stream, StosTransformInfo info, int pixelSpacing)
        {
            string[] lines = StreamUtil.StreamToLines(stream);
            string[] controlDims = lines[4].Split(new char[] { ' ','\t'}, StringSplitOptions.RemoveEmptyEntries);
            string[] mappedDims = lines[5].Split(new char[] { ' ','\t' }, StringSplitOptions.RemoveEmptyEntries);

            GridRectangle ControlBounds = new GridRectangle();
            GridRectangle MappedBounds= new GridRectangle();

            ControlBounds.Left = (System.Convert.ToDouble(controlDims[0]) * pixelSpacing);
            ControlBounds.Bottom = (System.Convert.ToDouble(controlDims[1]) * pixelSpacing);
            ControlBounds.Right = ControlBounds.Left + (System.Convert.ToDouble(controlDims[2]) * pixelSpacing);
            ControlBounds.Top = ControlBounds.Bottom + (System.Convert.ToDouble(controlDims[3]) * pixelSpacing);

            MappedBounds.Left = (int)(System.Convert.ToDouble(mappedDims[0]) * pixelSpacing);
            MappedBounds.Bottom = (int)(System.Convert.ToDouble(mappedDims[1]) * pixelSpacing);
            MappedBounds.Right = ControlBounds.Left + (int)(System.Convert.ToDouble(mappedDims[2]) * pixelSpacing);
            MappedBounds.Top = ControlBounds.Bottom + (int)(System.Convert.ToDouble(mappedDims[3]) * pixelSpacing);

            //Check the parts to make sure they are actually numbers
            TransformParameters transform_parts = TransformParameters.Parse(lines[6]);

            Debug.Assert(transform_parts.fixedParameters.Length > 0 && transform_parts.variableParameters.Length > 0, "StosGridTransform::ParseGridTransform");

            switch (transform_parts.transform_name.ToLower())
            {
                case "gridtransform_double_2_2":
                    //return ParseGridTransform(parts, info, (float)pixelSpacing, iFixedParameters, iVariableParameters, ControlBounds, MappedBounds);
                    return ParseGridTransform(transform_parts, pixelSpacing, info);
                case "legendrepolynomialtransform_double_2_2_3":
                    throw new NotImplementedException("stos transform not supported: legendrepolynomialtransform_double_2_2_3");
                    //MapPoints = ParsePolyTransform(parts, (float)pixelSpacing, iFixedParameters, iVariableParameters, MappedBounds).ToArray();
                case "fixedcenterofrotationaffinetransform_double_2_2":
                    throw new NotImplementedException("stos transform not supported: fixedcenterofrotationaffinetransform_double_2_2");
                    //MapPoints = ParseRotateTranslateAffineTransform(parts, (float)pixelSpacing, iFixedParameters, iVariableParameters, MappedBounds, ControlBounds).ToArray();
                case "meshtransform_double_2_2":
                    return ParseMeshTransform(transform_parts, info, pixelSpacing);
                default:
                    Debug.Assert(false, "Trying to read stos tranform I don't understand");
                    return null;
            }
        }
コード例 #21
0
ファイル: TransfromFactory.cs プロジェクト: abordt/Viking
        public static ReadOnlyCollection<MappingGridVector2> ParseRotateTranslateAffineTransform(string[] parts,
            float pixelSpacing,
            int iFixedParameters,
            int iVariableParameters,
            GridRectangle MappedBounds, 
            GridRectangle ControlBounds)
        {
            //Find the dimensions of the grid
            List<MappingGridVector2> mappings = new List<MappingGridVector2>();
            /*
            GridVector2[] Points = new GridVector2[4];
            GridVector2[] mappedPoints = new GridVector2[4];
            GridVector2[] ctrlPoints = new GridVector2[4];

            Points[0] = new GridVector2(0, 0);
            Points[1] = new GridVector2(MappedBounds.Width, 0);
            Points[2] = new GridVector2(0, MappedBounds.Height);
            Points[3] = new GridVector2(MappedBounds.Width, MappedBounds.Height);

            ctrlPoints[0] = new GridVector2(0, 0);
            ctrlPoints[1] = new GridVector2(ControlBounds.Width, 0);
            ctrlPoints[2] = new GridVector2(0, ControlBounds.Height);
            ctrlPoints[3] = new GridVector2(ControlBounds.Width, ControlBounds.Height);

            Matrix mat = Matrix.Identity;
            mat.M11 = System.Convert.ToSingle(parts[iVariableParameters + 2]);
            mat.M12 = System.Convert.ToSingle(parts[iVariableParameters + 3]);
            mat.M21 = System.Convert.ToSingle(parts[iVariableParameters + 4]);
            mat.M22 = System.Convert.ToSingle(parts[iVariableParameters + 5]);

            //Cheating: since the rotation matrix is
            //[cos(t) -sin(t)]
            //[sin(t)  cos(t)]
            //we just take the asin of the parameter to find the rotation value

            //            double theta = Math.Acos(System.Convert.ToSingle(parts[iVariableParameters + 2]));

            //Matrix mat = Matrix.CreateRotationZ((float)theta);

            mappedPoints[0] = Vector2.Transform(Points[0], mat);
            mappedPoints[1] = Vector2.Transform(Points[1], mat);
            mappedPoints[2] = Vector2.Transform(Points[2], mat);
            mappedPoints[3] = Vector2.Transform(Points[3], mat);

            Triangle controlOne = new Triangle(ctrlPoints[0], ctrlPoints[1], ctrlPoints[2]);
            Triangle controlTwo = new Triangle(ctrlPoints[2], ctrlPoints[1], ctrlPoints[3]);
            Triangle mappedOne = new Triangle(mappedPoints[0], mappedPoints[1], mappedPoints[2]);
            Triangle mappedTwo = new Triangle(mappedPoints[2], mappedPoints[1], mappedPoints[3]);

            mappings.Add(new MappingTriangle(controlOne, mappedOne));
            mappings.Add(new MappingTriangle(controlTwo, mappedTwo));
            */
            return new ReadOnlyCollection<MappingGridVector2>(mappings);
        }
コード例 #22
0
        /// <summary>
        /// Translates all verticies in the tile according to the vector
        /// </summary>
        /// <param name="vector"></param>
        public override void Translate(GridVector2 vector)
        {
            for (int i = 0; i < MapPoints.Length; i++)
            {
                MapPoints[i].ControlPoint += vector;
            }

            //Remove any cached data structures
            //MinimizeMemory();

            ControlBounds = new GridRectangle(ControlBounds.Left + vector.X,
                                              ControlBounds.Right + vector.X,
                                              ControlBounds.Bottom + vector.Y,
                                              ControlBounds.Top + vector.Y);
        }
コード例 #23
0
ファイル: TransfromFactory.cs プロジェクト: abordt/Viking
        private static GridTransform ParseGridTransform(TransformParameters transform, double PixelSpacing, TransformInfo info)
        {
            //string filename = System.IO.Path.GetFileName(parts[1]);
            //string[] fileparts = filename.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
            //this.Number = System.Convert.ToInt32(fileparts[1]);

            int gridWidth = System.Convert.ToInt32(transform.fixedParameters[2] + 1.0);
            int gridHeight = System.Convert.ToInt32(transform.fixedParameters[1] + 1.0);

            int ImageWidth = System.Convert.ToInt32(transform.fixedParameters[5] * PixelSpacing);
            int ImageHeight = System.Convert.ToInt32(transform.fixedParameters[6] * PixelSpacing);

            GridRectangle MappedBounds = new GridRectangle(0, ImageWidth, 0, ImageHeight);

            int NumPts = transform.variableParameters.Length / 2;
            GridVector2[] Points = new GridVector2[NumPts];

            //           verticies = new VertexPositionNormalTexture[numPts];

            Double minX = Double.MaxValue;
            Double minY = Double.MaxValue;
            Double maxX = Double.MinValue;
            Double maxY = Double.MinValue;

            //Every number in the array is seperated by an empty space in the array
            for (int i = 0; i < NumPts; i++)
            {
                int iPoint = (i * 2);
                Double x = transform.variableParameters[iPoint] * PixelSpacing;
                Double y = transform.variableParameters[iPoint+1] * PixelSpacing;

                Points[i] = new GridVector2(x, y);

                //Trace.WriteLine(x.ToString() + ", " + y.ToString(), "Geometry");
                if (x < minX)
                    minX = x;
                if (x > maxX)
                    maxX = x;
                if (y < minY)
                    minY = y;
                if (y > maxY)
                    maxY = y;
            }

            //            List<int> indicies = new List<int>();
            MappingGridVector2[] mapList = new MappingGridVector2[gridHeight * gridWidth];
            List<int> triangleIndicies = new List<int>();

            for (int y = 0; y < gridHeight; y++)
            {
                for (int x = 0; x < gridWidth; x++)
                {
                    int i = x + (y * gridWidth);

                    GridVector2 mapPoint = GridTransform.CoordinateFromGridPos(x, y, gridWidth, gridHeight, ImageWidth,ImageHeight);
                    GridVector2 ctrlPoint = Points[i];

                    MappingGridVector2 gridPoint = new MappingGridVector2(ctrlPoint, mapPoint);
                    mapList[i] = gridPoint;
                }
            }

            for (int y = 0; y < gridHeight - 1; y++)
            {
                for (int x = 0; x < gridWidth - 1; x++)
                {
                    int botLeft = x + (y * gridWidth);
                    int botRight = (x + 1) + (y * gridWidth);
                    int topLeft = x + ((y + 1) * gridWidth);
                    int topRight = (x + 1) + ((y + 1) * gridWidth);

                    int[] triangles = new int[] { botLeft, botRight, topLeft, botRight, topRight, topLeft };
                    triangleIndicies.AddRange(triangles);
                }
            }

            return new GridTransform(mapList, MappedBounds, gridWidth, gridHeight, info);
        }
コード例 #24
0
ファイル: QuadTreeTest.cs プロジェクト: abordt/Viking
        public void QuadTreeTestOne()
        {
            GridVector2[] points = new GridVector2[] { new GridVector2(0,0),
                                                       new GridVector2(1,1),
                                                       new GridVector2(-10,-10),
                                                       new GridVector2(-7.5, 2.5),
                                                       new GridVector2(8.5, -1.5),
                                                       new GridVector2(3.5, -6.5),
                                                       new GridVector2(1.5, -8.5),
                                                       new GridVector2(10, 10)};
            int[] values = new int[] {0,1,2,3,4,5,6,7};
            GridRectangle border = GridVector2.Border(points);
            QuadTree<int> tree = new QuadTree<int>(points, values, border);

            //Start with a basic test ensuring we can find all the existing points
            for(int i = 0; i < points.Length; i++)
            {
                double distance;
                int RetValue;
                RetValue = tree.FindNearest(points[i], out distance);

                Debug.Assert(RetValue == i);
                Debug.Assert(distance == 0);
            }

            //Check to see if we can find nearby points
            GridVector2[] nearpoints = new GridVector2[] { new GridVector2(.25,.25),
                                                       new GridVector2(.5,.51),
                                                       new GridVector2(-7.5,-7.5),
                                                       new GridVector2(-7.5, -1.5),
                                                       new GridVector2(8.5, -5.5),
                                                       new GridVector2(4.5, -7.75),
                                                       new GridVector2(1, -8.75),
                                                       new GridVector2(11, 11)}; //Out of original boundaries

            for (int i = 0; i < nearpoints.Length; i++)
            {
                double distance;
                int RetValue;
                RetValue = tree.FindNearest(nearpoints[i], out distance);

                Debug.Assert(RetValue == i);
                Debug.Assert(distance == GridVector2.Distance(points[i], nearpoints[i]));
            }

            //Check to see if we can return all points in a rectangle
            GridRectangle gridRect = new GridRectangle(0,15, 0,15);
            List<GridVector2> intersectPoints;
            List<int> intersectValues;
            tree.Intersect(gridRect, out intersectPoints, out intersectValues);
            Debug.Assert(intersectValues.Contains(0));
            Debug.Assert(intersectValues.Contains(1));
            Debug.Assert(intersectValues.Contains(7));

            Debug.Assert(false == intersectValues.Contains(2));
            Debug.Assert(false == intersectValues.Contains(3));
            Debug.Assert(false == intersectValues.Contains(4));
            Debug.Assert(false == intersectValues.Contains(5));
            Debug.Assert(false == intersectValues.Contains(6));
        }
コード例 #25
0
 protected ReferencePointBasedTransform(MappingGridVector2[] points, GridRectangle mappedBounds, TransformInfo info)
     : this(points, info)
 {
     this.MappedBounds = mappedBounds;
 }
コード例 #26
0
 /// <summary>
 /// Checks if two rectangles overlap.
 /// </summary>
 /// <param name="rectangle1"></param>
 /// <param name="rectangle2"></param>
 /// <returns></returns>
 public bool DoOverlap(GridRectangle rectangle1, GridRectangle rectangle2)
 {
     return(rectangle1.A.X < rectangle2.B.X && rectangle1.B.X > rectangle2.A.X && rectangle1.A.Y < rectangle2.B.Y && rectangle1.B.Y > rectangle2.A.Y);
 }
コード例 #27
0
ファイル: TransfromFactory.cs プロジェクト: abordt/Viking
        private static GridTransform ParseGridTransform(TransformParameters transform,
                                                                StosTransformInfo info,
                                                                float pixelSpacing, 
                                                                int iFixedParameters,
                                                                int iVariableParameters,
                                                                GridRectangle ControlBounds,
                                                                GridRectangle MappedBounds)
        {
            //Find the dimensions of the grid
            MappingGridVector2[] mappings;

            float MappedWidth = (float)MappedBounds.Width;
            float MappedHeight = (float)MappedBounds.Height;

            int gridWidth = System.Convert.ToInt32(transform.fixedParameters[2] + 1.0);
            int gridHeight = System.Convert.ToInt32(transform.fixedParameters[1] + 1.0);
            double NumPts = gridHeight * gridWidth;

            mappings = new MappingGridVector2[gridWidth * gridHeight];
            GridVector2[] Points = new GridVector2[System.Convert.ToInt32(NumPts)];

            int iPoints = iVariableParameters + 2;

            for (int i = 0; i < NumPts; i++)
            {
                Points[i].X = transform.variableParameters[i*2] * pixelSpacing;
                Points[i].Y = transform.variableParameters[(i * 2) + 1] * pixelSpacing;
            }

            for (int y = 0; y < gridHeight; y++)
            {
                int iYOffset = y * gridWidth;
                for (int x = 0; x < gridWidth; x++)
                {
                    int i = x + iYOffset;
                    GridVector2 controlPoint = Points[i];
                    GridVector2 mappedPoint = GridTransform.CoordinateFromGridPos(x, y, gridWidth, gridHeight, MappedWidth, MappedHeight);

                    mappings[i] = new MappingGridVector2(controlPoint, mappedPoint);
                }
            }

            return new GridTransform(mappings, MappedBounds, gridWidth, gridHeight, info);
        }