/* * Draws the waveform(s) on the Graphics object */ private void DrawWaveform(Graphics g) { if (m_CurrentWaveformGroup == null) { return; } try { // Get number of channels int nChannelsCount = m_CurrentWaveformGroup.ChannelCount; if (nChannelsCount == 0) { return; } // How many samples do we have in a channel int nSamplesPerChannel = m_CurrentWaveformGroup.GetNumberOfSamplesPerChannel(); if (nSamplesPerChannel == 0) { return; } int[] nAllData; int nSampleIndex, nChannelIndex; int iMaxVal, iMinVal; double dExtent = 0; double dVertStep = 0; RectangleF DrawTextRect; int nViewRectHeight = m_nPageHeight - m_nFrameWidth; int nViewRectWidth = m_nPageWidth; DicomCodeSequenceItem ChannelSource; iMaxVal = -32768; iMinVal = 32767; // Find the minimum and maximum value for all the channels for (nChannelIndex = 0; nChannelIndex < nChannelsCount; nChannelIndex++) { nAllData = m_CurrentWaveformGroup.GetChannel(nChannelIndex).GetChannelSamples(); for (nSampleIndex = 0; nSampleIndex < nSamplesPerChannel; nSampleIndex++) { if (nAllData[nSampleIndex] > iMaxVal) { iMaxVal = nAllData[nSampleIndex]; } else if (nAllData[nSampleIndex] < iMinVal) { iMinVal = nAllData[nSampleIndex]; } } dVertStep = nViewRectHeight / nChannelsCount; dExtent = ((iMaxVal - iMinVal) * 1.2) / dVertStep; } int nIndex = 0; string strText; DicomWaveformAnnotation ann; long lStartPoint; // Loop through the channels one by one for (nChannelIndex = 0; nChannelIndex < nChannelsCount; nChannelIndex++) { strText = ""; nIndex = nChannelsCount - nChannelIndex - 1; //Get the data for this channel nAllData = m_CurrentWaveformGroup.GetChannel(nIndex).GetChannelSamples(); lStartPoint = ((nViewRectHeight + (int)((double)((nChannelIndex) * -1 * (int)dVertStep) - (nAllData[0] - iMinVal) / dExtent))) + m_nFrameWidth / 2; // Get the channel source ChannelSource = m_CurrentWaveformGroup.GetChannel(nIndex).GetChannelSource(); DrawTextRect = new RectangleF(5, lStartPoint, m_nFrameWidth - 5, (float)dVertStep); if ((ChannelSource != null) && (ChannelSource.CodeMeaning != null)) { // Display the channel source strText = ChannelSource.CodeMeaning; if (m_CurrentWaveformGroup.GetChannel(nIndex).GetAnnotationCount() > 0) { // Display the channel annotation ann = m_CurrentWaveformGroup.GetChannel(nIndex).GetAnnotation(0); if (ann != null) { if ((ann.UnformattedTextValue != null) && (ann.UnformattedTextValue != "")) { strText += " ("; strText += ann.UnformattedTextValue; strText += ")"; } else { if ((ann.CodedName != null) && ((ann.CodedName.CodeMeaning != null) && ann.CodedName.CodeMeaning != "")) { strText += " ("; strText += ann.CodedName.CodeMeaning; strText += ")"; } } } } g.DrawString(strText, new Font(FontFamily.GenericSansSerif, 10), Brushes.Red, DrawTextRect); } int nDiff; double dRatio; int nOffset; // Draw the points/lines for this channel Point ptPreviousPoint, ptCurrentPoint; ptPreviousPoint = new Point(m_nFrameWidth, (int)lStartPoint); for (nSampleIndex = 1; nSampleIndex < nSamplesPerChannel; nSampleIndex++) { nDiff = nAllData[nSampleIndex] - iMinVal; dRatio = (double)nDiff / dExtent; nOffset = m_nFrameWidth / 2; ptCurrentPoint = new Point( (nSampleIndex * nViewRectWidth / nSamplesPerChannel) + m_nFrameWidth, ((nViewRectHeight + (int)(((double)(nChannelIndex) * -1 * dVertStep) - dRatio))) + nOffset); g.DrawLine(new Pen(Color.FromArgb(0, 255, 0)), ptPreviousPoint, ptCurrentPoint); ptPreviousPoint = ptCurrentPoint; } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/* * Adds a waveform group for a Wav file to a Dataset */ private bool InsertWaveStream(ref DicomDataSet InDS, string strInputWaveFileName) { DicomWaveformGroup AudioWaveformGroup = new DicomWaveformGroup(); int nNumberOfChannels = 0; // Load an audio file into the waveform group try { AudioWaveformGroup.LoadAudio(strInputWaveFileName); } catch (Exception ex) { MessageBox.Show("Couldn't insert the wave stream into the dataset.\r\n\r\n" + ex.ToString()); return(false); } // Verify that hte frequency is 8K int nSamplingFrequency = (int)AudioWaveformGroup.GetSamplingFrequency(); if (nSamplingFrequency != 8000) { MessageBox.Show("The samples per second (sampling rate) for the wave file should be 8KHz."); return(false); } // Set the channel source nNumberOfChannels = AudioWaveformGroup.ChannelCount; if (nNumberOfChannels > 0) { DicomWaveformChannel channel = null; DicomCodeSequenceItem DicomSourceSequenceItem = new DicomCodeSequenceItem(); DicomSourceSequenceItem.CodeMeaning = "Dictation"; DicomSourceSequenceItem.CodeValue = "110011"; DicomSourceSequenceItem.CodingSchemeDesignator = "DCM"; DicomSourceSequenceItem.CodingSchemeVersion = "01"; for (int nIndex = 0; nIndex < nNumberOfChannels; nIndex++) { channel = AudioWaveformGroup.GetChannel(nIndex); if (channel != null) { try { channel.SetChannelSource(DicomSourceSequenceItem); } catch (Exception ex) { MessageBox.Show("Couldn't set the channel source\r\n\r\n" + ex.ToString()); return(false); } } } } // Insert the waveform group into the dataset try { InDS.AddWaveformGroup(AudioWaveformGroup, 0); } catch (Exception ex) { MessageBox.Show("Couldn't insert the wave stream into the dataset.\r\n\r\n" + ex.ToString()); return(false); } return(true); }
/* * Creates a new WaveformAttributesDialog and initializes the form elements with the information * from the DicomWaveformGroup passed */ public WaveformAttributesDialog(ref DicomWaveformGroup pWaveformGroup) { InitializeComponent(); m_pWaveformGroup = pWaveformGroup; // Add columns lvChannelAttributes.Columns.Add("Channel Sensitivity"); lvChannelAttributes.Columns.Add("Channel Sensitivity Units"); lvChannelAttributes.Columns.Add("Channel Source"); lvChannelAttributes.Columns.Add("Filter Low Freq."); lvChannelAttributes.Columns.Add("Filter High Freq."); lvChannelAttributes.Columns.Add("Waveform Annotation"); lvChannelAttributes.Columns[0].Width = 116; lvChannelAttributes.Columns[1].Width = 138; lvChannelAttributes.Columns[2].Width = 100; lvChannelAttributes.Columns[3].Width = 100; lvChannelAttributes.Columns[4].Width = 100; lvChannelAttributes.Columns[5].Width = 150; if ((m_pWaveformGroup != null) && (m_pWaveformGroup.ChannelCount > 0)) { DicomWaveformChannel channel = null; DicomCodeSequenceItem ChannelSource; DicomWaveformAnnotation annotation = null; // Populate the text boxes with the general waveform information txtNumberOfChannels.Text = string.Format("{0:g}", m_pWaveformGroup.ChannelCount); txtSamplingFrequency.Text = string.Format("{0:g}", m_pWaveformGroup.GetSamplingFrequency()); txtNumberOfWaveformSamples.Text = string.Format("{0:g}", m_pWaveformGroup.GetNumberOfSamplesPerChannel()); switch (m_pWaveformGroup.GetSampleInterpretation()) { case DicomWaveformSampleInterpretationType.Signed16BitLinear: txtSampleInterpretation.Text = "signed 16 bit linear"; break; case DicomWaveformSampleInterpretationType.Unsigned16BitLinear: txtSampleInterpretation.Text = "unsigned 16 bit linear"; break; case DicomWaveformSampleInterpretationType.Signed8BitLinear: txtSampleInterpretation.Text = "signed 8 bit linear"; break; case DicomWaveformSampleInterpretationType.Unsigned8BitLinear: txtSampleInterpretation.Text = "unsigned 8 bit linear"; break; case DicomWaveformSampleInterpretationType.Mulaw8Bit: txtSampleInterpretation.Text = "8 bit mu-law"; break; case DicomWaveformSampleInterpretationType.Alaw8Bit: txtSampleInterpretation.Text = "8 bit A-law"; break; } switch (m_pWaveformGroup.GetSampleInterpretation()) { case DicomWaveformSampleInterpretationType.Signed16BitLinear: case DicomWaveformSampleInterpretationType.Unsigned16BitLinear: txtWaveformBitsAllocated.Text = "16"; break; case DicomWaveformSampleInterpretationType.Signed8BitLinear: case DicomWaveformSampleInterpretationType.Unsigned8BitLinear: case DicomWaveformSampleInterpretationType.Mulaw8Bit: case DicomWaveformSampleInterpretationType.Alaw8Bit: txtWaveformBitsAllocated.Text = "8"; break; } txtWaveformPaddingValue.Text = string.Format("{0:g}", m_pWaveformGroup.GetWaveformPaddingValue()); // Populate the list view with the specific information for each channel string[] strItemText; for (int nIndex = 0; nIndex < m_pWaveformGroup.ChannelCount; nIndex++) { channel = m_pWaveformGroup.GetChannel(nIndex); if (channel != null) { DicomChannelSensitivity channelSensitivity = channel.GetChannelSensitivity(); if ((channelSensitivity != null) && ((channelSensitivity.SensitivityUnits.CodeMeaning != null) && (channelSensitivity.SensitivityUnits.CodeMeaning != ""))) { ChannelSource = channel.GetChannelSource(); strItemText = new string[6] { string.Format("{0:g}", channelSensitivity.Sensitivity), channelSensitivity.SensitivityUnits.CodeMeaning, ChannelSource.CodeMeaning, string.Format("{0:g}", channel.GetFilterLowFrequency()), string.Format("{0:g}", channel.GetFilterHighFrequency()), "" }; if (channel.GetAnnotationCount() > 0) { annotation = channel.GetAnnotation(0); if (annotation != null) { if ((annotation.UnformattedTextValue != null) && (annotation.UnformattedTextValue != "")) { strItemText[5] = annotation.UnformattedTextValue; } else { if ((annotation.CodedName != null) && ((annotation.CodedName.CodeMeaning != null) && (annotation.CodedName != null))) { strItemText[5] = annotation.CodedName.CodeMeaning; } } } } lvChannelAttributes.Items.Add(new ListViewItem(strItemText)); } } } } }