public void Dispose() { if (IsDisposed) { return; } if (_analysisThread != null) { _analysisThread.Dispose(); _analysisThread = null; } if (_smoother != null) { _smoother.Dispose(); _smoother = null; } if (_mova != null) { _mova.Dispose(); _mova = null; } if (_isb != null) { _isb.Dispose(); _isb = null; } IsDisposed = true; }
/// <summary> /// Extracts the bouts from an instant speed trace /// </summary> /// <param name="isb">The instant speed trace</param> /// <param name="speedThreshold">Speeds below this threshold will be set to 0</param> /// <param name="minFramesPerBout">For a movement to be called a bout we require at least this number of frames</param> /// <param name="maxFramesAtPeak">Bouts should have clearly defined peaks. Bouts with a peak longer than this number get rejected</param> /// <param name="frameRate">The framerate used for acquisition</param> /// <returns>A queue of bout structures describing every bout</returns> public Queue <Bout> DetectBouts(InstantSpeedBuffer isb, float speedThreshold, int minFramesPerBout, int maxFramesAtPeak, int frameRate) { if (IsDisposed) { throw new ObjectDisposedException(this.ToString()); } if (_isCalc == null) { _isCalc = new InstantSpeedBuffer(isb.Size.width); } else if (_isCalc.Size.width != isb.Size.width) { _isCalc.Dispose(); _isCalc = new InstantSpeedBuffer(isb.Size.width); } Queue <Bout> retval = new Queue <Bout>(); int i = 0; //threshold the speed trace - copy result into our calculation buffer ip.ippiThreshold_LTVal_32f_C1R(isb.Buffer, isb.Stride, _isCalc.Buffer, _isCalc.Stride, isb.Size, speedThreshold, 0); while (i < _isCalc.Size.width) { if (_isCalc[i] == 0) { i++; continue; } else//found potential bout start since speed above threshold { int peaklength = 0; Bout b = new Bout(); b.BoutStart = i; b.PeakSpeed = _isCalc[i]; b.BoutPeak = i; b.TotalDisplacement = _isCalc[i] / frameRate; //loop over following frames collecting all frames that belong to the bout while (i < _isCalc.Size.width && _isCalc[i] > 0) { if (_isCalc[i] > b.PeakSpeed) { b.PeakSpeed = _isCalc[i]; b.BoutPeak = i; peaklength = 0; //new peakspeed found, reset peaklength } else if (_isCalc[i] == b.PeakSpeed) //another frame with the same speed as our peak { peaklength++; } b.TotalDisplacement += _isCalc[i] / frameRate; i++; } b.BoutEnd = i - 1; //check our bout criteria if ((b.BoutEnd - b.BoutStart + 1) >= minFramesPerBout && peaklength <= maxFramesAtPeak) { //we have a valid bout if (b.BoutStart == b.BoutPeak) { b.BoutStart--; } retval.Enqueue(b); } }//found potential bout } return(retval); }