Пример #1
0
        //Duplication
        public Type_KDTree DuplicateKDTree()
        {
            GH_Cloud     newCloud = (GH_Cloud)this.Value.Item2.Duplicate();
            KDTree <int> newTree  = KDTreeLib.DubplicateTree(this.Value.Item1);

            return(new Type_KDTree(newTree, newCloud));
        }
Пример #2
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //Initialize Input Variables, Persistent in ComponentChange.

            //Excute Instruction
            ///If Component is set as Instruction.
            if (isInstruction)
            {
                //this.Message = "";
                DA.SetData("Instr", new Instruction.Instr_GrayScale());
            }
            else
            ///If Component is set to StandAlone.
            {
                ///Initialize PointCloud Input Variable.
                GH_Cloud pointCloud = null;
                if (!DA.GetData("Cloud", ref pointCloud))
                {
                    return;
                }
                ///Duplicate GH Cloud.
                GH_Cloud   newGHCloud = pointCloud.DuplicateCloud();
                PointCloud newCloud   = newGHCloud.Value;
                ///Execute Instruction.
                Instruction.Instr_GrayScale inst = new Instruction.Instr_GrayScale();
                Boolean Result = inst.Execute(ref newCloud);

                ///Set New Output Cloud
                newGHCloud.Value = newCloud;
                DA.SetData("Cloud", newGHCloud);

                //Add RuntimeMessage: ComponentChange.
                AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "'Right Click' to Switch between StandAlone and Instruction Component.");
            }
        }
Пример #3
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //Initialize Input Variables, Persistent in ComponentChange.
            Type_KDTree KDTree = null;
            int         Amount = 1;
            Vector3d    GV     = Vector3d.ZAxis;
            Boolean     GS     = true;

            if (!DA.GetData("Number of Neighbors", ref Amount))
            {
                return;
            }
            if (!DA.GetData("Guide Vector", ref GV))
            {
                return;
            }
            if (!DA.GetData("GuideStyle", ref GS))
            {
                return;
            }

            //Excute Instruction
            ///If Component is set as Instruction.
            if (isInstruction)
            {
                //this.Message = "";
                DA.SetData("Instr", new Instruction.Instr_KDTree_Normals(null, GV, GS, Amount, colorize));
            }
            else
            ///If Component is set to StandAlone.
            {
                if (!DA.GetData("KDTree", ref KDTree))
                {
                    return;
                }
                ///Initialize PointCloud Input Variable.
                GH_Cloud pointCloud = KDTree.Value.Item2;
                //if (!DA.GetData("Cloud", ref pointCloud)) return;
                ///Duplicate GH Cloud.
                GH_Cloud   newGHCloud = pointCloud.DuplicateCloud();
                PointCloud newCloud   = newGHCloud.Value;
                ///Execute Instruction.
                Instruction.Instr_KDTree_Normals inst = new Instruction.Instr_KDTree_Normals(KDTree.Value.Item1, GV, GS, Amount, colorize);
                Boolean Result = inst.Execute(ref newCloud);

                ///Set New Output Cloud
                newGHCloud.Value = newCloud;
                Type_KDTree newKDTree = new Type_KDTree(KDTree.Value.Item1, newGHCloud);
                DA.SetData("KDTree", newKDTree);

                //Add RuntimeMessage: ComponentChange.
                AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "'Right Click' to Switch between StandAlone and Instruction Component.");
            }
        }
