示例#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);
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            IGH_GeometricGoo geo = null;

            if (!DA.GetData("Geometry", ref geo))
            {
                return;
            }
            var bbox = geo.Boundingbox;

            if (!bbox.IsValid)
            {
                bbox = geo.GetBoundingBox(Transform.Identity);
            }
            var transVec = Point3d.Origin - bbox.Center;

            var newGeo = geo.DuplicateGeometry().Transform(Transform.Translation(transVec));

            DA.SetData("Recentered Geometry", newGeo);
            DA.SetData("Translation Vector", transVec);
        }
示例#3
0
        private static IGH_GeometricGoo DeReferenceWithReflection(IGH_GeometricGoo geom)
        {
            var geomType = geom.GetType();
            var geomInfo = geomType.GetRuntimeProperty("Value");

            if (geomInfo != null)
            {
                var geomVal = geomInfo.GetValue(geom);
                if (geomVal is GeometryBase rhinoGeom)
                {
                    IGH_GeometricGoo newGoo;
                    try
                    {
                        newGoo = (IGH_GeometricGoo)Activator.CreateInstance(geomType, rhinoGeom);
                    }
                    catch { newGoo = geom; }
                    geom = newGoo;
                }
            }
            return(geom.DuplicateGeometry());
        }
示例#4
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);
        }
