コード例 #1
0
        ///////////////////////////////////////////////////////////////////////////////
        // Eventhandler                                                              //
        ///////////////////////////////////////////////////////////////////////////////
        #region EVENTHANDLER

        /// <summary>
        /// The <see cref="Form.Load"/> event handler that initializes the UI.
        /// </summary>
        /// <param name="sender">Source of the event</param>
        /// <param name="e">An empty <see cref="EventArgs"/></param>
        private void VideoPropertiesDialog_Load(object sender, EventArgs e)
        {
            // Intialize picture
            this.picPreview.PresentationSize = this.outputVideoSize;
            this.ResizeCanvas();

            this.gazeVideoRect      = new VGImage(this.videoExportProperties.GazeVideoProperties.StreamScreenshot, ImageLayout.Stretch, this.outputVideoSize);
            this.gazeVideoRect.Name = this.videoExportProperties.GazeVideoProperties.StreamName;
            this.picPreview.Elements.Add(this.gazeVideoRect);

            if (File.Exists(this.videoExportProperties.UserVideoProperties.StreamFilename))
            {
                this.userVideoRect      = new VGImage(this.videoExportProperties.UserVideoProperties.StreamScreenshot, ImageLayout.Stretch, this.outputVideoSize);
                this.userVideoRect.Name = this.videoExportProperties.UserVideoProperties.StreamName;
                this.picPreview.Elements.Add(this.userVideoRect);
                this.isUserVideoAvailable = true;
            }
            else
            {
                this.grbUserVideoOptions.Visible = false;
                this.chbUserVideoVisible.Checked = false;
                this.isUserVideoAvailable        = false;
                this.grpGazeMouseOptions.Visible = false;
                this.chbUserVideoVisible.Visible = false;
                this.label13.Visible             = false;
            }

            this.PopulateDefaultProperties();

            this.UpdatePositionNumerics();
            this.isInitializing = false;
            this.UpdatePreview();
        }
コード例 #2
0
        /// <summary>
        /// The <see cref="Control.Click"/> event handler for the
        /// <see cref="Button"/> <see cref="btnImage"/>.
        /// Shows a <see cref="ImageDialog"/> to define an umage stimulus
        /// that is added to all imported slides.
        /// </summary>
        /// <param name="sender">Source of the event.</param>
        /// <param name="e">An empty <see cref="EventArgs"/></param>
        private void btnImage_Click(object sender, EventArgs e)
        {
            ImageDialog dlg = new ImageDialog();

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                VGImage image = dlg.NewImage;
                image.Canvas = Document.ActiveDocument.PresentationSize;
                this.cbbDesignedItem.Items.Add(image);
                this.cbbDesignedItem.SelectedItem = image;
            }
        }
コード例 #3
0
 /// <summary>
 /// <see cref="ComboBox.SelectedIndexChanged"/> event handler
 /// for the <see cref="cbbImageLayout"/> <see cref="ComboBox"/>.
 /// Updates a selected <see cref="VGImage"/> with the new <see cref="ImageLayout"/>.
 /// </summary>
 /// <param name="sender">Source of the event.</param>
 /// <param name="e">An empty <see cref="EventArgs"/></param>
 private void cbbImageLayout_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (this.designPicture.SelectedElement != null && !this.isInitializingSelectedShape)
     {
         if (this.designPicture.SelectedElement is VGImage)
         {
             VGImage image = (VGImage)this.designPicture.SelectedElement;
             image.Layout = (ImageLayout)Enum.Parse(typeof(ImageLayout), this.cbbImageLayout.Text);
             this.designPicture.DrawForeground(true);
         }
     }
 }
