2.1.18.22 ocmath_xyz_remove_duplicates
Description
This function remove duplicated points.
Syntax
int ocmath_xyz_remove_duplicates( UINT n, double * x, double * y, double * z, int nMethod = Remove_With_Mean, double dXPrecision = 1.0e-8, double dYPrecision = 1.0e-8 )
Parameters
- n
- [input] the number of scatters.
- x
- [modify] the x-coordinates of the scatters, when output, the unique points are stored in the lower bound of x
- y
- [modify] the y-coordinates of the scatters, when output, the unique points are stored in the lower bound of y
- z
- [modify] the z-coordinates of the scatters, when output, the unique points are stored in the lower bound of z
- nMethod
- [input] the method to calculate the Z value on the duplicates.
- 0 replace with mean
- 1 median
- 2 min
- 3 max
- 4 sum
- dXPrecision
- [input] the precision to determine whether the points are duplicated in X dimension.
- dYPrecision
- [input] the precision to determine whether the points are duplicated in Y dimension.
Return
the number of unique points in (x,y,z).
Examples
EX1
#include <wks2mat.h>
void ocmath_xyz_remove_duplicates_ex1()
{
int n = 10;
double a[]={2,2,4,6,2,4,8,5,0,3};
double b[]={3,3,9,2,3,4,0,5,8,2};
double c[]={5,3,7,3,6,5,0,4,3,7};
int nr = ocmath_xyz_remove_duplicates(n, a, b, c, Remove_With_Mean, 0.1, 0.1);
printf("%d\n", nr);
for(int i =0 ; i<nr; i++)
{
printf("%f\t%f\t%f\n", a[i], b[i], c[i]);
}
}
EX2
#include <wks2mat.h>
// XYZ data points are loaded from the active Workshheet (Cols 0, 1, 2).
// Resulting data are written back to the same Worksheet (Cols 3, 4, 5)
void ocmath_xyz_remove_duplicates_ex2(double dPrecision = 1.0e-8)
{
// The active Worksheet.
Worksheet wks = Project.ActiveLayer();
wks.SetSize(-1, 6); // To contain the results
Dataset dsX(wks, 0), dsY(wks, 1), dsZ(wks, 2);
vector vX(dsX), vY(dsY), vZ(dsZ);
int nSize = vX.GetSize();
int iRet = ocmath_xyz_remove_duplicates(nSize, vX, vY, vZ, Remove_With_Mean, dPrecision, dPrecision);
printf("%d points removed.\n", nSize - iRet);
//Output results to Cols 3, 4, 5.
vX.SetSize(iRet); vY.SetSize(iRet); vZ.SetSize(iRet);
dsX.Attach(wks, 3); dsY.Attach(wks, 4); dsZ.Attach(wks, 5);
dsX.SetSize(0); dsY.SetSize(0); dsZ.SetSize(0);
dsX.Append(vX); dsY.Append(vY); dsZ.Append(vZ);
}
Remark
See Also
ocmath_xy_remove_duplicates
Header to Include
wks2mat.h
Reference
|