protected override void SolveInstance(IGH_DataAccess DA) { ///input parameters PointCloud Rhino_Cloud1 = new PointCloud(); PointCloud Rhino_Cloud2 = new PointCloud(); /// initialise parameters double Metric = 0.0, InlierRatio = 1.0, MaxIterations = 60; ///import if (!DA.GetData("pc_moving", ref Rhino_Cloud1)) { return; } if (!DA.GetData("pc_fixed", ref Rhino_Cloud2)) { return; } if (!DA.GetData("Metric", ref Metric)) { return; } if (!DA.GetData("InlierRatio", ref InlierRatio)) { return; } if (!DA.GetData("MaxIterations", ref MaxIterations)) { return; } /// 1. decompose points into doubles (rhinocommon => .NET) /// 2. create appropriete matlab arrays (.NET => Matlab) /// 3. run matlab function (Matlab) /// 4. convert function output (list with indices) to .Net array (Matlab => .Net) /// 5. convert array to rhinocommon list. (.Net => Rhinocommon) /// 6. output data /// 1. var Rhino_xyz1 = Rhino_Cloud1.GetPoints(); var Rhino_xyz2 = Rhino_Cloud2.GetPoints(); List <double> xyz1 = new List <double>(); List <double> xyz2 = new List <double>(); for (int i = 0; i < Rhino_Cloud1.Count; i++) { xyz1.Add(Rhino_xyz1[i].X); xyz1.Add(Rhino_xyz1[i].Y); xyz1.Add(Rhino_xyz1[i].Z); } var Matlab_xyz1 = new MWNumericArray(Rhino_Cloud1.Count, 3, xyz1.ToArray()); for (int j = 0; j < Rhino_Cloud2.Count; j++) { xyz2.Add(Rhino_xyz2[j].X); xyz2.Add(Rhino_xyz2[j].Y); xyz2.Add(Rhino_xyz2[j].Z); } var Matlab_xyz2 = new MWNumericArray(Rhino_Cloud2.Count, 3, xyz2.ToArray()); /// 3. Scan2BIM_Matlab.General general = new Scan2BIM_Matlab.General(); //MWArray[] Result = new MWArray[2]; MWArray cluster = new MWNumericArray(); cluster = general.S2B_ICP2(Matlab_xyz1, Matlab_xyz2, Metric, InlierRatio, MaxIterations); /// 4. MWNumericArray na = (MWNumericArray)cluster; double[] dc = (double[])na.ToVector(0); /// 5. var Rhino_param = new List <double>(dc); /// 6. DA.SetDataList(0, Rhino_param); }
/// <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 rhinoCloud = new PointCloud(); Double k = 6; /// read inputs if (!DA.GetData(0, ref rhinoCloud)) { return; } if (!DA.GetData("k", ref k)) { return; } ///exceptions if (rhinoCloud.Count <= k) { throw new Size_Exception(string.Format("Use point clouds with more than k points")); } if (k < 3) { throw new Size_Exception(string.Format("enter value k >=3")); } /// interal parameters List <Vector3d> normals = new List <Vector3d>(); if (!rhinoCloud.ContainsNormals) { var X = rhinoCloud.Select(x => x.X).ToList(); var Y = rhinoCloud.Select(x => x.Y).ToList(); var Z = rhinoCloud.Select(x => x.Z).ToList(); ///2. var Matlab_X = new MWNumericArray(rhinoCloud.Count, 1, X.ToArray()); var Matlab_Y = new MWNumericArray(rhinoCloud.Count, 1, Y.ToArray()); var Matlab_Z = new MWNumericArray(rhinoCloud.Count, 1, Z.ToArray()); /// 3. Scan2BIM_Matlab.General general = new Scan2BIM_Matlab.General(); var mwca = (MWCellArray)general.S2B_ComputeNormals2(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 = rhinoCloud.GetNormals().ToList(); } PointCloud rhinoCloud_out = new PointCloud(); rhinoCloud_out.AddRange(rhinoCloud.GetPoints(), normals); GH_Cloud rhinoCloud_out2 = new GH_Cloud(rhinoCloud_out); /// 6. DA.SetData(0, rhinoCloud_out2); }