2.2.3.4.3 Curve::Curve

Description

Default constructor for Curve class.


Copy constructor for Curve class. The original Y data set is copied into a new Curve object and is then associated with a copy of the original X data set. The Datasets of the original Curve object are not affected by operations on the copy Curve.


Constructor for Curve class. The Y data set is specified by name and, if it exists, the Y data set's internally associated X data set is automatically used for the X data set. Otherwise, row numbers are used for the X data set. Operations on the Curve object do affect the X and/or the specified Y dataset(s)


Constructor for Curve class. Both the X and Y data sets are specified by name. Operations on the Curve object do affect the specified X and Y data sets.


Construct a Curve from X and Y Datasets. Both the X and Y data sets are specified by Origin C Dataset objects which are attached to internal Origin data sets. Operations on the Curve object do not affect the associated Origin X and Y data sets.


Construct a Curve from a Worksheet and X and Y column numbers. The X and Y data sets are specified by column number in an Origin C worksheet object. Operations on the Curve object do affect the associated Origin X and Y worksheet columns (data sets).


Construct a Curve from a Worksheet, a Y column number, and an associated X column. The Y data set is specified by column number in an Origin C worksheet object and, if it exists, the Y column's internally associated X column is automatically used for the X column. Otherwise, row numbers are used for the X data set. Operations on the Curve object do affect the X and/or the specified Y column(s).


Construct a Curve from a DataPlot. The X and Y data sets are specified by an Origin C DataPlot object. Operations on the Curve object do affect the associated data plot and underlying data sets in Origin.


Constructor for Curve class. It creates a temporary curve object from a curvebase reference such as Project.ActiveCurveBase(). It allows the handling of missing values, and specifying range (start and end indexes) to copy. The resulting Curve values are all doubles, and so can be used for analysis.


Construct a Curve from a DataPlot. When bTemp = true, the operations on the Curve object do not affect the associated data plot and underlying data sets in Origin.


Constructor for Curve class. The X and Y dataasets come from the supplied XYRange object. It can be used for XYRange's that are inputs of xfunctions.

Syntax

Curve( )


Curve( Curve crvOriginal )


Curve( LPCSTR lpcszYData )


Curve( LPCSTR lpcszXData, LPCSTR lpcszYData )


Curve( Dataset dsX, Dataset dsY )


Curve( Worksheet & wks, int nColX, int nColY )


Curve( Worksheet & wks, int nColY )


Curve( DataPlot & dp )


Curve( curvebase & cv, int & nNumMissingInCopy, int & nSrcOffset, DWORD dwOptions = 0, int nLower = -1, int nUpper = -1 )


Curve( DataPlot& dp, BOOL bTemp);


Curve( XYRange &xy);

Parameters

crvOriginal
[input] Curve object which is copied


lpcszYData
[input] Name of Y Dataset


lpcszXData
[input] Name of X Dataset
lpcszYData
[input] Name of Y Dataset


dsX
[input] Origin C Dataset object attached to internal Origin X data set
dsY
[input] Origin C Dataset object attached to internal Origin Y data set


wks
[input] Origin C Dataset object attached to an internal Origin worksheet
nColX
[input] 0 based offset or column number of X column (data set)
nColY
[input] 0 based offset or column number of Y column (data set)


wks
[input] Origin C Dataset object attached to an internal Origin worksheet
nColY
[input] 0 based offset or column number of Y column (data set)


dp
[input] the data plot object to construct curve


cv
[input] source curve
nNumMissingInCopy
[output] number of missing values in the created curve.
nSrcOffset
[output] index in source curve that the result curve's 1st point is copied from
dwOptions
[input] a combination of values from the enumeration
enum {
CURVECOPY_SCAN_OVER_MISSING_FROM_LEFT = 0x00000001, // if on, it will scan from the left (see the parameter nLower) until it finds the first nonmissing value
CURVECOPY_SCAN_OVER_MISSING_FROM_RIGHT = 0x00000002, // if on, it will scan back from the right (see the parameter nUpper) until it finds the first nonmissing value
CURVECOPY_SKIP_MISSING_INSIDE = 0x00000004, // if on, it will not copy any missing values found in the middle
CURVECOPY_REPLACE_MISSING_INSIDE = 0x00000008, // if on, any missing values in the middle will be replaced with the average of neighboring points (not used if the bit CURVECOPY_SKIP_MISSING_INSIDE is on)
};
nLower
[input] lower index to start from or <0 (-1) to start from the lower bound.
nUpper
[input] upper index to end at, or <0 (-1) to end at the upper bound.


bTemp
[input] When bTemp = true, the operations on the Curve object do not affect the associated data plot and underlying data sets in Origin.


xy
[input] one XYRange object used to construct the Curve object.

Return

Examples

EX1

void Curve_Curve_ex1()
{
	// Assumes the active worksheet contains column A and column B with data
	Worksheet wks = Project.ActiveLayer();
	if(wks)
	{
		Curve crv; // Use default constructor to create unattached Origin C Curve object
		crv.Attach( wks, 0, 1 ); // Attach Origin C Curve object to internal Origin data sets
	}
}


