00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00026 #ifndef SCENE_H
00027 #define SCENE_H
00028
00029 #include "Displayable.h"
00030 #include "NameList.h"
00031
00032 class DisplayDevice;
00033 class FileRenderer;
00034 class DisplayColor;
00035
00036
00037 #define DISP_LIGHTS 4
00038
00039
00040 #define REGCLRS 33
00041 #define EXTRACLRS 1
00042 #define VISCLRS (REGCLRS - EXTRACLRS)
00043 #define MAPCLRS 1024
00044 #define MAXCOLORS (REGCLRS + MAPCLRS)
00045
00046
00047 #define BEGREGCLRS 0
00048 #define BEGMAP REGCLRS
00049
00050
00051 #define REGBLUE 0
00052 #define REGRED 1
00053 #define REGGREY 2
00054 #define REGORANGE 3
00055 #define REGYELLOW 4
00056 #define REGTAN 5
00057 #define REGSILVER 6
00058 #define REGGREEN 7
00059 #define REGWHITE 8
00060 #define REGPINK 9
00061 #define REGCYAN 10
00062 #define REGPURPLE 11
00063 #define REGLIME 12
00064 #define REGMAUVRE 13
00065 #define REGOCHRE 14
00066 #define REGICEBLUE 15
00067 #define REGBLACK 16
00068
00069 #define REGBLUE2 23
00070
00071
00072 #define MAPCOLOR(a) (a + BEGMAP)
00073
00074
00076 class ColorScale {
00077 public:
00078 float min[3], mid[3], max[3];
00079 char name[32];
00080
00081 int operator==(const ColorScale c) {
00082 return !memcmp(&c, this, sizeof(ColorScale));
00083 }
00084 };
00085
00086
00088 class Scene {
00089 private:
00091 int backgroundmode;
00092 int backgroundmode_changed;
00093
00095 struct LightState {
00096 float color[3];
00097 float pos[3];
00098 int highlighted;
00099 int on;
00100 };
00101 int light_changed;
00102 LightState lightState[DISP_LIGHTS];
00103
00105 struct AdvancedLightState {
00106 float color[3];
00107 float pos[3];
00108 float constfactor;
00109 float linearfactor;
00110 float quadfactor;
00111 float spotdir[3];
00112 float fallstart;
00113 float fallend;
00114 int spoton;
00115 int highlighted;
00116 int on;
00117 };
00118 int adv_light_changed;
00119 AdvancedLightState advLightState[DISP_LIGHTS];
00120
00122 static const float defaultColor[3L*REGCLRS];
00123 float colorData[3L*MAXCOLORS];
00124 NameList<NameList<int> *> categories;
00125
00126 NameList<int> colorNames;
00127
00128 int scaleActive;
00129 float scaleMin, scaleMid, scaleMax;
00130 int scaleReverse;
00131 int scalePosterize;
00132 ResizeArray<ColorScale> colorScales;
00133 ResizeArray<const char *> colorScaleMenuNames;
00134 void create_colorscale();
00135
00136
00137 DisplayColor *background;
00138 DisplayColor *backgradtop;
00139 DisplayColor *backgradbot;
00140 DisplayColor *foreground;
00141
00144 int background_color_changed;
00145 int background_color_id;
00146
00149 int backgradtop_color_changed;
00150 int backgradtop_color_id;
00151 int backgradbot_color_changed;
00152 int backgradbot_color_id;
00153
00156 int foreground_color_changed;
00157 int foreground_color_id;
00158
00159 public:
00160 Scene(void);
00161 virtual ~Scene(void);
00162
00166 Displayable root;
00167
00169 void set_background_mode(int mode);
00170 int background_mode(void);
00171
00172 void reset_lights();
00173
00175
00176 void define_light(int n, const float *color, const float *position);
00177 void activate_light(int n, int turnon);
00178 void highlight_light(int , int ) {}
00179 void rotate_light(int n, float theta, char axis);
00180 void move_light(int n, const float *);
00181 const float *light_pos(int n) const;
00182 const float *light_pos_default(int n) const;
00183 const float *light_color(int n) const;
00184 const float *light_color_default(int n) const;
00185 int light_active(int n) const { return lightState[n].on; }
00186 int light_highlighted(int) const { return FALSE; }
00188
00190
00191 void define_adv_light(int n, const float *color, const float *position,
00192 float constant, float linear, float quad,
00193 float *spotdir, float fallstart, float fallend,
00194 int spoton);
00195 void activate_adv_light(int n, int turnon);
00196 void highlight_adv_light(int , int ) {}
00197 void move_adv_light(int n, const float *);
00198 const float *adv_light_pos(int n) const;
00199 const float *adv_light_pos_default(int n) const;
00200 const float *adv_light_color(int n) const;
00201 const float *adv_light_color_default(int n) const;
00202 void adv_light_attenuation(int n, float constant, float linear, float quad);
00203 void adv_light_get_attenuation(int n, float &constant, float &linear, float &quad) const;
00204 void adv_light_spotlight(int n, float *spotdir, float fallstart,
00205 float fallend, int spoton);
00206 const float *adv_light_get_spotlight(int n, float &fallstart,
00207 float &fallend, int &spoton) const;
00208 int adv_light_active(int n) const { return advLightState[n].on; }
00209 int adv_light_highlighted(int) const { return FALSE; }
00211
00213
00214 int add_color_category(const char *catname) {
00215 if (categories.typecode(catname) != -1) return -1;
00216 return categories.add_name(catname, new NameList<int>);
00217 }
00218 int add_color_item(int cat_id, const char *name, int init_color) {
00219 NameList<int> *cat = categories.data(cat_id);
00220 return cat->add_name(name, init_color);
00221 }
00222
00225 void set_category_item(int cat_id, int item, int color) {
00226 NameList<int> *cat = categories.data(cat_id);
00227 cat->set_data(item, color);
00228 root.color_changed(cat_id);
00229 }
00230 void set_color_value(int n, const float *rgb) {
00231 memcpy(colorData+3L*n, rgb, 3L*sizeof(float));
00232 root.color_rgb_changed(n);
00233 }
00234
00235
00236 int get_category_item(int cat_id, int item) {
00237 NameList<int> *cat = categories.data(cat_id);
00238 return cat->data(item);
00239 }
00240
00242 int num_categories() const { return categories.num(); }
00243 const char *category_name(int cat) const { return categories.name(cat); }
00244 int category_index(const char *catname) const {
00245 return categories.typecode(catname);
00246 }
00247 int num_colors() const { return MAXCOLORS; }
00248 int num_regular_colors() const { return REGCLRS; }
00249 const char *color_name(int n) const { return colorNames.name(n); }
00250
00252 int color_index(const char *name) const { return colorNames.typecode(name); }
00253 const float *color_value(int n) const { return colorData+3L*n; }
00254 const float *color_default_value(int n) const { return defaultColor+3L*n; }
00255 int num_category_items(int cat) const {
00256 return categories.data(cat)->num();
00257 }
00258 const char *category_item_name(int cat, int item) const {
00259 return categories.data(cat)->name(item);
00260 }
00261 int category_item_index(int cat, const char *item) const {
00262 return categories.data(cat)->typecode(item);
00263 }
00264 int category_item_value(int cat, const char *item) const {
00265 return categories.data(cat)->data(item);
00266 }
00267 int category_item_value(int cat, int item) const {
00268 return categories.data(cat)->data(item);
00269 }
00270
00273 int nearest_index(float r, float g, float b) const;
00274
00276 void set_colorscale_params(float min, float mid, float max,
00277 int reverse, int posterize) {
00278 scaleMin = min; scaleMid = mid; scaleMax = max;
00279 scaleReverse = reverse;
00280 scalePosterize = posterize;
00281 create_colorscale();
00282 }
00283 void set_colorscale_method(int index) {
00284 if (scaleActive != index) {
00285 scaleActive = index;
00286 create_colorscale();
00287 }
00288 }
00289
00291 int get_colorscale_colors(int whichScale,
00292 float min[3], float mid[3], float max[3]);
00293
00295 int set_colorscale_colors(int whichScale,
00296 const float min[3], const float mid[3], const float max[3]);
00297
00299 void colorscale_params(float *mid, float *min, float *max,
00300 int *reverse, int *posterize) const {
00301 *mid = scaleMid; *min = scaleMin; *max = scaleMax;
00302 *reverse = scaleReverse;
00303 *posterize = scalePosterize;
00304 }
00305
00306 int colorscale_method() const { return scaleActive; }
00307
00308 int num_colorscale_methods() const { return int(colorScales.num()); }
00309 const char *colorscale_method_name(int n) const {
00310 return colorScales[n].name;
00311 }
00312 const char *colorscale_method_menuname(int n) const {
00313 return colorScaleMenuNames[n];
00314 }
00315
00316 int colorscale_type(int index);
00317
00319
00322 virtual int prepare();
00323
00330 virtual void draw(DisplayDevice *);
00331
00337 int filedraw(FileRenderer *, const char *, DisplayDevice *);
00338
00340 void draw_finished();
00341
00342 };
00343
00344 #endif
00345