Exemple #1
0
        /// <summary>
        /// Manual aedat splitter cut click event. Creates a new Aedat file witht the events contained in the range [text_ManualAedatSplitterInit, text_ManualAedatSplitterEnd]
        /// </summary>
        private void Btn_cutManualAedatSplitter_Click(object sender, RoutedEventArgs e)
        {
            if (Convert.ToInt32(text_ManualAedatSplitterInit.Text) > Convert.ToInt32(text_ManualAedatSplitterEnd.Text))
            {
                InfoWindow iw = new InfoWindow("Parameters not valid", "The end of the range can't be lesser than the init");
                iw.ShowDialog();
            }
            else if (Convert.ToInt32(text_ManualAedatSplitterInit.Text) == Convert.ToInt32(text_ManualAedatSplitterEnd.Text))
            {
                InfoWindow iw = new InfoWindow("Parameters not valid", "The current selected range is zero");
                iw.ShowDialog();
            }
            else
            {
                SaveFileDialog saveSplit = new SaveFileDialog();
                saveSplit.Title  = "Select a name and a path for the .aedat file";
                saveSplit.Filter = "aedat files|*.aedat";
                if (saveSplit.ShowDialog() == true)
                {
                    this.Cursor = Cursors.Wait;
                    if (settings.MainS.eventSize == 16)
                    {
                        aedatObject16.AERSplitterManual(Convert.ToInt32(text_ManualAedatSplitterInit.Text), Convert.ToInt32(text_ManualAedatSplitterEnd.Text), saveSplit.FileName);
                    }
                    else if (settings.MainS.eventSize == 32)
                    {
                        aedatObject32.AedatSplitterManual(Convert.ToInt32(text_ManualAedatSplitterInit.Text), Convert.ToInt32(text_ManualAedatSplitterEnd.Text), saveSplit.FileName);
                    }
                    this.Cursor = Cursors.Arrow;

                    InfoWindow iw = new InfoWindow("Split operation succeded", "The aedat file was saved correctly");
                    iw.ShowDialog();
                }
            }
        }
        private void Btn_saveCSV_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = "CSV file (.csv)|*.csv";

            sfd.Title = "Select path to save the csv file";
            sfd.ShowDialog();

            if (sfd.FileName != "")
            {
                if (MainWindow.settings.MainS.eventSize == 16)
                {
                    c16.generateSonogramCSV(sfd.FileName);
                }

                else if (MainWindow.settings.MainS.eventSize == 32)
                {
                    c32.generateSonogramCSV(sfd.FileName);
                }

                InfoWindow iw = new InfoWindow("Success!", "CSV file saved successfuly");
                iw.ShowDialog();
            }
        }
Exemple #3
0
        /// <summary>
        /// CSV click event. Generates a CSV file with the event information (address and timestamp for each event) of the loaded aedat file
        /// </summary>
        private void Btn_CSV_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog saveCSVDialog = new SaveFileDialog();

            saveCSVDialog.Title  = "Select a name and a path for the .csv file";
            saveCSVDialog.Filter = "csv files|*.csv";
            if (saveCSVDialog.ShowDialog() == true)
            {
                this.Cursor = Cursors.Wait;
                File.WriteAllText(saveCSVDialog.FileName, "Timestamp;Address\n", Encoding.UTF8);
                StringBuilder sb = new StringBuilder();

                if (settings.MainS.eventSize == 16)
                {
                    foreach (aedatEvent16 row in aedatObject16.getValues())
                    {
                        sb.Append(row.timestamp + ";" + row.addr + "\n");
                    }
                }
                else if (settings.MainS.eventSize == 32)
                {
                    foreach (aedatEvent32 row in aedatObject32.getValues())
                    {
                        sb.Append(row.timestamp + ";" + row.addr + "\n");
                    }
                }

                File.AppendAllText(saveCSVDialog.FileName, sb.ToString());
                this.Cursor = Cursors.Arrow;

                InfoWindow iw = new InfoWindow("Success!", "CSV file generated correctly");
                iw.ShowDialog();
            }
        }
