/// <summary> /// /// </summary> /// <param name="wall"></param> /// <param name="offset"></param> /// <returns></returns> public static BoundingBox GetAlignedBoundingBox(Element wall, Offset offset) { if (wall == null) { throw new ArgumentException(nameof(wall)); } if (!(wall.InternalElement is Autodesk.Revit.DB.Wall w)) { throw new Exception("Element is not a Wall."); } if (!(w.Location is Autodesk.Revit.DB.LocationCurve loc) || !(loc.Curve is Autodesk.Revit.DB.Line)) { throw new Exception("This functionality only supports Line based Walls."); } var bb = w.get_BoundingBox(null); var minScaled = bb.Min.ToPoint(); // converts units var maxScaled = bb.Max.ToPoint(); // converts units var min = Point.ByCoordinates(minScaled.X - offset.Left, minScaled.Y - offset.Bottom, minScaled.Z); var max = Point.ByCoordinates(maxScaled.X + offset.Right, maxScaled.Y + offset.Top, maxScaled.Z); return(BoundingBox.ByCorners(min, max)); }
public static BoundingBox UnionBoundingBoxes(BoundingBox a, BoundingBox b) { return(BoundingBox.ByCorners( Point.ByCoordinates(Math.Min(a.MinPoint.X, b.MinPoint.X), Math.Min(a.MinPoint.Y, b.MinPoint.Y), Math.Min(a.MinPoint.Z, b.MinPoint.Z)), Point.ByCoordinates(Math.Max(a.MaxPoint.X, b.MaxPoint.X), Math.Max(a.MaxPoint.Y, b.MaxPoint.Y), Math.Max(a.MaxPoint.Z, b.MaxPoint.Z)) )); }
private void Split() { if (!IsLeaf()) { return; } _childNodes = new List <SimpleOctreeNode>(); for (int i = 0; i < 8; ++i) { double x = _origin.X + _halfDimension.X * ((i & 4) != 0 ? .5 : -.5); double y = _origin.Y + _halfDimension.Y * ((i & 2) != 0 ? .5 : -.5); double z = _origin.Z + _halfDimension.Z * ((i & 1) != 0 ? .5 : -.5); Point newOrigin = Point.ByCoordinates(x, y, z); Vector newHalfDimension = _halfDimension.Scale(0.5); _childNodes.Add(new SimpleOctreeNode(_parent, BoundingBox.ByCorners(newOrigin.Subtract(newHalfDimension), newOrigin.Add(newHalfDimension)))); } var oldChildren = new List <Tuple <int, BoundingBox> >(); oldChildren.AddRange(_childObjects); _childObjects = new List <Tuple <int, BoundingBox> >(); foreach (var tuple in oldChildren) { bool wasAddedToChild = Add(tuple.Item1, tuple.Item2); if (!wasAddedToChild) { _childObjects.Add(tuple); } } }
public void InsertOne() { var boundingBox = BoundingBox.ByCorners(Point.ByCoordinates(0, 0, 0), Point.ByCoordinates(1, 1, 1)); var tree = new SimpleOctree(boundingBox, new OctreeOptions()); tree.Add("test object", boundingBox); var list = tree.QueryRange(boundingBox); Assert.AreEqual(1, list.Count); Assert.AreEqual("test object", list[0]); }
public static BoundingBox CropBox(View view) { if (!(view.InternalElement is Autodesk.Revit.DB.View v)) { throw new ArgumentNullException(nameof(view)); } var cb = v.CropBox; var min = cb.Min.ToPoint(); var max = cb.Max.ToPoint(); return(BoundingBox.ByCorners(min, max)); }
public static Dictionary <string, object> LocationData(global::Revit.Elements.Element viewport) { //obtain the element id from the sheet Autodesk.Revit.DB.Viewport internalViewport = (Autodesk.Revit.DB.Viewport)viewport.InternalElement; //obtain the box center of the viewport var boxCenterInternal = internalViewport.GetBoxCenter().ToPoint(); //Construct new point at sheet elevation of 0 Autodesk.DesignScript.Geometry.Point boxCenter = Autodesk.DesignScript.Geometry.Point.ByCoordinates(boxCenterInternal.X, boxCenterInternal.Y, 0); //this obtains the box outline var boxOutline = internalViewport.GetBoxOutline(); //temporary geometry var bBox = BoundingBox.ByCorners(boxOutline.MaximumPoint.ToPoint(), boxOutline.MinimumPoint.ToPoint()); var boxCuboid = Cuboid.ByCorners(boxOutline.MaximumPoint.ToPoint(), boxOutline.MinimumPoint.ToPoint()); //create plane that corresponds to sheet plane Plane boxPlane = Plane.ByOriginNormal(boxOutline.MaximumPoint.ToPoint(), Vector.ZAxis()); var boxSurface = boxCuboid.Intersect(boxPlane); List <Autodesk.DesignScript.Geometry.Curve[]> boxCurves = new List <Autodesk.DesignScript.Geometry.Curve[]>(); foreach (var geometry in boxSurface) { var surf = (Surface)geometry; boxCurves.Add(surf.PerimeterCurves()); surf.Dispose(); } List <Autodesk.DesignScript.Geometry.Curve> boxSheetCurves = new List <Autodesk.DesignScript.Geometry.Curve>(); //pull the curves onto a plane at 0,0,0 foreach (Autodesk.DesignScript.Geometry.Curve[] curve in boxCurves) { foreach (Autodesk.DesignScript.Geometry.Curve c in curve) { boxSheetCurves.Add(c.PullOntoPlane(Plane.XY())); c.Dispose(); } } //dispose of temporary geometries boxCuboid.Dispose(); boxPlane.Dispose(); //returns the outputs var outInfo = new Dictionary <string, object> { { "bBox", bBox }, { "boxCenter", boxCenter }, { "boxOutline", boxSheetCurves } }; return(outInfo); }
public void SetUpOctree() { var boundingBox = BoundingBox.ByCorners(Point.ByCoordinates(0, 0, 0), Point.ByCoordinates(10, 10, 10)); tree = new SimpleOctree(boundingBox, new OctreeOptions()); // Create octree with eight objects, one in each first-level cell tree.Add("test object 1", BoundingBox.ByCorners(Point.ByCoordinates(1, 1, 1), Point.ByCoordinates(4, 4, 4))); tree.Add("test object 2", BoundingBox.ByCorners(Point.ByCoordinates(1, 6, 1), Point.ByCoordinates(4, 9, 4))); tree.Add("test object 3", BoundingBox.ByCorners(Point.ByCoordinates(6, 1, 1), Point.ByCoordinates(9, 4, 4))); tree.Add("test object 4", BoundingBox.ByCorners(Point.ByCoordinates(6, 6, 1), Point.ByCoordinates(9, 9, 4))); tree.Add("test object 5", BoundingBox.ByCorners(Point.ByCoordinates(1, 1, 6), Point.ByCoordinates(4, 4, 9))); tree.Add("test object 6", BoundingBox.ByCorners(Point.ByCoordinates(1, 6, 6), Point.ByCoordinates(4, 9, 9))); tree.Add("test object 7", BoundingBox.ByCorners(Point.ByCoordinates(6, 1, 6), Point.ByCoordinates(9, 4, 9))); tree.Add("test object 8", BoundingBox.ByCorners(Point.ByCoordinates(6, 6, 6), Point.ByCoordinates(9, 9, 9))); }
public void QueryRange() { List <object> list = null; list = tree.QueryRange(BoundingBox.ByCorners(Point.ByCoordinates(0, 0, 0), Point.ByCoordinates(10, 10, 10))); Assert.AreEqual(8, list.Count); list = tree.QueryRange(BoundingBox.ByCorners(Point.ByCoordinates(0, 0, 0), Point.ByCoordinates(10, 10, 5))); Assert.AreEqual(4, list.Count); list = tree.QueryRange(BoundingBox.ByCorners(Point.ByCoordinates(0, 0, 5), Point.ByCoordinates(10, 10, 10))); Assert.AreEqual(4, list.Count); list = tree.QueryRange(BoundingBox.ByCorners(Point.ByCoordinates(0, 0, 0), Point.ByCoordinates(5, 5, 5))); Assert.AreEqual(1, list.Count); Assert.AreEqual("test object 1", list[0]); list = tree.QueryRange(BoundingBox.ByCorners(Point.ByCoordinates(0, 5, 0), Point.ByCoordinates(5, 10, 5))); Assert.AreEqual(1, list.Count); Assert.AreEqual("test object 2", list[0]); list = tree.QueryRange(BoundingBox.ByCorners(Point.ByCoordinates(5, 0, 0), Point.ByCoordinates(10, 5, 5))); Assert.AreEqual(1, list.Count); Assert.AreEqual("test object 3", list[0]); list = tree.QueryRange(BoundingBox.ByCorners(Point.ByCoordinates(5, 5, 0), Point.ByCoordinates(10, 10, 5))); Assert.AreEqual(1, list.Count); Assert.AreEqual("test object 4", list[0]); list = tree.QueryRange(BoundingBox.ByCorners(Point.ByCoordinates(0, 0, 5), Point.ByCoordinates(5, 5, 10))); Assert.AreEqual(1, list.Count); Assert.AreEqual("test object 5", list[0]); list = tree.QueryRange(BoundingBox.ByCorners(Point.ByCoordinates(0, 5, 5), Point.ByCoordinates(5, 10, 10))); Assert.AreEqual(1, list.Count); Assert.AreEqual("test object 6", list[0]); list = tree.QueryRange(BoundingBox.ByCorners(Point.ByCoordinates(5, 0, 5), Point.ByCoordinates(10, 5, 10))); Assert.AreEqual(1, list.Count); Assert.AreEqual("test object 7", list[0]); list = tree.QueryRange(BoundingBox.ByCorners(Point.ByCoordinates(5, 5, 5), Point.ByCoordinates(10, 10, 10))); Assert.AreEqual(1, list.Count); Assert.AreEqual("test object 8", list[0]); }
public static Octree ByObjectsAndBoundingBoxes(object[] objects, BoundingBox[] boundingBoxes) { var q = new Octree(); BoundingBox worldBox = BoundingBox.ByCorners(boundingBoxes[0].MinPoint, boundingBoxes[0].MaxPoint); for (int i = 1; i < boundingBoxes.Length; i++) { worldBox = Utils.UnionBoundingBoxes(worldBox, boundingBoxes[i]); } q._Impl = new SimpleOctree(worldBox, new OctreeOptions()); for (int i = 0; i < Math.Min(objects.Length, boundingBoxes.Length); i++) { q._Impl.Add(objects[i], boundingBoxes[i]); } return(q); }