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
 All Forums
 Origin Forum
 Origin Forum
 Clipping Data

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
schotz Posted - 11/09/2005 : 3:11:44 PM
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
3   L A T E S T    R E P L I E S    (Newest First)
easwar Posted - 11/14/2005 : 2:41:13 PM
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)
}
}
//


schotz Posted - 11/10/2005 : 08:24:22 AM
Apologies, I thought I had it attached. The insert functionality seems to not work properly in Firefox. See attached.

easwar Posted - 11/09/2005 : 8:53:59 PM
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


The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000