Set the Z levels for the colormap inside the data plot (applies to dataplot with colormaps, like contour plot) The 1st value in vz is the minimum Z value and the last value in vz the maximum, so vz must at least contain 2 values.
BOOL SetColormap( TreeNode & trColormap )
BOOL SetColormap( const vector<double> & vz, BOOL bLogScale = FALSE )
TRUE for success and FALSE for failure.
TRUE for success and FALSE for failure. Returns FALSE if has negative in vz.
EX1
// assume active window has a contour plot, or any plot that supports colormap void DataObject_SetColormap_ex1() { int nLevels = 20; double z1 = -1.5, z2 = 1.5; GraphLayer gl = Project.ActiveLayer(); DataPlot dp = gl.DataPlots(0); // setup z levels in percent // first value must be 0 and last value must be < 100 vector vLevels; vLevels.Data(0, 100*(nLevels-1)/nLevels, 100./nLevels); // setup colors for each vector<uint> vColors; vColors.SetSize(nLevels); for(int ii = 0; ii < nLevels; ii++) { int gg = 255* ii / (nLevels-1); int bb = 255 * (nLevels-ii-1)/(nLevels-1); int nRGB = RGB(0, gg, bb); vColors[ii] = RGB2OCOLOR(nRGB); } // construct tree from scratch, you can also get the colormap tree by calling GetColormap, but then // you will have to match up all the vectors, so simpler to just create new tree with only the // settings that we need to change Tree tr; tr.ColorMap.Details.Levels.dVals = vLevels; tr.ColorMap.Details.BelowColor.nVal = SYSCOLOR_RED; tr.ColorMap.Details.AboveColor.nVal = SYSCOLOR_PINK; tr.ColorMap.Details.Colors.nVals = vColors; tr.ColorMap.Min.dVal = z1; tr.ColorMap.Max.dVal = z2; if(dp.SetColormap(tr)) { GraphObject grBand = gl.GraphObjects("Spectrum1"); if(grBand) grBand.Invalidate(); } }
EX2
// this example plots a XYZ contour and set its colormap by calling a utility function in page_utils.c void DataObject_SetColormap_ex2() { int npts = 30; Worksheet wks; wks.Create(); wks.SetSize(-1,3); // fill wks with some XYZ data Dataset dsX(wks, 0); Dataset dsY(wks, 1); Dataset dsZ(wks, 2); dsX.Data(1, npts); dsX *= 0.05; dsY.Normal(npts); dsY += 1.2; dsZ.Normal(npts); // then we construct the XYZ data range DataRange dr; dr.Add(wks, 0, "X"); dr.Add(wks, 1, "Y"); dr.Add(wks, 2, "Z"); // in this example, we will create a new graph, but you can use any exisitng graph layer // as long as the layer is a 2D layer GraphPage gp; // You must use a 3D scatter/line template, you can first make a 3d scatter plot, // make needed modifications, then save your own gp.Create("TriContour"); if( gp ) { GraphLayer gl = gp.Layers(); if( gl ) { int nPlot = gl.AddPlot(dr, IDM_PLOT_TRI_CONTOUR); DataPlot dp = gl.DataPlots(nPlot); gl.Rescale(); // now we will set the colormap, we have to assume here that the color spectrum gr object is already in the // layer to show the colormap vector vLevels; vector<uint> vColors; vLevels.Data(0, 100, 5); int nLevels = vLevels.GetSize(); double z1 = -1.5, z2 = 1.5; vLevels = z1 + (z2-z1)*vLevels/100.; vColors.SetSize(nLevels-1); for(int ii = 0; ii < vColors.GetSize(); ii++) { int gg = 255* ii / (nLevels-1); int bb = 255 * (nLevels-ii-1)/(nLevels-1); int nRGB = RGB(0, gg, bb); vColors[ii] = RGB2OCOLOR(nRGB); } dataplot_set_colormap(dp, vLevels, vColors, SYSCOLOR_RED, SYSCOLOR_PINK); } } }
EX3
void DataPlot_SetColormap_ex3() { Worksheet wks; wks.Create("origin"); Column colZ(wks, wks.AddCol()); colZ.SetType(OKDATAOBJ_DESIGNATION_Z); Dataset ds1(wks,0); Dataset ds2(wks,1); Dataset ds3(wks,2); ds1.Data(1,20,1); ds2.Normal(20); ds3.Normal(20); GraphPage gp; gp.Create("TRICONTOUR"); GraphLayer gl(gp.GetName(), 0); if(!gl) return; gl.AddPlot(wks, IDM_PLOT_TRI_CONTOUR); DataPlot dp = gl.DataPlots(0); if( !dp ) return; vector vZs = {-5, -2.5, 0, 2.5, 5}; BOOL bRet = dp.SetColormap(vZs, false); }
origin.h