Skip to content

Commit

Permalink
add: gaussian curvature.
Browse files Browse the repository at this point in the history
  • Loading branch information
xarthurx committed Mar 24, 2022
1 parent baf18fa commit 1fe254b
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 18 deletions.
31 changes: 23 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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).

Expand All @@ -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`).

Expand All @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion igmGH/igmGH.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<ItemGroup>
<Compile Include="meshBoundEdge.cs" />
<Compile Include="meshFastWindingNumber.cs" />
<Compile Include="meshCurvatureGaussian.cs" />
<Compile Include="meshInfo.cs" />
<Compile Include="meshNormalFace.cs" />
<Compile Include="meshNormalsCorner.cs" />
Expand All @@ -55,7 +56,7 @@
<Compile Include="meshBoundLoop.cs" />
<Compile Include="meshAdjacencyTriTri.cs" />
<Compile Include="meshAdjacencyVertTri.cs" />
<Compile Include="meshPrincipalCurvature.cs" />
<Compile Include="meshCurvaturePrincipal.cs" />
<Compile Include="meshRandomPointsOnMesh.cs" />
<Compile Include="igm_Info.cs" />
<Compile Include="meshAdjacentVertVert.cs" />
Expand Down
2 changes: 1 addition & 1 deletion igmGH/meshBarycenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
}

Expand Down
73 changes: 73 additions & 0 deletions igmGH/meshCurvatureGaussian.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using Grasshopper.Kernel;
using System;

namespace igmGH
{
public class IGM_gaussian_curvature : GH_Component
{
/// <summary>
/// Initializes the new instance of the corner_normals class.
/// </summary>
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")
{
}

/// <summary>
/// Registers all the input parameters for this component.
/// </summary>
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddMeshParameter("Mesh", "M", "input mesh to analysis.", GH_ParamAccess.item);
}

/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddNumberParameter("Curvature", "K", "Discrete gaussian curvature values.", GH_ParamAccess.list);
}

/// <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)
{

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);
}

/// <summary>
/// Provides an Icon for the component.
/// </summary>
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;
}
}

/// <summary>
/// Gets the unique ID for this component. Do not change this ID after release.
/// </summary>
public override Guid ComponentGuid
{
get { return new Guid("6d32480e-e790-4b3f-9ad5-1fb638b75ba4"); }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
}

Expand Down
2 changes: 1 addition & 1 deletion igmGH/meshLaplacian.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
}

Expand Down
2 changes: 1 addition & 1 deletion igmGH/meshNormalFace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
}

Expand Down
2 changes: 1 addition & 1 deletion igmGH/meshNormalsCorner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
}

Expand Down
2 changes: 1 addition & 1 deletion igmGH/meshNormalsVertex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
}

Expand Down
13 changes: 13 additions & 0 deletions igmRhinoCommon/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,19 @@ public static (List<Vector3d> PD1, List<Vector3d> PD2, List<double> PV1, List<do
return (PD1, PD2, PV1, PV2);
}

public static List<double> 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<double> K = new List<double>(Kcpp.ToArray());
return K;
}

public static List<double> getFastWindingNumber(ref Mesh rMesh, ref List<Point3d> Q)
{
if (rMesh == null) throw new ArgumentNullException(nameof(rMesh));
Expand Down
12 changes: 9 additions & 3 deletions igmRhinoCommon/cppNativeMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/// <summary>
/// randomly sample points on meshes.
/// randomly sample points on meshes
/// </summary>
[DllImport(Import.cppLib, CallingConvention = CallingConvention.Cdecl)]
internal static extern void IGM_random_point_on_mesh(IntPtr pMesh, int N, IntPtr B, IntPtr FI);

/// <summary>
/// principal curvatures.
/// Compute principal curvatures
/// </summary>
[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);

/// <summary>
/// compute fast winding number
/// Compute gaussian curvatures
/// </summary>
[DllImport(Import.cppLib, CallingConvention = CallingConvention.Cdecl)]
internal static extern void IGM_gaussian_curvature(IntPtr pMesh, IntPtr K);

/// <summary>
/// compute the fast winding number
/// </summary>
[DllImport(Import.cppLib, CallingConvention = CallingConvention.Cdecl)]
internal static extern void IGM_fast_winding_number(IntPtr pMesh, IntPtr Q, IntPtr W);
Expand Down

0 comments on commit 1fe254b

Please sign in to comment.