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 for Programming
 Forum for Origin C
 2D Contour Plot, Change # and color of levels
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

thrigs00

Germany
Posts

Posted - 11/04/2005 :  3:03:28 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version : 7.5Pro SR5
Operating System: Win 2K

Hi all!

I try to change the number and the color of levels in a contour plot using a tree, but I face some problems. My code is the following:

//Assuming there is a matrix of name Test filled with values <10:

void testfunction(){

MatrixObject mat_obj("Test", 0);

int nLevels = 15;
GraphPage gp;
gp.Create("CONTOUR");
GraphLayer glay = gp.Layers();
int nplot = glay.AddPlot(mat_obj, IDM_PLOT_CONTOUR);
glay.Rescale();
if(nLevels){
DataPlot dp = glay.DataPlots(0);
vector vLevels(15);
Tree tr;
tr = dp.Surface;
tr.ColorMap.Details.Remove(); //DO I HAVE TO DELETE AS
//IT IS CONTRARY TO THE NEW SETTING?
tr.ColorMap.Count.nVal = vLevels.GetSize();
dp.Surface = tr;

//So far so good, but now the color table is messed up. Reds are small
//values and blue are high ones. Ok, than just change it, I thought...

dp.GetColormap(tr); //this is actually accessing only a part of
//.Surface, isn't it?
tr.Min.dVal = 0; //Though setting of highest values works,
tr.Max.dVal = 10; //setting the minimum doesn't!

vLevels = tr.Details.Levels.dVals;
vLevels[14] = 1400/15;
vLevels[13] = 1300/15;
vLevels[12] = 1200/15;
vLevels[11] = 1100/15;
vLevels[10] = 1000/15;
vLevels[9] = 900/15;
vLevels = 800/15;
vLevels[7] = 700/15;
vLevels[6] = 600/15;
vLevels[5] = 500/15;
vLevels[4] = 450/15;
vLevels[3] = 400/15;
vLevels[2] = 350/15;
vLevels[1] = 300/15;
vLevels[0] = 0/15;

tr.Details.Levels.dVals = vLevels;
dp.SetColormap(tr);
}
gp.SetShow();
gp.Refresh(TRUE); //Just to be sure...

//Ok, now I should be done, but the I would like to have blue for
// small values
//If I try to cheat and say:
// vLevels[0] = 1400/15;
// vLevels[1] = 1300/15; //and so on and so on, then everything is
//getting black
//Does it have to do with Detail.BellowValue and comparable stuff?
//Is there a better way of accessing the colors themselve?

}

Thanks for help, feel free to use the code, if it's eventually working!

Tom

ML

USA
63 Posts

Posted - 11/07/2005 :  11:09:34 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Tom,