EX2

void Curve_Curve_ex2()
{
	// Assumes the active worksheet contains column A and column B with data
	Worksheet wks = Project.ActiveLayer();
	if(wks)
	{
		Curve crv1( wks, 0, 1 );
		Curve crv2( crv1 );
	}
}


EX3

void Curve_Curve_ex3()
{
	// Assumes the active worksheet contains column A and column B with data
	Worksheet wks = Project.ActiveLayer();
	if(wks)
	{
		Dataset ds2(wks, 1);
		string strB = ds2.GetName();
		Curve crv(strB);
	}
}


EX4

void Curve_Curve_ex4()
{
	// Assumes the active worksheet contains column A and column B with data
	Worksheet wks = Project.ActiveLayer();
	if(wks)
	{
		Dataset ds1(wks, 0);
		Dataset ds2(wks, 1);
		string strA = ds1.GetName();
		string strB = ds2.GetName();
		
		Curve crv( strA, strB );
	}
}


EX5

void Curve_Curve_ex5()
{
	// Assumes the active worksheet contains column A and column B with data
	Worksheet wks = Project.ActiveLayer();
	if(wks)
	{
		Dataset ds1(wks, 0);
		Dataset ds2(wks, 1);		
		Curve crv( ds1, ds2 );
	}
}


EX6

void Curve_Curve_ex6()
{
	// Assumes the active worksheet contains column A and column B with data
	Worksheet wks = Project.ActiveLayer();
	if(wks)
	{
		Curve crv( wks, 0, 1 ); // column A as X, column B as Y
	}
}


EX7

void Curve_Curve_ex7()
{
	// Assumes the active worksheet contains column A and column B with data
	Worksheet wks = Project.ActiveLayer();
	if(wks)
	{
		Curve crv( wks, 1 ); // column A as X, column B as Y
	}
}


EX8

void Curve_Curve_ex8()
{
	// Assumes Graph window with one or more data plots is active in Origin
	GraphLayer    gl = Project.ActiveLayer(); // Get active layer in project file
	if(gl)                                  // If valid graph layer...
	{
	    DataPlot dp = gl.DataPlots(0);      // Get first data plot in graph layer
	    if(dp)                              // If valid DataPlot...
	    {
	        Curve crv(dp);                  // Get Curve from DataPlot
	    }
	}
}

EX9

// This example shows how to create a copy of xy data into a Curve object. 
// This Curve constructor creates a Curve object consisting of doubles, 
// which can then be used for analysis such as ocmath_integrate.
void Curve_Curve_Ex9(int i1=0, int i2=-1)
{
	// Use Curve constructor to make a copy of Project.ActiveCurveBase() which is all numeric, double, without missing values.
	int nMissing;
	int nSrcOffset;
	Curve cc(Project.ActiveCurveBase(), nMissing, nSrcOffset, CURVECOPY_SCAN_OVER_MISSING_FROM_LEFT | CURVECOPY_SCAN_OVER_MISSING_FROM_RIGHT | CURVECOPY_REPLACE_MISSING_INSIDE, i1, i2);

	// get the upper and lower value for the integration
	Dataset dx;
	cc.AttachX(dx);
	i1 = cc.GetLowerIndex();
	i2 = cc.GetUpperIndex();
	
	// the Curve object cc can be passed into ocmath_integrate(), which requires a pointer to double in the second argument.
	IntegrationResult irResult;
	ocmath_integrate(dx, cc, i1, i2, &irResult);
	
}

EX10

