Tuesday, June 29, 2010

Setting colors in Tobii SDK codes (for C#)

This post is just for myself.
Now, I am making my own control program of Tobii Eye Tracker using TET SDK kit.

Many of functions are well written in sample codes. But, still, I need to learn how to write codes for some functions.
During this word, one critical problem is that Tobii prepared the SDK manual only for C++ and VB but not for C# with which I am making my program.
Today, I solved one little issue which is setting colors of the calibration target (which is a circle moving around a display during calibration).

In the default codes of the designing calibration procedure is like the following.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Initiate window properties and start calibration
tetCalibProc.WindowTopmost = false;
tetCalibProc.WindowVisible = true;
tetCalibProc.StartCalibration(isRecalibrating ? etCalibType.TetCalibType_Recalib
: TetCalibType.TetCalibType_Calib, true);
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

It seems that 'tetCalibProc' object has parameters. and actually it does! however,
In TETCalibProcClass
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[ComAliasName("stdole.OLE_COLOR")]
[DispId(19)]
public virtual uint PointColor { get; set; }

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

So how should I set the color for PointColor parameter?

First, I guessed I could use the real color name.
but this ways makes an error such as "the types were different".

When I search through the definition of TetCalibProc.PointColor, it was found to be a uint object. this means, the value should be positive integer from 0 to 4,294,967,295.

After some searching through Google, I should this object as OLE_color type object.
This may be very basic for programming. but, (because of such a basic thing),
I took much time to get this the answer.
In OLE_color type object, Red, Green, Blue colors are independently controlled from 0 to 255. and in the binary scale, first 8bit is used for blue, next 8bit is used for green, and the last 8bit is used for Red.
so, in the binary scale.
Blue is expressed as 11111111 00000000 00000000. If this value is converted to the form of decimal system, it is 16711680.
Similary, Red(00000000 00000000 11111111) is 255.
Green(00000000 11111111 00000000) is 65280.

I can use another color,say yellow. it's mix of red and green.so
its value is 00000000 11111111 11111111(or 65535).

Alternatively, i may use other code in the system class.
********************************************************************
tetCalibProc.PointColor = (uint)System.ColorTranslator.ToOle(System.Drawing.Color.Yellow);
********************************************************************

Later, I want to check whether this codes works fine or not.

0 Comments:

Post a Comment

<< Home