FFSM++  1.1.0
French Forest Sector Model ++
Layers.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2015 by Laboratoire d'Economie Forestière *
3  * http://ffsm-project.org *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version, given the compliance with the *
9  * exceptions listed in the file COPYING that is distribued together *
10  * with this file. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  ***************************************************************************/
22 #ifndef LAYERS_H
23 #define LAYERS_H
24 #include <string>
25 #include <vector>
26 #include <stdexcept>
27 #include <iostream>
28 #include <sstream>
29 
30 #include <QColor>
31 
32 // regmas headers...
33 #include "BaseClass.h"
34 
35 using namespace std;
36 
37 struct LegendItems;
38 struct ReclassRules;
39 
40 /// Define layer objects at the regional level
41 /**
42 Layer class (setting, legend...)
43 <br>This class define layer objects, including:
44  - a set of layer proprieties (name(ID), label, associated dataset, typology (integer or double)
45  - a vector of legend items, associating one color to each value or interval
46  - a vector of reclassification rule, when we need to work with a level of depth different of those coming with the dataset
47 @author Antonello Lobianco <antonello@regmas.org>
48 */
49 class Layers : public BaseClass{
50 
51 public:
52  /// In the constructor we set the main layer properties
53  Layers( ThreadManager* MTHREAD_h,
54  string name_h,
55  string label_h,
56  bool isInteger_h,
57  bool dynamicContent_h,
58  string fullFilename_h,
59  bool display_h=true);
60  ~Layers();
61  /// Add a legend item. @see LegendItems
62  void addLegendItem( int ID_h,
63  string label_h,
64  int rColor_h,
65  int gColor_h,
66  int bColor_h,
67  double minValue_h,
68  double maxValue_h );
69  void addLegendItems(vector <LegendItems> legendItems_h);
70  vector<LegendItems> getLegendItems(){return legendItems;};
71 
72  /// Evaluates all the legend items to find the one that match the input code, and return its color as a QColor
73  QColor getColor(double ID_h);
74  /// Evaluates all the legend items to find the one that match the input code, and return its label
75  string getCategory(double ID_h);
76  /// Used to reclassify the land use map for "generic" categories
77  double filterExogenousDataset(double code_h);
78  /// Count the pixels going to each legend item and print them if debug==true
79  void countMyPixels(bool debug=false);
80  /// For some sensitivity analisys, random the values for this layer for not-empty values (only integer layers)
81  void randomShuffle();
82  /// Return if the layer is integer or not (If integer on each legend item: minValue==maxValue==ID)
83  bool getIsInteger() {return isInteger;}
84  /// Print the layer content as an ASCII grid map with its companion files (classification and colors). It always print the whole region, even when subregion is actived.
85  void print();
86  /// Print a binary reppresentation of the data (a standard image, e.g. a .png file). It prints only the subregion if this is active.
87  void printBinMap();
88 
89  string getName() const {return name;}
90  /// Return the filename of the associated dataset
91  string getFilename(){return fullFileName;}
92  /// Return true if the content may change during simulation period
93  bool getDynamicContent(){return dynamicContent;}
94  bool getDisplay(){return display;}
95 
96 
97 private:
98  string name; ///< ID of the layer (no spaces allowed)
99  string label; ///< Label of the layer (spaces allowed)
100  bool isInteger; ///< Type of the layer (true==integer, false==double. If true, on each legend item: minValue==maxValue==ID)
101  bool dynamicContent; ///< True if the content may change during simulation year
102  bool display; ///< Normally true, but some layers used to just keep data shoudn't be normally processed
103  string fullFileName; ///< Filename of the associated dataset (map)
104  vector<LegendItems> legendItems; ///< Vector of legend items. @see LegendItems
105  vector<ReclassRules> reclassRulesVector; ///< Vector of initial reclassification rules. @see ReclassRules
106 };
107 
108 /// Legend items
109 
110 /**
111 Struct containing data about the programm settings.
112 <br>The minValue and the maxValue are used to compare one record value and return the right color. If the layer is of type integer (isInteger==true), minValue==maxValue==ID.
113 @author Antonello Lobianco
114 */
115 struct LegendItems {
116  int ID;
117  string label;
118  int rColor;
119  int gColor;
120  int bColor;
121  double minValue;
122  double maxValue;
123  int cashedCount; ///< count the pixels whitin a item range
124 };
125 
126 /// Initial reclassification rules (dataset filters)
127 
128 /**
129 A structure for easy reclassification of "mixed" categories in some layers.
130 <br>The reclassification can be made to both <i>increase</i> depth or <i>decrease</i> depth to the original dataset.
131 <br>Eg, if in our model we don't differ between coniferous and hardwood forests, we can set all them to be "forest".
132 <br>At the opposite, if our model require more detail than the map provide, e.g. irrigable arable VS dry arable, we can set the generic "arable land" of becoming "arable" or "dry" according with a regional-defined probability (getted from other sources, e.g. census data).
133 @author Antonello Lobianco
134 */
136  int inCode;
137  int outCode;
138  /// Probability that one pixel of code inCode will become of code outCode. 1 for fixed transformation.
139  double p;
140 };
141 
142 #endif
vector< LegendItems > getLegendItems()
Definition: Layers.h:70
int inCode
Definition: Layers.h:136
string label
Label of the layer (spaces allowed)
Definition: Layers.h:99
string name
ID of the layer (no spaces allowed)
Definition: Layers.h:98
vector< LegendItems > legendItems
Vector of legend items.
Definition: Layers.h:104
double maxValue
Definition: Layers.h:122
bool isInteger
Type of the layer (true==integer, false==double. If true, on each legend item: minValue==maxValue==ID...
Definition: Layers.h:100
STL namespace.
Thread manager. Responsable to manage the main thread and "speak" with the GUI.
Definition: ThreadManager.h:65
bool getDisplay()
Definition: Layers.h:94
string fullFileName
Filename of the associated dataset (map)
Definition: Layers.h:103
string getFilename()
Return the filename of the associated dataset.
Definition: Layers.h:91
string getName() const
Definition: Layers.h:89
Define layer objects at the regional level.
Definition: Layers.h:49
Legend items.
Definition: Layers.h:115
int bColor
Definition: Layers.h:120
int ID
Definition: Layers.h:116
double minValue
Definition: Layers.h:121
int gColor
Definition: Layers.h:119
int outCode
Definition: Layers.h:137
Initial reclassification rules (dataset filters)
Definition: Layers.h:135
Base class for the regmas application.
Definition: BaseClass.h:239
double p
Probability that one pixel of code inCode will become of code outCode. 1 for fixed transformation...
Definition: Layers.h:139
int cashedCount
count the pixels whitin a item range
Definition: Layers.h:123
bool getDynamicContent()
Return true if the content may change during simulation period.
Definition: Layers.h:93
string label
Definition: Layers.h:117
bool getIsInteger()
Return if the layer is integer or not (If integer on each legend item: minValue==maxValue==ID) ...
Definition: Layers.h:83
vector< ReclassRules > reclassRulesVector
Vector of initial reclassification rules.
Definition: Layers.h:105
This file is the header of BaseClass and it is included by ALL compiled code.
bool display
Normally true, but some layers used to just keep data shoudn&#39;t be normally processed.
Definition: Layers.h:102
int rColor
Definition: Layers.h:118
bool dynamicContent
True if the content may change during simulation year.
Definition: Layers.h:101