123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- /****************************************************************************
- *
- * MODULE: r.terraflow
- *
- * COPYRIGHT (C) 2007 Laura Toma
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- *****************************************************************************/
- #ifndef _types_H
- #define _types_H
- #include <limits.h>
- #include <iostream>
- /* input parameters type */
- /* ------------------------------------------------------------ */
- typedef int dimension_type; /* represent dimension of the grid */
- static const dimension_type dimension_type_max=INT_MAX;
- typedef short direction_type; /* represent the direction of a cell */
- static const direction_type DIRECTION_UNDEF=-1;
- /* one of these options must be defined at compile time */
- /* #define ELEV_SHORT */
- /* #define ELEV_FLOAT */
- #if (!defined ELEV_SHORT && !defined ELEV_FLOAT)
- #error Must define ELEVATION TYPE
- #endif
- #ifdef ELEV_SHORT
- typedef short elevation_type; /* represent the elevation of a cell */
- static const elevation_type elevation_type_max = SHRT_MAX;
- #endif
- #ifdef ELEV_FLOAT
- typedef float elevation_type; /* represent the elevation of a cell */
- static const elevation_type elevation_type_max = 1e+15;
- #endif
- /* static const elevation_type ELEVATION_UNDEF=SHRT_MAX;
- static const elevation_type ELEVATION_MIN=SHRT_MIN;
- also see nodata.H for ELEVATION_BOUNDARY and ELEVATION_NODATA
- */
- /* represent the topological rank of a cell */
- typedef int toporank_type;
- /* output parameter types */
- /* ------------------------------------------------------------ */
- typedef float flowaccumulation_type;
- static const flowaccumulation_type MAX_ACCU = 1e+15;
- typedef float tci_type;
- typedef int cclabel_type;
- #define CCLABEL_FMT "%3d"
- /* the following are not arbitrary. LABEL_UNDEF should be the
- * most-negative value */
- static const cclabel_type LABEL_UNDEF=-1;
- static const cclabel_type LABEL_BOUNDARY=0;
- static const cclabel_type LABEL_NODATA=1;
- static const cclabel_type LABEL_START=1; /* the next label will be used */
- typedef int bfs_depth_type;
- static const bfs_depth_type DEPTH_INITIAL=1;
- #define IS_BOUNDARY(i,j,nr,nc) (((i)==0) || ((i)==((nr)-1)) || \
- ((j)==0) || ((j)==((nc)-1)))
- /* ---------------------------------------------------------------------- */
- class labelFactory {
- protected:
- static cclabel_type label;
- public:
- static cclabel_type getNewLabel() { return ++label; }
- static cclabel_type getCurrentLabel() { return label; }
- static const cclabel_type getLabelInit() {
- return cclabel_type(LABEL_START);
- }
- static const cclabel_type getLabelCount() {
- return label+1;
- }
- static void setLabelCount(int n) {
- label = n-1;
- }
- static void reset() { label = getLabelInit(); }
- };
- /* ---------------------------------------------------------------------- */
- class ijBaseType {
- public:
- dimension_type i,j;
- ijBaseType() : i(-1), j(-1) {};
- ijBaseType(dimension_type gi, dimension_type gj) : i(gi), j(gj) {};
- friend int operator==(const ijBaseType &a, const ijBaseType &b) {
- return (compare(a,b) == 0);
- }
- friend int operator!=(const ijBaseType &a, const ijBaseType &b) {
- return (compare(a,b) != 0);
- }
- friend std::ostream& operator << (std::ostream& s, const ijBaseType &p);
- static int compare(const ijBaseType &a, const ijBaseType &b);
- };
- #define SHALLOW_OP_EQ(_cls) \
- friend int \
- operator==(const _cls &a, const _cls &b) { \
- const int n = sizeof(_cls); \
- const char *ap = (const char *)&a; \
- const char *bp = (const char *)&b; \
- for(int i=0; i<n; i++) { \
- if(ap[i] != bp[i]) return 0; \
- } \
- return 1; \
- }
- #endif
|