예제 #1
0
        public int setSignals(Signals signals)
        {
            if ((signals != null) &&
                (signals.NrLeads > 0))
            {
                // Decide wich encoding to use.
                switch (_EncodingType)
                {
                case EncodingType.None:
                    ((SCPSection2)_Default[2]).UseNoHuffman();
                    break;

                case EncodingType.OptimizedHuffman:
                    // not implemented!
                    ((SCPSection2)_Default[2]).UseStandard();
                    break;

                case EncodingType.DefaultHuffman:
                default:
                    ((SCPSection2)_Default[2]).UseStandard();
                    break;
                }

                if (((ISignal)_Default[3]).setSignals(signals) != 0)
                {
                    return(2);
                }

                SCPSection5 median = (SCPSection5)_Default[5];
                median.setAVM(signals.MedianAVM);
                median.setSamplesPerSecond(signals.MedianSamplesPerSecond);

                SCPSection6 rhythm = (SCPSection6)_Default[6];
                rhythm.setAVM(signals.RhythmAVM);
                rhythm.setSamplesPerSecond(signals.RhythmSamplesPerSecond);

                short[][] rhythmData = new short[signals.NrLeads][];
                short[][] medianData = new short[signals.NrLeads][];
                for (int loper = 0; loper < signals.NrLeads; loper++)
                {
                    if (signals[loper].Rhythm == null)
                    {
                        return(4);
                    }
                    rhythmData[loper] = signals[loper].Rhythm;
                    if ((medianData == null) ||
                        (signals[loper].Median == null))
                    {
                        medianData = null;
                    }
                    else
                    {
                        medianData[loper] = signals[loper].Median;
                    }
                }

                if (medianData != null)
                {
                    if (((ISignal)_Default[4]).setSignals(signals) != 0)
                    {
                        return(8);
                    }

                    if (signals.MedianSamplesPerSecond < signals.RhythmSamplesPerSecond)
                    {
                        median.setSamplesPerSecond(signals.RhythmSamplesPerSecond);
                        ECGTool.ResampleSignal(medianData, signals.MedianSamplesPerSecond, signals.RhythmSamplesPerSecond, out medianData);
                    }

                    if (median.EncodeData(medianData, (SCPSection2)_Default[2], (ushort)((signals.MedianLength * signals.MedianSamplesPerSecond) / 1000), (_EncodingType == EncodingType.None ? (byte)0 : _DifferenceDataSection5Used)) != 0)
                    {
                        return(16);
                    }

                    if (signals.QRSZone != null)
                    {
                        if (signals.RhythmAVM <= signals.MedianAVM)
                        {
                            ECGTool.ChangeMultiplier(medianData, signals.MedianAVM, signals.RhythmAVM);
                        }
                        else
                        {
                            ECGTool.ChangeMultiplier(rhythmData, signals.RhythmAVM, signals.MedianAVM);
                            rhythm.setAVM(signals.MedianAVM);
                        }
                    }

                    ECGTool.ResampleSignal(rhythmData, signals.RhythmSamplesPerSecond, median.getSamplesPerSecond(), out rhythmData);

                    if (_QRSSubtractionSupport &&
                        (signals.QRSZone != null))
                    {
                        ((SCPSection3)_Default[3]).setMediansUsed(true);
                        ((SCPSection4)_Default[4]).SubtractMedians((SCPSection3)_Default[3], rhythmData, medianData);
                    }
                }

                if (_BimodalCompressionUsed &&
                    (_BimodalCompressionRate > 0) &&
                    (medianData != null) &&
                    (signals.QRSZone != null))
                {
                    // Bimodal Compression must be set in set section 6.
                    rhythm.setBimodal(true);
                    rhythm.setSamplesPerSecond(signals.MedianSamplesPerSecond / _BimodalCompressionRate);

                    // Determine QRS zones for bimodal compression
                    GlobalMeasurements global;
                    ((IGlobalMeasurement)_Default[7]).getGlobalMeasurements(out global);
                    ((SCPSection4)_Default[4]).setProtected(global, median.getSamplesPerSecond(), _BimodalCompressionRate, ((SCPSection3)_Default[3]).getMinBegin(), ((SCPSection3)_Default[3]).getMaxEnd());
                }

                if (rhythm.EncodeData(rhythmData, (SCPSection2)_Default[2], (SCPSection3)_Default[3], (SCPSection4)_Default[4], signals.MedianSamplesPerSecond, (_EncodingType == EncodingType.None ? (byte)0 : _DifferenceDataSection6Used)) != 0)
                {
                    return(32);
                }
                return(0);
            }
            return(1);
        }
