public void DrawRect(double x0, double y0, double x1, double y1, DicomColor color)
        {
            int y0i = transyi(y0);
            int y1i = transyi(y1);

            _bitmap.DrawRectangle(transxi(x0), transyi(y0), transxi(x1), transyi(y1), DicomColorConverter.FromDicomColor(color));
        }
示例#2
0
 public void DrawLines(double[] vertices, DicomColor color)
 {
     for (int i = 0; i < vertices.Length; i += 4)
     {
         DrawLine(vertices[i], vertices[i + 1], vertices[i + 2], vertices[i + 3], color);
     }
 }
示例#3
0
        public void DrawLine(double x0, double y0, double x1, double y1, DicomColor color, LineType lineType)
        {
            x0 *= Canvas.ActualWidth;
            x1 *= Canvas.ActualWidth;
            y1 *= Canvas.ActualHeight;
            y0 *= Canvas.ActualHeight;
            Line line = new Line();

            line.Stroke = new SolidColorBrush(DicomColorConverter.FromDicomColor(color));
            if (lineType != LineType.Normal)
            {
                line.StrokeDashArray = new DoubleCollection();
                if (lineType == LineType.Dotted)
                {
                    line.StrokeDashArray.Add(1);
                    line.StrokeDashArray.Add(1);
                }
                else if (lineType == LineType.Dashed)
                {
                    line.StrokeDashArray.Add(2);
                    line.StrokeDashArray.Add(2);
                }
            }
            line.StrokeThickness = 1;
            line.X1 = x0;
            line.X2 = x1;
            line.Y1 = y0;
            line.Y2 = y1;
            Canvas?.Children.Add(line);
        }
        public void FillRect(double x0, double y0, double x1, double y1, DicomColor fill, DicomColor stroke)
        {
            int y0i = transyi(y0);
            int y1i = transyi(y1);

            _bitmap.FillRectangle(transxi(x0), transyi(y0), transxi(x1), transyi(y1), DicomColorConverter.FromDicomColor(fill));
            DrawRect(x0, y0, x1, y1, stroke);
        }
示例#5
0
 public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 {
     if (value is Color)
     {
         var color = (Color)value;
         return(DicomColor.FromArgb(color.A, color.R, color.G, color.B));
     }
     return(null);
 }
        public void DrawLines(double[] vertices, DicomColor color)
        {
            var actualColor = WriteableBitmapExtensions.ConvertColor(DicomColorConverter.FromDicomColor(color));

            using (var context = _bitmap.GetBitmapContext())
            {
                for (int i = 0; i < vertices.Length; i += 4)
                {
                    WriteableBitmapExtensions.DrawLine(context, context.Width, context.Height, transxi(vertices[i]), transyi(vertices[i + 1]), transxi(vertices[i + 2]), transyi(vertices[i + 3]), actualColor);
                }
            }
        }
 public void DrawLine(double x0, double y0, double x1, double y1, DicomColor color, LineType lineType)
 {
     if (lineType == LineType.Normal)
     {
         _bitmap.DrawLine(transxi(x0), transyi(y0), transxi(x1), transyi(y1), getCachedColor(color));
     }
     else
     {
         double hx = x0 + (x1 - x0) / 2;
         double hy = y0 + (y1 - y0) / 2;
         _bitmap.DrawLine(transxi(x0), transyi(y0), transxi(hx), transyi(hy), getCachedColor(color));
     }
 }
