Esempio n. 1
0
        /// <summary>
        /// This method draws the statistic bubbles and transisiton arrows
        ///   of given <see cref="SampleType"/> in given <see cref="VisualizationModes"/>.
        /// </summary>
        /// <param name="mode">
        /// The <see cref="VisualizationModes"/> to be used.
        /// </param>
        /// <param name="sampleType">
        /// The <see cref="SampleType"/> of the data.
        /// </param>
        public void DrawAOIStatistics(VisualizationModes mode, SampleType sampleType)
        {
            // Skip if no data available
            if (this.aoiStatistics == null)
            {
                return;
            }

            // Get all statistical elements
            var statisticalElements = this.Elements.FindAllGroupMembers(VGStyleGroup.AOI_STATISTICS_ARROW);

            statisticalElements.AddRange(this.Elements.FindAllGroupMembers(VGStyleGroup.AOI_STATISTICS_BUBBLE));

            this.Elements.RemoveAll(statisticalElements);

            var distances = new List <int>();

            var aoisWithoutSearchRects = new VGElementCollection();

            foreach (VGElement aoi in this.AoiCollection)
            {
                if (aoi.StyleGroup != VGStyleGroup.AOI_SEARCHRECT)
                {
                    aoisWithoutSearchRects.Add(aoi);
                }
            }

            foreach (VGElement aoi in aoisWithoutSearchRects)
            {
                if (!this.aoiStatistics.ContainsKey(aoi.Name))
                {
                    continue;
                }

                var aoiStatistic = this.aoiStatistics[aoi.Name];
                if ((mode & VisualizationModes.FixationTime) == VisualizationModes.FixationTime)
                {
                    if (aoiStatistic.SumOfTimeOfAllFixations > 0)
                    {
                        var bounds  = this.GetCircleBounds(aoi.Center, aoiStatistic.SumOfTimeOfAllFixations, mode);
                        var ellipse = new VGEllipse(
                            this.BubbleDrawAction,
                            this.BubblePen,
                            this.BubbleBrush,
                            this.BubbleFont,
                            this.BubbleFontColor,
                            bounds,
                            VGStyleGroup.AOI_STATISTICS_BUBBLE,
                            aoiStatistic.SumOfTimeOfAllFixations + " ms",
                            string.Empty);

                        ellipse.TextAlignment = this.BubbleTextAlignment;
                        distances.Add((int)(bounds.Width / 2));
                        this.Elements.Add(ellipse);
                    }
                }

                if ((mode & VisualizationModes.NumberOfFixations) == VisualizationModes.NumberOfFixations)
                {
                    if (aoiStatistic.FixationCount > 0)
                    {
                        var bounds  = this.GetCircleBounds(aoi.Center, aoiStatistic.FixationCount, mode);
                        var ellipse = new VGEllipse(
                            this.BubbleDrawAction,
                            this.BubblePen,
                            this.BubbleBrush,
                            this.BubbleFont,
                            this.BubbleFontColor,
                            bounds,
                            VGStyleGroup.AOI_STATISTICS_BUBBLE,
                            aoiStatistic.FixationCount.ToString(CultureInfo.InvariantCulture),
                            string.Empty);

                        ellipse.TextAlignment = this.BubbleTextAlignment;
                        distances.Add((int)(bounds.Width / 2));
                        this.Elements.Add(ellipse);
                    }
                }

                if ((mode & VisualizationModes.AverageFixationDuration) == VisualizationModes.AverageFixationDuration)
                {
                    if (aoiStatistic.FixationDurationMean > 0)
                    {
                        var bounds  = this.GetCircleBounds(aoi.Center, aoiStatistic.FixationDurationMean, mode);
                        var ellipse = new VGEllipse(
                            this.BubbleDrawAction,
                            this.BubblePen,
                            this.BubbleBrush,
                            this.BubbleFont,
                            this.BubbleFontColor,
                            bounds,
                            VGStyleGroup.AOI_STATISTICS_BUBBLE,
                            aoiStatistic.FixationDurationMean.ToString("N0") + " ms",
                            string.Empty);
                        ellipse.TextAlignment = this.BubbleTextAlignment;
                        distances.Add((int)(bounds.Width / 2));
                        this.Elements.Add(ellipse);
                    }
                }
            }

            // Check for absolute or relative transition values
            var absolute = (mode & VisualizationModes.AbsoluteTransitions) == VisualizationModes.AbsoluteTransitions;

            if ((mode & VisualizationModes.RelativeTransitions) == VisualizationModes.RelativeTransitions ||
                (mode & VisualizationModes.AbsoluteTransitions) == VisualizationModes.AbsoluteTransitions)
            {
                DataView trialsFixations = null;

                // Get filtered fixations data view
                switch (sampleType)
                {
                case SampleType.Gaze:
                    trialsFixations = this.GazeFixationsView;
                    break;

                case SampleType.Mouse:
                    trialsFixations = this.MouseFixationsView;
                    break;
                }

                var transitions = Statistics.Statistic.CreateTransitionMatrixForSingleAOIs(
                    trialsFixations,
                    aoisWithoutSearchRects);

                float transitionSum = 0;

                // Calculate transition total sum only if relative values are requested.
                if (!absolute)
                {
                    for (var i = 0; i <= transitions.GetUpperBound(0); i++)
                    {
                        // Skip nowhere transitions
                        if (i == 0)
                        {
                            continue;
                        }

                        for (var j = 0; j <= transitions.GetUpperBound(1); j++)
                        {
                            // Only take values outside the diagonal
                            if (i == j || j == 0)
                            {
                                continue;
                            }

                            transitionSum += (int)transitions.GetValue(i, j);
                        }
                    }
                }

                // Write transitionMatrix to dgv
                for (var i = transitions.GetLowerBound(0); i <= transitions.GetUpperBound(0); i++)
                {
                    // Skip nowhere transitions
                    if (i == 0)
                    {
                        continue;
                    }

                    for (var j = transitions.GetLowerBound(1); j <= transitions.GetUpperBound(1); j++)
                    {
                        // Only take values above the diagonal
                        if (i >= j)
                        {
                            continue;
                        }

                        float transAtoB;
                        float transBtoA;
                        if (absolute)
                        {
                            transAtoB = (int)transitions.GetValue(i, j);
                            transBtoA = (int)transitions.GetValue(j, i);
                        }
                        else
                        {
                            transAtoB = (float)Math.Round((int)transitions.GetValue(i, j) / transitionSum * 100, 1);
                            transBtoA = (float)Math.Round((int)transitions.GetValue(j, i) / transitionSum * 100, 1);
                        }

                        if (transAtoB > 0 || transBtoA > 0)
                        {
                            var showNumbers = false;
                            if ((this.ArrowDrawAction & ShapeDrawAction.Name) == ShapeDrawAction.Name)
                            {
                                this.ArrowDrawAction |= ~ShapeDrawAction.Name;
                                showNumbers           = true;
                            }

                            var arrow = new VGArrow(this.ArrowDrawAction, this.ArrowPen);
                            arrow.Brush = this.ArrowBrush;
                            if (!showNumbers)
                            {
                                arrow.HideWeights = true;
                            }

                            var location1      = aoisWithoutSearchRects[i - 1].Center;
                            var location2      = aoisWithoutSearchRects[j - 1].Center;
                            var distanceFirst  = distances.Count >= i ? distances[i - 1] : 15;
                            var distanceSecond = distances.Count >= j ? distances[j - 1] : 15;
                            if (location1.X <= location2.X)
                            {
                                arrow.FirstPoint          = location1;
                                arrow.SecondPoint         = location2;
                                arrow.FirstPointDistance  = distanceFirst;
                                arrow.SecondPointDistance = distanceSecond;
                                arrow.FirstPointWeight    = transBtoA;
                                arrow.SecondPointWeight   = transAtoB;
                            }
                            else
                            {
                                arrow.FirstPoint          = location2;
                                arrow.SecondPoint         = location1;
                                arrow.FirstPointDistance  = distanceSecond;
                                arrow.SecondPointDistance = distanceFirst;
                                arrow.FirstPointWeight    = transAtoB;
                                arrow.SecondPointWeight   = transBtoA;
                            }

                            arrow.FormatString = "N0";
                            if (!absolute)
                            {
                                if (arrow.FirstPointWeight < 1 && arrow.SecondPointWeight < 1)
                                {
                                    arrow.FormatString = "N1";
                                }

                                arrow.AddOnString = "%";
                            }

                            arrow.WeightFont      = this.ArrowFont;
                            arrow.WeightFontColor = this.ArrowFontColor;
                            arrow.ScaleFactor     = this.ArrowFactor;
                            arrow.StyleGroup      = VGStyleGroup.AOI_STATISTICS_ARROW;
                            arrow.TextAlignment   = this.ArrowTextAlignment;
                            this.Elements.Add(arrow);
                        }
                    }
                }
            }

            this.DrawForeground(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Loads the shapes that are listed in the given database table
        ///   and creates corresponding graphic elements.
        /// </summary>
        /// <param name="areaOfInterestTableRows">
        /// Areas of interest table as
        ///   a <see cref="DataGridViewRowCollection"/>
        /// </param>
        public void LoadShapesFromDataGridView(DataGridViewRowCollection areaOfInterestTableRows)
        {
            try
            {
                // Create aoi elements from data view
                this.AoiCollection = new VGElementCollection();

                foreach (DataGridViewRow row in areaOfInterestTableRows)
                {
                    if (!row.IsNewRow)
                    {
                        // retrieve shape parameters from cell values.
                        var          shapeName = row.Cells["colShapeName"].Value.ToString();
                        var          strPtList = row.Cells["colShapePts"].Value.ToString();
                        Pen          usedPen;
                        Font         usedFont;
                        Color        usedFontColor;
                        VGAlignment  usedAlignment;
                        VGStyleGroup usedStyleGroup;
                        var          pointList        = ObjectStringConverter.StringToPointFList(strPtList);
                        var          usedElementGroup = row.Cells["colShapeGroup"].Value.ToString();
                        switch (usedElementGroup)
                        {
                        case "Target":
                            usedPen        = this.TargetPen;
                            usedFont       = this.TargetFont;
                            usedFontColor  = this.TargetFontColor;
                            usedStyleGroup = VGStyleGroup.AOI_TARGET;
                            usedAlignment  = this.TargetTextAlignment;
                            break;

                        case "SearchRect":
                            usedPen        = this.SearchRectPen;
                            usedFont       = this.SearchRectFont;
                            usedFontColor  = this.SearchRectFontColor;
                            usedStyleGroup = VGStyleGroup.AOI_SEARCHRECT;
                            usedAlignment  = this.SearchRectTextAlignment;
                            break;

                        default:
                            usedPen        = this.DefaultPen;
                            usedFont       = this.DefaultFonts;
                            usedFontColor  = this.DefaultFontColor;
                            usedStyleGroup = VGStyleGroup.AOI_NORMAL;
                            usedAlignment  = this.DefaultTextAlignment;
                            break;
                        }

                        // Create the shape depending on ShapeType
                        var boundingRect = new RectangleF();
                        switch (row.Cells["colShapeType"].Value.ToString())
                        {
                        case "Rectangle":
                            boundingRect.Location = pointList[0];
                            boundingRect.Width    = pointList[2].X - pointList[0].X;
                            boundingRect.Height   = pointList[2].Y - pointList[0].Y;

                            // Create Rect with defined stroke
                            var newRect =
                                new VGRectangle(
                                    this.hideAOIDescription ? ShapeDrawAction.Edge : ShapeDrawAction.NameAndEdge,
                                    usedPen,
                                    usedFont,
                                    usedFontColor,
                                    boundingRect,
                                    usedStyleGroup,
                                    shapeName,
                                    usedElementGroup);
                            newRect.TextAlignment = usedAlignment;
                            this.AoiCollection.Add(newRect);
                            break;

                        case "Ellipse":
                            boundingRect.Location = pointList[0];
                            boundingRect.Width    = pointList[2].X - pointList[0].X;
                            boundingRect.Height   = pointList[2].Y - pointList[0].Y;

                            // Create Rect with defined stroke
                            var newEllipse =
                                new VGEllipse(
                                    this.hideAOIDescription ? ShapeDrawAction.Edge : ShapeDrawAction.NameAndEdge,
                                    usedPen,
                                    usedFont,
                                    usedFontColor,
                                    boundingRect,
                                    usedStyleGroup,
                                    shapeName,
                                    usedElementGroup);
                            newEllipse.TextAlignment = usedAlignment;
                            this.AoiCollection.Add(newEllipse);
                            break;

                        case "Polyline":

                            // Create Polyline with defined stroke
                            var newPolyline =
                                new VGPolyline(
                                    this.hideAOIDescription ? ShapeDrawAction.Edge : ShapeDrawAction.NameAndEdge,
                                    usedPen,
                                    usedFont,
                                    usedFontColor,
                                    usedStyleGroup,
                                    shapeName,
                                    usedElementGroup);
                            newPolyline.TextAlignment = usedAlignment;
                            foreach (var point in pointList)
                            {
                                newPolyline.AddPt(point);
                            }

                            newPolyline.ClosePolyline();
                            this.AoiCollection.Add(newPolyline);
                            break;
                        }
                    }
                }

                // Reset Elements (deselect and clear all)
                this.ResetPicture();

                this.Elements.AddRange(this.AoiCollection);

                // If there were a selected element before updating, try
                // to select it again.
                if (this.SelectedElement != null)
                {
                    foreach (VGElement element in this.Elements)
                    {
                        if (VGPolyline.Distance(element.Location, this.SelectedElement.Location) < 1)
                        {
                            this.SelectedElement = element;
                            element.IsInEditMode = true;
                        }
                    }
                }

                this.DrawForeground(true);
            }
            catch (Exception ex)
            {
                ExceptionMethods.HandleException(ex);
            }
        }
Esempio n. 3
0
        ///////////////////////////////////////////////////////////////////////////////
        // Eventhandler for Custom Defined Events                                    //
        ///////////////////////////////////////////////////////////////////////////////
        #region CUSTOMEVENTHANDLER
        #endregion //CUSTOMEVENTHANDLER

        #endregion //EVENTS

        ///////////////////////////////////////////////////////////////////////////////
        // Methods and Eventhandling for Background tasks                            //
        ///////////////////////////////////////////////////////////////////////////////
        #region BACKGROUNDWORKER
        #endregion //BACKGROUNDWORKER

        ///////////////////////////////////////////////////////////////////////////////
        // Inherited methods                                                         //
        ///////////////////////////////////////////////////////////////////////////////
        #region OVERRIDES
        #endregion //OVERRIDES

        ///////////////////////////////////////////////////////////////////////////////
        // Methods for doing main class job                                          //
        ///////////////////////////////////////////////////////////////////////////////
        #region METHODS

        /// <summary>
        /// This method creates the shape that is defined in this dialog to be added to a slide.
        /// </summary>
        /// <returns>The ready to use <see cref="VGElement"/>.</returns>
        private VGElement GenerateNewShape()
        {
            VGElement element = null;

            if (this.rdbRectangle.Checked)
            {
                element = new VGRectangle(
                    this.pbcStyle.DrawAction,
                    this.pbcStyle.NewPen,
                    this.pbcStyle.NewBrush,
                    this.pbcStyle.NewFont,
                    this.pbcStyle.NewFontColor,
                    new RectangleF(0, 0, 100, 100),
                    VGStyleGroup.None,
                    this.pbcStyle.NewName,
                    string.Empty);
            }
            else if (this.rdbEllipse.Checked)
            {
                element = new VGEllipse(
                    this.pbcStyle.DrawAction,
                    this.pbcStyle.NewPen,
                    this.pbcStyle.NewBrush,
                    this.pbcStyle.NewFont,
                    this.pbcStyle.NewFontColor,
                    new RectangleF(0, 0, 100, 100),
                    VGStyleGroup.None,
                    this.pbcStyle.NewName,
                    string.Empty);
            }
            else if (this.rdbPolyline.Checked)
            {
                element = new VGPolyline(
                    this.pbcStyle.DrawAction,
                    this.pbcStyle.NewPen,
                    this.pbcStyle.NewBrush,
                    this.pbcStyle.NewFont,
                    this.pbcStyle.NewFontColor,
                    VGStyleGroup.None,
                    this.pbcStyle.NewName,
                    string.Empty);
            }
            else if (this.rdbSharp.Checked)
            {
                element = new VGSharp(
                    this.pbcStyle.DrawAction,
                    this.pbcStyle.NewPen,
                    this.pbcStyle.NewFont,
                    this.pbcStyle.NewFontColor,
                    new RectangleF(0, 0, 100, 100),
                    VGStyleGroup.None,
                    this.pbcStyle.NewName,
                    string.Empty);
            }
            else if (this.rdbLine.Checked)
            {
                element = new VGLine(
                    this.pbcStyle.DrawAction,
                    this.pbcStyle.NewPen,
                    this.pbcStyle.NewFont,
                    this.pbcStyle.NewFontColor,
                    VGStyleGroup.None,
                    this.pbcStyle.NewName,
                    string.Empty);
            }

            element.Sound = this.audioControl.Sound;

            return(element);
        }