Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GRIDEDIT-1282 Add PolygonLinearRefineThroughAPI #73

Merged
Merged
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Deltares.MeshKernel" Version="4.3.0.3304" />
<PackageVersion Include="Deltares.MeshKernel" Version="4.3.0.3348" />
<PackageVersion Include="DHYDRO.SharedConfigurations" Version="1.0.0.27" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageVersion Include="NetTopologySuite" Version="1.15.0" />
Expand Down
48 changes: 44 additions & 4 deletions src/MeshKernelNET/Api/IMeshKernelApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,18 @@ int CurvilinearComputeTransfiniteFromTriangle(int meshKernelId,
/// <returns>Error code</returns>
int CurvilinearGridGetData(int meshKernelId, out DisposableCurvilinearGrid disposableCurvilinearGrid);

/// <summary>
/// Gets the boundary polygon of a curvilinear grid, nodes with invalid coordinates are excluded
/// </summary>
/// <param name="meshKernelId">Id of the mesh state</param>
/// <param name="lowerLeftN">The n index of the lower left corner</param>
/// <param name="lowerLeftM">The m index of the lower left corner</param>
/// <param name="upperRightN">The n index of the upper right corner</param>
/// <param name="upperRightM">The m index of the upper right corner</param>
/// <param name="boundaryPolygons">The geometry list containing the boundary polygons. If multiple polygons are present, a separator is used</param>
/// <returns>Error code</returns>
int CurvilinearGetBoundariesAsPolygons(int meshKernelId, int lowerLeftN, int lowerLeftM, int upperRightN, int upperRightM, out DisposableGeometryList boundaryPolygons);

/// <summary>
/// Gets the index of the closest curvilinear edge
/// </summary>
Expand Down Expand Up @@ -1518,7 +1530,7 @@ int PolygonCountOffset(int meshKernelId, in DisposableGeometryList disposableGeo
bool innerPolygon, double distance, ref int numberOfPolygonVertices);

/// <summary>
/// Count the number of polygon vertices after refinement
/// Count the number of polygon vertices after equidistant refinement
/// </summary>
/// <param name="meshKernelId">Id of the grid state</param>
/// <param name="disposableGeometryListIn">The input polygon</param>
Expand All @@ -1527,13 +1539,29 @@ int PolygonCountOffset(int meshKernelId, in DisposableGeometryList disposableGeo
/// <param name="distance">The refinement distance</param>
/// <param name="numberOfPolygonVertices">The number of vertices after refinement </param>
/// <returns>Error code</returns>
int PolygonCountRefine(int meshKernelId,
int PolygonCountEquidistantRefine(int meshKernelId,
in DisposableGeometryList disposableGeometryListIn,
int firstIndex,
int secondIndex,
double distance,
ref int numberOfPolygonVertices);

/// <summary>
/// Count the number of polygon vertices after linear refinement
/// </summary>
/// <param name="meshKernelId">Id of the grid state</param>
/// <param name="disposableGeometryListIn">The input polygon</param>
/// <param name="firstIndex">The index of the first vertex</param>
/// <param name="secondIndex">The index of the second vertex</param>
/// <param name="distance">The refinement distance</param>
/// <param name="numberOfPolygonVertices">The number of vertices after refinement </param>
/// <returns>Error code</returns>
int PolygonCountLinearRefine(int meshKernelId,
in DisposableGeometryList disposableGeometryListIn,
int firstIndex,
int secondIndex,
ref int numberOfPolygonVertices);

/// <summary>
/// Selects points in polygons
/// </summary>
Expand Down Expand Up @@ -1562,7 +1590,7 @@ int PolygonGetOffset(int meshKernelId,
double distance, ref DisposableGeometryList disposableGeometryListOut);

/// <summary>
/// Gets the refined polygon
/// Equidistant refinement of a polygon.
/// </summary>
/// <param name="meshKernelId">Id of the grid state</param>
/// <param name="disposableGeometryListIn">The input polygon</param>
Expand All @@ -1571,9 +1599,21 @@ int PolygonGetOffset(int meshKernelId,
/// <param name="distance">The refinement distance</param>
/// <param name="disposableGeometryListOut">The refined polygon</param>
/// <returns>Error code</returns>
int PolygonRefine(int meshKernelId, in DisposableGeometryList disposableGeometryListIn, int firstIndex,
int PolygonEquidistantRefine(int meshKernelId, in DisposableGeometryList disposableGeometryListIn, int firstIndex,
int secondIndex, double distance, ref DisposableGeometryList disposableGeometryListOut);

/// <summary>
/// Linear refinement of a polygon
/// </summary>
/// <param name="meshKernelId">Id of the grid state</param>
/// <param name="disposableGeometryListIn">The input polygon</param>
/// <param name="firstIndex">The index of the first vertex</param>
/// <param name="secondIndex">The index of the second vertex</param>
/// <param name="disposableGeometryListOut">The refined polygon</param>
/// <returns>Error code</returns>
int PolygonLinearRefine(int meshKernelId, in DisposableGeometryList disposableGeometryListIn, int firstIndex,
int secondIndex, ref DisposableGeometryList disposableGeometryListOut);

/// <summary>
/// Redo editing action
/// </summary>
Expand Down
67 changes: 63 additions & 4 deletions src/MeshKernelNET/Api/MeshKernelApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,47 @@ public int CurvilinearGridGetData(int meshKernelId, out DisposableCurvilinearGri
return exitCode;
}

public int CurvilinearGetBoundariesAsPolygons(int meshKernelId, int lowerLeftN, int lowerLeftM, int upperRightN, int upperRightM, out DisposableGeometryList boundaryPolygons)
{
int numberOfPolygonNodes = 0;
int exitCode = MeshKernelDll.CurvilinearCountGetBoundariesAsPolygons(meshKernelId,
lowerLeftN,
lowerLeftM,
upperRightN,
upperRightM,
ref numberOfPolygonNodes);
if (exitCode != 0)
{
boundaryPolygons = new DisposableGeometryList();
return exitCode;
}

boundaryPolygons = new DisposableGeometryList();
boundaryPolygons.XCoordinates = new double[numberOfPolygonNodes];
boundaryPolygons.YCoordinates = new double[numberOfPolygonNodes];
double geometrySeparator = GetSeparator();
boundaryPolygons.GeometrySeparator = geometrySeparator;
boundaryPolygons.NumberOfCoordinates = numberOfPolygonNodes;

var geometryListNative = boundaryPolygons.CreateNativeObject();
exitCode = MeshKernelDll.CurvilinearGetBoundariesAsPolygons(meshKernelId,
lowerLeftN,
lowerLeftM,
upperRightN,
upperRightM,
ref geometryListNative);

if (exitCode != 0)
{
boundaryPolygons = new DisposableGeometryList();
return exitCode;
}

boundaryPolygons.XCoordinates = geometryListNative.xCoordinates.CreateValueArray<double>(numberOfPolygonNodes);
boundaryPolygons.YCoordinates = geometryListNative.yCoordinates.CreateValueArray<double>(numberOfPolygonNodes);
return exitCode;
}

public int CurvilinearGetEdgeLocationIndex(int meshKernelId, double xCoordinate, double yCoordinate, BoundingBox boundingBox, ref int locationIndex)
{
int locationType = -1;
Expand Down Expand Up @@ -1408,10 +1449,19 @@ public int PolygonCountOffset(int meshKernelId, in DisposableGeometryList dispos
return MeshKernelDll.PolygonCountOffset(meshKernelId, ref geometryListNativeIn, innerPolygonInt, distance, ref numberOfPolygonVertices);
}

public int PolygonCountRefine(int meshKernelId, in DisposableGeometryList disposableGeometryList, int firstIndex, int secondIndex, double distance, ref int numberOfPolygonVertices)
public int PolygonCountLinearRefine(int meshKernelId,
in DisposableGeometryList disposableGeometryListIn,
int firstIndex,
int secondIndex, ref int numberOfPolygonNodes)
{
GeometryListNative geometryListNativeIn = disposableGeometryListIn.CreateNativeObject();
return MeshKernelDll.PolygonCountLinearRefine(meshKernelId, ref geometryListNativeIn, firstIndex, secondIndex, ref numberOfPolygonNodes);
}

public int PolygonCountEquidistantRefine(int meshKernelId, in DisposableGeometryList disposableGeometryList, int firstIndex, int secondIndex, double distance, ref int numberOfPolygonVertices)
{
GeometryListNative geometryListInNative = disposableGeometryList.CreateNativeObject();
return MeshKernelDll.PolygonCountRefine(meshKernelId, ref geometryListInNative, firstIndex, secondIndex, distance, ref numberOfPolygonVertices);
return MeshKernelDll.PolygonCountEquidistantRefine(meshKernelId, ref geometryListInNative, firstIndex, secondIndex, distance, ref numberOfPolygonVertices);
}

public int GetPointsInPolygon(int meshKernelId, in DisposableGeometryList inputPolygon, in DisposableGeometryList inputPoints, ref DisposableGeometryList selectedPoints)
Expand All @@ -1430,12 +1480,21 @@ public int PolygonGetOffset(int meshKernelId, in DisposableGeometryList disposab
return MeshKernelDll.PolygonGetOffset(meshKernelId, ref geometryListNativeIn, innerPolygonInt, distance, ref geometryListNativeOut);
}

public int PolygonRefine(int meshKernelId, in DisposableGeometryList disposableGeometryListIn, int firstIndex,
public int PolygonEquidistantRefine(int meshKernelId, in DisposableGeometryList disposableGeometryListIn, int firstIndex,
int secondIndex, double distance, ref DisposableGeometryList disposableGeometryListOut)
{
GeometryListNative geometryListNativeIn = disposableGeometryListIn.CreateNativeObject();
GeometryListNative geometryListNativeOut = disposableGeometryListOut.CreateNativeObject(); // Create an instance for the out parameter
return MeshKernelDll.PolygonRefine(meshKernelId, ref geometryListNativeIn, firstIndex, secondIndex, distance, ref geometryListNativeOut);
return MeshKernelDll.PolygonEquidistantRefine(meshKernelId, ref geometryListNativeIn, firstIndex, secondIndex, distance, ref geometryListNativeOut);
}


public int PolygonLinearRefine(int meshKernelId, in DisposableGeometryList disposableGeometryListIn, int firstIndex,
int secondIndex, ref DisposableGeometryList disposableGeometryListOut)
{
GeometryListNative geometryListNativeIn = disposableGeometryListIn.CreateNativeObject();
GeometryListNative geometryListNativeOut = disposableGeometryListOut.CreateNativeObject(); // Create an instance for the out parameter
return MeshKernelDll.PolygonLinearRefine(meshKernelId, ref geometryListNativeIn, firstIndex, secondIndex, ref geometryListNativeOut);
}

/// <inheritdoc/>
Expand Down
56 changes: 53 additions & 3 deletions src/MeshKernelNET/Native/MeshKernelDll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,32 @@ public static extern int CurvilinearDerefine([In] int meshKernelId,
[DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_get_data", CallingConvention = CallingConvention.Cdecl)]
internal static extern int CurvilinearGetData([In] int meshKernelId, [In][Out] ref CurvilinearGridNative curvilinearGridNative);

/// <summary>
/// Counts the number of nodes in curvilinear grid boundary polygons.
/// </summary>
/// <param name="meshKernelId">Id of the mesh state</param>
/// <param name="lowerLeftN">The n index of the lower left corner</param>
/// <param name="lowerLeftM">The m index of the lower left corner</param>
/// <param name="upperRightN">The n index of the upper right corner</param>
/// <param name="upperRightM">The m index of the upper right corner</param>
/// <param name="numberOfPolygonNodes">The number of polygon nodes</param>
/// <returns>Error code</returns>
[DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_count_boundaries_as_polygons", CallingConvention = CallingConvention.Cdecl)]
internal static extern int CurvilinearCountGetBoundariesAsPolygons([In] int meshKernelId, [In] int lowerLeftN, [In] int lowerLeftM, [In] int upperRightN, [In] int upperRightM, [In][Out] ref int numberOfPolygonNodes);

/// <summary>
/// Gets the boundary polygon of a curvilinear grid, nodes with invalid coordinates are excluded.
/// </summary>
/// <param name="meshKernelId">Id of the mesh state</param>
/// <param name="lowerLeftN">The n index of the lower left corner</param>
/// <param name="lowerLeftM">The m index of the lower left corner</param>
/// <param name="upperRightN">The n index of the upper right corner</param>
/// <param name="upperRightM">The m index of the upper right corner</param>
/// <param name="boundaryPolygons">The geometry list containing the boundary polygons. If multiple polygons are present, a separator is used</param>
/// <returns>Error code</returns>
[DllImport(MeshKernelDllName, EntryPoint = "mkernel_curvilinear_get_boundaries_as_polygons", CallingConvention = CallingConvention.Cdecl)]
internal static extern int CurvilinearGetBoundariesAsPolygons([In] int meshKernelId, [In] int lowerLeftN, [In] int lowerLeftM, [In] int upperRightN, [In] int upperRightM, [In][Out] ref GeometryListNative boundaryPolygons);

/// <summary>
/// Gets the curvilinear grid dimensions as a CurvilinearGrid struct (converted as set of edges and nodes).
/// </summary>
Expand Down Expand Up @@ -1770,7 +1796,19 @@ internal static extern int PolygonCountOffset([In] int meshKernelId,
/// <param name="numberOfPolygonVertices">The number of vertices after refinement </param>
/// <returns>Error code</returns>
[DllImport(MeshKernelDllName, EntryPoint = "mkernel_polygon_count_refine", CallingConvention = CallingConvention.Cdecl)]
internal static extern int PolygonCountRefine([In] int meshKernelId, [In] ref GeometryListNative geometryListIn, [In] int firstIndex, [In] int secondIndex, [In] double distance, [In][Out] ref int numberOfPolygonVertices);
internal static extern int PolygonCountEquidistantRefine([In] int meshKernelId, [In] ref GeometryListNative geometryListIn, [In] int firstIndex, [In] int secondIndex, [In] double distance, [In][Out] ref int numberOfPolygonVertices);

/// <summary>
/// Count the number of vertices after linear refinement of a polygon
/// </summary>
/// <param name="meshKernelId">Id of the mesh state</param>
/// <param name="geometryListIn">The input polygon</param>
/// <param name="firstIndex">The index of the first vertex</param>
/// <param name="secondIndex">The index of the second vertex</param>
/// <param name="numberOfPolygonVertices">The number of vertices after refinement </param>
/// <returns>Error code</returns>
[DllImport(MeshKernelDllName, EntryPoint = "mkernel_polygon_count_linear_refine", CallingConvention = CallingConvention.Cdecl)]
internal static extern int PolygonCountLinearRefine([In] int meshKernelId, [In] ref GeometryListNative geometryListIn, [In] int firstIndex, [In] int secondIndex, [In][Out] ref int numberOfPolygonVertices);

/// <summary>
/// Selects points in polygons
Expand All @@ -1796,7 +1834,7 @@ internal static extern int PolygonCountOffset([In] int meshKernelId,
internal static extern int PolygonGetOffset([In] int meshKernelId, [In] ref GeometryListNative geometryListIn, [In] int innerPolygon, [In] double distance, [In][Out] ref GeometryListNative geometryListOut);

/// <summary>
/// Gets the refined polygon
/// Equidistant refinement of a polygon
/// </summary>
/// <param name="meshKernelId">Id of the mesh state</param>
/// <param name="geometryListIn">The input polygons</param>
Expand All @@ -1806,7 +1844,19 @@ internal static extern int PolygonCountOffset([In] int meshKernelId,
/// <param name="geometryListOut"></param>
/// <returns>Error code</returns>
[DllImport(MeshKernelDllName, EntryPoint = "mkernel_polygon_refine", CallingConvention = CallingConvention.Cdecl)]
internal static extern int PolygonRefine([In] int meshKernelId, [In] ref GeometryListNative geometryListIn, [In] int firstIndex, [In] int secondIndex, [In] double distance, [In][Out] ref GeometryListNative geometryListOut);
internal static extern int PolygonEquidistantRefine([In] int meshKernelId, [In] ref GeometryListNative geometryListIn, [In] int firstIndex, [In] int secondIndex, [In] double distance, [In][Out] ref GeometryListNative geometryListOut);

/// <summary>
/// Linear refinement of a polygon
/// </summary>
/// <param name="meshKernelId">Id of the mesh state</param>
/// <param name="geometryListIn">The input polygons</param>
/// <param name="firstIndex">The index of the first vertex</param>
/// <param name="secondIndex">The index of the second vertex</param>
/// <param name="geometryListOut"></param>
/// <returns>Error code</returns>
[DllImport(MeshKernelDllName, EntryPoint = "mkernel_polygon_linear_refine", CallingConvention = CallingConvention.Cdecl)]
internal static extern int PolygonLinearRefine([In] int meshKernelId, [In] ref GeometryListNative geometryListIn, [In] int firstIndex, [In] int secondIndex, [In][Out] ref GeometryListNative geometryListOut);

/// <summary>
/// Redo editing action
Expand Down
Loading