openModeller  Version 1.5.0
Environment.hh
Go to the documentation of this file.
1 
29 #ifndef _ENVIRONMENTHH_
30 #define _ENVIRONMENTHH_
31 
32 #include <openmodeller/om_defs.hh>
33 #include <openmodeller/refcount.hh>
37 #include <openmodeller/Sample.hh>
38 
39 #include <vector>
40 #include <string>
41 #include <utility>
42 
43 class Map;
44 class SampledData;
45 
49 
50 /****************************************************************/
51 /************************* Environment **************************/
52 
53 EnvironmentPtr dllexp createEnvironment( const std::vector<std::string>& categs,
54  const std::vector<std::string>& maps,
55  const std::string& mask_file );
56 
57 EnvironmentPtr dllexp createEnvironment( const std::vector<std::string>& categs,
58  const std::vector<std::string>& maps );
59 
61 
63 
64 
69 class dllexp EnvironmentImpl : public Configurable, public Normalizable, private ReferenceCountedObject
70 {
73 
74  friend EnvironmentPtr dllexp createEnvironment( const std::vector<std::string>& categs,
75  const std::vector<std::string>& maps,
76  const std::string& mask_file );
77 
78  friend EnvironmentPtr dllexp createEnvironment( const std::vector<std::string>& categs,
79  const std::vector<std::string>& maps );
80 
81  friend EnvironmentPtr dllexp createEnvironment( const ConstConfigurationPtr& config );
82 
83  friend EnvironmentPtr dllexp createEnvironment( );
84 
85  typedef std::pair<std::string, Map*> layer;
86  typedef std::vector<layer> layers;
87 
89 
97  EnvironmentImpl( const std::vector<std::string>& categs,
98  const std::vector<std::string>& maps,
99  const std::string& mask_file = "" );
100 
101 public:
102 
103  ~EnvironmentImpl();
104 
106  EnvironmentImpl* clone() const;
107 
108  unsigned int numLayers() const { return _layers.size(); }
109 
110  size_t numCategoricalLayers() const;
111 
115  int isCategorical( int i );
116 
120  void getMinMax( Sample * min, Sample * max ) const;
121 
124  void normalize( Normalizer * normalizerPtr );
125 
128  void resetNormalization();
129 
137  Sample get( Coord x, Coord y ) const;
138 
139  Sample getNormalized( Coord x, Coord y ) const;
140  Sample getUnnormalized( Coord x, Coord y ) const;
141 
148  Sample getRandom( Coord *x = 0, Coord *y = 0 ) const;
149 
152  int checkCoordinates( Coord x, Coord y ) const;
153 
156  int getRegion( Coord *xmin, Coord *ymin, Coord *xmax,
157  Coord *ymax ) const;
158 
163  int getExtremes( Sample* min, Sample* max ) const;
164 
165  Map * getLayer(int index) const { return _layers[index].second; }
166 
168  int changeMask( const std::string& mask_file );
169 
170  Map * getMask() const { return _mask.second; }
171 
172  const std::string& getLayerPath(int index) const { return _layers[index].first; }
173 
174  const std::string& getMaskPath() const { return _mask.first; }
175 
176  void removeLayer(unsigned int index);
177 
178  virtual ConfigurationPtr getConfiguration() const;
179 
180  virtual void setConfiguration( const ConstConfigurationPtr & );
181 
182 private:
183 
184  void initialize( const std::vector<std::string>& categs,
185  const std::vector<std::string>& maps,
186  const std::string& mask_file="" );
187 
188  /* utility function to extract unnormalized environment vector
189  * Only needed to prevent unnecessary memory copy due to Sample
190  * not having a reasonable copy constructor/temporary
191  */
192  void getUnnormalizedInternal( Sample *, Coord x, Coord y ) const;
193 
194  /* utility to clear the mask information. Deallocates memory. Does not computeRegion() */
195  void clearMask();
196 
197  /* utility to clear the layer information, deallocates memory. Does not computeRegion() */
198  void clearLayers();
199 
200  /* utility to construct a ConfigurationPtr representation of a Layer.
201  Does not properly set the Configuration name.
202  Is a member function so it can access the private typedefs. */
203  static ConfigurationPtr getLayerConfig( const layer& l, bool basicConfig=false );
204 
205  /* load specified layers. Zeros in map_refs are populated with Map instances based on the
206  corresponding ids in the other vector */
207  static void loadLayers( const std::vector<std::string>& map_ids, std::vector<Map*>& map_refs, int categ=0 );
208 
209  /* utility to construct a layer pair object.
210  It is declared a member so it has access to the private typedef for layer */
211  static layer makeLayer( const ConstConfigurationPtr& config, Map *map );
212  static layer makeLayer( const std::string& filename, int categ );
213  static layer makeLayer( const std::string& filename, Map *map );
214 
216  int changeLayers( const std::vector<std::string>& categs,
217  const std::vector<std::string>& maps );
218 
220  void calcRegion();
221 
224 
229 
231 };
232 
233 
234 #endif
Normalizer * _normalizerPtr
Normalize the environment.
Definition: Environment.hh:230
virtual ConfigurationPtr getConfiguration() const =0
std::pair< std::string, Map * > layer
Definition: Environment.hh:85
unsigned int numLayers() const
Definition: Environment.hh:108
const std::string & getLayerPath(int index) const
Definition: Environment.hh:172
const std::string & getMaskPath() const
Definition: Environment.hh:174
Coord _xmin
Intersection of all layers.
Definition: Environment.hh:225
Coord _ymax
Intersection of all layers.
Definition: Environment.hh:228
Map * getLayer(int index) const
Definition: Environment.hh:165
Coord _xmax
Intersection of all layers.
Definition: Environment.hh:227
Coord _ymin
Intersection of all layers.
Definition: Environment.hh:226
EnvironmentPtr dllexp createEnvironment(const std::vector< std::string > &categs, const std::vector< std::string > &maps, const std::string &mask_file)
Definition: Environment.cpp:55
Definition: Map.hh:49
virtual void getMinMax(Sample *min, Sample *max) const =0
ReferenceCountedPointer< const EnvironmentImpl > ConstEnvironmentPtr
Definition: Environment.hh:48
ReferenceCountedPointer< EnvironmentImpl > EnvironmentPtr
Definition: Environment.hh:46
std::vector< layer > layers
Definition: Environment.hh:86
virtual void setConfiguration(const ConstConfigurationPtr &)=0
virtual void normalize(Normalizer *normalizerPtr)=0
double Coord
Type of map coordinates.
Definition: om_defs.hh:38
Map * getMask() const
Definition: Environment.hh:170
layer _mask
Mask (can be 0).
Definition: Environment.hh:223
layers _layers
Vector with all layers that describe the variables.
Definition: Environment.hh:222
int min(int v1, int v2)
Definition: rules_base.cpp:56
Definition: Sample.hh:25