Exemple #4
0
        /// <summary>
        /// Reload the cochleogram chart in the main window. Used to refresh the graph after changing settings like dots to paint or chart color.
        /// </summary>
        public void reloadCochcleogram()
        {
            if (isLoaded)
            {
                try
                {
                    if (settings.MainS.eventSize == 16)
                    {
                        aedatObject16.closeAedat();
                        aedatObject16 = new aedat16(root);
                        aedatObject16.adaptAedat();
                    }

                    if (settings.MainS.eventSize == 32)
                    {
                        aedatObject32.closeAedat();
                        aedatObject32 = new aedat32(root);
                        aedatObject32.adaptAedat();
                    }
                    initState();
                    displayCharts();
                    if (cochleaInfo == EnumCochleaInfo.MONO32 || cochleaInfo == EnumCochleaInfo.MONO64 || cochleaInfo == EnumCochleaInfo.MONO128 || cochleaInfo == EnumCochleaInfo.MONO256) // If the file corresponds to a mono sound, there's no point on enabling the "Disparity between cochleae" function.
                    {
                        Btn_difference.IsEnabled   = false;
                        Btn_difference.Opacity     = 0.6;
                        Btn_StereoToMono.IsEnabled = false;
                        Btn_StereoToMono.Opacity   = 0.6;
                        Btn_MonoToStereo.IsEnabled = true;
                        Btn_MonoToStereo.Opacity   = 1;
                    }
                    else
                    {
                        Btn_difference.IsEnabled   = true;
                        Btn_difference.Opacity     = 1;
                        Btn_StereoToMono.IsEnabled = true;
                        Btn_StereoToMono.Opacity   = 1;
                        Btn_MonoToStereo.IsEnabled = false;
                        Btn_MonoToStereo.Opacity   = 0.6;
                    }
                    InfoWindow iw = new InfoWindow("Success!", "The Aedat file was loaded correctly");
                    iw.ShowDialog();
                }
                catch (Exception e)
                {
                    this.Cursor = Cursors.Arrow;
                    InfoWindow iw = new InfoWindow("Error", "The Aedat file was not loaded correctly. This may be caused by an incorrect\nconfiguration of the number of channels and address length in NAVIS' settings.");
                    iw.ShowDialog();
                    for (int i = 2; i < buttonList.Count; i++)  //Enable tools buttons after loading the file
                    {
                        buttonList[i].IsEnabled = false;
                        buttonList[i].Opacity   = 0.6;
                    }
                    menuItem_Reload.IsEnabled = false; menuItem_Report.IsEnabled = false; menuItem_Tools.IsEnabled = false;
                    tab_fileLoaded.Visibility = Visibility.Hidden;
                }
            }
        }
        /// <summary>
        /// Save image click event. Saves an image with the information shown in the histogram chart.
        /// </summary>
        private void B_saveImage_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog saveImageDialog = new SaveFileDialog();

            saveImageDialog.Title  = "Select a name and a path for the .png file";
            saveImageDialog.Filter = "png files|*.png";
            if (saveImageDialog.ShowDialog() == true)
            {
                chart_Histogram.SaveImage(saveImageDialog.FileName, System.Drawing.Imaging.ImageFormat.Png);

                InfoWindow iw = new InfoWindow("Success!", "Image saved successfuly");
                iw.ShowDialog();
            }
        }
        /// <summary>
        /// Export click event. Creates a CSV file with the information from the histogram.
        /// </summary>
        private void B_exportCSV_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog saveCSVDialog = new SaveFileDialog();

            saveCSVDialog.Title  = "Select a name and a path for the .csv file";
            saveCSVDialog.Filter = "csv files|*.csv";
            if (saveCSVDialog.ShowDialog() == true)
            {
                File.WriteAllText(saveCSVDialog.FileName, "Address;Number of events\n", Encoding.UTF8);
                File.AppendAllText(saveCSVDialog.FileName, sb.ToString());

                InfoWindow iw = new InfoWindow("Success!", "CSV saved successfuly");
                iw.ShowDialog();
            }
        }
