41 #if defined (HAVE_VALUES_H) && !defined(WIN32)
45 #define MAXFLOAT FLT_MAX
56 const std::vector<std::string>& maps,
57 const std::string& mask_file )
63 const std::vector<std::string>& maps )
72 env->setConfiguration( config );
91 cfg->addNameValue(
"Id", l.first );
93 if ( ! basicConfig ) {
95 cfg->addNameValue(
"IsCategorical", l.second->isCategorical() );
97 if ( l.second->hasMinMax() ) {
101 l.second->getMinMax( &min, &max );
102 cfg->addNameValue(
"Min", min );
103 cfg->addNameValue(
"Max", max );
113 string filename = config->getAttribute(
"Id" );
123 config->getAttribute(
"Min");
124 config->getAttribute(
"Max");
128 double min = config->getAttributeAsDouble(
"Min", 0.0 );
129 double max = config->getAttributeAsDouble(
"Max", 0.0 );
131 l.second->setMinMax( min, max );
156 Log::instance()->
warn(
"Cannot read environment file: '%s'\n", filename.c_str() );
186 const std::vector<std::string>& maps,
187 const std::string& mask )
194 const std::vector<std::string>& maps,
195 const std::string& mask )
226 std::vector<std::string> categs;
227 std::vector<std::string> maps;
229 layers::const_iterator lay =
_layers.begin();
230 layers::const_iterator end =
_layers.end();
232 while ( lay != end ) {
234 if ( lay->second->isCategorical() ) {
236 categs.push_back( lay->first );
240 maps.push_back( lay->first );
261 layers::iterator first =
_layers.begin();
262 layers::iterator end =
_layers.end();
263 for ( ; first != end; ++ first ) {
264 delete (*first).second;
286 config->addNameValue(
"NumLayers", (
int)
_layers.size() );
288 layers::const_iterator l =
_layers.begin();
289 layers::const_iterator end =
_layers.end();
291 for( ; l != end; ++l ) {
295 config->addSubsection( cfg );
298 if (
_mask.second ) {
300 bool onlyBasicConfig =
true;
302 maskcfg->setName(
"Mask" );
303 config->addSubsection( maskcfg );
319 std::vector<ConstConfigurationPtr> categ_layer_confs;
320 std::vector<ConstConfigurationPtr> cont_layer_confs;
324 std::vector<string> categ_layer_ids;
325 std::vector<Map*> categ_layer_refs;
326 std::vector<string> cont_layer_ids;
327 std::vector<Map*> cont_layer_refs;
331 std::vector<string> mask_id;
332 std::vector<Map*> mask_ref;
336 Configuration::subsection_list::const_iterator it = subs.begin();
337 while( it != subs.end() ) {
339 string subname = (*it)->getName();
340 string id = (*it)->getAttribute(
"Id");
342 if ( subname ==
"Mask" && mask_id.size() == 0 ) {
346 mask_id.push_back(
id);
347 mask_ref.push_back(0);
353 int categ = (*it)->getAttributeAsInt(
"IsCategorical", 0 );
357 cont_layer_ids.push_back(
id);
358 cont_layer_refs.push_back(0);
360 cont_layer_confs.push_back(lconf);
364 categ_layer_ids.push_back(
id);
365 categ_layer_refs.push_back(0);
367 categ_layer_confs.push_back(lconf);
374 loadLayers( categ_layer_ids, categ_layer_refs, 1 );
375 loadLayers( cont_layer_ids, cont_layer_refs, 0 );
378 for(
unsigned int i = 0; i< categ_layer_confs.size(); i++ ) {
382 _layers.push_back(
makeLayer( categ_layer_confs[i], categ_layer_refs[i] ) );
385 for(
unsigned int i = 0; i< cont_layer_confs.size(); i++ ) {
393 if ( mask_id.size() ) {
407 bool unfinished_loading =
true;
408 bool got_one =
false;
410 while ( unfinished_loading ) {
412 unfinished_loading =
false;
415 for(
unsigned int i = 0; i< map_ids.size(); i++ ) {
417 if ( map_refs[i] == 0 ) {
430 unfinished_loading =
true;
440 if ( unfinished_loading && !got_one ) {
451 const std::vector<std::string>& maps )
453 if ( ! (categs.size() + maps.size()) )
461 std::vector<Map*> categ_layer_refs;
462 for(
unsigned int i = 0; i< categs.size(); i++ ) {
464 categ_layer_refs.push_back(0);
470 std::vector<Map*> cont_layer_refs;
471 for(
unsigned int i = 0; i< maps.size(); i++ ) {
473 cont_layer_refs.push_back(0);
479 for(
unsigned int i = 0; i< categs.size(); i++ ) {
484 for(
unsigned int i = 0; i< maps.size(); i++ ) {
491 return categs.size() + maps.size();
505 if ( !mask_file.empty() ) {
507 bool unfinished_loading =
true;
509 while ( unfinished_loading ) {
511 unfinished_loading =
false;
522 unfinished_loading =
true;
532 if ( !
_mask.second ) {
551 layers::const_iterator lay =
_layers.begin();
552 layers::const_iterator end =
_layers.end();
554 while ( lay != end && lay->second->isCategorical() ) {
569 return _layers[i].second->isCategorical();
580 layers::const_iterator lay =
_layers.begin();
581 layers::const_iterator end =
_layers.end();
583 while ( lay != end ) {
585 Map *map = lay->second;
602 if ( normalizerPtr ) {
633 #if defined(DEBUG_GET)
634 Log::instance()->
debug(
"EnvironmentImpl::get() Coordinate (%f,%f) is not in common region\n",x,y);
643 layers::const_iterator lay =
_layers.begin();
644 layers::const_iterator end =
_layers.end();
647 while ( lay != end ) {
649 if ( ! lay->second->get( x, y, s ) ) {
650 #if defined(DEBUG_GET)
651 Log::instance()->
debug(
"EnvironmentImpl::get() Coordinate (%f,%f) does not have data in layer %s\n",x,y,lay->first.c_str());
719 }
while ( s.
size() == 0 && loop < max_loop );
721 if ( loop == max_loop ) {
723 std::string msg =
"Exceeded maximum number of attempts to generate pseudo point.\n";
746 if ( x < _xmin || x >
_xmax || y < _ymin || y >
_ymax ) {
747 #if defined(DEBUG_GET)
748 Log::instance()->
debug(
"EnvironmentImpl::checkCoordinates() Coordinate (%f,%f) not in extent of all regions\n",x,y);
755 if ( !
_mask.second ) {
762 bool hasmaskevalue = (
_mask.second->get( x, y, &val ) > 0 );
764 if ( ! hasmaskevalue ) {
765 #if defined(DEBUG_GET)
766 Log::instance()->
debug(
"EnvironmentImpl::check() Coordinate (%f,%f) has no mask value\n",x,y);
770 return hasmaskevalue;
794 layers::const_iterator map =
_layers.begin();
796 for (
int i = 0; i < nlayers; i++ ) {
798 map->second->getMinMax( &amin, &amax );
819 Coord xmin, ymin, xmax, ymax;
829 layers::const_iterator lay =
_layers.begin();
830 layers::const_iterator end =
_layers.end();
831 while ( lay != end ) {
832 lay->second->getExtent( &xmin, &ymin, &xmax, &ymax );
864 layers::iterator it =
_layers.begin();
866 unsigned int tmp = 0;
868 while ( tmp < index ) {
EnvironmentImpl * clone() const
void getMinMax(Sample *min, Sample *max) const
void warn(const char *format,...)
'Warn' level.
Normalizer * _normalizerPtr
Normalize the environment.
void setCategoricalThreshold(std::size_t index)
std::vector< ConfigurationPtr > subsection_list
double Scalar
Type of map values.
void initialize(const std::vector< std::string > &categs, const std::vector< std::string > &maps, const std::string &mask_file="")
Sample getNormalized(Coord x, Coord y) const
int checkCoordinates(Coord x, Coord y) const
virtual ConfigurationPtr getConfiguration() const
std::pair< std::string, Map * > layer
unsigned int numLayers() const
void resetNormalization()
static Log * instance()
Returns the instance pointer, creating the object on the first call.
void removeLayer(unsigned int index)
Coord _xmin
Intersection of all layers.
Sample getRandom(Coord *x=0, Coord *y=0) const
virtual void setConfiguration(const ConstConfigurationPtr &)
void getUnnormalizedInternal(Sample *, Coord x, Coord y) const
EnvironmentPtr createEnvironment(const std::vector< std::string > &categs, const std::vector< std::string > &maps, const std::string &mask_file)
Coord _ymax
Intersection of all layers.
size_t numCategoricalLayers() const
void error(const char *format,...)
'Error' level.
int getRegion(Coord *xmin, Coord *ymin, Coord *xmax, Coord *ymax) const
Coord _xmax
Intersection of all layers.
Coord _ymin
Intersection of all layers.
void resize(std::size_t size)
void normalize(Normalizer *normalizerPtr)
virtual void normalize(Sample *samplePtr)=0
int getExtremes(Sample *min, Sample *max) const
int getMinMax(Scalar *min, Scalar *max) const
static ConfigurationPtr getLayerConfig(const layer &l, bool basicConfig=false)
static void loadLayers(const std::vector< std::string > &map_ids, std::vector< Map * > &map_refs, int categ=0)
static RasterFactory & instance()
ReferenceCountedPointer< EnvironmentImpl > EnvironmentPtr
int changeLayers(const std::vector< std::string > &categs, const std::vector< std::string > &maps)
Sample getUnnormalized(Coord x, Coord y) const
double Coord
Type of map coordinates.
Sample get(Coord x, Coord y) const
layer _mask
Mask (can be 0).
layers _layers
Vector with all layers that describe the variables.
static layer makeLayer(const ConstConfigurationPtr &config, Map *map)
void debug(const char *format,...)
'Debug' level.
virtual Normalizer * getCopy()=0
int changeMask(const std::string &mask_file)