/// <summary> /// Extends a plane into a plane surface so that the latter goes through a bounding box. /// </summary> /// <param name="plane">An original plane value.</param> /// <param name="box">A box to use for extension boundary.</param> /// <returns>A new plane surface on success, or null on error.</returns> /// <example> /// <code source='examples\vbnet\ex_splitbrepwithplane.vb' lang='vbnet'/> /// <code source='examples\cs\ex_splitbrepwithplane.cs' lang='cs'/> /// <code source='examples\py\ex_splitbrepwithplane.py' lang='py'/> /// </example> public static PlaneSurface CreateThroughBox(Plane plane, BoundingBox box) { IntPtr ptr = UnsafeNativeMethods.RHC_RhinoPlaneThroughBox2(ref plane, ref box); if (IntPtr.Zero == ptr) return null; return new PlaneSurface(ptr, null); }
public Mesh Mesh2DMinimalBox(Mesh mesh) { List <Point3d> x = new List <Point3d>(); Rhino.Geometry.Collections.MeshTopologyVertexList vs = mesh.TopologyVertices; for (int i = 0; i < vs.Count; i++) { x.Add(new Point3d(vs[i])); } Grasshopper.Kernel.Geometry.Node2List list = new Grasshopper.Kernel.Geometry.Node2List(x); Polyline pl = Grasshopper.Kernel.Geometry.ConvexHull.Solver.ComputeHull(list); double t = double.MaxValue; Transform xform = new Transform(); for (int i = 0; i < pl.Count - 1; i++) { Vector3d Xaxis = pl[i + 1] - pl[i]; Vector3d Yaxis = Vector3d.CrossProduct(Xaxis, Vector3d.ZAxis); Plane p = new Plane(pl[i], Xaxis, Yaxis); Polyline pl2 = new Polyline(pl); pl2.Transform(Transform.PlaneToPlane(p, Plane.WorldXY)); Rhino.Geometry.BoundingBox box = pl2.BoundingBox; double area = (box.Max.X - box.Min.X) * (box.Max.Y - box.Min.Y); if (area < t) { t = area; xform = Transform.PlaneToPlane(p, Plane.WorldXY); } } mesh.Transform(xform); return(mesh); }
public Polyline MinimalBox(List <Point3d> x) { Grasshopper.Kernel.Geometry.Node2List list = new Grasshopper.Kernel.Geometry.Node2List(x); Polyline pl = Grasshopper.Kernel.Geometry.ConvexHull.Solver.ComputeHull(list); // List<Polyline> boxes = new List<Polyline>(); Polyline output = new Polyline(); double t = double.MaxValue; for (int i = 0; i < pl.Count - 1; i++) { Vector3d Xaxis = pl[i + 1] - pl[i]; Vector3d Yaxis = Vector3d.CrossProduct(Xaxis, Vector3d.ZAxis); Plane p = new Plane(pl[i], Xaxis, Yaxis); Polyline pl2 = new Polyline(pl); pl2.Transform(Transform.PlaneToPlane(p, Plane.WorldXY)); Rhino.Geometry.BoundingBox box = pl2.BoundingBox; Polyline pl3 = new Polyline(); pl3.Add(box.Corner(false, false, false)); pl3.Add(box.Corner(false, true, false)); pl3.Add(box.Corner(true, true, false)); pl3.Add(box.Corner(true, false, false)); pl3.Add(box.Corner(false, false, false)); double area = pl3[1].DistanceTo(pl3[0]) * pl3[1].DistanceTo(pl3[2]); if (area < t) { t = area; pl3.Transform(Transform.PlaneToPlane(Plane.WorldXY, p)); output = pl3; } // boxes.Add(pl3); } return(output); }
public Mesh Mesh3DMinimalBox(Mesh mesh) { List <Point3d> x = new List <Point3d>(); Rhino.Geometry.Collections.MeshTopologyVertexList vs = mesh.TopologyVertices; for (int i = 0; i < vs.Count; i++) { x.Add(new Point3d(vs[i])); } Mesh mesh2 = ch.ConvexHull(x); mesh2.Faces.ConvertQuadsToTriangles(); double t = double.MaxValue; Transform xform = new Transform(); for (int i = 0; i < mesh2.Faces.Count - 1; i++) { Point3d p1 = new Point3d(mesh2.Vertices[mesh2.Faces[i].A]); Point3d p2 = new Point3d(mesh2.Vertices[mesh2.Faces[i].B]); Point3d p3 = new Point3d(mesh2.Vertices[mesh2.Faces[i].C]); Plane p = new Plane(p1, p2, p3); Mesh mesh3 = new Mesh(); mesh3.Append(mesh); mesh3.Transform(Transform.PlaneToPlane(p, Plane.WorldXY)); Rhino.Geometry.BoundingBox box = mesh3.GetBoundingBox(true); double area = (box.Max.X - box.Min.X) * (box.Max.Y - box.Min.Y) * (box.Max.Z - box.Min.Z); if (area < t) { t = area; xform = Transform.PlaneToPlane(p, Plane.WorldXY); } } mesh.Transform(xform); return(mesh); }
static SelectionScreen() { _transformMouseDown = Transform.Translation(Vector3d.ZAxis * -1); _transformMouseOver = Transform.Translation(Vector3d.ZAxis * 1); var menuTitle = new SelectableObject(ElementType.Drawable); menuTitle.AddGeoemtry(Serialized.Meshes.Menu.TitleBigBackground, Settings.MaterialOrange); menuTitle.AddGeoemtry(Serialized.Meshes.Menu.TitleBigBorder, Settings.MaterialRed); menuTitle.AddGeoemtry(Serialized.Meshes.Menu.TitleBigLetters, Settings.MaterialYellow); var menuOptions = new SelectableObject(ElementType.MenuOptions); menuOptions.AddGeoemtry(Serialized.Meshes.Menu.OptionsBackground, Settings.MaterialOrange); menuOptions.AddGeoemtry(Serialized.Meshes.Menu.OptionsBorder, Settings.MaterialRed); menuOptions.AddGeoemtry(Serialized.Meshes.Menu.OptionsLetters, Settings.MaterialYellow); var menuStart = new SelectableObject(ElementType.MenuStart); menuStart.AddGeoemtry(Serialized.Meshes.Menu.StartBacbground, Settings.MaterialOrange); menuStart.AddGeoemtry(Serialized.Meshes.Menu.StartBorder, Settings.MaterialRed); menuStart.AddGeoemtry(Serialized.Meshes.Menu.StartLetters, Settings.MaterialYellow); var menuExit = new SelectableObject(ElementType.MenuExit); menuExit.AddGeoemtry(Serialized.Meshes.Menu.ExitBacground, Settings.MaterialOrange); menuExit.AddGeoemtry(Serialized.Meshes.Menu.ExitBorder, Settings.MaterialRed); menuExit.AddGeoemtry(Serialized.Meshes.Menu.ExitLetters, Settings.MaterialYellow); _menuObjects = new[] { menuTitle, menuOptions, menuStart, menuExit }; _mouseController = new MouseController(new[] { menuOptions, menuStart, menuExit }); _mouseController.OnChange += _mouseController_OnChange; _mouseController.OnMouseClick += _mouseController_OnMouseClick; _mouseController.OnMouseRelease += _mouseController_OnMouseRelease; _box = new BoundingBox(-400, -400, -100, 400, 400, 100); }
public DisplayElementSectionsComponent() : base("DisplayElementSectionsComponent", "DES", "Displays the element sections", "CIFem", "Results") { _bb = new BoundingBox(); _secCrvs = new List<Curve>(); _breps = new List<Brep>(); }
public DisplayThickVectors() : base("VectorDisplay", "VDisp", "Displays a vector with set thickness", "CIFem", "Utilities") { //_vectors = new List<Vector3d>(); _vectors = new List<DisplayVector>(); _bounds = BoundingBox.Unset; }
public static Karamba.Geometry.BoundingBox3 Convert( this Rhino.Geometry.BoundingBox box) { return(new Karamba.Geometry.BoundingBox3( box.Min.Convert(), box.Max.Convert())); }
protected override void DrawOverlay(Rhino.Display.DrawEventArgs e) { base.DrawOverlay(e); Rhino.Display.RhinoView myViewport = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView; Rhino.Display.RhinoViewport viewport = myViewport.ActiveViewport; for (int i = 0; i < Ids.Count; i++) { RhinoObject foundObject = Rhino.RhinoDoc.ActiveDoc.Objects.Find(Ids[i]); Rhino.Geometry.BoundingBox bbox = foundObject.Geometry.GetBoundingBox(true); Rhino.Geometry.Plane myFrustumPlane = new Rhino.Geometry.Plane(); //viewport.GetFrustumFarPlane(out myFrustumPlane); //myFrustumPlane.Origin = bbox.Center; //Rhino.Geometry.Circle myFrustumCircle = new Rhino.Geometry.Circle(); //myFrustumCircle.Plane = myFrustumPlane; //myFrustumCircle.Radius = bbox.Diagonal.Length / 2; //Rhino.Geometry.Curve myFrustumCurve = myFrustumCircle.ToNurbsCurve(); //myFrustumCurve.Domain = new Rhino.Geometry.Interval(0.0,1.0); //e.Display.DrawDot(myFrustumCurve.PointAtNormalizedLength(0.4), i.ToString(), System.Drawing.Color.Red, System.Drawing.Color.White); } Rhino.RhinoDoc.ActiveDoc.Views.Redraw(); }
/// <summary> /// Initializes a new Box that mimics a BoundingBox struct. /// <para>The orientation plane of the Box is coincident with the /// World XY plane.</para> /// </summary> /// <param name="bbox">BoundingBox to mimic.</param> public Box(BoundingBox bbox) { m_plane = Plane.WorldXY; m_dx = new Interval(bbox.m_min.m_x, bbox.m_max.m_x); m_dy = new Interval(bbox.m_min.m_y, bbox.m_max.m_y); m_dz = new Interval(bbox.m_min.m_z, bbox.m_max.m_z); }
/// <summary> /// Makes a plane that includes a line and a vector and goes through a bounding box. /// </summary> /// <param name="lineInPlane">A line that will lie on the plane.</param> /// <param name="vectorInPlane">A vector the direction of which will be in plane.</param> /// <param name="box">A box to cut through.</param> /// <returns>A new plane surface on success, or null on error.</returns> public static PlaneSurface CreateThroughBox(Line lineInPlane, Vector3d vectorInPlane, BoundingBox box) { IntPtr ptr = UnsafeNativeMethods.RHC_RhinoPlaneThroughBox(ref lineInPlane, vectorInPlane, ref box); if (IntPtr.Zero == ptr) return null; return new PlaneSurface(ptr, null); }
private static bool CheckBoxInOther(BoundingBox box1, BoundingBox box2) { return CheckIntervals(box1.Min.X, box2.Min.X, box2.Max.X) || CheckIntervals(box1.Max.X, box2.Min.X, box2.Max.X) || CheckIntervals(box1.Min.Y, box2.Min.Y, box2.Max.Y) || CheckIntervals(box1.Max.Y, box2.Min.Y, box2.Max.Y); }
static public Rhino.Geometry.BoundingBox ToRhino(this BoundingBoxXYZ bbox) { if (bbox?.Enabled ?? false) { var box = new Rhino.Geometry.BoundingBox(bbox.Min.ToRhino(), bbox.Max.ToRhino()); return(bbox.Transform.ToRhino().TransformBoundingBox(box)); } return(Rhino.Geometry.BoundingBox.Empty); }
protected override void CalculateBoundingBox(Rhino.Display.CalculateBoundingBoxEventArgs e) { if (null != Mesh) { Rhino.Geometry.BoundingBox bbox = Mesh.GetBoundingBox(false); // Unites a bounding box with the current display bounding box in // order to ensure dynamic objects in "box" are drawn. e.IncludeBoundingBox(bbox); } }
public DrawBlueMeshConduit(Mesh mesh) { // set up as much data as possible so we do the minimum amount of work possible inside // the actual display code m_mesh = mesh; m_color = System.Drawing.Color.Blue; m_material = new DisplayMaterial(); m_material.Diffuse = m_color; if (m_mesh != null && m_mesh.IsValid) m_bbox = m_mesh.GetBoundingBox(true); }
public DisplayResultElementsComponent() : base("DisplayElementResults", "ER", "Displays the element results", "CIFem", "Results") { _bb = new BoundingBox(); _bbPts = new List<Point3d>(); _dispCrvN = new List<Curve>(); _dispCrvVy = new List<Curve>(); _dispCrvVz = new List<Curve>(); _dispCrvT = new List<Curve>(); _dispCrvMyy = new List<Curve>(); _dispCrvMzz = new List<Curve>(); }
void DisplayPipeline_CalculateBoundingBox(object sender, Rhino.Display.CalculateBoundingBoxEventArgs e) { if (m_draw_single_sprite) { BoundingBox bbox = new BoundingBox(new Point3d(20, 0, 0), new Point3d(20, 0, 0)); e.IncludeBoundingBox(bbox); } else { var items = GetItems(); e.IncludeBoundingBox(items.BoundingBox); } }
public static Rhino.Commands.Result AddBrepBox(Rhino.RhinoDoc doc) { Rhino.Geometry.Point3d pt0 = new Rhino.Geometry.Point3d(0, 0, 0); Rhino.Geometry.Point3d pt1 = new Rhino.Geometry.Point3d(10, 10, 10); Rhino.Geometry.BoundingBox box = new Rhino.Geometry.BoundingBox(pt0, pt1); Rhino.Geometry.Brep brep = box.ToBrep(); Rhino.Commands.Result rc = Rhino.Commands.Result.Failure; if( doc.Objects.AddBrep(brep) != System.Guid.Empty ) { rc = Rhino.Commands.Result.Success; doc.Views.Redraw(); } return rc; }
public void SpreadObjects(double step, Boolean refresh) { if (myDisplayBool == null) { } else { Rhino.Display.RhinoView myViewport = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView; Rhino.Display.RhinoViewport viewport = myViewport.ActiveViewport; //viewport.DisplayMode = Rhino.Display.DisplayModeDescription.FindByName("Wireframe"); Rhino.Geometry.BoundingBox myGlobalBbox = new Rhino.Geometry.BoundingBox(); myGlobalBbox = Rhino.Geometry.BoundingBox.Empty; List <Rhino.Geometry.Point3d> myCentroids = new List <Rhino.Geometry.Point3d>(); //myCentroids.Clear(); //Rhino.Geometry.Point3d explosionCenter; // First iteration: find initial object and initial bounding box center if (originalCentroids.Count == 0 || refresh == true) { myCentroids.Clear(); foreach (Guid guid in allGuids) { RhinoObject foundObject = Rhino.RhinoDoc.ActiveDoc.Objects.Find(guid); Rhino.Geometry.BoundingBox foundBbox = foundObject.Geometry.GetBoundingBox(true); myGlobalBbox.Union(foundBbox); myCentroids.Add(foundBbox.Center); explosionCenter = myGlobalBbox.Center; } originalCentroids = myCentroids; } else { for (int i = 0; i < allGuids.Count; i++) { RhinoObject foundObject = Rhino.RhinoDoc.ActiveDoc.Objects.Find(allGuids[i]); Rhino.Geometry.Vector3d trans = explosionCenter - originalCentroids[i]; // Brings back to original position. Rhino.Geometry.Vector3d backTrans = originalCentroids[i] - foundObject.Geometry.GetBoundingBox(true).Center; trans.Unitize(); Rhino.RhinoDoc.ActiveDoc.Objects.Transform(foundObject, Rhino.Geometry.Transform.Translation(backTrans - Rhino.Geometry.Vector3d.Multiply(step, trans)), true); Rhino.RhinoDoc.ActiveDoc.Views.Redraw(); } } } }
protected override void CalculateBoundingBoxZoomExtents(CalculateBoundingBoxEventArgs e) { Rhino.Geometry.BoundingBox bbox = Rhino.Geometry.BoundingBox.Unset; if (null != Geometry) { var localCopy = Geometry.ToList(); foreach (var obj in localCopy) { if (obj != null) { try { bbox.Union(obj.GetBoundingBox(false)); } catch { } } } e.IncludeBoundingBox(bbox); } }
public Rh.Rectangle3d GetBoundary() { List <Rh.Point3d> points = new List <Rh.Point3d>(); foreach (Shape shape in this.Shapes) { foreach (Rh.Curve curve in shape.Curves) { Rh.BoundingBox box = curve.GetBoundingBox(true); points.Add(box.Min); points.Add(box.Max); } } Rh.BoundingBox bbox = new Rh.BoundingBox(points); return(new Rh.Rectangle3d(Rh.Plane.WorldXY, new Rh.Point3d(bbox.Min.X, bbox.Min.Y, 0), new Rh.Point3d(bbox.Max.X, bbox.Max.Y, 0))); }
/***************************************************/ private static bool IsSameEdge(this RHG.Curve curve, RHG.BrepEdge edge) { double tolerance = BHG.Tolerance.Distance; RHG.Curve edgeCurve = edge.DuplicateCurve(); edgeCurve.Reverse(); RHG.BoundingBox bb1 = curve.GetBoundingBox(false); RHG.BoundingBox bb2 = edgeCurve.GetBoundingBox(false); if (bb1.Min.DistanceTo(bb2.Min) > tolerance || bb1.Max.DistanceTo(bb2.Max) > tolerance) { return(false); } int frameCount = 100; RHG.Point3d[] frames1, frames2; curve.DivideByCount(frameCount, false, out frames1); edgeCurve.DivideByCount(frameCount, false, out frames2); return(Enumerable.Range(0, frameCount - 1).All(i => frames1[i].DistanceTo(frames2[i]) <= tolerance)); }
/// <summary> /// Unites a bounding box with the current display bounding box in order to ensure /// dynamic objects in "box" are drawn. /// </summary> /// <param name="box">The box to unite.</param> public void IncludeBoundingBox(BoundingBox box) { m_bbox.Union(box); UnsafeNativeMethods.CChannelAttr_GetSetBBox(m_pDisplayConduit, true, ref m_bbox); }
/// <summary> /// Test a given box for visibility inside the view frustum under the current /// viewport and model transformation settings. /// </summary> /// <param name="bbox">Box to test for visibility.</param> /// <returns>true if at least some portion of the box is visible, false if not.</returns> public bool IsVisible(BoundingBox bbox) { return UnsafeNativeMethods.CRhinoDisplayPipeline_IsVisible2(m_ptr, ref bbox); }
/***************************************************/ /**** Public Methods - Miscellanea ****/ /***************************************************/ public static void RenderRhinoWires(RHG.BoundingBox bbBox, Rhino.Display.DisplayPipeline pipeline, Color bhColour, int thickness) { pipeline.DrawBox(bbBox, bhColour, thickness); }
/// <summary> /// Draws corner widgets of a world aligned boundingbox. /// </summary> /// <param name="box">Box to draw.</param> /// <param name="color">Color to draw with.</param> /// <param name="size">Size (in model units) of the corner widgets.</param> /// <param name="thickness">Thickness (in pixels) of the corner widgets.</param> public void DrawBoxCorners(BoundingBox box, System.Drawing.Color color, double size, int thickness) { if (!box.IsValid) { return; } // Size of box in all directions. double dx = box.m_max.m_x - box.m_min.m_x; double dy = box.m_max.m_y - box.m_min.m_y; double dz = box.m_max.m_z - box.m_min.m_z; // Singleton flags for all directions. bool fx = dx < 1e-6; bool fy = dy < 1e-6; bool fz = dz < 1e-6; // Singular box, don't draw. if (fx && fy && fz) { return; } // Linear box, don't draw. if (fx && fy) { return; } if (fx && fz) { return; } if (fy && fz) { return; } Point3d[] c = box.GetCorners(); // Draw edges parallel to world Xaxis. if (dx > 1e-6) { if ((2.0 * size) >= dx) { // Draw single connecting wires. DrawLine(c[0], c[1], color, thickness); DrawLine(c[3], c[2], color, thickness); DrawLine(c[4], c[5], color, thickness); DrawLine(c[7], c[6], color, thickness); } else { // Draw corner widgets. DrawLine(c[0], new Point3d(c[0].m_x + size, c[0].m_y, c[0].m_z), color, thickness); DrawLine(c[3], new Point3d(c[3].m_x + size, c[3].m_y, c[3].m_z), color, thickness); DrawLine(c[4], new Point3d(c[4].m_x + size, c[4].m_y, c[4].m_z), color, thickness); DrawLine(c[7], new Point3d(c[7].m_x + size, c[7].m_y, c[7].m_z), color, thickness); DrawLine(c[1], new Point3d(c[1].m_x - size, c[1].m_y, c[1].m_z), color, thickness); DrawLine(c[2], new Point3d(c[2].m_x - size, c[2].m_y, c[2].m_z), color, thickness); DrawLine(c[5], new Point3d(c[5].m_x - size, c[5].m_y, c[5].m_z), color, thickness); DrawLine(c[6], new Point3d(c[6].m_x - size, c[6].m_y, c[6].m_z), color, thickness); } } // Draw edges parallel to world Yaxis. if (dy > 1e-6) { if ((2.0 * size) >= dy) { // Draw single connecting wires. DrawLine(c[0], c[3], color, thickness); DrawLine(c[1], c[2], color, thickness); DrawLine(c[4], c[7], color, thickness); DrawLine(c[5], c[6], color, thickness); } else { // Draw corner widgets. DrawLine(c[0], new Point3d(c[0].m_x, c[0].m_y + size, c[0].m_z), color, thickness); DrawLine(c[1], new Point3d(c[1].m_x, c[1].m_y + size, c[1].m_z), color, thickness); DrawLine(c[4], new Point3d(c[4].m_x, c[4].m_y + size, c[4].m_z), color, thickness); DrawLine(c[5], new Point3d(c[5].m_x, c[5].m_y + size, c[5].m_z), color, thickness); DrawLine(c[2], new Point3d(c[2].m_x, c[2].m_y - size, c[2].m_z), color, thickness); DrawLine(c[3], new Point3d(c[3].m_x, c[3].m_y - size, c[3].m_z), color, thickness); DrawLine(c[6], new Point3d(c[6].m_x, c[6].m_y - size, c[6].m_z), color, thickness); DrawLine(c[7], new Point3d(c[7].m_x, c[7].m_y - size, c[7].m_z), color, thickness); } } // Draw edges parallel to world Zaxis. if (dz > 1e-6) { if ((2.0 * size) >= dz) { // Draw single connecting wires. DrawLine(c[0], c[4], color, thickness); DrawLine(c[1], c[5], color, thickness); DrawLine(c[2], c[6], color, thickness); DrawLine(c[3], c[7], color, thickness); } else { // Draw corner widgets. DrawLine(c[0], new Point3d(c[0].m_x, c[0].m_y, c[0].m_z + size), color, thickness); DrawLine(c[1], new Point3d(c[1].m_x, c[1].m_y, c[1].m_z + size), color, thickness); DrawLine(c[2], new Point3d(c[2].m_x, c[2].m_y, c[2].m_z + size), color, thickness); DrawLine(c[3], new Point3d(c[3].m_x, c[3].m_y, c[3].m_z + size), color, thickness); DrawLine(c[4], new Point3d(c[4].m_x, c[4].m_y, c[4].m_z - size), color, thickness); DrawLine(c[5], new Point3d(c[5].m_x, c[5].m_y, c[5].m_z - size), color, thickness); DrawLine(c[6], new Point3d(c[6].m_x, c[6].m_y, c[6].m_z - size), color, thickness); DrawLine(c[7], new Point3d(c[7].m_x, c[7].m_y, c[7].m_z - size), color, thickness); } } }
/***************************************************/ /**** Public Methods - Miscellanea ****/ /***************************************************/ public static RHG.Mesh CreatePreviewMesh(RHG.BoundingBox bbBox, RHG.MeshingParameters parameters) { return(CreatePreviewMesh(bbBox.ToBrep(), parameters)); }
/// <summary> /// Makes a plane that includes a line and a vector and goes through a bounding box. /// </summary> /// <param name="lineInPlane">A line that will lie on the plane.</param> /// <param name="vectorInPlane">A vector the direction of which will be in plane.</param> /// <param name="box">A box to cut through.</param> /// <returns>A new plane surface on success, or null on error.</returns> public static PlaneSurface CreateThroughBox(Line lineInPlane, Vector3d vectorInPlane, BoundingBox box) { IntPtr ptr = UnsafeNativeMethods.RHC_RhinoPlaneThroughBox(ref lineInPlane, vectorInPlane, ref box); if (IntPtr.Zero == ptr) { return(null); } return(new PlaneSurface(ptr, null)); }
public BoundingBox bboxAll(List<Brep> things) { //Find the bounding box of a list of objects BoundingBox bbox; Point3d maxPt = new Point3d(0, 0, 0); Point3d minPt = new Point3d(0, 0, 0); foreach (Brep thing in things) { BoundingBox b_box = thing.GetBoundingBox(Plane.WorldXY); if (b_box.Max.X > maxPt.X && b_box.Max.Y > maxPt.Y && b_box.Max.Z > maxPt.Z) { maxPt = b_box.Max; } if (b_box.Min.X < minPt.X && b_box.Min.Y < minPt.Y && b_box.Min.Z < minPt.Z) { minPt = b_box.Min; } } bbox = new BoundingBox(minPt, maxPt); return bbox; }
/// <summary>Inserts an element into the tree.</summary> /// <param name="box">A bounding box.</param> /// <param name="elementId">A number.</param> /// <returns>true if element was successfully inserted.</returns> public bool Insert(BoundingBox box, int elementId) { return(Insert(box, new IntPtr(elementId))); }
/// <summary> /// Searches for items in a bounding box. /// <para>The bounding box can be singular and contain exactly one single point.</para> /// </summary> /// <param name="box">A bounding box.</param> /// <param name="callback">An event handler to be raised when items are found.</param> /// <returns> /// true if entire tree was searched. It is possible no results were found. /// </returns> public bool Search(BoundingBox box, EventHandler <RTreeEventArgs> callback) { return(Search(box, callback, null)); }
protected override void CalculateBoundingBox(CalculateBoundingBoxEventArgs e) { base.CalculateBoundingBox(e); RC.BoundingBox bBox = ToRC.Convert(Core.Instance.ActiveDocument.Model.BoundingBox); e.IncludeBoundingBox(bBox); }
protected override void PreDrawObjects(Rhino.Display.DrawEventArgs e) { base.PreDrawObjects(e); RhinoObject foundObject = Rhino.RhinoDoc.ActiveDoc.Objects.Find(Id); Rhino.Geometry.BoundingBox bbox = foundObject.Geometry.GetBoundingBox(true); bbox.Inflate(2); e.Display.EnableDepthWriting(false); List <Rhino.Geometry.Point3d> bboxCorners = bbox.GetCorners().ToList(); List <Rhino.Geometry.Line> bboxEdges = bbox.GetEdges().ToList(); //e.Display.DrawBoxCorners(bbox, System.Drawing.Color.Red, 3, 4); Rhino.Display.RhinoView myViewport = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView; Rhino.Display.RhinoViewport viewport = myViewport.ActiveViewport; e.Display.EnableDepthWriting(true); e.Display.EnableDepthWriting(false); switch (foundObject.ObjectType) { case Rhino.DocObjects.ObjectType.Point: e.Display.DrawPoint(((Rhino.Geometry.Point)foundObject.Geometry).Location, PointStyle.X, 2, myCol); break; case Rhino.DocObjects.ObjectType.Curve: e.Display.DrawCurve((Rhino.Geometry.Curve)foundObject.Geometry, myCol, 4); break; case Rhino.DocObjects.ObjectType.Extrusion: DisplayMaterial eMaterial = new DisplayMaterial(myCol, 0.5); e.Display.DrawBrepShaded(((Rhino.Geometry.Extrusion)foundObject.Geometry).ToBrep(), eMaterial); break; case Rhino.DocObjects.ObjectType.Brep: DisplayMaterial bMaterial = new DisplayMaterial(myCol, 0.5); e.Display.DrawBrepShaded((Brep)foundObject.Geometry, bMaterial); Mesh[] meshes = Rhino.Geometry.Mesh.CreateFromBrep((Brep)foundObject.Geometry); Mesh globalMesh = new Rhino.Geometry.Mesh(); foreach (Mesh m in meshes) { globalMesh.Append(m); } Polyline[] myPolys2 = globalMesh.GetOutlines(viewport); foreach (Polyline poly in myPolys2) { e.Display.DrawCurve(poly.ToNurbsCurve(), Color.Black, 6); } break; case Rhino.DocObjects.ObjectType.Mesh: var mesh = foundObject.Geometry as Rhino.Geometry.Mesh; if (mesh.VertexColors.Count > 0) { for (int i = 0; i < mesh.VertexColors.Count; i++) { mesh.VertexColors[i] = Color.FromArgb(100, mesh.VertexColors[i]); } e.Display.DrawMeshFalseColors(mesh); } else { DisplayMaterial mMaterial = new DisplayMaterial(myCol, 0.5); e.Display.DrawMeshShaded(mesh, mMaterial); } //e.Display.DrawMeshWires((Mesh)obj, Color.DarkGray); break; case Rhino.DocObjects.ObjectType.TextDot: //e.Display.Draw3dText( ((TextDot)obj).Text, Colors[count], new Plane(((TextDot)obj).Point)); var textDot = (TextDot)foundObject.Geometry; e.Display.DrawDot(textDot.Point, textDot.Text, myCol, Color.White); break; case Rhino.DocObjects.ObjectType.Annotation: var textObj = (Rhino.Geometry.TextEntity)foundObject.Geometry; e.Display.Draw3dText(textObj.Text, Color.Black, textObj.Plane, textObj.TextHeight, Rhino.RhinoDoc.ActiveDoc.Fonts[textObj.FontIndex].FaceName); break; } e.Display.EnableDepthWriting(true); List <Rhino.Geometry.Line> myEdges = new List <Rhino.Geometry.Line>(); if (Edges.Count > 0) { System.Drawing.Color colorKid = System.Drawing.Color.LightCoral; foreach (List <Guid> li in Edges) { RhinoObject foundObject0 = Rhino.RhinoDoc.ActiveDoc.Objects.Find(li[0]); RhinoObject foundObject1 = Rhino.RhinoDoc.ActiveDoc.Objects.Find(li[1]); } } Rhino.RhinoDoc.ActiveDoc.Views.Redraw(); }
public static BoundingBox3D AsBoundingBoxXYZ(Rhino.Geometry.BoundingBox value) { return(new BoundingBox3D(AsXYZ(value.Min), AsXYZ(value.Max))); }
/***************************************************/ /**** Public Methods - Surfaces ****/ /***************************************************/ public static BHG.BoundingBox FromRhino(this RHG.BoundingBox boundingBox) { return(new BHG.BoundingBox { Min = boundingBox.Min.FromRhino(), Max = boundingBox.Max.FromRhino() }); }
//bool SetCenter(const ON_3dPoint& center); public bool SetFromBoundingBox(BoundingBox boundingBox) { IntPtr pThis = NonConstPointer(); return UnsafeNativeMethods.CRhinoGumball_SetFromBoundingBox(pThis, boundingBox.Min, boundingBox.Max); }
/// <summary> /// Returns true if some portion of a world coordinate bounding box is /// potentially visible in the viewing frustum. /// </summary> /// <param name="bbox">A bounding box that is tested for visibility.</param> /// <returns>true if the box is potentially visible; otherwise false.</returns> public bool IsVisible(BoundingBox bbox) { IntPtr ptr = NonConstPointer(); return UnsafeNativeMethods.CRhinoViewport_IsVisible(ptr, bbox.Min, bbox.Max, true); }
/// <summary> /// Sets the gumball bounding box with respect to a frame. /// </summary> /// <param name="frame">The frame.</param> /// <param name="frameBoundingBox">Bounding box with respect to frame.</param> /// <returns> /// true if input is valid and gumball is set. false if input is not valid. /// In this case, gumball is set to the default. /// </returns> public bool SetFromBoundingBox(Plane frame, BoundingBox frameBoundingBox) { IntPtr pThis = NonConstPointer(); return UnsafeNativeMethods.CRhinoGumball_SetFromBoundingBox2(pThis, ref frame, frameBoundingBox.Min, frameBoundingBox.Max); }
public BoundingBox GetCameraExtents(System.Collections.Generic.IEnumerable<Point3d> points) { Rhino.Collections.Point3dList _points = new Collections.Point3dList(points); IntPtr pConstThis = ConstPointer(); IntPtr pConstViewport = UnsafeNativeMethods.CRhinoViewport_VP(pConstThis); BoundingBox bbox = new BoundingBox(); UnsafeNativeMethods.ON_Viewport_GetCameraExtents(pConstViewport, _points.Count, _points.m_items, ref bbox); return bbox; }
protected override void SolveInstance(IGH_DataAccess DA) { if (DA.Iteration == 0) { _vectors = new List<DisplayVector>(); _bounds = BoundingBox.Unset; } Point3d point = Point3d.Unset; Vector3d vector = Vector3d.Unset; Color colour = Color.Black; int width = 1; if (!DA.GetData(0, ref point)) { return; } if (!DA.GetData(1, ref vector)) { return; } if (!DA.GetData(2, ref colour)) { return; } if (!DA.GetData(3, ref width)) { return; } DisplayVector dispVec = new DisplayVector(); dispVec.Colour = colour; dispVec.Point = point; dispVec.Vector = vector; dispVec.Width = width; _vectors.Add(dispVec); _bounds.Union(point); _bounds.Union((Point3d)(point + vector)); }
/// <summary> /// Dolly the camera location and so that the view frustum contains /// all of the document objects that can be seen in view. /// If the projection is perspective, the camera angle is not changed. /// </summary> /// <param name="cameraCoordinateBoundingBox"></param> /// <param name="border"> /// If border > 1.0, then the fustum in enlarged by this factor /// to provide a border around the view. 1.1 works well for /// parallel projections; 0.0 is suggested for perspective projections. /// </param> /// <returns>True if successful.</returns> public bool DollyExtents(BoundingBox cameraCoordinateBoundingBox, double border) { bool rc = false; if (cameraCoordinateBoundingBox.IsValid) { if (border > 1.0 && RhinoMath.IsValidDouble(border)) { double dx = cameraCoordinateBoundingBox.Max.X - cameraCoordinateBoundingBox.Min.X; dx *= 0.5 * (border - 1.0); double dy = cameraCoordinateBoundingBox.Max.Y - cameraCoordinateBoundingBox.Min.Y; dy *= 0.5 * (border - 1.0); var pt = cameraCoordinateBoundingBox.Max; cameraCoordinateBoundingBox.Max = new Point3d(pt.X + dx, pt.Y + dy, pt.Z); pt = cameraCoordinateBoundingBox.Min; cameraCoordinateBoundingBox.Min = new Point3d(pt.X - dx, pt.Y - dy, pt.Z); } IntPtr ptr_this = NonConstPointer(); rc = UnsafeNativeMethods.ON_Viewport_DollyExtents(ptr_this, cameraCoordinateBoundingBox.Min, cameraCoordinateBoundingBox.Max); } return rc; }
/// <summary> /// Boundingbox solver. Gets the world axis aligned boundingbox for the geometry. /// </summary> /// <param name="accurate">If true, a physically accurate boundingbox will be computed. /// If not, a boundingbox estimate will be computed. For some geometry types there is no /// difference between the estimate and the accurate boundingbox. Estimated boundingboxes /// can be computed much (much) faster than accurate (or "tight") bounding boxes. /// Estimated bounding boxes are always similar to or larger than accurate bounding boxes.</param> /// <returns> /// The boundingbox of the geometry in world coordinates or BoundingBox.Empty /// if not bounding box could be found. /// </returns> /// <example> /// <code source='examples\vbnet\ex_curveboundingbox.vb' lang='vbnet'/> /// <code source='examples\cs\ex_curveboundingbox.cs' lang='cs'/> /// <code source='examples\py\ex_curveboundingbox.py' lang='py'/> /// </example> public BoundingBox GetBoundingBox(bool accurate) { #if RHINO_SDK Rhino.DocObjects.RhinoObject parent_object = ParentRhinoObject(); #endif if (accurate) { BoundingBox bbox = new BoundingBox(); Transform xf = new Transform(); #if RHINO_SDK if (null != parent_object) { IntPtr pParentObject = parent_object.ConstPointer(); if (UnsafeNativeMethods.CRhinoObject_GetTightBoundingBox(pParentObject, ref bbox, ref xf, false)) return bbox; } #endif IntPtr ptr = ConstPointer(); return UnsafeNativeMethods.ON_Geometry_GetTightBoundingBox(ptr, ref bbox, ref xf, false) ? bbox : BoundingBox.Empty; } else { BoundingBox rc = new BoundingBox(); #if RHINO_SDK if (null != parent_object) { IntPtr pParentObject = parent_object.ConstPointer(); if (UnsafeNativeMethods.CRhinoObject_BoundingBox(pParentObject, ref rc)) return rc; } #endif IntPtr ptr = ConstPointer(); UnsafeNativeMethods.ON_Geometry_BoundingBox(ptr, ref rc); return rc; } }
/***************************************************/ /**** Public Methods - Miscellanea ****/ /***************************************************/ public static void RenderRhinoMeshes(RHG.BoundingBox bbBox, Rhino.Display.DisplayPipeline pipeline, DisplayMaterial material) { pipeline.DrawBrepShaded(bbBox.ToBrep(), material); }
/// <summary> /// Gets near and far clipping distances of a bounding box. /// </summary> /// <param name="bbox">The bounding box.</param> /// <param name="nearDistance">The near distance is assigned to this out parameter during this call.</param> /// <param name="farDistance">The far distance is assigned to this out parameter during this call.</param> /// <returns> /// true if the bounding box intersects the view frustum and near_dist/far_dist were set. /// false if the bounding box does not intesect the view frustum. /// </returns> public bool GetDepth(BoundingBox bbox, out double nearDistance, out double farDistance) { IntPtr ptr = ConstPointer(); nearDistance = farDistance = 0; return UnsafeNativeMethods.CRhinoViewport_VP_GetDepth2(ptr, bbox.m_min, bbox.m_max, ref nearDistance, ref farDistance); }
/// <summary>Removes an element from the tree.</summary> /// <param name="box">A bounding box.</param> /// <param name="elementId">A number.</param> /// <returns>true if element was successfully removed.</returns> public bool Remove(BoundingBox box, int elementId) { return(Remove(box, new IntPtr(elementId))); }
/// <summary> /// Sets optimal clipping planes to view objects in a world coordinate 3d bounding box. /// </summary> /// <param name="box">The bounding box </param> public void SetClippingPlanes(BoundingBox box) { IntPtr pThis = NonConstPointer(); UnsafeNativeMethods.CRhinoViewport_SetClippingPlanes(pThis, box.Min, box.Max); }
/// <summary> /// Draws the edges of a BoundingBox. /// </summary> /// <param name="box">Box to draw.</param> /// <param name="color">Color to draw in.</param> /// <param name="thickness">Thickness (in pixels) of box edges.</param> public void DrawBox(BoundingBox box, System.Drawing.Color color, int thickness) { int argb = color.ToArgb(); UnsafeNativeMethods.CRhinoDisplayPipeline_DrawBox(m_ptr, box.m_min, box.m_max, argb, thickness); }
/// <summary> /// Zooms the viewport to the given bounding box. /// </summary> /// <param name="box">The bouding box to zoom.</param> /// <returns>true if operation succeeded; otherwise false.</returns> public bool ZoomBoundingBox(BoundingBox box) { IntPtr pThis = NonConstPointer(); return UnsafeNativeMethods.RHC_RhZoomExtentsHelper(pThis, box.m_min, box.m_max); }
/// <summary> /// Draws corner widgets of a world aligned boundingbox. /// Widget size will be 5% of the Box diagonal. /// </summary> /// <param name="box">Box to draw.</param> /// <param name="color">Color to draw with.</param> public void DrawBoxCorners(BoundingBox box, System.Drawing.Color color) { double diag = box.m_min.DistanceTo(box.m_max); DrawBoxCorners(box, color, 0.05 * diag, 1); }
protected override void SolveInstance(IGH_DataAccess DA) { // Clear lists _dispCrvN.Clear(); _dispCrvVy.Clear(); _dispCrvVz.Clear(); _dispCrvT.Clear(); _dispCrvMyy.Clear(); _dispCrvMzz.Clear(); _bbPts.Clear(); ////// INDATA ////// List<ResultElement> res = new List<ResultElement>(); List<bool> dispToggles = new List<bool>(); List<double> sFacs = new List<double>(); string name = null; // Result element if (!DA.GetDataList(0, res)) { return; } // Display toggles if (!DA.GetDataList(1, dispToggles)) { return; } if (dispToggles.Count != 6) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Number of bools in input should be 6"); return; } // Scaling factors if (!DA.GetDataList(2, sFacs)) { return; } bool sFacInputCorrect = false; if (sFacs.Count == 6) sFacInputCorrect = true; else if (sFacs.Count == 1) { sFacs.AddRange(new List<double> { sFacs[0], sFacs[0], sFacs[0], sFacs[0], sFacs[0] }); sFacInputCorrect = true; } if (!sFacInputCorrect) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Number of scale factors in input should be 1 or 6"); return; } if (!DA.GetData(3, ref name)) { if (res.Count > 0) { name = res[0].N1.First().Key; } } // Now it is assumed that all inputs are correct // Get toggles and scaling factors bool bN = dispToggles[0]; double sfN = sFacs[0]; bool bVy = dispToggles[1]; double sfVy = sFacs[1]; bool bVz = dispToggles[2]; double sfVz = sFacs[2]; bool bT = dispToggles[3]; double sfT = sFacs[3]; bool bMyy = dispToggles[4]; double sfMyy = sFacs[4]; bool bMzz = dispToggles[5]; double sfMzz = sFacs[5]; foreach (ResultElement re in res) { // Get element orientation Vector3d elX = re.LocalX; Vector3d elY = re.LocalY; Vector3d elZ = re.elNormal; ////// START DRAWING STUFF ////// // Normal force if (bN) _dispCrvN.AddRange(CreateCurvesFromResults(re, re.N1[name], elZ, sfN)); // Shear force in weak direction if (bVy) _dispCrvVy.AddRange(CreateCurvesFromResults(re, re.Vy[name], elY, sfVy)); // Shear force in strong direction if (bVz) _dispCrvVz.AddRange(CreateCurvesFromResults(re, re.Vz[name], elZ, sfVz)); // Torsion if (bT) _dispCrvT.AddRange(CreateCurvesFromResults(re, re.T[name], elZ, sfT)); // Moment around minor axis (bending in strong direction) if (bMyy) _dispCrvMyy.AddRange(CreateCurvesFromResults(re, re.My[name], elZ, sfMyy)); // Moment around major axis (bending in weak direction) if (bMzz) _dispCrvMzz.AddRange(CreateCurvesFromResults(re, re.Mz[name], elY, sfMzz)); } // Set bounding box _bb = new BoundingBox(_bbPts); _bb.Inflate(1.2); //Increase size by 20% to include all parts of all curves }
/// <summary> /// Draws corner widgets of a world aligned boundingbox. /// </summary> /// <param name="box">Box to draw.</param> /// <param name="color">Color to draw with.</param> /// <param name="size">Size (in model units) of the corner widgets.</param> public void DrawBoxCorners(BoundingBox box, System.Drawing.Color color, double size) { DrawBoxCorners(box, color, size, 1); }
/// <summary> /// Determines if a 2d bounding box is iso-parameteric in the parameter space of this surface. /// </summary> /// <param name="bbox">Bounding box to test.</param> /// <returns>IsoStatus flag describing the iso-parametric relationship between the surface and the bounding box.</returns> public IsoStatus IsIsoparametric(BoundingBox bbox) { IntPtr ptr = ConstPointer(); int rc = UnsafeNativeMethods.ON_Surface_IsIsoparametric2(ptr, bbox.Min, bbox.Max); return (IsoStatus)rc; }
protected override void PreDrawObjects(Rhino.Display.DrawEventArgs e) { base.PreDrawObjects(e); for (int i = 0; i < Ids.Count; i++) { RhinoObject foundObject = Rhino.RhinoDoc.ActiveDoc.Objects.Find(Ids[i]); Rhino.Geometry.BoundingBox bbox = foundObject.Geometry.GetBoundingBox(true); bbox.Inflate(2); e.Display.EnableDepthWriting(false); //e.Display.DrawBoxCorners(bbox, System.Drawing.Color.DarkGray, 3, 2); e.Display.EnableDepthWriting(true); switch (foundObject.ObjectType) { case Rhino.DocObjects.ObjectType.Point: e.Display.DrawPoint(((Rhino.Geometry.Point)foundObject.Geometry).Location, PointStyle.X, 2, myCol); break; case Rhino.DocObjects.ObjectType.Curve: e.Display.DrawCurve((Rhino.Geometry.Curve)foundObject.Geometry, myCol, 3); break; case Rhino.DocObjects.ObjectType.Extrusion: DisplayMaterial eMaterial = new DisplayMaterial(myCol, 0.5); e.Display.DrawBrepShaded(((Rhino.Geometry.Extrusion)foundObject.Geometry).ToBrep(), eMaterial); break; case Rhino.DocObjects.ObjectType.Brep: DisplayMaterial bMaterial = new DisplayMaterial(myCol, 0.5); e.Display.DrawBrepShaded((Brep)foundObject.Geometry, bMaterial); break; case Rhino.DocObjects.ObjectType.Mesh: var mesh = foundObject.Geometry as Rhino.Geometry.Mesh; if (mesh.VertexColors.Count > 0) { for (int j = 0; j < mesh.VertexColors.Count; j++) { mesh.VertexColors[j] = Color.FromArgb(100, mesh.VertexColors[j]); } e.Display.DrawMeshFalseColors(mesh); } else { DisplayMaterial mMaterial = new DisplayMaterial(myCol, 0.5); e.Display.DrawMeshShaded(mesh, mMaterial); } //e.Display.DrawMeshWires((Mesh)obj, Color.DarkGray); break; case Rhino.DocObjects.ObjectType.TextDot: //e.Display.Draw3dText( ((TextDot)obj).Text, Colors[count], new Plane(((TextDot)obj).Point)); var textDot = (TextDot)foundObject.Geometry; e.Display.DrawDot(textDot.Point, textDot.Text, myCol, Color.White); break; case Rhino.DocObjects.ObjectType.Annotation: var textObj = (Rhino.Geometry.TextEntity)foundObject.Geometry; e.Display.Draw3dText(textObj.Text, Color.Black, textObj.Plane, textObj.TextHeight, Rhino.RhinoDoc.ActiveDoc.Fonts[textObj.FontIndex].FaceName); break; } } Rhino.RhinoDoc.ActiveDoc.Views.Redraw(); }