Hi Mike,
Thanks for checking the link.
Hi vistec,
This was put up many days ago and not sure why you could not see it - perhaps you were looking at a cached page and needed to refresh?
Anyway, I have pasted the code here in case you still have problems accessing it.
Easwar
OriginLab
#include <Origin.h>
/////////////////////////////////////////////////////////////////////////////////
// This example shows how to change various settings of contour plot.
// NOTE: It is assumed that a graph layer with a contour plot is active.
//
void customize_contour_plot()
{
// Point to active contour plot and check validity
GraphLayer gly = Project.ActiveLayer();
DataPlot dp = gly.DataPlots(-1);
if( !dp ) return;
// Get color map into tree object
Tree tr;
if( !dp.GetColormap(tr) )
return;
// Uncomment next line to dump tree in script window to see what is available
//out_tree(tr);
// You can also examine tree from the Save Theme dialog by editing theme
// Get current contour levels
vector vLevels;
vLevels = tr.Details.Levels.dVals;
// Uncomment next two lines to dump current levels
//for(int i = 0; i < vLevels.GetSize(); i++)
// printf("%d %f\n", i, vLevels[i]);
// Now let us change levels, colors etc
// Following code uses some sample numbers for each
// Modify code as applicable to your data
// Set new min, max (arbitrary numbers, change as needed for your data)
double dMin = -5;
double dMax = 5;
// Change number of levels and values (arbitrary, change as needed)
// In this example we are setting to a nonlinear scale, 2nd order polynomial
int nLevels = 32;
vLevels.SetSize(nLevels);
for(int i = 0; i < nLevels; i++)
{
// Note that level needs to be set as % of (max-min)
vLevels[i] = 100 * (i^2)/(nLevels^2);
// Actual value in dialog/GUI will be:
//printf("%f\n", dMin + vLevels[i]*(dMax-dMin)/100);
}
// Write new level info to tree
tr.Min.dVal = dMin;
tr.Max.dVal = dMax;
tr.Details.Levels.dVals = vLevels;
// Now let us set colors for each level, using RGB values
vector<uint> vColors;
vColors.SetSize(nLevels);
// Set colors using some nonlinear function for R, G, B
// Arbitrary, change as desired.
// Could instead read from say a palette file and assign values
for(i = 0; i < nLevels; i++)
{
int nRed = 256* i / nLevels; // linear in R
int nGreen = 256 * i^2 / nLevels^2; // power of 2 in G
int nBlue = 128 + 128 * sin(2 * Pi * i / nLevels) ; // sinusoidal in B
vColors[i] = nRed + 256 * nGreen + 65536 * nBlue + OCOLOR_RGB_BITS;
// The above sets colors using direct RGB values
// The offset OCOLOR_RGB_BITS indicates to Origin to interpret as RGB
}
// Set above and below color values, such as:
tr.Colormap.Details.BelowColor.nVal = 3; // set to 4th color in Origin color list
tr.Details.AboveColor.nVal = 1; // set to 2nd color in Origin color list
// So can use color list index, or RGB as shown previously
// Write colors to tree
tr.Details.Colors.nVals = vColors;
// Set new color map properties using updated tree
if( !dp.SetColormap(tr) )
printf("Failed to set color map\n");
}
//
// Note also that settings can be saved as Theme or entire graph can be saved
// as template for future use with different data, so it is not necessary to
// programmatically modify settings for each case.