예제 #1
0
        private double GetDistance(VectorDouble s, VectorDouble t)
        {
            var x = s.X - t.X;
            var y = s.Y - t.Y;

            return(Math.Sqrt(x * x + y * y));
        }
예제 #2
0
        private static void ConstrainPoints15Degrees(PointDouble a, PointDouble b, out PointDouble bP)
        {
            double       num5;
            VectorDouble num    = (VectorDouble)(b - a);
            double       num2   = Math.Atan2(num.Y, num.X);
            double       length = num.Length;
            double       theta  = (Math.Round((double)((12.0 * num2) / 3.1415926535897931), MidpointRounding.AwayFromZero) * 3.1415926535897931) / 12.0;

            if (IsThetaMultipleOf90Degress(theta))
            {
                num5 = Math.Round(length, MidpointRounding.AwayFromZero);
            }
            else if (IsThetaMultipleOf45Degrees(theta))
            {
                num5 = Math.Round((double)(length / 1.4142135623730951), MidpointRounding.AwayFromZero) * 1.4142135623730951;
            }
            else
            {
                num5 = length;
            }
            double x = a.X + (num5 * Math.Cos(theta));
            double y = a.Y + (num5 * Math.Sin(theta));

            bP = new PointDouble(x, y);
        }
예제 #3
0
        internal Vector CalculateMoveByNearbyLions(List <Vector> vectorsLionToAntelope)
        {
            var vectorsWeighedByDistance = WeighByDistance(vectorsLionToAntelope);
            var resultingVector          = new VectorDouble(0, 0);

            foreach (var processedVector in vectorsWeighedByDistance)
            {
                var signedAngleResultToCurrentRadians = _vectorMath.SignedAngleBetween(resultingVector, processedVector);

                var currentAngleAbs = Math.Abs(signedAngleResultToCurrentRadians);
                if (currentAngleAbs < Constants.DELTA)
                {
                    resultingVector += processedVector;
                    continue;
                }

                if (currentAngleAbs >= Math.PI - Constants.DELTA && currentAngleAbs <= Math.PI + Constants.DELTA)
                {
                    Perform180DegreeLogics(ref signedAngleResultToCurrentRadians, vectorsWeighedByDistance,
                                           processedVector);
                }

                // ToDo: weigh angle by distance.
                signedAngleResultToCurrentRadians /= 2;

                resultingVector = _vectorMath.RotateClockwise(resultingVector, signedAngleResultToCurrentRadians) +
                                  _vectorMath.RotateClockwise(processedVector, -signedAngleResultToCurrentRadians);
            }
            resultingVector = _vectorMath.NormalizeDouble(resultingVector);

            return(new Vector(resultingVector));
        }
예제 #4
0
        private double GetDistanceFast(VectorDouble s, VectorDouble t)
        {
            var x = s.X - t.X;
            var y = s.Y - t.Y;

            return(x * x + y * y);
        }
예제 #5
0
        public VectorDouble NormalizeDouble(VectorDouble v)
        {
            if (Math.Abs(v.X) < Constants.DELTA && Math.Abs(v.Y) < Constants.DELTA)
            {
                return(new VectorDouble(0, 0));
            }

            double absX = Math.Abs(v.X),
                   absY = Math.Abs(v.Y);
            double normalizedX, normalizedY;


            if (absX > absY)
            {
                normalizedX = v.X / absX;
                normalizedY = v.Y / absX;
            }
            else
            {
                normalizedY = v.Y / absY;
                normalizedX = v.X / absY;
            }

            return(new VectorDouble(normalizedX, normalizedY));
        }