示例#8
0
        public void Render(DicomPanelModel model, IRenderContext context)
        {
            var s  = model.Camera.ConvertWorldToScreenCoords(Position);
            var r1 = new Point3d(Position.X - 2 / model.Camera.Scale, Position.Y - 2 / model.Camera.Scale, Position.Z);
            var r2 = new Point3d(Position.X, Position.Y, Position.Z);

            r2 += model.Camera.ColDir * 48 / model.Camera.Scale;
            r2 += model.Camera.RowDir * 16 / model.Camera.Scale;
            var sr1 = model.Camera.ConvertWorldToScreenCoords(r1);
            var sr2 = model.Camera.ConvertWorldToScreenCoords(r2);

            context.DrawString(Text, s.X, s.Y, 12, DicomColor.FromArgb((int)(255 * Opacity), 0, 255, 255));
        }
        private Color getCachedColor(DicomColor dicomColor)
        {
            Color color;

            if (!cachedColors.ContainsKey(dicomColor))
            {
                color = DicomColorConverter.FromDicomColor(dicomColor);
                cachedColors.Add(dicomColor, color);
            }
            else
            {
                color = cachedColors[dicomColor];
            }
            return(color);
        }
示例#10
0
        public void DrawRect(double x0, double y0, double x1, double y1, DicomColor color)
        {
            x0 *= Canvas.ActualWidth;
            x1 *= Canvas.ActualWidth;
            y1 *= Canvas.ActualHeight;
            y0 *= Canvas.ActualHeight;

            Rectangle rectangle = new Rectangle();

            rectangle.Stroke = new SolidColorBrush(DicomColorConverter.FromDicomColor(color));
            rectangle.Width  = Math.Abs(x1 - x0);
            rectangle.Height = Math.Abs(y1 - y0);
            Canvas.SetLeft(rectangle, Math.Min(x0, x1));
            Canvas.SetTop(rectangle, Math.Min(y0, y1));
            Canvas?.Children.Add(rectangle);
        }
        private void DrawArrowHead(double x0, double y0, double x1, double y1, DicomColor color)
        {
            double       dx   = (x1 - x0) / 2;
            double       dy   = (y1 - y0) / 2;
            double       px   = x0 + dx;
            double       py   = y0 + dy;
            const double cos  = 0.866;
            const double sin  = 0.500;
            Point2d      end1 = new Point2d(
                (float)(px + (dx * cos + dy * -sin)),
                (float)(py + (dx * sin + dy * cos)));
            Point2d end2 = new Point2d(
                (float)(px + (dx * cos + dy * sin)),
                (float)(py + (dx * -sin + dy * cos)));

            DrawLine(x1, y1, end1.X, end1.Y, color);
            DrawLine(x1, y1, end2.X, end2.Y, color);
        }
示例#12
0
        public void DrawString(string text, double x, double y, double size, DicomColor color)
        {
            TextBlock tb  = new TextBlock();
            var       dse = new DropShadowEffect();

            dse.BlurRadius  = 1;
            dse.ShadowDepth = 4;
            dse.Direction   = 0;
            tb.FontSize     = size;
            tb.Foreground   = new SolidColorBrush(DicomColorConverter.FromDicomColor(color));
            tb.Text         = text;
            Canvas.SetLeft(tb, x * Canvas.ActualWidth);
            Canvas.SetTop(tb, y * Canvas.ActualHeight);

            FormattedText fm = new FormattedText(tb.Text, System.Globalization.CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight, new Typeface(tb.FontFamily, tb.FontStyle, tb.FontWeight, tb.FontStretch), tb.FontSize, tb.Foreground);

            FillRect(x, y, x + fm.Width / Canvas.ActualWidth, y + fm.Height / Canvas.ActualHeight, DicomColor.FromArgb(128, 0, 0, 0), DicomColor.FromArgb(0, 0, 0, 0));

            Canvas?.Children.Add(tb);
        }
示例#13
0
 public void DrawString(string text, double x, double y, double size, DicomColor color)
 {
 }
示例#14
0
 public void DrawRect(double x0, double y0, double x1, double y1, DicomColor color)
 {
 }
示例#15
0
 public void DrawLines(double[] vertices, DicomColor color)
 {
     throw new NotImplementedException();
 }
示例#16
0
 public void DrawLine(double x0, double y0, double x1, double y1, DicomColor color)
 {
 }
