openModeller  Version 1.4.0
Environment.hh
Go to the documentation of this file.
00001 
00029 #ifndef _ENVIRONMENTHH_
00030 #define _ENVIRONMENTHH_
00031 
00032 #include <openmodeller/om_defs.hh>
00033 #include <openmodeller/refcount.hh>
00034 #include <openmodeller/Configurable.hh>
00035 #include <openmodeller/Normalizable.hh>
00036 #include <openmodeller/Normalizer.hh>
00037 #include <openmodeller/Sample.hh>
00038 
00039 #include <vector>
00040 #include <string>
00041 #include <utility>
00042 
00043 class Map;
00044 class SampledData;
00045 
00046 class EnvironmentImpl;
00047 typedef ReferenceCountedPointer<EnvironmentImpl> EnvironmentPtr;
00048 typedef ReferenceCountedPointer<const EnvironmentImpl> ConstEnvironmentPtr;
00049 
00050 /****************************************************************/
00051 /************************* Environment **************************/
00052 
00053 EnvironmentPtr dllexp createEnvironment( const std::vector<std::string>& categs,
00054           const std::vector<std::string>& maps,
00055           const std::string& mask_file );
00056 
00057 EnvironmentPtr dllexp createEnvironment( const std::vector<std::string>& categs,
00058           const std::vector<std::string>& maps );
00059 
00060 EnvironmentPtr dllexp createEnvironment( const ConstConfigurationPtr& config );
00061 
00062 EnvironmentPtr dllexp createEnvironment( );
00063 
00064 
00069 class dllexp EnvironmentImpl : public Configurable, public Normalizable, private ReferenceCountedObject
00070 {
00071   friend class ReferenceCountedPointer<EnvironmentImpl>;
00072   friend class ReferenceCountedPointer<const EnvironmentImpl>;
00073 
00074   friend EnvironmentPtr dllexp createEnvironment( const std::vector<std::string>& categs,
00075              const std::vector<std::string>& maps,
00076              const std::string& mask_file );
00077   
00078   friend EnvironmentPtr dllexp createEnvironment( const std::vector<std::string>& categs,
00079              const std::vector<std::string>& maps );
00080 
00081   friend EnvironmentPtr dllexp createEnvironment( const ConstConfigurationPtr& config );
00082 
00083   friend EnvironmentPtr dllexp createEnvironment( );
00084 
00085   typedef std::pair<std::string, Map*> layer;
00086   typedef std::vector<layer> layers;
00087 
00088   EnvironmentImpl();
00089 
00097   EnvironmentImpl( const std::vector<std::string>& categs,
00098        const std::vector<std::string>& maps, 
00099        const std::string& mask_file = "" );
00100 
00101 public:
00102 
00103   ~EnvironmentImpl();
00104 
00106   EnvironmentImpl* clone() const;
00107 
00108   unsigned int numLayers() const { return _layers.size(); }
00109 
00110   size_t numCategoricalLayers() const;
00111 
00115   int isCategorical( int i );
00116 
00120   void getMinMax( Sample * min, Sample * max ) const;
00121 
00124   void normalize( Normalizer * normalizerPtr );
00125 
00128   void resetNormalization();
00129 
00137   Sample get( Coord x, Coord y ) const;
00138 
00139   Sample getNormalized( Coord x, Coord y ) const;
00140   Sample getUnnormalized( Coord x, Coord y ) const;
00141 
00148   Sample getRandom( Coord *x = 0, Coord *y = 0 ) const;
00149 
00152   int checkCoordinates( Coord x, Coord y ) const;
00153 
00156   int getRegion( Coord *xmin, Coord *ymin, Coord *xmax,
00157                  Coord *ymax ) const;
00158 
00163   int getExtremes( Sample* min, Sample* max ) const;
00164 
00165   Map * getLayer(int index) const { return _layers[index].second; }
00166 
00168   int changeMask( const std::string& mask_file );
00169 
00170   Map * getMask() const { return _mask.second; }
00171 
00172   const std::string& getLayerPath(int index) const { return _layers[index].first; }
00173 
00174   const std::string& getMaskPath() const { return _mask.first; }
00175 
00176   void removeLayer(unsigned int index);
00177 
00178   virtual ConfigurationPtr getConfiguration() const;
00179 
00180   virtual void setConfiguration( const ConstConfigurationPtr & );
00181 
00182 private:
00183 
00184   void initialize( const std::vector<std::string>& categs,
00185        const std::vector<std::string>& maps, 
00186        const std::string& mask_file="" );
00187 
00188   /* utility function to extract unnormalized environment vector
00189    * Only needed to prevent unnecessary memory copy due to Sample
00190    * not having a reasonable copy constructor/temporary
00191    */
00192   void getUnnormalizedInternal( Sample *, Coord x, Coord y ) const;
00193 
00194   /* utility to clear the mask information.  Deallocates memory.  Does not computeRegion() */
00195   void clearMask();
00196 
00197   /* utility to clear the layer information, deallocates memory.  Does not computeRegion() */
00198   void clearLayers();
00199 
00200   /* utility to construct a ConfigurationPtr representation of a Layer.
00201      Does not properly set the Configuration name.
00202      Is a member function so it can access the private typedefs. */
00203   static ConfigurationPtr getLayerConfig( const layer& l, bool basicConfig=false );
00204 
00205   /* load specified layers. Zeros in map_refs are populated with Map instances based on the
00206      corresponding ids in the other vector */
00207   static void loadLayers( const std::vector<std::string>& map_ids, std::vector<Map*>& map_refs, int categ=0 );
00208 
00209   /* utility to construct a layer pair object.
00210      It is declared a member so it has access to the private typedef for layer */
00211   static layer makeLayer( const ConstConfigurationPtr& config, Map *map );
00212   static layer makeLayer( const std::string& filename, int categ );
00213   static layer makeLayer( const std::string& filename, Map *map );
00214 
00216   int changeLayers( const std::vector<std::string>& categs, 
00217         const std::vector<std::string>& maps );
00218 
00220   void calcRegion();
00221 
00222   layers _layers; 
00223   layer _mask;   
00224 
00225   Coord _xmin; 
00226   Coord _ymin; 
00227   Coord _xmax; 
00228   Coord _ymax; 
00229 
00230   Normalizer * _normalizerPtr; 
00231 };
00232 
00233 
00234 #endif