From 1fe254b340ad28315db9a8c880d9212a896f1d8a Mon Sep 17 00:00:00 2001 From: xArthur Date: Thu, 24 Mar 2022 14:14:47 +0100 Subject: [PATCH] add: gaussian curvature. --- README.md | 31 ++++++-- igmGH/igmGH.csproj | 3 +- igmGH/meshBarycenter.cs | 2 +- igmGH/meshCurvatureGaussian.cs | 73 +++++++++++++++++++ ...Curvature.cs => meshCurvaturePrincipal.cs} | 2 +- igmGH/meshLaplacian.cs | 2 +- igmGH/meshNormalFace.cs | 2 +- igmGH/meshNormalsCorner.cs | 2 +- igmGH/meshNormalsVertex.cs | 2 +- igmRhinoCommon/Utils.cs | 13 ++++ igmRhinoCommon/cppNativeMethod.cs | 12 ++- 11 files changed, 126 insertions(+), 18 deletions(-) create mode 100644 igmGH/meshCurvatureGaussian.cs rename igmGH/{meshPrincipalCurvature.cs => meshCurvaturePrincipal.cs} (98%) diff --git a/README.md b/README.md index a1ba843..1610ee9 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,13 @@ The library is developed for the general architecture, design, and fabrication community, hoping to provide solutions for low-level mesh operation to resolve the long-lasting pain for mesh processing on the [Rhino](https://www.rhino3d.com) \& [Grasshopper](https://www.grasshopper3d.com) platform. ## Download & Installation (TODO) -The most recent release version can be found in the release section. -The [project page](_blank) on [Food4Rhino](https://www.food4rhino.com/en) also holds major release version of this library. +Pre-compiled releases are available on the [GitHub repo](https://github.com/xarthurx/IG-Mesh): +1. Download the `.zip` file for your OS from [the latest release](https://github.com/xarthurx/IG-Mesh/releases/latest). +2. Unzip the `.zip` file and put the folder into you "Grasshopper Component Folder". +3. Restart Rhino and Grasshopper. + +The [project page on Food4Rhino](https://www.food4rhino.com/en) also holds major release versions of this library. ## Library credit @@ -31,6 +35,15 @@ Please submit an issue and tell me what your mesh processing task requires and w I will add the corresponding functions to the library after evaluation, ASAP. +## Future Planning +Below is an incomplete list of functions that `IG-Mesh` plans to provide. The list is constantly adjusted based on feedback: + +- edge-related functions and half-Edge data structure +- geodesic related functions (shortest paths, heat-geodesic, etc.) +- FEM-related functions (need evaluation on speed and computational efficiency) +- tet-based volume processing functionality + + ## Licence The library is released under the [MIT licence](./docs/LICENCE.md). @@ -50,6 +63,8 @@ If `IG-Mesh` contributes to an academic publication, cite it as: ``` ## Compilation and Contribution +You need to install `Visual Studio 2017` or above to compile the project. + ### `openNURBS` 1. Download the [openNURBS](https://github.com/mcneel/opennurbs) library to your local desk, compile it (both `debug` and `Release`). @@ -60,12 +75,12 @@ If `IG-Mesh` contributes to an academic publication, cite it as: 1. Download the [libigl](https://libigl.github.io) library to your local desk. 2. Add the `include` dir in the Property Page of `igm_cppPort`. -### nuget packages -In the `NuGet` package manager, you should install the following packages for the solution: -- Grasshopper -- RhinoCommon -- System.Collections -- System.Runtime +### `nuget` Packages +In the `NuGet` package manager of `Visual Studio`, you should install the following packages for the solution: +- `Grasshopper` +- `RhinoCommon` +- `System.Collections` +- `System.Runtime` ### Build this library After the above two steps, you should now be able to build the whole solution and generate the `.gha` and `.dll` file. diff --git a/igmGH/igmGH.csproj b/igmGH/igmGH.csproj index 4a67581..2fb1c13 100644 --- a/igmGH/igmGH.csproj +++ b/igmGH/igmGH.csproj @@ -47,6 +47,7 @@ + @@ -55,7 +56,7 @@ - + diff --git a/igmGH/meshBarycenter.cs b/igmGH/meshBarycenter.cs index 0fea0d2..48cd790 100644 --- a/igmGH/meshBarycenter.cs +++ b/igmGH/meshBarycenter.cs @@ -11,7 +11,7 @@ public class IGM_barycenter : GH_Component public IGM_barycenter() : base("Barycenter", "iBarycenter", "compute the barycenter of each triangle of the given mesh.", - "IG-Mesh", "02 | Basic Property") + "IG-Mesh", "02 | Properties") { } diff --git a/igmGH/meshCurvatureGaussian.cs b/igmGH/meshCurvatureGaussian.cs new file mode 100644 index 0000000..8245e5c --- /dev/null +++ b/igmGH/meshCurvatureGaussian.cs @@ -0,0 +1,73 @@ +using Grasshopper.Kernel; +using System; + +namespace igmGH +{ + public class IGM_gaussian_curvature : GH_Component + { + /// + /// Initializes the new instance of the corner_normals class. + /// + public IGM_gaussian_curvature() + : base("Gaussian Curvature", "iGaussianCurvature", + "Compute discrete local integral gaussian curvature of the given mesh (angle deficit, without averaging by local area).", + "IG-Mesh", "02 | Properties") + { + } + + /// + /// Registers all the input parameters for this component. + /// + protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager) + { + pManager.AddMeshParameter("Mesh", "M", "input mesh to analysis.", GH_ParamAccess.item); + } + + /// + /// Registers all the output parameters for this component. + /// + protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager) + { + pManager.AddNumberParameter("Curvature", "K", "Discrete gaussian curvature values.", GH_ParamAccess.list); + } + + /// + /// This is the method that actually does the work. + /// + /// The DA object is used to retrieve from inputs and store in outputs. + protected override void SolveInstance(IGH_DataAccess DA) + { + + Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh(); + if (!DA.GetData(0, ref mesh)) { return; } + if (!mesh.IsValid) { return; } + + // call the cpp function to solve the adjacency list + var k = IGLRhinoCommon.Utils.getGaussianCurvature(ref mesh); + + // output + DA.SetDataList(0, k); + } + + /// + /// Provides an Icon for the component. + /// + protected override System.Drawing.Bitmap Icon + { + get + { + //You can add image files to your project resources and access them like this: + // return Resources.IconForThisComponent; + return null; + } + } + + /// + /// Gets the unique ID for this component. Do not change this ID after release. + /// + public override Guid ComponentGuid + { + get { return new Guid("6d32480e-e790-4b3f-9ad5-1fb638b75ba4"); } + } + } +} diff --git a/igmGH/meshPrincipalCurvature.cs b/igmGH/meshCurvaturePrincipal.cs similarity index 98% rename from igmGH/meshPrincipalCurvature.cs rename to igmGH/meshCurvaturePrincipal.cs index 306b239..be1dea4 100644 --- a/igmGH/meshPrincipalCurvature.cs +++ b/igmGH/meshCurvaturePrincipal.cs @@ -11,7 +11,7 @@ public class IGM_principal_curvature : GH_Component public IGM_principal_curvature() : base("Principal Curvature", "iPrincipalCurvature", "Compute the principal curvature directions and magnitude of the given triangle mesh.", - "IG-Mesh", "05 | Query") + "IG-Mesh", "02 | Properties") { } diff --git a/igmGH/meshLaplacian.cs b/igmGH/meshLaplacian.cs index ec45606..a0509d7 100644 --- a/igmGH/meshLaplacian.cs +++ b/igmGH/meshLaplacian.cs @@ -12,7 +12,7 @@ public class IGM_laplacian : GH_Component public IGM_laplacian() : base("IGM_Laplacian", "igLaplacian", "Solve laplacian equation under given boundary condition.", - "IG-Mesh", "05 | Query") + "IG-Mesh", "06 | Utils") { } diff --git a/igmGH/meshNormalFace.cs b/igmGH/meshNormalFace.cs index 7218187..e9d2974 100644 --- a/igmGH/meshNormalFace.cs +++ b/igmGH/meshNormalFace.cs @@ -11,7 +11,7 @@ public class IGM_vert_face_normals : GH_Component public IGM_vert_face_normals() : base("Face Normal", "iNormals_F", "Compute the per face normals of the given mesh.", - "IG-Mesh", "02 | Basic Property") + "IG-Mesh", "02 | Properties") { } diff --git a/igmGH/meshNormalsCorner.cs b/igmGH/meshNormalsCorner.cs index 6e3a94b..54fb2c1 100644 --- a/igmGH/meshNormalsCorner.cs +++ b/igmGH/meshNormalsCorner.cs @@ -12,7 +12,7 @@ public class IGM_normals_corner : GH_Component public IGM_normals_corner() : base("Corner Normal", "iNormals_C", "Compute per corner normals for a triangle mesh by computing the area-weighted average of normals at incident faces whose normals deviate less than the provided threshold.", - "IG-Mesh", "02 | Basic Property") + "IG-Mesh", "02 | Properties") { } diff --git a/igmGH/meshNormalsVertex.cs b/igmGH/meshNormalsVertex.cs index 161d8fe..1013e86 100644 --- a/igmGH/meshNormalsVertex.cs +++ b/igmGH/meshNormalsVertex.cs @@ -11,7 +11,7 @@ public class IGM_vert_normals : GH_Component public IGM_vert_normals() : base("Vertex Normal", "iNormals_V", "Compute the per vertex normals of the given mesh.", - "IG-Mesh", "02 | Basic Property") + "IG-Mesh", "02 | Properties") { } diff --git a/igmRhinoCommon/Utils.cs b/igmRhinoCommon/Utils.cs index 3149f42..f434f49 100644 --- a/igmRhinoCommon/Utils.cs +++ b/igmRhinoCommon/Utils.cs @@ -707,6 +707,19 @@ public static (List PD1, List PD2, List PV1, List getGaussianCurvature(ref Mesh rMesh) + { + if (rMesh == null) throw new ArgumentNullException(nameof(rMesh)); + IntPtr pMesh = Rhino.Runtime.Interop.NativeGeometryConstPointer(rMesh); + + var Kcpp = new Rhino.Runtime.InteropWrappers.SimpleArrayDouble(); + + CppIGM.IGM_gaussian_curvature(pMesh, Kcpp.NonConstPointer()); + + List K = new List(Kcpp.ToArray()); + return K; + } + public static List getFastWindingNumber(ref Mesh rMesh, ref List Q) { if (rMesh == null) throw new ArgumentNullException(nameof(rMesh)); diff --git a/igmRhinoCommon/cppNativeMethod.cs b/igmRhinoCommon/cppNativeMethod.cs index a337788..7525edf 100644 --- a/igmRhinoCommon/cppNativeMethod.cs +++ b/igmRhinoCommon/cppNativeMethod.cs @@ -121,19 +121,25 @@ internal static extern void computeLaplacian(IntPtr V, int nV, IntPtr F, int nF, IntPtr con_idx, IntPtr con_val, int numCon, IntPtr laplacianValue); /// - /// randomly sample points on meshes. + /// randomly sample points on meshes /// [DllImport(Import.cppLib, CallingConvention = CallingConvention.Cdecl)] internal static extern void IGM_random_point_on_mesh(IntPtr pMesh, int N, IntPtr B, IntPtr FI); /// - /// principal curvatures. + /// Compute principal curvatures /// [DllImport(Import.cppLib, CallingConvention = CallingConvention.Cdecl)] internal static extern void IGM_principal_curvature(IntPtr pMesh, uint r, IntPtr PD1, IntPtr PD2, IntPtr PV1, IntPtr PV2); /// - /// compute fast winding number + /// Compute gaussian curvatures + /// + [DllImport(Import.cppLib, CallingConvention = CallingConvention.Cdecl)] + internal static extern void IGM_gaussian_curvature(IntPtr pMesh, IntPtr K); + + /// + /// compute the fast winding number /// [DllImport(Import.cppLib, CallingConvention = CallingConvention.Cdecl)] internal static extern void IGM_fast_winding_number(IntPtr pMesh, IntPtr Q, IntPtr W);