Ejemplo n.º 1
0
        public static GridRectangle CalculateControlBounds(ReferencePointBasedTransform[] transforms)
        {
            if (transforms == null || transforms.Length == 0)
                return new GridRectangle();

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

            foreach (ReferencePointBasedTransform T in transforms)
            {
                GridRectangle R = T.ControlBounds;

                if (R.Left < minX)
                    minX = R.Left;
                if (R.Right > maxX)
                    maxX = R.Right;
                if (R.Bottom < minY)
                    minY = R.Bottom;
                if (R.Top > maxY)
                    maxY = R.Top;
            }

            return new GridRectangle(minX, maxX, minY, maxY);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Load mosaic from specified file and add it to transforms list using specified key
        /// </summary>
        /// <param name="file"></param>
        /// <param name="Key"></param>
        public static ReferencePointBasedTransform[] LoadMosaic(string path, string[] mosaic, DateTime lastModified)
        {
            if (mosaic == null || path == null)
                throw new ArgumentNullException();

            string[] parts;
            int numTiles = 0;
             //           double PixelSpacing;

            int formatVersion = 0;
            int iTileStart = 3;
            for (int i = 0; i < mosaic.Length; i++)
            {
                string line = mosaic[i];
                if (line.StartsWith("format_version_number:"))
                {
                    parts = line.Split(':');
                    formatVersion = System.Convert.ToInt32(parts[1]);
                }
                if (line.StartsWith("number_of_images:"))
                {
                    parts = line.Split(':');
                    numTiles = System.Convert.ToInt32(parts[1]);
                }
                if (line.StartsWith("pixel_spacing:"))
                {
                    parts = line.Split(':');
                //    PixelSpacing = System.Convert.ToDouble(parts[1]);
                }
                if (line.StartsWith("image:"))
                {
                    iTileStart = i;
                    break;
                }
            }

            Trace.WriteLine("Loading " + numTiles.ToString() + " tiles", "Geometry");
            ReferencePointBasedTransform[] tileTransforms = new ReferencePointBasedTransform[numTiles];

            int iTile = 0;

            if (formatVersion == 0)
            {

                for (int i = iTileStart; i < mosaic.Length; i++)
                {
                    string Transform = mosaic[i];
                    //Trace.WriteLine(line, "Geometry");

                    //Get the second entry which is the file name
                    string[] transformParts = Transform.Split(new char[] { ' ' }, 3, StringSplitOptions.RemoveEmptyEntries);

                    string TileFileName = transformParts[1];
                    //Make sure we don't pull in the full path
                    TileFileName = System.IO.Path.GetFileName(TileFileName);

                    string[] TileNameParts = TileFileName.Split(new char[] { '.' }, 3, StringSplitOptions.RemoveEmptyEntries);

                    int iTileNumber = 0;
                    //Viking originally used a format with section.number.png, but Iris may write number.png instead
                    if (TileNameParts.Length == 3)
                    {
                        iTileNumber = System.Convert.ToInt32(TileNameParts[1]);
                    }
                    else
                    {
                        iTileNumber = System.Convert.ToInt32(TileNameParts[0]);
                    }

                    //Crop the tile file name fron the Transform string
                    int iFileName = Transform.IndexOf(TileFileName);
                    Transform = Transform.Remove(0, iFileName + TileFileName.Length);

                    ReferencePointBasedTransform newTGT = ParseMosaicTileEntry(Transform, null);
                    TileTransformInfo info = new TileTransformInfo(TileFileName, iTileNumber, lastModified, newTGT.MappedBounds.Width, newTGT.MappedBounds.Height);
                    newTGT.Info = info;

                    //GridTransform newTGT = new GridTransform(path, Transform, new TileTransformInfo(TileFileName, iTileNumber, lastModified));

                    tileTransforms[iTile++] = newTGT;
                    //tileTransforms.Add(newTGT);
                }
            }
            else if (formatVersion == 1)
            {
                for (int i = iTileStart; i < mosaic.Length; i += 3)
                {
                    string TileFileName = mosaic[i + 1];
                    string Transform = mosaic[i + 2];
                    //Trace.WriteLine(line, "Geometry");

                    //Make sure we don't pull in the full path
                    TileFileName = System.IO.Path.GetFileName(TileFileName);
                    string[] TileNameParts = TileFileName.Split(new char[] { '.' }, 3, StringSplitOptions.RemoveEmptyEntries);
                    int iTileNumber = 0;

                    try
                    {
                        //Viking originally used a format with section.number.png, but Iris may write number.png instead
                        if (TileNameParts.Length == 3)
                        {
                            iTileNumber = System.Convert.ToInt32(TileNameParts[1]);
                        }
                        else
                        {
                            iTileNumber = System.Convert.ToInt32(TileNameParts[0]);
                        }
                    }
                    catch (System.FormatException)
                    {
                        iTileNumber = i;
                    }

                    //Get the second entry which is the transform
                    ReferencePointBasedTransform newTGT = ParseMosaicTileEntry(Transform, null);
                    TileTransformInfo info = new TileTransformInfo(TileFileName, iTileNumber, lastModified, newTGT.MappedBounds.Width, newTGT.MappedBounds.Height);
                    newTGT.Info = info;

                    //string[] transformParts = Transform.Split(new char[] { ' ' }, 3, StringSplitOptions.RemoveEmptyEntries);
                    //TileGridTransform newTGT = new TileGridTransform(path, Transform, new TileTransformInfo(TileFileName, iTileNumber, lastModified));

                    tileTransforms[iTile++] = newTGT;
                    //tileTransforms.Add(newTGT);
                }
            }
            else
            {
                Debug.Assert(false, "Unknown format version in mosaic file");
                return new GridTransform[0];
            }

            /*
             * Don't translate mosaics to 0,0 origin because the buildscripts do it automatically and the mosaic to volume transforms are broken by the translation
            GridRectangle R = ReferencePointBasedTransform.CalculateControlBounds(tileTransforms as ReferencePointBasedTransform[]);

            foreach (TransformBase T in tileTransforms)
            {
                //Adjusting to center here breaks vclume tranformation since volume transforms assume mosaic origin of 0,0
                T.Translate(new GridVector2(-R.Left, -R.Bottom));
            }
            */

            //Add transform list to our collection of transforms
            return tileTransforms;
        }