public RasterImage Depict(DicomWaveformGroup CurrentWaveformGroup) { RasterImage ri = new RasterImage(RasterMemoryFlags.Conventional, PageWidth, PageHeight, 24, RasterByteOrder.Bgr, RasterViewPerspective.BottomLeft, null, null, 0); using (Leadtools.Drawing.RasterImageGdiPlusGraphicsContainer GraphicsContainer = new Leadtools.Drawing.RasterImageGdiPlusGraphicsContainer(ri)) { _DrawWaveformBackground(GraphicsContainer.Graphics); _DrawWaveform(GraphicsContainer.Graphics, CurrentWaveformGroup, PageWidth, PageHeight, FrameWidth); } return(ri); }
/* * Loads a dataset, checks to make sure it has waveforms, and then builds the tree */ private void OpenDataset(string file) { Cursor = Cursors.WaitCursor; try { m_bLoadedWaveform = false; ds.Load(file, DicomDataSetLoadFlags.LoadAndClose); // Do we have any waveform groups at all if (ds.WaveformGroupCount == 0) { MessageBox.Show("The DICOM file you are trying to load doesn't include any waveforms."); m_bLoadedWaveform = false; return; } else { m_bLoadedWaveform = true; } // There is at least one waveform group in this DS, the first waveform group will be loaded if (m_CurrentWaveformGroup != null) { m_CurrentWaveformGroup.Reset(); } m_CurrentWaveformGroup = ds.GetWaveformGroup(0); // Update the Tree View UpdateTree(); } catch (Exception exception) { MessageBox.Show(exception.ToString()); } finally { Cursor = Cursors.Arrow; } if (treeViewElements.Nodes.Count > 0) { treeViewElements.SelectedNode = treeViewElements.Nodes[0]; } }
/* * 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); }
private void _DrawWaveform(Graphics g, DicomWaveformGroup CurrentWaveformGroup, int PageWidth, int PageHeight, int FrameWidth) { if (CurrentWaveformGroup == null) { return; } // Get number of channels int nChannelsCount = CurrentWaveformGroup.ChannelCount; if (nChannelsCount == 0) { return; } // How many samples do we have in a channel int nSamplesPerChannel = CurrentWaveformGroup.GetNumberOfSamplesPerChannel(); if (nSamplesPerChannel == 0) { return; } int[] nAllData; int nSampleIndex, nChannelIndex; int iMaxVal, iMinVal; double dExtent = 0; double dVertStep = 0; RectangleF DrawTextRect; int nViewRectHeight = PageHeight - FrameWidth; int nViewRectWidth = PageWidth; DicomCodeSequenceItem ChannelSource; iMaxVal = -32768; iMinVal = 32767; // Find the minimum and maximum value for all the channels for (nChannelIndex = 0; nChannelIndex < nChannelsCount; nChannelIndex++) { nAllData = 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 = CurrentWaveformGroup.GetChannel(nIndex).GetChannelSamples(); lStartPoint = ((nViewRectHeight + (int)((double)((nChannelIndex) * -1 * (int)dVertStep) - (nAllData[0] - iMinVal) / dExtent))) + FrameWidth / 2; // Get the channel source ChannelSource = CurrentWaveformGroup.GetChannel(nIndex).GetChannelSource(); DrawTextRect = new RectangleF(5, lStartPoint, FrameWidth - 5, (float)dVertStep); if ((ChannelSource != null) && (ChannelSource.CodeMeaning != null)) { // Display the channel source strText = ChannelSource.CodeMeaning; if (CurrentWaveformGroup.GetChannel(nIndex).GetAnnotationCount() > 0) { // Display the channel annotation ann = 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 += ")"; } } } } using (var font = new Font(FontFamily.GenericSansSerif, 8)) { g.DrawString(strText, font, Brushes.Red, DrawTextRect); } } int nDiff; double dRatio; int nOffset; // Draw the points/lines for this channel Point ptPreviousPoint, ptCurrentPoint; ptPreviousPoint = new Point(FrameWidth, (int)lStartPoint); using (var pen = new Pen(Color.FromArgb(0, 255, 0))) { for (nSampleIndex = 1; nSampleIndex < nSamplesPerChannel; nSampleIndex++) { nDiff = nAllData[nSampleIndex] - iMinVal; dRatio = (double)nDiff / dExtent; nOffset = FrameWidth / 2; ptCurrentPoint = new Point( (nSampleIndex * nViewRectWidth / nSamplesPerChannel) + FrameWidth, ((nViewRectHeight + (int)(((double)(nChannelIndex) * -1 * dVertStep) - dRatio))) + nOffset); g.DrawLine(pen, ptPreviousPoint, ptCurrentPoint); ptPreviousPoint = ptCurrentPoint; } } } }
/* * 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)); } } } } }