Esempio n. 1
0
 /// <summary>
 /// Given an array of edges, weeds out any edges
 /// not present on the desired plane
 /// </summary>
 /// <param name="xyzArray">the array of edges </param>
 /// <param name="normal">normal to the desired plane</param>
 /// <returns>edges on the desired plane</returns>
 public static EdgeArray GetEdgesOnPlane(EdgeArray edgeArray, XYZ normal)
 {
     EdgeArray edgesOnPlane = new EdgeArray();
     for (int i = 0; i < edgeArray.Size; i++) {
         IList<XYZ> xyzArray = edgeArray.get_Item(i).Tessellate();
         if (normal.Equals(GeomUtils.kXAxis)) {
             if (xyzArray[0].X == xyzArray[1].X) {
                 edgesOnPlane.Append(edgeArray.get_Item(i));
             }
         }
         if (normal.Equals(GeomUtils.kYAxis)) {
             if (xyzArray[0].Y == xyzArray[1].Y) {
                 edgesOnPlane.Append(edgeArray.get_Item(i));
             }
         }
         if (normal.Equals(GeomUtils.kZAxis)) {
             if (xyzArray[0].Z == xyzArray[1].Z) {
                 edgesOnPlane.Append(edgeArray.get_Item(i));
             }
         }
     }
     return edgesOnPlane;
 }
Esempio n. 2
0
 /// <summary>
 /// Given an array of edges, weeds out any edges
 /// not present at the given offset
 /// </summary>
 /// <param name="edgeArray">the array of edges </param>
 /// <param name="normal">normal to the desired plane</param>
 /// <param name="offset">offset from the plane</param>
 /// <returns>edges on a plane at given offset</returns>
 public static EdgeArray GetEdgesOnPlaneAtOffset(EdgeArray edgeArray, XYZ normal, double offset)
 {
     EdgeArray edgesAtOffset = new EdgeArray();
     edgeArray = GetEdgesOnPlane(edgeArray, normal);
     for (int i = 0; i < edgeArray.Size; i++) {
         IList<XYZ> xyzArray = edgeArray.get_Item(i).Tessellate();
         if (normal.Equals(GeomUtils.kXAxis)) {
             if ((xyzArray[0].X == offset)) {
                 edgesAtOffset.Append(edgeArray.get_Item(i));
             }
         }
         if (normal.Equals(GeomUtils.kYAxis)) {
             if (xyzArray[0].Y == offset) {
                 edgesAtOffset.Append(edgeArray.get_Item(i));
             }
         }
         if (normal.Equals(GeomUtils.kZAxis)) {
             if (xyzArray[0].Z == offset) {
                 edgesAtOffset.Append(edgeArray.get_Item(i));
             }
         }
     }
     return edgesAtOffset;
 }
Esempio n. 3
0
 /// <summary>
 /// Calculate geometry info for Slab
 /// </summary>
 public void GetSlabProfileInfo()
 {
     // get all the edges of the Slab
     m_edges = GetFloorEdges();
     // Get a matrix which can transform points to 2D
     m_to2DMatrix = GetTo2DMatrix();
     // get the boundary of all the points
     m_boundPoints = GetBoundsPoints();
     // get a matrix which can keep all the points in the center of the canvas
     m_moveToCenterMatrix = GetMoveToCenterMatrix();
     // get a matrix for scaling all the points and lines within the canvas
     m_scaleMatrix = GetScaleMatrix();
     // get a matrix for moving all point in the middle of PictureBox
     m_MoveToPictureBoxCenter = GetMoveToCenterOfPictureBox();
     // transform 3D points to 2D
     m_transformMatrix = Get3DTo2DMatrix();
     // transform from 2D to 3D
     m_restoreMatrix = Get2DTo3DMatrix();
 }
