ocmath_mesh_in_polygon

Description

The function generates a triangular mesh of a closed polygonal region.

Syntax

int ocmath_mesh_in_polygon( int nVertices, const double * pxVertices, const double * pyVertices, int nEdgePts, int * nMeshPts, double * pxMesh, double * pyMesh )


Parameters

nVertices
[input] the number of vertices in the input boundary.
pxVertices
[input] the X coordinates in the input boundary.
pyVertices
[input] the Y coordinates in the input boundary.
nEdgePts
[input] how many points are interpolated in the boundary; more boundary points, finer the mesh.
nMeshPts
[modify] on input, the size of pxMesh and pyMesh buffer; on output, the total number of mesh points.
pxMesh
[output] the buffer to receive X coordinates of mesh, the initial size is nMeshPts.
pyMesh
[output] the buffer to receive Y coordinates of mesh, the initial size is nMeshPts.

Return

OE_NOERROR = 0 Succeed.

OE_SIZE_LT = -1 nEdgePts is smaller than *nMeshPts, or nEdgePts is too small to generate interior points.

OE_NULL_POINTER = -11 pxVertices, pyVertices, pxMesh, or pyMesh must not be NULL.

NE_MESH_ERROR = 2099 Inccorrect boundary input, or nMeshPts is not large enough.

Examples

EX1

#include <wks2mat.h>
#define MAX_MESH_PTS    2000
int ocmath_mesh_in_polygon_ex1(int nEdgePts = 100, double dSmooth = 0.02)
{
int iRet;
// Step1. Generating mesh in the given polygon.
// Assume there is worksheet named "Boundary", which contains boundary data.
vector vxMesh, vyMesh;
int nvmax = MAX_MESH_PTS;

Worksheet wksBd("Boundary");
Dataset dsX(wksBd, 0);
Dataset dsY(wksBd, 1);
vector vxVertices(dsX), vyVertices(dsY);
int nvb = vxVertices.GetSize();

vxMesh.SetSize(nvmax);
vyMesh.SetSize(nvmax);
iRet = ocmath_mesh_in_polygon(nvb, vxVertices, vyVertices, nEdgePts, &nvmax, vxMesh, vyMesh);
if (OE_NOERROR != iRet)
{
printf("Error occurs when calling nag mesh funcion!\n");
return -1;
}
vxMesh.SetSize(nvmax);
vyMesh.SetSize(nvmax);

// Step2. Gridding XYZ triplets on the generated mesh by using TPS method.
// Assume that XYZ triplets are contained in the active layer.
vector vX, vY, vZ;
Worksheet wks = Project.ActiveLayer();
Dataset ds1(wks, 0), ds2(wks, 1), ds3(wks, 2);
vX=ds1; vY=ds2; vZ=ds3;

ocmath_strTPS strTPS;
double dReg;
vector vzMesh(nvmax);
iRet = ocmath_tps_fit(vX.GetSize(), vX, vY, vZ, dSmooth, &strTPS, &dReg);
if( iRet == OE_NOERROR )
{
iRet = ocmath_tps_eval(nvmax, vxMesh, vyMesh, vzMesh, &strTPS);
}
ocmath_tps_free(&strTPS);

// Step3. Put result data to a new worksheet
Worksheet wksResult;
wksResult.Create();
wksResult.SetSize(-1,3);
Dataset d1(wksResult,0), d2(wksResult,1), d3(wksResult,2);
d1 = vxMesh;
d2 = vyMesh;
d3 = vzMesh;

return iRet;
}


Remark

The function generates a triangular mesh of a closed polygonal region.

It uses an Advancing Front process from NAG (d06acc), based on an incremental method.

The orientation of input boundary vertices must be counter-clockwise.

One can specify the numer of points on boundary. More points on boundary will result finer mesh in interior region of polygon.

On input, one must allocate memory buffer large enough to receive resulting mesh points.

The number of mesh points is determined internally.

On output, nMeshPts is the total number of vertices in the mesh (including boundary).