예제 #6
0
        protected override void OnUIDragBegin(object sender, PaintDotNet.UI.Input.MouseEventArgs e)
        {
            if (e.Source is UIElement)
            {
                bool        flag          = (base.PresentationSource.PrimaryKeyboardDevice.Modifiers & ModifierKeys.Control) == ModifierKeys.Control;
                PointDouble mouseCenterPt = BrushToolBase <CloneStampTool, CloneStampToolChanges, CloneStampToolUI> .GetMouseCenterPt(e.GetPosition(base.UI), base.CanvasView.CanvasHairWidth);

                if (flag)
                {
                    this.isHandlingDrag = true;
                    this.GetStaticData().anchorOffsetMode = AnchorOffsetMode.Absolute;
                    this.GetStaticData().anchorOffset     = (VectorDouble)mouseCenterPt;
                    this.GetStaticData().anchorLayerWeak  = new WeakReferenceT <Layer>(base.ActiveLayer);
                    this.UpdateAnchor();
                    e.Handled = true;
                }
                else if (this.GetStaticData().anchorOffsetMode == AnchorOffsetMode.NotSet)
                {
                    this.isHandlingDrag = true;
                    e.Handled           = true;
                }
                else if (this.GetStaticData().anchorOffsetMode == AnchorOffsetMode.Absolute)
                {
                    PointDouble anchorCenter = this.GetStaticData().anchorCenter;
                    this.GetStaticData().anchorOffsetMode = AnchorOffsetMode.Relative;
                    VectorDouble num4 = (VectorDouble)(((PointDouble)this.GetStaticData().anchorOffset) - mouseCenterPt);
                    this.GetStaticData().anchorOffset = num4;
                    this.UpdateAnchor();
                    PointDouble num5 = this.GetStaticData().anchorCenter;
                }
            }
            base.OnUIDragBegin(sender, e);
        }
예제 #7
0
        private void OnUIDragMove(object sender, MouseEventArgs e)
        {
            using (this.onUIGestureRegion.UseEnterScope())
            {
                MagicWandToolChanges changes2;
                UIElement            source = e.Source as UIElement;
                if (source != null)
                {
                    PointDouble             position   = e.GetPosition(this.UI);
                    FloodFillToolHandleType handleType = FloodFillToolUIBase <MagicWandTool, MagicWandToolChanges> .GetHandleType(source);

                    PointDouble?nullable = null;
                    switch (handleType)
                    {
                    case FloodFillToolHandleType.Canvas:
                        if ((this.State == TransactedToolState.Drawing) && this.mouseInputDrawingAgent.IsActive)
                        {
                            nullable = new PointDouble?(this.gestureBeginCanvasPt);
                        }
                        break;

                    case FloodFillToolHandleType.Origin:
                    case FloodFillToolHandleType.Move:
                        if ((this.State == TransactedToolState.Editing) && this.mouseInputEditingAgent.IsActive)
                        {
                            nullable = new PointDouble?(base.ChangesBeforeEditing.OriginPoint);
                        }
                        break;

                    default:
                        throw ExceptionUtil.InvalidEnumArgumentException <FloodFillToolHandleType>(handleType, "sender.(MagicWandToolUI.HandleType)");
                    }
                    if (nullable.HasValue)
                    {
                        VectorDouble         num2        = (VectorDouble)(position - this.gestureBeginCanvasPt);
                        PointDouble          originPoint = nullable.Value + num2;
                        MagicWandToolChanges changes     = base.Changes;
                        changes2 = new MagicWandToolChanges(changes.DrawingSettingsValues, originPoint, changes.SelectionCombineModeOverride, changes.FloodModeOverride, changes.BaseGeometryPersistenceKey);
                        if (!changes.Equals((ReferenceValue)changes2))
                        {
                            switch (handleType)
                            {
                            case FloodFillToolHandleType.Canvas:
                                this.mouseInputDrawingAgent.TransactionToken.Changes = changes2;
                                break;

                            case FloodFillToolHandleType.Origin:
                            case FloodFillToolHandleType.Move:
                                goto Label_0139;
                            }
                        }
                    }
                }
                return;

Label_0139:
                this.mouseInputEditingAgent.TransactionToken.Changes = changes2;
            }
        }
예제 #8
0
        private static PointDouble GetWedgePathPoint(PointDouble ellipseCenter, double thetaDelta)
        {
            VectorDouble num6 = (VectorDouble)ellipseCenter;
            double       num2 = num6.Length + 2.0;
            double       d    = Math.Atan2(-ellipseCenter.Y, -ellipseCenter.X) + thetaDelta;

            return(new PointDouble(Math.Cos(d) * num2, Math.Sin(d) * num2));
        }
예제 #9
0
        public override void Execute()
        {
            VectorDouble pos = m_Method.GetOptimizerPosition();

            Console.WriteLine("{0:3} = {1:10.5} : [{2}, {3}]",
                              m_Method.GetOptimizerIteration(),
                              m_Method.GetMetricValue(),
                              pos[0], pos[1]);
        }
