Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Plants.h
1 //
2 // Plants.h
3 //
4 // Copyright (c) 2001-2011 Virtual Terrain Project
5 // Free for all uses, see license.txt for details.
6 //
7 
8 #ifndef VTDATA_PLANTSH
9 #define VTDATA_PLANTSH
10 
11 #include "Array.h"
12 #include "Features.h"
13 
14 enum AppearType {
15  AT_UNKNOWN,
16  AT_BILLBOARD,
17  AT_MODEL,
18  AT_XFROG
19 };
20 
26 {
27 public:
29  vtPlantAppearance(AppearType type, const char *filename, float width,
30  float height, float shadow_radius, float shadow_darkness);
31  virtual ~vtPlantAppearance();
32 
33  AppearType m_eType;
34  vtString m_filename;
35  float m_width;
36  float m_height;
37  float m_shadow_radius;
38  float m_shadow_darkness;
39 };
40 
46 {
47 public:
49  virtual ~vtPlantSpecies();
50 
51  // copy
52  vtPlantSpecies &operator=(const vtPlantSpecies &v);
53 
54  struct CommonName { vtString m_strName, m_strLang; };
55 
56  void AddCommonName(const char *Name, const char *Lang = NULL);
57  size_t NumCommonNames() const { return m_CommonNames.size(); }
58  CommonName GetCommonName(int n = 0) const { return m_CommonNames[n]; }
59  uint CommonNamesOfLanguage(const char *lang);
60 
61  void SetSciName(const char *szSciName);
62  const char *GetSciName() const { return m_szSciName; }
63 
64  void SetMaxHeight(float f) { m_fMaxHeight = f; }
65  float GetMaxHeight() const { return m_fMaxHeight; }
66 
67  virtual void AddAppearance(AppearType type, const char *filename,
68  float width, float height, float shadow_radius, float shadow_darkness)
69  {
70  vtPlantAppearance *pApp = new vtPlantAppearance(type, filename,
71  width, height, shadow_radius, shadow_darkness);
72  m_Apps.Append(pApp);
73  }
74 
75  uint NumAppearances() const { return m_Apps.GetSize(); }
76  vtPlantAppearance *GetAppearance(int i) const { return m_Apps[i]; }
77 
78 protected:
79  std::vector<CommonName> m_CommonNames;
80 
81  vtString m_szSciName;
82  float m_fMaxHeight;
84 };
85 
86 
95 {
96 public:
97  void ResetAmounts() { m_amount = 0.0f; m_iNumPlanted = 0; }
98 
99  vtPlantSpecies *m_pSpecies;
100  float m_plant_per_m2;
101  float m_typical_size;
102 
103  float m_amount; // these two fields are using during the
104  int m_iNumPlanted; // plant distribution process
105 };
106 
114 {
115 public:
116  vtBioType();
117  ~vtBioType();
118 
119  void AddPlant(vtPlantSpecies *pSpecies, float plant_per_m2, float typical_size = -1.0f);
120  void ResetAmounts();
122 
123  vtArray<vtPlantDensity *> m_Densities;
124 
125  vtString m_name;
126 };
127 
132 {
133 public:
134  vtSpeciesList();
135  virtual ~vtSpeciesList();
136 
137  bool ReadXML(const char *fname, vtString *msg = NULL);
138  bool WriteXML(const char *fname) const;
139  bool WriteHTML(const char *fname) const;
140 
141  uint NumSpecies() const { return m_Species.GetSize(); }
142  vtPlantSpecies *GetSpecies(uint i) const
143  {
144  if (i < m_Species.GetSize())
145  return m_Species[i];
146  else
147  return NULL;
148  }
149  short GetSpeciesIdByName(const char *name) const;
150  short GetSpeciesIdByCommonName(const char *name) const;
151  void Append(vtPlantSpecies *pSpecies)
152  {
153  m_Species.Append(pSpecies);
154  }
155  short FindSpeciesId(vtPlantSpecies *ps);
156  void Clear() { m_Species.Empty(); }
157 
158 protected:
159  vtArray<vtPlantSpecies*> m_Species;
160 };
161 
169 {
170 public:
171  vtBioRegion();
172  ~vtBioRegion();
173 
174  bool Read(const char *fname, const vtSpeciesList &species);
175  bool ReadXML(const char *fname, const vtSpeciesList &species,
176  vtString *msg = NULL);
177  bool WriteXML(const char *fname) const;
178 
179  int AddType(vtBioType *bt) { return m_Types.Append(bt); }
180  int NumTypes() const { return m_Types.GetSize(); }
181  vtBioType *GetBioType(int i) const { return m_Types[i]; }
182  int FindBiotypeIdByName(const char *name) const;
183  void ResetAmounts();
184  void Clear() { m_Types.Empty(); }
185 
186  vtArray<vtBioType *> m_Types;
187 };
188 
198 {
199 public:
201 
202  void SetPlantList(vtSpeciesList *list) { m_pPlantList = list; }
203  int AddPlant(const DPoint2 &pos, float size, short species_id);
204  int AddPlant(const DPoint2 &pos, float size, vtPlantSpecies *ps);
205  void SetPlant(int iNum, float size, short species_id);
206  void GetPlant(int iNum, float &size, short &species_id) const;
207  uint InstancesOfSpecies(short species_id);
208 
209  bool ReadVF_version11(const char *fname);
210  bool ReadVF(const char *fname);
211  bool ReadSHP(const char *fname);
212  bool WriteVF(const char *fname) const;
213 
214 protected:
215  vtSpeciesList *m_pPlantList;
216 
217  int m_SizeField;
218  int m_SpeciesField;
219 };
220 
221 #endif // VTDATA_PLANTSH
222