private static WaveData Read1Channel(Stream stream, int sampleNumber, int width, Func <BinaryReader, short> reader) { var result = new PixelInfo[width]; var samplesPerPixel = (double)sampleNumber / (double)width; using (var br = new BinaryReader(stream)) { var drawedSample = 0; for (int i = 0; i < width; i++) { var drawSample = 0; if (i == width - 1) { drawSample = sampleNumber - drawedSample; } else { drawSample = (int)((i + 1) * samplesPerPixel - drawedSample); } var pixInfo = new PixelInfo(); for (int j = 0; j < drawSample; j++) { try { pixInfo.Push(reader(br)); } catch { drawedSample += j; } } drawedSample += drawSample; result[i] = pixInfo; } return(new WaveData(result)); } }
/// <summary>( /// Erstellt das fertige Bild /// </summary> public override void Paint(Graphics grLabel) { _width = pData.Width; _height = pData.Height; PreCalculate(); for (int i = 0; i < _width; i++) { for (int j = 0; j < _height; j++) { Pen p = new Pen(Color.Transparent); grLabel.DrawRectangle(p, i, j, (float)0.5, (float)0.5); } } // ?? Eigentlich sollte width==grLabel.VisibleClipBounds.Width gelten. for (int i = 0; i < _width && i < grLabel.VisibleClipBounds.Width; i++) { for (int j = 0; j < grLabel.VisibleClipBounds.Height && j < _height; j++) { Pen p = new Pen(Color.Black); // Switch to front draw PixelInfo pInfo = pData.Points[i, j]; if (pInfo != null) { double y = pInfo.Coord.Y; if (y != 0) { double dheight = _height; double ypos = y - _expectedMinY; ypos = ypos / (_expectedMaxY - _expectedMinY); ypos = dheight - dheight * ypos; grLabel.DrawRectangle(p, i, (int)ypos, (float)0.5, (float)0.5); } } } } }
public void ScanImage() { var path = Server.MapPath("~/all_you_need_is_love_schulz.jpg"); FileStream originalFile = System.IO.File.Open(path, FileMode.Open); Image fileImage = System.Drawing.Image.FromStream(originalFile); List <PixelInfo> colors = new List <PixelInfo>(); List <Color> systemColors = GetAllColors(); using (Bitmap bmp = new Bitmap(fileImage)) { for (int y = 0; y < bmp.Height; y++) { if (y % 2 == 0) { for (int x = 0; x < bmp.Width; x++) { if (x % 2 == 0) { var pixel = bmp.GetPixel(x, y); PixelInfo pixi = new PixelInfo(); pixi.x = x; pixi.y = y; pixi.name = GetFromARGB(systemColors, pixel).Name; pixi.color = pixel; colors.Add(pixi); } } } } } }
private unsafe void PrintPixelInfo(PixelInfo pixelInfo) { _sb.Clear(); // ICanvasViewer v = _session.SmartWindowManager.ActiveViewer as ICanvasViewer; if (v == null) { return; } IRasterDrawing drawing = v.ActiveObject as IRasterDrawing; int bandCount = drawing.BandCount; if (txtOriginChannels.Checked || txtSelectChannels.Checked) { fixed(double *ptr = bandValues) { //Stopwatch sw1 = new Stopwatch(); //sw1.Start(); drawing.ReadPixelValues(pixelInfo.RasterX, pixelInfo.RasterY, ptr); //sw1.Stop(); //Console.WriteLine("read data:" +sw1.ElapsedMilliseconds.ToString()); } } int[] selectedBandNos = drawing.SelectedBandNos; // _sb.AppendLine("-------------------------------"); // if (txtSecondaryInfo.Checked) { _sb.AppendLine("辅助信息"); if (drawing.DataProviderCopy.CoordType != enumCoordType.Raster) { if (_landTypeDictionary != null) { _sb.AppendLine(string.Format(ITEM_EXTAND_INFO, "土地利用类型", _landTypeDictionary.GetPixelName(pixelInfo.GeoX, pixelInfo.GeoY))); } if (_xianJieDictionary != null) { _sb.AppendLine(string.Format(ITEM_EXTAND_INFO, "行政区划", _xianJieDictionary.GetPixelName(pixelInfo.GeoX, pixelInfo.GeoY))); } } } // if (txtCoordInfo.Checked) { _sb.AppendLine("坐标信息"); _sb.AppendLine(string.Format(ITEM_SCREEN_COORD, pixelInfo.ScreenX, pixelInfo.ScreenY)); _sb.AppendLine(string.Format(ITEM_RASTER_COORD, pixelInfo.RasterX, pixelInfo.RasterY)); _sb.AppendLine(string.Format(ITEM_PRJ_COORD, pixelInfo.PrjX.ToString("0.##"), pixelInfo.PrjY.ToString("0.##"))); if (rd10DecimalDegree.Checked) { _sb.AppendLine(string.Format(ITEM_GEO_COORD, pixelInfo.GeoX.ToString("0.####"), pixelInfo.GeoY.ToString("0.####"))); } else { _sb.AppendLine(string.Format(ITEM_GEO_COORD, DegreeToString(pixelInfo.GeoX), DegreeToString(pixelInfo.GeoY))); } } // if (txtSelectChannels.Checked) { Color rgb = drawing.GetColorAt(pixelInfo.ScreenX, pixelInfo.ScreenY); _sb.AppendLine("显示通道"); if (drawing.SelectedBandNos.Length == 1) { _sb.AppendLine(string.Format(ITEM_RGB_BANDS1, selectedBandNos[0])); _sb.AppendLine(string.Format(ITEM_RGB_VALUES1, rgb.R)); _sb.AppendLine(string.Format(ITEM_DATA_VALUES1, bandValues[selectedBandNos[0] - 1])); } else { _sb.AppendLine(string.Format(ITEM_RGB_BANDS3, selectedBandNos[0], selectedBandNos[1], selectedBandNos[2])); _sb.AppendLine(string.Format(ITEM_RGB_VALUES3, rgb.R, rgb.G, rgb.B)); _sb.AppendLine(string.Format(ITEM_DATA_VALUES3, bandValues[selectedBandNos[0] - 1], bandValues[selectedBandNos[1] - 1], bandValues[selectedBandNos[2] - 1])); } } // if (txtOriginChannels.Checked) { _sb.AppendLine("原始通道值"); for (int i = 1; i <= bandCount; i++) { string bandDesc = drawing.DataProviderCopy.GetRasterBand(i).Description; if (string.IsNullOrEmpty(bandDesc)) { _sb.AppendLine(string.Format(ITEM_BAND_VALUE, i, bandValues[i - 1])); } else { _sb.AppendLine(string.Format(ITEM_BAND_VALUE_WITHNAME, i, bandValues[i - 1], bandDesc)); } } } //判识面积 string extractingArea = TryGetExtractingArea(); string tempStr = _sb.ToString() + extractingArea + TryGetExtInfoFromInfoProvider(pixelInfo); //面板显示参数 string argInfos = TryGetExtractingArgInfos(); txtInfo.Text = tempStr + argInfos; }
public void SetPixel(PixelInfo pixelInfo) { ColorHLS oldColor; SetPixel(pixelInfo.X, pixelInfo.Y, pixelInfo.Color, out oldColor); }
public static void GetRGBPixelInfo(int row, int col, int rgb1, int rgb2, int rgb3, int rgb4) { RPixel = new List <PixelInfo>(); GPixel = new List <PixelInfo>(); BPixel = new List <PixelInfo>(); for (int i = 0; i < row; i += 2) { for (int j = 0; j < col; j += 2) { PixelInfo p = new PixelInfo(); p.row = i; p.col = j; switch (rgb1) { case 0: RPixel.Add(p); break; case 1: GPixel.Add(p); break; case 2: BPixel.Add(p); break; } p.row = i; p.col = j + 1; switch (rgb2) { case 0: RPixel.Add(p); break; case 1: GPixel.Add(p); break; case 2: BPixel.Add(p); break; } p.row = i + 1; p.col = j; switch (rgb3) { case 0: RPixel.Add(p); break; case 1: GPixel.Add(p); break; case 2: BPixel.Add(p); break; } p.row = i + 1; p.col = j + 1; switch (rgb4) { case 0: RPixel.Add(p); break; case 1: GPixel.Add(p); break; case 2: BPixel.Add(p); break; } } } }
/// <summary> /// Draw one channel. /// For single channel wave, it draws the channel and wave grid. /// For two channel wave,use this method to draw one channel of two. /// </summary> /// <param name="info">chached sample info</param> /// <param name="style">style of the wave</param> /// <param name="startPer">the percent of start position</param> /// <param name="scale">scale</param> /// <param name="width">width of the return bitmap</param> /// <param name="height">height of the return bitmap</param> /// <returns>bitmap that the wave drawed on</returns> public static ImageSource Draw1Channel(PixelInfo[] info, WaveStyle style, double startPer, double scale, double width, double height = -1) { if (width <= 0) { return(null); } if (info.Length < width) { return(null); } if (height == -1) { height = WavFile.MinHeight; } var startPos = (int)(info.Length * startPer); var sampleNumber = (int)(info.Length * scale); if (startPos + sampleNumber > info.Length) { startPos = info.Length - sampleNumber; } var samplesPerPixel = (double)sampleNumber / width; DrawingVisual dv = new DrawingVisual(); var dc = dv.RenderOpen(); var pen = new Pen(style.WaveBrush, 1); var gridPen = new Pen(style.GridBrush, 0.2); gridPen.Freeze(); pen.Freeze(); //draw wave grid var hNumber = GetGridNumber(height / 2, 50); var k = height / (2 * hNumber); for (int i = 1; i < hNumber; i++) { dc.DrawLine(gridPen, new Point(0, i * k), new Point(width, i * k)); dc.DrawLine(gridPen, new Point(0, height / 2 + i * k), new Point(width, height / 2 + i * k)); } var vNumber = GetGridNumber(width, 100); var vGridSpace = width / vNumber; for (int i = 1; i < vNumber; i++) { dc.DrawLine(gridPen, new Point(i * vGridSpace, 0), new Point(i * vGridSpace, height)); } //draw wave var drawedSample = 0; PixelInfo prePixel = null; for (int i = 0; i < width; i++) { var drawSample = 0; if (i == width - 1) { drawSample = sampleNumber - drawedSample; } else { drawSample = (int)((i + 1) * samplesPerPixel - drawedSample); } var tempInfo = new PixelInfo(); for (int j = 0; j < drawSample; j++) { tempInfo.Push(info[startPos + drawedSample + j]); } var min = tempInfo.Min; var max = tempInfo.Max; if (height != WavFile.MinHeight) { min = (short)ScaleToHeight(min, height); max = (short)ScaleToHeight(max, height); } dc.DrawLine(pen, new Point(i, min), new Point(i, max)); if (prePixel == null) { prePixel = new PixelInfo { Min = min, Max = max, }; } else { if (prePixel.Max < min) { dc.DrawLine(pen, new Point(i - 1, prePixel.Max), new Point(i, min)); } if (prePixel.Min > max) { dc.DrawLine(pen, new Point(i - 1, prePixel.Min), new Point(i, max)); } prePixel.Max = max; prePixel.Min = min; } drawedSample += drawSample; } dc.Close(); var bmp = new RenderTargetBitmap((int)width, (int)height, 0, 0, PixelFormats.Default); bmp.Render(dv); return(bmp); }
void RGB_第二步数据处理(object LockWatingThread) { int count = SystemParam.L * 4; ushort[] yR; ushort[] yG; ushort[] yB; byte[] p = SystemParam.ReadTempFile(SystemParam.ByteLen4Pic, 0, Calc2.LightTempFile); wfSapGUI.TransPicDatas(p, m_Buffers.Height, m_Buffers.Width, m_Buffers.PixelDepth, SystemParam.cmosInfo.RGB1, SystemParam.cmosInfo.RGB2, SystemParam.cmosInfo.RGB3, SystemParam.cmosInfo.RGB4, out yR, out yG, out yB); Calc2.R_y50 = new double[yR.Length]; Calc2.G_y50 = new double[yG.Length]; Calc2.B_y50 = new double[yB.Length]; Calc2.R_y50_dark = new double[yR.Length]; Calc2.G_y50_dark = new double[yG.Length]; Calc2.B_y50_dark = new double[yB.Length]; Calc2.R_delta_y50 = new double[yR.Length]; Calc2.G_delta_y50 = new double[yG.Length]; Calc2.B_delta_y50 = new double[yB.Length]; Calc2.R_delta_y50_dark = new double[yR.Length]; Calc2.G_delta_y50_dark = new double[yG.Length]; Calc2.B_delta_y50_dark = new double[yB.Length]; /************************************************************************/ /* y50 */ /************************************************************************/ waitProc.SetTitle("相同曝光条件下数据处理---计算明场像素点均值"); for (int i = 0; i < SystemParam.L; i++) { p = SystemParam.ReadTempFile(SystemParam.ByteLen4Pic, i, Calc2.LightTempFile); wfSapGUI.TransPicDatas(p, m_Buffers.Height, m_Buffers.Width, m_Buffers.PixelDepth, SystemParam.cmosInfo.RGB1, SystemParam.cmosInfo.RGB2, SystemParam.cmosInfo.RGB3, SystemParam.cmosInfo.RGB4, out yR, out yG, out yB); for (int j = 0; j < yR.Length; j++) { Calc2.R_y50[j] += yR[j]; } for (int j = 0; j < yG.Length; j++) { Calc2.G_y50[j] += yG[j]; } for (int j = 0; j < yB.Length; j++) { Calc2.B_y50[j] += yB[j]; } if (waitProc.HasBeenCancelled()) { return; } waitProc.SetProcessBar((int)((i + 1))); this.Invoke((EventHandler)(delegate { listView1.Items[14].SubItems[1].Text = (((double)(i + 1)) * 100 / count).ToString("F1") + "%"; })); } for (int j = 0; j < Calc2.R_y50.Length; j++) { Calc2.R_y50[j] = Calc2.R_y50[j] / SystemParam.L; } for (int j = 0; j < Calc2.G_y50.Length; j++) { Calc2.G_y50[j] = Calc2.G_y50[j] / SystemParam.L; } for (int j = 0; j < Calc2.B_y50.Length; j++) { Calc2.B_y50[j] = Calc2.B_y50[j] / SystemParam.L; } /************************************************************************/ /* y50_dark */ /************************************************************************/ waitProc.SetTitle("相同曝光条件下数据处理---计算暗场像素点均值"); waitProc.SetProcessBar(0); Calc2.y50_dark = new double[m_Buffers.Height, m_Buffers.Width]; for (int i = 0; i < SystemParam.L; i++) { p = SystemParam.ReadTempFile(SystemParam.ByteLen4Pic, i, Calc2.DarkTempFile); wfSapGUI.TransPicDatas(p, m_Buffers.Height, m_Buffers.Width, m_Buffers.PixelDepth, SystemParam.cmosInfo.RGB1, SystemParam.cmosInfo.RGB2, SystemParam.cmosInfo.RGB3, SystemParam.cmosInfo.RGB4, out yR, out yG, out yB); for (int j = 0; j < yR.Length; j++) { Calc2.R_y50_dark[j] += yR[j]; } for (int j = 0; j < yG.Length; j++) { Calc2.G_y50_dark[j] += yG[j]; } for (int j = 0; j < yB.Length; j++) { Calc2.B_y50_dark[j] += yB[j]; } if (waitProc.HasBeenCancelled()) { return; } waitProc.SetProcessBar((int)((i + 1))); this.Invoke((EventHandler)(delegate { listView1.Items[14].SubItems[1].Text = (((double)(i + 1) + SystemParam.L) * 100 / count).ToString("F1") + "%"; })); } for (int j = 0; j < Calc2.R_y50_dark.Length; j++) { Calc2.R_y50_dark[j] = Calc2.R_y50_dark[j] / SystemParam.L; } for (int j = 0; j < Calc2.G_y50_dark.Length; j++) { Calc2.G_y50_dark[j] = Calc2.G_y50_dark[j] / SystemParam.L; } for (int j = 0; j < Calc2.B_y50_dark.Length; j++) { Calc2.B_y50_dark[j] = Calc2.B_y50_dark[j] / SystemParam.L; } /************************************************************************/ /* miu_y50 */ /************************************************************************/ Calc2.R_miu_y50 = 0; for (int j = 0; j < Calc2.R_y50.Length; j++) { Calc2.R_miu_y50 += Calc2.R_y50[j]; } Calc2.R_miu_y50 = Calc2.R_miu_y50 / Calc2.R_y50.Length; Calc2.G_miu_y50 = 0; for (int j = 0; j < Calc2.G_y50.Length; j++) { Calc2.G_miu_y50 += Calc2.G_y50[j]; } Calc2.G_miu_y50 = Calc2.G_miu_y50 / Calc2.G_y50.Length; Calc2.B_miu_y50 = 0; for (int j = 0; j < Calc2.B_y50.Length; j++) { Calc2.B_miu_y50 += Calc2.B_y50[j]; } Calc2.B_miu_y50 = Calc2.B_miu_y50 / Calc2.B_y50.Length; /************************************************************************/ /* miu_y50_dark */ /************************************************************************/ Calc2.R_miu_y50_dark = 0; for (int j = 0; j < Calc2.R_y50_dark.Length; j++) { Calc2.R_miu_y50_dark += Calc2.R_y50_dark[j]; } Calc2.R_miu_y50_dark = Calc2.R_miu_y50_dark / Calc2.R_y50_dark.Length; Calc2.G_miu_y50_dark = 0; for (int j = 0; j < Calc2.G_y50_dark.Length; j++) { Calc2.G_miu_y50_dark += Calc2.G_y50_dark[j]; } Calc2.G_miu_y50_dark = Calc2.G_miu_y50_dark / Calc2.G_y50_dark.Length; Calc2.B_miu_y50_dark = 0; for (int j = 0; j < Calc2.B_y50_dark.Length; j++) { Calc2.B_miu_y50_dark += Calc2.B_y50_dark[j]; } Calc2.B_miu_y50_dark = Calc2.B_miu_y50_dark / Calc2.B_y50_dark.Length; /************************************************************************/ /* delta_y50 */ /************************************************************************/ waitProc.SetTitle("相同曝光条件下数据处理---计算明场像素点方差"); waitProc.SetProcessBar(0); for (int i = 0; i < SystemParam.L; i++) { p = SystemParam.ReadTempFile(SystemParam.ByteLen4Pic, i, Calc2.LightTempFile); wfSapGUI.TransPicDatas(p, m_Buffers.Height, m_Buffers.Width, m_Buffers.PixelDepth, SystemParam.cmosInfo.RGB1, SystemParam.cmosInfo.RGB2, SystemParam.cmosInfo.RGB3, SystemParam.cmosInfo.RGB4, out yR, out yG, out yB); for (int j = 0; j < yR.Length; j++) { Calc2.R_delta_y50[j] += (yR[j] - Calc2.R_y50[j]) * (yR[j] - Calc2.R_y50[j]); } for (int j = 0; j < yG.Length; j++) { Calc2.G_delta_y50[j] += (yG[j] - Calc2.G_y50[j]) * (yG[j] - Calc2.G_y50[j]); } for (int j = 0; j < yB.Length; j++) { Calc2.B_delta_y50[j] += (yB[j] - Calc2.B_y50[j]) * (yB[j] - Calc2.B_y50[j]); } if (waitProc.HasBeenCancelled()) { return; } waitProc.SetProcessBar((int)((i + 1))); this.Invoke((EventHandler)(delegate { listView1.Items[14].SubItems[1].Text = (((double)(i + 1) + SystemParam.L * 2) * 100 / count).ToString("F1") + "%"; })); } for (int j = 0; j < Calc2.R_y50.Length; j++) { Calc2.R_delta_y50[j] = Calc2.R_delta_y50[j] / SystemParam.L; } for (int j = 0; j < Calc2.G_y50.Length; j++) { Calc2.G_delta_y50[j] = Calc2.G_delta_y50[j] / SystemParam.L; } for (int j = 0; j < Calc2.B_y50.Length; j++) { Calc2.B_delta_y50[j] = Calc2.B_delta_y50[j] / SystemParam.L; } /************************************************************************/ /* delta_y50_dark */ /************************************************************************/ waitProc.SetTitle("相同曝光条件下数据处理---计算暗场像素点方差"); waitProc.SetProcessBar(0); Calc2.delta_y50_dark = new double[m_Buffers.Height, m_Buffers.Width]; for (int i = 0; i < SystemParam.L; i++) { p = SystemParam.ReadTempFile(SystemParam.ByteLen4Pic, i, Calc2.DarkTempFile); wfSapGUI.TransPicDatas(p, m_Buffers.Height, m_Buffers.Width, m_Buffers.PixelDepth, SystemParam.cmosInfo.RGB1, SystemParam.cmosInfo.RGB2, SystemParam.cmosInfo.RGB3, SystemParam.cmosInfo.RGB4, out yR, out yG, out yB); for (int j = 0; j < yR.Length; j++) { Calc2.R_delta_y50_dark[j] += (yR[j] - Calc2.R_y50_dark[j]) * (yR[j] - Calc2.R_y50_dark[j]); } for (int j = 0; j < yG.Length; j++) { Calc2.G_delta_y50_dark[j] += (yG[j] - Calc2.G_y50_dark[j]) * (yG[j] - Calc2.G_y50_dark[j]); } for (int j = 0; j < yB.Length; j++) { Calc2.B_delta_y50_dark[j] += (yB[j] - Calc2.B_y50_dark[j]) * (yB[j] - Calc2.B_y50_dark[j]); } if (waitProc.HasBeenCancelled()) { this.Invoke((EventHandler)(delegate { textBox1.AppendText("用户终止自动测试\r\n"); return; })); } waitProc.SetProcessBar((int)((i + 1))); this.Invoke((EventHandler)(delegate { listView1.Items[14].SubItems[1].Text = (((double)(i + 1) + SystemParam.L * 3) * 100 / count).ToString("F1") + "%"; })); } for (int j = 0; j < Calc2.R_y50_dark.Length; j++) { Calc2.R_delta_y50_dark[j] = Calc2.R_delta_y50_dark[j] / SystemParam.L; } for (int j = 0; j < Calc2.G_y50_dark.Length; j++) { Calc2.G_delta_y50_dark[j] = Calc2.G_delta_y50_dark[j] / SystemParam.L; } for (int j = 0; j < Calc2.B_y50_dark.Length; j++) { Calc2.B_delta_y50_dark[j] = Calc2.B_delta_y50_dark[j] / SystemParam.L; } /************************************************************************/ /* delta_y50_stack */ /************************************************************************/ waitProc.SetTitle("相同曝光条件下数据处理---计算PRUN、DSUN、亮点、暗点"); waitProc.SetProcessBar(0); waitProc.SetProcessBarRange(0, 7); Calc2.R_delta_y50_stack = 0; for (int j = 0; j < Calc2.R_y50.Length; j++) { Calc2.R_delta_y50_stack += Calc2.R_delta_y50[j]; } Calc2.R_delta_y50_stack = Calc2.R_delta_y50_stack / Calc2.R_y50.Length; Calc2.G_delta_y50_stack = 0; for (int j = 0; j < Calc2.G_y50.Length; j++) { Calc2.G_delta_y50_stack += Calc2.G_delta_y50[j]; } Calc2.G_delta_y50_stack = Calc2.G_delta_y50_stack / Calc2.G_y50.Length; Calc2.B_delta_y50_stack = 0; for (int j = 0; j < Calc2.B_y50.Length; j++) { Calc2.B_delta_y50_stack += Calc2.B_delta_y50[j]; } Calc2.B_delta_y50_stack = Calc2.B_delta_y50_stack / Calc2.B_y50.Length; waitProc.SetProcessBarPerformStep(); /************************************************************************/ /* delta_y50_dark_stack */ /************************************************************************/ Calc2.R_delta_y50_dark_stack = 0; for (int j = 0; j < Calc2.R_y50_dark.Length; j++) { Calc2.R_delta_y50_dark_stack += Calc2.R_delta_y50_dark[j]; } Calc2.R_delta_y50_dark_stack = Calc2.R_delta_y50_dark_stack / Calc2.R_y50_dark.Length; Calc2.G_delta_y50_dark_stack = 0; for (int j = 0; j < Calc2.G_y50_dark.Length; j++) { Calc2.G_delta_y50_dark_stack += Calc2.G_delta_y50_dark[j]; } Calc2.G_delta_y50_dark_stack = Calc2.G_delta_y50_dark_stack / Calc2.G_y50_dark.Length; Calc2.B_delta_y50_dark_stack = 0; for (int j = 0; j < Calc2.B_y50_dark.Length; j++) { Calc2.B_delta_y50_dark_stack += Calc2.B_delta_y50_dark[j]; } Calc2.B_delta_y50_dark_stack = Calc2.B_delta_y50_dark_stack / Calc2.B_y50_dark.Length; waitProc.SetProcessBarPerformStep(); /************************************************************************/ /* S2_y50 */ /************************************************************************/ Calc2.R_S2_y50 = 0; for (int j = 0; j < Calc2.R_y50.Length; j++) { Calc2.R_S2_y50 += (Calc2.R_y50[j] - Calc2.R_miu_y50) * (Calc2.R_y50[j] - Calc2.R_miu_y50); } Calc2.R_S2_y50 = Calc2.R_S2_y50 / (Calc2.R_y50.Length - 1); Calc2.R_S2_y50 = Calc2.R_S2_y50 - Calc2.R_delta_y50_stack / SystemParam.L; Calc2.G_S2_y50 = 0; for (int j = 0; j < Calc2.G_y50.Length; j++) { Calc2.G_S2_y50 += (Calc2.G_y50[j] - Calc2.G_miu_y50) * (Calc2.G_y50[j] - Calc2.G_miu_y50); } Calc2.G_S2_y50 = Calc2.G_S2_y50 / (Calc2.G_y50.Length - 1); Calc2.G_S2_y50 = Calc2.G_S2_y50 - Calc2.G_delta_y50_stack / SystemParam.L; Calc2.B_S2_y50 = 0; for (int j = 0; j < Calc2.B_y50.Length; j++) { Calc2.B_S2_y50 += (Calc2.B_y50[j] - Calc2.B_miu_y50) * (Calc2.B_y50[j] - Calc2.B_miu_y50); } Calc2.B_S2_y50 = Calc2.B_S2_y50 / (Calc2.B_y50.Length - 1); Calc2.B_S2_y50 = Calc2.B_S2_y50 - Calc2.B_delta_y50_stack / SystemParam.L; waitProc.SetProcessBarPerformStep(); /************************************************************************/ /* S2_y50_dark */ /************************************************************************/ Calc2.R_S2_y50_dark = 0; for (int j = 0; j < Calc2.R_y50_dark.Length; j++) { Calc2.R_S2_y50_dark += (Calc2.R_y50_dark[j] - Calc2.R_miu_y50_dark) * (Calc2.R_y50_dark[j] - Calc2.R_miu_y50_dark); } Calc2.R_S2_y50_dark = Calc2.R_S2_y50_dark / (Calc2.R_y50_dark.Length - 1); Calc2.R_S2_y50_dark = Calc2.R_S2_y50_dark - Calc2.R_delta_y50_dark_stack / SystemParam.L; Calc2.G_S2_y50_dark = 0; for (int j = 0; j < Calc2.G_y50_dark.Length; j++) { Calc2.G_S2_y50_dark += (Calc2.G_y50_dark[j] - Calc2.G_miu_y50_dark) * (Calc2.G_y50_dark[j] - Calc2.G_miu_y50_dark); } Calc2.G_S2_y50_dark = Calc2.G_S2_y50_dark / (Calc2.G_y50_dark.Length - 1); Calc2.G_S2_y50_dark = Calc2.G_S2_y50_dark - Calc2.G_delta_y50_dark_stack / SystemParam.L; Calc2.B_S2_y50_dark = 0; for (int j = 0; j < Calc2.B_y50_dark.Length; j++) { Calc2.B_S2_y50_dark += (Calc2.B_y50_dark[j] - Calc2.B_miu_y50_dark) * (Calc2.B_y50_dark[j] - Calc2.B_miu_y50_dark); } Calc2.B_S2_y50_dark = Calc2.B_S2_y50_dark / (Calc2.B_y50_dark.Length - 1); Calc2.B_S2_y50_dark = Calc2.B_S2_y50_dark - Calc2.B_delta_y50_dark_stack / SystemParam.L; waitProc.SetProcessBarPerformStep(); /************************************************************************/ /* DSNU1288 ,PRNU1288 */ /************************************************************************/ Calc2.R_DSNU1288 = Math.Sqrt(Calc2.R_S2_y50_dark) / Calc1.R_OverAllGain_K; Calc2.G_DSNU1288 = Math.Sqrt(Calc2.G_S2_y50_dark) / Calc1.G_OverAllGain_K; Calc2.B_DSNU1288 = Math.Sqrt(Calc2.B_S2_y50_dark) / Calc1.B_OverAllGain_K; Calc2.R_PRNU1288 = Math.Sqrt(Math.Abs(Calc2.R_S2_y50 - Calc2.R_S2_y50_dark)) / (Calc2.R_miu_y50 - Calc2.R_miu_y50_dark); Calc2.G_PRNU1288 = Math.Sqrt(Math.Abs(Calc2.G_S2_y50 - Calc2.G_S2_y50_dark)) / (Calc2.G_miu_y50 - Calc2.G_miu_y50_dark); Calc2.B_PRNU1288 = Math.Sqrt(Math.Abs(Calc2.B_S2_y50 - Calc2.B_S2_y50_dark)) / (Calc2.B_miu_y50 - Calc2.B_miu_y50_dark); this.Invoke((EventHandler)(delegate { listView1.Items[14].SubItems[1].Text = "完成"; listView1.Items[15].SubItems[1].Text = "完成"; listView1.Items[14].SubItems[2].Text = Calc2.R_DSNU1288.ToString("F2") + "||" + Calc2.G_DSNU1288.ToString("F2") + "||" + Calc2.B_DSNU1288.ToString("F2"); listView1.Items[15].SubItems[2].Text = Calc2.R_PRNU1288.ToString("F4") + "||" + Calc2.G_PRNU1288.ToString("F4") + "||" + Calc2.B_PRNU1288.ToString("F4"); textBox1.AppendText("DSNU1288 ,PRNU1288计算完成\r\n"); })); waitProc.SetProcessBarPerformStep(); /************************************************************************/ /* 暗点查找 */ /************************************************************************/ double dP = Calc2.R_miu_y50 * SystemParam.DarkPointPer / 100; Calc2.R_DarkPoints = new List <PixelInfo>(); for (int j = 0; j < Calc2.R_y50.Length; j++) { if (Calc2.R_y50[j] < dP) { PixelInfo pD = wfSapGUI.RPixel[j]; pD.y = Calc2.R_y50[j]; Calc2.R_DarkPoints.Add(pD); } } dP = Calc2.G_miu_y50 * SystemParam.DarkPointPer / 100; Calc2.G_DarkPoints = new List <PixelInfo>(); for (int j = 0; j < Calc2.G_y50.Length; j++) { if (Calc2.G_y50[j] < dP) { PixelInfo pD = wfSapGUI.GPixel[j]; pD.y = Calc2.G_y50[j]; Calc2.G_DarkPoints.Add(pD); } } dP = Calc2.B_miu_y50 * SystemParam.DarkPointPer / 100; Calc2.B_DarkPoints = new List <PixelInfo>(); for (int j = 0; j < Calc2.B_y50.Length; j++) { if (Calc2.B_y50[j] < dP) { PixelInfo pD = wfSapGUI.BPixel[j]; pD.y = Calc2.B_y50[j]; Calc2.B_DarkPoints.Add(pD); } } waitProc.SetProcessBarPerformStep(); this.Invoke((EventHandler)(delegate { listView1.Items[16].SubItems[1].Text = "完成"; textBox1.AppendText("暗点查找完成\r\n"); })); /************************************************************************/ /* 明点查找 */ /************************************************************************/ double lP = Calc2.R_miu_y50_dark * (100 + SystemParam.LightPointPer) / 100; Calc2.R_LightPoints = new List <PixelInfo>(); for (int j = 0; j < Calc2.R_y50.Length; j++) { if (Calc2.R_y50_dark[j] > lP) { PixelInfo pD = wfSapGUI.RPixel[j]; pD.y = Calc2.R_y50_dark[j]; Calc2.R_LightPoints.Add(pD); } } lP = Calc2.G_miu_y50_dark * (100 + SystemParam.LightPointPer) / 100; Calc2.G_LightPoints = new List <PixelInfo>(); for (int j = 0; j < Calc2.G_y50.Length; j++) { if (Calc2.G_y50_dark[j] > lP) { PixelInfo pD = wfSapGUI.GPixel[j]; pD.y = Calc2.G_y50_dark[j]; Calc2.G_LightPoints.Add(pD); } } lP = Calc2.B_miu_y50_dark * (100 + SystemParam.LightPointPer) / 100; Calc2.B_LightPoints = new List <PixelInfo>(); for (int j = 0; j < Calc2.B_y50.Length; j++) { if (Calc2.B_y50_dark[j] > lP) { PixelInfo pD = wfSapGUI.BPixel[j]; pD.y = Calc2.B_y50_dark[j]; Calc2.B_LightPoints.Add(pD); } } waitProc.SetProcessBarPerformStep(); this.Invoke((EventHandler)(delegate { listView1.Items[17].SubItems[1].Text = "完成"; textBox1.AppendText("亮点查找完成\r\n"); })); }
public Mesh Update(Iterate iter, PictureData pictureData) { _iterate = iter; _pictureData = pictureData; // TODO: Update _mesh data List <Coord2D> pointList = new List <Coord2D>(); int[,] pointIndex = new int[_pictureData.Width + 1, _pictureData.Height + 1]; int currentIndex = _mesh.Coordinates.Count / 3; // lenght of pointindex in _mesh?? for (int i = 0; i < _pictureData.Width; i++) { for (int j = 0; j < _pictureData.Height; j++) { if (_pictureData.Points[i, j] != null) { Coord2D coord = new Coord2D(i, j); pointIndex[i, j] = currentIndex; pointList.Add(coord); currentIndex++; } else { pointIndex[i, j] = -1; } } } // to test for invalid pdata double maxcol = 0; foreach (Coord2D coord in pointList) { PixelInfo pInfo = Transform(_pictureData.Points[coord.X, coord.Y]); if (pInfo != null && pInfo.Coord != null && pInfo.AdditionalInfo != null) { double x, y, z; if (_needScaling || AlwaysScale) { x = (pInfo.Coord.X - _centerx) / _radius; y = (pInfo.Coord.Y - _centery) / _radius; z = (pInfo.Coord.Z - _centerz) / _radius; } else { // Scale by 1000 x = 1000.0 * pInfo.Coord.X; y = 1000.0 * pInfo.Coord.Y; z = 1000.0 * pInfo.Coord.Z; } _mesh.Coordinates.Add((float)x); _mesh.Coordinates.Add((float)y); _mesh.Coordinates.Add((float)z); double red = pInfo.AdditionalInfo.red2; double green = pInfo.AdditionalInfo.green2; double blue = pInfo.AdditionalInfo.blue2; _mesh.Colors.Add((float)red); _mesh.Colors.Add((float)green); _mesh.Colors.Add((float)blue); // test for invalid data only if (maxcol < red) { maxcol = red; } if (maxcol < green) { maxcol = green; } if (maxcol < blue) { maxcol = blue; } } } for (int i = 0; i < _pictureData.Width; i++) { for (int j = 0; j < _pictureData.Height; j++) { if (_pictureData.Points[i, j] != null) { PixelInfo point1 = _pictureData.Points[i, j]; if (point1.Coord.X > 1000 && point1.Coord.X < -1000 && point1.Coord.Y > 1000 && point1.Coord.Y < -1000 && point1.Coord.Z > 1000 && point1.Coord.Z < -1000) { System.Diagnostics.Debug.WriteLine("Error"); } if (i > 0 && j > 0 && _pictureData.Points[i - 1, j - 1] != null) { if (_pictureData.Points[i - 1, j] != null) { // triangle 1 bool useTriangle = true; if (_useDistance) { PixelInfo point2 = _pictureData.Points[i - 1, j]; PixelInfo point3 = _pictureData.Points[i - 1, j - 1]; if (Dist(point1, point2) > _maxDist || Dist(point1, point3) > _maxDist) { useTriangle = false; } } if (useTriangle) { _mesh.Faces.Add(pointIndex[i, j]); _mesh.Faces.Add(pointIndex[i - 1, j]); _mesh.Faces.Add(pointIndex[i - 1, j - 1]); _mesh.Normales.Add((float)point1.Normal.X); _mesh.Normales.Add((float)point1.Normal.Y); _mesh.Normales.Add((float)point1.Normal.Z); } } if (_pictureData.Points[i, j - 1] != null) { // triangle 2 bool useTriangle = true; if (_useDistance) { PixelInfo point2 = _pictureData.Points[i - 1, j - 1]; PixelInfo point3 = _pictureData.Points[i, j - 1]; if (Dist(point1, point2) > _maxDist || Dist(point1, point3) > _maxDist) { useTriangle = false; } } if (useTriangle) { _mesh.Faces.Add(pointIndex[i, j]); _mesh.Faces.Add(pointIndex[i - 1, j - 1]); _mesh.Faces.Add(pointIndex[i, j - 1]); _mesh.Normales.Add((float)point1.Normal.X); _mesh.Normales.Add((float)point1.Normal.Y); _mesh.Normales.Add((float)point1.Normal.Z); } } } } } } if (maxcol < 0.0001) { _valid = false; } return(_mesh); }
/// <summary> /// Draw two channels /// </summary> /// <param name="lInfo">cached samples of the left channel</param> /// <param name="rInfo">cached samples of the right channel</param> /// <param name="style">style of the wave</param> /// <param name="startPer">the percent of the start position</param> /// <param name="scale">scale</param> /// <param name="width">the width of the return bitmap</param> /// <param name="height">the height of the return bitmap</param> /// <returns>bitmap that the wave drawed on</returns> public static ImageSource Draw2Channel(PixelInfo[] lInfo, PixelInfo[] rInfo, WaveStyle style, double startPer, double scale, double width, double height = -1) { if (width <= 0) { return(null); } if (lInfo.Length < width) { return(null); } var startPos = (int)(lInfo.Length * startPer); var sampleNumber = (int)(lInfo.Length * scale); if (startPos + sampleNumber > lInfo.Length) { startPos = lInfo.Length - sampleNumber; } var samplesPerPixel = (double)sampleNumber / width; if (height == -1) { height = WavFile.MinHeight; } var singleHeight = height / 2; DrawingVisual dv = new DrawingVisual(); var dc = dv.RenderOpen(); var pen = new Pen(style.WaveBrush, 1); var linePen = new Pen(style.WaveBrush, 1); pen.Freeze(); //draw wave var drawedSample = 0; PixelInfo lprePixel = null; PixelInfo rprePixel = null; for (int i = 0; i < width; i++) { var drawSample = 0; if (i == width - 1) { drawSample = sampleNumber - drawedSample; } else { drawSample = (int)((i + 1) * samplesPerPixel - drawedSample); } var lTemp = new PixelInfo(); var rTemp = new PixelInfo(); for (int j = 0; j < drawSample; j++) { lTemp.Push(lInfo[startPos + drawedSample + j]); rTemp.Push(rInfo[startPos + drawedSample + j]); } var lmin = lTemp.Min; var lmax = lTemp.Max; var rmin = rTemp.Min; var rmax = rTemp.Max; if (height != -1) { lmin = (short)ScaleToHeight(lmin, height); lmax = (short)ScaleToHeight(lmax, height); rmin = (short)ScaleToHeight(rmin, height); rmax = (short)ScaleToHeight(rmax, height); } dc.DrawLine(pen, new Point(i, lmin / 2), new Point(i, lmax / 2)); dc.DrawLine(pen, new Point(i, rmin / 2 + singleHeight), new Point(i, rmax / 2 + singleHeight)); if (lprePixel == null) { lprePixel = new PixelInfo { Max = lmax, Min = lmin, }; } else { if (lprePixel.Max < lmin) { dc.DrawLine(pen, new Point(i - 1, lprePixel.Max / 2), new Point(i, lmin / 2)); } if (lprePixel.Min > lmax) { dc.DrawLine(pen, new Point(i - 1, lprePixel.Min / 2), new Point(i, lmax / 2)); } } if (rprePixel == null) { rprePixel = new PixelInfo { Max = rmax, Min = rmin, }; } else { if (rprePixel.Max < rmin) { dc.DrawLine(pen, new Point(i - 1, rprePixel.Max / 2), new Point(i, rmin / 2)); } if (rprePixel.Min > rmax) { dc.DrawLine(pen, new Point(i - 1, rprePixel.Min / 2), new Point(i, rmax / 2)); } } drawedSample += drawSample; } dc.Close(); var bmp = new RenderTargetBitmap((int)width, (int)height, 0, 0, PixelFormats.Default); bmp.Render(dv); return(bmp); }
public Mesh CreateMesh() { _useDistance = !Fractrace.Basic.ParameterDict.Current.GetBool("Export.X3d.ClosedSurface"); List <Coord2D> pointList = new List <Coord2D>(); int[,] pointIndex = new int[_pictureData.Width + 1, _pictureData.Height + 1]; double minx = Double.MaxValue; double miny = Double.MaxValue; double minz = Double.MaxValue; double maxx = Double.MinValue; double maxy = Double.MinValue; double maxz = Double.MinValue; int currentIndex = 0; int pointsFound = 0; for (int i = 0; i < _pictureData.Width; i++) { for (int j = 0; j < _pictureData.Height; j++) { if (_pictureData.Points[i, j] != null) { PixelInfo point = Transform(_pictureData.Points[i, j]); if (minx > point.Coord.X) { minx = point.Coord.X; } if (miny > point.Coord.Y) { miny = point.Coord.Y; } if (minz > point.Coord.Z) { minz = point.Coord.Z; } if (maxx < point.Coord.X) { maxx = point.Coord.X; } if (maxy < point.Coord.Y) { maxy = point.Coord.Y; } if (maxz < point.Coord.Z) { maxz = point.Coord.Z; } Coord2D coord = new Coord2D(i, j); pointIndex[i, j] = currentIndex; pointList.Add(coord); currentIndex++; pointsFound++; } else { pointIndex[i, j] = -1; } } } if (pointsFound < 100) { _valid = false; return(null); } _radius = maxz - minz + maxy - miny + maxx - minx; _centerx = (maxx + minx) / 2.0; _centery = (maxy + miny) / 2.0; _centerz = (maxz + minz) / 2.0; _needScaling = _radius < 0.01; // Rounding scale parameters to allow combine different 3d scenes at later time. int noOfDigits = 1; double d = 1; if (_needScaling || AlwaysScale) { while (d > _radius) { d /= 10.0; noOfDigits++; } noOfDigits -= 3; _radius = d; if (noOfDigits > 1) { _centerx = Math.Round(_centerx, noOfDigits); _centery = Math.Round(_centery, noOfDigits); _centerz = Math.Round(_centerz, noOfDigits); } } // Maximal Distance to draw triangle. double noOfPoints = Math.Max(_pictureData.Width, _pictureData.Height); _maxDist = Fractrace.Basic.ParameterDict.Current.GetDouble("Export.X3d.ClosedSurfaceDist") * _radius / noOfPoints; // to test for invalid pdata double maxcol = 0; foreach (Coord2D coord in pointList) { PixelInfo pInfo = Transform(_pictureData.Points[coord.X, coord.Y]); if (pInfo != null && pInfo.Coord != null && pInfo.AdditionalInfo != null) { double x, y, z; if (_needScaling || AlwaysScale) { x = (pInfo.Coord.X - _centerx) / _radius; y = (pInfo.Coord.Y - _centery) / _radius; z = (pInfo.Coord.Z - _centerz) / _radius; } else { // Scale by 1000 x = 1000.0 * pInfo.Coord.X; y = 1000.0 * pInfo.Coord.Y; z = 1000.0 * pInfo.Coord.Z; } _mesh.Coordinates.Add((float)x); _mesh.Coordinates.Add((float)y); _mesh.Coordinates.Add((float)z); double red = pInfo.AdditionalInfo.red2; double green = pInfo.AdditionalInfo.green2; double blue = pInfo.AdditionalInfo.blue2; _mesh.Colors.Add((float)red); _mesh.Colors.Add((float)green); _mesh.Colors.Add((float)blue); // test for invalid data only if (maxcol < red) { maxcol = red; } if (maxcol < green) { maxcol = green; } if (maxcol < blue) { maxcol = blue; } } } for (int i = 0; i < _pictureData.Width; i++) { for (int j = 0; j < _pictureData.Height; j++) { if (_pictureData.Points[i, j] != null) { PixelInfo point1 = _pictureData.Points[i, j]; if (point1.Coord.X > 1000 && point1.Coord.X < -1000 && point1.Coord.Y > 1000 && point1.Coord.Y < -1000 && point1.Coord.Z > 1000 && point1.Coord.Z < -1000) { System.Diagnostics.Debug.WriteLine("Error"); } if (i > 0 && j > 0 && _pictureData.Points[i - 1, j - 1] != null) { if (_pictureData.Points[i - 1, j] != null) { // triangle 1 bool useTriangle = true; if (_useDistance) { PixelInfo point2 = _pictureData.Points[i - 1, j]; PixelInfo point3 = _pictureData.Points[i - 1, j - 1]; if (Dist(point1, point2) > _maxDist || Dist(point1, point3) > _maxDist) { useTriangle = false; } } if (useTriangle) { _mesh.Faces.Add(pointIndex[i, j]); _mesh.Faces.Add(pointIndex[i - 1, j]); _mesh.Faces.Add(pointIndex[i - 1, j - 1]); _mesh.Normales.Add((float)point1.Normal.X); _mesh.Normales.Add((float)point1.Normal.Y); _mesh.Normales.Add((float)point1.Normal.Z); } } if (_pictureData.Points[i, j - 1] != null) { // triangle 2 bool useTriangle = true; if (_useDistance) { PixelInfo point2 = _pictureData.Points[i - 1, j - 1]; PixelInfo point3 = _pictureData.Points[i, j - 1]; if (Dist(point1, point2) > _maxDist || Dist(point1, point3) > _maxDist) { useTriangle = false; } } if (useTriangle) { _mesh.Faces.Add(pointIndex[i, j]); _mesh.Faces.Add(pointIndex[i - 1, j - 1]); _mesh.Faces.Add(pointIndex[i, j - 1]); _mesh.Normales.Add((float)point1.Normal.X); _mesh.Normales.Add((float)point1.Normal.Y); _mesh.Normales.Add((float)point1.Normal.Z); } } } } } } if (maxcol < 0.0001) { _valid = false; } return(_mesh); }
public void Init(Iterate iter, PictureData pictureData) { _iterate = iter; _pictureData = pictureData; _useDistance = !Fractrace.Basic.ParameterDict.Current.GetBool("Export.X3d.ClosedSurface"); double minx = Double.MaxValue; double miny = Double.MaxValue; double minz = Double.MaxValue; double maxx = Double.MinValue; double maxy = Double.MinValue; double maxz = Double.MinValue; int currentIndex = 0; for (int i = 0; i < _pictureData.Width; i++) { for (int j = 0; j < _pictureData.Height; j++) { if (_pictureData.Points[i, j] != null) { PixelInfo point = Transform(_pictureData.Points[i, j]); if (minx > point.Coord.X) { minx = point.Coord.X; } if (miny > point.Coord.Y) { miny = point.Coord.Y; } if (minz > point.Coord.Z) { minz = point.Coord.Z; } if (maxx < point.Coord.X) { maxx = point.Coord.X; } if (maxy < point.Coord.Y) { maxy = point.Coord.Y; } if (maxz < point.Coord.Z) { maxz = point.Coord.Z; } currentIndex++; } } } if (currentIndex == 0) { _valid = false; return; } _radius = maxz - minz + maxy - miny + maxx - minx; _centerx = (maxx + minx) / 2.0; _centery = (maxy + miny) / 2.0; _centerz = (maxz + minz) / 2.0; _needScaling = _radius < 0.01; // Rounding scale parameters to allow combine different 3d scenes at later time. int noOfDigits = 1; double d = 1; if (_needScaling || AlwaysScale) { while (d > _radius) { d /= 10.0; noOfDigits++; } noOfDigits -= 3; _radius = d; if (noOfDigits > 1) { _centerx = Math.Round(_centerx, noOfDigits); _centery = Math.Round(_centery, noOfDigits); _centerz = Math.Round(_centerz, noOfDigits); } } // Maximal Distance to draw triangle. double noOfPoints = Math.Max(_pictureData.Width, _pictureData.Height); _maxDist = Fractrace.Basic.ParameterDict.Current.GetDouble("Export.X3d.ClosedSurfaceDist") * _radius / noOfPoints; }
public Texture(int index, byte[] bytes, ImageFormat format = ImageFormat.RGBA, PixelInfo pixel = PixelInfo.Size_32b, int width = 0, int height = 0, Palette palette = null, int paletteIndex = 0) : base(index, bytes) { Format = format; PixelSize = pixel; Width = width; Height = height; ImagePalette = palette; PaletteIndex = paletteIndex; //generate image _initializing = false; RawData = bytes; }
/// <summary> /// Compute surface data. /// </summary> protected void Generate(FracValues act_val, int zyklen, double screensize, int formula, bool perspective) { Random rand = new Random(); _maxUpdateSteps = ParameterDict.Current.GetInt("View.UpdateSteps"); double xd, yd, zd; double x, y, z; double dephAdd = ParameterDict.Current.GetInt("View.DephAdd") * screensize; act_val = act_val.Clone(); Formulas formulas = new Formulas(_pData); _lastUsedFormulas = formulas; if (ParameterDict.Current["Intern.Formula.Source"].Trim() == "") { formulas.InternFormula = new Fractrace.TomoGeometry.VecRotMandel2d(); } else { Fractrace.TomoGeometry.TomoFormulaFactory fac = new Fractrace.TomoGeometry.TomoFormulaFactory(); formulas.InternFormula = fac.CreateFromString(ParameterDict.Current["Intern.Formula.Source"]); } if (formulas.InternFormula == null) { return; } formulas.InternFormula.Init(); double centerX = ParameterDict.Current.GetDouble("Scene.CenterX"); double centerY = ParameterDict.Current.GetDouble("Scene.CenterY"); double centerZ = ParameterDict.Current.GetDouble("Scene.CenterZ"); Rotation rotView = new Rotation(); rotView.Init(centerX, centerY, centerZ, ParameterDict.Current.GetDouble("Transformation.Camera.AngleX"), ParameterDict.Current.GetDouble("Transformation.Camera.AngleY"), ParameterDict.Current.GetDouble("Transformation.Camera.AngleZ")); formulas.Transforms.Add(rotView); // TODO: only use in compatibility mode. Rotation rot = new Rotation(); rot.Init(); formulas.Transforms.Add(rot); if (_isRightView) { RightEyeView stereoTransform = new RightEyeView(); stereoTransform.Init(); formulas.Transforms.Add(stereoTransform); } _maxxIter = _width; _maxyIter = (int)(ParameterDict.Current.GetDouble("View.Deph") * screensize); if (IsSmallPreview() && _updateCount == 0) { _maxyIter = _maxxIter; } _maxzIter = _height; int MINX_ITER = 0; int MINY_ITER = 0; int MINZ_ITER = 0; int xschl = 0, yschl = 0, zschl = 0, xx = 0, yy = 0; double wix = 0, wiy = 0, wiz = 0; double jx = 0, jy = 0, jz = 0, jzz = 0; jx = ParameterDict.Current.GetDouble("Formula.Static.jx"); jy = ParameterDict.Current.GetDouble("Formula.Static.jy"); jz = ParameterDict.Current.GetDouble("Formula.Static.jz"); jzz = ParameterDict.Current.GetDouble("Formula.Static.jzz"); // Innenbereich int minCycle = (int)ParameterDict.Current.GetDouble("Formula.Static.MinCycle"); if (minCycle == 0) { minCycle = zyklen; } // Offset für den Maximalzyklus für die klassische 2D-Darstellung //int cycleAdd = 128; wix = act_val.arc.x; wiy = act_val.arc.y; wiz = act_val.arc.z; xd = (act_val.end_tupel.x - act_val.start_tupel.x) / (_maxxIter - MINX_ITER); yd = (act_val.end_tupel.y - act_val.start_tupel.y) / (_maxyIter - MINY_ITER); zd = (act_val.end_tupel.z - act_val.start_tupel.z) / (_maxzIter - MINZ_ITER); if (_oldData != null) { yd = yd / (_updateCount); if (_updateCount < 5) { _maxyIter *= _updateCount; } } if (_transformUpdate) { yd *= 3.0; } double xcenter = (act_val.start_tupel.x + act_val.end_tupel.x) / 2.0; double zcenter = (act_val.start_tupel.z + act_val.end_tupel.z) / 2.0; bool isYborder = true; // Projektion initialisieren und der Berechnung zuordnen: // TODO: Projektion über Einstellungen abwählbar machen double cameraDeph = act_val.end_tupel.y - act_val.start_tupel.y; cameraDeph *= ParameterDict.Current.GetDouble("Transformation.Camera.Position"); Vec3 camera = new Vec3(xcenter, act_val.end_tupel.y + cameraDeph, zcenter); Vec3 viewPoint = new Vec3(xcenter, act_val.end_tupel.y, zcenter); Projection proj = new Projection(camera, viewPoint); if (!ParameterDict.Current.GetBool("Transformation.Camera.IsometricProjection")) { formulas.Projection = proj; } // Bei der Postererstellung werden die Parameter der räumlichen Projektion auf das mittlere Bild // ausgerichtet und anschließend die Grenzen verschoben double xPoster = ParameterDict.Current.GetInt("View.PosterX"); double zPoster = ParameterDict.Current.GetInt("View.PosterZ"); double xDiff = act_val.end_tupel.x - act_val.start_tupel.x; double zDiff = act_val.end_tupel.z - act_val.start_tupel.z; act_val.end_tupel.x += xDiff * xPoster; act_val.start_tupel.x += xDiff * xPoster; act_val.end_tupel.z += zDiff * zPoster; act_val.start_tupel.z += zDiff * zPoster; // Start der Iteration in der Reihenfolge: z,x,y (y entspricht der Tiefe) z = act_val.end_tupel.z + zd; for (zschl = (int)(_maxzIter); zschl >= (MINZ_ITER); zschl -= 1) { // Nur wenn der Scheduler die Erlaubnis gibt, zschl zu benutzen, // die Berechnung ausführen (sonst nächste Iteration) if (IsAvailable(_maxzIter - zschl)) { System.Windows.Forms.Application.DoEvents(); z = act_val.end_tupel.z - (double)zd * (_maxzIter - zschl); for (xschl = (int)(MINX_ITER); xschl <= _maxxIter; xschl += 1) { if (_abort) { return; } x = act_val.start_tupel.x + (double)xd * xschl; isYborder = true; xx = xschl; yy = _maxzIter - zschl; if (double.IsNaN(x)) { return; } // Used for better start values in update iteration double yAdd = rand.NextDouble() * yd; // In last computation a voxel ist found at (xx,zz) bool centerIsSet = false; // In last computation at least on voxel ist found near (xx,zz) bool areaIsSet = false; double yAddCenter = 0; bool needComputing = true; if (_oldPictureData != null) { needComputing = false; PixelInfo pxInfoTest = _oldPictureData.Points[xx, yy]; if (pxInfoTest != null && pxInfoTest.Coord != null) { yAddCenter = pxInfoTest.Coord.Y; yAdd = yAddCenter; centerIsSet = true; } for (int xxi = -1; xxi <= 1; xxi++) { for (int yyi = -1; yyi <= 1; yyi++) { int xxposi = xx + xxi; int yyposi = yy + yyi; if (xxposi >= 0 && xxposi <= _maxxIter && yyposi >= 0 && yyposi <= _maxzIter) { PixelInfo pxInfo = _oldPictureData.Points[xxposi, yyposi]; if (pxInfo != null && pxInfo.Coord != null) { areaIsSet = true; double yAddTemp = pxInfo.Coord.Y; if (yAdd < yAddTemp || !centerIsSet) { yAdd = yAddTemp; } } } } } } if (yAdd + yd < act_val.end_tupel.y) { if (centerIsSet) { if (yAddCenter + 4.0 * yd < yAdd) { needComputing = true; yAdd = yAdd - act_val.end_tupel.y + 2.0 * ((double)_updateCount) * yd + rand.NextDouble() * yd; _gData.Picture[xx, yy] = _oldData.Picture[xx, yy]; } } else { if (areaIsSet) { needComputing = true; yAdd = rand.NextDouble() * yd; } } } if (needComputing) { // yadd cannot be easy handled (because of inside rendering). for (yschl = (int)(_maxyIter); yschl >= MINY_ITER - dephAdd; yschl -= 1) { if (_abort) { return; } if (xx >= 0 && xx < _width && yy >= 0 && yy < _height) { if ((_gData.Picture)[xx, yy] == 0 || (_gData.Picture)[xx, yy] == 2) { // aha, noch zeichnen // Test, ob Schnitt mit Begrenzung vorliegt y = act_val.end_tupel.y - (double)yd * (_maxyIter - yschl); y += yAdd; if (double.IsNaN(x) || double.IsNaN(y) || double.IsNaN(z)) { return; } int usedCycles = 0; bool inverse = false; if (_gData == null) { System.Diagnostics.Debug.WriteLine("Error: GData == null"); return; } if ((_gData.Picture)[xx, yy] == 0) { usedCycles = formulas.Rechne(x, y, z, 0, zyklen, wix, wiy, wiz, jx, jy, jz, jzz, formula, inverse); } if ((_gData.Picture)[xx, yy] == 2) {// Inverse computing inverse = true; usedCycles = formulas.Rechne(x, y, z, 0, minCycle, wix, wiy, wiz, jx, jy, jz, jzz, formula, inverse); } if (usedCycles == 0) { // Iteration ist nicht abgebrochen, also weiterrechnen: //int oldPictureInfo = (_gData.Picture)[xx, yy]; // pictureInfo wird eventuell zurückgesetzt, wenn // die Farbberechnung wiederholt wird. _gData.Picture[xx, yy] = 1; // Punkt als gesetzt markieren VoxelInfo vInfo = new VoxelInfo(); _gData.PointInfo[xx, yy] = vInfo; vInfo.i = x; vInfo.j = y; vInfo.k = z; /* * cycleAdd = 1024; * if (minCycle >= 0) * { * cycleAdd = minCycle - zyklen; * } */ if (isYborder) { if (formulas.Rechne(x, y, z, 0, zyklen, wix, wiy, wiz, jx, jy, jz, jzz, formula, false) == 0) { (_gData.Picture)[xx, yy] = 2; // Mark point as not set. } } else {// inner Point if (inverse) { if (IsSmallPreview() && _updateCount == 0) { formulas.RayCastAt(minCycle, x, y, z, 0, xd, yd, zd, 0, wix, wiy, wiz, jx, jy, jz, jzz, formula, inverse, xx, yy, true); } else { formulas.FixPoint(minCycle, x, y, z, 0, xd, yd, zd, 0, wix, wiy, wiz, jx, jy, jz, jzz, formula, inverse, xx, yy, true); } } else { if (IsSmallPreview() && _updateCount == 0) { formulas.RayCastAt(zyklen, x, y, z, 0, xd, yd, zd, 0, wix, wiy, wiz, jx, jy, jz, jzz, formula, inverse, xx, yy, true); } else { formulas.FixPoint(zyklen, x, y, z, 0, xd, yd, zd, 0, wix, wiy, wiz, jx, jy, jz, jzz, formula, inverse, xx, yy, true); } } } } } } isYborder = false; } if ((_gData.Picture)[xx, yy] == 0 || (_gData.Picture)[xx, yy] == 2) { if (_oldPictureData != null) { _pData.Points[xx, yy] = _oldPictureData.Points[xx, yy]; } } if (_oldData != null && _updateCount > 2) { if (_oldPictureData.Points[xx, yy] != null) { if (_pData.Points[xx, yy] == null) { _pData.Points[xx, yy] = _oldPictureData.Points[xx, yy]; } else { if (_pData.Points[xx, yy].Coord.Y < _oldPictureData.Points[xx, yy].Coord.Y) { _pData.Points[xx, yy] = _oldPictureData.Points[xx, yy]; } } } } } else { // Get the old values: _pData.Points[xx, yy] = _oldPictureData.Points[xx, yy]; } } } } }
public static Texture2D Create(int width, int height, int count_CenterPoints, int count_PointsPerGroup = 10, float radius = 15, Texture2D referenceTex = null, Texture2D barrierTex = null) { Texture2D texture = new Texture2D(width, height); PixelInfo[] PixelInfoes = new PixelInfo[width * height]; //用于存储各像素点的信息(最近特征点和与其的距离) Vector2[] CenterPoints = null; if (centerPoints == null) { CenterPoints = RandomPoints(count_CenterPoints, width, height, referenceTex); //随机选择特征点 } else { CenterPoints = centerPoints; } centerPoints = CenterPoints; Vector2[] FeaturePoints = new Vector2[CenterPoints.Length * count_PointsPerGroup]; PixelInfo[] FeaturePointInfos = new PixelInfo[FeaturePoints.Length]; PixelInfo[] FeaturePointInfos_FeaturePoint = new PixelInfo[FeaturePoints.Length]; for (int i = 0; i < CenterPoints.Length; i++) { for (int j = 0; j < count_PointsPerGroup; j++) { Vector2 FeaturePoint = CenterPoints[i] + Random.insideUnitCircle * radius; while ((FeaturePoint.x < 0 || FeaturePoint.x > width - 1 || FeaturePoint.y < 0 || FeaturePoint.y > height - 1)) { FeaturePoint = CenterPoints[i] + Random.insideUnitCircle * radius; } FeaturePoint.x = (int)FeaturePoint.x; FeaturePoint.y = (int)FeaturePoint.y; FeaturePoints[i * count_PointsPerGroup + j] = FeaturePoint; } } FeaturePointInfos = ComputeDistance_FC(FeaturePoints, CenterPoints); FeaturePointInfos_FeaturePoint = ComputeDistance_FF(FeaturePoints, FeaturePointInfos); SortFeaturePoints(ref FeaturePoints, ref FeaturePointInfos, ref FeaturePointInfos_FeaturePoint); /* * 计算每个像素与其最近特征点之间的距离 */ PixelInfoes = ComputeDistanceFast(width, height, CenterPoints, FeaturePoints, FeaturePointInfos); /* * 计算最长的距离 * 用于实现颜色变化 */ float MaxDistance = GetMaxDistance(PixelInfoes); /* * 为实现特征点有先后顺序,对中心点的颜色进行干扰 */ for (int i = 0; i < CenterPoints.Length; i++) { texture.SetPixel((int)CenterPoints[i].x, (int)CenterPoints[i].y, DEC2Color((int)(MaxDistance * RandomNumer.Single() * 0.5f * SCALE))); } /* * 赋予每个特征点颜色 */ for (int i = 0; i < FeaturePoints.Length; i++) { Color FeaturePixel = texture.GetPixel((int)FeaturePointInfos_FeaturePoint[i].X_NearestPoint, (int)FeaturePointInfos_FeaturePoint[i].Y_NearestPoint); texture.SetPixel((int)FeaturePoints[i].x, (int)FeaturePoints[i].y, GetColor(FeaturePointInfos[i].Distance, MaxDistance, FeaturePixel)); } /* * 赋予每个像素点颜色 * 根据位置之间的关系,从近到远(黑到白) */ for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { Color FeaturePixel = texture.GetPixel((int)PixelInfoes[i * height + j].X_NearestPoint, (int)PixelInfoes[i * height + j].Y_NearestPoint); //获取最近特征点的颜色 Color pixel = GetColor(PixelInfoes[i * height + j].Distance, MaxDistance, FeaturePixel); pixel.a = 1.0f; texture.SetPixel(i, j, pixel); } } //添加障碍物像素 if (barrierTex != null) { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (barrierTex.GetPixel(x, y).a != 0) { texture.SetPixel(x, y, GetTransparentColor(texture.GetPixel(x, y))); } } } } //添加轮廓像素 if (referenceTex != null) { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (referenceTex.GetPixel(x, y).a == 0) { texture.SetPixel(x, y, GetTransparentColor(texture.GetPixel(x, y))); } } } } texture.Apply(); return(texture); }
void 第二步数据处理(object LockWatingThread) { int count = SystemParam.L * 4; /************************************************************************/ /* y50 */ /************************************************************************/ waitProc.SetTitle("相同曝光条件下数据处理---计算明场像素点均值"); Calc2.y50 = new double[m_Buffers.Height, m_Buffers.Width]; for (int i = 0; i < SystemParam.L; i++) { byte[] p = SystemParam.ReadTempFile(SystemParam.ByteLen4Pic, i, Calc2.LightTempFile); ushort[,] pic = wfSapGUI.TransPicDatas(p, m_Buffers.Height, m_Buffers.Width, m_Buffers.PixelDepth); for (int m = 0; m < m_Buffers.Height; m++) { for (int n = 0; n < m_Buffers.Width; n++) { Calc2.y50[m, n] += pic[m, n]; } } if (waitProc.HasBeenCancelled()) { return; } waitProc.SetProcessBar((int)((i + 1))); this.Invoke((EventHandler)(delegate { listView1.Items[14].SubItems[1].Text = (((double)(i + 1)) * 100 / count).ToString("F1") + "%"; })); } for (int m = 0; m < m_Buffers.Height; m++) { for (int n = 0; n < m_Buffers.Width; n++) { Calc2.y50[m, n] = Calc2.y50[m, n] / SystemParam.L; } } /************************************************************************/ /* y50_dark */ /************************************************************************/ waitProc.SetTitle("相同曝光条件下数据处理---计算暗场像素点均值"); waitProc.SetProcessBar(0); Calc2.y50_dark = new double[m_Buffers.Height, m_Buffers.Width]; for (int i = 0; i < SystemParam.L; i++) { byte[] p = SystemParam.ReadTempFile(SystemParam.ByteLen4Pic, i, Calc2.DarkTempFile); ushort[,] pic = wfSapGUI.TransPicDatas(p, m_Buffers.Height, m_Buffers.Width, m_Buffers.PixelDepth); for (int m = 0; m < m_Buffers.Height; m++) { for (int n = 0; n < m_Buffers.Width; n++) { Calc2.y50_dark[m, n] += pic[m, n]; } } if (waitProc.HasBeenCancelled()) { return; } waitProc.SetProcessBar((int)((i + 1))); this.Invoke((EventHandler)(delegate { listView1.Items[14].SubItems[1].Text = (((double)(i + 1) + SystemParam.L) * 100 / count).ToString("F1") + "%"; })); } for (int m = 0; m < m_Buffers.Height; m++) { for (int n = 0; n < m_Buffers.Width; n++) { Calc2.y50_dark[m, n] = Calc2.y50_dark[m, n] / SystemParam.L; } } /************************************************************************/ /* miu_y50 */ /************************************************************************/ Calc2.miu_y50 = 0; for (int m = 0; m < m_Buffers.Height; m++) { for (int n = 0; n < m_Buffers.Width; n++) { Calc2.miu_y50 += Calc2.y50[m, n]; } } Calc2.miu_y50 = Calc2.miu_y50 / m_Buffers.Height / m_Buffers.Width; /************************************************************************/ /* miu_y50_dark */ /************************************************************************/ Calc2.miu_y50_dark = 0; for (int m = 0; m < m_Buffers.Height; m++) { for (int n = 0; n < m_Buffers.Width; n++) { Calc2.miu_y50_dark += Calc2.y50_dark[m, n]; } } Calc2.miu_y50_dark = Calc2.miu_y50_dark / m_Buffers.Height / m_Buffers.Width; /************************************************************************/ /* delta_y50 */ /************************************************************************/ waitProc.SetTitle("相同曝光条件下数据处理---计算明场像素点方差"); waitProc.SetProcessBar(0); Calc2.delta_y50 = new double[m_Buffers.Height, m_Buffers.Width]; for (int i = 0; i < SystemParam.L; i++) { byte[] p = SystemParam.ReadTempFile(SystemParam.ByteLen4Pic, i, Calc2.LightTempFile); ushort[,] pic = wfSapGUI.TransPicDatas(p, m_Buffers.Height, m_Buffers.Width, m_Buffers.PixelDepth); for (int m = 0; m < m_Buffers.Height; m++) { for (int n = 0; n < m_Buffers.Width; n++) { Calc2.delta_y50[m, n] += (pic[m, n] - Calc2.y50[m, n]) * (pic[m, n] - Calc2.y50[m, n]); } } if (waitProc.HasBeenCancelled()) { return; } waitProc.SetProcessBar((int)((i + 1))); this.Invoke((EventHandler)(delegate { listView1.Items[14].SubItems[1].Text = (((double)(i + 1) + SystemParam.L * 2) * 100 / count).ToString("F1") + "%"; })); } for (int m = 0; m < m_Buffers.Height; m++) { for (int n = 0; n < m_Buffers.Width; n++) { Calc2.delta_y50[m, n] = Calc2.delta_y50[m, n] / (SystemParam.L - 1); } } /************************************************************************/ /* delta_y50_dark */ /************************************************************************/ waitProc.SetTitle("相同曝光条件下数据处理---计算暗场像素点方差"); waitProc.SetProcessBar(0); Calc2.delta_y50_dark = new double[m_Buffers.Height, m_Buffers.Width]; for (int i = 0; i < SystemParam.L; i++) { byte[] p = SystemParam.ReadTempFile(SystemParam.ByteLen4Pic, i, Calc2.DarkTempFile); ushort[,] pic = wfSapGUI.TransPicDatas(p, m_Buffers.Height, m_Buffers.Width, m_Buffers.PixelDepth); for (int m = 0; m < m_Buffers.Height; m++) { for (int n = 0; n < m_Buffers.Width; n++) { Calc2.delta_y50_dark[m, n] += (pic[m, n] - Calc2.y50_dark[m, n]) * (pic[m, n] - Calc2.y50_dark[m, n]); } } if (waitProc.HasBeenCancelled()) { this.Invoke((EventHandler)(delegate { textBox1.AppendText("用户终止自动测试\r\n"); return; })); } waitProc.SetProcessBar((int)((i + 1))); this.Invoke((EventHandler)(delegate { listView1.Items[14].SubItems[1].Text = (((double)(i + 1) + SystemParam.L * 3) * 100 / count).ToString("F1") + "%"; })); } for (int m = 0; m < m_Buffers.Height; m++) { for (int n = 0; n < m_Buffers.Width; n++) { Calc2.delta_y50_dark[m, n] = Calc2.delta_y50_dark[m, n] / (SystemParam.L - 1); } } /************************************************************************/ /* delta_y50_stack */ /************************************************************************/ waitProc.SetTitle("相同曝光条件下数据处理---计算PRUN、DSUN、亮点、暗点"); waitProc.SetProcessBar(0); waitProc.SetProcessBarRange(0, 7); Calc2.delta_y50_stack = 0; for (int m = 0; m < m_Buffers.Height; m++) { for (int n = 0; n < m_Buffers.Width; n++) { Calc2.delta_y50_stack += Calc2.delta_y50[m, n]; } } Calc2.delta_y50_stack = Calc2.delta_y50_stack / m_Buffers.Height / m_Buffers.Width; waitProc.SetProcessBarPerformStep(); /************************************************************************/ /* delta_y50_dark_stack */ /************************************************************************/ Calc2.delta_y50_dark_stack = 0; for (int m = 0; m < m_Buffers.Height; m++) { for (int n = 0; n < m_Buffers.Width; n++) { Calc2.delta_y50_dark_stack += Calc2.delta_y50_dark[m, n]; } } Calc2.delta_y50_dark_stack = Calc2.delta_y50_dark_stack / m_Buffers.Height / m_Buffers.Width; waitProc.SetProcessBarPerformStep(); /************************************************************************/ /* S2_y50 */ /************************************************************************/ Calc2.S2_y50 = 0; for (int m = 0; m < m_Buffers.Height; m++) { for (int n = 0; n < m_Buffers.Width; n++) { Calc2.S2_y50 += (Calc2.y50[m, n] - Calc2.miu_y50) * (Calc2.y50[m, n] - Calc2.miu_y50); } } Calc2.S2_y50 = Calc2.S2_y50 / (m_Buffers.Height * m_Buffers.Width - 1); Calc2.S2_y50 = Calc2.S2_y50 - Calc2.delta_y50_stack / SystemParam.L; waitProc.SetProcessBarPerformStep(); /************************************************************************/ /* S2_y50_dark */ /************************************************************************/ Calc2.S2_y50_dark = 0; for (int m = 0; m < m_Buffers.Height; m++) { for (int n = 0; n < m_Buffers.Width; n++) { Calc2.S2_y50_dark += (Calc2.y50_dark[m, n] - Calc2.miu_y50_dark) * (Calc2.y50_dark[m, n] - Calc2.miu_y50_dark); } } Calc2.S2_y50_dark = Calc2.S2_y50_dark / (m_Buffers.Height * m_Buffers.Width - 1); Calc2.S2_y50_dark = Calc2.S2_y50_dark - Calc2.delta_y50_dark_stack / SystemParam.L; waitProc.SetProcessBarPerformStep(); /************************************************************************/ /* DSNU1288 ,PRNU1288 */ /************************************************************************/ Calc2.DSNU1288 = Math.Sqrt(Calc2.S2_y50_dark) / Calc1.OverAllGain_K; Calc2.PRNU1288 = Math.Sqrt(Math.Abs(Calc2.S2_y50 - Calc2.S2_y50_dark)) / (Calc2.miu_y50 - Calc2.miu_y50_dark); this.Invoke((EventHandler)(delegate { listView1.Items[14].SubItems[1].Text = "完成"; listView1.Items[15].SubItems[1].Text = "完成"; listView1.Items[14].SubItems[2].Text = Calc2.DSNU1288.ToString("F2"); listView1.Items[15].SubItems[2].Text = Calc2.PRNU1288.ToString("F4"); textBox1.AppendText("DSNU1288 ,PRNU1288计算完成\r\n"); })); waitProc.SetProcessBarPerformStep(); /************************************************************************/ /* 暗点查找 */ /************************************************************************/ double dP = Calc2.miu_y50 * SystemParam.DarkPointPer / 100; Calc2.DarkPoints = new List <PixelInfo>(); for (int m = 0; m < m_Buffers.Height; m++) { for (int n = 0; n < m_Buffers.Width; n++) { if (Calc2.y50[m, n] < dP) { PixelInfo p = new PixelInfo(); p.row = m; p.col = n; p.y = Calc2.y50[m, n]; Calc2.DarkPoints.Add(p); } } } waitProc.SetProcessBarPerformStep(); this.Invoke((EventHandler)(delegate { listView1.Items[16].SubItems[1].Text = "完成"; textBox1.AppendText("暗点查找完成\r\n"); })); /************************************************************************/ /* 明点查找 */ /************************************************************************/ double lP = Calc2.miu_y50_dark * (100 + SystemParam.LightPointPer) / 100; Calc2.LightPoints = new List <PixelInfo>(); for (int m = 0; m < m_Buffers.Height; m++) { for (int n = 0; n < m_Buffers.Width; n++) { if (Calc2.y50_dark[m, n] > lP) { PixelInfo p = new PixelInfo(); p.row = m; p.col = n; p.y = Calc2.y50_dark[m, n]; Calc2.LightPoints.Add(p); } } } waitProc.SetProcessBarPerformStep(); this.Invoke((EventHandler)(delegate { listView1.Items[17].SubItems[1].Text = "完成"; textBox1.AppendText("亮点查找完成\r\n"); })); }
/// <summary> /// Initialisation with formula is needed for computing original coordinates. /// </summary> public override void Init(Formulas formula) { base.Init(formula); // Original data has to scale such that values fits into float range. Vec3 minPoint = new Vec3(0, 0, 0); Vec3 maxPoint = new Vec3(0, 0, 0); minPoint.X = Double.MaxValue; minPoint.Y = Double.MaxValue; minPoint.Z = Double.MaxValue; maxPoint.X = Double.MinValue; maxPoint.Y = Double.MinValue; maxPoint.Z = Double.MinValue; for (int i = 0; i < pData.Width; i++) { for (int j = 0; j < pData.Height; j++) { PixelInfo pInfo = pData.Points[i, j]; if (pInfo != null) { Vec3 coord = formula.GetTransform(pInfo.Coord.X, pInfo.Coord.Y, pInfo.Coord.Z); if (coord.X < minPoint.X) { minPoint.X = coord.X; } if (coord.Y < minPoint.Y) { minPoint.Y = coord.Y; } if (coord.Z < minPoint.Z) { minPoint.Z = coord.Z; } if (coord.X > maxPoint.X) { maxPoint.X = coord.X; } if (coord.Y > maxPoint.Y) { maxPoint.Y = coord.Y; } if (coord.Z > maxPoint.Z) { maxPoint.Z = coord.Z; } } } } Vec3 center = new Vec3(0, 0, 0); center.X = (maxPoint.X + minPoint.X) / 2.0; center.Y = (maxPoint.Y + minPoint.Y) / 2.0; center.Z = (maxPoint.Z + minPoint.Z) / 2.0; double radius = maxPoint.X - minPoint.X + maxPoint.Y - minPoint.Y + maxPoint.Z - minPoint.Z; for (int i = 0; i < pData.Width; i++) { for (int j = 0; j < pData.Height; j++) { PixelInfo pInfo = pData.Points[i, j]; if (pInfo != null) { FloatPixelInfo floatPixelInfo = new FloatPixelInfo(); floatPixelInfo.Coord.X = (float)((pInfo.Coord.X - center.X) / radius); floatPixelInfo.Coord.Y = (float)((pInfo.Coord.Y - center.Y) / radius); floatPixelInfo.Coord.Z = (float)((pInfo.Coord.Z - center.Z) / radius); floatPixelInfo.AdditionalInfo = pInfo.AdditionalInfo; floatPixelInfo.IsInside = pInfo.IsInside; pInfo.Normal.Normalize(); floatPixelInfo.Normal.X = (float)pInfo.Normal.X; floatPixelInfo.Normal.Y = (float)pInfo.Normal.Y; floatPixelInfo.Normal.Z = (float)pInfo.Normal.Z; _pictureData.Points[i, j] = floatPixelInfo; } } } }
public static Mesh Generate(IImageData resizedImage, double maxZ, double nozzleWidth, double pixelsPerMM, bool invert, IProgress <ProgressStatus> reporter) { // TODO: Move this to a user supplied value double baseThickness = nozzleWidth; // base thickness (in mm) double zRange = maxZ - baseThickness; // Dimensions of image var width = resizedImage.Width; var height = resizedImage.Height; var zScale = zRange / 255; var pixelData = resizedImage.Pixels; Stopwatch stopwatch = Stopwatch.StartNew(); var mesh = new Mesh(); //var rescale = (double)onPlateWidth / imageData.Width; var rescale = 1; var progressStatus = new ProgressStatus(); // Build an array of PixelInfo objects from each pixel // Collapse from 4 bytes per pixel to one - makes subsequent processing more logical and has minimal cost var pixels = pixelData.Where((x, i) => i % 4 == 0) // Interpolate the pixel color to zheight .Select(b => baseThickness + (invert ? 255 - b : b) * zScale) // Project to Vector3 for each pixel at the computed x/y/z .Select((z, i) => new Vector3( i % width * rescale, (i - i % width) / width * rescale * -1, z)) // Project to PixelInfo, creating a mirrored Vector3 at z0, paired together and added to the mesh .Select(vec => { var pixelInfo = new PixelInfo() { Top = vec, Bottom = new Vector3(vec.X, vec.Y, 0) }; mesh.Vertices.Add(pixelInfo.Top); mesh.Vertices.Add(pixelInfo.Bottom); return(pixelInfo); }).ToArray(); Console.WriteLine("ElapsedTime - PixelInfo Linq Generation: {0}", stopwatch.ElapsedMilliseconds); stopwatch.Restart(); // Select pixels along image edges var backRow = pixels.Take(width).Reverse().ToArray(); var frontRow = pixels.Skip((height - 1) * width).Take(width).ToArray(); var leftRow = pixels.Where((x, i) => i % width == 0).ToArray(); var rightRow = pixels.Where((x, i) => (i + 1) % width == 0).Reverse().ToArray(); int k, nextJ, nextK; var notificationInterval = 100; var workCount = (resizedImage.Width - 1) * (resizedImage.Height - 1) + (height - 1) + (width - 1); double workIndex = 0; // Vertical faces: process each row and column, creating the top and bottom faces as appropriate for (int i = 0; i < resizedImage.Height - 1; ++i) { var startAt = i * width; // Process each column for (int j = startAt; j < startAt + resizedImage.Width - 1; ++j) { k = j + 1; nextJ = j + resizedImage.Width; nextK = nextJ + 1; // Create north, then south face mesh.CreateFace(new [] { pixels[k].Top, pixels[j].Top, pixels[nextJ].Top, pixels[nextK].Top }); mesh.CreateFace(new [] { pixels[j].Bottom, pixels[k].Bottom, pixels[nextK].Bottom, pixels[nextJ].Bottom }); workIndex++; if (workIndex % notificationInterval == 0) { progressStatus.Progress0To1 = workIndex / workCount; reporter.Report(progressStatus); } } } // Side faces: East/West for (int j = 0; j < height - 1; ++j) { //Next row k = j + 1; // Create east, then west face mesh.CreateFace(new [] { leftRow[k].Top, leftRow[j].Top, leftRow[j].Bottom, leftRow[k].Bottom }); mesh.CreateFace(new [] { rightRow[k].Top, rightRow[j].Top, rightRow[j].Bottom, rightRow[k].Bottom }); workIndex++; if (workIndex % notificationInterval == 0) { progressStatus.Progress0To1 = workIndex / workCount; reporter.Report(progressStatus); } } // Side faces: North/South for (int j = 0; j < width - 1; ++j) { // Next row k = j + 1; // Create north, then south face mesh.CreateFace(new [] { frontRow[k].Top, frontRow[j].Top, frontRow[j].Bottom, frontRow[k].Bottom }); mesh.CreateFace(new [] { backRow[k].Top, backRow[j].Top, backRow[j].Bottom, backRow[k].Bottom }); workIndex++; if (workIndex % notificationInterval == 0) { progressStatus.Progress0To1 = workIndex / workCount; reporter.Report(progressStatus); } } Console.WriteLine("ElapsedTime - Face Generation: {0}", stopwatch.ElapsedMilliseconds); return(mesh); }
public ObjectPoints(PixelInfo Type) { this.Type = Type; this.Points = new List <Point>(); }