244 #include <grass/gis.h> 
  250 #define MIN(a,b) ((a) < (b) ? (a) : (b)) 
  251 #define MAX(a,b) ((a) > (b) ? (a) : (b)) 
  253 #define NO_DEFAULT_RULE (! r->defaultDRuleSet) 
  254 #define NO_LEFT_INFINITE_RULE (! r->infiniteLeftSet) 
  255 #define NO_RIGHT_INFINITE_RULE (! r->infiniteRightSet) 
  256 #define NO_FINITE_RULE (r->nofRules <= 0) 
  257 #define NO_EXPLICIT_RULE (NO_FINITE_RULE && \ 
  258                           NO_LEFT_INFINITE_RULE && NO_RIGHT_INFINITE_RULE) 
  260 #define DEFAULT_MIN ((DCELL) 1) 
  261 #define DEFAULT_MAX ((DCELL) 255) 
  268     r->defaultDRuleSet = 0;
 
  269     r->defaultRRuleSet = 0;
 
  270     r->infiniteRightSet = r->infiniteLeftSet = 0;
 
  279     if (r->maxNofRules > 0)
 
  299     r->defaultDMin = dLow;
 
  300     r->defaultDMax = dHigh;
 
  301     r->defaultDRuleSet = 1;
 
  308     r->defaultRMin = low;
 
  309     r->defaultRMax = high;
 
  310     r->defaultRRuleSet = 1;
 
  316 fpreclass_set_limits(
struct FPReclass *
r, DCELL dLow, DCELL dHigh, DCELL rLow,
 
  328 fpreclass_update_limits(
struct FPReclass *
r, DCELL dLow, DCELL dHigh,
 
  329                         DCELL rLow, DCELL rHigh)
 
  332         fpreclass_set_limits(r, dLow, dHigh, rLow, rHigh);
 
  336     r->dMin = 
MIN(r->dMin, 
MIN(dLow, dHigh));
 
  337     r->dMax = 
MAX(r->dMax, 
MAX(dLow, dHigh));
 
  338     r->rMin = 
MIN(r->rMin, 
MIN(rLow, rHigh));
 
  339     r->rMax = 
MAX(r->rMax, 
MAX(rLow, rHigh));
 
  346                        DCELL * rMin, DCELL * rMax)
 
  352         *dMin = r->defaultDMin;
 
  353         *dMax = r->defaultDMax;
 
  355         if (r->defaultRRuleSet) {
 
  356             *rMin = r->defaultRMin;
 
  357             *rMax = r->defaultRMax;
 
  386                          DCELL * dHigh, DCELL * rLow, DCELL * rHigh)
 
  388     *dLow = r->table[i].dLow;
 
  389     *dHigh = r->table[i].dHigh;
 
  390     *rLow = r->table[i].rLow;
 
  391     *rHigh = r->table[i].rHigh;
 
  396 static void fpreclass_table_increase(
struct FPReclass *r)
 
  398     if (r->nofRules < r->maxNofRules)
 
  401     if (r->maxNofRules == 0) {
 
  403         r->table = (
struct FPReclass_table *)
 
  404             G_malloc(r->maxNofRules * 
sizeof(
struct FPReclass_table));
 
  407         r->maxNofRules += 50;
 
  408         r->table = (
struct FPReclass_table *)
 
  409             G_realloc((
char *)r->table,
 
  410                       r->maxNofRules * 
sizeof(
struct FPReclass_table));
 
  419     r->infiniteDLeft = dLeft;
 
  420     r->infiniteRLeft = c;
 
  421     fpreclass_update_limits(r, dLeft, dLeft, c, c);
 
  422     r->infiniteLeftSet = 1;
 
  431     if (r->infiniteLeftSet == 0)
 
  434     *dLeft = r->infiniteDLeft;
 
  435     *c = r->infiniteRLeft;
 
  445     r->infiniteDRight = dRight;
 
  446     r->infiniteRRight = c;
 
  447     fpreclass_update_limits(r, dRight, dRight, c, c);
 
  448     r->infiniteRightSet = 1;
 
  457     if (r->infiniteRightSet == 0)
 
  460     *dRight = r->infiniteDRight;
 
  461     *c = r->infiniteRRight;
 
  473     struct FPReclass_table *p;
 
  475     fpreclass_table_increase(r);
 
  493     fpreclass_update_limits(r, dLow, dHigh, rLow, rHigh);
 
  502     struct FPReclass_table tmp;
 
  503     struct FPReclass_table *pLeft, *pRight;
 
  506     pRight = &(r->table[r->nofRules - 1]);
 
  508     while (pLeft < pRight) {
 
  509         tmp.dLow = pLeft->dLow;
 
  510         tmp.dHigh = pLeft->dHigh;
 
  511         tmp.rLow = pLeft->rLow;
 
  512         tmp.rHigh = pLeft->rHigh;
 
  514         pLeft->dLow = pRight->dLow;
 
  515         pLeft->dHigh = pRight->dHigh;
 
  516         pLeft->rLow = pRight->rLow;
 
  517         pLeft->rHigh = pRight->rHigh;
 
  519         pRight->dLow = tmp.dLow;
 
  520         pRight->dHigh = tmp.dHigh;
 
  521         pRight->rLow = tmp.rLow;
 
  522         pRight->rHigh = tmp.rHigh;
 
  532 fpreclass_interpolate(DCELL dLow, DCELL dHigh, DCELL rLow, DCELL rHigh,
 
  540     return ((dValue - dLow) / (dHigh - dLow) * (rHigh - rLow) + rLow);
 
  546 fpreclass_get_default_cell_value(
const struct FPReclass *r, DCELL cellVal)
 
  552     if ((cellVal < 
MIN(r->defaultDMin, r->defaultDMax)) ||
 
  553         (cellVal > 
MAX(r->defaultDMin, r->defaultDMax)))
 
  556     if (r->defaultRRuleSet)
 
  557         return fpreclass_interpolate(r->defaultDMin, r->defaultDMax,
 
  558                                      r->defaultRMin, r->defaultRMax, cellVal);
 
  560         return fpreclass_interpolate(r->defaultDMin, r->defaultDMax,
 
  569     const struct FPReclass_table *p;
 
  576         return fpreclass_get_default_cell_value(r, cellVal);
 
  580         for (p = &(r->table[r->nofRules - 1]); p >= r->table; p--)
 
  581             if ((cellVal >= p->dLow) && (cellVal <= p->dHigh))
 
  582                 return fpreclass_interpolate(p->dLow, p->dHigh, p->rLow,
 
  586         return r->infiniteRLeft;
 
  591     return r->infiniteRRight;
 
  602     for (i = 0; i < 
n; i++, dcell++)
 
  617     for (i = 0; i < 
n; i++, dcell++)
 
  632     for (i = 0; i < 
n; i++, dcell++)
 
  647     for (i = 0; i < 
n; i++, fcell++)
 
  662     for (i = 0; i < 
n; i++, fcell++)
 
  677     for (i = 0; i < 
n; i++, fcell++)
 
  692     for (i = 0; i < 
n; i++, icell++)
 
  707     for (i = 0; i < 
n; i++, icell++)
 
  722     for (i = 0; i < 
n; i++, icell++)
 
int G_is_c_null_value(const CELL *cellVal)
Returns 1 if cell is NULL, 0 otherwise. This will test if the value cell is the largest int...
 
void G_free(void *buf)
Free allocated memory. 
 
void G_fpreclass_perform_fi(const struct FPReclass *r, const FCELL *fcell, CELL *cell, int n)
 
int G_fpreclass_init(struct FPReclass *r)
 
#define NO_LEFT_INFINITE_RULE
 
void G_fpreclass_add_rule(struct FPReclass *r, DCELL dLow, DCELL dHigh, DCELL rLow, DCELL rHigh)
 
void G_set_d_null_value(DCELL *dcellVals, int numVals)
 
void G_fpreclass_perform_di(const struct FPReclass *r, const DCELL *dcell, CELL *cell, int n)
 
void G_fpreclass_perform_id(const struct FPReclass *r, const CELL *icell, DCELL *cell, int n)
 
void G_fpreclass_set_domain(struct FPReclass *r, DCELL dLow, DCELL dHigh)
 
void G_fpreclass_reset(struct FPReclass *r)
 
void G_fpreclass_perform_if(const struct FPReclass *r, const CELL *icell, FCELL *cell, int n)
 
int G_fpreclass_get_pos_infinite_rule(const struct FPReclass *r, DCELL *dRight, DCELL *c)
 
void G_fpreclass_set_pos_infinite_rule(struct FPReclass *r, DCELL dRight, DCELL c)
 
int G_fpreclass_get_limits(const struct FPReclass *r, DCELL *dMin, DCELL *dMax, DCELL *rMin, DCELL *rMax)
 
int G_is_d_null_value(const DCELL *dcellVal)
Returns 1 if dcell is NULL, 0 otherwise. This will test if the value dcell is a NaN. Same test as in G_is_f_null_value(). 
 
int G_is_f_null_value(const FCELL *fcellVal)
Returns 1 if fcell is NULL, 0 otherwise. This will test if the value fcell is a NaN. It isn't good enough to test for a particular NaN bit pattern since the machine code may change this bit pattern to a different NaN. The test will be. 
 
void G_fpreclass_perform_dd(const struct FPReclass *r, const DCELL *dcell, DCELL *cell, int n)
 
DCELL G_fpreclass_get_cell_value(const struct FPReclass *r, DCELL cellVal)
 
void G_fpreclass_perform_fd(const struct FPReclass *r, const FCELL *fcell, DCELL *cell, int n)
 
int G_fpreclass_get_neg_infinite_rule(const struct FPReclass *r, DCELL *dLeft, DCELL *c)
 
void G_fpreclass_get_ith_rule(const struct FPReclass *r, int i, DCELL *dLow, DCELL *dHigh, DCELL *rLow, DCELL *rHigh)
 
void G_fpreclass_perform_ii(const struct FPReclass *r, const CELL *icell, CELL *cell, int n)
 
void G_fpreclass_clear(struct FPReclass *r)
 
void G_set_f_null_value(FCELL *fcellVals, int numVals)
 
int G_fpreclass_nof_rules(const struct FPReclass *r)
 
void G_fpreclass_set_neg_infinite_rule(struct FPReclass *r, DCELL dLeft, DCELL c)
 
void G_fpreclass_reverse_rule_order(struct FPReclass *r)
 
void G_fpreclass_perform_df(const struct FPReclass *r, const DCELL *dcell, FCELL *cell, int n)
 
void G_set_c_null_value(CELL *cellVals, int numVals)
 
void G_fpreclass_perform_ff(const struct FPReclass *r, const FCELL *fcell, FCELL *cell, int n)
 
void G_fpreclass_set_range(struct FPReclass *r, DCELL low, DCELL high)
 
#define NO_RIGHT_INFINITE_RULE