Example #1
0
        public static List <Brep> CurvesToOffsetBreps(List <Curve> curves, double dist)
        {
            double tolerance = Units.ConvertFromMeter(0.01);
            var    openType  = new List <Polyline3D.OpenFilletType> {
                Polyline3D.OpenFilletType.Butt
            };
            List <Polyline3D.ClosedFilletType> closedType = new List <Polyline3D.ClosedFilletType>()
            {
                Polyline3D.ClosedFilletType.Miter
            };
            double miter = Units.ConvertFromMeter(0.5);


            List <List <Polyline> > holes    = new List <List <Polyline> >();
            List <Brep>             brepsOut = new List <Brep>();

            if (curves.Count == 0)
            {
                return(null);
            }
            List <Polyline> inPolylines = Polyline3D.ConvertCurvesToPolyline(curves).ToList();
            var             pln         = inPolylines.First().FitPlane();

            if (dist == 0)
            {
                holes.Add(inPolylines);
                List <Curve> holesPoly = holes.SelectMany(p => p).Select(p => (Curve)p.ToPolylineCurve()).ToList();
                brepsOut.AddRange(InputGeometries.UpwardsPointingBrepsFromCurves(holesPoly));
                //outside.Add(new List<Polyline>() { null });
            }
            else
            {
                // endtypes: http://www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Types/EndType.htm
                Polyline3D.Offset(inPolylines, openType, closedType, pln, tolerance, new List <double> {
                    dist
                }, miter, arcTolerance: 0.25, out _, out holes, EndType.etClosedLine);

                List <Curve> holesPoly = holes.SelectMany(p => p).Select(p => (Curve)p.ToPolylineCurve()).ToList();
                brepsOut.AddRange(InputGeometries.UpwardsPointingBrepsFromCurves(holesPoly));
            }

            return(brepsOut);
        }
Example #2
0
        /// <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)
        {
            var gridSize   = Units.ConvertFromMeter(DA.Fetch <double>("GridSize [m]"));
            var edgeOffset = Units.ConvertFromMeter(DA.Fetch <double>("Edge Offset [m]"));

            var offset     = Units.ConvertFromMeter(DA.Fetch <double>("Vertical Offset [m]"));
            var useCenters = DA.Fetch <bool>("IsoCurves");
            var geometries = DA.FetchList <IGH_GeometricGoo>("Geometry");
            var goLarge    = DA.Fetch <bool>("GoLarge");

            DataTree <Point3d> centers = new DataTree <Point3d>();
            List <Grid>        myGrids = new List <Grid>();
            List <Mesh>        meshes  = new List <Mesh>();

            //List<Mesh> inMeshes = new List<Mesh>();
            List <Brep>  inBreps = new List <Brep>();
            List <Curve> inCrvs  = new List <Curve>();

            //string msg = "";
            useCenters = !useCenters;

            for (int i = 0; i < geometries.Count; i++)
            {
                if (geometries[i] == null)
                {
                    continue;
                }

                IGH_GeometricGoo shape = geometries[i].DuplicateGeometry();

                shape.Transform(Transform.Translation(0, 0, offset));

                if (shape is Mesh || shape is GH_Mesh)
                {
                    //inMeshes.Add(GH_Convert.ToGeometryBase(shape) as Mesh);
                    myGrids.Add(new Grid(GH_Convert.ToGeometryBase(shape) as Mesh, useCenters: useCenters));
                }
                else if (shape is Brep || shape is GH_Brep)
                {
                    //myGrids.Add(new Grid(GH_Convert.ToGeometryBase(shape) as Brep, gridSize, useCenters: useCenters));
                    inBreps.Add(GH_Convert.ToGeometryBase(shape) as Brep);
                }
                else if (shape is Curve || shape is GH_Curve)
                {
                    //myGrids.Add(new Grid(GH_Convert.ToGeometryBase(shape) as Curve, gridSize, useCenters: useCenters));
                    inCrvs.Add(GH_Convert.ToGeometryBase(shape) as Curve);
                }
                else
                {
                    myGrids.Add(null);
                    meshes.Add(null);
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "error on an input grid");
                }
            }

            List <Brep> breps = InputGeometries.CurvesToOffsetBreps(inCrvs, edgeOffset) ?? new List <Brep>();

            breps.AddRange(InputGeometries.BrepsToOffsetBreps(inBreps, edgeOffset));


            for (int i = 0; i < breps.Count; i++)
            {
                myGrids.Add(new Grid(breps[i], gridSize, useCenters: useCenters, goLarge));
            }

            for (int i = 0; i < myGrids.Count; i++)
            {
                meshes.Add(myGrids[i].SimMesh);
                GH_Path p = new GH_Path(i);
                centers.AddRange(myGrids[i].SimPoints, p);
            }


            DA.SetDataList(0, myGrids);
            DA.SetDataList(1, meshes);
            DA.SetDataTree(2, centers);
            //DA.SetData(3, msg);
        }
