[vtkusers] HSV to RGB

Benjamin King king.benjamin at mh-hannover.de
Mon Oct 27 04:34:10 EST 2003


Hello Jihwan,

you can use the following Tcl code

--
set x 0

vtkColorTransferFunction f
f AddHSVPoint $x <your h> <your s> <your v>
set r [f GetRedValue $x]
set g [f GetGreenValue $x]
set b [f GetBlueValue $x]

f Delete
--

If you want to convert several values, you can use the same function f for 
different values of x (vtk interpolates between them).

There are also HSVtoRGB and RGBtoHSV methods in vtkMath, but they aren't 
wrapped with Tcl. If using the function seems to be to much overhead for 
your purpose, then you may modify the following code (provided by Google, 
so I don't know if it is correct.)

--
HSV_to_RGB( HSVType HSV ) { 	// H is given on [0, 6] or UNDEFINED. S and V 
are given on [0, 1]. 	// RGB are each returned on [0, 1]. 	float h = HSV.H, 
s = HSV.S, v = HSV.V, m, n, f; 	int i; 	RGBType RGB;

	if(h == UNDEFINED) RETURN_RGB(v, v, v); 	i = floor(h); 	f = h - i; 	if(!(i 
& 1)) f = 1 - f; // if i is even 	m = v * (1 - s); 	n = v * (1 - s * f); 
	switch (i) { 		case 6: 		case 0: RETURN_RGB(v, n, m); 		case 1: 
RETURN_RGB(n, v, m); 		case 2: RETURN_RGB(m, v, n) 		case 3: RETURN_RGB(m, 
n, v); 		case 4: RETURN_RGB(n, m, v); 		case 5: RETURN_RGB(v, m, n); 	} } --

Hope it helps,
  Benjamin


On Sat, 25 Oct 2003 11:33:59 -0600 (MDT), Jihwan Kim <jihwan at cs.utah.edu> 
wrote:

> How can I convert HSV to RGB from vtk script?
> I see HSVTORGB function, but don't know how to get rerutn values from the
> arguments passed by reference in VTK.
>
> Thanks
> _______________________________________________
> This is the private VTK discussion list. Please keep messages on-topic. 
> Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>



-- 
Benjamin King
Institut für Medizinische Informatik
Medizinische Hochschule Hannover
Tel.: +49  511  532-2663



More information about the vtkusers mailing list