GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
gs_norms.c File Reference

OGSF library - calculation normals (lower level functions) More...

#include <math.h>
#include <grass/gis.h>
#include <grass/ogsf.h>
#include "gsget.h"
#include "rowcol.h"
Include dependency graph for gs_norms.c:

Go to the source code of this file.

Macros

#define NTOP   0x00001000
 
#define NBOT   0x00000100
 
#define NLFT   0x00000010
 
#define NRGT   0x00000001
 
#define NALL   0x00001111
 
#define NTL   0x00001010
 
#define NTR   0x00001001
 
#define NBL   0x00000110
 
#define NBR   0x00000101
 
#define SET_NORM(i)
 This macro is only used in the function calc_norm() More...
 

Functions

void init_vars (geosurf *gs)
 Init variables. More...
 
int gs_calc_normals (geosurf *gs)
 Calculate normals. More...
 
int calc_norm (geosurf *gs, int drow, int dcol, unsigned int neighbors)
 Calculate normals. More...
 

Detailed Description

OGSF library - calculation normals (lower level functions)

GRASS OpenGL gsurf OGSF Library

(C) 1999-2008 by the GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Author
Bill Brown USACERL
Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)

Definition in file gs_norms.c.

Macro Definition Documentation

◆ NALL

#define NALL   0x00001111

Definition at line 32 of file gs_norms.c.

Referenced by gs_calc_normals().

◆ NBL

#define NBL   0x00000110

Definition at line 36 of file gs_norms.c.

Referenced by gs_calc_normals().

◆ NBOT

#define NBOT   0x00000100

Definition at line 28 of file gs_norms.c.

Referenced by calc_norm(), and gs_calc_normals().

◆ NBR

#define NBR   0x00000101

Definition at line 37 of file gs_norms.c.

Referenced by gs_calc_normals().

◆ NLFT

#define NLFT   0x00000010

Definition at line 29 of file gs_norms.c.

Referenced by calc_norm(), and gs_calc_normals().

◆ NRGT

#define NRGT   0x00000001

Definition at line 30 of file gs_norms.c.

Referenced by calc_norm(), and gs_calc_normals().

◆ NTL

#define NTL   0x00001010

Definition at line 34 of file gs_norms.c.

Referenced by gs_calc_normals().

◆ NTOP

#define NTOP   0x00001000

Definition at line 27 of file gs_norms.c.

Referenced by calc_norm(), and gs_calc_normals().

◆ NTR

#define NTR   0x00001001

Definition at line 35 of file gs_norms.c.

Referenced by gs_calc_normals().

◆ SET_NORM

#define SET_NORM (   i)
Value:
dz1 = z1 - z2; \
dz2 = z3 - z4; \
temp[0] = (float) -dz1 * y_res_z2; \
temp[1] = (float) dz2 * x_res_z2; \
temp[2] = c_z2; \
normalizer = sqrt(temp[0] * temp[0] + temp[1] * temp[1] + c_z2_sq); \
if (!normalizer) normalizer= 1.0; \
temp[X] /= normalizer; \
temp[Y] /= normalizer; \
temp[Z] /= normalizer; \
PNORM(i,temp);
#define Z
Definition: ogsf.h:139
#define Y
Definition: ogsf.h:138
#define X
Definition: ogsf.h:137

This macro is only used in the function calc_norm()

Definition at line 42 of file gs_norms.c.

Function Documentation

◆ calc_norm()

int calc_norm ( geosurf gs,
int  drow,
int  dcol,
unsigned int  neighbors 
)

Calculate normals.

Need either four neighbors or two non-linear neighbors passed initial state of neighbors known from array position and data row & col

Parameters
gssurface (geosurf)
drowdata row
dcoldata col
neighborsneighbors id
Returns
0 no normals
1 on success

Definition at line 206 of file gs_norms.c.

References BM_get(), g_surf::curmask, DRC2OFF, GET_MAPATT, NBOT, NLFT, NRGT, NTOP, g_surf::x_mod, and g_surf::y_mod.

Referenced by gs_calc_normals().

◆ gs_calc_normals()

int gs_calc_normals ( geosurf gs)

Calculate normals.

OPTIMIZED for constant dy & dx

The norm array is always the same size, but diff resolutions force resampled data points to have their normals recalculated, then only those norms are passed to n3f during drawing. Norms are converted to a packed unsigned int for storage, must be converted back at time of use.

Todo:
fix to correctly calculate norms when mapped to sphere!

Uses the previous and next cells (when available) for normal calculations to produce smoother normals

Parameters
gssurface (geosurf)
Returns
1 on success
0 on failure

Definition at line 124 of file gs_norms.c.

References calc_norm(), G_debug(), gs_update_curmask(), g_surf::gsurf_id, init_vars(), NALL, NBL, NBOT, NBR, NLFT, g_surf::norm_needupdate, g_surf::norms, NRGT, NTL, NTOP, NTR, VCOLS, VROWS, g_surf::x_mod, and g_surf::y_mod.

Referenced by GS_get_norm_at_xy(), GS_update_normals(), and gsd_surf().

◆ init_vars()

void init_vars ( geosurf gs)

Init variables.

for optimization

Parameters
gssurface (geosurf)

Definition at line 72 of file gs_norms.c.

Referenced by gs_calc_normals().