예제 #1
0
        private GeometricShutter ConvertToGeometricShutter()
        {
            GeometricShutter shutter;

            if (_selectedShutterType == ShutterType.Rectangle)
            {
                RectanglePrimitive primitive = (RectanglePrimitive)_primitiveGraphic;
                primitive.CoordinateSystem = CoordinateSystem.Source;
                Rectangle rectangle =
                    new Rectangle((int)primitive.TopLeft.X, (int)primitive.TopLeft.Y, (int)primitive.Width, (int)primitive.Height);
                primitive.ResetCoordinateSystem();

                shutter = new RectangularShutter(rectangle);
            }
            else if (_selectedShutterType == ShutterType.Polygon)
            {
                PolylineGraphic polyLine = (PolylineGraphic)_primitiveGraphic;
                polyLine.CoordinateSystem = CoordinateSystem.Source;

                List <Point> points = new List <Point>();
                for (int i = 0; i < polyLine.Points.Count; ++i)
                {
                    points.Add(new Point((int)polyLine.Points[i].X, (int)polyLine.Points[i].Y));
                }

                polyLine.ResetCoordinateSystem();
                shutter = new PolygonalShutter(points);
            }
            else
            {
                EllipsePrimitive primitive = (EllipsePrimitive)_primitiveGraphic;
                primitive.CoordinateSystem = CoordinateSystem.Source;
                Rectangle rectangle = new Rectangle((int)primitive.TopLeft.X, (int)primitive.TopLeft.Y, (int)primitive.Width, (int)primitive.Height);
                rectangle = RectangleUtilities.ConvertToPositiveRectangle(rectangle);
                int   radius = rectangle.Width / 2;
                Point center = new Point(rectangle.X + radius, rectangle.Y + radius);
                primitive.ResetCoordinateSystem();

                shutter = new CircularShutter(center, radius);
            }

            RemoveDrawShutterGraphic();
            return(shutter);
        }
        protected void SerializeDisplayShutter(DisplayShutterModuleIod displayShutterModule, DicomPresentationImageCollection <T> images)
        {
            // Doesn't support multiframe or whatever case it is when we get more than one image serialized to one state
            CircularShutter    circular    = null;
            RectangularShutter rectangular = null;
            PolygonalShutter   polygonal   = null;
            int unserializedCount          = 0;

            foreach (T image in images)
            {
                DicomGraphicsPlane dicomGraphics = DicomGraphicsPlane.GetDicomGraphicsPlane(image, false);
                if (dicomGraphics != null)
                {
                    // identify visible geometric shutter if exists
                    GeometricShuttersGraphic geometricShutters = dicomGraphics.Shutters.ActiveShutter as GeometricShuttersGraphic;
                    if (geometricShutters != null)
                    {
                        // we can only save the first of each
                        foreach (GeometricShutter shutter in geometricShutters.CustomShutters)
                        {
                            if (shutter is CircularShutter && circular == null)
                            {
                                circular = (CircularShutter)shutter;
                            }
                            else if (shutter is RectangularShutter && rectangular == null)
                            {
                                rectangular = (RectangularShutter)shutter;
                            }
                            else if (shutter is PolygonalShutter && polygonal == null)
                            {
                                polygonal = (PolygonalShutter)shutter;
                            }
                            else
                            {
                                unserializedCount++;
                            }
                        }
                        foreach (GeometricShutter shutter in geometricShutters.DicomShutters)
                        {
                            if (shutter is CircularShutter && circular == null)
                            {
                                circular = (CircularShutter)shutter;
                            }
                            else if (shutter is RectangularShutter && rectangular == null)
                            {
                                rectangular = (RectangularShutter)shutter;
                            }
                            else if (shutter is PolygonalShutter && polygonal == null)
                            {
                                polygonal = (PolygonalShutter)shutter;
                            }
                            else
                            {
                                unserializedCount++;
                            }
                        }
                    }
                }
            }

            ShutterShape shape = ShutterShape.None;

            if (circular != null)
            {
                shape |= ShutterShape.Circular;

                displayShutterModule.CenterOfCircularShutter = circular.Center;
                displayShutterModule.RadiusOfCircularShutter = circular.Radius;
            }
            if (rectangular != null)
            {
                shape |= ShutterShape.Rectangular;

                Rectangle r = rectangular.Rectangle;
                displayShutterModule.ShutterLeftVerticalEdge    = r.Left;
                displayShutterModule.ShutterRightVerticalEdge   = r.Right;
                displayShutterModule.ShutterUpperHorizontalEdge = r.Top;
                displayShutterModule.ShutterLowerHorizontalEdge = r.Bottom;
            }
            if (polygonal != null)
            {
                shape |= ShutterShape.Polygonal;

                List <Point> vertices = new List <Point>();
                vertices.AddRange(polygonal.Vertices);
                displayShutterModule.VerticesOfThePolygonalShutter = vertices.ToArray();
            }

            if (shape != ShutterShape.None)
            {
                displayShutterModule.ShutterShape             = shape;
                displayShutterModule.ShutterPresentationValue = 0;
            }
            else
            {
                foreach (uint tag in DisplayShutterMacroIod.DefinedTags)
                {
                    displayShutterModule.DicomAttributeProvider[tag] = null;
                }
            }

            if (unserializedCount > 0)
            {
                Platform.Log(LogLevel.Warn, "Attempt to serialize presentation state with an unsupported combination of shutters - some information may be lost.");
            }
        }
예제 #3
0
		private GeometricShutter ConvertToGeometricShutter()
		{
			GeometricShutter shutter;

			if (_selectedShutterType == ShutterType.Rectangle)
			{
				RectanglePrimitive primitive = (RectanglePrimitive)_primitiveGraphic;
				primitive.CoordinateSystem = CoordinateSystem.Source;
				Rectangle rectangle =
					new Rectangle((int)primitive.TopLeft.X, (int)primitive.TopLeft.Y, (int)primitive.Width, (int)primitive.Height);
				primitive.ResetCoordinateSystem();
				
				shutter = new RectangularShutter(rectangle);
			}
			else if (_selectedShutterType == ShutterType.Polygon)
			{
				PolylineGraphic polyLine = (PolylineGraphic)_primitiveGraphic;
				polyLine.CoordinateSystem = CoordinateSystem.Source;

				List<Point> points = new List<Point>();
				for (int i = 0; i < polyLine.Points.Count; ++i)
					points.Add(new Point((int)polyLine.Points[i].X, (int)polyLine.Points[i].Y));

				polyLine.ResetCoordinateSystem();
				shutter = new PolygonalShutter(points);
			}
			else
			{
				EllipsePrimitive primitive = (EllipsePrimitive)_primitiveGraphic;
				primitive.CoordinateSystem = CoordinateSystem.Source;
				Rectangle rectangle = new Rectangle((int)primitive.TopLeft.X, (int)primitive.TopLeft.Y, (int)primitive.Width, (int)primitive.Height);
				rectangle = RectangleUtilities.ConvertToPositiveRectangle(rectangle);
				int radius = rectangle.Width/2;
				Point center = new Point(rectangle.X + radius, rectangle.Y + radius);
				primitive.ResetCoordinateSystem();

				shutter = new CircularShutter(center, radius);
			}

			RemoveDrawShutterGraphic();
			return shutter;
		}