Пример #4
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //Initialize Input Variables, Persistent in ComponentChange.
            Plane  Plane = Plane.Unset;
            string Key   = string.Empty;

            if (!DA.GetData("Plane", ref Plane))
            {
                return;
            }
            if (!DA.GetData("Key", ref Key))
            {
                return;
            }


            //Excute Instruction
            ///If Component is set as Instruction.
            if (isInstruction)
            {
                //this.Message = "";
                DA.SetData("Instr", new Instruction.Instr_PlaneCompare(Plane, Key, colorize));
            }
            else
            ///If Component is set to StandAlone.
            {
                ///Initialize PointCloud Input Variable.
                GH_Cloud pointCloud = null;
                if (!DA.GetData("Cloud", ref pointCloud))
                {
                    return;
                }
                ///Duplicate GH Cloud.
                GH_Cloud   newGHCloud = pointCloud.DuplicateCloud();
                PointCloud newCloud   = newGHCloud.Value;
                ///Execute Instruction.
                Instruction.Instr_PlaneCompare inst = new Instruction.Instr_PlaneCompare(Plane, Key, colorize);
                Boolean Result = inst.Execute(ref newCloud);

                ///Display ColorRange
                //if (colorize)   {   this.Message = String.Format("Blue:{0} to Red:{1}\nmultiplePC?\nengineDisp?", Math.Round(inst.colorValues.First(), 2), Math.Round(inst.colorValues.Last(), 2)); }
                //else { this.Message = ""; }

                ///Set New Output Cloud
                newGHCloud.Value = newCloud;
                DA.SetData("Cloud", newGHCloud);

                //Add RuntimeMessage: ComponentChange.
                AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "'Right Click' to Switch between StandAlone and Instruction Component.");
            }
        }
Пример #5
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //Initialize Input Variables, Persistent in ComponentChange.
            Mesh     Mesh   = null;
            Vector3d Vector = Vector3d.Zero;
            string   Key    = string.Empty;

            if (!DA.GetData("Mesh", ref Mesh))
            {
                return;
            }
            if (!DA.GetData("Vector", ref Vector))
            {
                return;
            }
            if (!DA.GetData("Key", ref Key))
            {
                return;
            }

            //Excute Instruction
            ///If Component is set as Instruction.
            if (isInstruction)
            {
                //this.Message = "";
                DA.SetData("Instr", new Instruction.Instr_MeshRay(Mesh, Vector, Key, colorize));
            }
            else
            ///If Component is set to StandAlone.
            {
                ///Initialize PointCloud Input Variable.
                GH_Cloud pointCloud = null;
                if (!DA.GetData("Cloud", ref pointCloud))
                {
                    return;
                }
                ///Duplicate GH Cloud.
                GH_Cloud   newGHCloud = pointCloud.DuplicateCloud();
                PointCloud newCloud   = newGHCloud.Value;
                ///Execute Instruction.
                Instruction.Instr_MeshRay inst = new Instruction.Instr_MeshRay(Mesh, Vector, Key, colorize);
                Boolean Result = inst.Execute(ref newCloud);

                ///Set New Output Cloud
                newGHCloud.Value = newCloud;
                DA.SetData("Cloud", newGHCloud);

                //Add RuntimeMessage: ComponentChange.
                AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "'Right Click' to Switch between StandAlone and Instruction Component.");
            }
        }
Пример #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)
        {
            Type_KDTree treeT = null;

            if (!DA.GetData("KDTree", ref treeT))
            {
                return;
            }

            Tuple <KDTree <int>, GH_Cloud> KDTreeCloud = treeT.Value;
            GH_Cloud cloud = KDTreeCloud.Item2;


            DA.SetData(0, cloud);
        }
Пример #7
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)
        {
            GH_Cloud GHcloud = null;


            if (!DA.GetData(0, ref GHcloud))
            {
                return;
            }

            PointCloud   cloud = (PointCloud)GHcloud.Value;
            KDTree <int> tree  = KDTreeLib.ConstructKDTree(cloud);


            DA.SetData(0, new Type_KDTree(tree, GHcloud));
        }
