internal Aim4AnnotationInstance(Aim4DocumentInstance aim4Document, aim4_dotnet.iso_21090.II annotationUid) { Platform.CheckForNullReference(aim4Document, "aim4Document"); Platform.CheckForNullReference(annotationUid, "annotationUid"); if (aim4Document.IsImageAnnotation) { var imageAnnotationCollection = (aim4_dotnet.ImageAnnotationCollection) aim4Document.AnnotationCollection; if (imageAnnotationCollection.ImageAnnotations != null) { AimAnnotationEntity = imageAnnotationCollection.ImageAnnotations.Find(imageAnnotation => imageAnnotation != null && Equals(imageAnnotation.UniqueIdentifier, annotationUid)); } } else if (aim4Document.IsAnnotationOfAnnotation) { var annotationOfAnnotationCollection = (aim4_dotnet.AnnotationOfAnnotationCollection) aim4Document.AnnotationCollection; if (annotationOfAnnotationCollection.AnnotationOfAnnotations != null) { AimAnnotationEntity = annotationOfAnnotationCollection.AnnotationOfAnnotations.Find( annOfAnnotation => annOfAnnotation != null && Equals(annOfAnnotation.UniqueIdentifier, annotationUid)); } } else { Debug.Assert(false, "Unexpected Annotation Collection type: " + aim4Document.GetType().Name); } if (AimAnnotationEntity == null) throw new ArgumentException("AIM4: failed to initialize Annotation Instance from the collection"); //_parentAimDocument = new WeakReference(aim4Document); // TODO _parentAimDocument = aim4Document; }
internal DataProvider(aim4_dotnet.AnnotationEntity annotation, aim4_dotnet.Person person, aim4_dotnet.User user) { Platform.CheckForNullReference(annotation, "Annotation"); _annotation = annotation; _person = person; _user = user; }
internal Aim4DocumentInstance(aim4_dotnet.AnnotationCollection annotationCollection, string studyInstanceUid, string seriesInstanceUid, string sopInstanceUid) { Platform.CheckForEmptyString(studyInstanceUid, "studyInstanceUid"); Platform.CheckForEmptyString(seriesInstanceUid, "seriesInstanceUid"); Platform.CheckForEmptyString(sopInstanceUid, "sopInstanceUid"); Platform.CheckForNullReference(annotationCollection, "annotationCollection"); _annotationCollection = annotationCollection; StudyInstanceUid = studyInstanceUid; SeriesInstanceUid = seriesInstanceUid; SopInstanceUid = sopInstanceUid; }
// Retrieves SOP Instance UID and Referenced Frame Number from the coordinate private static void SetMarkupImageReference(IMarkup markup, aim4_dotnet.TwoDimensionGeometricShapeEntity geoShape) { if (geoShape != null) { Debug.Assert(geoShape.ReferencedFrameNumber > 0, "Referenced Frame Number must be positive"); markup.PresentationImageUid = geoShape.ImageReferenceUid.Uid; markup.FrameNumber = geoShape.ReferencedFrameNumber.HasValue ? geoShape.ReferencedFrameNumber.Value : 1; } }
private static AimTemplateTreeAnatomicEntityCharacteristicNode FromImagingPhysicalEntityCharacteristic(aim4_dotnet.ImagingPhysicalEntityCharacteristic imgPhysEntityChar, List<AimTemplateTreeAnatomicEntityCharacteristicNode> treeAecList) { AimTemplateTreeAnatomicEntityCharacteristicNode matchingAecTreeNode = null; if (imgPhysEntityChar.QuestionTypeCode != null) matchingAecTreeNode = treeAecList.FirstOrDefault(treeAec => DoTheyMatch(treeAec.QuestionType, imgPhysEntityChar.QuestionTypeCode)); else if (!String.IsNullOrEmpty(imgPhysEntityChar.Label)) matchingAecTreeNode = treeAecList.FirstOrDefault(treeAec => String.Equals(imgPhysEntityChar.Label, treeAec.Label)); else matchingAecTreeNode = treeAecList.FirstOrDefault(treeAe => treeAe.ItemNumber == imgPhysEntityChar.QuestionIndex); if (matchingAecTreeNode != null) { CharacteristicQuantificationAllowedTerm matchingAllowedTerm = matchingAecTreeNode.CharacteristicQuantificationAllowedTerms.FirstOrDefault(treeAec => DoTheyMatch(treeAec, imgPhysEntityChar.TypeCode)); if (matchingAllowedTerm != null) { matchingAllowedTerm.Selected = true; foreach (var quantification in matchingAllowedTerm.CharacteristicQuantifications) { if (ReadBackCharacteristicQuantificationFromAnnotation(imgPhysEntityChar.CharacteristicQuantificationCollection, quantification) == null) return null; } } else return null; if (matchingAecTreeNode.HasConfidence && imgPhysEntityChar.AnnotatorConfidence.HasValue) matchingAecTreeNode.ConfidenceValue = imgPhysEntityChar.AnnotatorConfidence.Value; } else return null; return matchingAecTreeNode; }
private static AimTemplateTreeAnatomicEntityNode FromImagingPhysicalEntity(aim4_dotnet.ImagingPhysicalEntity imagingPhysicalEntity, AimTemplateTree template) { AimTemplateTreeAnatomicEntityNode matchingTreeNode = null; if (imagingPhysicalEntity.QuestionTypeCode != null) matchingTreeNode = template.TemplateNodes.OfType<AimTemplateTreeAnatomicEntityNode>().FirstOrDefault(treeAe => DoTheyMatch(treeAe.QuestionType, imagingPhysicalEntity.QuestionTypeCode)); else if (!String.IsNullOrEmpty(imagingPhysicalEntity.Label)) matchingTreeNode = template.TemplateNodes.OfType<AimTemplateTreeAnatomicEntityNode>().FirstOrDefault(treeAe => String.Equals(imagingPhysicalEntity.Label, treeAe.Label)); else matchingTreeNode = template.TemplateNodes.OfType<AimTemplateTreeAnatomicEntityNode>().FirstOrDefault(treeAe => treeAe.ItemNumber == imagingPhysicalEntity.QuestionIndex); if (matchingTreeNode != null) { AimTemplateTreeAllowedTerm matchingAllowedTerm = matchingTreeNode.AllowedTerms.FirstOrDefault(treeAe => DoTheyMatch(treeAe, imagingPhysicalEntity.TypeCode)); if (matchingAllowedTerm != null) matchingAllowedTerm.Selected = true; else return null; if (matchingTreeNode.HasConfidence && imagingPhysicalEntity.AnnotatorConfidence.HasValue) matchingTreeNode.ConfidenceValue = imagingPhysicalEntity.AnnotatorConfidence.Value; } else return null; if (imagingPhysicalEntity.ImagingPhysicalEntityCharacteristicCollection != null) { foreach (var aec in imagingPhysicalEntity.ImagingPhysicalEntityCharacteristicCollection) { if (IsNullCodeList(aec.TypeCode)) continue; AimTemplateTreeAnatomicEntityCharacteristicNode matchingAecTreeNode = FromImagingPhysicalEntityCharacteristic(aec, matchingTreeNode.AnatomicEntityCharacteristicTreeNodes); if (matchingAecTreeNode == null) return null; } } if (imagingPhysicalEntity.ImagingObservationCharacteristicCollection != null) { foreach (var ioc in imagingPhysicalEntity.ImagingObservationCharacteristicCollection) { if (IsNullCodeList(ioc.TypeCode)) continue; AimTemplateTreeImagingObservationCharacteristicNode matchingIocTreeNode = FromImagingObservationCharacteristic(ioc, matchingTreeNode.ImagingObservationCharacteristicTreeNodes); if (matchingIocTreeNode == null) return null; } } return matchingTreeNode; }
private static bool DoTheyMatch(TemplateTree.StandardCodeSequence standardCodeSequence, aim4_dotnet.iso_21090.CD code) { if (standardCodeSequence == null) return code == null; if (code == null) return false; return string.Equals(standardCodeSequence.CodeMeaning, code.CodeMeaning) && string.Equals(standardCodeSequence.CodeValue, code.CodeValue) && string.Equals(standardCodeSequence.CodingSchemeDesignator, code.CodingSchemeDesignator) && StringEquals(standardCodeSequence.CodingSchemeVersion, code.CodingSchemeVersion); }
// TODO - use AimNativeConverter instead of this private static PointF AsPointF(aim4_dotnet.TwoDimensionSpatialCoordinate twoDimensionSpatialCoordinate) { Platform.CheckTrue(twoDimensionSpatialCoordinate != null, "Spatial Coordinate Exists"); return new PointF((float)twoDimensionSpatialCoordinate.X, (float)twoDimensionSpatialCoordinate.Y); }
private static string GetAnnotationOfAnnotationHtml(aim4_dotnet.AnnotationOfAnnotation annotationOfAnnotation, aim4_dotnet.User aimUserInfo) { throw new NotImplementedException(); }
public static bool AimDotNetNumericalEqualsTemplateTreeNumerical(aim4_dotnet.Numerical a, TemplateTree.Numerical b) { return a.Value == b.Value && a.UcumString == b.UcumString && a.Operator == ToAimComparisonOperator(b.Operator); }
public string WriteXmlAnnotationToString(aim4_dotnet.AnnotationCollection annotationCollection) { try { return Model.WriteAnnotationCollectionToXmlString(annotationCollection); } catch (Exception ex) { Platform.Log(LogLevel.Error, ex, "Failed to convert annotation to xml."); } return null; }
public bool WriteAnnotationToFile(aim4_dotnet.AnnotationCollection annotation, string filePathName) { try { Model.WriteAnnotationCollectionToFile(annotation, filePathName); return true; } catch (Exception ex) { Platform.Log(LogLevel.Error, ex, "Failed to save annotation to file \"{0}\"", filePathName); } return false; }
internal Aim4ObjectReference(aim4_dotnet.AnnotationCollection annotationCollection) { AnnotationCollection = annotationCollection; }
private string GetCharacteristicQuantificationHtml(aim4_dotnet.CharacteristicQuantification characteristicQuantification) { if (characteristicQuantification == null) return ""; switch (characteristicQuantification.QuantificationType) { case aim4_dotnet.CharacteristicQuantificationType.Numerical: aim4_dotnet.Numerical numerical = (aim4_dotnet.Numerical) characteristicQuantification; return numerical.Operator == aim4_dotnet.ComparisonOperatorIdentifier.InvalidComparisonOperator || numerical.Operator == aim4_dotnet.ComparisonOperatorIdentifier.None ? string.Format("{0} {1}", numerical.Value, numerical.UcumString) : string.Format("{0} {1} {2}", OperatorToString(numerical.Operator, true), numerical.Value, numerical.UcumString); case aim4_dotnet.CharacteristicQuantificationType.Quantile: aim4_dotnet.Quantile quantile = (aim4_dotnet.Quantile) characteristicQuantification; return string.Format("Quantile [{0}] of [{1}", quantile.SelectedBin, quantile.Bins); case aim4_dotnet.CharacteristicQuantificationType.NonQuantifiable: aim4_dotnet.NonQuantifiable nonQuantifiable = (aim4_dotnet.NonQuantifiable) characteristicQuantification; return nonQuantifiable.TypeCode == null ? "" : nonQuantifiable.TypeCode.CodeMeaning; case aim4_dotnet.CharacteristicQuantificationType.Scale: aim4_dotnet.Scale scale = (aim4_dotnet.Scale) characteristicQuantification; return scale.Value ?? ""; case aim4_dotnet.CharacteristicQuantificationType.Interval: aim4_dotnet.Interval interval = (aim4_dotnet.Interval) characteristicQuantification; { string left = CombineOperatorAndValue(interval.MinOperator, interval.MinValue == double.MinValue ? "" : interval.MinValue.ToString(), true); string right = CombineOperatorAndValue(interval.MaxOperator, interval.MaxValue == double.MaxValue ? "" : interval.MaxValue.ToString(), string.IsNullOrEmpty(left)); StringBuilder sb = new StringBuilder(); sb.Append(left); if (!string.IsNullOrEmpty(left) && !string.IsNullOrEmpty(right)) sb.Append(" and "); sb.Append(right); return sb.ToString(); } default: Debug.Assert(false, "Unknown characteristic quantification type"); break; } return ""; }
private static string OperatorToString(aim4_dotnet.ComparisonOperatorIdentifier operatorIdentifier, bool capFirst) { switch(operatorIdentifier) { case aim4_dotnet.ComparisonOperatorIdentifier.Equal: return capFirst ? "Equal to" : "equal to"; case aim4_dotnet.ComparisonOperatorIdentifier.NotEqual: return capFirst ? "Not equal to" : "not equal to"; case aim4_dotnet.ComparisonOperatorIdentifier.LessThan: return capFirst ? "Less than" : "less than"; case aim4_dotnet.ComparisonOperatorIdentifier.LessThanEqual: return capFirst ? "Less than or equal" : "less than or equal"; case aim4_dotnet.ComparisonOperatorIdentifier.GreaterThan: return capFirst ? "Greater than" : "greater than"; case aim4_dotnet.ComparisonOperatorIdentifier.GreaterThanEqual: return capFirst ? "Greater than or equal" : "greater than or equal"; case aim4_dotnet.ComparisonOperatorIdentifier.None: return capFirst ? "None" : "none"; case aim4_dotnet.ComparisonOperatorIdentifier.InvalidComparisonOperator: return capFirst ? "Invalid" : "invalid"; } return string.Empty; }
private static string GetImageAnnotationHtml(aim4_dotnet.ImageAnnotation imageAnnotation, aim4_dotnet.User aimUserInfo) { StringBuilder sb = new StringBuilder(); AimHtmlFormatter htmlFormatter = new AimHtmlFormatter(); Color ctrlColor = Color.FromKnownColor(KnownColor.Control); Color fontColor = Color.FromKnownColor(KnownColor.WindowText); sb.Append(HtmlDocHeader); sb.AppendFormat("<body style=\"background-color: #{0}{1}{2};\" onload=\"setupPaths(['{3}', '{4}'])\">", ctrlColor.R.ToString("X2"), ctrlColor.G.ToString("X2"), ctrlColor.B.ToString("X2"), MinusImagePathName, PlusImagePathName); sb.Append("<div id=\"main_content\">"); sb.AppendFormat("<div><b>Name: {0}</b></div>", imageAnnotation.Name); sb.AppendFormat("<div>Number of Geometric Shapes: {0}</div>", imageAnnotation.MarkupEntityCollection == null ? 0 : imageAnnotation.MarkupEntityCollection.Count(geoShape => geoShape is aim4_dotnet.GeometricShapeEntity)); sb.AppendFormat("<div>Number of Text Annotations: {0}</div>", imageAnnotation.MarkupEntityCollection == null ? 0 : imageAnnotation.MarkupEntityCollection.Count(geoShape => geoShape is aim4_dotnet.TextAnnotationEntity)); if (aimUserInfo != null) sb.AppendFormat("<div>Created by: {0}</div>", aimUserInfo.Name); sb.Append(htmlFormatter.GetImagingPhysicalEntitiesHtml(imageAnnotation.ImagingPhysicalEntityCollection)); sb.Append(htmlFormatter.GetImagingObservationHtml(imageAnnotation.ImagingObservationEntityCollection)); // TODO - append other sections sb.Append("</div>"); sb.Append("</body>"); sb.Append("</html>"); return sb.ToString(); }
public static bool AimDotNetIntervalEqualsTemplateTreeInterval(aim4_dotnet.Interval a, TemplateTree.Interval b) { return a.MinValue == b.MinValue && a.MaxValue == b.MaxValue && a.MinOperator == ToAimComparisonOperator(b.MinOperator) && a.MaxOperator == ToAimComparisonOperator(b.MaxOperator) && a.UcumString == b.UcumString; }
public static bool AimDotNetNonQuantifiableEqualsTemplateTreeNonQuantifiable(aim4_dotnet.NonQuantifiable a, TemplateTree.StandardCodedTerm b) { return a.TypeCode != null && String.Equals(a.TypeCode.CodeValue, b.CodeValue) && String.Equals(a.TypeCode.CodeMeaning, b.CodeMeaning) && String.Equals(a.TypeCode.CodingSchemeDesignator, b.CodingSchemeDesignator) && StringEquals(a.TypeCode.CodingSchemeVersion, b.CodingSchemeVersion); }
public static IMarkup ToMarkup2D(aim4_dotnet.GeometricShapeEntity geometricShape, string markupText) { if (geometricShape == null) return null; if (geometricShape is aim4_dotnet.TwoDimensionPoint) { var point = (aim4_dotnet.TwoDimensionPoint)geometricShape; var markup = new MarkupPoint(); markup.Name = markupText; markup.IncludeInAnnotation = point.IncludeFlag; markup.Point = AsPointF(point.Center); markup.CalloutText = string.Empty; // markupText; markup.CalloutLocation = markup.Point - new SizeF(30, 30); SetMarkupImageReference(markup, point); return markup; } if (geometricShape is aim4_dotnet.TwoDimensionCircle) { var circle = (aim4_dotnet.TwoDimensionCircle)geometricShape; PointF centerPt = AsPointF(circle.Center); PointF radiusPt = AsPointF(circle.RadiusPoint); double radiusLength = Vector.Distance(centerPt, radiusPt); var markup = new MarkupEllipse(); markup.Name = markupText; markup.IncludeInAnnotation = circle.IncludeFlag; markup.TopLeft = new PointF((float)(centerPt.X - radiusLength), (float)(centerPt.Y - radiusLength)); markup.BottomRight = new PointF((float)(centerPt.X + radiusLength), (float)(centerPt.Y + radiusLength)); markup.CalloutLocation = markup.TopLeft - new SizeF(30, 30); SetMarkupImageReference(markup, circle); return markup; } if (geometricShape is aim4_dotnet.TwoDimensionEllipse) { var ellipse = (aim4_dotnet.TwoDimensionEllipse)geometricShape; Debug.Assert(ellipse.TwoDimensionSpatialCoordinateCollection.Count == 4, "Ellipse must have four points"); var firstMajorAxisPt = AsPointF(ellipse.TwoDimensionSpatialCoordinateCollection[0]); var secondMajorAxisPt = AsPointF(ellipse.TwoDimensionSpatialCoordinateCollection[1]); var firstMinorAxisPt = AsPointF(ellipse.TwoDimensionSpatialCoordinateCollection[2]); var secondMinorAxisPt = AsPointF(ellipse.TwoDimensionSpatialCoordinateCollection[3]); var markup = new MarkupEllipse(); markup.Name = markupText; markup.IncludeInAnnotation = ellipse.IncludeFlag; markup.TopLeft = new PointF(firstMajorAxisPt.X, firstMinorAxisPt.Y); markup.BottomRight = new PointF(secondMajorAxisPt.X, secondMinorAxisPt.Y); markup.CalloutLocation = markup.TopLeft - new SizeF(30, 30); SetMarkupImageReference(markup, ellipse); return markup; } if (geometricShape is aim4_dotnet.TwoDimensionPolyline) { var polyline = (aim4_dotnet.TwoDimensionPolyline)geometricShape; // Check if this is a non-rotated rectangle if (polyline.TwoDimensionSpatialCoordinateCollection.Count == 4) { PointF twoDPoint1 = AsPointF(polyline.TwoDimensionSpatialCoordinateCollection[0]); PointF twoDPoint2 = AsPointF(polyline.TwoDimensionSpatialCoordinateCollection[1]); PointF twoDPoint3 = AsPointF(polyline.TwoDimensionSpatialCoordinateCollection[2]); PointF twoDPoint4 = AsPointF(polyline.TwoDimensionSpatialCoordinateCollection[3]); // If it's a rectangle with sides parallel to the axes if ((twoDPoint1.X == twoDPoint2.X && twoDPoint2.Y == twoDPoint3.Y && twoDPoint3.X == twoDPoint4.X && twoDPoint4.Y == twoDPoint1.Y) || (twoDPoint1.Y == twoDPoint2.Y && twoDPoint2.X == twoDPoint3.X && twoDPoint3.Y == twoDPoint4.Y && twoDPoint4.X == twoDPoint1.X)) { var markupRectangle = new MarkupRectangle(); markupRectangle.TopLeft = twoDPoint1; markupRectangle.BottomRight = twoDPoint3; markupRectangle.Name = markupText; markupRectangle.IncludeInAnnotation = polyline.IncludeFlag; markupRectangle.CalloutLocation = markupRectangle.TopLeft - new SizeF(30, 30); SetMarkupImageReference(markupRectangle, polyline); return markupRectangle; } } var points = new List<PointF>(); foreach (var spatialCoordinate in polyline.TwoDimensionSpatialCoordinateCollection) if (spatialCoordinate != null) points.Add(AsPointF(spatialCoordinate)); var markup = new MarkupPolygonal(); markup.Vertices = points; markup.Name = markupText; markup.IncludeInAnnotation = polyline.IncludeFlag; markup.CalloutLocation = markup.Vertices[0] - new SizeF(30, 30); SetMarkupImageReference(markup, polyline); return markup; } if (geometricShape is aim4_dotnet.TwoDimensionMultiPoint) { var multiPoint = (aim4_dotnet.TwoDimensionMultiPoint)geometricShape; IMarkup markup; switch (multiPoint.TwoDimensionSpatialCoordinateCollection.Count) { case 2: { // Line var markupLinear = new MarkupLinear(); markupLinear.Vertices = new List<PointF>(2); markupLinear.Vertices.Add(AsPointF(multiPoint.TwoDimensionSpatialCoordinateCollection[0])); markupLinear.Vertices.Add(AsPointF(multiPoint.TwoDimensionSpatialCoordinateCollection[1])); markupLinear.CalloutLocation = markupLinear.Vertices[0] - new SizeF(30, 30); markup = markupLinear; } break; case 3: { // Protractor var markupProtractor = new MarkupProtractor(); markupProtractor.Points = new List<PointF>(3); markupProtractor.Points.Add(AsPointF(multiPoint.TwoDimensionSpatialCoordinateCollection[0])); markupProtractor.Points.Add(AsPointF(multiPoint.TwoDimensionSpatialCoordinateCollection[1])); markupProtractor.Points.Add(AsPointF(multiPoint.TwoDimensionSpatialCoordinateCollection[2])); markupProtractor.CalloutLocation = markupProtractor.Points[0] - new SizeF(30, 30); markup = markupProtractor; } break; default: throw new NotImplementedException("Reading non-linear or non-triangular MultiPoint shape is not implemented"); } markup.Name = markupText; markup.IncludeInAnnotation = multiPoint.IncludeFlag; SetMarkupImageReference(markup, multiPoint); return markup; } // TODO - 3D GeoShapes Conversions throw new NotImplementedException(); return null; }
public static bool AimDotNetScaleEqualsTemplateTreeScaleLevel(aim4_dotnet.Scale a, TemplateTree.ScaleLevel b) { return a.Value == b.Value; }
private static string CombineOperatorAndValue(aim4_dotnet.ComparisonOperatorIdentifier operatorIdentifier, string aValue, bool capFirst) { aValue = aValue.Trim(); if (operatorIdentifier == aim4_dotnet.ComparisonOperatorIdentifier.None || operatorIdentifier == aim4_dotnet.ComparisonOperatorIdentifier.InvalidComparisonOperator) return string.IsNullOrEmpty(aValue) ? "" : aValue; if (string.IsNullOrEmpty(aValue)) return OperatorToString(operatorIdentifier, capFirst); return string.Format("{0} {1}", OperatorToString(operatorIdentifier, capFirst), aValue); }
public static TemplateTree.StandardCodeSequence ToStandardCodeSequence(aim4_dotnet.iso_21090.CD code) { return code == null ? null : new TemplateTree.StandardCodeSequence(code.CodeValue, code.CodeMeaning, code.CodingSchemeDesignator, code.CodingSchemeVersion); }
internal Aim4ImageAnnotationInstance(Aim4DocumentInstance aim4Document, aim4_dotnet.iso_21090.II annotationUid) : base(aim4Document, annotationUid) { Platform.CheckTrue(IsImageAnnotation, "IsImageAnnotation"); }