21 #include <grass/gis.h> 
   22 #include <grass/gstypes.h> 
   27 #define NTOP 0x00001000 
   28 #define NBOT 0x00000100 
   29 #define NLFT 0x00000010 
   30 #define NRGT 0x00000001 
   32 #define NALL 0x00001111 
   34 #define NTL  0x00001010 
   35 #define NTR  0x00001001 
   36 #define NBL  0x00000110 
   37 #define NBR  0x00000101 
   45        temp[0] = (float) -dz1 * y_res_z2; \ 
   46        temp[1] = (float) dz2 * x_res_z2; \ 
   48        normalizer = sqrt(temp[0] * temp[0] + temp[1] * temp[1] + c_z2_sq); \ 
   49        if (!normalizer) normalizer= 1.0; \ 
   50        temp[X] /= normalizer; \ 
   51        temp[Y] /= normalizer; \ 
   52        temp[Z] /= normalizer; \ 
   56 static float x_res_z2, y_res_z2;
 
   57 static float c_z2, c_z2_sq;
 
   58 static typbuff *elbuf;
 
   59 static unsigned long *norm;
 
   78 #ifdef USE_GL_NORMALIZE 
   80         2.0 * gs->xres * gs->yres * gs->x_mod * gs->y_mod / 
GS_global_exag();
 
   81     c_z2_sq = c_z2 * c_z2;
 
   82     x_res_z2 = 2.0 * gs->xres * gs->z_exag * gs->x_mod;
 
   83     y_res_z2 = 2.0 * gs->yres * gs->z_exag * gs->y_mod;
 
   91         c_z2 = 2.0 * gs->xres * gs->yres * gs->x_mod * gs->y_mod;
 
   92         c_z2_sq = c_z2 * c_z2;
 
   93         x_res_z2 = 2.0 * gs->xres * gs->z_exag * gs->x_mod;
 
   94         y_res_z2 = 2.0 * gs->yres * gs->z_exag * gs->y_mod;
 
   98     slice = gs->y_mod * gs->cols;
 
  130     if (!gs->norm_needupdate || !gs->norms) {
 
  134     gs->norm_needupdate = 0;
 
  145     G_debug(5, 
"gs_calc_normals(): id=%d", gs->gsurf_id);
 
  151     for (col = 1; col < xcnt; col++) {
 
  160     for (row = 1; row < ycnt; row++) {
 
  162             G_debug(5, 
"gs_calc_normals(): row=%d", row);
 
  168         for (col = 1; col < xcnt; col++) {
 
  180     for (col = 1; col < xcnt; col++) {
 
  206 int calc_norm(geosurf * gs, 
int drow, 
int dcol, 
unsigned int neighbors)
 
  209     float temp[3], normalizer, dz1, dz2, z0, z1, z2, z3, z4;
 
  214         if (neighbors & 
NTOP) {
 
  215             if (
BM_get(gs->curmask, dcol, drow - gs->y_mod)) {
 
  221         if (neighbors & 
NBOT) {
 
  222             if (
BM_get(gs->curmask, dcol, drow + gs->y_mod)) {
 
  228         if (neighbors & 
NLFT) {
 
  229             if (
BM_get(gs->curmask, dcol - gs->x_mod, drow)) {
 
  235         if (neighbors & 
NRGT) {
 
  236             if (
BM_get(gs->curmask, dcol + gs->x_mod, drow)) {
 
  248     noffset = 
DRC2OFF(gs, drow, dcol);
 
  254     z1 = z2 = z3 = z4 = z0;
 
  257     if (neighbors & 
NRGT) {
 
  259         if (!(neighbors & 
NLFT)) {
 
  264     if (neighbors & 
NLFT) {
 
  267         if (!(neighbors & NRGT)) {
 
  272     if (neighbors & 
NTOP) {
 
  275         if (!(neighbors & 
NBOT)) {
 
  280     if (neighbors & 
NBOT) {
 
  283         if (!(neighbors & NTOP)) {
 
int BM_get(struct BM *map, int x, int y)
Gets 'val' from the bitmap. 
#define DRC2OFF(gs, drow, dcol)
#define SET_NORM(i)
This macro is only used in the function calc_norm() 
int gs_calc_normals(geosurf *gs)
Calculate normals. 
void init_vars(geosurf *gs)
Init variables. 
typbuff * gs_get_att_typbuff(geosurf *gs, int desc, int to_write)
Get attribute data buffer. 
int G_debug(int level, const char *msg,...)
Print debugging message. 
int calc_norm(geosurf *gs, int drow, int dcol, unsigned int neighbors)
Calculate normals. 
float GS_global_exag(void)
Get global z-exag value. 
int gs_update_curmask(geosurf *surf)
Update current maps. 
void GS_get_scale(float *sx, float *sy, float *sz, int doexag)
Get axis scale. 
#define GET_MAPATT(buff, offset, att)