/// <summary> /// Returns the maximize BoundinBox by the vector size. /// </summary> /// <param name="boundingBox"></param> /// <param name="vectorSize"></param> /// <returns></returns> public static DS.BoundingBox MaxBoundingBox(DS.BoundingBox boundingBox, DS.Vector vectorSize) { return(DS.BoundingBox.ByCorners( MaxMinBound(Math.Floor, boundingBox.MinPoint, vectorSize), MaxMinBound(Math.Ceiling, boundingBox.MaxPoint, vectorSize) )); }
/// <summary> /// Divides a BoundingBox into a grid of voxels. /// </summary> /// <param name="boundingBox"></param> /// <param name="vectorSize"></param> /// <returns></returns> public static List <DS.Point> BoundingBoxToVoxels(DS.BoundingBox boundingBox, DS.Vector vectorSize) { DS.Point minPt = boundingBox.MinPoint; List <DS.Point> VoxelPoints = new List <DS.Point>(); using (DS.Vector diagonal = DS.Vector.ByTwoPoints(boundingBox.MinPoint, boundingBox.MaxPoint)) { int xMax = Convert.ToInt32(Math.Abs(diagonal.X / vectorSize.X)); int yMax = Convert.ToInt32(Math.Abs(diagonal.Y / vectorSize.Y)); int zMax = Convert.ToInt32(Math.Abs(diagonal.Z / vectorSize.Z)); var coordinates = from x in Enumerable.Range(0, xMax) from y in Enumerable.Range(0, yMax) from z in Enumerable.Range(0, zMax) select new { x, y, z }; foreach (var coord in coordinates) { double x = (coord.x * vectorSize.X + minPt.X) + vectorSize.X * 0.5; double y = (coord.y * vectorSize.Y + minPt.Y) + vectorSize.Y * 0.5; double z = (coord.z * vectorSize.Z + minPt.Z) + vectorSize.Z * 0.5; VoxelPoints.Add(DS.Point.ByCoordinates(x, y, z)); } } return(VoxelPoints); }
public Octree(MeshToolkit mesh, bool cubic = true) { this._mesh = mesh; this._cubic = cubic; //this.triangles = _mesh.Triangles(); this.vertices = _mesh.Vertices(); this.vertexIndexByTri = Core.List.Chop <int>(_mesh.VertexIndicesByTri(), 3); BoundingBox bbox = Graphical.Geometry.MeshToolkit.BoundingBox(this._mesh); // Extending the BoundingBox to be cubical from the centre. // Done by getting the max component of the Bounding box and translating min and max points outwards. // https://github.com/diwi/Space_Partitioning_Octree_BVH/blob/b7f66fe04e4af3b98ab9404363ab33f5dc1628a9/SpacePartitioning/src/DwOctree/Octree.java#L83 if (cubic) { using (Point center = Geometry.Point.MidPoint(bbox.MinPoint, bbox.MaxPoint)) { Vector bboxSize = Vector.ByTwoPoints(bbox.MinPoint, bbox.MaxPoint); Vector halfSize = bboxSize.Scale(0.5); double[] halfComponents = new double[3] { halfSize.X, halfSize.Y, halfSize.Z }; double maxComponent = halfComponents[getSubdivisionPlane(bbox)]; Vector expansionDirection = Vector.ByCoordinates(maxComponent, maxComponent, maxComponent); bbox = BoundingBox.ByCorners( (Point)center.Translate(-maxComponent, -maxComponent, -maxComponent), (Point)center.Translate(maxComponent, maxComponent, maxComponent) ); } } _root = new OctreeNode(0, bbox); }
internal bool AssureChildren(OctreeNode ot, int maxDepth) { if (ot.depth >= maxDepth) { return(false); } if (ot.isLeaf()) { ot.children = new OctreeNode[8]; // Half vector size, by scaling total diagonal or maybe faster creating the MidPoint? Vector halfSize = Vector.ByTwoPoints(ot.bbox.MinPoint, ot.bbox.MaxPoint).Scale(0.5); int childDepth = ot.depth + 1; for (int i = 0; i < ot.children.Count(); i++) { Point min = Point.ByCoordinates( ot.bbox.MinPoint.X + (((i & 4) > 0) ? halfSize.X : 0), ot.bbox.MinPoint.Y + (((i & 2) > 0) ? halfSize.Y : 0), ot.bbox.MinPoint.Z + (((i & 1) > 0) ? halfSize.Z : 0) ); Point max = (Point)min.Translate(halfSize); ot.children[i] = new OctreeNode(childDepth, BoundingBox.ByCorners(min, max)); } } return(true); }
/// <summary> /// Returns the maximum vector size for the given BoundingBox /// </summary> /// <param name="boundingBox"></param> /// <param name="vectorSize"></param> /// <returns name="vectorSize">Maximum vecotr size for the given BoundinBox</returns> public static DS.Vector MaxVectorSize(DS.BoundingBox boundingBox, DS.Vector vectorSize) { using (DS.Vector diagonal = DS.Vector.ByTwoPoints(boundingBox.MinPoint, boundingBox.MaxPoint)) { double x = diagonal.X / (Math.Ceiling(diagonal.X / vectorSize.X)); double y = diagonal.Y / (Math.Ceiling(diagonal.Y / vectorSize.Y)); double z = diagonal.Z / (Math.Ceiling(diagonal.Z / vectorSize.Z)); return(DS.Vector.ByCoordinates(x, y, z)); } }
/// <summary> /// Return the bounding surface of the input surface /// </summary> /// <param name="surface"></param> /// <search></search> public static Autodesk.DesignScript.Geometry.Surface BoundingSurface(this Autodesk.DesignScript.Geometry.Surface surface) { Autodesk.DesignScript.Geometry.BoundingBox bb = surface.BoundingBox; Cuboid c = bb.ToCuboid(); Autodesk.DesignScript.Geometry.Surface srf = (c.Explode())[0] as Autodesk.DesignScript.Geometry.Surface; bb.Dispose(); c.Dispose(); return(srf); }
/// <summary> /// Convert a Revit BoundingBox to a ProtoGeometry BoundingBox /// </summary> /// <returns></returns> public static Autodesk.Revit.DB.BoundingBoxXYZ ToRevitType(this Autodesk.DesignScript.Geometry.BoundingBox bb) { var rbb = new BoundingBoxXYZ(); rbb.Enabled = true; // placeholder until we can get coordinate system from bounding box rbb.Transform = Transform.Identity; rbb.Max = bb.MaxPoint.ToXyz(); rbb.Min = bb.MinPoint.ToXyz(); return(rbb); }
internal sBoundingBox TosBoundingBox(Dyn.BoundingBox dybx) { sBoundingBox sbox = new sBoundingBox(); sbox.center = TosXYZ((Dyn.Point)EnsureUnit(Dyn.Line.ByStartPointEndPoint(dybx.MinPoint, dybx.MaxPoint).PointAtParameter(0.5))); sbox.min = TosXYZ((Dyn.Point)EnsureUnit(dybx.MinPoint)); sbox.max = TosXYZ((Dyn.Point)EnsureUnit(dybx.MaxPoint)); sbox.diagonal = sbox.max - sbox.min; sbox.xSize = new sRange(sbox.min.X, sbox.max.X); sbox.ySize = new sRange(sbox.min.Y, sbox.max.Y); sbox.zSize = new sRange(sbox.min.Z, sbox.max.Z); return(sbox); }
private Dyn.BoundingBox ToDynamoBoundingBox(List <IsObject> sobjs) { List <Dyn.Geometry> dygeos = new List <Autodesk.DesignScript.Geometry.Geometry>(); foreach (IsObject so in sobjs) { if (so is sFrame) { sFrame sb = so as sFrame; dygeos.Add(ToDynamoLine(sb.axis)); } } Dyn.BoundingBox dbox = Dyn.BoundingBox.ByGeometryCoordinateSystem(dygeos, Dyn.CoordinateSystem.ByOrigin(0, 0, 0)); dygeos.Clear(); return(dbox); }
internal bool IntersectsWithTriangle(OctreeNode ot, int triangleIndex) { List <Point> vertices = vertexIndexByTri[triangleIndex].Select(v => this.vertices[v]).ToList(); using (Polygon pol = Polygon.ByPoints(vertices)) { if (!ot.bbox.Intersects(BoundingBox.ByGeometry(pol))) { return(false); } using (Cuboid cube = ot.bbox.ToCuboid()) { return(cube.DoesIntersect(pol)); } } }
/// <summary> /// Create a bounding box and display its edges. /// </summary> /// <param name="width"></param> /// <param name="depth"></param> /// <param name="height"></param> /// <returns></returns> public static List <Autodesk.DesignScript.Geometry.Curve> PrintingBoundaries(double width = 248.92, double depth = 233.68, double height = 162.56) { // ZMorph 2.0 dimensions // in: { 9.8,9.2,6.4} // mm: {248.92,487.68,162.56} List <Autodesk.DesignScript.Geometry.Curve> curves = new List <Autodesk.DesignScript.Geometry.Curve>(); Autodesk.DesignScript.Geometry.BoundingBox bb = Autodesk.DesignScript.Geometry.BoundingBox.ByCorners( Autodesk.DesignScript.Geometry.Point.ByCoordinates(0, 0, 0), Autodesk.DesignScript.Geometry.Point.ByCoordinates(width, depth, height)); Edge[] edges = bb.ToPolySurface().Edges; foreach (Edge edge in edges) { curves.Add(edge.CurveGeometry); } return(curves); }
internal int getSubdivisionPlane(BoundingBox bbox) { using (Vector v = Vector.ByTwoPoints(bbox.MinPoint, bbox.MaxPoint)) { var s = new double[3] { v.X, v.Y, v.Z }; double max = s.Max(); if (max == s[0]) { return(0); } else if (max == s[1]) { return(1); } else { return(2); } } }
public static Autodesk.Revit.DB.BoundingBoxXYZ ToRevitType(this Autodesk.DesignScript.Geometry.BoundingBox bb, bool convertUnits = true) { return(ToRevitBoundingBox(bb.ContextCoordinateSystem, bb.MinPoint, bb.MaxPoint, convertUnits)); }
/// <summary> /// Create a Revit Axonometric (isometric) View from an Eye position and target position and Bounding Box /// </summary> /// <param name="eyePoint"></param> /// <param name="target"></param> /// <param name="boundingBox"></param> /// <param name="name"></param> /// <param name="isolateElement"></param> /// <returns></returns> public static AxonometricView ByEyePointTargetAndBoundingBox(Autodesk.DesignScript.Geometry.Point eyePoint, Autodesk.DesignScript.Geometry.Point target, Autodesk.DesignScript.Geometry.BoundingBox boundingBox, string name, bool isolateElement) { if (boundingBox == null) { throw new ArgumentNullException("boundingBox"); } if (eyePoint == null) { throw new ArgumentNullException("eyePoint"); } if (target == null) { throw new ArgumentNullException("target"); } if (name == null) { throw new ArgumentNullException("name"); } return(new AxonometricView(eyePoint.ToXyz(), target.ToXyz(), boundingBox.ToRevitType(), name, isolateElement)); }