示例#17
0
 /// <summary>
 /// Holds line segments in the 3D world and a color
 /// </summary>
 /// <param name="vertices"></param>
 /// <param name="color"></param>
 public Contour(double[] vertices, DicomColor color)
 {
     Vertices = vertices;
     Color    = color;
 }
 public void DrawArrow(double x0, double y0, double x1, double y1, DicomColor color)
 {
     DrawLine(x0, y0, x1, y1, color);
     DrawArrowHead(x0, y0, x1, y1, color);
 }
示例#19
0
 public void DrawArrow(Point2d p1, Point2d p2, DicomColor color)
 {
     DrawArrow(p1.X, p1.Y, p2.X, p2.Y, color);
 }
示例#20
0
        public Contour GetContour(float[][] grid, int rows, int columns, double[][][] coords, double thresholds, DicomColor color)
        {
            Contour contour = new Contour(GetVertices(grid, rows, columns, coords, thresholds), color);

            return(contour);
        }
示例#21
0
 public void DrawLine(double x0, double y0, double x1, double y1, DicomColor color)
 {
     DrawLine(x0, y0, x1, y1, color, LineType.Normal);
 }
示例#22
0
        public void DrawEllipse(double x0, double y0, double radiusX, double radiusY, DicomColor color)
        {
            x0      *= Canvas.ActualWidth;
            y0      *= Canvas.ActualHeight;
            radiusX *= Canvas.ActualWidth;
            radiusY *= Canvas.ActualHeight;

            Ellipse ellipse = new Ellipse();

            ellipse.Stroke = new SolidColorBrush(DicomColorConverter.FromDicomColor(color));
            ellipse.Width  = Math.Abs(radiusX);
            ellipse.Height = Math.Abs(radiusY);
            Canvas.SetLeft(ellipse, x0 - radiusX / 2);
            Canvas.SetTop(ellipse, y0 - radiusY / 2);
            Canvas?.Children.Add(ellipse);
        }
示例#23
0
 public void FillRect(double x0, double y0, double x1, double y1, DicomColor fill, DicomColor stroke)
 {
 }
