Beispiel #1
0
        public static TransformParameters Parse(string transform)
        {
            TransformParameters parameters = new TransformParameters();

            string[] transform_parts = transform.Split(new Char[] {' '}, StringSplitOptions.RemoveEmptyEntries);

            parameters.transform_name = transform_parts[0];

            long iWord = 1;

            while(iWord < transform_parts.Length)
            {
                if (transform_parts[iWord].ToLower() == "vp")
                {
                    ++iWord;
                    parameters.variableParameters = ReadParameterValues(transform_parts, iWord);
                    iWord += parameters.variableParameters.Length+1;
                }
                else if (transform_parts[iWord].ToLower() == "fp")
                {
                    ++iWord;
                    parameters.fixedParameters = ReadParameterValues(transform_parts, iWord);
                    iWord += parameters.fixedParameters.Length+1;
                }
                else
                {
                    iWord++;
                }
            }

            return parameters;
        }
Beispiel #2
0
        private static ReferencePointBasedTransform ParsePolyTransform(TransformParameters transform, 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]);

            //Figure out tile size
            int ImageWidth = System.Convert.ToInt32(transform.fixedParameters[2]) * 2;
            int ImageHeight = System.Convert.ToInt32(transform.fixedParameters[3]) * 2;

            //The poly transform parameters dictate the center of the image
            double x = transform.fixedParameters[0] - (ImageWidth / 2.0);
            double y = transform.fixedParameters[1] - (ImageHeight / 2.0);

            GridVector2 ctrlBotLeft = new GridVector2(x, y);
            GridVector2 ctrlBotRight = new GridVector2(x + ImageWidth, y);
            GridVector2 ctrlTopLeft = new GridVector2(x, y + ImageHeight);
            GridVector2 ctrlTopRight = new GridVector2(x + ImageWidth, y + ImageHeight);

            GridVector2 mapBotLeft = new GridVector2(0, 0);
            GridVector2 mapBotRight = new GridVector2(ImageWidth, 0);
            GridVector2 mapTopLeft = new GridVector2(0, ImageHeight);
            GridVector2 mapTopRight = new GridVector2(ImageWidth, ImageHeight);

            MappingGridVector2 BotLeft = new MappingGridVector2(ctrlBotLeft, mapBotLeft);
            MappingGridVector2 BotRight = new MappingGridVector2(ctrlBotRight, mapBotRight);
            MappingGridVector2 TopLeft = new MappingGridVector2(ctrlTopLeft, mapTopLeft);
            MappingGridVector2 TopRight = new MappingGridVector2(ctrlTopRight, mapTopRight);

            MappingGridVector2[] MapPoints = new MappingGridVector2[] { BotLeft, BotRight, TopLeft, TopRight };

            return new GridTransform(MapPoints, new GridRectangle(0, ImageWidth, 0, ImageHeight), 2, 2, info);
        }
Beispiel #3
0
        private static ReferencePointBasedTransform ParseTranslateTransform(TransformParameters transform, TransformInfo info)
        {
            if (transform == null)
                throw new ArgumentNullException("transform");

            //string filename = System.IO.Path.GetFileName(parts[1]);

            //Figure out tile size if we haven't already
            int ImageWidth = System.Convert.ToInt32(transform.fixedParameters[2]) * 2;
            int ImageHeight = System.Convert.ToInt32(transform.fixedParameters[3]) * 2;

            double x = transform.variableParameters[0];
            double y = transform.variableParameters[1];

            GridVector2 ctrlBotLeft = new GridVector2(x, y);
            GridVector2 ctrlBotRight = new GridVector2(x + ImageWidth, y);
            GridVector2 ctrlTopLeft = new GridVector2(x, y + ImageHeight);
            GridVector2 ctrlTopRight = new GridVector2(x + ImageWidth, y + ImageHeight);

            GridVector2 mapBotLeft = new GridVector2(0, 0);
            GridVector2 mapBotRight = new GridVector2(ImageWidth, 0);
            GridVector2 mapTopLeft = new GridVector2(0, ImageHeight);
            GridVector2 mapTopRight = new GridVector2(ImageWidth, ImageHeight);

            MappingGridVector2 BotLeft = new MappingGridVector2(ctrlBotLeft, mapBotLeft);
            MappingGridVector2 BotRight = new MappingGridVector2(ctrlBotRight, mapBotRight);
            MappingGridVector2 TopLeft = new MappingGridVector2(ctrlTopLeft, mapTopLeft);
            MappingGridVector2 TopRight = new MappingGridVector2(ctrlTopRight, mapTopRight);

            MappingGridVector2[] mapPoints = new MappingGridVector2[] { BotLeft, BotRight, TopLeft, TopRight };

            return new GridTransform(mapPoints, new GridRectangle(0, ImageWidth, 0, ImageHeight), 2, 2, info);
        }
Beispiel #4
0
        private static MeshTransform ParseMeshTransform(TransformParameters transform, TransformInfo info, double PixelSpacing= 1.0 )
        {
            int NumVariableParameters = transform.variableParameters.Length;
            Debug.Assert(NumVariableParameters % 4 == 0);
            int NumPoints = NumVariableParameters / 4;

            double Left = System.Convert.ToInt32(transform.fixedParameters[3] * PixelSpacing);
            double Bottom = System.Convert.ToInt32(transform.fixedParameters[4] * PixelSpacing);
            double ImageWidth = System.Convert.ToInt32(transform.fixedParameters[5] * PixelSpacing);
            double ImageHeight = System.Convert.ToInt32(transform.fixedParameters[6] * PixelSpacing);

            MappingGridVector2[] Points = new MappingGridVector2[NumPoints];

            for (int iP = 0; iP < NumPoints; iP++)
            {
                int iOffset = (iP * 4);
                GridVector2 Mapped = new GridVector2((transform.variableParameters[iOffset] * ImageWidth) + Left,
                                                     (transform.variableParameters[iOffset+1] * ImageHeight) + Bottom);
                GridVector2 Control = new GridVector2(transform.variableParameters[iOffset+2] * PixelSpacing,
                                                     transform.variableParameters[iOffset+3] * PixelSpacing);

                Points[iP] = new MappingGridVector2(Control, Mapped);
            }

            return new MeshTransform(Points, info);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
 private static GridTransform ParseGridTransform(TransformParameters transform, TransformInfo info)
 {
     return ParseGridTransform(transform, 1, info);
 }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        /// <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;
        }