//This routine creates a new entries in the list of plotted points (FilePointList) based on data //at the given location (index) in the BDF/EDF file; it finds the minimum and maximum values in //the next decimateNew points and saves those values in FilePoint, placing the new Points above //or below the Points already in FilePoint internal void createMinMaxPoints(BDFEDFFileStream.BDFLoc index, bool addAbove) { double secs = index.ToSecs(); if (decimateNew == 1) //only time we generate single point { if (addAbove) this.PointList.Add(new PointListPoint(secs,bdf.getSample(_channel,index))); else this.PointList.Insert(0, new PointListPoint(secs,bdf.getSample(_channel,index))); return; } double sample; double max = double.MinValue; //max value in this decimate double min = double.MaxValue; //min value in this decimate int imax = 0; //location of max value in this decimate int imin = 0; //location of min value in this decimate BDFEDFFileStream.BDFLoc temp = index; for (int j = 0; j < decimateNew; j++) { if(temp.IsInFile) sample = bdf.getSample(_channel, temp++); // we use scaled valued (in uV) else break; if (sample > max) { max = sample; imax = j; } //if all values in the decimate are the same, we still create two separate if (sample <= min) { min = sample; imin = j; } //points: the first and last in the decimate by using the <= for } //the min! We have to have two points for each, unles decimation = 1 double st = bdf.SampTime; PointListPoint pt1 = new PointListPoint(); PointListPoint pt2 = new PointListPoint(); if (imax < imin) //if maximum to the "left" of minimum; NB: imin cannot equal imax, //because there are always at least two points in the decimate { pt1.X = secs + imax * st; pt1.rawY = max; pt2.X = secs + imin * st; pt2.rawY = min; } else { pt1.X = secs + imin * st; pt1.rawY = min; pt2.X = secs + imax * st; pt2.rawY = max; } if (addAbove) { this.PointList.Add(pt1); this.PointList.Add(pt2); } else { this.PointList.Insert(0, pt2); this.PointList.Insert(0, pt1); } }
//This routine creates a new entry in the list of plotted points (FilePointList) based on data //at the given location (index) in the BDF/EDF file; it finds the minimum and maximum values in //the next decimateNew points and saves those values in the FilePoint; it also updates the //current maximum and minimum points in the currently displayed segment, so that the plot can //be appropriately scaled internal FilePoint createFilePoint(BDFEDFFileStream.BDFLoc index) { int sample; int max = 0; //assign to fool compiler int min = 0; double maxVal; double minVal; int imax = 0; int imin = 0; BDFEDFFileStream.BDFLoc temp = index; if (MainWindow.dType == DecimationType.MinMax) { max = int.MinValue; min = int.MaxValue; for (int j = 0; j < decimateNew; j++) { if(temp.IsInFile) sample = bdf.getRawSample(_channel, temp++); else break; if (sample > max) { max = sample; imax = j; } //OK if NaN; neither > or < any number if (sample < min) { min = sample; imin = j; } } maxVal = (double)max; minVal = (double)min; } else if (MainWindow.dType == DecimationType.Average) { int ave = 0; int n = 0; for (int j = 0; j < decimateNew; j++) { if (temp.IsInFile) sample = bdf.getRawSample(_channel, temp++); else break; ave += sample; n++; } maxVal = minVal = (double)ave / n; imax = imin = n >> 1; } else //MainWindow.dType == decimationType.FirstPoint maxVal = minVal = bdf.getRawSample(_channel, temp); if (maxVal > overallMax) overallMax = maxVal; if (minVal < overallMin) overallMin = minVal; FilePoint fp = new FilePoint(); fp.fileLocation = index; double secs = index.ToSecs(); double st = bdf.SampTime; if (imax < imin) { fp.first.X = secs + imax * st; fp.first.Y = maxVal; fp.second.X = secs + imin * st; fp.second.Y = minVal; fp.SecondValid = true; } else if (imax > imin) { fp.first.X = secs + imin * st; fp.first.Y = minVal; fp.second.X = secs + imax * st; fp.second.Y = maxVal; fp.SecondValid = true; } else //imax == imin { fp.first.X = secs + imax * st; fp.first.Y = maxVal; fp.SecondValid = false; } return fp; }