예제 #2
0
        public int getSignalsToObj(Signals signals)
        {
            if (signals != null)
            {
                if (((ISignal)_Default[3]).getSignalsToObj(signals) != 0)
                {
                    return(2);
                }

                short[][] medianData = null;
                if (((ISignal)_Default[4]).getSignalsToObj(signals) == 0)
                {
                    SCPSection5 median = (SCPSection5)_Default[5];

                    if (median == null)
                    {
                        return(4);
                    }

                    medianData = median.DecodeData((SCPSection2)_Default[2], signals.MedianLength);

                    signals.MedianAVM = median.getAVM();
                    signals.MedianSamplesPerSecond = median.getSamplesPerSecond();

                    for (int loper = 0; loper < signals.NrLeads; loper++)
                    {
                        signals[loper].Median = medianData[loper];
                    }
                }
                else
                {
                    // this will make sure that Decoding of rhythm data will work also for strange files
                    signals.MedianAVM              = 0;
                    signals.MedianLength           = 0;
                    signals.MedianSamplesPerSecond = 0;
                }

                SCPSection6 rhythm     = (SCPSection6)_Default[6];
                short[][]   rhythmData = rhythm.DecodeData((SCPSection2)_Default[2], (SCPSection3)_Default[3], (SCPSection4)_Default[4], signals.MedianSamplesPerSecond);
                signals.RhythmAVM = rhythm.getAVM();

                if (rhythmData == null)
                {
                    return(8);
                }

                if ((medianData != null) &&
                    (((SCPSection3)_Default[3]).isMediansUsed()))
                {
                    // check this because corpuls ECG are in violation of this rule, but don't use median subtraction
                    if (((signals.MedianSamplesPerSecond % signals.RhythmSamplesPerSecond) != 0) ||
                        ((signals.MedianSamplesPerSecond / signals.RhythmSamplesPerSecond) < 1) ||
                        ((signals.MedianSamplesPerSecond / signals.RhythmSamplesPerSecond) > 4))
                    {
                        return(16);
                    }

                    if (signals.RhythmAVM <= signals.MedianAVM)
                    {
                        ECGTool.ChangeMultiplier(medianData, signals.MedianAVM, signals.RhythmAVM);
                        signals.MedianAVM = signals.RhythmAVM;
                    }
                    else
                    {
                        ECGTool.ChangeMultiplier(rhythmData, signals.RhythmAVM, signals.MedianAVM);
                        signals.RhythmAVM = signals.MedianAVM;
                    }

                    signals.RhythmSamplesPerSecond = signals.MedianSamplesPerSecond;

                    ((SCPSection4)_Default[4]).AddMedians((SCPSection3)_Default[3], rhythmData, medianData);
                }
                else
                {
                    signals.RhythmAVM = rhythm.getAVM();
                    signals.RhythmSamplesPerSecond = rhythm.getSamplesPerSecond();

                    // Begin: special correction for SCP-ECG by corpuls (part 2)
                    if ((_Default[5] != null) &&
                        _Default[5].Works())
                    {
                        SCPSection5 medianSpecial = (SCPSection5)_Default[5];

                        signals.MedianLength           = 1000;
                        signals.MedianAVM              = medianSpecial.getAVM();
                        signals.MedianSamplesPerSecond = medianSpecial.getSamplesPerSecond();

                        medianData = medianSpecial.DecodeData((SCPSection2)_Default[2], signals.MedianLength);

                        if (medianData != null)
                        {
                            for (int loper = 0; loper < signals.NrLeads; loper++)
                            {
                                signals[loper].Median = medianData[loper];
                            }
                        }
                        else
                        {
                            signals.MedianLength           = 0;
                            signals.MedianAVM              = 0;
                            signals.MedianSamplesPerSecond = 0;
                        }
                    }
                    // End: special correction for SCP-ECG by corpuls (part 2)
                }

                for (int loper = 0; loper < signals.NrLeads; loper++)
                {
                    signals[loper].Rhythm = rhythmData[loper];
                }

                return(0);
            }
            return(1);
        }