private RenderContext2D(ICamera camera) { this.camera = camera; rectangle = new RectangleModel(1, 1); circle = new CircleModel(1); }
private Tuple <bool, IList <RectangleModel <Bitmap> > > TemplateComparsion(Bitmap source, Bitmap template, double threshold) { var src = source.ToImageGrayByte(); var tmpl = template.ToImageGrayByte(); using (var result = src.MatchTemplate(tmpl, TemplateMatchingType.CcoeffNormed)) { result.MinMax(out var _, out var maxValues, out var minLocations, out var maxLocations); if (minLocations.Length != maxLocations.Length) { throw new ArgumentException(); } var collection = new List <RectangleModel <Bitmap> >(); foreach (var point in maxLocations) { var rect = new RectangleModel <Bitmap>(leftTop: point, height: template.Height, width: template.Width); rect.SetImage(tmpl.Bitmap); collection.Add(rect); } return(new Tuple <bool, IList <RectangleModel <Bitmap> > >(maxValues[0] > threshold, collection)); } }
private IList <RectangleModel> Checker(Bitmap first, Bitmap second, IProgress <int> progress, double threshold, bool equal = false) { var matrix = WorkScreen.GetMatrix(first); var source = second; var list = new List <RectangleModel>(); for (int i = 0; i < matrix.GetLength(0); i++) { for (int j = 0; j < matrix.GetLength(1); j++) { var template = matrix[i, j].Image; var result = IsIncludes(source, template, threshold); var procent = (i * matrix.GetLength(1) + j) * 101 / (matrix.GetLength(0) * matrix.GetLength(1)); if (result == equal) { var rect = new RectangleModel <Bitmap>(leftTop: matrix[i, j].LeftTop, height: template.Height, width: template.Width); rect.SetImage(matrix[i, j].Image); list.Add(rect); } progress.Report(procent); } } progress.Report(0); return(list); }
/// <summary> /// Create the primitives to be drawed /// X ---- Width /// Z ---- Height /// </summary> public override void Initialize( ) { if (rectangleMesh != null) { rectangleMesh.Dispose(); } model = base.source as RectangleModel; //Create the mesh rectangleMesh = new AutoMesh(d3d, Mesh.Box(d3d.Dx, model.Width, model.Height, 0.0f)); //Get the bounding box rectangleMesh.BoundingBox(out minVector3, out maxVector3); minVector3.TransformCoordinate(model.WorldMatrix); maxVector3.TransformCoordinate(model.WorldMatrix); Vector3 minClone = minVector3; Vector3 maxClone = maxVector3; minVector3.X = minClone.X < maxClone.X ? minClone.X : maxClone.X; minVector3.Y = minClone.Y < maxClone.Y ? minClone.Y : maxClone.Y; minVector3.Z = minClone.Z < maxClone.Z ? minClone.Z : maxClone.Z; maxVector3.X = minClone.X < maxClone.X ? maxClone.X : minClone.X; maxVector3.Y = minClone.Y < maxClone.Y ? maxClone.Y : minClone.Y; maxVector3.Z = minClone.Z < maxClone.Z ? maxClone.Z : minClone.Z; model.MaxVector3 = maxVector3; model.MinVector3 = minVector3; }
public static RectangleModel GetRectangleModel(string input) { RectangleModel model = new RectangleModel(); string[] values = input.Split(' '); string code = values[0].ToUpper(); uint x1, y1, x2, y2; if (values.Length != 5 || code != "R") { throw new ArgumentOutOfRangeException("Rectangle dimensions are not valid!"); } if (uint.TryParse(values[1], out x1) && x1 > 0 && uint.TryParse(values[2], out y1) && y1 > 0 && uint.TryParse(values[3], out x2) && x2 > 0 && uint.TryParse(values[4], out y2) && y2 > 0) { model.Code = code; model.X1 = x1; model.Y1 = y1; model.X2 = x2; model.Y2 = y2; } else { throw new ArgumentOutOfRangeException("Rectangle dimensions must be positive integers!"); } return(model); }
private static void DrawRectangleFilling(VertexHelper vh, RectangleModel model, GeometryStyleAsset.GeometryStyleSet styleSet) { var p0 = CoordinateTupleToVector3(model.P0); var p1 = CoordinateTupleToVector3(model.P1); ColorAsset color; switch (model.Color) { case GeometryStyleAsset.GeometryColor.Black: color = model.IsBaked ? styleSet.DefaultStyle.FillColorBlack : styleSet.DrawingStyle.FillColorBlack; break; case GeometryStyleAsset.GeometryColor.Grey: color = model.IsBaked ? styleSet.DefaultStyle.FillColorGrey : styleSet.DrawingStyle.FillColorGrey; break; case GeometryStyleAsset.GeometryColor.White: default: color = model.IsBaked ? styleSet.DefaultStyle.FillColorWhite : styleSet.DrawingStyle.FillColorWhite; break; } var p0World = p0; var p1World = new Vector3(p1.x, 0f, p0.z); var p2World = p1; var p3World = new Vector3(p0.x, 0f, p1.z); UIMeshGenerationHelper.AddQuadrilateral(vh, (p0World, p1World, p2World, p3World), color.Value); }
public override GeometryModel CreateSourceGeometryModel() { RectangleModel rectangle = new RectangleModel(); float width = this.width.ChangeUnit(Parent.Parent.Environment.DefaultLengthUnit); float height = this.height.ChangeUnit(Parent.Parent.Environment.DefaultLengthUnit); rectangle.Width = Math.Abs(width); rectangle.Height = Math.Abs(height); Vector3 centerVector3 = this.refPoint.GetDirectXVector(Parent.Parent.Environment.DefaultLengthUnit); Matrix worldMatrix = Matrix.Identity; Vector3 eoStart = Vector3.Empty; Vector3 eoEnd = Vector3.Empty; switch (this.alineAxis) { case Axis.X: eoStart = centerVector3 + new Vector3(0, 0, height); eoEnd = new Vector3(GeometryModel.DefaultEOLineLength, 0, 0); centerVector3.Add(new Vector3(0, width / 2.0f, height / 2.0f)); worldMatrix = Matrix.RotationX((float)Math.PI / 2.0f) * Matrix.RotationZ((float)Math.PI / 2.0f) * Matrix.Translation(centerVector3); break; case Axis.Y: eoStart = centerVector3 + new Vector3(height, 0, 0); eoEnd = new Vector3(0, GeometryModel.DefaultEOLineLength, 0); centerVector3.Add(new Vector3(height / 2.0f, 0, width / 2.0f)); worldMatrix = Matrix.RotationY((float)Math.PI / 2.0f) * Matrix.RotationZ((float)Math.PI / 2.0f) * Matrix.Translation(centerVector3); break; case Axis.Z: eoStart = centerVector3 + new Vector3(0, height, 0); eoEnd = new Vector3(0, 0, GeometryModel.DefaultEOLineLength); centerVector3.Add(new Vector3(width / 2.0f, height / 2.0f, 0)); worldMatrix = Matrix.Translation(centerVector3); break; } rectangle.WorldMatrix = worldMatrix; rectangle.CenterVector3 = centerVector3; rectangle.EOStart = eoStart; rectangle.EOEnd = eoEnd; rectangle.AlineAxis = this.alineAxis; return(rectangle); }
public static RectangleModel StartNewRectangle(Vec <Coordinate> focusPosition, GeometryStyleAsset.GeometryColor color) { var nextRectangle = new RectangleModel { P0 = focusPosition, Color = color }; focusPosition.ForEach(c => c.AddAttachedGeometry(nextRectangle)); return(nextRectangle); }
public void SetSerialization(Serialization serialization) { coordinateSystem.SetSerialization(serialization.cs); var axes = coordinateSystem.Axes; var coordinates = new Vec <List <Coordinate> >(axis => axes[axis].Coordinates); geometries = new List <GeometryModel>(); geometries.AddRange(serialization.points.Select(p => PointModel.FromSerialization(p, coordinates))); geometries.AddRange(serialization.lines.Select(l => LineModel.FromSerialization(l, coordinates))); geometries.AddRange(serialization.rectangles.Select(r => RectangleModel.FromSerialization(r, coordinates))); }
public void AddRectangle(RectangleModel rectangle) { if (!_rectangles.Any(r => r.Contains(rectangle))) { _rectangles.RemoveAll(r => rectangle.Contains(r)); _rectangles.Add(rectangle); var rectangleArea = rectangle.Area; if (MaximalArea < rectangleArea) { MaximalArea = rectangleArea; } } }
private IModel ModelTypeTo(string model) { IModel model2 = new IModel(); switch (model) { case "ItemLine": { LineModel line = new LineModel(); return(line); } case "ItemEllipse": { EllipsModel ellipsModel = new EllipsModel(); return(ellipsModel); } case "ItemCursor": { CursorModel cursor = new CursorModel(); return(cursor); } case "ItemRectangle": { RectangleModel rectangle = new RectangleModel(); return(rectangle); } case "ItemAdd": { AddModel add = new AddModel(); return(add); } case "ItemAddInButton": { AddInButtonModel addInButton = new AddInButtonModel(); return(addInButton); } case "RemoveListSprites": { AddSprites.Create create = new AddSprites.Create(); } break; } return(model2); }
private static List <RectangleModel> GetRectangles(JArray objects) { List <RectangleModel> rectangles = new List <RectangleModel>(); //Loop each children (if more than 1 license plate) foreach (JObject obj in objects.Children()) { try { JObject vehicleAnnotation = (JObject)obj["vehicleAnnotation"]; JObject licencePlate = (JObject)vehicleAnnotation["licenseplate"]; if (licencePlate != null) { JObject bounding = (JObject)licencePlate["bounding"]; JArray vertices = (JArray)bounding["vertices"]; List <int> xcoord = new List <int>(); List <int> ycoord = new List <int>(); //loop each coordinate (x,y) foreach (JObject vert in vertices.Children()) { string x = vert["x"].Value <string>(); string y = vert["y"].Value <string>(); xcoord.Add(Convert.ToInt32(x)); ycoord.Add(Convert.ToInt32(y)); } RectangleModel rect1 = new RectangleModel { ObjectType = ObjectTypeEnum.Licenseplate, x = xcoord.Min(), y = ycoord.Min(), height = ycoord.Max() - ycoord.Min(), width = xcoord.Max() - xcoord.Min() }; rectangles.Add(rect1); } } catch (Exception ex) { //TODO throw new Exception(ex.Message, ex); } } return(rectangles); }
public static Bitmap GetBitmapFromProcess(string name) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException(name); } IntPtr handle = FindWindow(null, name); GetWindowRect(handle, out var rect); var gameScreenRect = new RectangleModel(leftTop: new Point(rect.Left + 2, rect.Top + 2), height: rect.Bottom - rect.Top - 4, width: rect.Right - rect.Left - 4); var gameBmp = GetBitmapFromScreen(gameScreenRect); return(gameBmp); }
/// <summary> /// Obtiene un rectángulo a partir de una cadena de coordenada Top, Left, Width, Height /// </summary> internal RectangleModel GetRectangle(string value) { RectangleModel rectangle = null; // Obtiene el rectángulo if (!value.IsEmpty()) { string[] valueParts = value.Split(','); if (valueParts.Length == 4) { rectangle = new RectangleModel(valueParts[0].GetDouble(), valueParts[1].GetDouble(), valueParts[2].GetDouble(), valueParts[3].GetDouble()); } } // Devuelve el rectángulo return(rectangle); }
public static void SaveFromScreen(RectangleModel rectangle) { if (rectangle.Height < 5) { throw new ArgumentOutOfRangeException(nameof(rectangle.Height)); } if (rectangle.Width < 5) { throw new ArgumentOutOfRangeException(nameof(rectangle.Width)); } var printscreen = new Bitmap(rectangle.Width - 4, rectangle.Height - 4); var graphics = Graphics.FromImage(printscreen); graphics.CopyFromScreen(rectangle.LeftTop.X + 2, rectangle.LeftTop.Y + 2, 0, 0, printscreen.Size); printscreen.Save($"{DateTime.Now:dd.MM.yyyy HH-mm-ss}.png", ImageFormat.Png); }
private static void DrawRectangleOutline(VertexHelper vh, RectangleModel model, GeometryStyleAsset.GeometryStyleSet styleSet) { var p0 = CoordinateTupleToVector3(model.P0); var p1 = CoordinateTupleToVector3(model.P1); var style = model.IsBaked ? styleSet.DefaultStyle : styleSet.DrawingStyle; var p0World = p0; var p1World = new Vector3(p1.x, 0f, p0.z); var p2World = p1; var p3World = new Vector3(p0.x, 0f, p1.z); UIMeshGenerationHelper.AddLine(vh, p0World, p1World - p0World, style.OutlineWidth, style.OutlineColor.Value, UIMeshGenerationHelper.CapsType.Round); UIMeshGenerationHelper.AddLine(vh, p1World, p2World - p1World, style.OutlineWidth, style.OutlineColor.Value, UIMeshGenerationHelper.CapsType.Round); UIMeshGenerationHelper.AddLine(vh, p2World, p3World - p2World, style.OutlineWidth, style.OutlineColor.Value, UIMeshGenerationHelper.CapsType.Round); UIMeshGenerationHelper.AddLine(vh, p3World, p0World - p3World, style.OutlineWidth, style.OutlineColor.Value, UIMeshGenerationHelper.CapsType.Round); }
public static Bitmap GetBitmapFromScreen(RectangleModel rectangle) { if (rectangle.Height < 5) { throw new ArgumentOutOfRangeException(nameof(rectangle.Height)); } if (rectangle.Width < 5) { throw new ArgumentOutOfRangeException(nameof(rectangle.Width)); } var printscreen = new Bitmap(rectangle.Width - 4, rectangle.Height - 4); using (var graphics = Graphics.FromImage(printscreen)) { graphics.CopyFromScreen(rectangle.LeftTop.X + 2, rectangle.LeftTop.Y + 2, 0, 0, printscreen.Size, CopyPixelOperation.SourceCopy); } return(printscreen); }
private static List <RectangleModel> GetRectangles(JArray objects) { List <RectangleModel> rectangles = new List <RectangleModel>(); //Loop each children (if more than 1 face) foreach (JObject obj in objects.Children()) { try { string type = obj["type"].Value <string>(); if (type.ToLower() == "face") { JObject bbox = (JObject)obj["boundingBox"]; string width = bbox["width"].Value <string>(); string height = bbox["height"].Value <string>(); string xStr = bbox["x"].Value <string>(); string yStr = bbox["y"].Value <string>(); RectangleModel rect1 = new RectangleModel { ObjectType = ObjectTypeEnum.Face, x = Convert.ToInt32(xStr), y = Convert.ToInt32(yStr), height = Convert.ToInt32(height), width = Convert.ToInt32(width) }; rectangles.Add(rect1); } } catch (Exception ex) { //TODO throw new Exception(ex.Message, ex); } } return(rectangles); }
public static void CompleteRectangle(RectangleModel nextRectangle, Vec <Coordinate> focusPosition) { nextRectangle.P1 = focusPosition; nextRectangle.IsBaked = true; }
/// <summary> /// Render propeller in legacy opengl. /// </summary> private SliceNode(RectangleModel model, string positionNameInIBufferable, params RenderMethodBuilder[] builders) : base(model, positionNameInIBufferable, builders) { this.ModelSize = model.ModelSize; }
public bool Contains(RectangleModel r) => P1.I <= r.P1.I && P1.J <= r.P1.J && P2.I >= r.P2.I && P2.J >= r.P2.J;
private static Rectangle ConvertToRectangle(RectangleModel p) { Rectangle rect1 = new Rectangle(p.x, p.y, p.width, p.height); return(rect1); }
public static RectangleModel <Bitmap>[,] GetMatrix(Bitmap bm, byte procentHeight = 4, byte procentWidth = 4, ushort pixelHeight = 10, ushort pixelWidth = 10) { if (procentHeight >= 50) { throw new ArgumentOutOfRangeException(nameof(procentHeight)); } if (procentWidth >= 50) { throw new ArgumentOutOfRangeException(nameof(procentWidth)); } int frameHeight; int rank0; if (bm.Height < pixelHeight) { frameHeight = bm.Height; rank0 = 1; } else if (bm.Height * procentHeight / 100 < pixelHeight) { frameHeight = pixelHeight; rank0 = bm.Height / frameHeight; } else { frameHeight = bm.Height * procentHeight / 100; rank0 = bm.Height / frameHeight; } int frameWidth; int rank1; if (bm.Width < pixelWidth) { frameWidth = bm.Width; rank1 = 1; } else if (bm.Width * procentWidth / 100 < pixelWidth) { frameWidth = pixelWidth; rank1 = bm.Width / frameWidth; } else { frameWidth = bm.Width * procentWidth / 100; rank1 = bm.Width / frameWidth; } var arr = new RectangleModel <Bitmap> [rank0, rank1]; for (var i = 0; i < arr.GetLength(0); i++) { int h; if (i == (arr.GetLength(0) - 1)) { h = bm.Height - i * frameHeight; } else { h = frameHeight; } for (var j = 0; j < arr.GetLength(1); j++) { int w; if (j == arr.GetLength(1) - 1) { w = bm.Width - j * frameWidth; } else { w = frameWidth; } try { var point = new Point(j * frameWidth, i * frameHeight); arr[i, j] = new RectangleModel <Bitmap>(point, h, w); var img = bm.Clone(new Rectangle(point.X, point.Y, w, h), bm.PixelFormat); arr[i, j].SetImage(img); } catch (Exception ex) { Logger.Log.Error($"{nameof(GetMatrix)}", ex); } } } return(arr); }
/// <summary> /// Convierte un rectángulo /// </summary> internal static Rect ConvertToRect(RectangleModel rectangle) { return(new Rect(rectangle.LeftDefault, rectangle.TopDefault, rectangle.WidthDefault, rectangle.HeightDefault)); }
public RectangleView(RectangleModel rectangleModel) { InitializeComponent(); this.DataContext = rectangleModel; }
public static void UpdateRectangle(RectangleModel nextRectangle, Vec <Coordinate> focusPosition) { nextRectangle.P1 = focusPosition; }
public RectangleViewModel(RectangleModel model) : base(model) { }
/// <summary> /// Clean up any resources being used. /// </summary> protected override void PerformDispose( ) { rectangleMesh.Dispose( ); model = null; }
public GraphicRectangle(Point point, RectangleModel model) { this.point = point; this.model = model; }
public static void AbortRectangle(RectangleModel nextRectangle) { nextRectangle.P0.ForEach(c => c.UnregisterGeometryAndTryToDelete(nextRectangle)); }
public SpatialTextViewModel(string text, RectangleModel position) { Text = text; Position = position; }