private void CalcDsc(int id) { RectangleF rectFRoiRecord; PointF[] rectFRoiPoints; Size rectRoiSize; RectangleF rectFBlkRecord; Rectangle rectBlkRecord; PointF[] rectFBlkPoints; Size rectBlkSize; string fileName = Path.Combine(fileDir + "-", Convert.ToString(id));; rectFRoiRecord = RectConverter.ConvertFromDrawRect(roi[id], slide[id], id); rectFRoiPoints = RectConverter.GetAllPointsByRectangleF(rectFRoiRecord, amp); rectRoiSize = RectConverter.GetStepsByRectangleF(rectFRoiRecord, amp); rectBlkRecord = rectsBLK[id]; rectFBlkRecord = RectConverter.ConvertFromDrawRect(rectsBLK[id], slide[id], id); // Cal two Points. rectFBlkPoints = new PointF[2]; rectFBlkPoints[0] = new PointF(rectFBlkRecord.Left - rectFBlkRecord.Width / 3, rectFBlkRecord.Top + rectFBlkRecord.Height / 2); rectFBlkPoints[1] = new PointF(rectFBlkRecord.Left - rectFBlkRecord.Width * 2 / 3, rectFBlkRecord.Top + rectFBlkRecord.Height / 2); rectBlkSize = RectConverter.GetStepsByRectangleF(rectFBlkRecord, amp); roi[id] = RectConverter.ConvertToDrawRect(roi[id], slide[id], id); GenerateTaskDesc(fileName, roi[id], rectFRoiRecord, rectFRoiPoints, rectRoiSize, rectBlkRecord, rectFBlkRecord, rectFBlkPoints, rectBlkSize, id); }
private void btnImportTask_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.InitialDirectory = colorconfig.location; ofd.Filter = "dsc任务描述文件|*.dsc|所有文件|*.*"; ofd.Multiselect = true; ofd.ValidateNames = true; ofd.CheckPathExists = true; ofd.CheckFileExists = true; // clear status broi[0] = broi[1] = broi[2] = broi[3] = false; isimporttask[0] = isimporttask[1] = isimporttask[2] = isimporttask[3] = false; tdscs[0] = tdscs[1] = tdscs[2] = tdscs[3] = null; tdscs_storepath[0] = tdscs_storepath[1] = tdscs_storepath[2] = tdscs_storepath[3] = @""; GC.Collect(); if (ofd.ShowDialog() == DialogResult.OK) { Refresh(); foreach (var filename in ofd.FileNames) { FullSlideScanHelper.RectConverter.TaskDesc tdsc = RectConverter.RestoreTaskDesc(filename); tdscs[tdsc.slideid] = tdsc; tdscs_storepath[tdsc.slideid] = filename; broi[tdsc.slideid] = true; //setnames[tdsc.slideid] = Path.GetFileNameWithoutExtension(filename); rectsROI[tdsc.slideid] = tdsc.rectRoi; rectsBLK[tdsc.slideid] = tdsc.rectBlk; isimporttask[tdsc.slideid] = true; RefreshUI(); rect = rectsROI[tdsc.slideid]; idxRect = tdsc.slideid; RectangleF debugrectf = tdsc.rectRoiF; SizeF sizef = debugrectf.Size; tp_lu = debugrectf.Location; tp_ru = new PointF(debugrectf.Left - sizef.Width, debugrectf.Top); tp_ld = new PointF(debugrectf.Left, debugrectf.Top - sizef.Height); tp_rd = new PointF(debugrectf.Left - sizef.Width, debugrectf.Top - sizef.Height); label6.Text = tp_lu.ToString(); label7.Text = tp_ru.ToString(); label8.Text = tp_ld.ToString(); label9.Text = tp_rd.ToString(); int x_total_steps = (int)((tp_ld.X - tp_rd.X) / x_step); int y_total_steps = (int)((tp_ld.Y - tp_lu.Y) / y_step); label10.Text = "size: (" + Math.Abs(x_total_steps).ToString() + ", " + Math.Abs(y_total_steps).ToString() + ")"; } } }
public void CanConvertTo() { RectConverter r = new RectConverter(); Assert.IsTrue(r.CanConvertTo(typeof(string))); Assert.IsFalse(r.CanConvertTo(typeof(Rect))); Assert.IsFalse(r.CanConvertTo(typeof(Size))); }
private void btntestmove_Click(object sender, EventArgs e) { RectangleF testmoveRF = RectConverter.ConvertFromDrawRect(rect, idxRect); PointF testmovePt = RectConverter.GetAllPointsByRectangleF(testmoveRF, amp)[0]; double testmovezp = TangoController.TangoGetZPos(); TangoController.TangoMoveAbs(1, testmovePt.X, testmovePt.Y, testmovezp, 0, true); }
public void ConvertTo() { RectConverter r = new RectConverter(); Rect rect = new Rect(0, 0, 1, 2); object o = r.ConvertTo(null, CultureInfo.InvariantCulture, rect, typeof(string)); Assert.AreEqual(typeof(string), o.GetType()); Assert.AreEqual("0,0,1,2", (string)o); }
static GridUnitExtension() { _dipMultiplier = DipHelper.GetDipMultiplier(); _thicknessConverter = new ThicknessConverter(); _cornerRadiusConverter = new CornerRadiusConverter(); _sizeConverter = new SizeConverter(); _pointConverter = new PointConverter(); _rectConverter = new RectConverter(); _gridLengthConverter = new GridLengthConverter(); }
public void ConvertTo() { RectConverter r = new RectConverter(); Rect rect = new Rect(0, 0, 1, 2); object o = r.ConvertTo(rect, typeof(string)); Assert.AreEqual(typeof(string), o.GetType()); Assert.AreEqual("0,0,1,2", (string)o); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { RectConverter rc = new RectConverter(); if (value == null) { return(new Rect(0, 0, 0, 0)); } return(rc.ConvertFromString((String)value)); }
private static bool TryParseRect(string value, out Rect rect) { var converter = new RectConverter(); try { rect = (Rect?)converter.ConvertFromInvariantString(value) ?? new Rect(); return(true); } catch { rect = new Rect(); return(false); } }
public void ConvertFrom() { RectConverter r = new RectConverter(); object or = r.ConvertFrom("1, 2, 3, 4"); Assert.AreEqual(typeof(Rect), or.GetType()); Assert.AreEqual(new Rect(1, 2, 3, 4), or); or = r.ConvertFrom("Empty"); Assert.AreEqual(typeof(Rect), or.GetType()); Assert.IsTrue(((Rect)or).IsEmpty); }
// Applies the selected options to the image brush. private void UpdateBrush(object sender, RoutedEventArgs args) { try { myImageBrush.ImageSource = (_selectedButton.Content as Image).Source; myImageBrush.Stretch = (Stretch)Enum.Parse(typeof(Stretch), (string)stretchSelector.SelectedItem); myImageBrush.AlignmentX = (AlignmentX)Enum.Parse(typeof(AlignmentX), (string)horizontalAlignmentSelector.SelectedItem); myImageBrush.AlignmentY = (AlignmentY)Enum.Parse(typeof(AlignmentY), (string)verticalAlignmentSelector.SelectedItem); myImageBrush.TileMode = (TileMode)Enum.Parse(typeof(TileMode), (string)tileSelector.SelectedItem); myImageBrush.ViewportUnits = (BrushMappingMode) Enum.Parse(typeof(BrushMappingMode), (string)viewportUnitsSelector.SelectedItem); myImageBrush.ViewboxUnits = (BrushMappingMode)Enum.Parse(typeof(BrushMappingMode), (string)viewboxUnitsSelector.SelectedItem); var myRectConverter = new RectConverter(); var parseString = viewportEntry.Text; if (!string.IsNullOrEmpty(parseString)) { myImageBrush.Viewport = (Rect)myRectConverter.ConvertFromString(parseString); } else { myImageBrush.Viewport = Rect.Empty; viewportEntry.Text = "Empty"; } parseString = viewboxEntry.Text; if (!string.IsNullOrEmpty(parseString) && parseString.ToLower() != "(auto)") { myImageBrush.Viewbox = (Rect)myRectConverter.ConvertFromString(parseString); } else { viewboxEntry.Text = "Empty"; myImageBrush.Viewbox = Rect.Empty; } } catch (InvalidOperationException invalidOpEx) { MessageBox.Show("Invalid Viewport or Viewbox. " + invalidOpEx); } catch (FormatException formatEx) { MessageBox.Show("Invalid Viewport or Viewbox. " + formatEx); } }
private void pictureBox1_MouseUp(object sender, MouseEventArgs e) { if (isStartPointValid) { blnDraw = false; if (rectSel == 1) { rectsROI[idxRect] = rect; } else if (rectSel == 2) { rectsBLK[idxRect] = rect; } //rectsROI[idxRect] = rect; RectangleF debugrectf = RectConverter.ConvertFromDrawRect(rect, idxRect); SizeF sizef = debugrectf.Size; tp_lu = debugrectf.Location; tp_ru = new PointF(debugrectf.Left - sizef.Width, debugrectf.Top); tp_ld = new PointF(debugrectf.Left, debugrectf.Top - sizef.Height); tp_rd = new PointF(debugrectf.Left - sizef.Width, debugrectf.Top - sizef.Height); label6.Text = tp_lu.ToString(); label7.Text = tp_ru.ToString(); label8.Text = tp_ld.ToString(); label9.Text = tp_rd.ToString(); int x_total_steps = (int)((tp_ld.X - tp_rd.X) / x_step); int y_total_steps = (int)((tp_ld.Y - tp_lu.Y) / y_step); label10.Text = "size: (" + Math.Abs(x_total_steps).ToString() + ", " + Math.Abs(y_total_steps).ToString() + ")"; using (Graphics g = Graphics.FromHwnd(this.pictureBox1.Handle)) { foreach (Rectangle _rect in rectsROI) { g.DrawRectangle(new Pen(Color.Red, 4), _rect); } foreach (Rectangle _rect in rectsBLK) { g.DrawRectangle(new Pen(Color.Blue, 4), _rect); } } InfoPanelUtil.MyConsoleWrite(ref thisForm, "Done"); } }
public void ConvertFrom_negative() { RectConverter r = new RectConverter(); r.ConvertFrom("1, 2, -4, -5"); }
public void ConvertFrom_size() { RectConverter r = new RectConverter(); r.ConvertFrom(new Size(10, 20)); }
private void btnStartScan_Click(object sender, EventArgs e) { if (isSetName) { rectFRoiTotalPoints = 0; if (MessageBox.Show(generateConfirmMessage(), "确认", MessageBoxButtons.YesNo) == DialogResult.No) { } else { RectangleF rectFRoiRecord; Rectangle rectRoiRecord; PointF[] rectFRoiPoints; Size rectRoiSize; RectangleF rectFBlkRecord; Rectangle rectBlkRecord; PointF[] rectFBlkPoints; Size rectBlkSize; for (int i = 0; i < 4; i++) { if (broi[i]) { //if (isimporttask[i]) //{ // rectFRoiTotalPoints += tdscs[i].rectRoiSize.Width * tdscs[i].rectRoiSize.Height; // rectFRoiTotalPoints += tdscs[i].rectBlkPts.Length; // rectRoiRecord = rectsROI[i]; // rectFRoiRecord = RectConverter.ConvertFromDrawRect(rectsROI[i], i); // rectFRoiPoints = RectConverter.GetAllPointsByRectangleF(rectFRoiRecord, amp); // rectRoiSize = RectConverter.GetStepsByRectangleF(rectFRoiRecord, amp); // rectFRoiTotalPoints += rectRoiSize.Width * rectRoiSize.Height; // rectBlkRecord = rectsBLK[i]; // rectFBlkRecord = RectConverter.ConvertFromDrawRect(rectsBLK[i], i); // // Cal two Points. // rectFBlkPoints = new PointF[2]; // rectFBlkPoints[0] = new PointF(rectFBlkRecord.Left - rectFBlkRecord.Width / 3, rectFBlkRecord.Top + rectFBlkRecord.Height / 2); // rectFBlkPoints[1] = new PointF(rectFBlkRecord.Left - rectFBlkRecord.Width * 2 / 3, rectFBlkRecord.Top + rectFBlkRecord.Height / 2); // rectBlkSize = RectConverter.GetStepsByRectangleF(rectFBlkRecord, amp); // rectFRoiTotalPoints += rectFBlkPoints.Length; // Temp = RectConverter.GenerateTaskDesc(colorconfig.location, setnames[i], // rectRoiRecord, rectFRoiRecord, rectFRoiPoints, rectRoiSize, // rectBlkRecord, rectFBlkRecord, rectFBlkPoints, rectBlkSize, // i); //} //else //{ rectRoiRecord = rectsROI[i]; rectFRoiRecord = RectConverter.ConvertFromDrawRect(rectsROI[i], i); rectFRoiPoints = RectConverter.GetAllPointsByRectangleF(rectFRoiRecord, amp); rectRoiSize = RectConverter.GetStepsByRectangleF(rectFRoiRecord, amp); rectFRoiTotalPoints += rectRoiSize.Width * rectRoiSize.Height; rectBlkRecord = rectsBLK[i]; rectFBlkRecord = RectConverter.ConvertFromDrawRect(rectsBLK[i], i); // Cal two Points. rectFBlkPoints = new PointF[2]; rectFBlkPoints[0] = new PointF(rectFBlkRecord.Left - rectFBlkRecord.Width / 3, rectFBlkRecord.Top + rectFBlkRecord.Height / 2); rectFBlkPoints[1] = new PointF(rectFBlkRecord.Left - rectFBlkRecord.Width * 2 / 3, rectFBlkRecord.Top + rectFBlkRecord.Height / 2); rectBlkSize = RectConverter.GetStepsByRectangleF(rectFBlkRecord, amp); rectFRoiTotalPoints += rectFBlkPoints.Length; Temp = RectConverter.GenerateTaskDesc(colorconfig.location, setnames[i], rectRoiRecord, rectFRoiRecord, rectFRoiPoints, rectRoiSize, rectBlkRecord, rectFBlkRecord, rectFBlkPoints, rectBlkSize, i); //} } } this.Close(); } } else { MessageBox.Show("请先设置扫描玻片的名字"); } }
public static void SuperDebug(ScratchControl ctl) { Grid grid = null; if (ctl.FileNameInCode == null && ctl.FileNameInImage == null && ctl.FileNameInStl == null && ctl.FileNameInSvg == null) { Console.WriteLine("Must have FileNameIn type."); return; } if (ctl.FileNameInSvg != null) { Console.WriteLine("SVG Input filename: {0}", ctl.FileNameInSvg); string codeString = Svg2Gly.ConvertSvg2Gly(ctl.FileNameInSvg); Console.WriteLine("SVG:\n" + codeString); Code code = RasterLib.RasterApi.CreateCode(codeString); if (ctl.Resize != null) { code = RasterLib.RasterApi.CodeToRescaledCode(code, ctl.Resize[0], ctl.Resize[1], ctl.Resize[2]); } Console.WriteLine("Code: {0}\n", codeString); grid = RasterLib.RasterApi.CodeToGrid(code); } else if (ctl.FileNameInStl != null) { grid = RasterLib.RasterApi.CreateGrid(64, 64, 64, 4); Console.WriteLine("STL Input filename: {0}", ctl.FileNameInStl); //Load the triangles from the STL file and reduce to a unit 1x1x1 size Triangles triangles = RasterLib.RasterApi.StlToTriangles(ctl.FileNameInStl); triangles.ReduceToUnit(); Console.WriteLine("Triangle count: {0}", triangles.Count); //Render the triangles to the grid, will autosize to grid size RasterLib.RasterApi.Renderer.RenderTrianglesToGrid(triangles, grid); } else if (ctl.FileNameInImage != null) { Grid gridImg = GraphicsApi.FileToGrid(ctl.FileNameInImage); GridContext gc = new GridContext(gridImg); RasterLib.RasterApi.Painter.FlipY(gc); int div = 63;// 31;// 15; grid = RasterLib.RasterApi.CreateGrid(gridImg.SizeX, 255 / div + 1, gridImg.SizeY, 4); Console.WriteLine("Extruding"); Extrusion(grid, gridImg, div); Console.WriteLine("Rendering"); Grid gridIsometricScaledQuick = RasterLib.RasterApi.Renderer.RenderIsometricCellsScaled(grid, 0, 0, 0, 0, 4, 4); Console.WriteLine("Saving"); GraphicsApi.SaveFlatPng(ctl.FileNameOutIsometric, gridIsometricScaledQuick); Console.WriteLine("Saved"); } else if (ctl.FileNameInCode != null) { string codeString = RasterLib.RasterApi.ReadGlyc(ctl.FileNameInCode).Replace(';', '\n'); Code code = RasterLib.RasterApi.CreateCode(codeString); Console.WriteLine("Code: {0}\n", codeString); Codename codename = RasterLib.RasterApi.CodeToCodename(code); Console.WriteLine("Codename: {0}\n", codename); if (ctl.OutputTokens) { TokenList glyphTokens = RasterLib.RasterApi.CodeToTokens(code); string tokenDesc = "Tokens:\n" + glyphTokens + "\n"; Console.WriteLine(tokenDesc); } if (ctl.Resize != null) { code = RasterLib.RasterApi.CodeToRescaledCode(code, ctl.Resize[0], ctl.Resize[1], ctl.Resize[2]); } grid = RasterLib.RasterApi.CodeToGrid(code); Console.WriteLine("Grid: {0}\n", grid); if (ctl.FileNameOutOrthogonalAnimated || ctl.FileNameOutIsometricAnimated) { ControlAnimator.DoAnimation(ctl, code.codeString, codename.ToString()); } } //DownSolver ds = new GeneralLibrary.DownSolver(codeString); if (ctl.OutputBytes && grid != null) { string bytesDesc = RasterLib.RasterApi.BytesToString(grid.CloneData()); Console.WriteLine("GridBytes:\n{0}\n", bytesDesc); } RectList rects = RasterLib.RasterApi.GridToRects(grid); if (ctl.OutputRectangles)//rects { Console.WriteLine("Rects: {0}\n{1}", rects.Count, rects); RasterLib.RasterApi.BuildCircuit(rects, true); string serialized = RasterLib.RasterApi.RectsToSerializedRectsLimit255(rects).SerializedData; Console.WriteLine("Serialized Rects: (len={0})\n{1}\n", serialized.Length, serialized); RasterLib.RasterApi.SaveFlatText("..\\..\\foo.txt", serialized); //Clipboard.SetText(serialized); SerializedRects serializedRects = new SerializedRects(serialized); RectList rectsDecoded = RectConverter.SerializedRectsToRects(serializedRects); int count = 0; Console.WriteLine("# of Decoded Rects = {0}", rectsDecoded.Count); foreach (Rect rect in rectsDecoded) { Console.WriteLine(count + " : " + rect); count++; } } if (ctl.OutputRenderedAscii) { Console.WriteLine("2d view:\n{0}", RasterLib.RasterApi.Renderer.GridToHexDescription(grid)); Console.WriteLine("3d view:\n{0}", RasterLib.RasterApi.Renderer.GridTo3DDescription(grid, 0, 0, 0)); } if (ctl.OutputSceneGraph) { Scene scene = RasterLib.RasterApi.RectsToScene(rects); Console.WriteLine("Scene: {0}", scene); QuadList quads = RasterLib.RasterApi.RectsToQuads(rects); Console.WriteLine("Quads: {0}", quads); Triangles triangles = RasterLib.RasterApi.QuadsToTriangles(quads); Console.WriteLine("Triangles: {0}", triangles); } if (ctl.FileNameOutStl != null) { ControlStl.Control(ctl, rects); } if (ctl.FileNameOutOrthogonal != null) { Console.WriteLine("Orthogonal Rendering.."); Grid gridOrthogonal = RasterLib.RasterApi.Renderer.RenderObliqueCells(grid); GraphicsApi.SaveFlatPng(ctl.FileNameOutOrthogonal, gridOrthogonal); } if (ctl.FileNameOutIsometric != null) { Console.WriteLine("Isometric Rendering.."); if (ctl.IsometricCellWidth < 1) { ctl.IsometricCellWidth = 1; } if (ctl.IsometricCellHeight < 1) { ctl.IsometricCellHeight = 1; } Grid gridIsometricScaled = RasterLib.RasterApi.Renderer.RenderIsometricCellsScaled(grid, ctl.IsometricBgRgba[0], ctl.IsometricBgRgba[1], ctl.IsometricBgRgba[2], ctl.IsometricBgRgba[3], ctl.IsometricCellWidth, ctl.IsometricCellHeight); GraphicsApi.SaveFlatPng(ctl.FileNameOutIsometric, gridIsometricScaled); } Console.WriteLine(); }
//"../../../../Glyph Cores/Nexus.glyc" -sr static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine("Usage : GlyView <filename> "); Console.WriteLine(" Output types:"); Console.WriteLine(" -c : display code "); Console.WriteLine(" -r : display rects "); Console.WriteLine(" -sr : display serialized rects "); Console.WriteLine(" -q : display quads "); Console.WriteLine(" -t : display triangles "); Console.WriteLine(" -sg : display scenegraph"); Console.WriteLine(" -ci : display circuit"); return; } string filename = args[0]; Options options = new Options(); for (int i = 0; i < args.Length; i++) { if (args[i] == "-c") { options.displayCode = true; } if (args[i] == "-r") { options.displayRects = true; } if (args[i] == "-sr") { options.displaySerializedRects = true; } if (args[i] == "-q") { options.displayQuads = true; } if (args[i] == "-t") { options.displayTriangles = true; } if (args[i] == "-sg") { options.displaySceneGraph = true; } if (args[i] == "-ci") { options.displayCircuit = true; } } string codeString = RasterLib.RasterApi.ReadGlyc(filename); Code code = new Code(codeString); if (options.displayCode) { Console.WriteLine("Code: " + codeString); } Grid grid = RasterLib.RasterApi.CodeToGrid(code); if (grid != null) { //string bytesDesc = RasterLib.RasterApi.BytesToString(grid.CloneData()); //Console.WriteLine("GridBytes:\n{0}\n", bytesDesc); } RectList rects = RasterLib.RasterApi.GridToRects(grid); //rects { if (options.displayRects) { Console.WriteLine("Rects: {0}\n{1}", rects.Count, rects); } RasterLib.RasterApi.BuildCircuit(rects, options.displayCircuit); string serialized = RasterLib.RasterApi.RectsToSerializedRectsLimit255(rects).SerializedData; if (options.displaySerializedRects) { Console.WriteLine("{0}\n", serialized); } //Console.WriteLine("Serialized Rects: (len={0})\n{1}\n", serialized.Length, serialized); SerializedRects serializedRects = new SerializedRects(serialized); RectList rectsDecoded = RectConverter.SerializedRectsToRects(serializedRects); } //if (ctl.OutputRenderedAscii) { //Console.WriteLine("2d view:\n{0}", RasterLib.RasterApi.Renderer.GridToHexDescription(grid)); //Console.WriteLine("3d view:\n{0}", RasterLib.RasterApi.Renderer.GridTo3DDescription(grid, 0, 0, 0)); } //if (ctl.OutputSceneGraph) { Scene scene = RasterLib.RasterApi.RectsToScene(rects); if (options.displaySceneGraph) { Console.WriteLine("Scene: {0}", scene); } QuadList quads = RasterLib.RasterApi.RectsToQuads(rects); if (options.displayQuads) { Console.WriteLine("Quads: {0}", quads); } Triangles triangles = RasterLib.RasterApi.QuadsToTriangles(quads); if (options.displayTriangles) { Console.WriteLine("Triangles: {0}", triangles); } } }