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 for Programming
 Forum for Origin C
 How to specify custom colormap?

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
xgu Posted - 06/14/2006 : 08:01:28 AM
Origin Version (Select Help-->About Origin): Pro 7.5
Operating System: Windows XP SP2

I'd like to use a rainbow colormap in a pseudocolor image plot. Origin does not have the colormap, so I am going to build one myself. But the question is, what are the names and meanings of colormap class properties that I can use? The Origin help system lacks such information. Can somebody help me on it? Basically I need to specify invididual colors for a set of levels programmatically.

Thanks.
1   L A T E S T    R E P L I E S    (Newest First)
easwar Posted - 06/14/2006 : 10:43:13 AM
Hi xgu,

I presume you are referring to the image plot that can be created from a matrix (menu item Plot->Image Plot with matrix active).

If so, you can use code such as posted below.

A few notes:
-> The image plot has 256 fixed levels.
-> Colors can be assigned arbitrary to these levels using any desired mapping/formula for R, G, B
-> Colors can also be read from a palette file
-> The colormap property can be read as a tree object in OC and then can be set back to the data plot to apply changes
-> Need to use appropriate offset constant to color to indicate to Origin how to interpret the color values - for this plot type, the constant is OCOLOR_RGB_FLAG_BIT - these constants are defined in OC_CONST.h

The code below is very similar to how one can set color map for contour plots, and an example of manipulating contour plots can be found at:
http://originlab.com/index.aspx?s=9&lm=71&pid=268
(see the Customize Contour Plot example under Graphing)

Hope this helps.

Easwar
OriginLab




void image_plot_set_colormap()
{
// Point to active graph layer
GraphLayer gly = Project.ActiveLayer();
if( !gly ) return;

// Check to ensure first plot in layer is a matrix image plot
StyleHolder sh = gly.StyleHolders(0);
if( sh.GetPlotId() != IDM_PLOT_MATRIX_IMAGE )
return;
DataPlot dp = gly.DataPlots(0);
if( !dp ) return;

// Get colormap
Tree tr;
dp.GetColormap(tr);

// The colormap for matrix image plot has 256 fixed levels

// Declare R, G, B vectors to hold color info
vector<uint> vecR(256), vecG(256), vecB(256);

// You can fill these vectors with any color scheme that you desire
// by directly assigning values to vector such as
// for(int i = 0; i < nLevels; i++)
//{
// vecR[i] = 256* i / nLevels; // linear in R
// vecG[i] = 256 * i^2 / nLevels^2; // power of 2 in G
// vecB[i] = 128 + 128 * sin(2 * Pi * i / nLevels) ; // sinusoidal in B
//}

// For this example, let us read the colors from a palette file instead
// In this example, let us read in a binary palette file that has 256 colors
// Origin ships with three palette files, one of which is rainbow
string strPaletteFile = GetAppPath(TRUE) + "Palettes\\Rainbow.PAL";
// Call function to read binary palette file
int iRet = read_palette(strPaletteFile, vecR, vecG, vecB);
if( iRet < 0 )
{
out_str("Error reading palette file!");
return;
}
if( iRet != 256 )
out_str("Palette file contained less than 256 colors!");

// Now that R, G, B vectors are ready, need to combine them into one vector to set
// colors for the colormap
vector<uint> vecColors(256);
for(int i = 0; i < 256; i++)
vecColors[i] = vecR[i] + 256 * vecG[i] + 65536 * vecB[i] + OCOLOR_RGB_FLAG_BIT;
// The constant OCOLOR_RGB_FLAG_BIT tells Origin to treat the color map in
// accordance with what is needed for the image plot coloring


// Now set the colormpa to the tree
tr.Details.Colors.nVals = vecColors;

// Set the dataplot using modified tree
dp.SetColormap(tr);

// Refresh graph page (may not be required)
gly.GetPage().Refresh();
}



/////////////////////////////////////////////////////////////////////////////////////
// This function reads the color map from a binary palette file - the format for the
// binary file is same as the Microsoft Palette file
//
static int read_palette(string strFileName, vector<uint>& vecR, vector<uint>& vecG, vector<uint>& vecB)
{
bool bRet;
int ierr;

file ff;
bRet = ff.Open(strFileName, file::modeRead);
if(!bRet) return -1;

// first read header information that includes some text
// plus information on file size etc.

int ijunk;
ierr = ff.Read(&ijunk,4); // read and discard "RIFF"
int isize;
ierr = ff.Read(&isize,4); // read file size
ierr = ff.Read(&ijunk,4); // read and discard "PAL "
ierr = ff.Read(&ijunk,4); // read and discard "data"

ierr = ff.Read(&isize,4); // read size
short nShort;
ierr = ff.Read(&nShort,2); // read short
short nCols;
ierr = ff.Read(&nCols,2); // read num colors

if (nCols < 2 | nCols > 256)
{
bRet = ff.Close();
return -1;
}
// now read icol entries of the color map
for (int ii=0; ii < nCols; ii++)
{
uint ivalue;
ierr = ff.Read(&ivalue,4);
vecB[ii] = (int) (ivalue / (256 * 256));
ivalue = ivalue - vecB[ii] * 256 * 256;
vecG[ii] = (int) (ivalue / 256);
vecR[ii] = ivalue - vecG[ii] * 256;

}

// close file
bRet = ff.Close();
if(!bRet) return -1;

return nCols;
}





Edited by - easwar on 06/14/2006 10:43:59 AM

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