private Dictionary<string, HashSet<int>> _sopInstanceUidAndFrameNumber; // if specified, annotation is created for these SOP Instances with the specified frame numbers only. The images must belong to the same series.

        #endregion Fields

        #region Constructors

        public AimAnnotationCreationContext(AnnotationKind annotationKind, TemplateTree.StandardCodeSequence annotationTypeCode, TemplateTree.AimTemplateTree templateTree, int seriesNumber)
        {
            Platform.CheckForNullReference(annotationTypeCode, "annotationTypeCode");
            Platform.CheckForNullReference(templateTree, "templateTree");

            _annotationKind = annotationKind;
            _annotationTypeCode = annotationTypeCode;
            _templateTree = templateTree;
            _seriesNumber = seriesNumber;
            _includeCalculations = true;
        }
Пример #2
0
        private Dictionary <string, HashSet <int> > _sopInstanceUidAndFrameNumber;      // if specified, annotation is created for these SOP Instances with the specified frame numbers only. The images must belong to the same series.

        public AimAnnotationCreationContext(AnnotationKind annotationKind, TemplateTree.StandardCodeSequence annotationTypeCode, TemplateTree.AimTemplateTree templateTree, int seriesNumber)
        {
            Platform.CheckForNullReference(annotationTypeCode, "annotationTypeCode");
            Platform.CheckForNullReference(templateTree, "templateTree");

            _annotationKind      = annotationKind;
            _annotationTypeCode  = annotationTypeCode;
            _templateTree        = templateTree;
            _seriesNumber        = seriesNumber;
            _includeCalculations = true;
        }
        public static AimTemplateTree AimAnnotationToAimTemplateTree(Aim4AnnotationInstance annotationInstance, AimTemplateTree template)
        {
            if (annotationInstance == null || annotationInstance.AimAnnotationEntity == null)
                return null;

            var annotation = annotationInstance.AimAnnotationEntity;
            if (annotation.ImagingPhysicalEntityCollection != null)
            {
                foreach (var imgPhysEnt in annotation.ImagingPhysicalEntityCollection)
                {
                    if (IsNullCodeList(imgPhysEnt.TypeCode))
                        continue;

                    AimTemplateTreeAnatomicEntityNode matchingTreeNode = FromImagingPhysicalEntity(imgPhysEnt, template);
                    if (matchingTreeNode == null)
                        return null;
                }
            }
            if (annotation.ImagingObservationEntityCollection != null)
            {
                foreach (var io in annotation.ImagingObservationEntityCollection)
                {
                    if (IsNullCodeList(io.TypeCode))
                        continue;

                    AimTemplateTreeImagingObservationNode matchingTreeNode = FromImagingObservationEntity(io, template);
                    if (matchingTreeNode == null)
                        return null;
                }
            }
            if (annotation.CalculationEntityCollection != null)
            {
                //foreach (var calc in annotation.CalculationCollection)
                //{
                //    AimTemplateTreeCalculationNode matchingTreeNode =
                //        template.TemplateNodes.OfType<AimTemplateTreeCalculationNode>().FirstOrDefault(
                //            treeCalc => treeCalc.Label == calc.Description);
                //    if (matchingTreeNode != null)
                //    {
                //        AimTemplateTreeCalculationType matchingCalculationType =
                //            matchingTreeNode.CalculationTypes.FirstOrDefault(
                //                treeCalc => ToStandardCodeSequence(treeCalc).CodeValue == calc.CodeValue);
                //        if (matchingCalculationType != null)
                //        {
                //            matchingTreeNode.SelectedCalculationType = matchingCalculationType;
                //        }
                //        else
                //            return null;

                //        //if (matchingTreeNode.HasConfidence && calc..HasValue)
                //        //    matchingTreeNode.ConfidenceValue = calc.AnnotatorConfidence.Value;
                //    }
                //    else
                //        return null;
                //}
            }
            if (annotation.InferenceEntityCollection != null)
            {
                foreach (var inference in annotation.InferenceEntityCollection)
                {
                    if (IsNullCodeList(inference.TypeCode))
                        continue;

                    foreach (var inferenceNode in template.TemplateNodes.OfType<AimTemplateTreeInferenceNode>())
                    {
                        AimTemplateTreeAllowedTerm matchingAllowedTerm =
                            inferenceNode.AllowedTerms.FirstOrDefault(term => DoTheyMatch(term, inference.TypeCode));
                        if (matchingAllowedTerm != null)
                            matchingAllowedTerm.Selected = true;
                    }
                }
            }
            template.Markup.Clear();
            if (annotation is aim4_dotnet.ImageAnnotation)
            {
                var imageAnnotation = (aim4_dotnet.ImageAnnotation)annotation;
                var annotationName = string.IsNullOrEmpty(imageAnnotation.Name) ? "" : imageAnnotation.Name;

                if (imageAnnotation.MarkupEntityCollection != null)
                {
                    foreach (var markupEntity in imageAnnotation.MarkupEntityCollection)
                    {
                        if (markupEntity is aim4_dotnet.GeometricShapeEntity)
                        {
                            var markup = ToMarkup2D((aim4_dotnet.GeometricShapeEntity)markupEntity, annotationName);
                            if (markup != null)
                                template.Markup.Add(markup);
                        }
                        else if (markupEntity is aim4_dotnet.TextAnnotationEntity)
                        {
                            var textAnnotationEntity = (aim4_dotnet.TextAnnotationEntity) markupEntity;
                            if (textAnnotationEntity.GeometricShapeEntity != null)
                            {
                                var calloutText = AimHelpers.FormatPointCalloutText(annotationName, textAnnotationEntity.Text);
                                aim4_dotnet.TwoDimensionGeometricShapeEntity geoShapeEntity = null;
                                if (textAnnotationEntity.GeometricShapeEntity is aim4_dotnet.TwoDimensionGeometricShapeEntity)
                                {
                                    var twoDGeoShape = (aim4_dotnet.TwoDimensionGeometricShapeEntity) textAnnotationEntity.GeometricShapeEntity;
                                    switch (twoDGeoShape.TwoDimensionSpatialCoordinateCollection.Count)
                                    {
                                        case 1:
                                            {
                                                var markup = new MarkupPoint();
                                                markup.Name = annotationName;
                                                markup.IncludeInAnnotation = twoDGeoShape.IncludeFlag;
                                                markup.Point = AsPointF(twoDGeoShape.TwoDimensionSpatialCoordinateCollection[0]);
                                                markup.CalloutText = calloutText;
                                                markup.CalloutLocation = new PointF(markup.Point.X, markup.Point.Y);
                                                SetMarkupImageReference(markup, twoDGeoShape);
                                                markup.UseCrosshair = AimSettings.Default.UseCrosshairsForTextCallouts;
                                                template.Markup.Add(markup);
                                            }
                                            break;
                                        case 2:
                                            {
                                                var markup = new MarkupPoint();
                                                markup.Name = annotationName;
                                                markup.IncludeInAnnotation = twoDGeoShape.IncludeFlag;
                                                markup.Point = AsPointF(twoDGeoShape.TwoDimensionSpatialCoordinateCollection[0]);
                                                markup.CalloutText = calloutText;
                                                markup.CalloutLocation = AsPointF(twoDGeoShape.TwoDimensionSpatialCoordinateCollection[1]);
                                                SetMarkupImageReference(markup, twoDGeoShape);
                                                markup.UseCrosshair = AimSettings.Default.UseCrosshairsForTextCallouts;
                                                template.Markup.Add(markup);
                                            }
                                            break;
                                        default:
                                            Platform.Log(LogLevel.Error, "TextAnnotation has [{0}] Connector Points", twoDGeoShape.TwoDimensionSpatialCoordinateCollection.Count);
                                            break;
                                    }
                                }
                                else if (textAnnotationEntity.GeometricShapeEntity is aim4_dotnet.ThreeDimensionGeometricShapeEntity)
                                {
                                    // TODO: implement 2D markup conversion!
                                    // TODO: convert to the 2D ImageReferenceUid and referencedFrameNumber!

                                    var threeDGeoShape = (aim4_dotnet.ThreeDimensionGeometricShapeEntity) textAnnotationEntity.GeometricShapeEntity;
                                    switch (threeDGeoShape.ThreeDimensionSpatialCoordinateCollection.Count)
                                    {
                                        case 1:
                                            throw new NotImplementedException();
                                            break;
                                        case 2:
                                            throw new NotImplementedException();
                                            break;
                                        default:
                                            Platform.Log(LogLevel.Error, "TextAnnotation has [{0}] 3D Connector Points", threeDGeoShape.ThreeDimensionSpatialCoordinateCollection.Count);
                                            break;
                                    }
                                }
                            }
                        }
                        else
                            Debug.Assert(false, "Unexpected markup type");
                    }
                }
            }
            return template;
        }
        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;
        }