Hello,
Please try the code pasted here. The code assumes that the last plotted dataset in the layer is the one that should be used for clipping. It then clips the points in all other data plots that lie to the left of this clipping curve. The clipping is done by setting y values to missing value.
Easwar
OriginLab
// This function assumes a graph layer is active.
// It then takes the last data plot in the layer and clips all other
// data from other data plots that are to the left of this clipping dataset.
// The clipping is done by setting y values to missing value.
void clip_left()
{
// Assume graph layer is active
GraphLayer gly = Project.ActiveLayer();
if( !gly ) return;
// Count number of data plots in layer
int nDataPlots = 0;
foreach(DataPlot dp in gly.DataPlots)
{
nDataPlots++;
}
// If less than two datasets, quit
if( nDataPlots < 2 ) return;
// Assume last data plot is the one used for clipping
// Declare curve and attach to last data plot
Curve crvClip(gly.DataPlots(nDataPlots - 1));
int nClipDataSize = crvClip.GetSize();
// Get X values
vector vecClipX;
get_x_values(crvClip, vecClipX);
// Loop over all data plots other than the last one
for(int idp = 0; idp < nDataPlots - 1; idp++)
{
Curve crvData(gly.DataPlots(idp));
// Loop over all adjacent x value pairs in clip dataset
double x1, x2, y1, y2, cy1, cy2;
for(int i = 0; i < nClipDataSize - 1; i++)
{
// Get x,y of clip data curve
x1 = vecClipX[i];
x2 = vecClipX[i + 1];
cy1 = Curve_yfromX(&crvClip, x1);
cy2 = Curve_yfromX(&crvClip, x2);
// Get y of current data curve and check for intersection
y1 = Curve_yfromX(&crvData, x1);
y2 = Curve_yfromX(&crvData, x2);
if( (cy1 - y1) * (cy2 - y2) < 1 )
{
// The two curves intersect - find intersection point x value
double m1, m2, c1, c2;
m1 = (cy2 - cy1) / (x2 - x1);
c1 = (cy1 * x2 - cy2 * x1 ) / (x2 - x1);
m2 = (y2 - y1) / (x2 - x1);
c2 = (y1 * x2 - y2 * x1 ) / (x2 - x1);
double xint = (c2 - c1) / (m1 - m2);
// Set points to left of this x value as missing
set_left_missing(crvData, xint);
break;
}
}
}
}
// This function sets points to left as missing values
static void set_left_missing(Curve& crv, double dx)
{
// Get X values of curve into vector
vector vecX;
get_x_values(crv, vecX);
int nSize = crv.GetSize();
// Loop over all points in data curve
for(int i = 0; i < nSize; i++)
{
// If current x is less than cutoff x, set y as missing
if( vecX[i] < dx )
crv[i] = NANUM;
else
break;
}
}
// This function fills vector with X values of the curve
static void get_x_values(Curve& crvClip, vector& vecClipX)
{
if( crvClip.HasX() )
{
Dataset dsX;
crvClip.AttachX(dsX);
vecClipX = dsX;
}
else
{
vecClipX.Data(1, crvClip.GetSize(), 1)
}
}
//