private Point2d ScreenSpaceToPixelSpace(Point clickLocation) { Domain2d canvasDomain = GetCanvasDomain(); var mappedPoint = clickLocation.ToPoint2d().Map(canvasDomain, this._massingDomain); return(mappedPoint); }
private Domain2d GetCanvasDomain() { // Get canvas properties var canvasWidth = this.canv_Main.ActualWidth; var canvasHeight = this.canv_Main.ActualHeight; // Test height // Get canvas ready lines var canvasDomain = new Domain2d( new Domain(0 + CanvasMargin, canvasWidth - CanvasMargin), new Domain(canvasHeight - CanvasMargin, 0 + CanvasMargin) ); // Scale the canvas domain to the aspect ratio of the input domain if (_massingDomain.X.IsLargerThan(_massingDomain.Y)) { double YscaleFactor = _massingDomain.AspectRatioY; canvasDomain.Y.ScaleMid(YscaleFactor); } else { double XscaleFactor = _massingDomain.AspectRatioX; canvasDomain.Y.ScaleMid(XscaleFactor); } return(canvasDomain); }
public FrixelReferenceData(PixelStructure pixelStructure, MassingStructure massingStructure) { this.Structure = pixelStructure; this.MassingStructure = massingStructure; this.ActualShape = massingStructure.Outline; this.BoundingBox = massingStructure.BoundingBox; this.ActualXSize = massingStructure.xSpacing; this.ActuveYSize = massingStructure.ySpacing; }
private void SetUpdated(FrixelReferenceData refData) { if (refData == null) { return; } this._pixelStructure = refData.Structure; this._actualOutline = refData.ActualShape; this._massingDomain = refData.BoundingBox; this.tb_GridSize.Text = refData.ActualXSize.RoundTo(2) + "', " + refData.ActuveYSize.RoundTo(2) + "'"; }
public Line2d Map(Domain2d from, Domain2d to) { var start = new Point2d(this.Start.X.Map(from.X, to.X), this.Start.Y.Map(from.Y, to.Y)); var end = new Point2d(this.End.X.Map(from.X, to.X), this.End.Y.Map(from.Y, to.Y)); var line = new Line2d(start, end); return(line); }
/// <summary> /// Fires when the window updates the bay size /// </summary> /// <param name="xSize"></param> /// <param name="ySize"></param> /// <returns></returns> private UI.FrixelReferenceData MainWindow_UpdateClient(double xSize, double ySize) { // Generate an array of points var bb = _lastReffedCurve.GetBoundingBox(true); var corns = bb.GetCorners(); var xDim = corns[0].DistanceTo(corns[1]); var yDim = corns[0].DistanceTo(corns[3]); // Create a 2d domain bbox Core.Domain2d Boundingbox = new Domain2d(new Core.Domain(corns[0].X, corns[1].X), new Core.Domain(corns[0].Y, corns[3].Y)); // Check if dimensions are valid if (!(xSize * 2 > xDim)) { this._xSize = xSize; } if (!(ySize * 2 > yDim)) { this._ySize = ySize; } return(this.Regenerate()); }
private MassingStructure GenerateMassingStructure() { // Generate an array of points var bb = _lastReffedCurve.GetBoundingBox(true); var corns = bb.GetCorners(); #region Bbox corner order // Remarks: // [0] Min.X, Min.Y, Min.Z // [1] Max.X, Min.Y, Min.Z // [2] Max.X, Max.Y, Min.Z // [3] Min.X, Max.Y, Min.Z // [4] Min.X, Min.Y, Max.Z // [5] Max.X, Min.Y, Max.Z // [6] Max.X, Max.Y, Max.Z // [7] Min.X, Max.Y, Max.Z #endregion var xDim = corns[0].DistanceTo(corns[1]); var yDim = corns[0].DistanceTo(corns[3]); var startCorner = corns[0]; // Create a 2d domain bbox Core.Domain2d Boundingbox = new Domain2d(new Core.Domain(corns[0].X, corns[1].X), new Core.Domain(corns[0].Y, corns[3].Y)); // Get the dimensions of the massing bbox var xNumber = System.Convert.ToInt32(Math.Ceiling(xDim / _xSize)); var yNumber = System.Convert.ToInt32(Math.Ceiling(yDim / _ySize)); var xSpacing = xDim / xNumber; var ySpacing = yDim / yNumber; List <Point3d> nodePointTests = new List <Point3d>(); List <Point3d> nodePoints = new List <Point3d>(); // Generate a point array Dictionary <Tuple <int, int>, Core.Geometry.Point2d> Nodes = new Dictionary <Tuple <int, int>, Core.Geometry.Point2d>(); for (int x = 0; x <= xNumber; x++) { for (int y = 0; y <= yNumber; y++) { var p = new Point3d((x * xSpacing) + startCorner.X, (y * ySpacing) + startCorner.Y, 0); nodePoints.Add(p); Nodes.Add( new Tuple <int, int>(x, y), p.ToFrixelPoint(Utilities.PointIsInsideOrOnCurve(_lastReffedCurve, p, 0.01))); if (Utilities.PointIsInsideOrOnCurve(_lastReffedCurve, p, 0.01)) { nodePointTests.Add(p); } } } // Get the line representation of our massing List <Core.Geometry.Line2d> massingLines = new List <Core.Geometry.Line2d>(); var pline = _lastReffedCurve.ToPolyline(0.01, Math.PI, 1, 1); var plinePoints = pline.ToPolyline().ToArray(); for (int i = 0; i < plinePoints.Count() - 1; i++) { massingLines.Add(new Core.Geometry.Line2d(plinePoints[i].ToFrixelPoint(), plinePoints[i + 1].ToFrixelPoint()) ); } return(new MassingStructure() { Nodes = Nodes, xSpacing = xSpacing, ySpacing = ySpacing, xBayCount = xNumber, yBayCount = yNumber, BoundingBox = Boundingbox, Outline = massingLines }); }
public Point2d Map(Domain2d from, Domain2d to) { return(new Point2d(this.X.Map(from.X, to.X), this.Y.Map(from.Y, to.Y))); }
private void Redraw() { // Early returns if canvas is too small or no structure loaded if (CanvasIsSmall()) { return; } if (this._pixelStructure == null | this._actualOutline == null) { return; } // Set state this._isRedrawing = true; // Render analysis colors bool renderAnalColors = this._displayState == DisplayState.Analytical; // Render displacement? bool renderDisplacement = this._pixelStructure.HasAnalysisValues(); // Clear canvas ClearCanvas(); // Get domains for canvas and point collection Domain2d pxlSDomain = this._massingDomain; Domain2d canvasDomain = GetCanvasDomain(); List <Line> pxsLines = _pixelStructure.GetAllLines(renderDisplacement).Select(l => { return(l.Map(pxlSDomain, canvasDomain).ToCanvasLine(Brushes.Gray)); }).ToList(); if (renderDisplacement) { // Add analysis colors List <double> edgeMap = new List <double>(); _pixelStructure.GetAllEdges().ForEach(e => { edgeMap.Add(Math.Abs(_dispMap[e.Start]) + Math.Abs(_dispMap[e.End])); }); var startingDomain = new Domain( edgeMap.Min(), edgeMap.Max() ); var redDomain = new Domain(0, 255); int i = 0; _pixelStructure.ClearAllEdgeColors(); pxsLines.ForEach(l => { try { var edgeColor = new Core.Display.Color(255, System.Convert.ToInt32(edgeMap[i].Map(startingDomain, redDomain)), 0, 0); _pixelStructure.AllEdgeColors.Add(edgeColor); if (renderAnalColors) { l.Stroke = new SolidColorBrush(edgeColor.ToMediaColor()); } else { l.Stroke = Brushes.Black; } } catch { l.Stroke = Brushes.Black; _pixelStructure.AllEdgeColors.Add(new Core.Display.Color(255, 0, 0, 0)); } i++; }); } List <Line> actualMassingLInes = _actualOutline.Select(l => { return(l.Map(pxlSDomain, canvasDomain).ToCanvasLine(Brushes.LightBlue)); }).ToList(); // Add lines to canvas pxsLines.ForEach(l => canv_Main.Children.Add(l)); actualMassingLInes.ForEach(l => canv_Main.Children.Add(l)); // Render support points List <Rectangle> supports = _pixelStructure.Nodes.Where(n => n.IsLocked).ToList().Select(n => { return(n.Map(pxlSDomain, canvasDomain).ToCanvasRect(20, Brushes.Blue)); }).ToList(); supports.ForEach(r => { int index = canv_Main.Children.Add(r); }); // Update summary if (this._pixelStructure != null && MainWindow.AnalysisResults != null) { RenderAnalysisSummary(); } // Set state this._isRedrawing = false; }