예제 #1
0
        //Box映射
        public static IGH_GeometricGoo BoxMapping(Box box1, Box box2, IGH_GeometricGoo geo)
        {
            if (!box1.IsValid || !box2.IsValid)
            {
                return(null);
            }
            Plane plane1 = box1.Plane;
            Plane plane2 = box2.Plane;

            plane1.Origin = box1.Center;
            plane2.Origin = box2.Center;
            double       xscale       = box2.X.Length / box1.X.Length;
            double       yscale       = box2.Y.Length / box1.Y.Length;
            double       zscale       = box2.Z.Length / box1.Z.Length;
            ITransform   item         = new Scale(plane1, xscale, yscale, zscale);
            ITransform   item2        = new Orientation(plane1, plane2);
            GH_Transform gh_Transform = new GH_Transform();

            gh_Transform.CompoundTransforms.Add(item);
            gh_Transform.CompoundTransforms.Add(item2);
            gh_Transform.ClearCaches();

            IGH_GeometricGoo geo2 = geo.DuplicateGeometry();

            geo2 = geo2.Transform(gh_Transform.Value);
            return(geo2);
        }
예제 #2
0
    //this is for transform
    public GeomObject Transform(Transform xform)
    {
        GeomObject xObj = Duplicate();

        foreach (string key in xObj.MemberDict.Keys)
        {
            List <IGH_Goo> newData = new List <IGH_Goo>();
            for (int i = 0; i < xObj.MemberDict[key].Count; i++)
            {
                if (typeof(IGH_GeometricGoo).IsAssignableFrom(xObj.MemberDict[key][i].GetType()))
                {
                    IGH_GeometricGoo geom = (IGH_GeometricGoo)xObj.MemberDict[key][i];
                    xObj.MemberDict[key][i] = geom.Transform(xform);
                }
            }
        }

        return(xObj);
    }
예제 #3
0
        public static IGH_GeometricGoo BoxTrans(Box box1, Box box2, IGH_GeometricGoo geo)
        {
            if (!box1.IsValid || !box2.IsValid)
            {
                return(null);
            }
            Plane plane1 = box1.Plane;
            Plane plane2 = box2.Plane;

            plane1.Origin = box1.Center;
            plane2.Origin = box2.Center;
            ITransform   item         = new Orientation(plane1, plane2);
            GH_Transform gh_Transform = new GH_Transform();

            gh_Transform.CompoundTransforms.Add(item);
            gh_Transform.ClearCaches();

            IGH_GeometricGoo geo2 = geo.DuplicateGeometry();

            geo2 = geo2.Transform(gh_Transform.Value);
            return(geo2);
        }
예제 #4
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);
        }