예제 #10
0
        /// <inheritdoc/>
        public Image ResampleImage2D(Image image, int outputSize)
        {
            Ensure.ArgumentNotNull(image, nameof(image));

            var dimension = image.GetDimension();

            if (dimension != 2)
            {
                throw new NotSupportedException($"The dimension ({dimension}) of the provided image is not supported.");
            }

            var inputSize      = image.GetSize();
            var inputSpacing   = image.GetSpacing();
            var inputDirection = image.GetDirection();
            var inputOrigin    = image.GetOrigin();

            double oldw = inputSize[0] * inputSpacing[0];
            double oldh = inputSize[1] * inputSpacing[1];
            double neww, newh = 0;
            double rw = oldw / outputSize;
            double rh = oldh / outputSize;

            if (rw > rh)
            {
                newh = oldh / rw;
                neww = outputSize;
            }
            else
            {
                neww = oldw / rh;
                newh = outputSize;
            }

            var outputSpacing = new VectorDouble()
            {
                inputSpacing[0] * inputSize[0] / neww,
                inputSpacing[1] * inputSize[1] / newh
            };

            var actualSize = new VectorUInt32()
            {
                Convert.ToUInt32(neww),
                Convert.ToUInt32(newh)
            };

            // https://itk.org/ITKExamples/src/Filtering/ImageGrid/ResampleAnImage/Documentation.html
            ResampleImageFilter filter = new ResampleImageFilter();

            filter.SetReferenceImage(image);
            filter.SetSize(actualSize);
            filter.SetOutputSpacing(outputSpacing);
            Image output = filter.Execute(image);

            filter.Dispose();

            return(output);
        }
예제 #11
0
        private static PointDouble ConstrainPoints(PointDouble a, PointDouble b)
        {
            VectorDouble num  = (VectorDouble)(b - a);
            double       d    = Math.Atan2(num.Y, num.X);
            double       num3 = Math.Sqrt((num.X * num.X) + (num.Y * num.Y));

            d = (Math.Round((double)((12.0 * d) / 3.1415926535897931), MidpointRounding.AwayFromZero) * 3.1415926535897931) / 12.0;
            return(new PointDouble(a.X + (num3 * Math.Cos(d)), a.Y + (num3 * Math.Sin(d))));
        }
예제 #12
0
        public bool Equals(VectorDouble v)
        {
            if ((object)v == null)
            {
                return(false);
            }


            return((X == v.X) && (Y == v.Y));
        }
예제 #13
0
        public VectorDouble RotateClockwise(VectorDouble v, double angleRadians)
        {
            var result = new VectorDouble
            {
                X = v.X * Math.Cos(angleRadians) - v.Y * Math.Sin(angleRadians),
                Y = v.X * Math.Sin(angleRadians) + v.Y * Math.Cos(angleRadians)
            };

            return(result);
        }
예제 #14
0
        public double SignedAngleBetween(VectorDouble v1, VectorDouble v2)
        {
            if (Math.Abs(v1.X) < Constants.DELTA && Math.Abs(v1.Y) < Constants.DELTA ||
                Math.Abs(v2.X) < Constants.DELTA && Math.Abs(v2.Y) < Constants.DELTA)
            {
                return(0);
            }

            return(Math.Atan2(v1.X * v2.Y - v1.Y * v2.X, v1.X * v2.X + v1.Y * v2.Y));
        }
예제 #15
0
        public double AngleFromMainAxisClockwise(VectorDouble v)
        {
            var angleRadians = AngleBetween(v, new VectorDouble(1, 0));

            if (v.Y < 0)
            {
                angleRadians = Math.PI * 2 - angleRadians;
            }
            return(angleRadians);
        }
예제 #16
0
        public bool Counterclockwise90DegreeRotationIsCloserToVector(VectorDouble vector, VectorDouble vectorToRotate)
        {
            var rotatedClockwise        = RotateClockwise(vectorToRotate, Math.PI / 2);
            var rotatedCounterclockwise = RotateClockwise(vectorToRotate, -Math.PI / 2);

            var distance1 = ToEuclideanDistanceNoRootDouble(vector.X - rotatedClockwise.X, vector.Y - rotatedClockwise.Y);
            var distance2 = ToEuclideanDistanceNoRootDouble(vector.X - rotatedCounterclockwise.X, vector.Y - rotatedCounterclockwise.Y);

            return(distance1 > distance2);
        }