Esempio n. 4
0
 /// <summary>
 /// Get all points of the Slab
 /// </summary>
 /// <returns>points array stores all the points on slab</returns>
 public EdgeArray GetFloorEdges()
 {
     EdgeArray edges = new EdgeArray();
     Options options = m_commandData.Application.Application.Create.NewGeometryOptions();
     options.DetailLevel = DetailLevels.Medium;
     //make sure references to geometric objects are computed.
     options.ComputeReferences = true;
     Autodesk.Revit.DB.GeometryElement geoElem = m_floor.get_Geometry(options);
     GeometryObjectArray gObjects = geoElem.Objects;
     //get all the edges in the Geometry object
     foreach (GeometryObject geo in gObjects)
     {
         Solid solid = geo as Solid;
         if (solid != null)
         {
             FaceArray faces = solid.Faces;
             foreach (Face face in faces)
             {
                 EdgeArrayArray edgeArrarr = face.EdgeLoops;
                 foreach (EdgeArray edgeArr in edgeArrarr)
                 {
                     foreach (Edge edge in edgeArr)
                     {
                         edges.Append(edge);
                     }
                 }
             }
         }
     }
     return edges;
 }
        private static CurveLoop GetFaceBoundary(Face face, EdgeArray faceBoundary, XYZ baseLoopOffset,
            bool polygonalOnly, out FaceBoundaryType faceBoundaryType)
        {
            faceBoundaryType = FaceBoundaryType.Polygonal;
            CurveLoop currLoop = new CurveLoop();
            foreach (Edge faceBoundaryEdge in faceBoundary)
            {
                Curve edgeCurve = faceBoundaryEdge.AsCurveFollowingFace(face);
                Curve offsetCurve = (baseLoopOffset != null) ? MoveCurve(edgeCurve, baseLoopOffset) : edgeCurve;
                if (!(offsetCurve is Line))
                {
                    if (polygonalOnly)
                    {
                        IList<XYZ> tessPts = offsetCurve.Tessellate();
                        int numTessPts = tessPts.Count;
                        for (int ii = 0; ii < numTessPts - 1; ii++)
                        {
                            Line line = Line.get_Bound(tessPts[ii], tessPts[ii + 1]);
                            currLoop.Append(line);
                        }
                    }
                    else
                    {
                        currLoop.Append(offsetCurve);
                    }

                    if (offsetCurve is Arc)
                        faceBoundaryType = FaceBoundaryType.LinesAndArcs;
                    else
                        faceBoundaryType = FaceBoundaryType.Complex;
                }
                else
                    currLoop.Append(offsetCurve);
            }
            return currLoop;
        }
        private void Stream(ArrayList data, EdgeArray edgeArray)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(EdgeArray)));

            IEnumerator iter = edgeArray.GetEnumerator();
            int i = 0;
            while (iter.MoveNext())
            {
                data.Add(new Snoop.Data.Object(string.Format("Edge {0:d}", i++), iter.Current));
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Change the swept profile edges from EdgeArray type to line list
        /// </summary>
        /// <param name="edges">the swept profile edges</param>
        /// <returns>the line list which stores the swept profile edges</returns>
        private List<Line> ChangeEdgeToLine(EdgeArray edges)
        {
            // create the line list instance.
            List<Line> edgeLines = new List<Line>();

            // get each edge from swept profile,
            // and changed the geometry information in line list
            foreach (Edge edge in edges)
            {
                //get the two points of each edge
                List<XYZ> points = edge.Tessellate() as List<XYZ>;
                Autodesk.Revit.DB.XYZ first = Transform(points[0]);
                Autodesk.Revit.DB.XYZ second = Transform(points[1]);

                // create new line and add them into line list
                edgeLines.Add(Line.get_Bound(first, second));
            }

            return edgeLines;
        }
Esempio n. 8
0
        /// <summary>
        /// Given an edge Array converts it to a curveArray
        /// </summary>
        /// <param name="edgeArray">edgeArray to convert</param>
        /// <param name="curveArray">curveArray to fill</param>
        /// <returns>a curveArray</returns>
        public static CurveArray ToCurveArray(EdgeArray edgeArray, CurveArray curveArray)
        {
            EdgeArrayIterator edgeArrayIter = edgeArray.ForwardIterator();
            while (edgeArrayIter.MoveNext()) {
                Edge edge = edgeArrayIter.Current as Edge;
                XYZ startPt = edge.Tessellate()[0];
                XYZ endPt = edge.Tessellate()[1];
                Line curve = Line.CreateBound(startPt, endPt);
                curveArray.Append(curve);
            }

            return curveArray;
        }
Esempio n. 9
0
 public virtual void Stream(EdgeArray edgeArray)
 {
     foreach (Edge edge in edgeArray) {
         Stream(edge);
     }
 }
Esempio n. 10
0
 Stream(EdgeArray edgeArray)
 {
     foreach (Edge edge in edgeArray) {
         Stream(edge);
     }
 }
        /// <summary>
        /// get a list of points representing an edge array
        /// found on the building coder:
        /// http://thebuildingcoder.typepad.com/blog/2011/07/
        /// </summary>
        /// <param name="ea"></param>
        /// <returns></returns>
        private static List<Autodesk.DesignScript.Geometry.Point> GetPolygon(EdgeArray ea)
        {
            int n = ea.Size;

            List<XYZ> polygon = new List<XYZ>(n);

            foreach (Autodesk.Revit.DB.Edge e in ea)
            {
                IList<XYZ> pts = e.Tessellate();

                n = polygon.Count;

                if (0 < n)
                {
                    polygon.RemoveAt(n - 1);
                }
                polygon.AddRange(pts);
            }
            n = polygon.Count;

            polygon.RemoveAt(n - 1);

            //return polygon;

            //convert polygon to designscript points and return
            List<Autodesk.DesignScript.Geometry.Point> outPoitns = new List<Autodesk.DesignScript.Geometry.Point>();
            foreach (var p in polygon)
            {
                outPoitns.Add(Autodesk.DesignScript.Geometry.Point.ByCoordinates(p.X, p.Y, p.Z));
            }
            return outPoitns;
        }
    private static void ComputerGeometryLoops(EdgeArray ea,
        out List<XYZ> loop, out XYZ loopNormal,
        out double loopArea)
    {
      // Create a list of points of the loop
      loop = new List<XYZ>();
      foreach (Edge e in ea)
      {
        IList<XYZ> edgePoints = e.Tessellate();

        // Avoid duplicated points (generic approach)
        foreach (XYZ edgePoint in edgePoints)
          if (!ListContains(loop, edgePoint))
            loop.Add(edgePoint);
      }

      // Calculate the area and length of the loop
      //
      // More information at
      // http://thebuildingcoder.typepad.com/
      //                         blog/2008/12/3d-polygon-areas.html

      double loopLength;

      GetPolygonPlane(loop, out loopNormal, 
        out loopLength, out loopArea);
    }
Esempio n. 13
0
        private CurveArray GetCurveArrayFromEdgeArary(EdgeArray edgeArray)
        {
            CurveArray curveArray =
                new CurveArray();

            foreach (Edge edge in edgeArray)
            {
                var edgeCurve =
                        edge.AsCurve();

                curveArray.Append(edgeCurve);
            }

            return curveArray;
        }