コード例 #4
0
        ///////////////////////////////////////////////////////////////////////////////
        // Eventhandler                                                              //
        ///////////////////////////////////////////////////////////////////////////////
        #region EVENTS

        ///////////////////////////////////////////////////////////////////////////////
        // Eventhandler for UI, Menu, Buttons, Toolbars etc.                         //
        ///////////////////////////////////////////////////////////////////////////////
        #region WINDOWSEVENTHANDLER
        #endregion //WINDOWSEVENTHANDLER

        ///////////////////////////////////////////////////////////////////////////////
        // Eventhandler for Custom Defined Events                                    //
        ///////////////////////////////////////////////////////////////////////////////
        #region CUSTOMEVENTHANDLER
        #endregion //CUSTOMEVENTHANDLER

        #endregion //EVENTS

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

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

        /// <summary>
        /// This method updates the given element with the new resources path
        /// </summary>
        /// <param name="newResourcesPath">The new resource path</param>
        /// <param name="element">The <see cref="VGElement"/> to update.</param>
        private static void UpdateElement(string newResourcesPath, VGElement element)
        {
            // check all element for sounds
            if (element.Sound == null)
            {
                element.Sound = new AudioFile();
            }

            if (element.Sound.Filename != null)
            {
                if (element.Sound.Filename.Contains(@"\"))
                {
                    element.Sound.Filename = System.IO.Path.GetFileName(element.Sound.Filename);
                }

                element.Sound.Filepath = newResourcesPath;
            }

            // check file based elements
            if (element is VGScrollImage)
            {
                var scrollImage = (VGScrollImage)element;
                if (scrollImage.Filepath != newResourcesPath)
                {
                    scrollImage.Filename = System.IO.Path.GetFileName(scrollImage.Filename);
                    scrollImage.Filepath = newResourcesPath;
                    scrollImage.Canvas   = Document.ActiveDocument.PresentationSize;
                }

                scrollImage.CreateInternalImage();
            }
            else if (element is VGImage)
            {
                VGImage image = (VGImage)element;
                if (image.Filepath != newResourcesPath)
                {
                    image.Filename = System.IO.Path.GetFileName(image.Filename);
                    image.Filepath = newResourcesPath;
                    image.Canvas   = Document.ActiveDocument.PresentationSize;
                    image.CreateInternalImage();
                }
            }
            else if (element is VGFlash)
            {
                VGFlash flash = (VGFlash)element;
                if (flash.Filepath != newResourcesPath)
                {
                    flash.Filename = System.IO.Path.GetFileName(flash.Filename);
                    flash.Filepath = newResourcesPath;
                }
            }
        }
コード例 #5
0
ファイル: CoverEffect.cs プロジェクト: liwq-net/XnaVG
        public void SetImagePaint(VGImage image, VGMatrix paintTransformation)
        {
            if (image.LinearColorspace)
                _passIndex |= 1;
            else
                _passIndex &= ~1;

            _effect.CurrentTechnique = _techniques[(int)(image.Premultiplied ? VGPaintType.PatternPremultiplied : VGPaintType.Pattern)];
            _paintTransformation.SetValue(paintTransformation);
            _focalPoint.SetValue(Vector2.Zero);
            _effect.GraphicsDevice.Textures[1] = image.Texture;
            _effect.GraphicsDevice.SamplerStates[1] = image.GetSamplerState();
        }
コード例 #6
0
 /// <summary>
 /// <see cref="Control.TextChanged"/> event handler for the
 /// <see cref="TextBox"/> <see cref="txbImageFilename"/>.
 /// Updates the image file of a selected <see cref="VGImage"/> element with the new value.
 /// </summary>
 /// <param name="sender">Source of the event.</param>
 /// <param name="e">A empty <see cref="EventArgs"/></param>
 private void txbImageFilename_TextChanged(object sender, EventArgs e)
 {
     if (this.designPicture.SelectedElement != null && !this.isInitializingSelectedShape)
     {
         if (this.designPicture.SelectedElement is VGImage)
         {
             VGImage image = (VGImage)this.designPicture.SelectedElement;
             image.Filename = Path.GetFileName(this.txbImageFilename.Text);
             image.CreateInternalImage();
             this.designPicture.DrawForeground(true);
         }
     }
 }
コード例 #7
0
        ///////////////////////////////////////////////////////////////////////////////
        // Eventhandler                                                              //
        ///////////////////////////////////////////////////////////////////////////////
        #region EVENTS

        ///////////////////////////////////////////////////////////////////////////////
        // Eventhandler for Custom Defined Events                                    //
        ///////////////////////////////////////////////////////////////////////////////
        #region CUSTOMEVENTHANDLER
        #endregion //CUSTOMEVENTHANDLER

        #endregion //EVENTS

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

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

        /// <summary>
        /// This method calculates an heat map out of the
        /// given channel file and overlays it on the
        /// background.
        /// </summary>
        /// <param name="channelFilename">A <see cref="string"/> with
        /// filename and full path of the channel image to use.</param>
        public void VisualizeChannelMapOverlay(string channelFilename)
        {
            Bitmap heatMap = AttentionMaps.CreateHeatMapFromBWImage(
                this.HeatMap,
                this.ColorMap,
                this.StimulusSize,
                channelFilename);
            VGImage newImage = new VGImage(heatMap, ImageLayout.Center, this.StimulusSize);

            this.Elements.Clear();
            this.Elements.Add(newImage);
            this.DrawFixationsForCurrentSubject();
            this.DrawForeground(true);
        }
コード例 #8
0
ファイル: CoverEffect.cs プロジェクト: liwq-net/XnaVG
 public void SetMask(VGImage mask, Vector4 channels)
 {
     if (mask == null)
     {
         _passIndex &= ~2;
         _effect.GraphicsDevice.Textures[0] = null;
     }
     else
     {
         _passIndex |= 2;
         _effect.GraphicsDevice.Textures[0] = mask.Texture;
         _effect.GraphicsDevice.SamplerStates[0] = mask.GetSamplerState();
         _maskChannels.SetValue(channels);
     }
 }
コード例 #9
0
ファイル: VGPatternPaint.cs プロジェクト: liwq-net/XnaVG
 internal VGPatternPaint(VGDevice device, VGImage image)
     : base(device)
 {
     Pattern = image;
 }
コード例 #10
0
        ///////////////////////////////////////////////////////////////////////////////
        // Eventhandler for Custom Defined Events                                    //
        ///////////////////////////////////////////////////////////////////////////////
        #region CUSTOMEVENTHANDLER
        #endregion //CUSTOMEVENTHANDLER

        #endregion //EVENTS

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

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

        /// <summary>
        /// This method does the parsing of the given path and creates for each readable
        /// image or media file a trial with the defined conditions.
        /// </summary>
        /// <returns>A <see cref="List{Slide}"/> to be imported in the slideshow of
        /// the experiment.</returns>
        private List <Slide> GetSlides()
        {
            var newSlides = new List <Slide>();

            var dirInfoStimuli = new DirectoryInfo(this.txbFolder.Text);

            if (dirInfoStimuli.Exists)
            {
                var files = dirInfoStimuli.GetFiles();
                Array.Sort(files, new NumericComparer());
                foreach (var file in files)
                {
                    var extension = file.Extension.ToLower();
                    // Ignore files with unrecognized extensions
                    switch (extension)
                    {
                    case ".bmp":
                    case ".png":
                    case ".jpg":
                    case ".wmf":
                    case ".mp3":
                    case ".wav":
                    case ".wma":
                        break;

                    default:
                        continue;
                    }

                    // Ignore hidden and MAC files
                    if (file.Name.StartsWith("."))
                    {
                        continue;
                    }

                    var newSlide = new Slide
                    {
                        BackgroundColor      = this.clbBackground.CurrentColor,
                        Modified             = true,
                        MouseCursorVisible   = this.chbShowMouseCursor.Checked,
                        MouseInitialPosition = this.psbMouseCursor.CurrentPosition,
                        Name             = Path.GetFileNameWithoutExtension(file.Name),
                        PresentationSize = Document.ActiveDocument.PresentationSize
                    };

                    StopCondition stop = null;
                    if (this.rdbTime.Checked)
                    {
                        stop = new TimeStopCondition((int)(this.nudTime.Value * 1000));
                    }
                    else if (this.rdbKey.Checked)
                    {
                        string           selectedItemKeys = (string)this.cbbKeys.SelectedItem;
                        KeyStopCondition ksc = new KeyStopCondition();
                        if (selectedItemKeys == "Any")
                        {
                            ksc.CanBeAnyInputOfThisType = true;
                        }
                        else
                        {
                            ksc.StopKey = (Keys)Enum.Parse(typeof(Keys), selectedItemKeys);
                        }

                        stop = ksc;
                    }
                    else if (this.rdbMouse.Checked)
                    {
                        string             selectedItemMouse = (string)this.cbbMouseButtons.SelectedItem;
                        MouseStopCondition msc = new MouseStopCondition();
                        msc.CanBeAnyInputOfThisType = selectedItemMouse == "Any" ? true : false;
                        if (!msc.CanBeAnyInputOfThisType)
                        {
                            msc.StopMouseButton = (MouseButtons)Enum.Parse(typeof(MouseButtons), selectedItemMouse);
                        }

                        msc.Target = string.Empty;
                        stop       = msc;
                    }
                    else if (this.rdbDuration.Checked)
                    {
                        if (extension == ".mp3" || extension == ".wav" || extension == ".wma")
                        {
                            int duration = this.GetAudioFileLength(file.FullName);
                            if (duration != 0)
                            {
                                stop = new TimeStopCondition(duration + (int)this.nudLatency.Value);
                            }
                            else
                            {
                                stop = new TimeStopCondition((int)(this.nudTime.Value * 1000));
                            }
                        }
                        else
                        {
                            stop = new TimeStopCondition((int)(this.nudTime.Value * 1000));
                        }
                    }

                    newSlide.StopConditions.Add(stop);

                    foreach (VGElement element in this.lsbStandardItems.Items)
                    {
                        newSlide.VGStimuli.Add(element);
                    }

                    string destination = Path.Combine(Document.ActiveDocument.ExperimentSettings.SlideResourcesPath, file.Name);
                    switch (extension)
                    {
                    case ".bmp":
                    case ".png":
                    case ".jpg":
                    case ".wmf":
                        if (!File.Exists(destination))
                        {
                            File.Copy(file.FullName, destination, true);
                        }

                        VGImage image = new VGImage(
                            ShapeDrawAction.None,
                            Pens.Red,
                            Brushes.Red,
                            SystemFonts.MenuFont,
                            Color.Red,
                            file.Name,
                            Document.ActiveDocument.ExperimentSettings.SlideResourcesPath,
                            ImageLayout.Stretch,
                            1f,
                            Document.ActiveDocument.PresentationSize,
                            VGStyleGroup.None,
                            file.Name,
                            string.Empty,
                            true);

                        newSlide.VGStimuli.Add(image);
                        newSlides.Add(newSlide);
                        break;

                    case ".mp3":
                    case ".wav":
                    case ".wma":
                        File.Copy(file.FullName, destination, true);
                        VGSound sound = new VGSound(ShapeDrawAction.None, Pens.Red, new Rectangle(0, 0, 200, 300));
                        sound.Center = newSlide.MouseInitialPosition;
                        sound.Size   = new SizeF(50, 50);
                        AudioFile audioFile = new AudioFile();
                        audioFile.Filename    = file.Name;
                        audioFile.Filepath    = Document.ActiveDocument.ExperimentSettings.SlideResourcesPath;
                        audioFile.Loop        = false;
                        audioFile.ShouldPlay  = true;
                        audioFile.ShowOnClick = false;
                        sound.Sound           = audioFile;
                        newSlide.VGStimuli.Add(sound);
                        newSlides.Add(newSlide);
                        break;
                    }
                }
            }

            return(newSlides);
        }
コード例 #11
0
        /// <summary>
        /// Performs the attention map calculation.
        /// </summary>
        /// <param name="weightened"><strong>True</strong>, if length of
        /// fixations should weighten the fixations, otherwise <strong>false</strong></param>
        /// <param name="worker">background worker</param>
        /// <param name="e">Background worker event arguments</param>
        private void DrawAttentionMap(bool weightened, BackgroundWorker worker, DoWorkEventArgs e)
        {
            this.Elements.Clear();

            // Read Eyetracker settings
            int eyeMonX = this.StimulusSize.Width;
            int eyeMonY = this.StimulusSize.Height;

            // init DistributionArray
            float[,] distributionArray = new float[eyeMonX, eyeMonY];

            // Calculate gaussian kernel for each entry in Fixationtable and add it to Distributionarray
            int counterRows = 0;

            foreach (DataRow row in this.tableAttentionMap.Rows)
            {
                float posX = Convert.ToSingle(row["PosX"]);
                float posY = Convert.ToSingle(row["PosY"]);
                float[,] kernelMultiplied = null;
                if (weightened)
                {
                    // 1 ms = 1 kernelMaximum
                    float factor = (int)row["Length"];
                    kernelMultiplied = AttentionMaps.MultiplyKernel(factor, AttentionMaps.KernelSize);
                }
                else
                {
                    // 1 Fixation = 1 kernelMaximum
                    kernelMultiplied = AttentionMaps.DefaultKernel;
                }

                AttentionMaps.AddKernelToArray(distributionArray, (int)posX, (int)posY, eyeMonX, eyeMonY, AttentionMaps.KernelSize, kernelMultiplied);

                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }
                else
                {
                    // Report progress as a percentage of the total task.
                    int percentComplete = Convert.ToInt32(Convert.ToSingle(counterRows) / this.tableAttentionMap.Rows.Count * 100);
                    worker.ReportProgress(percentComplete, "Calculating Subject:" + row["SubjectName"].ToString());
                }

                counterRows++;
            }

            ////this.valueForMaxColor = 20;
            AttentionMaps.RescaleArray(distributionArray, -1);

            Bitmap heatMapBitmap = AttentionMaps.CreateHeatMap(
                this.heatMap,
                this.colorMap,
                new Size(eyeMonX, eyeMonY),
                distributionArray);
            VGImage newImage = new VGImage(heatMapBitmap, ImageLayout.Center, new Size(eyeMonX, eyeMonY));

            Elements.Add(newImage);
            heatMapBitmap.Dispose();

            this.DrawForeground(true);
        }
コード例 #12
0
ファイル: Pipeline.cs プロジェクト: liwq-net/XnaVG
        internal void RenderImage(VGImage image, Rectangle source)
        {
            if (State.WriteStencilMask != VGStencilMasks.None)
            {
                Device.EffectManager.StencilSolid.Apply(State.Projection.Matrix, State.ImageToSurface.Matrix);

                _device.BlendState = Device.BlendStates.NoColor;
                _device.DepthStencilState = State.Stencils.Set;

                Vector4 extents = new Vector4(0, 0, source.Width, source.Height);
                RenderRectangle(ref extents);
            }
            else
            {
                var cxForm = State.ColorTransformationEnabled ? State.ColorTransformation.CxForm : VGCxForm.Identity;
                var effect = Device.EffectManager.Cover;

                _device.BlendState = Device.BlendStates.GetBlendState(State.BlendMode, State.ColorChannels);
                _device.DepthStencilState = DepthStencilState.None;

                effect.SetParameters(State.Projection.Matrix, State.ImageToSurface.Matrix, cxForm);
                effect.SetMask(State.MaskingEnabled ? State.Mask : null, State.MaskChannels);
                effect.SetImagePaint(image, VGMatrix.PaintToRectangle(-source.X, -source.Y, image.Texture.Width, image.Texture.Height));
                effect.Apply();

                Vector4 extents = new Vector4(0, 0, source.Width, source.Height);
                RenderRectangle(ref extents);
            }
        }