Exemple #7
0
        /// <summary>
        /// Generates a stereo aedat file from a mono aedat.
        /// </summary>
        private void Btn_MonoToStereo_Click(object sender, RoutedEventArgs e)
        {
            MonoToStereoConfig mtsc = new MonoToStereoConfig();

            if (mtsc.ShowDialog() == true)
            {
                if (settings.MainS.eventSize == 16)
                {
                    aedatObject16.saveMonoToStereo(mtsc.filePath, aedatObject16.getValues(), mtsc.delayValue);
                }
                else if (settings.MainS.eventSize == 32)
                {
                    aedatObject32.saveMonoToStereo(mtsc.filePath, aedatObject32.getValues(), mtsc.delayValue);
                }
                InfoWindow iw = new InfoWindow("Success", "The aedat file was saved correctly");
                iw.ShowDialog();
            }
        }
Exemple #8
0
        /// <summary>
        /// Saves an image with the disparity between cochleae chart information
        /// </summary>
        private void Btn_saveImage_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = "Png Image (.png)|*.png";

            sfd.Title = "Select path to save the image";
            sfd.ShowDialog();

            if (sfd.FileName != "")
            {
                var encoder = new PngBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create((BitmapSource)Img_Difference.Source));
                using (FileStream stream = new FileStream(sfd.FileName, FileMode.Create))
                    encoder.Save(stream);

                InfoWindow iw = new InfoWindow("Success!", "Image saved successfuly");
                iw.ShowDialog();
            }
        }
Exemple #9
0
        private void Btn_saveCSV_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog sfd         = new SaveFileDialog();
            StringBuilder  sb_csv      = new StringBuilder();
            float          mult_factor = 0.1f;

            sfd.Filter = "CSV file (.csv)|*.csv";

            sfd.Title = "Select path to save the csv file";
            sfd.ShowDialog();

            if (sfd.FileName != "")
            {
                switch (MainWindow.settings.MainS.eventSize)
                {
                case 16: mult_factor = 0.2f; break;

                case 32: mult_factor = 0.1f; break;
                }


                if (chart_Average.Series[1].Points.Count > 0)
                {
                    sb_csv.Append(chart_Average.Series[0].Name + "_X;" + chart_Average.Series[0].Name + "_Y;" + chart_Average.Series[1].Name + "_X;" + chart_Average.Series[1].Name + "_Y;\n");
                }
                else
                {
                    sb_csv.Append("Mono_X;" + "Mono_Y;\n");
                }


                if (chart_Average.Series[1].Points.Count > 0)
                {
                    for (int i = 0; i < chart_Average.Series[0].Points.Count; i++)
                    {
                        sb_csv.Append((chart_Average.Series[0].Points[i].XValue * mult_factor).ToString("0.######################") + ";" + chart_Average.Series[0].Points[i].YValues[0].ToString("0.######################") + ";" + (chart_Average.Series[1].Points[i].XValue * mult_factor).ToString("0.######################") + ";" + chart_Average.Series[1].Points[i].YValues[0].ToString("0.######################") + ";\n");
                    }
                }
                else
                {
                    for (int i = 0; i < chart_Average.Series[0].Points.Count; i++)
                    {
                        sb_csv.Append((chart_Average.Series[0].Points[i].XValue * mult_factor).ToString("0.######################") + ";" + chart_Average.Series[0].Points[i].YValues[0].ToString("0.######################") + ";\n");
                    }
                }

                File.AppendAllText(sfd.FileName, sb_csv.Replace(",", ".").ToString());
                InfoWindow iw = new InfoWindow("Success!", "CSV file saved successfuly");
                iw.ShowDialog();
            }


            /*
             * if (MainWindow.settings.MainS.eventSize == 16)
             * {
             *  c16.generateSonogramCSV(sfd.FileName);
             * }
             *
             * else if (MainWindow.settings.MainS.eventSize == 32)
             * {
             *  c32.generateSonogramCSV(sfd.FileName);
             * }
             *
             * InfoWindow iw = new InfoWindow("Success!", "CSV file saved successfuly");
             * iw.ShowDialog();
             */
        }
