openModeller
Version 1.4.0
|
00001 00029 #ifndef _OCCURRENCESHH_ 00030 #define _OCCURRENCESHH_ 00031 00032 #include <openmodeller/om_defs.hh> 00033 #include <openmodeller/Occurrence.hh> 00034 #include <openmodeller/Configurable.hh> 00035 #include <openmodeller/Environment.hh> 00036 #include <openmodeller/Normalizable.hh> 00037 #include <openmodeller/Normalizer.hh> 00038 #include <openmodeller/refcount.hh> 00039 #include <openmodeller/env_io/GeoTransform.hh> 00040 00041 #include <vector> 00042 #include <string> 00043 00044 /****************************************************************/ 00045 /************************* Occurrences **************************/ 00046 00047 class OccurrencesImpl; 00048 typedef ReferenceCountedPointer<OccurrencesImpl> OccurrencesPtr; 00049 typedef ReferenceCountedPointer<const OccurrencesImpl> ConstOccurrencesPtr; 00050 00051 typedef std::vector<Scalar> ScalarVector; 00052 00059 dllexp void splitOccurrences(const OccurrencesPtr& occurrences, 00060 OccurrencesPtr& trainOccurrences, 00061 OccurrencesPtr& testOccurrences, 00062 double propTrain); 00063 00069 dllexp void splitOccurrences(const OccurrencesPtr& occurrences, 00070 OccurrencesPtr& trainOccurrences, 00071 OccurrencesPtr& testOccurrences); 00072 00073 00078 class dllexp OccurrencesImpl : public Configurable, private ReferenceCountedObject 00079 { 00080 friend class ReferenceCountedPointer<OccurrencesImpl>; 00081 friend class ReferenceCountedPointer<const OccurrencesImpl>; 00082 00083 public: 00084 00085 typedef std::vector<OccurrencePtr>::const_iterator const_iterator; 00086 typedef std::vector<OccurrencePtr>::iterator iterator; 00087 00091 inline OccurrencesImpl( double default_abundance ) : 00092 default_abundance_( default_abundance ), 00093 label_( ), 00094 cs_( GeoTransform::getDefaultCS() ), 00095 gt_( 0 ), 00096 occur_( ) 00097 { 00098 initGeoTransform(); 00099 }; 00100 00106 inline OccurrencesImpl( const std::string& label, 00107 const std::string& coord_system=GeoTransform::getDefaultCS() ) : 00108 default_abundance_( 0.0 ), 00109 label_( label ), 00110 cs_( coord_system ), 00111 gt_( 0 ), 00112 occur_() 00113 { 00114 initGeoTransform(); 00115 }; 00116 00117 ~OccurrencesImpl(); 00118 00120 OccurrencesImpl* clone() const; 00121 00123 void reserve( int estimate ) { occur_.reserve( estimate ); } 00124 00126 char const * label() const { return label_.c_str(); } 00127 00129 char const * coordSystem() const { return cs_.c_str(); } 00130 00131 /* Indicates whether the object contains environmental samples 00132 * that can be used instead of a full blown Environment object 00133 */ 00134 bool hasEnvironment() const; 00135 00136 /* Dimension of environmental space in samples stored in this object 00137 */ 00138 int dimension() const; 00139 00142 void setLabel( const std::string& label ); 00143 00149 void setCoordinateSystem( const std::string& cs ); 00150 00165 void createOccurrence( const std::string& id, 00166 Coord longitude, Coord latitude, 00167 Scalar error, Scalar abundance, 00168 int num_attributes = 0, Scalar *attributes = 0, 00169 int num_env = 0, Scalar *env = 0 ); 00170 00174 void createOccurrence( const std::string& id, 00175 Coord longitude, Coord latitude, 00176 Scalar error, Scalar abundance, 00177 std::vector<double> attributes, 00178 std::vector<double> env); 00179 00181 void insert( const OccurrencePtr& ); 00182 00184 iterator erase( const iterator& it ); 00185 00192 int numAttributes() const { return 0; } 00193 00195 int numOccurrences() const { return occur_.size(); } 00196 00198 bool isEmpty() const { return occur_.empty(); } 00199 00201 ConstOccurrencePtr operator[]( int i ) const { return occur_[i]; } 00202 00204 const_iterator begin() const { return occur_.begin(); } 00205 const_iterator end() const { return occur_.end(); } 00206 iterator begin() { return occur_.begin(); } 00207 iterator end() { return occur_.end(); } 00208 00210 ConstOccurrencePtr getRandom() const; 00211 00213 void getMinMax( Sample * min, Sample * max ) const; 00214 00216 void normalize( Normalizer * normalizerPtr, size_t categoricalThreshold=0 ); 00217 00219 void resetNormalization(); 00220 00223 void setEnvironment( const EnvironmentPtr& env, 00224 const char *type = "Sample" ); 00225 00230 void appendFrom(const OccurrencesPtr& source); 00231 00233 std::vector<ScalarVector> getEnvironmentMatrix(); 00234 00236 void dump( std::string msg="" ) const; 00237 00238 virtual ConfigurationPtr getConfiguration() const; 00239 00240 virtual void setConfiguration( const ConstConfigurationPtr & ); 00241 00242 private: 00243 00244 void initGeoTransform(); 00245 00246 double default_abundance_; 00247 00248 std::string label_; // Label for the list of occurrences (e.g. species name) 00249 std::string cs_; // Coordinate system name 00250 00251 GeoTransform *gt_; // Object to transform between different coordinate systems 00252 00253 std::vector< OccurrencePtr > occur_; // Occurrences 00254 }; 00255 00256 00257 #endif