You need to set the color values the way you want them. In this case it appears that the colors just need to be reversed in order to get blue to be the lowest and red the highest. Here is the modified function (my modifications are between /// ML 11/7/2005 and /// end ML 11/7/2005 comment lines):



void testfunction(){

MatrixObject mat_obj("Test", 0);

int nLevels = 15;
GraphPage gp;
gp.Create("CONTOUR");
GraphLayer glay = gp.Layers();
int nplot = glay.AddPlot(mat_obj, IDM_PLOT_CONTOUR);
glay.Rescale();
if(nLevels){
DataPlot dp = glay.DataPlots(0);
vector vLevels(15);

Tree tr;
tr = dp.Surface;
tr.ColorMap.Details.Remove(); //DO I HAVE TO DELETE AS
//IT IS CONTRARY TO THE NEW SETTING?
tr.ColorMap.Count.nVal = vLevels.GetSize();
dp.Surface = tr;

//So far so good, but now the color table is messed up. Reds are small
//values and blue are high ones. Ok, than just change it, I thought...

dp.GetColormap(tr); //this is actually accessing only a part of
//.Surface, isn't it?
tr.Min.dVal = 0; //Though setting of highest values works,
tr.Max.dVal = 10; //setting the minimum doesn't!

vLevels = tr.Details.Levels.dVals;
vLevels[14] = 1400/15;
vLevels[13] = 1300/15;
vLevels[12] = 1200/15;
vLevels[11] = 1100/15;
vLevels[10] = 1000/15;
vLevels[9] = 900/15;
vLevels = 800/15;
vLevels[7] = 700/15;
vLevels[6] = 600/15;
vLevels[5] = 500/15;
vLevels[4] = 450/15;
vLevels[3] = 400/15;
vLevels[2] = 350/15;
vLevels[1] = 300/15;
vLevels[0] = 0/15;

/// ML 11/7/2005 --------------------------------------------
vector<uint> vnColors;
// Get the vector of colors:
vnColors = tr.Details.Colors.nVals;
// Reverse colors:
for (int ii = 0; ii < vnColors.GetSize() / 2; ii++)
{
uint nColor = vnColors[ii];
int iiUp = vnColors.GetSize() - ii - 1;
uint nColorUp = vnColors[iiUp];
vnColors[ii] = nColorUp;
vnColors[iiUp] = nColor;
}
// Set the vector of colors back:
tr.Details.Colors.nVals = vnColors;
/// end ML 11/7/2005 ----------------------------------------

tr.Details.Levels.dVals = vLevels;
dp.SetColormap(tr);
}
gp.SetShow();
gp.Refresh(TRUE); //Just to be sure...

//Ok, now I should be done, but the I would like to have blue for
// small values
//If I try to cheat and say:
// vLevels[0] = 1400/15;
// vLevels[1] = 1300/15; //and so on and so on, then everything is
//getting black
//Does it have to do with Detail.BellowValue and comparable stuff?
//Is there a better way of accessing the colors themselve?

}



Go to Top of Page

thrigs00

Germany
Posts

Posted - 11/07/2005 :  5:50:15 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
This worked actually great. I didn't know the colors are represented as integer values. Or did you actually just change the position?

I tried now to set the Below.BelowColor property to a certain color. How can you access the colors themselve?
The following code produces a runtime error....

int nBelowColor;
nBelowColor = tr.Details.Below.BelowColor.nVal;
nBelowColor = 4; //hoped this would be blue
tr.Details.Below.BelowColor.nVal = nBelowColor;

Is there any further documentation about Trees?

Thanks in advance!

Tom
Go to Top of Page

easwar

USA
1965 Posts

Posted - 11/07/2005 :  9:26:26 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Tom,

To set BelowColor, just use
tr.Details.BelowColor.nVal = 3;
before the line
dp.SetColormap(tr);

Note first of all that counting in OC starts at 0 and so color blue in default color list is 3, black being 0.

To see how to set the tree, easiest is to
a> place a break point in code and then looking at treenode in Code Builder variables window
b> insert the following statement at desired place in code to dump tree structure in script window:
out_tree(tr);

Easwar
OriginLab

Edited by - easwar on 11/07/2005 9:28:23 PM
Go to Top of Page

thrigs00

Germany
Posts

Posted - 11/23/2005 :  08:41:34 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Pretty cool, worked out well so far! Thanks!

I am getting picky now with my graphs...

What controls which colors are exactly used? Because if you adjust the number of levels, it creates the steps on its own...

Can you influence, say the color (maybe in RGB-values) of the minimum and maximum?

To change the system theme would only change the color on the specific engine, wouldn't it?

Tom
Go to Top of Page

easwar

USA
1965 Posts

Posted - 11/23/2005 :  5:28:28 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Tom,

If you use small numbers such as 1, 2, 3 etc these are interpreted as the index of the Origin color list, which as you correctly point out, is machine dependent - if user changes color table, then what is color 3 for you may not be same as color 3 for the user.

The good news is that you can set the color by specifying RGB values in your code so that any user who runs your code will see the same color.

In order to do this, you can use code such as below:


int nRed, nGreen, nBlue;
nRed = 10; nGreen = 20; nBlue = 100;
tr.Details.BelowColor.nVal = nRed + 256 * nGreen + 65536 * nBlue + 2^24;
dp.SetColormap(tr);



The number 2^24 is a bit offset that tells Origin that the number is to be interpreted as an RGB color. And you can then change the amount of R, G, B as well. Note that the values of nRed, nGreen, nBlue in the above equation can each range between 0 and 255.

Hope this helps.

Easwar
OriginLab



Edited by - easwar on 11/23/2005 5:28:52 PM
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