예제 #5
0
        /// <summary>
        /// 計算部分
        /// </summary>
        /// <param name="DA">インプットパラメータからデータを取得し、出力用のデータを保持するオブジェクト</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            int              nFL = 0;
            double           FH = 0, Angle = 0, R = 0;
            IGH_GeometricGoo FL    = null;
            Brep             Floor = null;

            // 入力設定============================
            if (!DA.GetData(0, ref nFL))
            {
                return;
            }
            if (!DA.GetData(1, ref FH))
            {
                return;
            }
            if (!DA.GetData(2, ref Angle))
            {
                return;
            }
            if (!DA.GetData(3, ref R))
            {
                return;
            }
            if (!DA.GetData(4, ref FL))
            {
                return;
            }
            if (!DA.GetData(4, ref Floor))
            {
                return;
            }

            // 床の作成
            List <IGH_GeometricGoo> list = new List <IGH_GeometricGoo>(nFL);
            Vector3d DirectionVector     = new Vector3d(0, 0, FH);
            Point3d  Center = new Point3d(0, 0, 0);

            for (int i = 0; i < nFL; i++)
            {
                ITransform transform  = new Translation(DirectionVector * (double)i);
                ITransform transform2 = new Rotation(Center, DirectionVector, Angle * (double)i);
                if (FL != null)
                {
                    IGH_GeometricGoo FL2 = FL.DuplicateGeometry();
                    FL2 = FL2.Transform(transform.ToMatrix());
                    FL2 = FL2.Transform(transform2.ToMatrix());
                    list.Add(FL2);
                }
                else
                {
                    list.Add(null);
                }
            }

            // 柱の作成
            List <Brep> collist = new List <Brep>(nFL);

            Point3d[] CornerPoints = Floor.DuplicateVertices();
            // 内柱
            Point3d Point1in = new Point3d(CornerPoints[0].X / 2.0, CornerPoints[0].Y / 2.0, CornerPoints[0].Z / 2.0);
            Point3d Point2in = new Point3d(CornerPoints[1].X / 2.0, CornerPoints[1].Y / 2.0, CornerPoints[1].Z / 2.0);
            Point3d Point3in = new Point3d(CornerPoints[2].X / 2.0, CornerPoints[2].Y / 2.0, CornerPoints[2].Z / 2.0);
            Point3d Point4in = new Point3d(CornerPoints[3].X / 2.0, CornerPoints[3].Y / 2.0, CornerPoints[3].Z / 2.0);
            // 外柱
            Point3d Point1outS = new Point3d(CornerPoints[0].X, CornerPoints[0].Y, CornerPoints[0].Z);
            Point3d Point2outS = new Point3d(CornerPoints[1].X, CornerPoints[1].Y, CornerPoints[1].Z);
            Point3d Point3outS = new Point3d(CornerPoints[2].X, CornerPoints[2].Y, CornerPoints[2].Z);
            Point3d Point4outS = new Point3d(CornerPoints[3].X, CornerPoints[3].Y, CornerPoints[3].Z);
            Point3d Point1outE = Point1outS;
            Point3d Point2outE = Point2outS;
            Point3d Point3outE = Point3outS;
            Point3d Point4outE = Point4outS;

            double num1 = GH_Component.DocumentTolerance();
            double num2 = GH_Component.DocumentAngleTolerance();

            for (int i = 0; i < nFL - 1; i++)
            {
                if (FL != null)
                {
                    if (i != 0)
                    {
                        // 内柱
                        Point1in = new Point3d(Point1in.X, Point1in.Y, Point1in.Z + FH);
                        Point2in = new Point3d(Point2in.X, Point2in.Y, Point2in.Z + FH);
                        Point3in = new Point3d(Point3in.X, Point3in.Y, Point3in.Z + FH);
                        Point4in = new Point3d(Point4in.X, Point4in.Y, Point4in.Z + FH);
                        // 外柱
                        Point1outS = new Point3d(Point1outE.X, Point1outE.Y, Point1outE.Z);
                        Point2outS = new Point3d(Point2outE.X, Point2outE.Y, Point2outE.Z);
                        Point3outS = new Point3d(Point3outE.X, Point3outE.Y, Point3outE.Z);
                        Point4outS = new Point3d(Point4outE.X, Point4outE.Y, Point4outE.Z);
                    }

                    // 外柱 終点
                    Point1outE = new Point3d(
                        Point1outS.X * Math.Cos(Angle) - Point1outS.Y * Math.Sin(Angle),
                        Point1outS.X * Math.Sin(Angle) + Point1outS.Y * Math.Cos(Angle),
                        Point1outS.Z + FH);
                    Point2outE = new Point3d(
                        Point2outS.X * Math.Cos(Angle) - Point2outS.Y * Math.Sin(Angle),
                        Point2outS.X * Math.Sin(Angle) + Point2outS.Y * Math.Cos(Angle),
                        Point2outS.Z + FH);
                    Point3outE = new Point3d(
                        Point3outS.X * Math.Cos(Angle) - Point3outS.Y * Math.Sin(Angle),
                        Point3outS.X * Math.Sin(Angle) + Point3outS.Y * Math.Cos(Angle),
                        Point3outS.Z + FH);
                    Point4outE = new Point3d(
                        Point4outS.X * Math.Cos(Angle) - Point4outS.Y * Math.Sin(Angle),
                        Point4outS.X * Math.Sin(Angle) + Point4outS.Y * Math.Cos(Angle),
                        Point4outS.Z + FH);

                    LineCurve LineCurve1in = new LineCurve(new Line(Point1in, DirectionVector));
                    LineCurve LineCurve2in = new LineCurve(new Line(Point2in, DirectionVector));
                    LineCurve LineCurve3in = new LineCurve(new Line(Point3in, DirectionVector));
                    LineCurve LineCurve4in = new LineCurve(new Line(Point4in, DirectionVector));
                    //
                    LineCurve LineCurve1out = new LineCurve(new Line(Point1outS, Point1outE));
                    LineCurve LineCurve2out = new LineCurve(new Line(Point2outS, Point2outE));
                    LineCurve LineCurve3out = new LineCurve(new Line(Point3outS, Point3outE));
                    LineCurve LineCurve4out = new LineCurve(new Line(Point4outS, Point4outE));

                    Brep[] col1in = Brep.CreatePipe(LineCurve1in, R, true, 0, false, num1, num2);
                    Brep[] col2in = Brep.CreatePipe(LineCurve2in, R, true, 0, false, num1, num2);
                    Brep[] col3in = Brep.CreatePipe(LineCurve3in, R, true, 0, false, num1, num2);
                    Brep[] col4in = Brep.CreatePipe(LineCurve4in, R, true, 0, false, num1, num2);
                    //
                    Brep[] col1out = Brep.CreatePipe(LineCurve1out, R, true, 0, false, num1, num2);
                    Brep[] col2out = Brep.CreatePipe(LineCurve2out, R, true, 0, false, num1, num2);
                    Brep[] col3out = Brep.CreatePipe(LineCurve3out, R, true, 0, false, num1, num2);
                    Brep[] col4out = Brep.CreatePipe(LineCurve4out, R, true, 0, false, num1, num2);

                    collist.AddRange(col1in);
                    collist.AddRange(col2in);
                    collist.AddRange(col3in);
                    collist.AddRange(col4in);
                    collist.AddRange(col1out);
                    collist.AddRange(col2out);
                    collist.AddRange(col3out);
                    collist.AddRange(col4out);
                }
            }
            // 出力設定============================
            DA.SetDataList(0, list);
            DA.SetDataList(1, collist);
        }
