Example #1
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);
        }
Example #2
0
        public static TransformBase ParseStos(Uri stosURI, XElement elem, System.Net.NetworkCredential UserCredentials)
        {
            if (elem == null || stosURI == null)
                throw new ArgumentNullException();

            int pixelSpacing = System.Convert.ToInt32(Utils.IO.GetAttributeCaseInsensitive(elem,"pixelSpacing").Value);

            int MappedSection = System.Convert.ToInt32(IO.GetAttributeCaseInsensitive(elem, "mappedSection").Value);
            int ControlSection = System.Convert.ToInt32(IO.GetAttributeCaseInsensitive(elem, "controlSection").Value);

            System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.CreateDefault(stosURI);
            if (stosURI.Scheme.ToLower() == "https")
                request.Credentials = UserCredentials;

            request.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.Revalidate);
            request.AutomaticDecompression = System.Net.DecompressionMethods.Deflate | System.Net.DecompressionMethods.GZip;

            try
            {
                using (System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse())
                {
                    StosTransformInfo info = null;
                    info = new StosTransformInfo(ControlSection, MappedSection, response.LastModified);

                    Trace.WriteLine(stosURI.ToString() + " From Cache: " + response.IsFromCache.ToString() + " Modified: " + info.LastModified.ToString(), "Geometry");
                    using (Stream stream = response.GetResponseStream())
                    {
                        return ParseStos(stream, info, pixelSpacing);
                    }
                }
            }
            catch (System.Net.WebException e)
            {
                Trace.WriteLine(stosURI.ToString() + " could not be loaded", "Geometry");
                return null;
            }
        }
Example #3
0
        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;
            }
        }
Example #4
0
        public static TransformBase ParseStos(string stosfile)
        {
            string filename = Path.GetFileNameWithoutExtension(stosfile);

            int pixelSpacing = 1;

            //this.LastModified = System.IO.File.GetCreationTime(stosfile);

            //Find out if the name ends in a number indicating the pixel spacing
            //Expecting format: ####-####_grid_##.stos
            string[] fileparts = filename.Split(new char[] { '-', '_' });
            int MappedSection = System.Convert.ToInt32(fileparts[0]);
            int ControlSection = System.Convert.ToInt32(fileparts[1]);

            StosTransformInfo Info = new StosTransformInfo(ControlSection, MappedSection, System.IO.File.GetLastWriteTimeUtc(stosfile));

            //File format may not contain downsample number, if it does record the value

            if (fileparts.Length >= 4)
            {
                pixelSpacing = System.Convert.ToInt32(fileparts[3]);
            }

            using (Stream transformStream = File.OpenRead(stosfile))
            {
                TransformBase transform = ParseStos(transformStream, Info, pixelSpacing);

                return transform;
            }
        }