示例#24
0
        public void Load(DicomFile[] files, StructureSet structureSet)
        {
            DicomFile file = files[0];

            structureSet.Name = file.Dataset.Get <string>(DicomTag.StructureSetLabel, "");

            Dictionary <int, string> roi_names = new Dictionary <int, string>();
            DicomSequence            structs   = file.Dataset.Get <DicomSequence>(DicomTag.StructureSetROISequence);

            foreach (DicomDataset item in structs)
            {
                roi_names.Add(item.Get <int>(DicomTag.ROINumber), item.Get <string>(DicomTag.ROIName));
            }

            List <RegionOfInterest> rois = new List <RegionOfInterest>();

            DicomSequence s = file.Dataset.Get <DicomSequence>(DicomTag.ROIContourSequence);

            foreach (DicomDataset item in s.Items)
            {
                RegionOfInterest roi   = new RegionOfInterest();
                int[]            color = item.Get <int[]>(DicomTag.ROIDisplayColor);
                roi.Color     = DicomColor.FromRgb(color[0], color[1], color[2]);
                roi.ROINumber = item.Get <int>(DicomTag.ReferencedROINumber);
                if (roi_names.ContainsKey(roi.ROINumber))
                {
                    roi.Name = roi_names[roi.ROINumber];
                }

                DicomSequence roi_definitions;
                try
                {
                    roi_definitions = item.Get <DicomSequence>(DicomTag.ContourSequence);
                }
                catch (Exception e)
                {
                    continue;
                }

                double xmin = double.MaxValue, ymin = double.MaxValue, zmin = double.MaxValue, xmax = double.MinValue, ymax = double.MinValue, zmax = double.MinValue;

                foreach (DicomDataset contourSlice in roi_definitions.Items)
                {
                    int           vertex_count = contourSlice.Get <int>(DicomTag.NumberOfContourPoints);
                    double[]      vertices     = contourSlice.Get <double[]>(DicomTag.ContourData);
                    PlanarPolygon poly         = new PlanarPolygon();
                    // we divide the number of vertices here by 1.5 because we are going from a 3d poly to a 2d poly on the z plane
                    poly.Vertices = new double[(int)(vertices.Length / 1.5)];
                    double zcoord    = vertices[2];
                    int    polyIndex = 0;

                    RegionOfInterestSlice slice = roi.GetSlice(zcoord);
                    if (slice == null)
                    {
                        slice = new RegionOfInterestSlice()
                        {
                            ZCoord = zcoord,
                        }
                    }
                    ;

                    for (int i = 0; i < vertices.Length; i += 3)
                    {
                        poly.Vertices[polyIndex]     = vertices[i];
                        poly.Vertices[polyIndex + 1] = vertices[i + 1];
                        if (vertices[i] < xmin)
                        {
                            xmin = vertices[i];
                        }
                        if (vertices[i] > xmax)
                        {
                            xmax = vertices[i];
                        }
                        if (vertices[i + 1] < ymin)
                        {
                            ymin = vertices[i + 1];
                        }
                        if (vertices[i + 1] > ymax)
                        {
                            ymax = vertices[i + 1];
                        }
                        if (zcoord < zmin)
                        {
                            zmin = zcoord;
                        }
                        if (zcoord > zmax)
                        {
                            zmax = zcoord;
                        }
                        polyIndex += 2;
                    }
                    if (zmin < roi.ZRange.Minimum)
                    {
                        roi.ZRange.Minimum = zmin;
                    }
                    if (zmax > roi.ZRange.Maximum)
                    {
                        roi.ZRange.Maximum = zmax;
                    }

                    slice.AddPolygon(poly);

                    roi.AddSlice(slice, zcoord);
                }

                roi.XRange = new Geometry.Range(xmin, xmax);
                roi.YRange = new Geometry.Range(ymin, ymax);
                roi.ZRange = new Geometry.Range(zmin, zmax);

                for (int i = 0; i < roi.RegionOfInterestSlices.Count; i++)
                {
                    for (int j = 0; j < roi.RegionOfInterestSlices[i].Polygons.Count; j++)
                    {
                        roi.RegionOfInterestSlices[i].Polygons[j].XRange = new Geometry.Range(xmin, xmax);
                        roi.RegionOfInterestSlices[i].Polygons[j].YRange = new Geometry.Range(ymin, ymax);
                    }
                    roi.RegionOfInterestSlices[i].ComputeBinaryMask();
                }
                rois.Add(roi);
            }
            GC.Collect();
            structureSet.ROIs = rois;
        }
    }
示例#25
0
 public void DrawLine(Point2d p1, Point2d p2, DicomColor color)
 {
     DrawLine(p1.X, p1.Y, p2.X, p2.Y, color);
 }
示例#26
0
 public void DrawEllipse(double x0, double y0, double radiusX, double radiusY, DicomColor color)
 {
 }
示例#27
0
 public void DrawArrow(double x0, double y0, double x1, double y1, DicomColor color)
 {
     throw new NotImplementedException();
 }
示例#28
0
 public void DrawLine(double x0, double y0, double x1, double y1, DicomColor color, LineType lineType)
 {
 }
 public void DrawEllipse(double x0, double y0, double radiusX, double radiusY, DicomColor color)
 {
     _bitmap.DrawEllipseCentered(transxi(x0), transyi(y0), transxi(radiusX / 2), transyi(radiusY / 2), DicomColorConverter.FromDicomColor(color));
 }
 public void DrawString(string text, double x, double y, double size, DicomColor color)
 {
     _bitmap.DrawString(transxi(x), transyi(y), DicomColorConverter.FromDicomColor(color), new PortableFontDesc("Aria", (int)((double)size / 1.5)), text);
 }