Exemple #10
0
        /// <summary>
        /// PDF click event. Generates a PDF with the cochleogram, histogram, sonogram, disparity between cochleae and average activity of the loaded aedat file.
        /// </summary>
        private void Btn_PDF_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog savePDFDialog = new SaveFileDialog();

            savePDFDialog.Title  = "Select a name and a path for the .pdf file";
            savePDFDialog.Filter = "pdf files|*.pdf";
            if (savePDFDialog.ShowDialog() == true)
            {
                this.Cursor = Cursors.Wait;
                Document  doc = new Document();
                PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream(savePDFDialog.FileName, FileMode.Create));
                doc.SetPageSize(iTextSharp.text.PageSize.A4);
                doc.SetMargins(50, 50, 50, 50);
                doc.Open();

                #region Fonts
                iTextSharp.text.Font fTitle = FontFactory.GetFont("Arial", 30, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                iTextSharp.text.Font fHead  = FontFactory.GetFont("Arial", 18, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                iTextSharp.text.Font fText  = FontFactory.GetFont("Arial", 11, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                #endregion

                #region Main page
                iTextSharp.text.Paragraph title = new iTextSharp.text.Paragraph("\n\n\n\n\nData Report for " + fileName, fTitle);
                title.Alignment = Element.ALIGN_CENTER;
                doc.Add(title);
                if (settings.PdfS.showDate)
                {
                    iTextSharp.text.Paragraph date = new iTextSharp.text.Paragraph("\n\n" + DateTime.Now);
                    date.Alignment = Element.ALIGN_RIGHT;
                    doc.Add(date);
                }
                #endregion
                if (settings.PdfS.showCochleogram || settings.PdfS.showHistogram)
                {
                    doc.SetMargins(0, 30, 50, 30);
                    doc.NewPage();
                }
                iTextSharp.text.Paragraph paragraph;
                #region Cochleogram
                if (settings.PdfS.showCochleogram)
                {
                    paragraph = new iTextSharp.text.Paragraph("           1. Cochleogram\n\n", fHead);
                    doc.Add(paragraph);
                    paragraph = new iTextSharp.text.Paragraph("                     The following charts represents the cochleogram for both cochleae.\n", fText);
                    doc.Add(paragraph);
                    paragraph = new iTextSharp.text.Paragraph("                         - " + settings.MainS.leftColor + " - Left Cochlea.", fText);
                    doc.Add(paragraph);
                    paragraph = new iTextSharp.text.Paragraph("                         - " + settings.MainS.rightColor + " - Right Cochlea.\n\n\n", fText);
                    doc.Add(paragraph);

                    using (MemoryStream stream = new MemoryStream())
                    {
                        chart_Cochleogram.SaveImage(stream, ImageFormat.Png);
                        iTextSharp.text.Image chartImage2 = iTextSharp.text.Image.GetInstance(stream.GetBuffer());
                        chartImage2.ScaleToFit(iTextSharp.text.PageSize.A4);// ScalePercent(75f);
                        doc.Add(chartImage2);
                    }
                }
                #endregion
                #region Histogram
                if (settings.PdfS.showHistogram)
                {
                    paragraph = new iTextSharp.text.Paragraph("\n           2. Histogram\n\n", fHead);
                    doc.Add(paragraph);
                    using (MemoryStream stream = new MemoryStream())
                    {
                        Histogram spd = new Histogram();
                        spd.chart_Histogram.Width  = 773;
                        spd.chart_Histogram.Height = 350;
                        spd.chart_Histogram.SaveImage(stream, ChartImageFormat.Png);
                        iTextSharp.text.Image chartImage3 = iTextSharp.text.Image.GetInstance(stream.GetBuffer());
                        chartImage3.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 100, iTextSharp.text.PageSize.A4.Height - 200);
                        doc.Add(chartImage3);
                    }
                }
                #endregion
                if (settings.PdfS.showSonogram || settings.PdfS.showDiff)
                {
                    doc.SetMargins(50, 30, 50, 30);
                    doc.NewPage();
                }
                #region Sonogram
                if (settings.PdfS.showSonogram)
                {
                    paragraph = new iTextSharp.text.Paragraph("           3. Sonogram\n\n", fHead);
                    doc.Add(paragraph);
                    using (MemoryStream stream = new MemoryStream())
                    {
                        if (settings.MainS.eventSize == 16)
                        {
                            aedatObject16.generateSonogram("archivobmp", aedatObject16.maxValueSonogram());
                        }
                        else if (settings.MainS.eventSize == 32)
                        {
                            aedatObject32.generateSonogram("archivobmp", aedatObject32.maxValueSonogram());
                        }
                        Sonogram sd = new Sonogram();
                        iTextSharp.text.Image image1 = iTextSharp.text.Image.GetInstance(ImageToBitmap(sd.Img_Sonogram), ImageFormat.Bmp);
                        image1.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 100, iTextSharp.text.PageSize.A4.Height - 200);
                        doc.Add(image1);
                    }
                }
                #endregion
                #region Disparity
                if (settings.PdfS.showDiff && (cochleaInfo == EnumCochleaInfo.STEREO32 || cochleaInfo == EnumCochleaInfo.STEREO64 || cochleaInfo == EnumCochleaInfo.STEREO128 || cochleaInfo == EnumCochleaInfo.STEREO256))
                {
                    paragraph = new iTextSharp.text.Paragraph("\n\n           4. Disparity between cochleae\n\n", fHead);
                    doc.Add(paragraph);
                    paragraph = new iTextSharp.text.Paragraph("                     Disparity between both cochleae.\n", fText);
                    doc.Add(paragraph);
                    paragraph = new iTextSharp.text.Paragraph("                         - Red: left cochlea predominance.", fText);
                    doc.Add(paragraph);
                    paragraph = new iTextSharp.text.Paragraph("                         - Green: right cochlea predominance.\n\n\n", fText);
                    doc.Add(paragraph);
                    using (MemoryStream stream = new MemoryStream())
                    {
                        if (settings.MainS.eventSize == 16)
                        {
                            aedatObject16.generateDisparity("archivobmpDiff", aedatObject16.maxValueSonogram());
                        }

                        else if (settings.MainS.eventSize == 32)
                        {
                            aedatObject32.generateDisparity("archivobmpDiff", aedatObject32.maxValueSonogram());
                        }
                        Difference            sd     = new Difference();
                        iTextSharp.text.Image image1 = iTextSharp.text.Image.GetInstance(ImageToBitmap(sd.Img_Difference), ImageFormat.Bmp);
                        image1.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 100, iTextSharp.text.PageSize.A4.Height - 200);
                        doc.Add(image1);
                    }
                }
                #endregion
                #region Average activity
                if (settings.PdfS.showAverage)
                {
                    doc.SetMargins(0, 30, 50, 30);
                    doc.NewPage();
                    paragraph = new iTextSharp.text.Paragraph("\n\n           5. Average activity of both cochleae\n\n", fHead);
                    doc.Add(paragraph);
                    paragraph = new iTextSharp.text.Paragraph("                     Each dot represents the average of events of a certain time period (Integration Period = " + settings.ToolsS.integrationPeriod.ToString() + " us ).\n", fText);
                    doc.Add(paragraph);
                    using (MemoryStream stream = new MemoryStream())
                    {
                        Average m = new Average();
                        m.chart_Average.Width  = 846;
                        m.chart_Average.Height = 322;
                        m.chart_Average.SaveImage(stream, ChartImageFormat.Png);
                        iTextSharp.text.Image chartImage4 = iTextSharp.text.Image.GetInstance(stream.GetBuffer());
                        chartImage4.ScaleToFit(iTextSharp.text.PageSize.A4);// ScalePercent(75f);
                        doc.Add(chartImage4);
                    }
                }
                #endregion
                doc.Close();

                InfoWindow iw = new InfoWindow("PDF generated", "The PDF file was generated succesfully and it's available at the path you chose");  // Tell the user that the process went OK
                iw.ShowDialog();

                this.Cursor = Cursors.Arrow;
            }
        }