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