protected override void SolveInstance(IGH_DataAccess DA) { ///input parameters List <double> tform = new List <double>(); /// initialise parameters ///import if (!DA.GetDataList("tform", tform)) { return; } /// 0. error catching /// 1. decompose tform into translation /// 2. decompose tform in euler XYZ rotations /// 4. convert function output (list with indices) to .Net array (Matlab => .Net) /// 5. convert array to rhinocommon list. (.Net => Rhinocommon) /// 6. output data ///0. if (tform.Count != 16) { throw new Size_Exception(string.Format("Need[16, 1] parameters")); } /// 1. Vector3d T = new Vector3d(tform[3], tform[7], tform[11]); /// 2. var param = new MWNumericArray(16, 1, tform.ToArray()); Segmentation.segment segment_mesh = new Segmentation.segment(); MWArray rotXYZ = new MWNumericArray(); rotXYZ = segment_mesh.G_rotm2eul(param); /// 4. MWNumericArray na = (MWNumericArray)rotXYZ; double[] dc = (double[])na.ToVector(0); /// 5. var Rhino_rotXYZ = new List <double>(dc); Vector3d R = new Vector3d(Rhino_rotXYZ[0], Rhino_rotXYZ[1], Rhino_rotXYZ[2]); /// 6. DA.SetData("R", R); DA.SetData("t", T); }
protected override void SolveInstance(IGH_DataAccess DA) { ///input parameters List <Point3d> Rhino_points = new List <Point3d>(); /// initialise parameters double T_N = 0.0, D = 0.0, M = 0.0, O = 0.0, T_s = 0.0; List <double> Rhino_indices = new List <double>(); List <double> Rhino_xyz = new List <double>(); ///import data if (!DA.GetDataList("Points", Rhino_points)) { return; } if (!DA.GetData("ThresValN", ref T_N)) { return; } if (!DA.GetData("MaxDist", ref D)) { return; } if (!DA.GetData("Minsize", ref M)) { return; } if (!DA.GetData("Offset", ref O)) { return; } if (!DA.GetData("Tilesize", ref T_s)) { 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. for (int i = 0; i < Rhino_points.Count; i++) { Rhino_xyz[i * 3] = Rhino_points[i].X; Rhino_xyz[i * 3 + 1] = Rhino_points[i].Y; Rhino_xyz[i * 3 + 2] = Rhino_points[i].Z; } /// 2. var Matlab_xyz = new MWNumericArray(Rhino_points.Count, 3, Rhino_xyz.ToArray()); var Matlab_n = new MWNumericArray(); var Matlab_c = new MWNumericArray(); /// 3. Segmentation.segment segment_mesh = new Segmentation.segment(); MWArray cluster = new MWNumericArray(); cluster = segment_mesh.G_RegionGrowingNC2(Matlab_xyz, Matlab_n, Matlab_c, T_N, D, M, O, T_s); /// 4. MWNumericArray na = (MWNumericArray)cluster; double[] dc = (double[])na.ToVector(0); /// 5. Rhino_indices = new List <double>(dc); /// 6. DA.SetDataList(0, Rhino_indices); }
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. Segmentation.segment segment_mesh = new Segmentation.segment(); //MWArray[] Result = new MWArray[2]; MWArray cluster = new MWNumericArray(); cluster = segment_mesh.G_ICP(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); }
protected override void SolveInstance(IGH_DataAccess DA) { ///input parameters Mesh Rhino_mesh = new Mesh(); /// initialise parameters double T_N = 0.0, T_C = 0.0, D = 0.0, M = 0.0, O = 0.0, T_s = 0.0; List <double> Rhino_indices = new List <double>(); ///import data if (!DA.GetData("Mesh", ref Rhino_mesh)) { return; } if (!DA.GetData("ThresValN", ref T_N)) { return; } if (!DA.GetData("ThresValC", ref T_C)) { return; } if (!DA.GetData("MaxDist", ref D)) { return; } if (!DA.GetData("Minsize", ref M)) { return; } if (!DA.GetData("Offset", ref O)) { return; } if (!DA.GetData("Tilesize", ref T_s)) { return; } ///get mesh data to Matlab /// 1. decompose mesh into face centroids/normals (rhinocommon => .NET) /// 1a. compute normals if not present /// 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_c = new Point3f(); var Rhino_n = new Vector3f(); MeshFace Rhino_face = new MeshFace(); var C_xyz = new float[Rhino_mesh.Faces.Count * 3]; var C_n = new float[Rhino_mesh.Faces.Count * 3]; var C_c = new float[Rhino_mesh.Faces.Count * 3]; int r1, r2, r3, g1, g2, g3, b1, b2, b3, r, g, b; ///1a. check if normals are present if (Rhino_mesh.FaceNormals.Count == 0) { Rhino_mesh.FaceNormals.ComputeFaceNormals(); } /// 2. for (int i = 0; i < Rhino_mesh.Faces.Count; i++) { Rhino_c = (Point3f)Rhino_mesh.Faces.GetFaceCenter(i); C_xyz[i * 3] = Rhino_c.X; C_xyz[i * 3 + 1] = Rhino_c.Y; C_xyz[i * 3 + 2] = Rhino_c.Z; Rhino_n = Rhino_mesh.FaceNormals[i]; C_n[i * 3] = Rhino_n.X; C_n[i * 3 + 1] = Rhino_n.Y; C_n[i * 3 + 2] = Rhino_n.Z; Rhino_face = Rhino_mesh.Faces.GetFace(i); if (Rhino_mesh.VertexColors.Count > 0) { r1 = Rhino_mesh.VertexColors[Rhino_face[0]].R; g1 = Rhino_mesh.VertexColors[Rhino_face[0]].G; b1 = Rhino_mesh.VertexColors[Rhino_face[0]].B; r2 = Rhino_mesh.VertexColors[Rhino_face[1]].R; g2 = Rhino_mesh.VertexColors[Rhino_face[1]].G; b2 = Rhino_mesh.VertexColors[Rhino_face[1]].B; r3 = Rhino_mesh.VertexColors[Rhino_face[2]].R; g3 = Rhino_mesh.VertexColors[Rhino_face[2]].G; b3 = Rhino_mesh.VertexColors[Rhino_face[2]].B; r = (r1 + r2 + r3) / 3; g = (g1 + g2 + g3) / 3; b = (b1 + b2 + b3) / 3; C_c[i * 3] = r; C_c[i * 3 + 1] = g; C_c[i * 3 + 2] = b; } } var Matlab_xyz = new MWNumericArray(Rhino_mesh.Faces.Count, 3, C_xyz); var Matlab_n = new MWNumericArray(Rhino_mesh.Faces.Count, 3, C_n); var Matlab_c = new MWNumericArray(Rhino_mesh.Faces.Count, 3, C_c); /// 3. Segmentation.segment segment_mesh = new Segmentation.segment(); MWArray cluster = new MWNumericArray(); cluster = segment_mesh.G_RegionGrowingNC2(Matlab_xyz, Matlab_n, Matlab_c, T_N, T_C, D, M, O, T_s); /// 4. MWNumericArray na = (MWNumericArray)cluster; double[] dc = (double[])na.ToVector(0); /// 5. Rhino_indices = new List <double>(dc); /// 6. DA.SetDataList(0, Rhino_indices); }
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 = 0.2, MaxIterations = 20, Downsampling1 = 1.0, Downsampling2 = 1.0; ///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; } if (!DA.GetData("Downsample pc_moving", ref Downsampling1)) { return; } if (!DA.GetData("Downsample pc_fixed", ref Downsampling2)) { return; } /// 0. error catching /// 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 if (Rhino_Cloud1.Count <= 1 || Rhino_Cloud2.Count <= 1) { throw new Size_Exception(string.Format("Use point clouds with more than 1 point")); } if (Downsampling1 == 0 || Downsampling2 == 0) { throw new Size_Exception(string.Format("Do not use 0 as downsampling")); } /// 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>(); int interval1 = (int)(1 / Downsampling1); int interval2 = (int)(1 / Downsampling2); var Rhino_xyz11 = Rhino_xyz1 .Where((v, index) => index % interval1 == 0) .ToList(); var Rhino_xyz22 = Rhino_xyz2 .Where((v, index) => index % interval2 == 0) .ToList(); for (int i = 0; i < Rhino_xyz11.Count; i++) { xyz1.Add(Rhino_xyz11[i].X); xyz1.Add(Rhino_xyz11[i].Y); xyz1.Add(Rhino_xyz11[i].Z); } var Matlab_xyz1 = new MWNumericArray(Rhino_xyz11.Count, 3, xyz1.ToArray()); for (int j = 0; j < Rhino_xyz22.Count; j++) { xyz2.Add(Rhino_xyz22[j].X); xyz2.Add(Rhino_xyz22[j].Y); xyz2.Add(Rhino_xyz22[j].Z); } var Matlab_xyz2 = new MWNumericArray(Rhino_xyz22.Count, 3, xyz2.ToArray()); /// 3. Segmentation.segment segment_mesh = new Segmentation.segment(); var mwca = (MWCellArray)segment_mesh.G_ICP2(Matlab_xyz1, Matlab_xyz2, Metric, InlierRatio, MaxIterations); /// 4. MWNumericArray na0 = (MWNumericArray)mwca[1]; double[] dc0 = (double[])na0.ToVector(0); MWNumericArray na1 = (MWNumericArray)mwca[2]; double[] dc1 = (double[])na1.ToVector(0); /// 5. var Rhino_param0 = new List <double>(dc0); var Rhino_param1 = new List <double>(dc1); /// 6. DA.SetDataList(0, Rhino_param0); DA.SetDataList(1, Rhino_param1); }