Пример #8
0
 public Type_KDTree(KDTree <int> tree, GH_Cloud cloud)
 {
     this.Value = new Tuple <KDTree <int>, GH_Cloud>(tree, cloud);
 }
        /// <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)
        {
            ///define i/o parameters
            PointCloud        Rhino_Cloud   = new PointCloud();
            List <double>     Rhino_indices = new List <double>();
            List <PointCloud> Sub_Clouds    = new List <PointCloud>();
            List <GH_Cloud>   GH_subclouds  = new List <GH_Cloud>();

            /// read inputs
            if (!DA.GetData("Point_Cloud", ref Rhino_Cloud))
            {
                return;
            }
            if (!DA.GetDataList <double>("Indices", Rhino_indices))
            {
                return;
            }

            /// define internal parameters
            int cluster_count = (int)Rhino_indices.Max();

            ///1. maak lijsten van idexen per value van Rhino-indices
            ///2. Retrieve het punt van iedere index
            ///3. Add punt aan nieuwe cloud
            ///7. output

            var Rhino_xyz = Rhino_Cloud.GetPoints();
            var Rhino_n   = Rhino_Cloud.GetNormals();
            var Rhino_c   = Rhino_Cloud.GetColors();

            for (int i = 0; i < cluster_count; i++)
            {
                PointCloud Rhino_subcloud = new PointCloud();
                Random     r = new Random();

                ///var R= r.Next(0, 255); var R = r.Next(0, 255); var R = r.Next(0, 255);
                var color = new Color();
                color = Color.FromArgb(r.Next(0, 255), r.Next(0, 255), r.Next(0, 255));

                ///1.
                var C_indexlist = Enumerable.Range(0, Rhino_indices.Count).Where(flap => Rhino_indices[flap] == i + 1).ToList();
                ///2.


                if (Rhino_Cloud.ContainsNormals == true)
                {
                    for (int j = 0; j < C_indexlist.Count; j++)
                    {
                        ///3.
                        Rhino_subcloud.Add(Rhino_xyz[C_indexlist[j]], Rhino_n[C_indexlist[j]], color);
                    }
                }
                else
                {
                    for (int j = 0; j < C_indexlist.Count; j++)
                    {
                        ///3.
                        Rhino_subcloud.Add(Rhino_xyz[C_indexlist[j]], color);
                    }
                }


                ///7.
                GH_Cloud GH_subcloud = new GH_Cloud(Rhino_subcloud);
                GH_subclouds.Add(GH_subcloud);
            }

            ///output
            DA.SetDataList(0, GH_subclouds);
        }
        /// <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)
        {
            ///define i/o parameters
            PointCloud Rhino_Cloud = new PointCloud();
            Double     k           = 6;

            /// read inputs
            if (!DA.GetData(0, ref Rhino_Cloud))
            {
                return;
            }
            if (!DA.GetData("k", ref k))
            {
                return;
            }


            if (Rhino_Cloud.Count <= k)
            {
                throw new Size_Exception(string.Format("Use point clouds with more than k points"));
            }

            /// interal parameters
            List <Vector3d> normals = new List <Vector3d>();

            if (!Rhino_Cloud.ContainsNormals)
            {
                var X = Rhino_Cloud.Select(x => x.X).ToList();
                var Y = Rhino_Cloud.Select(x => x.Y).ToList();
                var Z = Rhino_Cloud.Select(x => x.Z).ToList();

                ///2.
                var Matlab_X = new MWNumericArray(Rhino_Cloud.Count, 1, X.ToArray());
                var Matlab_Y = new MWNumericArray(Rhino_Cloud.Count, 1, Y.ToArray());
                var Matlab_Z = new MWNumericArray(Rhino_Cloud.Count, 1, Z.ToArray());

                /// 3.
                Segmentation.segment segment_mesh = new Segmentation.segment();

                var mwca = (MWCellArray)segment_mesh.G_Normals(Matlab_X, Matlab_Y, Matlab_Z, k);

                /// 4.
                MWNumericArray na0 = (MWNumericArray)mwca[1];
                double[]       dc0 = (double[])na0.ToVector(0);

                MWNumericArray na1 = (MWNumericArray)mwca[2];
                double[]       dc1 = (double[])na1.ToVector(0);

                MWNumericArray na2 = (MWNumericArray)mwca[3];
                double[]       dc2 = (double[])na2.ToVector(0);


                /// 5.
                var      Rhino_param0 = new List <double>(dc0);
                var      Rhino_param1 = new List <double>(dc1);
                var      Rhino_param2 = new List <double>(dc2);
                Vector3d R            = new Vector3d();
                for (int i = 0; i < Rhino_param0.Count; i++)
                {
                    R = new Vector3d(Rhino_param0[i], Rhino_param1[i], Rhino_param2[i]);
                    normals.Add(R);
                }
            }

            else
            {
                normals = Rhino_Cloud.GetNormals().ToList();
            }

            PointCloud Rhino_Cloud_out = new PointCloud();

            Rhino_Cloud_out.AddRange(Rhino_Cloud.GetPoints(), normals);
            GH_Cloud Rhino_Cloud_out2 = new GH_Cloud(Rhino_Cloud_out);

            /// 6.
            DA.SetData(0, Rhino_Cloud_out2);
        }
Пример #11
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //Initialize Input Variables, Persistent in ComponentChange.
            List <double> pars = new List <double>();
            List <Color>  cols = new List <Color>();

            string strdc  = null;
            double colPct = 0.00;
            double step   = 0.0;

            if (!DA.GetData("Key", ref strdc))
            {
                return;
            }
            if (!DA.GetDataList("Values", pars))
            {
                return;
            }
            if (!DA.GetDataList("Colors", cols))
            {
                return;
            }
            if (!DA.GetData("BlendPct", ref colPct))
            {
                return;
            }
            DA.GetData("StepSize", ref step);

            if (colPct > 1.00)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Color Blending Percentage cannot be above 1.00.");
            }

            //Excute Instruction
            ///If Component is set as Instruction.
            if (isInstruction)
            {
                DA.SetData("Instr", new Instruction.Instr_Dict_Color(strdc, pars, cols, step, colPct));
            }
            else
            ///If Component is set to StandAlone.
            {
                ///Initialize PointCloud Input Variable.
                GH_Cloud pointCloud = null;
                if (!DA.GetData("Cloud", ref pointCloud))
                {
                    return;
                }
                ///Duplicate GH Cloud.
                GH_Cloud   newGHCloud = pointCloud.DuplicateCloud();
                PointCloud newCloud   = newGHCloud.Value;
                ///Execute Instruction.
                Instruction.Instr_Dict_Color inst = new Instruction.Instr_Dict_Color(strdc, pars, cols, step, colPct);
                Boolean Result = inst.Execute(ref newCloud);

                ///Set New Output Cloud
                newGHCloud.Value = newCloud;
                DA.SetData("Cloud", newGHCloud);

                //Add RuntimeMessage: ComponentChange.
                AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "'Right Click' to Switch between StandAlone and Instruction Component.");
            }
        }
Пример #12
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // 0.import data
            Autodesk.Revit.DB.PointCloudInstance element = null;
            double averageDistance = 0.01; int numPoints = 999999;

            if (!DA.GetData("Revit Point Cloud Instance", ref element))
            {
                return;
            }
            if (!DA.GetData("averageDistance", ref averageDistance))
            {
                return;
            }
            if (!DA.GetData("numPoints", ref numPoints))
            {
                return;
            }

            // 1.Create selection filter
            BoundingBoxXYZ boundingBox = element.get_BoundingBox(null);
            List <Autodesk.Revit.DB.Plane> planes = new List <Autodesk.Revit.DB.Plane>();

            // X boundaries
            planes.Add(Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(XYZ.BasisX, boundingBox.Min));
            planes.Add(Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(-XYZ.BasisX, boundingBox.Max));

            // Y boundaries
            planes.Add(Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(XYZ.BasisY, boundingBox.Min));
            planes.Add(Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(-XYZ.BasisY, boundingBox.Max));

            // Z boundaries
            planes.Add(Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(XYZ.BasisZ, boundingBox.Min));
            planes.Add(Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(-XYZ.BasisZ, boundingBox.Max));

            // Create filter
            PointCloudFilter filter = PointCloudFilterFactory.CreateMultiPlaneFilter(planes);

            // 2.Fetch point cloud
            PointCollection cloudPoints   = element.GetPoints(filter, averageDistance, numPoints);
            PointCloud      Rh_pointCloud = new PointCloud();

            // 3.Convert CloudPoints to rhino point cloud


            if (element.HasColor())
            {
                foreach (CloudPoint point in cloudPoints)
                {
                    // Process each point
                    Point3d point3d = new Point3d(point.X * 1000, point.Y * 1000, point.Z * 1000);

                    byte[] bArray = BitConverter.GetBytes(point.Color);
                    var    color  = System.Drawing.Color.FromArgb(bArray[0], bArray[1], bArray[2]);

                    Rh_pointCloud.Add(point3d, color);
                }
            }
            else
            {
                foreach (CloudPoint point in cloudPoints)
                {
                    // Process each point
                    Point3d point3d = new Point3d(point.X * 1000, point.Y * 1000, point.Z * 1000);
                    Rh_pointCloud.Add(point3d);
                }
            }


            // 4.Return Grasshopper Cloud
            GH_Cloud GH_pointCloud = new GH_Cloud(Rh_pointCloud);

            DA.SetData(0, GH_pointCloud);
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // 0.import data
            Autodesk.Revit.DB.Wall wall = null;
            Autodesk.Revit.DB.PointCloudInstance element = null;
            double bufferDistance = 0.30; int numPoints = 50000;

            if (!DA.GetData("Revit Wall", ref wall))
            {
                return;
            }
            if (!DA.GetData("Revit Point Cloud Instance", ref element))
            {
                return;
            }
            if (!DA.GetData("bufferDistance", ref bufferDistance))
            {
                return;
            }
            if (!DA.GetData("numPoints", ref numPoints))
            {
                return;
            }

            // 1.Create selection filter
            var width                     = wall.Width + bufferDistance * 2;
            //var width = wall.get_Parameter(BuiltInParameter.WALL_ATTR_WIDTH_PARAM).AsDouble();
            //double width = UnitUtils.ConvertFromInternalUnits(wall.WallType.Width, DisplayUnitType);
            BoundingBoxXYZ boundingBox    = wall.get_BoundingBox(null);

            // 2. Compute boundary U
            LocationCurve locationCurve_u = wall.Location as LocationCurve;
            XYZ           endPoint0_u     = locationCurve_u.Curve.GetEndPoint(0);
            XYZ           endPoint1_u     = locationCurve_u.Curve.GetEndPoint(1);
            var           ux              = endPoint1_u.X - endPoint0_u.X;
            var           uy = endPoint1_u.Y - endPoint0_u.Y;
            XYZ           uxy = new XYZ(ux, uy, 0);

            // 3. Compute boudary V
            XYZ midpoint = endPoint0_u + ((endPoint1_u - endPoint0_u) / 2);
            //var axis =  Autodesk.Revit.DB.Line.CreateUnbound(midpoint, XYZ.BasisZ);
            //var locationCurve_v=locationCurve_u.Rotate(axis, Math.PI * 0.5);

            var endPoint0_v = locationCurve_u.Curve.Evaluate(locationCurve_u.Curve.Length * 0.5 - width * 0.5 * 10 - bufferDistance * 10, false);
            var endPoint1_v = locationCurve_u.Curve.Evaluate(locationCurve_u.Curve.Length * 0.5 + width * 0.5 * 10 + bufferDistance * 10, false);

            // rotate points 90°
            var endPoint0_v_X = (endPoint0_v.X - midpoint.X) * Math.Cos(Math.PI * 0.5) + (endPoint0_v.Y - midpoint.Y) * Math.Sin(Math.PI * 0.5) + midpoint.X;
            var endPoint0_v_Y = (endPoint0_v.X - midpoint.X) * -Math.Sin(Math.PI * 0.5) + (endPoint0_v.Y - midpoint.Y) * Math.Cos(Math.PI * 0.5) + midpoint.Y;
            var endPoint1_v_X = (endPoint1_v.X - midpoint.X) * Math.Cos(Math.PI * 0.5) + (endPoint1_v.Y - midpoint.Y) * Math.Sin(Math.PI * 0.5) + midpoint.X;
            var endPoint1_v_Y = (endPoint1_v.X - midpoint.X) * -Math.Sin(Math.PI * 0.5) + (endPoint1_v.Y - midpoint.Y) * Math.Cos(Math.PI * 0.5) + midpoint.Y;
            XYZ boundary0_v = new XYZ(endPoint0_v_X, endPoint0_v_Y, 0);
            XYZ boundary1_v = new XYZ(endPoint1_v_X, endPoint1_v_Y, 0);
            //XYZ endPoint0_v = locationCurve_u.Curve.GetEndPoint(0);
            //XYZ endPoint1_v = locationCurve_u.Curve.GetEndPoint(1);
            var vx = boundary1_v.X - boundary0_v.X;
            var vy = boundary1_v.Y - boundary0_v.Y;
            XYZ vxy = new XYZ(vx, vy, 0);



            // 4. Create boundary planes
            List <Autodesk.Revit.DB.Plane> planes = new List <Autodesk.Revit.DB.Plane>();

            // U boundaries
            planes.Add(Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(uxy, endPoint0_u));
            planes.Add(Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(-uxy, endPoint1_u));

            // V boundaries
            planes.Add(Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(vxy, boundary0_v));
            planes.Add(Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(-vxy, boundary1_v));

            // Z boundaries
            planes.Add(Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(XYZ.BasisZ, boundingBox.Min));
            planes.Add(Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(-XYZ.BasisZ, boundingBox.Max));

            // Create filter
            PointCloudFilter filter = PointCloudFilterFactory.CreateMultiPlaneFilter(planes);

            // 5.Fetch point cloud
            PointCollection cloudPoints   = element.GetPoints(filter, bufferDistance, numPoints);
            PointCloud      Rh_pointCloud = new PointCloud();

            // 6.Convert CloudPoints to rhino point cloud


            if (element.HasColor())
            {
                foreach (CloudPoint point in cloudPoints)
                {
                    // Process each point
                    Point3d point3d = new Point3d(point.X * 1000, point.Y * 1000, point.Z * 1000);

                    byte[] bArray = BitConverter.GetBytes(point.Color);
                    var    color  = System.Drawing.Color.FromArgb(bArray[0], bArray[1], bArray[2]);

                    Rh_pointCloud.Add(point3d, color);
                }
            }
            else
            {
                foreach (CloudPoint point in cloudPoints)
                {
                    // Process each point
                    Point3d point3d = new Point3d(point.X * 1000, point.Y * 1000, point.Z * 1000);
                    Rh_pointCloud.Add(point3d);
                }
            }


            // 7.Return Grasshopper Cloud
            GH_Cloud GH_pointCloud = new GH_Cloud(Rh_pointCloud);

            DA.SetData(0, GH_pointCloud);
        }
