openModeller  Version 1.4.0
OpenModeller.hh
Go to the documentation of this file.
00001 
00028 #ifndef _OM_CONTROLHH_
00029 #define _OM_CONTROLHH_
00030 
00031 #include <openmodeller/om_defs.hh>
00032 #include <openmodeller/CallbackWrapper.hh>
00033 #include <openmodeller/Log.hh>
00034 #include <openmodeller/Configuration.hh>
00035 #include <openmodeller/AlgMetadata.hh>
00036 #include <openmodeller/Sampler.hh>
00037 #include <openmodeller/Algorithm.hh>
00038 #include <openmodeller/ConfusionMatrix.hh>
00039 #include <openmodeller/RocCurve.hh>
00040 
00041 class AlgParameter;
00042 
00043 #include <openmodeller/Occurrences.hh>
00044 #include <openmodeller/Environment.hh>
00045 
00046 // Since MapCommand's defn/decl have been moved to om_projector.hh,
00047 // we need to actually include the entire header.
00048 #include <openmodeller/Projector.hh>
00049 
00050 #include <openmodeller/Algorithm.hh>
00051 
00052 #include <openmodeller/MapFormat.hh>
00053 
00054 class MapFormat;
00055 class ConfusionMatrix;
00056 class RocCurve;
00057 class AreaStats;
00058 
00059 #include <string>
00060 #include <vector>
00061 
00062 
00063 /****************************************************************/
00064 /************************* Open Modeller ************************/
00065 
00071 class dllexp OpenModeller
00072 {
00073 public:
00074 
00075   OpenModeller();
00076   ~OpenModeller();
00077 
00083   void setLogLevel(Log::Level level);
00084 
00085 
00089   std::string getVersion();
00090 
00091   /*****************************************************************************
00092    *
00093    * Algorithms related methods
00094    *
00095    ****************************************************************************/
00096 
00106   AlgMetadata const **availableAlgorithms();
00107 
00113   AlgMetadata const *algorithmMetadata( char const *algorithm_id );
00114 
00121   int numAvailableAlgorithms();
00122 
00123   /*****************************************************************************
00124    *
00125    * Accessor methods
00126    *
00127    ****************************************************************************/
00128 
00133   EnvironmentPtr getEnvironment() { return _env; }
00134 
00139   AlgorithmPtr getAlgorithm() { return _alg; }
00140 
00145   Model getModel() const { return _alg->getModel(); }
00146 
00151   const SamplerPtr& getSampler() const { return _samp; }
00152 
00153   /*****************************************************************************
00154    *
00155    * Parameters setting methods
00156    *
00157    ****************************************************************************/
00158 
00167   int setOccurrences( const OccurrencesPtr& presence,
00168                       const OccurrencesPtr& absence=OccurrencesPtr() );
00169 
00179   int setAlgorithm( std::string const id, int nparam, AlgParameter const *param );
00180 
00189   void setEnvironment( std::vector<std::string> categ_map,
00190            std::vector<std::string> continuous_map,
00191            const std::string& mask );
00192     
00196   void setSampler(const SamplerPtr& sampler);
00197 
00203   void setAbortionCallback( AbortionCallback func, void *param=0 );
00204 
00205   /*****************************************************************************
00206    *
00207    * Projection / Map Generation Methods
00208    *
00209    ****************************************************************************/
00210 
00217   void setMapCallback( ModelProjectionCallback func, void *param=0 );
00218 
00228   int createMap( const EnvironmentPtr & env, char const *output_file, MapFormat& format );
00229 
00237   int createMap( const EnvironmentPtr & env, char const *output_file );
00238   
00248   int createMap( char const *output_file, MapFormat& format );
00249 
00257   int createMap( char const *output_file );
00258 
00259   /*****************************************************************************
00260    *
00261    * Model generation procedures
00262    *
00263    ****************************************************************************/
00264 
00271   void setModelCallback( ModelCreationCallback func, void *param=0 );
00272 
00273   //
00274   // Model and distribution map related methods.
00275   //
00276 
00279   int createModel();
00280 
00283   int run()  { return createModel(); }
00284 
00294   Scalar getValue(const ConstEnvironmentPtr& env, Coord x, Coord y);
00295 
00302   Scalar getValue( Scalar const *environment_values );
00303 
00304   char *error()  { return _error; }
00305 
00306   /*****************************************************************************
00307    *
00308    * Statistics
00309    *
00310    ****************************************************************************/
00311 
00318   AreaStats * getActualAreaStats();
00319 
00330   AreaStats * getEstimatedAreaStats(double proportionAreaToSample = 0.01);
00331   AreaStats * getEstimatedAreaStats(const ConstEnvironmentPtr& env, 
00332             double proportionAreaToSample = 0.01);
00333 
00339   const ConfusionMatrix * const getConfusionMatrix();
00340 
00346   RocCurve * const getRocCurve();
00347 
00348   /*****************************************************************************
00349    *
00350    * Serialization & Deserialization
00351    *
00352    ****************************************************************************/
00353 
00354   ConfigurationPtr getModelConfiguration() const;
00355 
00356   void setModelConfiguration( const ConstConfigurationPtr & );
00357 
00358   void setProjectionConfiguration( const ConstConfigurationPtr & );
00359 
00360   void calculateModelStatistics( const ConstConfigurationPtr & );
00361 
00362 private:
00363 
00364   bool hasEnvironment();
00365 
00366   // Sampler object
00367   SamplerPtr _samp;
00368 
00369   // Algorithm object
00370   AlgorithmPtr _alg;
00371 
00372   // Presence occurrences points
00373   OccurrencesPtr _presence;
00374 
00375   // Absence occurrences points
00376   OccurrencesPtr _absence;
00377 
00378   // Original environmental layers
00379   EnvironmentPtr _env;
00380 
00381   // Wrapper object for callbacks
00382   CallbackWrapper _callback_wrapper;
00383 
00384   // Output format
00385   MapFormat _format;
00386 
00387   // Environmental layers for projection
00388   EnvironmentPtr _projEnv;
00389 
00390   // Model statistics: helper objects
00391   AreaStats * _actualAreaStats;
00392   AreaStats * _estimatedAreaStats;
00393 
00394   // Confusion matrix
00395   ConfusionMatrix _confusion_matrix;
00396 
00397   // ROC Curve
00398   RocCurve _roc_curve;
00399 
00400   char _error[256];
00401 };
00402 
00403 
00404 #endif