VR-Forces 4.7 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
surface.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2014 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
6 #pragma once
7 
8 #include <vlutil/vlConfig.h>
10 #include "geometry/color.h"
11 #include <stdio.h>
12 #include <locale>
13 #include <string>
14 #include <vlutil/vlString.h>
15 
16 class DtTerrainDatabase;
18 
19 // enumeration DtSoilType is used to specify the soiltype
20 // associated with a surface
21 typedef enum
22 {
25  Mud,
43 } DtSoilType;
44 
45 typedef enum
46 {
55 
56 typedef enum
57 {
62 
63 // enumeration DtEnvState is used to specify the prevailing
64 // environmental condition over a surface.
65 typedef enum
66 {
67  Dry,
68  Wet,
69  Icy,
72 } DtEnvState;
73 
75 {
84 };
85 
86 class DtSurface;
87 
88 // DtSurfaceCharacteristicStringMapper class can be installed in the DtSurface as a factory to map soil characteristics to strings
90 {
91 public:
94 
97  virtual DtString surfaceCharacteristicsString(const DtSurface&) const = 0;
98 };
99 
100 // class DtSurface:
101 //
102 // DtSurface has two member variables, a color specification and an
103 // unsigned 32-bit vector that specifies its characteristics - medium
104 // the surface is in, soil type, environmental state, etc.
105 //
106 // The characteristics vector is laid out as follows (Note: we refer to the
107 // most significant bit as bit-0 and the least significant bit as bit-31):
108 //
109 // bit interpretation when the bit is set
110 // --- ----------------------------------
111 //
112 // medium specification. Initially, we only envision Ground and Water Surface
113 // being used.
114 //
115 // bit 0 -- surface is Ground (is equivalent to IsTerrainSkin in
116 // earlier version)
117 // 1 -- surface is above ground
118 // 2 -- surface is under ground
119 // 3 -- top surface of a body of water
120 // 4 -- surface is above water
121 // 5 -- surface is under water
122 // 6,7 -- unused
123 //
124 // environment specification; the default is dry, unless otherwise specified.
125 //
126 // 8 -- surface is dry
127 // 9 -- surface is wet
128 // 10 -- surface is icy
129 // 11 -- surface is (covered with?) snow
130 //
131 // 12-15 -- unspecified
132 //
133 // soiltype specification
134 // when medium is ground
135 // 16 -- improved/unimproved
136 // when medium is WaterSurface
137 // 16 -- deep/shallow
138 // when medium is above ground
139 // 16 -- surface is / is not part of cultural feature
140 // 17-23 -- currently unused
141 //
142 // bits 24-31 are laid out as follows
143 // 0000 0000 -- unspecified soil type
144 // 0000 0001 -- softsoil (ground/unimproved)
145 // 0000 0010 -- swamp (ground/unimproved)
146 // 0000 0011 -- mud (ground/unimproved)
147 // 0000 0100 -- forest (ground/unimproved)
148 // 0000 0101 -- grass (ground)
149 // 0000 0110 -- Cultivated Fields (ground)
150 // 0000 0111 -- Orchards (ground)
151 // 0000 1000 -- Rock (ground/unimproved)
152 // 0000 1001 -- Boulder (ground/unimproved)
153 // 0000 1010 -- Sand (ground/unimproved)
154 // 0000 1011 -- Dirt Road (ground/improved)
155 // 0000 1100 -- Gravel Road (ground/improved)
156 // 0000 1101 -- paved road (ground/improved)
157 // 0000 1110 -- asphalt/other hard surface (ground/improved)
158 // 0000 1111 -- Railroad US (ground/improved)
159 // 0001 0000 -- RailRoad Euro (ground/improved)
160 // 0001 0001 -- flimsy (to map from ctdb soil types)
161 // 0001 0010 -- muddy road (ground/unimproved)
162 //
163 // body of water specification
164 //
165 // bits 24-31 are laid out as follows
166 // 0000 0001 -- ocean (water surface)
167 // 0000 0010 -- lake (water surface)
168 // 0000 0011 -- river (water surface)
169 // 0000 0100 -- pond (water surface)
170 // 0000 0101 -- stream(water surface)
171 // 0000 0110 -- brook (water surface)
172 //
173 // cultural feature specification
174 //
175 // bits 24-31 are laid out as follows
176 // 0000 0001 -- building (above ground)
177 // 0000 0010 -- tree (above ground)
178 
180 {
181 public:
182 
183  // enumeration DtMedium is used to specify where a surface
184  // is situated.
185  typedef enum
186  {
193  UnspecifiedMedium
194  } DtMedium;
195 
196  typedef unsigned int DtCharacteristics;
197 
198 public:
199 
200  // default constructor
201  DtSurface();
202 
203  // destructor
204  virtual ~DtSurface();
205 
206  // copy constructor
207  DtSurface(const DtSurface& orig);
208 
209  // assignment operator
210  DtSurface& operator=(const DtSurface& orig);
211 
212  // comparison operators
213  bool operator==(const DtSurface& orig) const;
214  bool operator!=(const DtSurface& orig) const;
215 
216  // accessor / mutator functions
217  virtual const DtColor& color() const;
218  virtual void setColor(const DtColor& c);
219 
220  // Set/Get the surface characteristics field.
221  virtual void setSurfaceCharacteristics(DtCharacteristics surfChar);
222  virtual DtCharacteristics characteristics() const;
223 
224  // \return A string that describes the surface characteristic.
225  DtString surfaceCharacteristicsString() const;
226 
227  // functions to return medium, environmental
228  // state, soil type, body of water type, and cultural feature type.
229  virtual DtMedium whereSurface() const;
230  virtual DtEnvState envState() const;
231  virtual DtSoilType soilType() const;
232  virtual DtBodyOfWaterType bodyOfWaterType() const;
233  virtual DtCulturalFeatureType culturalFeatureType() const;
234 
235  // functions to return medium, environmental
236  // state, soil type, body of water type, and
237  // cultural feature type as a string.
238  virtual DtString mediumString() const;
239  virtual DtString envStateString() const;
240  virtual DtString soilTypeString() const;
241  virtual DtString bodyOfWaterTypeString() const;
242  virtual DtString culturalFeatureTypeString() const;
243 
244  virtual DtRoughnessSoilType roughnessSoilType() const;
245  virtual DtString roughnessSoilTypeString() const;
246 
247  // Set/Get whether the surface is ground.
248  virtual void setIsGround(bool onOff);
249  virtual bool isGround() const;
250 
252 
253  // Set/Get whether the surface is above ground.
254  virtual void setAboveGround(bool onOff);
255  virtual bool aboveGround() const;
256 
257  // Set/Get whether the surface is under ground.
258  virtual void setUnderGround(bool onOff);
259  virtual bool underGround() const;
260 
261  // Set/Get whether the surface is water.
262  virtual void setIsWaterSurface(bool onOff);
263  virtual bool isWaterSurface() const;
264 
265  // Set/Get whether the surface is above water.
266  virtual void setAboveWater(bool onOff);
267  virtual bool aboveWater() const;
268 
269  // Set/Get whether the surface is under water.
270  virtual void setUnderWater(bool onOff);
271  virtual bool underWater() const;
272 
274 
275  // Set/Get whether the surface is dry.
276  virtual void setIsDry(bool onOff);
277  virtual bool isDry() const;
278 
279  // Set/Get whether the surface is wet.
280  virtual void setIsWet(bool onOff);
281  virtual bool isWet() const;
282 
283  // Set/Get whether the surface is icy.
284  virtual void setIsIcy(bool onOff);
285  virtual bool isIcy() const;
286 
287  // Set/Get whether the surface is covered by snow.
288  virtual void setIsCoveredBySnow(bool onOff);
289  virtual bool isCoveredBySnow() const;
290 
291 
292  // Set/Get whether the surface is improved.
293  // The medium is required to be Ground.
294  virtual void setIsImproved(bool onOff);
295  virtual bool isImproved() const;
296  virtual bool isUnimproved() const;
297 
298  // Set/Get whether the surface is a body of water
299  // and is deep.
300  virtual void setIsDeep(bool onOff);
301  virtual bool isDeep() const;
302  virtual bool isShallow() const;
303 
304  // Set/Get whether the surface is a part of a cultural
305  // feature. The medium is required to be AboveGround.
306  virtual void setIsCulturalFeature(bool onOff);
307  virtual bool isCulturalFeature() const;
308 
309  // Accessor/Mutator functions for soil type
310 
311  // Set/Get whether the surface is soft soil.
312  virtual void setIsSoftSoil(bool onOff);
313  virtual bool isSoftSoil() const;
314 
315  // Set/Get whether the surface is swamp.
316  virtual void setIsSwamp(bool onOff);
317  virtual bool isSwamp() const;
318 
319  // Set/Get whether the surface is mud.
320  virtual void setIsMud(bool onOff);
321  virtual bool isMud() const;
322 
323  // Set/Get whether the surface is forest.
324  virtual void setIsForest(bool onOff);
325  virtual bool isForest() const;
326 
327  // Set/Get whether the surface is grass.
328  virtual void setIsGrass(bool onOff);
329  virtual bool isGrass() const;
330 
331  // Set/Get whether the surface is grass.
332  virtual void setIsCultivatedField(bool onOff);
333  virtual bool isCultivatedField() const;
334 
335  // Set/Get whether the surface is grass.
336  virtual void setIsOrchard(bool onOff);
337  virtual bool isOrchard() const;
338 
339  // Set/Get whether the surface is rock.
340  virtual void setIsRock(bool onOff);
341  virtual bool isRock() const;
342 
343  // Set/Get whether the surface is boulder.
344  virtual void setIsBoulder(bool onOff);
345  virtual bool isBoulder() const;
346 
347  // Set/Get whether the surface is sand.
348  virtual void setIsSand(bool onOff);
349  virtual bool isSand() const;
350 
351  // Set/Get whether the surface is dirt road.
352  virtual void setIsDirtRoad(bool onOff);
353  virtual bool isDirtRoad() const;
354 
355  // Set/Get whether the surface is gravel road.
356  virtual void setIsGravelRoad(bool onOff);
357  virtual bool isGravelRoad() const;
358 
359  // Set/Get whether the surface is paved road.
360  virtual void setIsPavedRoad(bool onOff);
361  virtual bool isPavedRoad() const;
362 
363  // Set/Get whether the surface is Muddy road.
364  virtual void setIsMuddyRoad(bool onOff);
365  virtual bool isMuddyRoad() const;
366 
367  // Set/Get whether the surface is asphalt or other hard
368  // surface.
369  virtual void setIsHardSurface(bool onOff);
370  virtual bool isHardSurface() const;
371 
372  // Set/Get whether the surface is US rail road.
373  virtual void setIsUSRailRoad(bool onOff);
374  virtual bool isUSRailRoad() const;
375 
376  // Set/Get whether the surface is Euro rail road.
377  virtual void setIsEuroRailRoad(bool onOff);
378  virtual bool isEuroRailRoad() const;
379 
380  // Set/Get whether the surface is flimsy.
381  virtual void setIsFlimsy(bool onOff);
382  virtual bool isFlimsy() const;
383 
384  // Set/Get whether the soiltype is undefined.
385  virtual void setIsUndefinedSoilType(bool onOff);
386  virtual bool isUndefinedSoilType() const;
387 
388  // \deprecated Use standard version above.
389  // \see setIsUndefinedSoilType
390  // \see undefinedSoilType
391  virtual void setUndefinedSoilType(bool onOff);
392  virtual bool undefinedSoilType() const;
393 
394  // Accessor/Mutator functions for body of water type.
395 
397  // Set/Get whether the surface is ocean.
398  virtual void setIsOcean(bool onOff);
399  virtual bool isOcean() const;
400 
401  // Set/Get whether the surface is lake.
402  virtual void setIsLake(bool onOff);
403  virtual bool isLake() const;
404 
405  // Set/Get whether the surface is river.
406  virtual void setIsRiver(bool onOff);
407  virtual bool isRiver() const;
408 
409  // Set/Get whether the surface is pond.
410  virtual void setIsPond(bool onOff);
411  virtual bool isPond() const;
412 
413  // Set/Get whether the surface is stream.
414  virtual void setIsStream(bool onOff);
415  virtual bool isStream() const;
416 
417  // Set/Get whether the surface is brook.
418  virtual void setIsBrook(bool onOff);
419  virtual bool isBrook() const;
420 
421  // Set/Get whether the surface is part of a tree.
422  virtual void setIsTree(bool onOff);
423  virtual bool isTree() const;
424 
425  // Set/Get whether the surface is part of a Building.
426  virtual void setIsBuilding(bool onOff);
427  virtual bool isBuilding() const;
429 
430 
431  // Set characteristics based on an exact match with a string.
432  virtual bool characteristicsFromString(std::string characteristicsString, bool warn = true);
433 
434  // Set characteristics based on any match with a substring of the specified
435  // characteristics string.
436  // \note This may cause the incorrect surface characteristics to be set, if
437  // the specified string contains more than one of the substrings searched for.
438  virtual bool characteristicsFromSubString(std::string characteristicsString, bool warn = true);
439 
440  // debugging aid
441  virtual void dump() const;
442 
443  // \return The maximum color of the surface
444  virtual void maxColor(DtColor& theColor);
445 
446  // \return The default color associated with the surface type
447  DtColor colorForSurfaceType() const;
448 
449  // input/output functions
450  virtual bool readFrom(FILE* fp);
451  // virtual bool readFromOldFormat(FILE* fp, DtTerrainDatabase* ptdb);
452  virtual bool writeTo(FILE* fp);
453 
454  static DtString soilTypeToString(DtRoughnessSoilType type);
455  static DtRoughnessSoilType stringToSoilType(const DtString& string);
456 
457 public:
458 
459  static DtSurface& nullSurface();
460 
461  static void setSurfaceToRoughnessMapper(DtMapSurfaceToRoughness&
462  surfaceToRoughnessMapper);
463 
466  static DtSurfaceCharacteristicStringMapper* surfaceCharacteristicStringMapper();
467  static DtSurfaceCharacteristicStringMapper* setSurfaceCharacteristicStringMapper(DtSurfaceCharacteristicStringMapper* mapper);
468 
469 public:
470 
471  static const DtColor theSoftSoilColor;
472  static const DtColor theSwampColor;
473  static const DtColor theMudColor;
474  static const DtColor theForestColor;
475  static const DtColor theGrassColor;
477  static const DtColor theOrchardColor;
478  static const DtColor theRockColor;
479  static const DtColor theBoulderColor;
480  static const DtColor theSandColor;
481  static const DtColor theDirtRoadColor;
486  static const DtColor theRailRoadColor;
488  static const DtColor theOceanColor;
489  static const DtColor theLakeColor;
490  static const DtColor theRiverColor;
491  static const DtColor thePondColor;
492 
493  static const DtColor theIceColor;
494  static const DtColor theTreeColor;
495  static const DtColor theBuildingColor;
496 
497  //Dted colors
500 
501  static const char DtSoilPavedRoad[];
502  static const char DtSoilHardPacked[];
503  static const char DtSoilRocks[];
504  static const char DtSoilSand[];
505  static const char DtSoilGravel[];
506  static const char DtSoilShallowWater[];
507  static const char DtSoilMuck[];
508  static const char DtSoilDeepWater[];
509 
510 protected:
511 
514 
517 
520 
523 
526 
529 
532 
535 
538 
541 
544 
547 
550 
553 
556 
559 
562 
565 
568 
571 
574 
577 
580 
583 
586 
589 
592 
593 protected:
594  // Custom function to lower the case of a string. Necessary since the tolower
595  // function (from locale) needs to have a locale specified. Defaults to using
596  // the classic C locale, which is for ASCII.
597  std::string customToLower(const std::string& stringToConvert, const std::locale loc = std::locale::classic()) const;
598 
599  // Removes any white spaces on the right side of the string
600  std::string trimString(const std::string& strToTrim);
601 
602  virtual void setRoughnessSoilType();
603 
608 };
609 
610 inline const DtColor& DtSurface::color() const
611 {
612  return myColor;
613 }
614 
615 inline void DtSurface::setColor(const DtColor& c)
616 {
617  myColor = c;
618 }
619 
621 {
622  return myCharacteristics;
623 }
624 
626 {
627  myCharacteristics = surfChar;
629 }

Document ID: Generated on Fri Apr 26 21:53:14 EDT 2019 from SVN revision 197883
Copyright © 2005-2019 VT MAK. All Rights Reserved (www.mak.com)