Пример #14
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //Initialize Input Variables, Persistent in ComponentChange.
            List <Mesh> cMeshList  = new List <Mesh>();
            Boolean     InsideBool = true;

            if (!DA.GetDataList("Mesh", cMeshList))
            {
                return;
            }
            if (!DA.GetData("Leave", ref InsideBool))
            {
                return;
            }

            //Prepare Input for Instruction
            //and write ErrorMessages
            ///Initialize list of Boxes


            ///Loop through Input Meshes
            ///and test for face planarity and vertice count to determine if Box.
            foreach (Mesh cMesh in cMeshList)
            {
                cMesh.FaceNormals.ComputeFaceNormals();

                ///Write ErrorMessage.
                if (!cMesh.IsClosed)
                {
                    this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Are you sure it's a closed mesh?");
                    return;
                }
            }

            //Excute Instruction
            ///If Component is set as Instruction.
            if (isInstruction)
            {
                DA.SetData("Instr", new Instruction.Instr_MeshCrop(cMeshList, InsideBool));
            }
            else
            ///If Component is set to StandAlone.
            {
                ///Initialize PointCloud Input Variable.
                GH_Cloud pointCloud = null;
                if (!DA.GetData("Cloud", ref pointCloud))
                {
                    return;
                }
                ///Duplicate GH Cloud.
                GH_Cloud   newGHCloud = pointCloud.DuplicateCloud();
                PointCloud newCloud   = newGHCloud.Value;
                ///Execute Instruction.
                Instruction.Instr_MeshCrop inst = new Instruction.Instr_MeshCrop(cMeshList, InsideBool);
                Boolean Result = inst.Execute(ref newCloud);

                ///Set New Output Cloud
                newGHCloud.Value = newCloud;
                DA.SetData("Cloud", newGHCloud);

                //Add RuntimeMessage: ComponentChange.
                AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "'Right Click' to Switch between StandAlone and Instruction Component.");
            }
        }
