/// <summary> /// The method for generating Context Brep and a single mesh from the input Breps. /// </summary> /// <param name="breps"> Brep inputs that represent the search area for the pathfinding algorithm.</param> /// <returns>Rturns a list of generic types. First Item is a Brep representing the context of the navigation model. /// Second item of the list is a Mesh generated from the input Breps. /// </returns> private List <object> GenerateContext(GH_Structure <GH_Brep> breps) { List <object> result = new List <object>(); List <GH_Brep> searchArea = breps.FlattenData(); Mesh searchAreaMesh = new Mesh(); Brep context = new Brep(); // Generating a joined mesh from Breps if (searchArea.Count > 0) { for (int i = 0; i < searchArea.Count; i++) { if (i == 0) { searchAreaMesh = Mesh.CreateFromBrep(searchArea[i].Value)[0]; } else { searchAreaMesh.Append(Mesh.CreateFromBrep(searchArea[i].Value)[0]); } } } else { searchAreaMesh = Mesh.CreateFromBrep(searchArea[0].Value)[0]; } // Generating Context BoundingBox bBox = searchAreaMesh.GetBoundingBox(true); Point3d origin = bBox.Corner(true, false, true); Point3d oposite = bBox.Corner(false, true, true); double deltaX = System.Math.Abs(origin.X - oposite.X); double deltaY = System.Math.Abs(origin.Y - oposite.Y); double dimension = System.Math.Max(deltaX, deltaY); Rectangle3d contextBounds = new Rectangle3d(new Plane(origin, Vector3d.ZAxis), dimension, -dimension); context = Brep.CreateFromCornerPoints(contextBounds.Corner(0), contextBounds.Corner(1), contextBounds.Corner(2), contextBounds.Corner(3), 0.001); result.Add(context); result.Add(searchAreaMesh); return(result); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { GH_Structure <IGH_GeometricGoo> iGeometry = new GH_Structure <IGH_GeometricGoo>(); double iAngle = 0.0; List <string> iPatchNames = new List <string>(); List <int> iRefLvlGeom = new List <int>(); List <int> ieMeshRefLvl = new List <int>(); List <double> iX = new List <double>(); double iY = 0.0; double iZ = 0.0; Plane iZeroPlane = new Plane(); DA.GetDataTree(0, out iGeometry); DA.GetData(1, ref iAngle); DA.GetDataList(2, iPatchNames); DA.GetDataList(3, iRefLvlGeom); DA.GetDataList(4, ieMeshRefLvl); DA.GetDataList(5, iX); DA.GetData(6, ref iY); DA.GetData(7, ref iZ); DA.GetData(8, ref iZeroPlane); DataTree <Brep> convertedGeomTree = new DataTree <Brep>(); List <GH_Path> pathList = new List <GH_Path>(); foreach (var path in iGeometry.Paths) { for (int i = 0; i < iGeometry.get_Branch(path).Count; i++) { pathList.Add(path); } } var flattenedGeom = iGeometry.FlattenData(); for (int i = 0; i < flattenedGeom.Count; i++) { flattenedGeom[i].CastTo(out Brep tempBrep); convertedGeomTree.Add(tempBrep, pathList[i]); } DataTree <Brep> rotatedGeomTree = convertedGeomTree; Point3d centerPt = GetCenterPt(rotatedGeomTree.AllData()); foreach (GH_Path path in rotatedGeomTree.Paths) { foreach (var brep in rotatedGeomTree.Branch(path)) { brep.Rotate(iAngle * Math.PI / 180, Vector3d.ZAxis, centerPt); } } if (DA.GetData(8, ref iZeroPlane)) { centerPt.Z = iZeroPlane.OriginZ; } double height = GetHeight(convertedGeomTree.AllData()); double width = GetWidth(convertedGeomTree.AllData()); double depth = GetDepth(convertedGeomTree.AllData()); if (!DA.GetDataList(2, iPatchNames)) { for (int i = 0; i < rotatedGeomTree.BranchCount; i++) { iPatchNames.Add("PATCH_" + i); } } if (!DA.GetDataList(3, iRefLvlGeom)) { for (int i = 0; i < rotatedGeomTree.BranchCount; i++) { iRefLvlGeom.Add(2); } } if (!DA.GetDataList(4, ieMeshRefLvl)) { for (int i = 0; i < rotatedGeomTree.BranchCount; i++) { ieMeshRefLvl.Add(2); } } if (!DA.GetDataList(5, iX)) { iX.Add(4 * height); iX.Add(12 * height); } if (!DA.GetData(6, ref iY)) { iY = 6 * height; } if (!DA.GetData(7, ref iZ)) { iZ = 6 * height; } if (iX[0] <= 0.5 * depth || iX[1] <= 0.5 * depth) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "The depth of the wind tunnel is too small!"); } else if (iX[0] < 2.5 * height || iX[1] < 7.5 * height) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The depth of the wind tunnel is small, be aware."); } if (iY < 4 * height) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The width of the wind tunnel is small, be aware."); } else if (iY <= width) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "The width of the wind tunnel is too small!"); } if (iZ < 6 * height) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The height of the wind tunnel is small, be aware."); } else if (iZ <= height) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "The height of the wind tunnel is too small!"); } List <Point3d> cornerPoints = new List <Point3d> { new Point3d(centerPt.X - iX[0], centerPt.Y - iY / 2, centerPt.Z), new Point3d(centerPt.X + iX[1], centerPt.Y - iY / 2, centerPt.Z), new Point3d(centerPt.X + iX[1], centerPt.Y + iY / 2, centerPt.Z), new Point3d(centerPt.X - iX[0], centerPt.Y + iY / 2, centerPt.Z), new Point3d(centerPt.X - iX[0], centerPt.Y - iY / 2, centerPt.Z + iZ), new Point3d(centerPt.X + iX[1], centerPt.Y - iY / 2, centerPt.Z + iZ), new Point3d(centerPt.X + iX[1], centerPt.Y + iY / 2, centerPt.Z + iZ), new Point3d(centerPt.X - iX[0], centerPt.Y + iY / 2, centerPt.Z + iZ) }; List <Brep> surfaceList = new List <Brep> { Brep.CreateFromCornerPoints(cornerPoints[0], cornerPoints[4], cornerPoints[7], cornerPoints[3], 0.01), Brep.CreateFromCornerPoints(cornerPoints[1], cornerPoints[2], cornerPoints[6], cornerPoints[5], 0.01), Brep.CreateFromCornerPoints(cornerPoints[3], cornerPoints[7], cornerPoints[6], cornerPoints[2], 0.01), Brep.CreateFromCornerPoints(cornerPoints[0], cornerPoints[1], cornerPoints[5], cornerPoints[4], 0.01), Brep.CreateFromCornerPoints(cornerPoints[0], cornerPoints[3], cornerPoints[2], cornerPoints[1], 0.01), Brep.CreateFromCornerPoints(cornerPoints[4], cornerPoints[5], cornerPoints[6], cornerPoints[7], 0.01) }; List <string> nameList = new List <string> { "INLET", "OUTLET", "LEFTSIDE", "RIGHTSIDE", "BOTTOM", "TOP" }; DataTree <Brep> oGeometryList = new DataTree <Brep>(); int j = 0; int k = 0; foreach (var surface in surfaceList) { surface.SetUserString("Name", nameList[j]); surface.SetUserString("RefLvl", "0"); surface.SetUserString("eMeshLvl", "0"); surface.SetUserString("RotAngle", iAngle.ToString()); oGeometryList.Add(surface, new GH_Path(k)); j++; k++; } ; j = 0; foreach (GH_Path path in rotatedGeomTree.Paths) { foreach (var brep in rotatedGeomTree.Branch(path)) { brep.SetUserString("Name", iPatchNames[j]); brep.SetUserString("RefLvl", iRefLvlGeom[j].ToString()); brep.SetUserString("eMeshLvl", ieMeshRefLvl[j].ToString()); brep.SetUserString("RotAngle", iAngle.ToString()); oGeometryList.Add(brep, new GH_Path(k)); } j++; k++; } DA.SetDataTree(0, oGeometryList); }
public static Dictionary <string, dynamic> GHStructToDict(string k, GH_Structure <IGH_Goo> values) { Dictionary <string, dynamic> jsonDictWrite = new Dictionary <string, dynamic>(); if (!values.IsEmpty) { // if multiple items.. if (values.FlattenData().Count > 1) { //if list.. if (values.Branches.Count == 1) { dynamic _data = null; List <dynamic> _dataList = new List <dynamic>(); values.FlattenData().ForEach(x => x.CastTo(out _data)); _dataList.Add(_data); if (jsonDictWrite.ContainsKey(k)) { jsonDictWrite[k] = _dataList; } else { jsonDictWrite.Add(k, _dataList); } } // if datatree, convert to dictionary , then to List. Assign this new list as a value to jsondict using the input key else { Dictionary <string, dynamic> _dataDict = new Dictionary <string, dynamic>(); for (int i = 0; i < values.Branches.Count; i++) { dynamic _data = null; List <dynamic> _dataList = new List <dynamic>(); values[i].ForEach(x => x.CastTo(out _data)); _dataList.Add(_data); if (_dataDict.ContainsKey(i.ToString())) { _dataDict[i.ToString()] = _dataList; } else { _dataDict.Add(i.ToString(), _dataList); } if (jsonDictWrite.ContainsKey(k)) { jsonDictWrite[k] = _dataDict; } else { jsonDictWrite.Add(k, _dataDict); } } } } // if single item.. else if (jsonDictWrite.ContainsKey(k)) { jsonDictWrite[k] = values.get_FirstItem(true); } else { jsonDictWrite.Add(k, values.get_FirstItem(true)); } } return(jsonDictWrite); }
protected override void SolveInstance(IGH_DataAccess DA) { bool write = false; string folderPath = null; string fileName = null; GH_Structure <GH_Point> points = null; List <string> instructionData = new List <string>(); if (DA.Iteration == 0) { switch (this.loftMode) { case LoftMode.None: this.Message = "Default"; break; case LoftMode.Points: this.Message = "Ref Points"; break; case LoftMode.Lines: this.Message = "Lines"; break; case LoftMode.Loft: this.Message = "Surface"; break; } } // Set up Utility object and start process Utility utility = new Utility(DA); utility.Print("Starting Loft Form."); if (!utility.GetInput(0, ref write)) // Write command is required { utility.WriteOut(); return; } if (!utility.GetInput(1, ref folderPath)) // Folder path is required { utility.WriteOut(); return; } utility.GetInput(2, ref fileName, true, true, true); // File name is optional if (fileName == null) { fileName = this.DEFAULT_FILE_NAME; } if (!utility.GetInput(3, out points)) { return; } if (write) { // Create RevitModelBuilderUtility object and link to CSV file CsvWriter csvWriter = new CsvWriter(); utility.Print("CsvWriter Version: " + csvWriter.Version); if (!utility.EstablishCsvLink(csvWriter, folderPath, fileName)) { utility.Print("EstablishCsvLink() failed"); utility.WriteOut(); return; } switch (this.loftMode) { case LoftMode.Loft: // Loop for each branch, get points, and create form List <List <HbXYZ> > pointsListListRevit = new List <List <HbXYZ> >(); if (!utility.ReadDataTree(points, ref pointsListListRevit)) { return; } csvWriter.AddLoftForm(pointsListListRevit); instructionData.Add("Add Loft Form:"); csvWriter.WriteFile(); utility.Print("Loft Form completed successfully."); break; case LoftMode.Lines: // Loop for each branch, get points, and place curve for (int i = 0; i < points.Branches.Count; i++) { List <GH_Point> branch = points.Branches[i]; List <HbXYZ> pointsListRevit = new List <HbXYZ>(); for (int j = 0; j < branch.Count; j++) { HbXYZ hbXYZ = new HbXYZ(branch[j].Value.X, branch[j].Value.Y, branch[j].Value.Z); pointsListRevit.Add(hbXYZ); } csvWriter.AddCurveByPoints(pointsListRevit); instructionData.Add("Add Curve by Points:"); } csvWriter.WriteFile(); utility.Print("Curves By Points completed successfully."); break; case LoftMode.Points: List <GH_Point> points_list = null; points_list = points.FlattenData(); // Loop for each point and place reference point. for (int i = 0; i < points_list.Count; i++) { HbXYZ hbXYZ = new HbXYZ(points_list[i].Value.X, points_list[i].Value.Y, points_list[i].Value.Z); csvWriter.AddReferencePoint(hbXYZ); instructionData.Add("Add Reference Point:"); } csvWriter.WriteFile(); utility.Print("Reference Points completed successfully."); break; } } utility.WriteOut(); DA.SetDataList(1, instructionData); }
/** * Does the computation */ protected override void SolveRabbitInstance(IGH_DataAccess DA) { //Get the Structure of the Data of points, so that the underlying grid logic could be retrieved ------- DA.DisableGapLogic(); if (DA.Iteration > 0) { return; } //Get the points as GH Structure, because the dimensions of the space are based on the tree's structure: GH_Structure <GH_Point> ghPointsTree = (GH_Structure <GH_Point>) this.Params.Input[1].VolatileData; //get all points as a flat list: List <GH_Point> ghPointsList = ghPointsTree.FlattenData(); //expects a 2D grid: int XDimension = ghPointsTree.Paths.Count; int YDimension = ghPointsList.Count / XDimension; IList <Point3d> latticePoints = GH_PointUtils.ConvertToOnPoints(ghPointsList); //Get the cell prototype---------------------------------------------------------------------------------- GH_ObjectWrapper cellPrototypeWrapper = null; DA.GetData <GH_ObjectWrapper>(0, ref cellPrototypeWrapper); ICell cellPrototype = (ICell)cellPrototypeWrapper.Value; //Get the State configurations----------------------------------------------------------------------------- OnCellularGridBuilder gridBuilder = null; List <GH_ObjectWrapper> stateConfigurations = new List <GH_ObjectWrapper>(); DA.GetDataList(2, stateConfigurations); foreach (GH_ObjectWrapper stateConfigWrapper in stateConfigurations) { if (stateConfigWrapper != null) // Custom configuration defined { if (stateConfigWrapper.Value.GetType() == typeof(OnStateConfig)) { OnStateConfig stateConfig = (OnStateConfig)stateConfigWrapper.Value; //get the user-defined points that define custom Cell State IList <Point3d> userConfigurationGHPoints = stateConfig.GetPoints(); //get the real configuration points, by finding the points that are closer to the user defined configuration points IList <Point3d> realConfigurationPoints = PointUtils.GetClosestPoints(userConfigurationGHPoints, latticePoints); stateConfig.SetPoints(realConfigurationPoints); gridBuilder = new OnCellularGridBuilder(cellPrototype, latticePoints, XDimension, YDimension, stateConfig); } else if (stateConfigWrapper.Value.GetType() == typeof(RandomCAConfig)) { RandomCAConfig stateConfig = (RandomCAConfig)stateConfigWrapper.Value; gridBuilder = new OnCellularGridBuilder(cellPrototype, latticePoints, XDimension, YDimension, stateConfig); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Not supported configuration type!"); } } } if (stateConfigurations.Count == 0) // no configuration defined { gridBuilder = new OnCellularGridBuilder(cellPrototype, latticePoints, XDimension, YDimension); //, new RandomCAConfig(cellPrototype.GetFiniteStates())); } //build the grid Grid2d <ICell> grid2d = gridBuilder.BuildCellularGrid(); CA ca = new CA(grid2d); //set the output parameters DA.SetData(0, ca); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { GH_Structure <GH_Number> X_list = new GH_Structure <GH_Number>(); GH_Structure <GH_Number> F_Tree = new GH_Structure <GH_Number>(); GH_Structure <GH_Number> G_Tree = new GH_Structure <GH_Number>(); //if (!DA.GetDataTree<GH_Number>(0, out X_list)) return; if (!DA.GetDataTree <GH_Number>(1, out F_Tree)) { return; } //List<GH_NumberSlider> sliders = new List<GH_NumberSlider>(); Vars.sliders = new List <GH_NumberSlider>(); Vars.genepools = new List <GalapagosGeneListObject>(); foreach (IGH_Param param in Params.Input[0].Sources) { GH_NumberSlider slider = param as GH_NumberSlider; if (slider != null) { Vars.sliders.Add(slider); } else { GalapagosGeneListObject genepool = param as GalapagosGeneListObject; if (genepool != null) { Vars.genepools.Add(genepool); } } } if (Vars.sliders.Count == 0 && Vars.genepools.Count == 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Connect sliders to the variables (x) input."); return; } if (F_Tree.DataCount == 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Supply a fitness value to minimise/maximise."); return; } double F_x = new double(); if (F_Tree.DataCount > 1) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Only one fitness value should be supplied."); return; } try { if (F_Tree.get_FirstItem(true).CastTo <double>(out F_x)) { if (DA.GetDataTree <GH_Number>(2, out G_Tree)) { if (G_Tree.DataCount > 0) { List <GH_Number> G_List = G_Tree.FlattenData(); List <double> g = new List <double>(); for (int i = 0; i < G_List.Count; i++) { double g_temp = 0; G_List[i].CastTo <double>(out g_temp); g.Add(g_temp); } double G_x = new double(); double max = 0; double f = 0; for (int i = 0; i < g.Count; i++) { if (g[i] > max) { max = g[i]; } } if (max <= 1) { G_x = max; } else { double rho = 1 / (max - 1); for (int i = 0; i < g.Count; i++) { f = f + Math.Exp(rho * g[i]); } f = Math.Log(f) / rho; G_x = f; } Vars.g = G_x; Message = "g = " + String.Format("{0:0.000}", G_x); } else { Vars.g = 0; } } } } catch { Vars.f = double.PositiveInfinity; Vars.g = 0; return; } Vars.f = F_x; }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { List <Plane> camPlanes = new List <Plane>(); DA.GetDataList <Plane>(0, camPlanes); string folder = string.Empty; DA.GetData <string>(1, ref folder); bool saveCubemaps = !string.IsNullOrEmpty(folder); if (saveCubemaps) { folder = Path.GetFullPath(folder); if (!folder.EndsWith(Path.DirectorySeparatorChar.ToString())) { folder += Path.DirectorySeparatorChar; } } string prefix = string.Empty; DA.GetData <string>(2, ref prefix); int imageWidth = 0; DA.GetData <int>(3, ref imageWidth); imageWidth = imageWidth / 4; Size size = new Size(imageWidth, imageWidth); string displayMode = string.Empty; DA.GetData <string>(4, ref displayMode); List <Color> colors = new List <Color>(); DA.GetDataList <Color>(5, colors); bool filterColors = colors.Any(); GH_Structure <GH_Mesh> ghObstacles = new GH_Structure <GH_Mesh>(); DA.GetDataTree <GH_Mesh>(6, out ghObstacles); ///Flatten obstacle meshes and join them into one mesh ghObstacles.FlattenData(); Mesh obstacles = new Mesh(); bool showRays = false; if (ghObstacles.DataCount > 0) { showRays = true; foreach (var obstacle in ghObstacles) { Mesh temp = new Mesh(); GH_Convert.ToMesh(obstacle, ref temp, GH_Conversion.Primary); obstacles.Append(temp); } } bool run = false; DA.GetData <bool>(7, ref run); int pad = camPlanes.Count.ToString().Length; List <string> cubemaps = new List <string>(); GH_Structure <GH_Line> rayTree = new GH_Structure <GH_Line>(); GH_Structure <GH_Colour> colorTree = new GH_Structure <GH_Colour>(); ///Save the intial camera saveCam = camFromVP(Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport); ///Set the display mode to be used for bitmaps ///TODO: Add menu item to use "Heron View Analysis" display mode DisplayModeDescription viewMode = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.DisplayMode; if (DisplayModeDescription.FindByName(displayMode) != null) { viewMode = DisplayModeDescription.FindByName(displayMode); } Message = viewMode.EnglishName; if (run) { for (int i = 0; i < camPlanes.Count; i++) { ///TODO: setup ability to save cameras to the Rhino doc ///Setup camera Rhino.Display.RhinoView view = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView; Rhino.Display.RhinoViewport vp = view.ActiveViewport; ///Get the bounding box of all visible object in the doc for use in setting up the camera ///target so that the far frustrum plane doesn't clip anything double zoomDistance = Rhino.RhinoDoc.ActiveDoc.Objects.BoundingBoxVisible.Diagonal.Length; Plane camPlane = camPlanes[i]; Point3d camPoint = camPlane.Origin; Vector3d camDir = camPlane.YAxis; Point3d tarPoint = Transform.Translation(camDir * zoomDistance / 2) * camPoint; vp.ChangeToPerspectiveProjection(false, 12.0); vp.Size = size; vp.DisplayMode = viewMode; //view.Redraw(); ///Set up final bitmap Bitmap cubemap = new Bitmap(imageWidth * 4, imageWidth * 3); ///Place the images on cubemap bitmap using (Graphics gr = Graphics.FromImage(cubemap)) { ///Grab bitmap ///Set up camera directions Point3d tarLeft = Transform.Translation(-camPlane.XAxis * zoomDistance / 2) * camPoint; Point3d tarFront = Transform.Translation(camPlane.YAxis * zoomDistance / 2) * camPoint; Point3d tarRight = Transform.Translation(camPlane.XAxis * zoomDistance / 2) * camPoint; Point3d tarBack = Transform.Translation(-camPlane.YAxis * zoomDistance / 2) * camPoint; Point3d tarUp = Transform.Translation(camPlane.ZAxis * zoomDistance / 2) * camPoint; Point3d tarDown = Transform.Translation(-camPlane.ZAxis * zoomDistance / 2) * camPoint; List <Point3d> camTargets = new List <Point3d>() { tarLeft, tarFront, tarRight, tarBack, tarUp, tarDown }; ///Loop through pano directions int insertLoc = 0; for (int d = 0; d < 4; d++) { ///Set camera direction vp.SetCameraLocations(camTargets[d], camPoint); //view.Redraw(); Bitmap bitmap = new Bitmap(view.CaptureToBitmap(size, viewMode)); if (saveCubemaps) { gr.DrawImage(bitmap, insertLoc, imageWidth); } if (showRays) { GH_MemoryBitmap sampler = new GH_MemoryBitmap(bitmap); Color col = Color.Transparent; for (int x = 0; x < bitmap.Width; x++) { for (int y = 0; y < bitmap.Height; y++) { if (sampler.Sample(x, y, ref col)) { if (colors.Contains(col)) { GH_Path path = new GH_Path(i, colors.IndexOf(col)); Line line = vp.ClientToWorld(new System.Drawing.Point(x, y)); Ray3d ray = new Ray3d(vp.CameraLocation, -line.Direction); double rayEnd = (double)Rhino.Geometry.Intersect.Intersection.MeshRay(obstacles, ray); Point3d rayIntersection = ray.PointAt(rayEnd); Line ln = new Line(camPoint, rayIntersection); if (ln.IsValid & rayEnd > 0) { rayTree.Append(new GH_Line(ln), path); colorTree.Append(new GH_Colour(col), path); } } else if (!filterColors) { colors.Add(col); GH_Path path = new GH_Path(i, colors.IndexOf(col)); Line line = vp.ClientToWorld(new System.Drawing.Point(x, y)); Ray3d ray = new Ray3d(vp.CameraLocation, -line.Direction); double rayEnd = (double)Rhino.Geometry.Intersect.Intersection.MeshRay(obstacles, ray); Point3d rayIntersection = ray.PointAt(rayEnd); Line ln = new Line(camPoint, rayIntersection); if (ln.IsValid & rayEnd > 0) { rayTree.Append(new GH_Line(ln), path); colorTree.Append(new GH_Colour(col), path); } } } } } sampler.Release(false); } insertLoc = insertLoc + imageWidth; bitmap.Dispose(); } ///Get up and down views ///Get up view vp.SetCameraLocations(tarUp, camPoint); view.Redraw(); Bitmap bitmapUp = new Bitmap(view.CaptureToBitmap(size, viewMode)); if (showRays) { GH_MemoryBitmap sampler = new GH_MemoryBitmap(bitmapUp); Color col = Color.Transparent; for (int x = 0; x < bitmapUp.Width; x++) { for (int y = 0; y < bitmapUp.Height; y++) { if (sampler.Sample(x, y, ref col)) { if (colors.Contains(col)) { GH_Path path = new GH_Path(i, colors.IndexOf(col)); Line line = vp.ClientToWorld(new System.Drawing.Point(x, y)); Ray3d ray = new Ray3d(vp.CameraLocation, -line.Direction); double rayEnd = (double)Rhino.Geometry.Intersect.Intersection.MeshRay(obstacles, ray); Point3d rayIntersection = ray.PointAt(rayEnd); Line ln = new Line(camPoint, rayIntersection); if (ln.IsValid & rayEnd > 0) { rayTree.Append(new GH_Line(ln), path); colorTree.Append(new GH_Colour(col), path); } } else if (!filterColors) { colors.Add(col); GH_Path path = new GH_Path(i, colors.IndexOf(col)); Line line = vp.ClientToWorld(new System.Drawing.Point(x, y)); Ray3d ray = new Ray3d(vp.CameraLocation, -line.Direction); double rayEnd = (double)Rhino.Geometry.Intersect.Intersection.MeshRay(obstacles, ray); Point3d rayIntersection = ray.PointAt(rayEnd); Line ln = new Line(camPoint, rayIntersection); if (ln.IsValid & rayEnd > 0) { rayTree.Append(new GH_Line(ln), path); colorTree.Append(new GH_Colour(col), path); } } } } } sampler.Release(false); } bitmapUp.RotateFlip(RotateFlipType.Rotate180FlipNone); if (saveCubemaps) { gr.DrawImage(bitmapUp, imageWidth, 0); } bitmapUp.Dispose(); ///Get down view vp.SetCameraLocations(tarDown, camPoint); view.Redraw(); Bitmap bitmapDown = new Bitmap(view.CaptureToBitmap(size, viewMode)); if (saveCubemaps) { gr.DrawImage(bitmapDown, imageWidth, imageWidth * 2); } if (showRays) { GH_MemoryBitmap sampler = new GH_MemoryBitmap(bitmapDown); Color col = Color.Transparent; for (int x = 0; x < bitmapDown.Width; x++) { for (int y = 0; y < bitmapDown.Height; y++) { if (sampler.Sample(x, y, ref col)) { if (colors.Contains(col)) { GH_Path path = new GH_Path(i, colors.IndexOf(col)); Line line = vp.ClientToWorld(new System.Drawing.Point(x, y)); Ray3d ray = new Ray3d(vp.CameraLocation, -line.Direction); double rayEnd = (double)Rhino.Geometry.Intersect.Intersection.MeshRay(obstacles, ray); Point3d rayIntersection = ray.PointAt(rayEnd); Line ln = new Line(camPoint, rayIntersection); if (ln.IsValid & rayEnd > 0) { rayTree.Append(new GH_Line(ln), path); colorTree.Append(new GH_Colour(col), path); } } else if (!filterColors) { colors.Add(col); GH_Path path = new GH_Path(i, colors.IndexOf(col)); Line line = vp.ClientToWorld(new System.Drawing.Point(x, y)); Ray3d ray = new Ray3d(vp.CameraLocation, -line.Direction); double rayEnd = (double)Rhino.Geometry.Intersect.Intersection.MeshRay(obstacles, ray); Point3d rayIntersection = ray.PointAt(rayEnd); Line ln = new Line(camPoint, rayIntersection); if (ln.IsValid & rayEnd > 0) { rayTree.Append(new GH_Line(ln), path); colorTree.Append(new GH_Colour(col), path); } } } } } sampler.Release(false); } bitmapDown.Dispose(); } ///End pano directions loop if (saveCubemaps) { ///Save cubemap bitmap string s = i.ToString().PadLeft(pad, '0'); string saveText = folder + prefix + "_" + s + ".png"; cubemap.Save(saveText, System.Drawing.Imaging.ImageFormat.Png); cubemaps.Add(saveText); } cubemap.Dispose(); } } ///Restore initial camera setCamera(saveCam, Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport); Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.Redraw(); DA.SetDataList(0, cubemaps); DA.SetDataTree(1, rayTree); DA.SetDataTree(2, colorTree); }