Beispiel #1
0
        private ActionResult Navigate(Topic topic, NavigationParameter navigationParameter, ENavigationDirection navigationDirection)
        {
            #region validation

            CheckMandatoryParameter(nameof(navigationParameter), navigationParameter);

            #endregion

            // create naviation result
            ImageNavigationResultView result = GetImageLabelNavigationResult(topic, navigationParameter, navigationDirection);
            if (result != null)
            {
                return(Ok(result));
            }
            return(NotFound(Messages.ImageNotFound((uint)navigationParameter.Index)));
        }
Beispiel #2
0
        private ImageNavigationResultView GetImageLabelNavigationResult(Topic topic, NavigationParameter navigationParameter, ENavigationDirection navigationDirection)
        {
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // fill imagelabel-structure of image label
            ImageNavigationResult image = NavigationService.Navigate(topic, navigationParameter.Index, navigationParameter.LabelMode, navigationDirection);


            // default navigation if not label was found on navigation to blank
            if (image == null && (navigationDirection == ENavigationDirection.Blank || navigationDirection == ENavigationDirection.LastBlank))
            {
                image = NavigationService.Navigate(topic, navigationParameter.Index, navigationParameter.LabelMode, ENavigationDirection.Direct);
            }

            if (image == null)
            {
                // return http-404 if no label found
                return(null);
            }

            // create naviation result
            ImageNavigationResultView navigationResult = ImageNavigationResultFactory.CreateView(image);

            switch (navigationParameter.LabelMode)
            {
            case ELabelMode.ObjectDetection:
                if (image.ImageLabel.HasLabels)
                {
                    IEnumerable <Label> labels = LabelService.GetLabels(topic, image.ImageLabel);
                    navigationResult.ImageLabel.Labels = labels.Select(LabelFactory.CreateView);
                }
                break;
            }

            sw.Stop();
            Log.Information($"Navigation takes {sw.ElapsedMilliseconds} ms");

            return(navigationResult);
        }