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
00100 LightState lightState[DISP_LIGHTS];
00101
00103 static const float defaultColor[3*REGCLRS];
00104 float colorData[3*MAXCOLORS];
00105 NameList<NameList<int> *> categories;
00106
00107 NameList<int> colorNames;
00108
00109 int scaleMethod;
00110 float scaleMin, scaleMid, scaleMax;
00111 ResizeArray<ColorScale> colorScales;
00112 void create_colorscale();
00113
00114
00115 DisplayColor *background;
00116 DisplayColor *backgradtop;
00117 DisplayColor *backgradbot;
00118 DisplayColor *foreground;
00119
00122 int background_color_changed;
00123 int background_color_id;
00124
00127 int backgradtop_color_changed;
00128 int backgradtop_color_id;
00129 int backgradbot_color_changed;
00130 int backgradbot_color_id;
00131
00134 int foreground_color_changed;
00135 int foreground_color_id;
00136
00137 public:
00138 Scene(void);
00139 virtual ~Scene(void);
00140
00144 Displayable root;
00145
00147 void set_background_mode(int mode);
00148 int background_mode(void);
00149
00151
00152 void define_light(int n, const float *color, const float *position);
00153 void activate_light(int n, int turnon);
00154 void highlight_light(int , int ) {}
00155 void rotate_light(int n, float theta, char axis);
00156 void move_light(int n, const float *);
00157 const float *light_pos(int n) const;
00158 const float *light_pos_default(int n) const;
00159 const float *light_color(int n) const;
00160 const float *light_color_default(int n) const;
00161 void reset_lights();
00162 int light_active(int n) const { return lightState[n].on; }
00163 int light_highlighted(int) const { return FALSE; }
00165
00167
00168 int add_color_category(const char *catname) {
00169 if (categories.typecode(catname) != -1) return -1;
00170 return categories.add_name(catname, new NameList<int>);
00171 }
00172 int add_color_item(int cat_id, const char *name, int init_color) {
00173 NameList<int> *cat = categories.data(cat_id);
00174 return cat->add_name(name, init_color);
00175 }
00178 void set_category_item(int cat_id, int item, int color) {
00179 NameList<int> *cat = categories.data(cat_id);
00180 cat->set_data(item, color);
00181 root.color_changed(cat_id);
00182 }
00183 void set_color_value(int n, const float *rgb) {
00184 memcpy(colorData+3*n, rgb, 3*sizeof(float));
00185 root.color_rgb_changed(n);
00186 }
00187 void set_colorscale_value(float min, float mid, float max) {
00188 scaleMin = min; scaleMid = mid; scaleMax = max;
00189 create_colorscale();
00190 }
00191 void set_colorscale_method(int method) {
00192 if (scaleMethod != method) {
00193 scaleMethod = method;
00194 create_colorscale();
00195 }
00196 }
00197
00198
00199 int get_category_item(int cat_id, int item) {
00200 NameList<int> *cat = categories.data(cat_id);
00201 return cat->data(item);
00202 }
00203
00205 int get_colorscale_colors(int whichScale,
00206 float min[3], float mid[3], float max[3]);
00208 int set_colorscale_colors(int whichScale,
00209 const float min[3], const float mid[3], const float max[3]);
00210
00211
00213 int num_categories() const { return categories.num(); }
00214 const char *category_name(int cat) const { return categories.name(cat); }
00215 int category_index(const char *catname) const {
00216 return categories.typecode(catname);
00217 }
00218 int num_colors() const { return MAXCOLORS; }
00219 int num_regular_colors() const { return REGCLRS; }
00220 const char *color_name(int n) const { return colorNames.name(n); }
00221
00223 int color_index(const char *name) const { return colorNames.typecode(name); }
00224 const float *color_value(int n) const { return colorData+3*n; }
00225 const float *color_default_value(int n) const { return defaultColor+3*n; }
00226 int num_category_items(int cat) const {
00227 return categories.data(cat)->num();
00228 }
00229 const char *category_item_name(int cat, int item) const {
00230 return categories.data(cat)->name(item);
00231 }
00232 int category_item_index(int cat, const char *item) const {
00233 return categories.data(cat)->typecode(item);
00234 }
00235 int category_item_value(int cat, const char *item) const {
00236 return categories.data(cat)->data(item);
00237 }
00238 int category_item_value(int cat, int item) const {
00239 return categories.data(cat)->data(item);
00240 }
00241
00243 void colorscale_value(float *mid, float *min, float *max) const {
00244 *mid = scaleMid; *min = scaleMin; *max = scaleMax;
00245 }
00246 int num_colorscale_methods() const { return colorScales.num(); }
00247 int colorscale_method() const { return scaleMethod; }
00248 const char *colorscale_method_name(int n) const {
00249 return colorScales[n].name;
00250 }
00251
00254 int nearest_index(float r, float g, float b) const;
00255
00257
00260 virtual int prepare();
00261
00268 virtual void draw(DisplayDevice *);
00269
00275 int filedraw(FileRenderer *, const char *, DisplayDevice *);
00276
00278 void draw_finished();
00279
00280 };
00281
00282 #endif
00283