예제 #17
0
        private static PointDouble GetMoveHandleCanvasOffset(PointInt32 originPoint, double hairWidth, SizeDouble moveHandleActualSize)
        {
            VectorDouble vec  = new VectorDouble(1.0, 1.0);
            VectorDouble num3 = (VectorDouble)(VectorDouble.Normalize(vec) * (hairWidth * 25.0));
            double       x    = UIUtil.ScaleWidth(num3.X);
            VectorDouble num4 = new VectorDouble(x, UIUtil.ScaleHeight(num3.Y));
            PointDouble  num5 = new PointDouble((double)(originPoint.X + 1), (double)(originPoint.Y + 1));
            PointDouble  pt   = num5 + num4;

            return(PointDouble.Offset(pt, -moveHandleActualSize.Width / 2.0, -moveHandleActualSize.Height / 2.0));
        }
예제 #18
0
        public override bool Equals(object obj)
        {
            VectorDouble other = obj as VectorDouble;

            if (ReferenceEquals(other, null))
            {
                return(false);
            }

            return(Equals(other));
        }
예제 #19
0
        private static double GetAnamorphicLength(VectorDouble vec)
        {
            double num  = Math.Abs(vec.X);
            double num2 = Math.Abs(vec.Y);

            if (num > num2)
            {
                return(num);
            }
            return(num2);
        }
예제 #20
0
        protected virtual void ZoomToWithCentering(PaintDotNet.ScaleFactor newScaleFactor, Func <PointDouble> anchorPtCanvasFn)
        {
            PaintDotNet.ScaleFactor scaleFactor = this.ScaleFactor;
            PointDouble             num         = anchorPtCanvasFn();

            this.ScaleFactor = newScaleFactor;
            VectorDouble num3 = anchorPtCanvasFn() - num;

            PaintDotNet.Canvas.CanvasView canvasView = this.CanvasView;
            canvasView.ViewportCanvasOffset -= num3;
        }
예제 #21
0
        private double GetLength(VectorDouble vec)
        {
            switch (this.lengthMetric)
            {
            case BrushStrokeLengthMetric.Euclidean:
                return(vec.Length);

            case BrushStrokeLengthMetric.Anamorphic:
                return(GetAnamorphicLength(vec));
            }
            ExceptionUtil.ThrowInvalidEnumArgumentException <BrushStrokeLengthMetric>(this.lengthMetric, "this.lengthMetric");
            return(double.NegativeInfinity);
        }
예제 #22
0
        static void example3()
        {
            Euler2DTransform basic_transform = new Euler2DTransform();
            VectorDouble     trans           = new VectorDouble(new double[] { 2.0, 3.0 });

            basic_transform.SetTranslation(trans);

            sitk.WriteTransform(basic_transform, "euler2D.tfm");

            Transform read_result = sitk.ReadTransform("euler2D.tfm");

            Debug.Assert(basic_transform.GetName() != read_result.GetName());
        }
예제 #23
0
        static void Main(string[] args)
        {
            try {
                // Create an image
                PixelIDValueEnum pixelType = PixelIDValueEnum.sitkUInt8;
                VectorUInt32     imageSize = new VectorUInt32(new uint[] { 128, 128 });
                Image            image     = new Image(imageSize, pixelType);

                // Create a face image
                VectorDouble faceSize   = new VectorDouble(new double[] { 64, 64 });
                VectorDouble faceCenter = new VectorDouble(new double[] { 64, 64 });
                Image        face       = SimpleITK.GaussianSource(pixelType, imageSize, faceSize, faceCenter);

                // Create eye images
                VectorDouble eyeSize    = new VectorDouble(new double[] { 5, 5 });
                VectorDouble eye1Center = new VectorDouble(new double[] { 48, 48 });
                VectorDouble eye2Center = new VectorDouble(new double[] { 80, 48 });
                Image        eye1       = SimpleITK.GaussianSource(pixelType, imageSize, eyeSize, eye1Center, 150);
                Image        eye2       = SimpleITK.GaussianSource(pixelType, imageSize, eyeSize, eye2Center, 150);

                // Apply the eyes to the face
                face = SimpleITK.Subtract(face, eye1);
                face = SimpleITK.Subtract(face, eye2);
                face = SimpleITK.BinaryThreshold(face, 200, 255, 255);


                // Create the mouth
                VectorDouble mouthRadii  = new VectorDouble(new double[] { 30, 20 });
                VectorDouble mouthCenter = new VectorDouble(new double[] { 64, 76 });
                Image        mouth       = SimpleITK.GaussianSource(pixelType, imageSize, mouthRadii, mouthCenter);
                mouth = SimpleITK.BinaryThreshold(mouth, 200, 255, 255);
                mouth = SimpleITK.Subtract(255, mouth);

                // Paste the mouth onto the face
                VectorUInt32 mouthSize = new VectorUInt32(new uint[] { 64, 18 });
                VectorInt32  mouthLoc  = new VectorInt32(new int[] { 32, 76 });
                face = SimpleITK.Paste(face, mouth, mouthSize, mouthLoc, mouthLoc);

                // Apply the face to the original image
                image = SimpleITK.Add(image, face);

                // Display the results
                if (Environment.GetEnvironmentVariable("SITK_NOSHOW") == null)
                {
                    SimpleITK.Show(image, "Hello World: CSharp", true);
                }
            } catch (Exception ex) {
                Console.WriteLine(ex);
            }
        }