示例#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
        /// <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)
        {
            Mesh topoMesh = new Mesh();

            DA.GetData <Mesh>("Topography Mesh", ref topoMesh);

            GH_Structure <IGH_GeometricGoo> featureGoo = new GH_Structure <IGH_GeometricGoo>();

            DA.GetDataTree <IGH_GeometricGoo>("Feature Geometry", out featureGoo);

            ///Reserve one processor for GUI
            totalMaxConcurrancy = System.Environment.ProcessorCount - 1;

            ///Tells us how many threads were using
            //Message = totalMaxConcurrancy + " threads";


            ///Get Rtree of points and flat mesh for processing in detailed feature mesh projection
            Mesh topoFlat = new Mesh();

            Point3d[] topoFlatPoints = null;
            RTree     rTree          = new RTree();

            if (!fast)
            {
                topoFlat = topoMesh.DuplicateMesh();
                for (int i = 0; i < topoFlat.Vertices.Count; i++)
                {
                    Point3f v = topoFlat.Vertices[i];
                    v.Z = 0;
                    topoFlat.Vertices.SetVertex(i, v);
                }

                topoFlatPoints = topoFlat.Vertices.ToPoint3dArray();
                rTree          = RTree.CreateFromPointArray(topoFlatPoints);
            }

            ///Create a dictionary that works in parallel
            var gooTree = new System.Collections.Concurrent.ConcurrentDictionary <GH_Path, List <IGH_GeometricGoo> >();

            ///Multi-threading the loop
            System.Threading.Tasks.Parallel.ForEach(featureGoo.Paths,
                                                    new System.Threading.Tasks.ParallelOptions {
                MaxDegreeOfParallelism = totalMaxConcurrancy
            },
                                                    pth =>
            {
                ///Create containers for translating from GH Goo
                Point3d pt               = new Point3d();
                Polyline pLine           = null;
                PolylineCurve pLineCurve = null;
                Curve curve              = null;
                Mesh mesh       = new Mesh();
                Surface surface = null;
                Brep brep       = new Brep();

                ///Output container list
                List <IGH_GeometricGoo> gGooList = new List <IGH_GeometricGoo>();
                List <IGH_GeometricGoo> fGooList = new List <IGH_GeometricGoo>();
                var branchFeatures    = featureGoo.get_Branch(pth);
                BoundingBox branchBox = new BoundingBox();

                if (branchFeatures.Count > 0)
                {
                    foreach (var bGoo in branchFeatures)
                    {
                        ///Get geometry type(s) in branch
                        string geomType       = string.Empty;
                        IGH_GeometricGoo fGoo = GH_Convert.ToGeometricGoo(bGoo);

                        if (fGoo != null && fGoo.IsValid)
                        {
                            if (grouped)
                            {
                                ///Need to duplicate geometry or else move vector piles on similar to the following
                                ///https://www.grasshopper3d.com/forum/topics/c-component-refresh-problem
                                fGooList.Add(fGoo.DuplicateGeometry());
                                branchBox.Union(fGoo.Boundingbox);
                            }

                            geomType = fGoo.TypeName;

                            switch (geomType)
                            {
                            case "Point":
                                fGoo.CastTo <Point3d>(out pt);
                                gGooList.Add(ProjectPointToTopo(topoMesh, pt));
                                break;

                            case "Line":
                            case "Polyline":
                                fGoo.CastTo <Polyline>(out pLine);

                                if (fast)
                                {
                                    gGooList.Add(ProjectPolylineToTopo(topoMesh, pLine));
                                }
                                else
                                {
                                    ///Lock topoMesh so it's not accessed by mutliple threads at once in a "deadlock"
                                    ///https://docs.microsoft.com/en-us/dotnet/standard/threading/managed-threading-best-practices
                                    lock (topoMesh)
                                    {
                                        gGooList.AddRange(ProjectCurveToTopo(topoMesh, pLine.ToNurbsCurve()));
                                    }
                                }

                                break;

                            case "PolylineCurve":
                                fGoo.CastTo <PolylineCurve>(out pLineCurve);
                                if (fast)
                                {
                                    gGooList.Add(ProjectPolylineToTopo(topoMesh, pLineCurve.ToPolyline()));
                                }
                                else
                                {
                                    lock (topoMesh)
                                    {
                                        gGooList.AddRange(ProjectCurveToTopo(topoMesh, pLineCurve.ToNurbsCurve()));
                                    }
                                }
                                break;

                            case "Curve":
                                fGoo.CastTo <Curve>(out curve);
                                if (fast)
                                {
                                    if (curve.TryGetPolyline(out pLine))
                                    {
                                        gGooList.Add(ProjectPolylineToTopo(topoMesh, pLine));
                                    }
                                    else
                                    {
                                        gGooList.AddRange(ProjectCurveToTopo(topoMesh, curve));
                                    }
                                }
                                else
                                {
                                    lock (topoMesh)
                                    {
                                        gGooList.AddRange(ProjectCurveToTopo(topoMesh, curve));
                                    }
                                }
                                break;

                            case "Mesh":
                                fGoo.CastTo <Mesh>(out mesh);
                                if (mesh.IsClosed)
                                {
                                    gGooList.Add(ProjectSolidMeshToTopo(topoMesh, mesh));
                                }
                                else
                                {
                                    if (fast)
                                    {
                                        gGooList.Add(ProjectMeshToTopoFast(topoMesh, mesh));
                                    }
                                    else
                                    {
                                        lock (topoMesh)
                                        {
                                            gGooList.Add(ProjectMeshToTopoSlow(topoMesh, topoFlat, topoFlatPoints, rTree, mesh));
                                        }
                                    }
                                }
                                break;

                            case "Surface":
                                fGoo.CastTo <Surface>(out surface);
                                gGooList.Add(ProjectSurfaceToTopoFast(topoMesh, surface));
                                break;

                            case "Brep":
                                fGoo.CastTo <Brep>(out brep);
                                gGooList.Add(ProjectBrepToTopo(topoMesh, brep));
                                break;

                            default:
                                AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Not able to move " + geomType + " geometry to mesh" +
                                                  ". Geometry must be a Point, Curve, Mesh, Surface or Brep.");
                                break;
                            }
                        }
                        else
                        {
                        }
                    }

                    ///Move objects in branch a minimum distance if grouped selected
                    ///If only one feature in a branch, not need to group
                    if (grouped && gGooList.Count > 1)
                    {
                        ///Get the minimum move vector
                        Point3d lowestPoint = new Point3d();
                        double minDistance  = double.MaxValue;
                        Vector3d minimumVec = new Vector3d();
                        foreach (var gi in gGooList)
                        {
                            if (gi != null)
                            {
                                Point3d gGooMin     = gi.Boundingbox.Min;
                                Vector3d distVector = gGooMin - branchBox.Min;
                                if (distVector.Length < minDistance && distVector.Length > 0 && distVector.IsValid)
                                {
                                    lowestPoint = gGooMin;
                                    minDistance = distVector.Length;
                                    minimumVec  = new Vector3d(0, 0, distVector.Z);
                                }
                            }
                        }

                        ///Move orignal feature geometry the minimum move vector
                        if (minDistance != double.MaxValue)
                        {
                            Transform transform = Transform.Translation(minimumVec);
                            for (int f = 0; f < fGooList.Count; f++)
                            {
                                fGooList[f].Transform(transform);
                            }
                            gooTree[pth] = fGooList;
                        }
                    }
                    else
                    {
                        gooTree[pth] = gGooList;
                    }
                }
            });
            ///End of multi-threaded loop


            ///Convert dictionary to regular old data tree
            GH_Structure <IGH_GeometricGoo> gTree = new GH_Structure <IGH_GeometricGoo>();

            foreach (KeyValuePair <GH_Path, List <IGH_GeometricGoo> > g in gooTree)
            {
                gTree.AppendRange(g.Value, g.Key);
            }

            topoFlat.Dispose();
            topoMesh.Dispose();

            DA.SetDataTree(0, gTree);
        }