/// <summary>
            /// Sets this line segment's end points to be the intersection of the <paramref name="sliceImage"/> on the infinite plane of the <paramref name="referenceImage"/>.
            /// </summary>
            /// <remarks>
            /// In practice, a call to this method should have <paramref name="referenceImage"/> being equal to this line's <see cref="Graphic.ParentPresentationImage"/> or,
            /// if not, then followed by a call to <see cref="ResliceToolGroup.TranslocateGraphic">translocate</see> the line to the <paramref name="referenceImage"/>.
            /// Any other use may constitute a defect involving reference line bounds, and you should thusly inspect your code and explain why this is the case.
            /// </remarks>
            /// <param name="sliceImage">The slice whose position is controlled by this line.</param>
            /// <param name="referenceImage">The image on which the line is (or is to be) defined.</param>
            /// <returns>Returns true if a solution exists and the end points were updated.</returns>
            public bool SetLine(IPresentationImage sliceImage, IPresentationImage referenceImage)
            {
                DicomImagePlane sliceImagePlane     = DicomImagePlane.FromImage(sliceImage);
                DicomImagePlane referenceImagePlane = DicomImagePlane.FromImage(referenceImage);

                if (!sliceImagePlane.IsParallelTo(referenceImagePlane, 1f))
                {
                    Vector3D imagePt1 = referenceImagePlane.ConvertToImagePlane(sliceImagePlane.PositionPatientTopLeft);
                    Vector3D imagePt2 = referenceImagePlane.ConvertToImagePlane(sliceImagePlane.PositionPatientTopRight);

                    this.Points.SuspendEvents();
                    this.Points.Clear();
                    this.Points.Add(referenceImagePlane.ConvertToImage(new PointF(imagePt1.X, imagePt1.Y)));
                    this.Points.Add(referenceImagePlane.ConvertToImage(new PointF(imagePt2.X, imagePt2.Y)));
                    this.Points.ResumeEvents();
                    return(true);
                }
                return(false);
            }
Exemple #2
0
        protected static void ValidateVolumeSlicePoints(Volumes.Volume volume, IVolumeSlicerParams slicerParams, IList <KnownSample> expectedPoints,
                                                        double xAxialGantryTilt, double yAxialGantryTilt, bool gantryTiltInDegrees)
        {
            if (gantryTiltInDegrees)
            {
                xAxialGantryTilt *= Math.PI / 180;
                yAxialGantryTilt *= Math.PI / 180;
            }

            Trace.WriteLine(string.Format("Using slice plane: {0}", slicerParams.Description));
            using (VolumeSlicer slicer = new VolumeSlicer(volume, slicerParams))
            {
                foreach (ISopDataSource slice in slicer.CreateSliceSops())
                {
                    using (ImageSop imageSop = new ImageSop(slice))
                    {
                        foreach (IPresentationImage image in PresentationImageFactory.Create(imageSop))
                        {
                            IImageGraphicProvider imageGraphicProvider = (IImageGraphicProvider)image;
                            DicomImagePlane       dip = DicomImagePlane.FromImage(image);

                            foreach (KnownSample sample in expectedPoints)
                            {
                                Vector3D patientPoint = sample.Point;
                                if (xAxialGantryTilt != 0 && yAxialGantryTilt == 0)
                                {
                                    float cos = (float)Math.Cos(xAxialGantryTilt);
                                    float sin = (float)Math.Sin(xAxialGantryTilt);
                                    patientPoint = new Vector3D(patientPoint.X,
                                                                patientPoint.Y * cos + (xAxialGantryTilt > 0 ? 100 * sin : 0),
                                                                patientPoint.Z / cos - patientPoint.Y * sin - (xAxialGantryTilt > 0 ? 100 * sin * sin / cos : 0));
                                }
                                else if (yAxialGantryTilt != 0)
                                {
                                    Assert.Fail("Unit test not designed to work with gantry tilts about Y (i.e. slew)");
                                }

                                Vector3D slicedPoint = dip.ConvertToImagePlane(patientPoint);
                                if (slicedPoint.Z > -0.5 && slicedPoint.Z < 0.5)
                                {
                                    int actual = imageGraphicProvider.ImageGraphic.PixelData.GetPixel((int)slicedPoint.X, (int)slicedPoint.Y);
                                    Trace.WriteLine(string.Format("Sample {0} @{1} (SLICE: {2}; PATIENT: {3})", actual, FormatVector(sample.Point), FormatVector(slicedPoint), FormatVector(patientPoint)));
                                    Assert.AreEqual(sample.Value, actual, "Wrong colour sample @{0}", sample.Point);
                                }
                            }

                            image.Dispose();
                        }
                    }
                    slice.Dispose();
                }
            }
        }