BRL-CAD
Collaboration diagram for Color:

Files

file  color.c
 

Data Structures

struct  bu_color
 

Macros

#define RED   0
 
#define GRN   1
 
#define BLU   2
 
#define HUE   0
 
#define SAT   1
 
#define VAL   2
 
#define ACHROMATIC   -1.0
 
#define BU_COLOR_NULL   ((struct bu_color *) 0)
 
#define BU_CK_COLOR(_c)   BU_CKMAG(_c, BU_COLOR_MAGIC, "bu_color")
 
#define BU_COLOR_INIT(_c)
 
#define BU_COLOR_INIT_ZERO   { BU_COLOR_MAGIC, {0, 0, 0} }
 
#define BU_COLOR_IS_INITIALIZED(_c)   (((struct bu_color *)(_c) != BU_COLOR_NULL) && LIKELY((_c)->magic == BU_COLOR_MAGIC))
 

Typedefs

typedef struct bu_color bu_color_t
 

Functions

void bu_rgb_to_hsv (unsigned char *rgb, fastf_t *hsv)
 
int bu_hsv_to_rgb (fastf_t *hsv, unsigned char *rgb)
 
int bu_str_to_rgb (char *str, unsigned char *rgb)
 
int bu_color_from_rgb_floats (struct bu_color *cp, fastf_t *rgb)
 
int bu_color_to_rgb_floats (struct bu_color *cp, fastf_t *rgb)
 

Detailed Description

Macro Definition Documentation

#define HUE   0

Definition at line 43 of file color.h.

#define SAT   1

Definition at line 44 of file color.h.

#define VAL   2

Definition at line 45 of file color.h.

#define ACHROMATIC   -1.0

Definition at line 47 of file color.h.

#define BU_COLOR_NULL   ((struct bu_color *) 0)

Definition at line 55 of file color.h.

#define BU_CK_COLOR (   _c)    BU_CKMAG(_c, BU_COLOR_MAGIC, "bu_color")

asserts the integrity of a bu_color struct.

Definition at line 60 of file color.h.

#define BU_COLOR_INIT (   _c)
Value:
{ \
(_c)->buc_magic = BU_COLOR_MAGIC; \
(_c)->buc_rgb[0] = (_c)->buc_rgb[1] = (_c)->buc_rgb[2] = 0; \
}
#define BU_COLOR_MAGIC
Definition: magic.h:48

initializes a bu_bitv struct without allocating any memory.

Definition at line 65 of file color.h.

#define BU_COLOR_INIT_ZERO   { BU_COLOR_MAGIC, {0, 0, 0} }

macro suitable for declaration statement initialization of a bu_color struct. does not allocate memory.

Definition at line 74 of file color.h.

#define BU_COLOR_IS_INITIALIZED (   _c)    (((struct bu_color *)(_c) != BU_COLOR_NULL) && LIKELY((_c)->magic == BU_COLOR_MAGIC))

returns truthfully whether a bu_color has been initialized

Definition at line 79 of file color.h.

Typedef Documentation

typedef struct bu_color bu_color_t

Definition at line 54 of file color.h.

Function Documentation

void bu_rgb_to_hsv ( unsigned char *  rgb,
fastf_t hsv 
)

Function to generate random color

TODO - multiple possibilities here - truly random color, or "constrained" random aka the BRLCADWrapper:getRandomColor function. Need a function that provides flexibility. Possible calling syntax:

1 bu_color_rand(cp, NULL, NULL, NULL, 0); #generate a totally random color value
2 bu_color_rand(cp, NULL, rgb_seed, NULL, COLOR_SET_R); #randomize the R value only, else use rgb_seed values
3 bu_color_rand(cp, NULL, rgb_seed, NULL, COLOR_GOLDEN); #use the golden ratio constraining technique
4 bu_color_rand(cp, NULL, NULL, hsv_seed, COLOR_GOLDEN); #use the golden ratio constraining technique with an hsv input
5 bu_color_rand(cp, seed, NULL, NULL, 0); #randomize, using bu_color seed

Passing multiple seeds would be an error - the multiple slots are for formatting convenience. May be better to use just one bu_color seed and make callers pre-package it - not sure yet. If we go that route, we'll have to implement the unimplemented utility functions below. Convert between RGB and HSV color models

R, G, and B are in {0, 1, ..., 255},

H is in [0.0, 360.0), and S and V are in [0.0, 1.0],

unless S = 0.0, in which case H = ACHROMATIC.

These two routines are adapted from: pp. 592-3 of J.D. Foley, A. van Dam, S.K. Feiner, and J.F. Hughes, Computer graphics: principles and practice, 2nd ed., Addison-Wesley, Reading, MA, 1990.

Definition at line 60 of file color.c.

References ACHROMATIC, BLU, GRN, HUE, NEAR_ZERO, RED, SAT, SMALL_FASTF, and VAL.

Referenced by plotsurface(), and tcl_bu_rgb_to_hsv().

int bu_hsv_to_rgb ( fastf_t hsv,
unsigned char *  rgb 
)

Definition at line 121 of file color.c.

References ACHROMATIC, BLU, bu_bomb(), bu_log(), GRN, HUE, NEAR_ZERO, RED, SAT, SMALL_FASTF, V3ARGS, VAL, VSET, and VSETALL.

Referenced by plotsurface(), and tcl_bu_hsv_to_rgb().

Here is the call graph for this function:

int bu_str_to_rgb ( char *  str,
unsigned char *  rgb 
)

Utility functions to convert between various containers for color handling

Definition at line 178 of file color.c.

References UNLIKELY, and VSET.

int bu_color_from_rgb_floats ( struct bu_color cp,
fastf_t rgb 
)

Definition at line 235 of file color.c.

References BLU, bu_color::buc_rgb, GRN, RED, and UNLIKELY.

Referenced by rt_pnts_import5().

int bu_color_to_rgb_floats ( struct bu_color cp,
fastf_t rgb 
)

Definition at line 220 of file color.c.

References BLU, bu_color::buc_rgb, GRN, RED, and UNLIKELY.

Referenced by rt_pnts_export5().