예제 #24
0
 public ShapeRenderParameters(PointDouble startPoint, PointDouble endPoint, VectorDouble transformScale, IDictionary <string, object> settingValues, IDictionary <object, object> propertyValues)
 {
     Validate.Begin().IsFinite(startPoint.X, "startPoint.X").IsFinite(startPoint.Y, "startPoint.Y").IsFinite(endPoint.X, "endPoint.X").IsFinite(endPoint.Y, "endPoint.Y").IsNotNull <IDictionary <string, object> >(settingValues, "settingValues").Check();
     this.StartPoint     = startPoint;
     this.EndPoint       = endPoint;
     this.TransformScale = transformScale;
     this.SettingValues  = settingValues.ToDictionary <string, object>().AsReadOnly <string, object>();
     if (propertyValues == null)
     {
         this.PropertyValues = null;
     }
     else
     {
         this.PropertyValues = propertyValues.ToDictionary <object, object>().AsReadOnly <object, object>();
     }
 }
예제 #25
0
        public override bool Equals(System.Object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            VectorDouble v = obj as VectorDouble;

            if ((System.Object)v == null)
            {
                return(false);
            }

            return((X == v.X) && (Y == v.Y));
        }
예제 #26
0
    public DICOM3D(DICOMSeries seriesInfo) : base(seriesInfo)
    {
        dimensions = 3;

        Image firstSlice = seriesInfo.firstSlice;
        Image lastSlice  = seriesInfo.lastSlice;

        VectorDouble o1 = firstSlice.GetOrigin();

        if (o1.Count < 3)
        {
            throw(new System.Exception("Invalid origins found in first image."));
        }
        origin = new Vector3((float)o1 [0], (float)o1 [1], (float)o1 [2]);

        // Load the pixel spacing:
        // NOTE: It seems that the the first value is the spacing between rows (i.e. y direction),
        //		the second value is the spacing between columns (i.e. x direction).
        //		I was not able to verify this so far, since all test dicoms we had have the same spacing in
        //		x and y direction...
        VectorDouble spacing = firstSlice.GetSpacing();

        if (spacing.Count < 2)
        {
            throw(new System.Exception("Invalid pixel spacing found in images."));
        }
        pixelSpacing = new Vector2((float)spacing [1], (float)spacing [0]);

        // DICOMSeries already calculated these values, so get them from there:
        directionCosineX = seriesInfo.directionCosineX;
        directionCosineY = seriesInfo.directionCosineY;

        // Generate the transformation matrices which can later be used to translate pixels to
        // 3D positions and vice versa.
        setupTransformationMatrices();

        loadVolumeData();


        Vector3 corner1       = transformPixelToPatientPos(Vector2.zero, 0f);
        Vector2 imgDimensions = new Vector2(firstSlice.GetWidth(), firstSlice.GetHeight());
        Vector3 corner2       = transformPixelToPatientPos(imgDimensions, seriesInfo.numberOfSlices - 1);

        //boundingBox = new Bounds ((max - min) / 2 + min, (max - min));
        boundingBox = new Bounds((corner2 - corner1) / 2 + corner1, (corner2 - corner1));
        Debug.Log("bounding Box: " + boundingBox.center + " " + boundingBox.size);
    }
