private void MainWindow_BakeStructure(PixelStructure pixelStructure) { // Bake designed structure var rhLines = pixelStructure.GetAllEdges().Select(e => { return(new Rhino.Geometry.Line(pixelStructure.Nodes[e.Start].ToRhinoPoint(), pixelStructure.Nodes[e.End].ToRhinoPoint())); }).ToList(); var attr = SetUpAttr("Designed_Structure", System.Drawing.Color.White); rhLines.ForEach(l => Rhino.RhinoDoc.ActiveDoc.Objects.Add(l.ToNurbsCurve(), attr)); RhinoDoc.ActiveDoc.Views.Redraw(); // Bake analytical curves with their colors if (!pixelStructure.HasAnalysisValues() | !pixelStructure.HasEdgeColors()) { return; } var rhAnalyticalLines = pixelStructure.GetAllLines(true).Select(l => new Rhino.Geometry.Line(l.Start.ToRhinoPoint(), l.End.ToRhinoPoint()) ).ToList(); var analBaseAttr = SetUpAttr("Analyzed_Structure", System.Drawing.Color.Gray); var analAttrs = pixelStructure.AllEdgeColors.Select(c => { return(new ObjectAttributes() { LayerIndex = analBaseAttr.LayerIndex, ObjectColor = System.Drawing.Color.FromArgb( System.Convert.ToByte(c.A), System.Convert.ToByte(c.R), System.Convert.ToByte(c.G), System.Convert.ToByte(c.B) ), ObjectId = new Guid(), ColorSource = ObjectColorSource.ColorFromObject }); }).ToList(); for (int i = 0; i < rhAnalyticalLines.Count; i++) { RhinoDoc.ActiveDoc.Objects.Add(rhAnalyticalLines[i].ToNurbsCurve(), analAttrs[i]); } RhinoDoc.ActiveDoc.Views.Redraw(); }
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; }