Esempio n. 1
0
 public void AddSpinousProcessDescription(string key, SpinousProcessDescription state)
 {
     if (state != null)
     {
         state.Direction = this.direction;
         spinousprocessdecriptions[key] = state;
     }
 }
Esempio n. 2
0
        public static SpineStorage ReadFromFile(string filename)
        {
            var storage = new SpineStorage();

            string       text = null;
            StreamReader file = null;

            try
            {
                file = new StreamReader(filename);
                text = file.ReadToEnd();
                logger.Info("Read storage file - {0}", filename);
            }
            catch (FileNotFoundException e)
            {
                text = "";
                logger.Error(e, "File not found - {0}", filename);
            }
            finally {
                if (file != null)
                {
                    file.Close();
                }
            }

            XDocument doc = new XDocument();

            try
            {
                doc = XDocument.Parse(text);

                var root = doc.Element("storage");


                #region Window Parameters

                var window_params = ParseWindowParameters(root.Element("window"));
                storage.windowCenter = window_params.Item1;
                storage.windowWidth  = window_params.Item2;


                #endregion

                #region Direction Parameters

                storage.direction = ParseDirectionParameters(root.Element("direction"));

                storage.imageDirection = ParseImageDirectionParameters(root.Element("imageDirection"));

                var angle = ParseAngleParameters(root.Element("angle"));
                storage.SetRotatingAngle(angle);

                #endregion

                #region Marker Points

                var markers = ParseMarkers(root.Element("markers"));

                for (int i = 0; i < markers.Count; i++)
                {
                    var point = new Point(markers[i].Item1, markers[i].Item2);
                    storage.SetMarkerPoint(i, point);
                }

                #endregion

                #region Marker Line

                var markerl = ParseMarkerLine(root.Element("markerline"));

                storage.MarkerLine   = markerl.Item1;
                storage.MarkerLength = markerl.Item2;
                storage.MarkerSize   = markerl.Item3;

                #endregion


                logger.Info("Read pixel parameters for file - {0}", filename);

                foreach (var element in root.Descendants("spine"))
                {
                    var key    = element.Attribute("key").Value;
                    var points = new List <Point>();

                    var points_xml = element.Element("points");

                    var points_x = points_xml.Descendants("point");

                    foreach (var point in points_x)
                    {
                        var x = int.Parse(point.Attribute("x").Value, CultureInfo.InvariantCulture);
                        var y = int.Parse(point.Attribute("y").Value, CultureInfo.InvariantCulture);
                        points.Add(new Point(x, y));
                    }



                    storage.AddDescription(key, new SpineDescription()
                    {
                        UpLeft    = points[0],
                        DownLeft  = points[1],
                        DownRight = points[2],
                        UpRight   = points[3],
                    });


                    logger.Info("Read spine description {0} for file - {1}", key, filename);
                }

                foreach (var element in root.Descendants("process"))
                {
                    var key    = element.Attribute("key").Value;
                    var points = new List <Point>();

                    var points_xml = element.Element("points");

                    var points_x = points_xml.Descendants("point");

                    foreach (var point in points_x)
                    {
                        var x = int.Parse(point.Attribute("x").Value, CultureInfo.InvariantCulture);
                        var y = int.Parse(point.Attribute("y").Value, CultureInfo.InvariantCulture);
                        points.Add(new Point(x, y));
                    }

                    var i = new SpinousProcessDescription()
                    {
                        UpPoint     = points[0],
                        VertexPoint = points[1],
                        DownPoint   = points[2],
                    };

                    logger.Info("Read process description {0} for file - {1}", key, filename);

                    storage.AddSpinousProcessDescription(key, i);
                }
            }
            catch (Exception e)
            {
                logger.Error(e, "Error parsing storage XML");
                return(storage);
            }



            logger.Info("Storage has been read from file - {0}", filename);
            return(storage);
        }