private static IGraphic CreateInteractivePolyline(IList <PointF> vertices) { var closed = FloatComparer.AreEqual(vertices[0], vertices[vertices.Count - 1]); // use a standard rectangle primitive if the axes defines an axis-aligned rectangle if (closed && vertices.Count == 5 && IsAxisAligned(vertices[0], vertices[1]) && IsAxisAligned(vertices[1], vertices[2]) && IsAxisAligned(vertices[2], vertices[3]) && IsAxisAligned(vertices[3], vertices[4])) { var bounds = RectangleUtilities.ConvertToPositiveRectangle(RectangleUtilities.ComputeBoundingRectangle(vertices[0], vertices[1], vertices[2], vertices[3])); var rectangle = new RectanglePrimitive { TopLeft = bounds.Location, BottomRight = bounds.Location + bounds.Size }; return(new BoundableResizeControlGraphic(new BoundableStretchControlGraphic(new MoveControlGraphic(rectangle)))); } else if (!closed && vertices.Count == 3) { var protractor = new ProtractorGraphic { Points = { vertices[0], vertices[1], vertices[2] } }; return(new VerticesControlGraphic(new MoveControlGraphic(protractor))); } else if (!closed && vertices.Count == 2) { var line = new PolylineGraphic { Points = { vertices[0], vertices[1] } }; return(new VerticesControlGraphic(new MoveControlGraphic(line))); } var polyline = new PolylineGraphic(closed); polyline.Points.AddRange(vertices); return(closed ? new PolygonControlGraphic(true, new MoveControlGraphic(polyline)) : new VerticesControlGraphic(true, new MoveControlGraphic(polyline))); }
private static IGraphic CreateInteractiveInterpolated(IList <PointF> dataPoints) { var closed = FloatComparer.AreEqual(dataPoints[0], dataPoints[dataPoints.Count - 1]); var curve = CreateInterpolated(dataPoints); return(closed ? new PolygonControlGraphic(true, new MoveControlGraphic(curve)) : new VerticesControlGraphic(true, new MoveControlGraphic(curve))); }
public void TestDot() { Vector3D v1 = new Vector3D(2.2F, -6.1F, 7.4F); Vector3D v2 = new Vector3D(3.8F, 3.7F, 4.1F); Assert.IsTrue(FloatComparer.AreEqual(v1.Dot(v2), 16.13F)); }
public void TestUnitVector() { float oneOverSqrt2 = 1 / (float)Math.Sqrt(2); SizeF unitVector; PointF origin; origin = new PointF(0, 0); unitVector = new SizeF(Vector.CreateUnitVector(origin, origin + new SizeF(-1, 1))); Assert.IsTrue(FloatComparer.AreEqual(new SizeF(-oneOverSqrt2, oneOverSqrt2), unitVector)); Assert.IsTrue(FloatComparer.AreEqual(unitVector.Width * unitVector.Width + unitVector.Height * unitVector.Height, 1), "Magnitude must be 1."); origin = new PointF(-1, 1); unitVector = new SizeF(Vector.CreateUnitVector(origin, origin + new SizeF(-2, 2))); Assert.IsTrue(FloatComparer.AreEqual(new SizeF(-oneOverSqrt2, oneOverSqrt2), unitVector)); Assert.IsTrue(FloatComparer.AreEqual(unitVector.Width * unitVector.Width + unitVector.Height * unitVector.Height, 1), "Magnitude must be 1."); origin = new PointF(3, -1); unitVector = new SizeF(Vector.CreateUnitVector(origin, origin + new SizeF(-2, 2))); Assert.IsTrue(FloatComparer.AreEqual(new SizeF(-oneOverSqrt2, oneOverSqrt2), unitVector)); Assert.IsTrue(FloatComparer.AreEqual(unitVector.Width * unitVector.Width + unitVector.Height * unitVector.Height, 1), "Magnitude must be 1."); origin = new PointF(3, 1); unitVector = new SizeF(Vector.CreateUnitVector(origin, origin + new SizeF(-2, 2))); Assert.IsTrue(FloatComparer.AreEqual(new SizeF(-oneOverSqrt2, oneOverSqrt2), unitVector)); Assert.IsTrue(FloatComparer.AreEqual(unitVector.Width * unitVector.Width + unitVector.Height * unitVector.Height, 1), "Magnitude must be 1."); }
private static Matrix CalcRotateMatrixFromOrthogonalBasis(Vector3D xAxis, Vector3D yAxis, Vector3D zAxis) { const float zeroTolerance = 0.0000001f; Platform.CheckForNullReference(xAxis, "xAxis"); Platform.CheckForNullReference(yAxis, "yAxis"); Platform.CheckForNullReference(zAxis, "zAxis"); Platform.CheckFalse(xAxis.IsNull || yAxis.IsNull || zAxis.IsNull, "Input must be an orthogonal set of basis vectors (i.e. non-trivial vectors)."); Platform.CheckTrue(FloatComparer.AreEqual(xAxis.Dot(yAxis), 0, zeroTolerance) && FloatComparer.AreEqual(xAxis.Dot(zAxis), 0, zeroTolerance) && FloatComparer.AreEqual(yAxis.Dot(zAxis), 0, zeroTolerance), "Input must be an orthogonal set of basis vectors (i.e. mutually perpendicular)."); xAxis = xAxis.Normalize(); yAxis = yAxis.Normalize(); zAxis = zAxis.Normalize(); //TODO (CR Sept 2010): is this a rotation matrix, or the definition of a coordinate system? var basis = new Matrix(4, 4); basis.SetRow(0, xAxis.X, xAxis.Y, xAxis.Z, 0); basis.SetRow(1, yAxis.X, yAxis.Y, yAxis.Z, 0); basis.SetRow(2, zAxis.X, zAxis.Y, zAxis.Z, 0); basis.SetRow(3, 0, 0, 0, 1); return(basis); }
public void TestSanity() { // AreEqual { float x = 1.0f; float y = 2.0f; float z = x + y; Assert.IsTrue(FloatComparer.AreEqual(z, 3.0f)); } // IsGreaterThan { float x = 1.001f; float y = 1.0f; Assert.IsTrue(FloatComparer.IsGreaterThan(x, y)); } // IsLessThan { float x = 1.001f; float y = 1.0f; Assert.IsTrue(FloatComparer.IsLessThan(y, x)); } }
public string GetPixelSpacing() { var spatialTransformProvider = _image as ISpatialTransformProvider; var imageSopProvider = _image as IImageSopProvider; if (spatialTransformProvider != null && imageSopProvider != null && imageSopProvider.Frame.ImagePlaneHelper.IsValid) { var imageSize = _image.ClientRectangle.Size; var positionSource = spatialTransformProvider.SpatialTransform.ConvertToSource(new PointF(0, 0)); var bottomLeftSource = spatialTransformProvider.SpatialTransform.ConvertToSource(new PointF(0, imageSize.Height)); var topRightSource = spatialTransformProvider.SpatialTransform.ConvertToSource(new PointF(imageSize.Width, 0)); var positionPatient = imageSopProvider.Frame.ImagePlaneHelper.ConvertToPatient(positionSource); var imageHeightPatient = (imageSopProvider.Frame.ImagePlaneHelper.ConvertToPatient(bottomLeftSource) - positionPatient).Magnitude; var imageWidthPatient = (imageSopProvider.Frame.ImagePlaneHelper.ConvertToPatient(topRightSource) - positionPatient).Magnitude; var columnSpacing = imageWidthPatient / imageSize.Width; var rowSpacing = imageHeightPatient / imageSize.Height; // if the aspect ratio is supposed to be 1, ensure the pixel spacing actually says so, regardless of floating point calculation differences if (FloatComparer.AreEqual(1, rowSpacing / columnSpacing)) { rowSpacing = columnSpacing = (rowSpacing + columnSpacing) / 2; } return(new SizeF(columnSpacing, rowSpacing).ToDicomAttributeString()); } return(string.Empty); }
/// <summary> /// Initializes a <see cref="VolumeSlicerParams"/> for a slice orientation defined as a 4x4 affine transformation matrix. /// </summary> /// <param name="sliceRotation">The desired 4x4 affine transformation matrix.</param> /// <exception cref="ArgumentNullException">Thrown if the provided matrix is null.</exception> /// <exception cref="ArgumentException">Thrown if the provided matrix is not an affine transform.</exception> public VolumeSlicerParams(Matrix sliceRotation) { const string invalidTransformMessage = "sliceRotation must be a 4x4 affine transformation matrix."; Platform.CheckForNullReference(sliceRotation, "sliceRotation"); Platform.CheckTrue(sliceRotation.Columns == 4 && sliceRotation.Rows == 4, invalidTransformMessage); Platform.CheckTrue(FloatComparer.AreEqual(sliceRotation[3, 0], 0), invalidTransformMessage); Platform.CheckTrue(FloatComparer.AreEqual(sliceRotation[3, 1], 0), invalidTransformMessage); Platform.CheckTrue(FloatComparer.AreEqual(sliceRotation[3, 2], 0), invalidTransformMessage); Platform.CheckTrue(FloatComparer.AreEqual(sliceRotation[3, 3], 1), invalidTransformMessage); //is this a "rotation matrix" or a "desired coordinate system" _slicingPlaneRotation = sliceRotation; //TODO (CR Sept 2010): if the input matrix is a rotation matrix, why are we not just extracting values //for _rotateAboutX, etc. Also, _slicingPlaneRotation seems more or less unused. double yRadians = (float)Math.Asin(sliceRotation[0, 2]); double cosY = Math.Cos(yRadians); _rotateAboutX = (float)Math.Atan2(-sliceRotation[1, 2] / cosY, sliceRotation[2, 2] / cosY) * _degreesPerRadian; _rotateAboutY = (float)yRadians * _degreesPerRadian; _rotateAboutZ = (float)Math.Atan2(-sliceRotation[0, 1] / cosY, sliceRotation[0, 0] / cosY) * _degreesPerRadian; _description = string.Format(SR.FormatSliceCustom, _rotateAboutX, _rotateAboutY, _rotateAboutZ); }
public virtual bool AreEqual(Bitmap referenceImage, Bitmap testImage, Rectangle bounds) { Bitmap diffImage; var result = PerformComparison(referenceImage, testImage, bounds, false, out diffImage); return(FloatComparer.AreEqual((float)result, 0)); }
public virtual bool AreEqual(Bitmap referenceImage, Bitmap testImage, float tolerance) { Bitmap diffImage; var result = PerformComparison(referenceImage, testImage, false, out diffImage); return(FloatComparer.AreEqual((float)result, 0, tolerance)); }
public void AddTag(Type tagType, float startTime = 0f, float duration = -1f) { if (!Valid) { return; } if (duration < 0) { duration = DurationInSeconds - startTime; } int existing = tags.Count(t => t.Type == tagType && FloatComparer.AreEqual(t.startTime, startTime, FloatComparer.kEpsilon) && FloatComparer.AreEqual(t.duration, duration, FloatComparer.kEpsilon)); if (existing > 0) { return; } Undo.RecordObject(m_Asset, $"Add {TagAttribute.GetDescription(tagType)} tag"); TagAnnotation newTag = TagAnnotation.Create(tagType, startTime, duration); tags.Add(newTag); NotifyChanged(); }
internal void Validate() { int count = 0; // Check for null LUTs foreach (IComposableLut lut in this) { ++count; if (lut == null) { throw new InvalidOperationException(SR.ExceptionLUTNotAdded); } } if (count == 0) //do this instead of accessing Count b/c it can be expensive. { throw new InvalidOperationException(SR.ExceptionLUTNotAdded); } // Verify that the input range of the nth LUT is equal to the output // range of the n-1th LUT. for (int i = 1; i < count; i++) { IComposableLut curLut = this[i]; IComposableLut prevLut = this[i - 1]; if (!FloatComparer.AreEqual(prevLut.MinOutputValue, curLut.MinInputValue) || !FloatComparer.AreEqual(prevLut.MaxOutputValue, curLut.MaxInputValue)) { throw new InvalidOperationException(SR.ExceptionLUTInputOutputRange); } } }
public void ThirdPersonMove(Vector3 vec) { if (vec.magnitude > 1f) { vec.Normalize(); } vec = transform.InverseTransformDirection(vec); animator.applyRootMotion = true; vec = Vector3.ProjectOnPlane(vec, Vector3.up); if (!FloatComparer.AreEqual(vec.x, 0f, Mathf.Epsilon))// || !FloatComparer.AreEqual(vec.z, 0f, Mathf.Epsilon)) { m_TurnAmount = vec.x; /*Mathf.Atan2(vec.x, vec.z)*/; } else { m_TurnAmount = 0f; } m_ForwardAmount = vec.z * 2; ApplyExtraTurnRotation(); UpdateAnimator(vec); }
public void ThirdPersonMove(Vector3 move) { if (move.magnitude > 1f) { move.Normalize(); } move = transform.InverseTransformDirection(move); m_Animator.applyRootMotion = true; move = Vector3.ProjectOnPlane(move, Vector3.up); if (!FloatComparer.AreEqual(move.x, 0f, Mathf.Epsilon) || !FloatComparer.AreEqual(move.z, 0f, Mathf.Epsilon)) { m_TurnAmount = Mathf.Atan2(move.x, move.z); } else { m_TurnAmount = 0f; } m_ForwardAmount = move.z; ApplyExtraTurnRotation(); UpdateAnimator(move); }
public override sealed void UpdateSceneGraph(vtkRenderer vtkRenderer) { if (Disposed) { return; } vtkRenderer.SetBackground(VtkHelper.ConvertToVtkColor(_backgroundColor)); uint mTime; using (var camera = vtkRenderer.GetActiveCamera()) using (var vtkRenderWindow = vtkRenderer.GetRenderWindow()) { var clientSize = vtkRenderWindow.GetSize2(); var scale = ViewPortSpatialTransform.Scale; if (FloatComparer.AreEqual(0, scale)) { scale = 1; } camera.SetParallelScale(0.5 * clientSize.Height / scale); var cameraDistance = GetNominalCameraDistance(); var pos = ViewPortSpatialTransform.ConvertToSource(new PointF(clientSize.Width / 2f, clientSize.Height / 2f)); camera.SetPosition(pos.X, pos.Y, cameraDistance); camera.SetFocalPoint(pos.X, pos.Y, 0); camera.SetClippingRange(10, 2 * cameraDistance); camera.ComputeViewPlaneNormal(); var up = ViewPortSpatialTransform.ConvertToSource(new SizeF(0, -1)); camera.SetViewUp(up.Width, up.Height, 0); mTime = camera.GetMTime(); } var rootProp = ModelRootProp; using (var vtkTransform = rootProp.GetUserMatrix()) { var modelCumulativeTransform = GetModelCumulativeTransform(); vtkTransform.SetElements(modelCumulativeTransform); } UpdateModelRootProp(rootProp); var propMTime = rootProp.GetMTime(); if (mTime < propMTime) { mTime = propMTime; } if (_lastMTime < mTime) { _lastMTime = mTime; Modified(); } }
private static bool IsClosed(IPointsGraphic g) { if (g.Points.Count > 2) { return(FloatComparer.AreEqual(g.Points[0], g.Points[g.Points.Count - 1])); } return(false); }
private static IGraphic CreatePolyline(IList <PointF> vertices) { var closed = FloatComparer.AreEqual(vertices[0], vertices[vertices.Count - 1]); var polyline = new PolylineGraphic(closed); polyline.Points.AddRange(vertices); return(polyline); }
private static void VerifyPointOnEllipse(float a, float b, PointF center, PointF intersection) { float x = intersection.X - center.X; float y = intersection.Y - center.Y; float rule = x * x / (a * a) + y * y / (b * b); Assert.IsTrue(FloatComparer.AreEqual(1F, rule), "Point is not on ellipse!"); }
public override bool Equals(object obj) { var other = (ItemKey)obj; return(other.Name == Name && other.Style == Style && other.Unit == Unit && FloatComparer.AreEqual(other.Size, Size)); }
public override bool CalculateCalloutLocation(out PointF location, out CoordinateSystem coordinateSystem) { if (this.Roi.Points.Count < 3 || string.IsNullOrEmpty(this.Callout.Text)) { base.Callout.Visible = false; } else { base.Callout.Visible = true; } if (!base.Callout.Visible || _userMovedCallout) { return(base.CalculateCalloutLocation(out location, out coordinateSystem)); } SizeF calloutOffsetDestination = GetCalloutOffsetDestination(); coordinateSystem = CoordinateSystem.Destination; base.AnnotationGraphic.CoordinateSystem = coordinateSystem; // first, move the callout by the same amount the vertex moved (if it moved at all). location = base.Callout.TextLocation + calloutOffsetDestination; PointF start = this.Roi.Points[0]; PointF vertex = this.Roi.Points[1]; PointF end = this.Roi.Points[2]; base.AnnotationGraphic.ResetCoordinateSystem(); double vectorAngle = -Vector.SubtendedAngle(start, vertex, end) / 2 + 180; PointF[] points = new PointF[] { start, end }; using (Matrix rotation = new Matrix()) { rotation.Rotate((float)vectorAngle); rotation.Translate(-vertex.X, -vertex.Y); rotation.TransformPoints(points); } float calloutMagnitude = new Vector3D(location.X - vertex.X, location.Y - vertex.Y, 0).Magnitude; Vector3D startVector = new Vector3D(points[0].X, points[0].Y, 0); if (FloatComparer.AreEqual(startVector.Magnitude, 0F, 0.01F)) { startVector = new Vector3D(-1, 0, 0); } startVector = startVector / startVector.Magnitude * calloutMagnitude; location = new PointF(startVector.X + vertex.X, startVector.Y + vertex.Y); return(true); }
public void TestNormalize() { Vector3D v1 = new Vector3D(2.2F, -6.1F, 7.4F); Assert.IsTrue(FloatComparer.AreEqual(v1.Magnitude, 9.8392072851F)); Vector3D normalized = v1.Normalize(); Assert.IsTrue(FloatComparer.AreEqual(normalized.Magnitude, 1.0F)); }
public bool IsEqualTo(double value, double tolerance) { if (FloatComparer.AreEqual((float)this.Mean, (float)value, (float)tolerance)) { if (FloatComparer.AreEqual((float)this.StandardDeviation, 0, (float)tolerance)) { return(true); } } return(false); }
public void TestMinorAxisZero() { float a = 2.5F; float b = 0F; PointF center = new PointF(3F, 2F); PointF test = new PointF(13F, 7F); PointF intersection = EllipsePrimitive.IntersectEllipseAndLine(a, b, center, test); //intersection is at center. Assert.IsTrue(FloatComparer.AreEqual(center, intersection), "ellipse intersection point is not correct!"); }
public void TestPointVeryCloseToZero() { float a = 2.5F; float b = 1.25F; PointF center = new PointF(3F, 2F); PointF test = new PointF(3.0001F, 2.0001F); PointF intersection = EllipsePrimitive.IntersectEllipseAndLine(a, b, center, test); //intersection is at center. Assert.IsTrue(FloatComparer.AreEqual(center, intersection), "ellipse intersection point is not correct!"); }
/// <summary> /// Gets the normal vector describing the plane of the image in patient coordinates. /// </summary> /// <returns>The normal vector, or null if the <see cref="Frame"/>'s position information is invalid.</returns> public static Vector3D GetNormalVector(ImageOrientationPatient imageOrientationPatient) { if (imageOrientationPatient.IsNull) { return(null); } var left = new Vector3D((float)imageOrientationPatient.RowX, (float)imageOrientationPatient.RowY, (float)imageOrientationPatient.RowZ); var normal = left.Cross(new Vector3D((float)imageOrientationPatient.ColumnX, (float)imageOrientationPatient.ColumnY, (float)imageOrientationPatient.ColumnZ)); return(FloatComparer.AreEqual(normal.Magnitude, 0) ? Vector3D.Null : normal.Normalize()); }
public int IndexOf(PointF item) { if (_pointCount > 0 && FloatComparer.AreEqual(item, _lineGraphic.Point1)) { return(0); } else if (_pointCount > 1 && FloatComparer.AreEqual(item, _lineGraphic.Point2)) { return(1); } return(-1); }
public void DestinationToSourceRoundtrip() { // be sure to covert back and forth var transform = CreateTransform(); PointF dstPt1 = new Point(100, 200); PointF srcPt = transform.ConvertToSource(dstPt1); PointF dstPt2 = transform.ConvertToDestination(srcPt); Assert.IsTrue(FloatComparer.AreEqual(dstPt1, dstPt2)); }
private float GetSliceSpacing() { if (FloatComparer.AreEqual(0, _sliceSpacing)) { _sliceSpacing = _slicerParams.SliceSpacing; if (FloatComparer.AreEqual(0, _sliceSpacing)) { _sliceSpacing = GetDefaultSpacing(); } } return(_sliceSpacing); }
private double ComputeTiltAboutY() { float aboutYradians = (float)GetYRotation(this.ImageOrientationPatient); // If within specified tolerance of 0, Pi/2, -Pi/2, then treat as no tilt (return 0) if (FloatComparer.AreEqual(aboutYradians, 0f, _gantryTiltTolerance) || FloatComparer.AreEqual(Math.Abs(aboutYradians), _halfPi, _gantryTiltTolerance)) { return(0f); } return(aboutYradians); }
public void TestPointOutside() { float a = -2.5F; float b = -1.25F; PointF center = new PointF(3F, 2F); PointF test = new PointF(13F, 7F); PointF result = new PointF(4.767767F, 2.883884F); PointF intersection = EllipsePrimitive.IntersectEllipseAndLine(a, b, center, test); VerifyPointOnEllipse(a, b, center, intersection); Assert.IsTrue(FloatComparer.AreEqual(result, intersection), "ellipse intersection point is not correct!"); }