/*------------------------------------------------------------------------------ SMS3 classes Landscape and Square These classes define the landscape on which animals move in SMS. Each square within the landscape has a 'cost' value (in the sense of the Least Cost Path approach, i.e. it can be a true cost, or a resistance to movement) and a 'target' attribute, which identifies it as being part of a habitat patch (in the metapopulation sense) in which an animal may terminate its path through the landscape. Optionally, squares may also have a 'source' attribute to identify source patches, but this attribute is not used in the current implementation. Costs, target and (optionally) source data are read from text files in ArcGIS raster export format. Such files have 6 header records, and from the header records of the costs file, SMS determines the X and Y dimensions of the landscape, the origin and the cell size (which must be identical for all files). Author: Steve Palmer, University of Aberdeen Last updated: 1 May 2012 ------------------------------------------------------------------------------*/ #ifndef LandscapeH #define LandscapeH #include #include #include #include #include #include #include using namespace std; #include "Parameters.h" struct locn { int x; int y; }; struct costs { int F; int G; int H; }; struct lcpath { double length; double cumcost; }; struct array3x3d { double cell[3][3]; }; struct array3x3f { float cell[3][3]; }; class Square { public: Square(int,int); // default constructor locn get_locn(void); int get_cost(void); #if READSOURCE int get_source(void); #endif int get_target(void); int get_visits(void); array3x3d get_effcosts(void); void set_cost(int); void set_attributes(int,int,int); void inc_visits(void); void reset_visits(int); Square* get_parent(void); void set_effcosts(array3x3d); private: locn sq; int cost; #if READSOURCE int source; #endif int target; int visits; // no. of times square is visited by animal(s) // NOTE: when an animal has visited a square and incremented the visit count, // the count is made negative to prevent that animal from making repeat increments array3x3f effcost; // retained calulated effective costs }; class Landscape { public: Landscape(); // Landscape class constructor ~Landscape(); // Landscape class destructor int ReadLandscape( // Read landscape data from text files in ArcGIS raster export format char*, // pointer to costs file char*, // pointer to target file char* // pointer to source file - ALWAYS set to "null" - this option // is not implemented in this version ); void WriteLandFile( // Write landscape data to file int, // type of file to write: // 1 = costs, 2 = source cell, 3 = target cells, 4 = visits // NOTE: 1, 2 and 3 are essentially pointless other than as a check that // data were read correctly into the landscape int // file number ); int get_id(void); locn get_bounds(void); locn get_origin(void); locn get_XYmax(void); int get_cellsize(void); Square* locate_square(int,int); // X and Y co-ordinates of square to be located void ResetEffCosts(void); void ResetVisits( int // if 0, landscape visit counts are reset to zero // otherwise, visit counts are set back to positive if negative ); void draw_landscape(int,int,int,int); // declaration of function used by GUI version only int get_costcolour(int); protected: int xmax; // Landscape size x ) - will be set from cost grid file int ymax; // Landscape size y ) std::vector Squares; private: static int LandCounter; // used to create ID, held by class not members of class int id; int Xorigin,Yorigin; // used to hold the co-ordinates of the landscape origin int cellsize; // cell size as specified in the costs file // parallel vectors for storing unique costs and matching colour values std::vector colours; std::vector costs; }; //--------------------------------------------------------------------------- #endif