The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 Clipping Data
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

schotz

USA
Posts

Posted - 11/09/2005 :  3:11:44 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version: 7.5817 (SR2)
Operating System:XP (SP2)

Hello all-
I'm searching for a method to clip one data set based on the intersection of another data set in the same graph. Ultimately, I will have several data sets that will all be clipped to another single data set. In the attached picture, for example, I would like to clip all of the data from the green line that lies to the left of the black line.

Any suggestions would be appreciated.
Thanks

easwar

USA
1964 Posts

Posted - 11/09/2005 :  8:53:59 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

No picture attached...

You can upload an image by clicking on the Image button (the one to the immediate left of the button with the # sign) on the Format toolbar of the forum edit form. This pops up a window. Follow instructions in that window.

Easwar
OriginLab

Go to Top of Page

schotz

USA
Posts

Posted - 11/10/2005 :  08:24:22 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Apologies, I thought I had it attached. The insert functionality seems to not work properly in Firefox. See attached.

Go to Top of Page

easwar

USA
1964 Posts

Posted - 11/14/2005 :  2:41:13 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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)
}
}
//


Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000