예제 #6
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            try {
                this.reset         = DA.Fetch <bool>("Reset");
                this.run           = DA.Fetch <bool>("Run");
                this.iterations    = DA.Fetch <int>("Iterations");
                this.spacing       = DA.Fetch <double>("Spacing");
                this.placementType = DA.Fetch <int>("Placement");
                this.tolerance     = DA.Fetch <double>("Tolerance");
                this.rotations     = DA.Fetch <int>("Rotations");
                this.seed          = DA.Fetch <int>("Seed");
                this.spacing      *= (1 / tolerance);

                //Rhino.RhinoApp.WriteLine("ITER" + iterations.ToString());

                if (((this.reset) || this.scales.Length == 0) || (this.iterations > 0))
                {
                    //Input

                    //Rhino.RhinoApp.WriteLine("setup" + rotations.ToString());

                    List <Polyline> sheets = DA.FetchList <Curve>("Sheets").ToPolylines(true);

                    if (sheets.Count == 1)
                    {
                        Polyline sheetCopy = new Polyline(sheets[0]);
                        sheets.Clear();

                        Point3d  p0  = sheetCopy.BoundingBox.PointAt(0, 0, 0);
                        Point3d  p1  = sheetCopy.BoundingBox.PointAt(1, 0, 0);
                        Vector3d vec = p1 - p0;
                        x = (p1.X - p0.X + this.spacing) / this.tolerance;
                        for (int i = 0; i < 499; i++)
                        {
                            //Polyline sheetMoved = new Polyline(sheetCopy);
                            //sheetMoved.Transform(Transform.Translation(vec * i));
                            sheets.Add(sheetCopy);
                        }
                    }
                    else
                    {
                        this.x = 0;
                    }


                    List <IGH_GeometricGoo> geo_ = DA.FetchList <IGH_GeometricGoo>("Geo");

                    Polyline[][] outlines = GooToOutlines(geo_);



                    ////////////Solution////////////



                    base.Message = "Setup";

                    this.scalesInv   = new Transform[0];
                    this.scales      = new Transform[0];
                    this.orient      = new Transform[0];
                    this.sheetsRhino = new Polyline[0];
                    this.id          = new int[0];
                    this.transforms  = new Transform[0];



                    //Scale
                    Transform scale    = Transform.Scale(Point3d.Origin, 1 / tolerance);
                    Transform scaleInv = Transform.Scale(Point3d.Origin, tolerance);

                    for (int i = 0; i < sheets.Count; i++)
                    {
                        //sheets[i] = new Rectangle3d(sheets[i].Plane, sheets[i].Width * 1 / tolerance, sheets[i].Height * 1 / tolerance);
                        Polyline polyline = new Polyline(sheets[i]);
                        polyline.Transform(Transform.Scale(Point3d.Origin, 1 / tolerance));
                        sheets[i] = polyline;
                    }

                    //Scale polylines and holes by tolerance
                    scalesInv = new Transform[n];
                    scales    = new Transform[n];

                    for (int i = 0; i < n; i++)
                    {
                        for (int j = 0; j < outlines[i].Length; j++)
                        {
                            outlines[i][j].Transform(scale);
                        }

                        scalesInv[i] = scaleInv;
                        scales[i]    = scale;
                    }



                    //Translation
                    orient = new Transform[n];


                    for (int i = 0; i < n; i++)
                    {
                        int last = (outlines[i].Length - 1) % outlines[i].Length;
                        Tuple <Polyline, Transform> projectedPolyline = OpenNestUtil.FitPolylineToPlane(new Polyline(outlines[i][last]));



                        //Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(projectedPolyline.Item1);

                        for (int j = 0; j < outlines[i].Length; j++)
                        {
                            outlines[i][j].Transform(projectedPolyline.Item2);
                        }

                        //foreach (var pp in outlines[i][0])
                        //    Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(pp);

                        orient[i] = projectedPolyline.Item2;
                    }


                    ////////////Run Solver////////////
                    //OpenNestSolver sample = new OpenNestSolver();
                    //sample.Context.LoadSampleData(sheets, outlines);
                    //var output = sample.Run(spacing, iterations, placementType, rotations);

                    //Context = new NestingContext(this.seed);
                    Context = new NestingContext();
                    Context.LoadSampleData(sheets, outlines);


                    //Rhino.RhinoApp.WriteLine("outlines " + polyline[0].Count.ToString());



                    Background.UseParallel = true;


                    ONest.Config.placementType = (PlacementTypeEnum)(placementType % 3);
                    //Rhino.RhinoApp.WriteLine(((PlacementTypeEnum)(placementType % 3)).ToString());
                    ONest.Config.spacing        = this.spacing;
                    ONest.Config.rotations      = this.rotations;
                    ONest.Config.seed           = this.seed;
                    ONest.Config.clipperScale   = 1e7;
                    ONest.Config.simplify       = (placementType == 4);
                    ONest.Config.exploreConcave = (placementType == 5);
                    ONest.Config.mergeLines     = false;
                    //ONest.Config.useHoles = false;

                    Context.StartNest();
                }



                if ((run || this.scales.Length == 0) && iterations == 0)
                {
                    Context.NestIterate();
                    base.Message = "Run " + Context.Iterations.ToString() + " \n Current Best: " + Context.Current.fitness;
                }

                if (iterations > 0)
                {
                    for (int i = 0; i < iterations; i++)
                    {
                        Context.NestIterate();
                    }
                    base.Message = "Static Solver " + Context.Iterations.ToString() + " \n Current Best: " + Context.Current.fitness;
                }



                if (Context.SheetsNotUsed != -1)
                {
                    int sheetCount = Context.Sheets.Count - Context.SheetsNotUsed;
                    this.sheetsRhino = new Polyline[sheetCount];
                    for (int i = 0; i < sheetCount; i++)
                    {
                        //Rhino.RhinoApp.WriteLine(Context.Sheets[i].id.ToString());
                        Polyline sheetPoly = Context.Sheets[i].ToPolyline();
                        sheetPoly.Transform(Transform.Translation(new Vector3d(this.x * i, 0, 0)));
                        this.sheetsRhino[i] = sheetPoly;
                    }
                }
                else
                {
                    this.sheetsRhino = Context.Sheets.ToPolylines();
                }



                this.id = Context.Polygons.ToIDArray();
                //Context.Polygons[i].sheet.Id;
                Transform[] polygonsTransforms = Context.Polygons.GetTransforms();



                this.transforms = new Transform[scalesInv.Length];

                List <int> polygonIDinSheet = new List <int>();

                for (int i = 0; i < scalesInv.Length; i++)
                {
                    if (Context.Polygons[i].fitted)
                    {
                        this.transforms[i] = scalesInv[i] * Transform.Translation(new Vector3d(this.x * Context.Polygons[i].sheet.id, 0, 0)) * polygonsTransforms[i] * orient[i] * scales[i];
                        polygonIDinSheet.Add(Context.Polygons[i].sheet.id);
                    }
                    else
                    {
                        this.transforms[i] = Transform.Translation(new Vector3d(0, 0, 0));
                        //this.transforms[i] = scalesInv[i] * polygonsTransforms[i] * orient[i] * scales[i];
                        polygonIDinSheet.Add(-1);
                    }
                }


                for (int i = 0; i < n; i++)
                {
                    IGH_GeometricGoo goo = geo_Original[i].DuplicateGeometry(); //if not duplicated grasshopper will change original ones
                    goo.Transform(transforms[i]);
                    geo[i] = goo;
                }

                for (int i = 0; i < sheetsRhino.Length; i++)
                {
                    sheetsRhino[i].Transform(Transform.Scale(Point3d.Origin, tolerance));
                }



                ////////////Output////////////
                DA.SetDataList(0, sheetsRhino); //Sheets
                DA.SetDataList(1, geo);         //Surfaces or outlines
                DA.SetDataList(2, id);          //ID
                DA.SetDataList(3, transforms);  //transformations
                DA.SetDataList(4, polygonIDinSheet);
            } catch (Exception e) {
                base.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.ToString());
            }
        }