Example #3
0
        /// <summary>
        /// Using clipper
        /// </summary>
        /// <param name="breps"></param>
        /// <param name="dist"></param>
        /// <returns></returns>
        public static List <Brep> BrepsToOffsetBreps(List <Brep> breps, double dist)
        {
            List <Brep> brepsOut = new List <Brep>();
            //List<Polyline> polyOut2 = new List<Polyline>();

            double tolerance = Units.ConvertFromMeter(0.01);
            var    openType  = new List <Polyline3D.OpenFilletType> {
                Polyline3D.OpenFilletType.Butt
            };
            List <Polyline3D.ClosedFilletType> closedType = new List <Polyline3D.ClosedFilletType>()
            {
                Polyline3D.ClosedFilletType.Miter
            };
            double miter = Units.ConvertFromMeter(0.5);


            for (int i = 0; i < breps.Count; i++)
            {
                List <Curve> allEdges = new List <Curve>();
                if (dist > 0)
                {
                    Curve[] innerEdges = Curve.JoinCurves(breps[i].DuplicateNakedEdgeCurves(false, true));
                    Curve[] outerEdges = Curve.JoinCurves(breps[i].DuplicateNakedEdgeCurves(true, false));

                    outerEdges[0].TryGetPlane(out Plane pln, tolerance);

                    if (pln.ZAxis.Z < 0)
                    {
                        pln.Flip();
                    }

                    List <Polyline> polylineInner = new List <Polyline>();



                    for (int j = 0; j < innerEdges.Length; j++)
                    {
                        innerEdges[j].TryGetPolyline(out Polyline polyEdge);
                        if (polyEdge != null)
                        {
                            var crv = polyEdge.ToNurbsCurve();
                            CurveOrientation dir = crv.ClosedCurveOrientation(pln);
                            if (dir == CurveOrientation.Clockwise)
                            {
                                polyEdge.Reverse();
                            }
                            polylineInner.Add(polyEdge);
                            //polyOut.Add(polyEdge);
                        }
                    }

                    List <Polyline> polylineOuter = new List <Polyline>();
                    for (int j = 0; j < outerEdges.Length; j++)
                    {
                        outerEdges[j].TryGetPolyline(out Polyline polyEdge);
                        if (polyEdge != null)
                        {
                            var crv = polyEdge.ToNurbsCurve();
                            CurveOrientation dir = crv.ClosedCurveOrientation(pln);
                            if (dir == CurveOrientation.Clockwise)
                            {
                                polyEdge.Reverse();
                            }
                            polylineOuter.Add(polyEdge);
                        }
                    }

                    Polyline3D.Offset(polylineInner, openType, closedType, pln, tolerance, new List <double> {
                        dist
                    }, miter, arcTolerance: 0.25, outContour: out List <List <Polyline> > brepHoles, out _, EndType.etClosedLine);
                    Polyline3D.Offset(polylineOuter, openType, closedType, pln, tolerance, new List <double> {
                        dist
                    }, miter, arcTolerance: 0.25, out _, outHoles: out List <List <Polyline> > brepEdges, EndType.etClosedLine);

                    var holesCrvs = brepHoles.SelectMany(p => p).Select(p => (Curve)p.ToPolylineCurve()).ToList();
                    var edgeCrvs  = brepEdges.SelectMany(p => p).Select(p => (Curve)p.ToPolylineCurve()).ToList();

                    var result = Polyline3D.Boolean(ClipType.ctDifference, brepEdges[0], brepHoles[0], pln, tolerance, true);//var polylinesB = Polyline3D.ConvertCurvesToPolyline(curvesB).ToList();

                    allEdges.AddRange(result.Select(p => (Curve)p.ToPolylineCurve()).ToList());

                    //polyOut2.AddRange(brepHoles.SelectMany(p => p));
                    //polyOut2.AddRange(brepEdges.SelectMany(p => p));

                    brepsOut.AddRange(InputGeometries.UpwardsPointingBrepsFromCurves(allEdges));
                }
                else
                {
                    brepsOut.Add(breps[i].TurnUp());
                }
            }
            return(brepsOut);
        }