GRASS GIS 7 Programmer's Manual
7.9.dev(2021)0c200d663

Raster Library  Quantization rules. More...
#include <stdlib.h>
#include <grass/gis.h>
#include <grass/raster.h>
Go to the source code of this file.
Macros  
#define  USE_LOOKUP 1 
#define  MAX_LOOKUP_TABLE_SIZE 2048 
#define  NO_DATA (Rast_set_c_null_value (&tmp, 1), (CELL) tmp) 
#define  MIN(a, b) ((a) < (b) ? (a) : (b)) 
#define  MAX(a, b) ((a) > (b) ? (a) : (b)) 
#define  NO_LEFT_INFINITE_RULE (! q>infiniteLeftSet) 
#define  NO_RIGHT_INFINITE_RULE (! q>infiniteRightSet) 
#define  NO_FINITE_RULE (q>nofRules <= 0) 
#define  NO_EXPLICIT_RULE 
Functions  
void  Rast_quant_clear (struct Quant *q) 
Resets the number of defined rules and number of infinite rules to 0. More...  
void  Rast_quant_free (struct Quant *q) 
Resets and frees allocated memory. More...  
int  Rast__quant_organize_fp_lookup (struct Quant *q) 
Organized fp_lookup table. More...  
void  Rast_quant_init (struct Quant *quant) 
Initialize the structure. More...  
int  Rast_quant_is_truncate (const struct Quant *quant) 
Returns whether or not quant rules are set to truncate map. More...  
int  Rast_quant_is_round (const struct Quant *quant) 
Returns whether or not quant rules are set to round map. More...  
void  Rast_quant_truncate (struct Quant *quant) 
Sets the quant rules to perform simple truncation on floats. More...  
void  Rast_quant_round (struct Quant *quant) 
Sets the quant rules to perform simple rounding on floats. More...  
int  Rast_quant_get_limits (const struct Quant *q, DCELL *dMin, DCELL *dMax, CELL *cMin, CELL *cMax) 
Returns the minimum and maximum cell and dcell values of all the ranges defined. More...  
int  Rast_quant_nof_rules (const struct Quant *q) 
Returns the number of quantization rules defined. More...  
void  Rast_quant_get_ith_rule (const struct Quant *q, int i, DCELL *dLow, DCELL *dHigh, CELL *cLow, CELL *cHigh) 
Returns the i'th quantization rule. More...  
void  Rast_quant_set_neg_infinite_rule (struct Quant *q, DCELL dLeft, CELL c) 
Defines a rule for values "dLeft" and smaller. More...  
int  Rast_quant_get_neg_infinite_rule (const struct Quant *q, DCELL *dLeft, CELL *c) 
Returns in "dLeft" and "c" the rule values. More...  
void  Rast_quant_set_pos_infinite_rule (struct Quant *q, DCELL dRight, CELL c) 
Defines a rule for values "dRight" and larger. More...  
int  Rast_quant_get_pos_infinite_rule (const struct Quant *q, DCELL *dRight, CELL *c) 
Returns in "dRight" and "c" the rule values. More...  
void  Rast_quant_add_rule (struct Quant *q, DCELL dLow, DCELL dHigh, CELL cLow, CELL cHigh) 
Adds a new rule to the set of quantization rules. More...  
void  Rast_quant_reverse_rule_order (struct Quant *q) 
Rreverses the order in which the qunatization rules are stored. More...  
CELL  Rast_quant_get_cell_value (struct Quant *q, DCELL dcellVal) 
Returns a CELL category for the floatingpoint value based on the quantization rules in q. The first rule found that applies is used. The rules are searched in the reverse order they are added to q. If no rule is found, the value is first tested against the negative infinite rule, and finally against the positive infinite rule. If none of these rules apply, the NULLvalue is returned. More...  
void  Rast_quant_perform_d (struct Quant *q, const DCELL *dcell, CELL *cell, int n) 
Returns in "cell" the quantized CELL values. More...  
void  Rast_quant_perform_f (struct Quant *q, const FCELL *fcell, CELL *cell, int n) 
Same as Rast_quant_perform_d(), except the type. More...  
struct Quant_table *  Rast__quant_get_rule_for_d_raster_val (const struct Quant *q, DCELL val) 
Returns quant rule which will be applied. More...  
Raster Library  Quantization rules.
The quantization table is stored as a linear array. Rules are added starting from index 0. Redundant rules are not eliminated. Rules are tested from the highest index downto 0. There are two "infinite" rules. Support is provided to reverse the order of the rules.
(C) 19992009 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.
Definition in file quant.c.
#define NO_DATA (Rast_set_c_null_value (&tmp, 1), (CELL) tmp) 
#define NO_EXPLICIT_RULE 
Definition at line 38 of file quant.c.
Referenced by Rast_quant_get_limits().
struct Quant_table* Rast__quant_get_rule_for_d_raster_val  (  const struct Quant *  q, 
DCELL  val  
) 
Returns quant rule which will be applied.
Returns quant rule which will be applied when looking up the integer quant value for val (used when organizing fp_lookup).
q  pointer to Quant structure which holds quant rules info 
val  fp cell value 
Definition at line 780 of file quant.c.
References Quant_table::dHigh, Quant_table::dLow, Quant::nofRules, NULL, and Quant::table.
int Rast__quant_organize_fp_lookup  (  struct Quant *  q  ) 
Organized fp_lookup table.
Organizes fp_lookup table for faster (logarithmic) lookup time G_quant_organize_fp_lookup() creates a list of min and max for each quant rule, sorts this list, and stores the pointer to quant rule that should be used inbetween any 2 numbers in this list. Also it stores extreme points for 2 infinite rules, if exist. After the call to G_quant_organize_fp_lookup() instead of linearly searching through list of rules to find a rule to apply, quant lookup will perform a binary search to find an interval containing floating point value, and then use the rule associated with this interval. when the value doesn't fall within any interval, check for the infinite rules.
q  pointer to Quant structure which holds quant rules info 
Adds a new rule to the set of quantization rules.
If dLow < dHigh the rule will be stored with the low and high values interchanged.
Note: currently no cleanup of rules is performed, i.e. redundant rules are not removed. This can't be changed because Categories structure HEAVILY depends of quant rules stored in exactly the same order they are entered. So if the cleanup or rearrangement is done in the future make a flag for add_rule whether or not to do it, then quant will not set this flag.
q  pointer to Quant structure which holds quant rules info 
dLow  minimum fp value 
dHigh  maximum fp value 
cLow  minimum value 
cHigh  maximum value 
Definition at line 478 of file quant.c.
Referenced by Rast_quantize_fp_map_range(), Rast_set_d_cat(), and Rast_set_quant_rules().
void Rast_quant_clear  (  struct Quant *  q  ) 
Resets the number of defined rules and number of infinite rules to 0.
q  pointer to Quant structure to be reset 
Definition at line 46 of file quant.c.
References Quant::infiniteLeftSet, Quant::infiniteRightSet, and Quant::nofRules.
Referenced by Rast_quant_free(), and Rast_quant_init().
void Rast_quant_free  (  struct Quant *  q  ) 
Resets and frees allocated memory.
Resets the number of defined rules to 0 and free's space allocated for rules. Calls Rast_quant_clear().
q  pointer to Quant structure to be reset 
Definition at line 60 of file quant.c.
References Quant::active, Quant::fp_lookup, G_free(), Quant::maxNofRules, Quant::nalloc, Rast_quant_clear(), Quant::rules, Quant::table, and Quant::vals.
Referenced by Rast__quant_import(), and Rast_free_cats().
Returns a CELL category for the floatingpoint value based on the quantization rules in q. The first rule found that applies is used. The rules are searched in the reverse order they are added to q. If no rule is found, the value is first tested against the negative infinite rule, and finally against the positive infinite rule. If none of these rules apply, the NULLvalue is returned.
Note: See G_quant_organize_fp_lookup() for details on how the values are looked up from fp_lookup table when it is active. Right now fp_lookup is automatically organized during the first call to Rast_quant_get_cell_value().
q  pointer to Quant structure which holds quant rules info 
dcellValue  fp cell value 
Definition at line 601 of file quant.c.
Referenced by Rast_quant_perform_d(), and Rast_quant_perform_f().
void Rast_quant_get_ith_rule  (  const struct Quant *  q, 
int  i,  
DCELL *  dLow,  
DCELL *  dHigh,  
CELL *  cLow,  
CELL *  cHigh  
) 
Returns the i'th quantization rule.
For 0 <= i < Rast_quant_nof_rules(). A larger value for i means that the rule has been added later.
q  pointer to Quant structure which holds quant rules info  
i  index  
[out]  dLow  minimum fp value 
[out]  dHigh  maximum fp value 
[out]  cLow  minimum value 
[out]  cHigh  maximum value 
Definition at line 333 of file quant.c.
References Quant_table::cHigh, Quant_table::cLow, Quant_table::dHigh, Quant_table::dLow, and Quant::table.
Referenced by Rast_get_ith_d_cat().
int Rast_quant_get_limits  (  const struct Quant *  q, 
DCELL *  dMin,  
DCELL *  dMax,  
CELL *  cMin,  
CELL *  cMax  
) 
Returns the minimum and maximum cell and dcell values of all the ranges defined.
Extracts the minimum and maximum floatingpoint and integer values from all the rules (except the "infinite" rules) in q into dmin, dmax, cmin, and cmax.
quant  pointer to Quant structure which holds quant rules info  
[out]  dmin  minimum fp value 
[out]  dmax  maximum fp value 
[out]  cmin  minimum value 
[out]  cmax  maximum value 
Definition at line 286 of file quant.c.
References Quant::cMax, Quant::cMin, Quant::dMax, Quant::dMin, NO_EXPLICIT_RULE, Rast_set_c_null_value(), and Rast_set_d_null_value().
Referenced by Rast_read_range(), and Rast_write_quant().
Returns in "dLeft" and "c" the rule values.
For the negative infinite interval (see Rast_quant_set_neg_infinite_rule()).
q  pointer to Quant structure which holds quant rules info  
[out]  dLeft  fp value 
[out]  c  value 
Definition at line 399 of file quant.c.
Referenced by Rast_set_quant_rules().
Returns in "dRight" and "c" the rule values.
For the positive infinite interval (see Rast_quant_set_pos_infinite_rule()).
q  pointer to Quant structure which holds quant rules info  
[out]  dRight  fp value 
[out]  c  value 
Definition at line 447 of file quant.c.
Referenced by Rast_set_quant_rules().
void Rast_quant_init  (  struct Quant *  quant  ) 
Initialize the structure.
Initializes the q struct.
quant  pointer to Quant structure to be initialized 
Definition at line 179 of file quant.c.
References Quant::active, Quant::fp_lookup, Quant::maxNofRules, Rast_quant_clear(), Quant::round_only, and Quant::truncate_only.
Referenced by Rast_init_cats(), Rast_quantize_fp_map_range(), Rast_read_quant(), Rast_round_fp_map(), Rast_set_quant_rules(), and Rast_truncate_fp_map().
int Rast_quant_is_round  (  const struct Quant *  quant  ) 
Returns whether or not quant rules are set to round map.
quant  pointer to Quant structure which holds quant rules info 
Definition at line 208 of file quant.c.
References Quant::round_only.
Referenced by Rast_read_range().
int Rast_quant_is_truncate  (  const struct Quant *  quant  ) 
Returns whether or not quant rules are set to truncate map.
quant  pointer to Quant structure which holds quant rules info 
Definition at line 196 of file quant.c.
References Quant::truncate_only.
Referenced by Rast_read_range().
int Rast_quant_nof_rules  (  const struct Quant *  q  ) 
Returns the number of quantization rules defined.
This number does not include the 2 infinite intervals.
q  pointer to Quant structure which holds quant rules info 
Definition at line 315 of file quant.c.
References Quant::nofRules.
Referenced by Rast3d_write_cats(), and Rast_get_next_marked_d_cat().
Returns in "cell" the quantized CELL values.
Returns in "cell" the quantized CELL values corresponding to the DCELL values stored in "dcell". the number of elements quantized is n. quantization is performed by repeated application of Rast_quant_get_cell_value().
q  pointer to Quant structure which holds quant rules info  
dcell  pointer to fp cell values array  
[out]  cell  pointer cell values array 
n  number of cells 
Definition at line 721 of file quant.c.
References Rast_is_d_null_value(), Rast_quant_get_cell_value(), and Rast_set_c_null_value().
Same as Rast_quant_perform_d(), except the type.
q  pointer to Quant structure which holds quant rules info  
fcell  pointer to fp cell values array  
[out]  cell  pointer cell values array 
n  number of cells 
Definition at line 741 of file quant.c.
References Rast_is_f_null_value(), Rast_quant_get_cell_value(), and Rast_set_c_null_value().
void Rast_quant_reverse_rule_order  (  struct Quant *  q  ) 
Rreverses the order in which the qunatization rules are stored.
See also Rast_quant_get_ith_rule() and Rast_quant_perform_d()).
q  pointer to Quant rules which holds quant rules info 
Definition at line 522 of file quant.c.
References Quant_table::cHigh, Quant_table::cLow, Quant_table::dHigh, Quant_table::dLow, Quant::nofRules, and Quant::table.
void Rast_quant_round  (  struct Quant *  quant  ) 
Sets the quant rules to perform simple rounding on floats.
Sets the quant for q rules to perform simple rounding on floats.
quant  pointer to Quant structure which holds quant rules info 
Definition at line 234 of file quant.c.
References Quant::round_only.
Referenced by Rast_round_fp_map().
Defines a rule for values "dLeft" and smaller.
Values in this range are mapped to "c" if none of the "finite" quantization rules applies.
q  pointer to Quant structure which holds quant rules info 
dLeft  fp value 
c  value 
Definition at line 373 of file quant.c.
Referenced by Rast_set_quant_rules().
Defines a rule for values "dRight" and larger.
Values in this range are mapped to "c" if none of the "finite" quantization rules or the negative infinite rule applies.
q  pointer to Quant structure which holds quant rules info 
dRight  fp value 
c  value 
Definition at line 421 of file quant.c.
Referenced by Rast_set_quant_rules().
void Rast_quant_truncate  (  struct Quant *  quant  ) 
Sets the quant rules to perform simple truncation on floats.
Sets the quant for q rules to perform simple truncation on floats.
quant  pointer to Quant structure which holds quant rules info 
Definition at line 221 of file quant.c.
References Quant::truncate_only.
Referenced by Rast_set_quant_rules(), and Rast_truncate_fp_map().