/// <summary>
 /// Set Instruction Input Variables
 /// Calculate closestPoint distances between the two Clouds (KDTree Already Constructed).
 /// </summary>
 /// <param name="kdTree"></param>
 /// <param name="K"></param>
 ///  <param name="A">Amount of closest points to average out.</param>/param
 /// <param name="C_bool"></param>
 public Instr_KDTree_CloudCloud(Type_KDTree kdTree, string K, int A, Boolean C_bool)
 {
     insV_KDTree   = kdTree;
     insV_Key      = K;
     insV_Colorize = C_bool;
     insV_Amount   = A;
 }
        /// <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.");
            }
        }
        /// <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;
            string      Key    = string.Empty;

            if (!DA.GetData("KDTree", ref KDTree))
            {
                return;
            }
            if (!DA.GetData("Amount", ref Amount))
            {
                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_KDTree_CloudCloud(KDTree, Key, Amount, 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_KDTree_CloudCloud inst = new Instruction.Instr_KDTree_CloudCloud(KDTree, Key, Amount, 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.");
            }
        }
        /// <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);
        }
        /// <summary>
        /// SetUp Duplication procedure.
        /// </summary>
        /// <returns></returns>
        public override IGH_Goo Duplicate()
        {
            Type_KDTree nKd = insV_KDTree;
            string      nK  = insV_Key;
            int         nA  = insV_Amount;
            Boolean     nC  = insV_Colorize;

            Instr_KDTree_CloudCloud ni = new Instr_KDTree_CloudCloud(nKd, nK, nA, nC);

            ni.GlobalCloud         = null;
            ni.NewCloud            = null;
            ni.PointCounter        = 0;
            ni.LastPercentReported = 0;
            ni.tree      = null;
            ni.cloudTo   = null;
            ni.pts       = null;
            ni.Distances = null;
            return(ni);
        }
Beispiel #6
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)
        {
            // PointCloud to meassure Distance From.
            PointCloud cloudFrom = null;
            // PointCloud/KDTree to meassure Distance From.
            Type_KDTree treeT = null;
            // Amount
            int amount = 1;
            //UserData Key String.
            string key = "CloCloD";

            if (!DA.GetData(0, ref cloudFrom))
            {
                return;
            }
            if (!DA.GetData(1, ref treeT))
            {
                return;
            }
            if (!DA.GetData(2, ref amount))
            {
                return;
            }
            if (!DA.GetData(3, ref key))
            {
                return;
            }

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

            //Make Duplicate to make sure I dont change UserData in input Cloud.
            cloudFrom = (PointCloud)cloudFrom.Duplicate();

            //Calculate closestPoint distances between the two Clouds.
            double[] dist = KDTreeLib.CloudCloudDist(cloudFrom, KDTreeCloud, amount);

            //Add Distances to UserDictionary
            cloudFrom.UserDictionary.Set(key, dist);

            //Output
            DA.SetData(0, cloudFrom);
        }
Beispiel #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)
        {
            Type_KDTree    treeT       = null;
            List <Point3d> pts         = new List <Point3d>();
            List <double>  range       = new List <double>();
            int            maxReturned = 100;

            if (!DA.GetData("KDTree", ref treeT))
            {
                return;
            }
            if (!DA.GetDataList("Points", pts))
            {
                return;
            }
            if (!DA.GetDataList("Range", range))
            {
                return;
            }
            DA.GetData("Number of Neighbors", ref maxReturned);

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


            if (range.Count > 1 && range.Count < pts.Count)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Amount of Range values should be a single value, or match the amount of search points.");
                return;
            }

            List <int>[] idc = KDTreeLib.NearestNeighborSearch(tree, pts, range, maxReturned);


            var path1 = DA.ParameterTargetPath(0);
            DataTree <Point3d>        pointT    = new DataTree <Point3d>();
            DataTree <Vector3d>       normalT   = new DataTree <Vector3d>();
            DataTree <Color>          colorT    = new DataTree <Color>();
            DataTree <double>         distanceT = new DataTree <double>();
            GH_Structure <GH_Integer> idxT      = new GH_Structure <GH_Integer>();

            for (int i = 0; i < pts.Count; i++)
            {
                List <int> ids = idc[i];
                for (int j = 0; j < ids.Count; j++)
                {
                    pointT.Add(cloud[ids[j]].Location, path1.AppendElement(i));
                    if (cloud.ContainsNormals)
                    {
                        normalT.Add(cloud[ids[j]].Normal, path1.AppendElement(i));
                    }
                    if (cloud.ContainsColors)
                    {
                        colorT.Add(cloud[ids[j]].Color, path1.AppendElement(i));
                    }
                    //Distance betwen Points
                    double D = pts[i].DistanceTo(cloud[ids[j]].Location);
                    distanceT.Add(D, path1.AppendElement(i));
                }
                idxT.AppendRange(ids.Select(x => new GH_Integer(x)), path1.AppendElement(i));
            }


            DA.SetDataTree(0, pointT);
            DA.SetDataTree(1, normalT);
            DA.SetDataTree(2, colorT);
            DA.SetDataTree(3, distanceT);
            DA.SetDataTree(4, idxT);
        }