//__________________________________________________________________ #region BScan Part //private void initColorBar() //{ // int st = 4 * ((panelColorBar.Width * 24 + 31) / 32); // int index; // byte r = 0; // byte g = 0; // byte b = 0; // byte[] dataForColor = new byte[3*panelColorBar.Height * panelColorBar.Height]; // Bitmap imageForColor = new Bitmap(panelColorBar.Width, panelColorBar.Height); // for (int i = 0; i < panelColorBar.Height; i++) // { // if (RGBImage.getRGB(((double)i) / panelColorBar.Height, ref r, ref g, ref b)) // { // for (int j = 0; j < panelColorBar.Width; j++) // { // index = 3 * (i * panelColorBar.Width + j); // dataForColor[index] = b; // dataForColor[index + 1] = g; // dataForColor[index + 2] = r; // } // } // } // panelColorBar.BackgroundImage = RGBImage.CreateBitmap(dataForColor, imageForColor); //} public void AddData(AscanVideo ascan) { if (width == 0 || height == 0 || stride == 0) { int top = 0; int left = 0; int yMin = tChartBscan.Axes.Left.CalcPosValue(0); int yMax = tChartBscan.Axes.Left.CalcPosValue(100); int xMin = tChartBscan.Axes.Bottom.CalcPosValue(0); int xMax = tChartBscan.Axes.Bottom.CalcPosValue(totalcolumn); if (xMin < xMax) { left = xMin; } else { left = xMax; } if (yMin < yMax) { top = yMin; } else { top = yMax; } pictureBox.Location = new Point(left + 1, top + 1); width = Math.Abs(xMin - xMax) - 2; height = Math.Abs(yMax - yMin) - 2; stride = 4 * ((width * 24 + 31) / 32); currentcolumn = 0; totalcolumn = (int)width / thick; tChartBscan.Axes.Bottom.SetMinMax(0, totalcolumn); dateArray = new byte[stride * height]; for (int k = 0; k < dateArray.Length; k++) { dateArray[k] = byte.MaxValue; } pictureBox.Width = width; pictureBox.Height = height; bitmap = new Bitmap(width, height); changed = true; } float[] bigYValue = new float[ConstParameter.MaxAscanWaveLen]; float[] smallYValue = new float[ConstParameter.MaxAscanWaveLen / 2]; uint len = ascan.len; float[] yValue; float[] amp = new float[512]; //1024 if (len == ConstParameter.MaxAscanWaveLen) { yValue = bigYValue; Array.Copy(ascan.wave, yValue, len); for (int i = 0; i < 512; i++) { amp[i] = yValue[2 * i + 1]; } } //512 else { yValue = smallYValue; Array.Copy(ascan.wave, yValue, len); amp = yValue; } byte r = 0, g = 0, b = 0; int index = -1; //未满时填满 if (currentcolumn < totalcolumn) { for (int i = 0; i < height; i++) { index = (int)i * 512 / height; double data = Math.Abs(amp[index]); if (RGBImage.getRGB((double)data, ref r, ref g, ref b)) { for (int j = 0; j < thick; j++) { int a = i * stride + 3 * currentcolumn * thick + j * 3; dateArray[a] = b; dateArray[a + 1] = g; dateArray[a + 2] = r; } } } currentcolumn++; } //满后推动的感觉 else { currentcolumn--; // for (int i = 0; i < height; i++) { for (int j = 0; j < totalcolumn - 1; j++) { int a = i * stride + 9 * j; dateArray[a] = dateArray[a + 9]; dateArray[a + 1] = dateArray[a + 1 + 9]; dateArray[a + 2] = dateArray[a + 2 + 9]; dateArray[a + 3] = dateArray[a + 3 + 9]; dateArray[a + 4] = dateArray[a + 4 + 9]; dateArray[a + 5] = dateArray[a + 5 + 9]; dateArray[a + 6] = dateArray[a + 6 + 9]; dateArray[a + 7] = dateArray[a + 7 + 9]; dateArray[a + 8] = dateArray[a + 8 + 9]; } } for (int i = 0; i < height; i++) { index = (int)i * 512 / height; double data = Math.Abs(amp[index]); if (RGBImage.getRGB((double)data, ref r, ref g, ref b)) { for (int j = 0; j < thick; j++) { int a = i * stride + 3 * currentcolumn * thick + j * 3; dateArray[a] = b; dateArray[a + 1] = g; dateArray[a + 2] = r; } } } currentcolumn++; } }
public void AddData(AscanVideo ascan) { float[] bigXValue = new float[ConstParameter.MaxAscanWaveLen]; float[] bigYValue = new float[ConstParameter.MaxAscanWaveLen]; float[] smallXValue = new float[ConstParameter.MaxAscanWaveLen / 2]; float[] smallYValue = new float[ConstParameter.MaxAscanWaveLen / 2]; uint len = ascan.len; double xStep = ascan.width / (len - 1);//Divide width into (len - 1) part. float[] xValue, yValue; float[] amp = new float[512]; //1024 if (len == ConstParameter.MaxAscanWaveLen) { xValue = bigXValue; for (int i = 0; i < len; i++) { xValue[i] = (float)(ascan.delay + xStep * i); } yValue = bigYValue; Array.Copy(ascan.wave, yValue, len); for (int i = 0; i < 512; i++) { amp[i] = yValue[2 * i + 1]; } } //512 else { xValue = smallXValue; for (int i = 0; i < len; i++) { xValue[i] = (float)(ascan.delay + xStep * i); } yValue = smallYValue; Array.Copy(ascan.wave, yValue, len); amp = yValue; } byte r = 0, g = 0, b = 0; int index = -1; if (curentrow < totalrow) { for (int i = 0; i < width; i++) { index = i * 512 / width; double data = Math.Abs(amp[index]); if (RGBImage.getRGB((double)data, ref r, ref g, ref b)) { for (int j = 0; j < 3; j++) { int a = (curentrow * 3 + j) * stride + 3 * i; dateArray[a] = b; dateArray[a + 1] = g; dateArray[a + 2] = r; } } } curentrow++; } else { curentrow = 0; dateArray = new byte[stride * height]; for (int k = 0; k < dateArray.Length; k++) { dateArray[k] = byte.MaxValue; } } }