예제 #27
0
        private static LineGeometry ExtendLineGeometry(LineGeometry geometry, double exLength)
        {
            LineGeometry geometry2  = (LineGeometry)geometry.Clone();
            PointDouble  startPoint = geometry.StartPoint;
            PointDouble  endPoint   = geometry.EndPoint;

            if (startPoint != endPoint)
            {
                VectorDouble vec  = (VectorDouble)(endPoint - startPoint);
                VectorDouble num4 = VectorDouble.Normalize(vec);
                PointDouble  num5 = startPoint - ((PointDouble)(num4 * exLength));
                PointDouble  num6 = endPoint + ((PointDouble)(num4 * exLength));
                geometry2.StartPoint = num5;
                geometry2.EndPoint   = num6;
            }
            return(geometry2);
        }
예제 #28
0
        /// <inheritdoc/>
        public Image ResampleImage3D(Image image, int outputSize)
        {
            Ensure.ArgumentNotNull(image, nameof(image));

            var dimension = image.GetDimension();

            if (dimension != 3)
            {
                throw new NotSupportedException($"The dimension ({dimension}) of the provided image is not supported.");
            }

            var outputSizeConverted = Convert.ToUInt32(outputSize);
            var inputSize           = image.GetSize();
            var inputSpacing        = image.GetSpacing();

            var desiredSize = new VectorUInt32()
            {
                outputSizeConverted,
                outputSizeConverted,
                outputSizeConverted
            };

            var outputSpacing = new VectorDouble()
            {
                inputSpacing[0] * inputSize[0] / desiredSize[0],
                inputSpacing[1] * inputSize[1] / desiredSize[1],
                inputSpacing[2] * inputSize[2] / desiredSize[2]
            };

            // https://itk.org/Wiki/ITK/Examples/ImageProcessing/ResampleImageFilter
            ResampleImageFilter filter = new ResampleImageFilter();

            filter.SetReferenceImage(image);
            filter.SetTransform(new ScaleTransform(image.GetDimension()));
            filter.SetInterpolator(InterpolatorEnum.sitkLinear);
            filter.SetSize(desiredSize);
            filter.SetOutputSpacing(outputSpacing);
            Image output = filter.Execute(image);

            filter.Dispose();

            return(output);
        }
예제 #29
0
        protected override void OnMouseMove(MouseEventArgsF e)
        {
            base.OnMouseMove(e);
            PointInt32 b = new PointInt32(e.X, e.Y);

            if (this.moveOffsetMode)
            {
                VectorInt32 num2 = (VectorInt32)(b - this.lastPt);
                this.downPt.X += num2.X;
                this.downPt.Y += num2.Y;
            }
            if ((e.Button == MouseButtons.Left) && (this.mouseDown == MouseButtons.Left))
            {
                VectorDouble num3 = (VectorDouble)(b - this.downPt);
                if (num3.Length >= 10.0)
                {
                    goto Label_00B1;
                }
            }
            if (!this.rect.HasPositiveArea)
            {
                if ((e.Button == MouseButtons.Middle) && (this.mouseDown == MouseButtons.Middle))
                {
                    PointDouble documentScrollPosition = base.DocumentWorkspace.DocumentScrollPosition;
                    documentScrollPosition.X += b.X - this.lastPt.X;
                    documentScrollPosition.Y += b.Y - this.lastPt.Y;
                    base.DocumentWorkspace.DocumentScrollPosition = documentScrollPosition;
                    base.Update();
                }
                else
                {
                    this.rect = RectInt32.Zero;
                }
                goto Label_0173;
            }
Label_00B1:
            this.rect = RectInt32Util.FromPixelPoints(this.downPt, b);
            this.rect = RectInt32.Intersect(this.rect, base.ActiveLayer.Bounds());
            this.UpdateDrawnRect();
Label_0173:
            this.lastPt = b;
        }