// This example illustrates the argument dwOptions for handling missing values.
// To run this example, create a worksheet with x, y data of say 20 values. 
// Delete the y value for the first 3, last 2 and some middle two indices such as 10 and 11.
// Then create a plot, and make the plot active, then run Curve_Curve_Ex9 in the script window and examine the output.
void Curve_Curve_Ex10(int i1=0, int i2=-1)
{
	int nMissing;
	int nSrcOffset;
	
	curvebase& cb = Project.ActiveCurveBase();
	
	Curve cc(cb, nMissing, nSrcOffset, 0, i1, i2);
	printf("NMissing=%d, nSrcoffset index = %d\n", nMissing, nSrcOffset);
	printf("\n");
		
	Curve cc1(cb, nMissing, nSrcOffset, CURVECOPY_SCAN_OVER_MISSING_FROM_LEFT, i1, i2);
	printf("CURVECOPY_SCAN_OVER_MISSING_FROM_LEFT,\n NMissing=%d, nSrcoffset index = %d\n", nMissing, nSrcOffset);
	printf("\n");
	
	Curve cc2(cb, nMissing, nSrcOffset, CURVECOPY_SCAN_OVER_MISSING_FROM_RIGHT, i1, i2);
	printf("CURVECOPY_SCAN_OVER_MISSING_FROM_RIGHT,\n NMissing=%d, nSrcoffset index = %d\n", nMissing, nSrcOffset);
	printf("\n");
	
	Curve cc3(cb, nMissing, nSrcOffset, CURVECOPY_SKIP_MISSING_INSIDE, i1, i2);
	printf("CURVECOPY_SKIP_MISSING_INSIDE,\n NMissing=%d, nSrcoffset index = %d\n", nMissing, nSrcOffset);
	printf("Note: Left, right and inside missing valuses are skipped.\n");
	printf("\n");
	
	Curve cc4(cb, nMissing, nSrcOffset, CURVECOPY_REPLACE_MISSING_INSIDE, i1, i2);
	printf("CURVECOPY_REPLACE_MISSING_INSIDE,\n NMissing=%d, nSrcoffset index = %d\n", nMissing, nSrcOffset);
	printf("Note: Only inside missing values are replaced by averages.\n");
	printf("\n");
	
	Curve cc5(cb, nMissing, nSrcOffset, CURVECOPY_SCAN_OVER_MISSING_FROM_LEFT | CURVECOPY_REPLACE_MISSING_INSIDE, i1, i2);
	printf("CURVECOPY_SCAN_OVER_MISSING_FROM_LEFT  | CURVECOPY_REPLACE_MISSING_INSIDE,\n NMissing=%d, nSrcoffset index = %d\n", nMissing, nSrcOffset);
	printf("Note: CURVECOPY_REPLACE_MISSING_INSIDE does not work correctly if CURVECOPY_SCAN_OVER_MISSING_FROM_LEFT is also set and there are missing valuse on the left.\n");
	printf("\n");
	
	Curve cc6(cb, nMissing, nSrcOffset, CURVECOPY_SCAN_OVER_MISSING_FROM_LEFT | CURVECOPY_SCAN_OVER_MISSING_FROM_RIGHT | CURVECOPY_REPLACE_MISSING_INSIDE, i1, i2);
	printf("CURVECOPY_SCAN_OVER_MISSING_FROM_LEFT | CURVECOPY_SCAN_OVER_MISSING_FROM_RIGHT | CURVECOPY_REPLACE_MISSING_INSIDE,\n NMissing=%d, nSrcoffset index = %d\n", nMissing, nSrcOffset);
	printf("Note: CURVECOPY_REPLACE_MISSING_INSIDE does not work correctly if CURVECOPY_SCAN_OVER_MISSING_FROM_RIGHT is also set and there are missing valuse on the right.\n");
	printf("\n");
}

EX11

// The example test_Curve_xfromY tests the function x_from_y_after_peak, which uses the Curve constructor.
// This example assumes you have some single peak data, and a plot of the data is active.
static int IndexAtYMax(Dataset &aa)
{
	BasicStats	stat;
	stat.iMin =0;
	stat.iMax =0;
	Data_sum(&aa, &stat);
	return stat.iMax;
}

double x_from_y_after_peak(DataPlot& dp, double y)
{
	Curve crv(dp);
	// first make a copy so we can sort and smooth it
	int nMissing;
	int nSrcOffset;
	// this is a copy constructor to scan and skip all missing values in both X and Y
	Curve cvcpy(crv, nMissing, nSrcOffset, CURVECOPY_SKIP_MISSING_INSIDE);
	cvcpy.Sort(); // just incase data not monotonically increasing in X
	smooth(cvcpy, 0 , 3, 3);// apply simple adj ave with 3 pts on left and right
	int nYmax = IndexAtYMax(cvcpy); // index of Peak
	
	// now make a new curve starting from the peak
	Curve cvcpy2(cvcpy, nMissing, nSrcOffset, CURVECOPY_SKIP_MISSING_INSIDE, nYmax);
	return Curve_xfromY( &cvcpy2, y ); 
}

// now you can try this by plotting some data with a single peak
// and enter a y value and get x after the peak
void Curve_Curve_ex11(double y)
{
	GraphLayer gl = Project.ActiveLayer();
	DataPlot dp = gl.DataPlots(0); 
	double x = x_from_y_after_peak(dp, y);
	
	printf("for y = %g, x = %g\n", y, x);
}

EX12

void Curve_Curve_ex12()
{
    // Assumes Graph window with one or more data plots is active in Origin
    GraphLayer    gl = Project.ActiveLayer(); 	// Get active layer in project file
    if(gl)                                 
    {
        DataPlot dp = gl.DataPlots(0);      	// Get first data plot in graph layer
        if(dp)                              	// If valid DataPlot...
        {
            Curve crv(dp, FALSE);       		//If FALSE, it will affect the associated data plot 
            crv[0] = 1;
        }
    }
}

EX13

void Curve_Curve_ex13()
{
    // Assumes Graph window with one or more data plots is active in Origin
    GraphLayer    gl = Project.ActiveLayer();   // Get active layer in project file
    if(gl)                                 
    {
        DataPlot dp = gl.DataPlots(0);          // Get first data plot in graph layer
        if(dp)                                  // If valid DataPlot...
        {
        	XYRange xy;
			dp.GetDataRange(xy);
            Curve crv(xy);               
            crv[0] = 1;
        }
    }
}

Remark

See Also

Curve::Attach, Curve::Detach

Header to Include

curve.h