Пример #15
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //Initialize Input Variables, Persistent in ComponentChange.
            List <Brep> cboxlist   = new List <Brep>();
            Boolean     InsideBool = true;

            if (!DA.GetDataList("Box", cboxlist))
            {
                return;
            }
            if (!DA.GetData("Leave", ref InsideBool))
            {
                return;
            }


            //Prepare Input for Instruction
            //and write ErrorMessages
            ///Initialize list of Boxes
            List <Box> boxList = new List <Box>();

            ///Loop through Input Boxes
            ///and test for face planarity and vertice count to determine if Box.
            foreach (Brep cbox in cboxlist)
            {
                BrepFace bf        = cbox.Faces[0];
                Plane    thisplane = new Plane();
                ///Write ErrorMessage eles add box to Box List.
                if (!bf.TryGetPlane(out thisplane, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance))
                {
                    this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Are you sure it's a box?");
                    return;
                }
                if (cbox.DuplicateVertices().Length != 8)
                {
                    this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Are you sure it's a box?");
                    return;
                }
                boxList.Add(new Box(thisplane, cbox));
            }

            //Excute Instruction
            ///If Component is set as Instruction.
            if (isInstruction)
            {
                DA.SetData("Instr", new Instruction.Instr_BoxCrop(boxList, InsideBool));
            }
            else
            ///If Component is set to StandAlone.
            {
                ///Initialize PointCloud Input Variable.
                GH_Cloud pointCloud = null;
                if (!DA.GetData("Cloud", ref pointCloud))
                {
                    return;
                }
                ///Duplicate GH Cloud.
                GH_Cloud   newGHCloud = pointCloud.DuplicateCloud();
                PointCloud newCloud   = newGHCloud.Value;
                ///Execute Instruction.
                Instruction.Instr_BoxCrop inst = new Instruction.Instr_BoxCrop(boxList, InsideBool);
                Boolean Result = inst.Execute(ref newCloud);

                ///Set New Output Cloud
                newGHCloud.Value = newCloud;
                DA.SetData("Cloud", newGHCloud);

                //Add RuntimeMessage: ComponentChange.
                AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "'Right Click' to Switch between StandAlone and Instruction Component.");
            }
        }
Пример #16
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //Initialize Input Variables, Persistent in ComponentChange.
            List <Point3d> CenterList = new List <Point3d>();
            List <double>  RadiusList = new List <double>();
            Boolean        InsideBool = true;

            if (!DA.GetDataList("Center", CenterList))
            {
                return;
            }
            if (!DA.GetDataList("Radius", RadiusList))
            {
                return;
            }
            if (!DA.GetData("Leave", ref InsideBool))
            {
                return;
            }

            //Prepare Input for Instruction
            //and write ErrorMessages
            ///Loop through Input Centers and Radiuses
            ///and test for equal count or single count.

            if (CenterList.Count > 1 & RadiusList.Count == 1)
            {
                for (int i = 1; i < CenterList.Count; i++)
                {
                    RadiusList.Add(RadiusList[0]);
                }
            }
            if (RadiusList.Count > 1 & CenterList.Count == 1)
            {
                for (int i = 1; i < RadiusList.Count; i++)
                {
                    CenterList.Add(CenterList[0]);
                }
            }
            else if (CenterList.Count != RadiusList.Count)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Need equal amount of CenterPoints and Radius'. Or single of one of them.");
                return;
            }

            //Excute Instruction
            ///If Component is set as Instruction.
            if (isInstruction)
            {
                DA.SetData("Instr", new Instruction.Instr_SphereCrop(CenterList, RadiusList, InsideBool));
            }
            else
            ///If Component is set to StandAlone.
            {
                ///Initialize PointCloud Input Variable.
                GH_Cloud pointCloud = null;
                if (!DA.GetData("Cloud", ref pointCloud))
                {
                    return;
                }
                ///Duplicate GH Cloud.
                GH_Cloud   newGHCloud = pointCloud.DuplicateCloud();
                PointCloud newCloud   = newGHCloud.Value;
                ///Execute Instruction.
                Instruction.Instr_SphereCrop inst = new Instruction.Instr_SphereCrop(CenterList, RadiusList, InsideBool);
                Boolean Result = inst.Execute(ref newCloud);

                ///Set New Output Cloud
                newGHCloud.Value = newCloud;
                DA.SetData("Cloud", newGHCloud);

                //Add RuntimeMessage: ComponentChange.
                AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "'Right Click' to Switch between StandAlone and Instruction Component.");
            }
        }