예제 #30
0
        private static PathGeometry ExtendPathGeometry(PathGeometry geometry, double exLength)
        {
            if (geometry.Figures.Count != 1)
            {
                throw new ArgumentException();
            }
            PathGeometry          geometry2     = (PathGeometry)geometry.Clone();
            PointAndTangentDouble pointAtLength = geometry.GetPointAtLength(0.0, flatteningTolerance);
            VectorDouble          num2          = pointAtLength.Tangent.NormalizeOrZeroCopy();
            PointDouble           num3          = pointAtLength.Point - ((PointDouble)(num2 * exLength));

            geometry2.Figures[0].Segments.Insert(0, new LineSegment(pointAtLength.Point));
            geometry2.Figures[0].StartPoint = num3;
            PointAndTangentDouble num4  = geometry.GetPointAtLength(double.PositiveInfinity, flatteningTolerance);
            VectorDouble          num5  = num4.Tangent.NormalizeOrZeroCopy();
            PointDouble           point = num4.Point + ((PointDouble)(num5 * exLength));

            geometry2.Figures[0].Segments.Add(new LineSegment(point));
            return(geometry2);
        }
예제 #31
0
        static void Main(string[] args)
        {
            try {
                if (args.Length < 1) {
                    Console.WriteLine("Usage: RTKFirstReconstruction <output>");
                    return;
                }

                // Defines the RTK geometry object
                ThreeDCircularProjectionGeometry geometry = new ThreeDCircularProjectionGeometry();
                uint numberOfProjections = 360;
                float firstAngle = 0;
                float angularArc = 360;
                float sid = 600; // source to isocenter distance in mm
                float sdd = 1200; // source to detector distance in mm
                float isox = 0; // X coordinate on the projection image of isocenter
                float isoy = 0; // Y coordinate on the projection image of isocenter
                for (int x = 0; x < numberOfProjections; x++)
                  {
                  float angle = firstAngle + x * angularArc / numberOfProjections;
                  geometry.AddProjection(sid, sdd, angle, isox, isoy);
                  }
                ConstantImageSource constantImageSource = new ConstantImageSource();
                VectorDouble origin = new VectorDouble(3);
                origin.Add(-127.0);
                origin.Add(-127.0);
                origin.Add(-127.0);
                VectorUInt32 sizeOutput = new VectorUInt32(3);
                sizeOutput.Add(256);
                sizeOutput.Add(256);
                sizeOutput.Add(numberOfProjections);
                VectorDouble spacing = new VectorDouble(3);
                spacing.Add(1.0);
                spacing.Add(1.0);
                spacing.Add(1.0);

                constantImageSource.SetOrigin(origin);
                constantImageSource.SetSpacing(spacing);
                constantImageSource.SetSize(sizeOutput);
                constantImageSource.SetConstant(0.0);
                Image source = constantImageSource.Execute();

                RayEllipsoidIntersectionImageFilter rei = new RayEllipsoidIntersectionImageFilter();
                VectorDouble semiprincipalaxis = new VectorDouble(3);
                semiprincipalaxis.Add(50.0);
                semiprincipalaxis.Add(50.0);
                semiprincipalaxis.Add(50.0);

                VectorDouble center = new VectorDouble(3);
                center.Add(0.0);
                center.Add(0.0);
                center.Add(0.0);
                // Set GrayScale value, axes, center...
                rei.SetDensity(20);
                rei.SetAngle(0);
                rei.SetCenter(center);
                rei.SetAxis(semiprincipalaxis);
                rei.SetGeometry(geometry);
                Image reiImage = rei.Execute(source);

                // Create reconstructed image
                ConstantImageSource constantImageSource2 = new ConstantImageSource();
                VectorUInt32 sizeOutput2 = new VectorUInt32(3);
                sizeOutput2.Add(256);
                sizeOutput2.Add(256);
                sizeOutput2.Add(256);
                constantImageSource2.SetOrigin(origin);
                constantImageSource2.SetSpacing(spacing);
                constantImageSource2.SetSize(sizeOutput2);
                constantImageSource2.SetConstant(0.0);
                Image source2 = constantImageSource2.Execute();

                Console.WriteLine("Performing reconstruction");
                FDKConeBeamReconstructionFilter feldkamp = new FDKConeBeamReconstructionFilter();
                feldkamp.SetGeometry(geometry);
                feldkamp.SetTruncationCorrection(0.0);
                feldkamp.SetHannCutFrequency(0.0);
                Image image = feldkamp.Execute(source2, reiImage);

                ImageFileWriter writer = new ImageFileWriter();
                writer.SetFileName(args[0]);
                writer.Execute(image);

            } catch (Exception ex) {
                Console.WriteLine(ex);
            }
        }