GRASS Programmer's Manual  6.4.2(2012)
nviz.c
Go to the documentation of this file.
00001 
00015 #include <grass/glocale.h>
00016 #include <grass/nviz.h>
00017 
00023 void Nviz_init_data(nv_data * data)
00024 {
00025     unsigned int i;
00026 
00027     /* data range */
00028     data->zrange = 0;
00029     data->xyrange = 0;
00030 
00031     /* clip planes, turn off by default */
00032     data->num_cplanes = 0;
00033     data->cur_cplane = 0;
00034     for (i = 0; i < MAX_CPLANES; i++) {
00035         Nviz_new_cplane(data, i);
00036         Nviz_off_cplane(data, i);
00037     }
00038 
00039     /* lights */
00040     for (i = 0; i < MAX_LIGHTS; i++) {
00041         Nviz_new_light(data);
00042     }
00043 
00044     /* fringe */
00045     data->num_fringes = 0;
00046     data->fringe = NULL;
00047     
00048     return;
00049 }
00050 
00055 void Nviz_destroy_data(nv_data *data)
00056 {
00057     int i;
00058     for (i = 0; data->num_fringes; i++) {
00059         G_free(data->fringe[i]);
00060         data->fringe[i] = NULL;
00061     }
00062     data->num_fringes = 0;
00063     data->fringe = NULL;
00064 }
00065 
00072 void Nviz_set_bgcolor(nv_data * data, int color)
00073 {
00074     data->bgcolor = color;
00075 
00076     return;
00077 }
00078 
00086 int Nviz_get_bgcolor(nv_data * data)
00087 {
00088     return data->bgcolor;
00089 }
00090 
00098 int Nviz_color_from_str(const char *color_str)
00099 {
00100     int red, grn, blu;
00101 
00102     if (G_str_to_color(color_str, &red, &grn, &blu) != 1) {
00103         G_warning(_("Invalid color (%s), using \"white\" as default"),
00104                   color_str);
00105         red = grn = blu = 255;
00106     }
00107 
00108     return (red & RED_MASK) + ((int)((grn) << 8) & GRN_MASK) +
00109         ((int)((blu) << 16) & BLU_MASK);
00110 }
00111 
00123 struct fringe_data *Nviz_new_fringe(nv_data *data,
00124                                     int id, unsigned long color,
00125                                     double elev, int nw, int ne, int sw, int se)
00126 {
00127     int num;
00128     int *surf;
00129     struct fringe_data *f;
00130 
00131     if (!GS_surf_exists(id)) {
00132         /* select first surface from the list */
00133         surf = GS_get_surf_list(&num);
00134         if (num < 1)
00135             return NULL;
00136         id = surf[0];
00137     }
00138      
00139 
00140     f = (struct fringe_data *) G_malloc(sizeof(struct fringe_data));
00141     f->id = id;
00142     f->color = color;
00143     f->elev = elev;
00144     f->where[0] = nw;
00145     f->where[1] = ne;
00146     f->where[2] = sw;
00147     f->where[3] = se;
00148 
00149     data->fringe = (struct fringe_data **) G_realloc(data->fringe, data->num_fringes + 1 * sizeof(struct fringe_data *));
00150     data->fringe[data->num_fringes++] = f;
00151     
00152     return f;
00153 }
00154 
00166 struct fringe_data *Nviz_set_fringe(nv_data *data,
00167                                     int id, unsigned long color,
00168                                     double elev, int nw, int ne, int sw, int se)
00169 {
00170     int i, num;
00171     int *surf;
00172     struct fringe_data *f;
00173 
00174     if (!GS_surf_exists(id)) {
00175         /* select first surface from the list */
00176         surf = GS_get_surf_list(&num);
00177         if (num < 1)
00178             return NULL;
00179         id = surf[0];
00180     }
00181     
00182     for (i = 0; i < data->num_fringes; i++) {
00183         f = data->fringe[i];
00184         if (f->id == id) {
00185             f->color = color;
00186             f->elev  = elev;
00187             f->where[0] = nw;
00188             f->where[1] = ne;
00189             f->where[2] = sw;
00190             f->where[3] = se;
00191             
00192             return f;
00193         }
00194     }
00195 
00196     f = Nviz_new_fringe(data,
00197                         id, color,
00198                         elev, nw, ne, sw, se);
00199     
00200     return f;
00201 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines