VR-Forces 4.6 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
c4bReader.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2003 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 /*******************************************************************************
6 ** $RCSfile: c4b.h,v $ $Revision: 1.21 $ $State: Exp $
7 *******************************************************************************/
8 
9 #ifndef c4b_H
10 #define c4b_H
11 
12 #include "ctdb/ctdbDefines.h"
13 #include <vlutil/vlNetTypes.h>
14 
15 #include <vlutil/vlPrint.h>
16 
17 #include "geometry/point.h"
18 #include "gdb/gdbNode.h"
19 #include "gdb/group.h"
20 #include "gdb/feature.h"
21 #include "gdb/gridPostList.h"
22 #include "gdb/surfaceManager.h"
23 #include "geometry/surface.h"
24 #include "gdb/terrainReader.h"
25 
26 #include "gdb/terrainDatabase.h"
27 
28 #define DO_CANOPIES
29 #define DO_TREES
30 #define DO_TREELINES
31 #define DO_LINEAR_FEATURES
32 #define DO_BUILDINGS
33 #define DO_GRID_POSTS
34 #define DO_TINS
35 #define DO_MICRO_TERRAIN
36 
37 
38 static const int CTDB_N_SOILS = 16;
39 
40 static const int DATUM_ED50 = 0;
41 static const int DATUM_ED79 = 1;
42 static const int DATUM_WGS72 = 2;
43 static const int DATUM_WGS84 = 3;
44 static const int DATUM_CONUSNAD27 = 4;
45 static const int DATUM_NASBNAD27 = 5;
46 static const int DATUM_NASANAD27 = 6;
47 static const int DATUM_NAD83 = 7;
48 static const int DATUM_ADINDAN = 8;
49 static const int DATUM_ARC50 = 9;
50 static const int DATUM_AUSTRALIAN = 10;
51 static const int DATUM_BUKITRIMPAH = 11;
52 static const int DATUM_CAMPAREAASTRO = 12;
53 static const int DATUM_DJAKARTA = 13;
54 static const int DATUM_GEOD49 = 14;
55 static const int DATUM_GUAM63 = 15;
56 static const int DATUM_GUNUNGSEGARA = 16;
57 static const int DATUM_HERATNORTH = 17;
58 static const int DATUM_HJORSEY55 = 18;
59 static const int DATUM_INDIAN = 19;
60 static const int DATUM_IRELAND65 = 20;
61 static const int DATUM_KERTAU48 = 21;
62 static const int DATUM_LIBERIA64 = 22;
63 static const int DATUM_LUZON = 23;
64 static const int DATUM_MERCHICH = 24;
65 static const int DATUM_NIGERIA = 25;
66 static const int DATUM_ALASKACANADA27 = 26;
67 static const int DATUM_MAUI = 27;
68 static const int DATUM_OAHU = 28;
69 static const int DATUM_KAUAI = 29;
70 static const int DATUM_GREATBRITAIN36 = 30;
71 static const int DATUM_QORNOQ = 31;
72 static const int DATUM_SACAMPOINCHAUSPE = 32;
73 static const int DATUM_SACHUAASTRO = 33;
74 static const int DATUM_SACORREGOALEGRE = 34;
75 static const int DATUM_SAPROVISIONAL56 = 35;
76 static const int DATUM_SAYACARE = 36;
77 static const int DATUM_TAMANARIVEOBSV25 = 37;
78 static const int DATUM_TIMBOLAI48 = 38;
79 static const int DATUM_TOKYO = 39;
80 
81 static const int CTDB_PATCH_CACHES = 16;
82 static const int CTDB_NAME_LENGTH = 14;
83 static const int CTDB_DATE_LENGTH = 28;
84 static const int CTDB_HEADER_RESERVED = 10;
85 
86 class DtC4bReader;
87 
88 DT_DLL_ctdb double scale_to_patch(double bar);
89 
90 /*
91  * Class definitions.
92  */
93 
95 {
96  public:
97 
98  bool is_curved();
99  bool is_sw_ne();
100  bool is_gridded();
101  bool is_tinned();
102  void describe();
103 
104  private:
105 
106  DtNetU32 raw_bits;
107 };
108 
109 
110 /*
111  * These values were determined from a combination of s1000 and modsaf rdr files.
112  */
113 
114 typedef enum
115 {
116  C4B_SOIL_NON_C4B_SOIL = 0, // Unknown type of soil
117  C4B_SOIL_ROAD = 1, // Asphalt or other hard surface
118  C4B_SOIL_RCI250 = 2, // Packed soil or dirt road
119  C4B_SOIL_RCI050 = 3, // Soft sandy soil
120  C4B_SOIL_DEEP_WATER = 4, // Impassable deep water
121  C4B_SOIL_SHALLOW_WATER = 5, // Passable shallow water
122  C4B_SOIL_MUD = 6, // Muddy soil
123  C4B_SOIL_MUDDY_ROAD = 7, // Wet dirt road
124  C4B_SOIL_ICE = 8, // Slick ice surface
125  C4B_SOIL_SWAMP = 9, // Very soft surface
126  C4B_SOIL_FORRESTED = 10, // Canopy or forrested area
127  C4B_SOIL_US_RAILROAD = 11, // Railroad w/ US specifications
128  C4B_SOIL_EURO_RAILROAD = 12, // Railroad w/ European specs.
129  C4B_SOIL_ROCKY = 13, // Small rocks <= 18 inches
130  C4B_SOIL_BOULDERS = 14, // Large boulders 6 ft. high
131 
132  // Weird, eh? (What a kludge.)
133 
134  C4B_SOIL_FLIMSY = 15, // Indoor surface for DI
135  C4B_SOIL_NO_GO = 15 // General No Go Terrain for NTC
136 
138 
139 
140 
141 
143 {
144  public:
145 
146  bool is_water();
147  bool is_no_go();
148  bool is_slow_go();
149  bool is_road();
150  unsigned int CCTT_constant();
151  c4b_s1000_soil_type SIMNET_constant();
152  void describe();
153 
154  private:
155 
156  DtNetU32 raw_bits;
157 };
158 
159 
161 {
162  public:
163  bool read(FILE *fp);
164  void describe();
165 
166  DtNetInt32 format;
168  DtNetFloat64 fixed_point_basis;
170  DtNetInt32 post_increment;
172  DtNetInt32 pages_wide;
173  DtNetInt32 pages_high;
174  DtNetInt32 min_x;
175  DtNetInt32 max_x;
176  DtNetInt32 min_y;
177  DtNetInt32 max_y;
178  DtNetInt32 num_features; // physical features
179  DtNetInt32 patch_cache_size_map[CTDB_PATCH_CACHES];
180  DtNetInt32 pad2;
181  DtNetFloat64 origin_northing;
182  DtNetFloat64 origin_easting;
183  DtNetInt32 origin_zone_number;
184  DtNetInt32 origin_zone_letter;
185  DtNetInt32 datum;
186  DtNetU8 name[CTDB_NAME_LENGTH];
187  DtNetInt16 version;
188  DtNetU8 date[CTDB_DATE_LENGTH];
189  DtNetInt32 num_nodes;
190  DtNetInt32 node_size;
191  DtNetInt32 num_edges;
192  DtNetInt32 edge_size;
193  DtNetInt32 num_quad_data; // abstract features
194  DtNetInt32 n_patch_bytes;
195  DtNetInt32 reserved[CTDB_HEADER_RESERVED];
196 };
197 
198 
199 /*
200  * Patch group headers.
201  */
203 {
204  public:
205 
206  unsigned int cache();
207  bool mapped();
208  bool contains_tins();
209  bool patch0_occupied();
210  bool patch0_dyn_terr();
211  bool patch0_ta16();
212  bool patch0_no_tas();
213  bool patch1_occupied();
214  bool patch1_dyn_terr();
215  bool patch1_ta16();
216  bool patch1_no_tas();
217  bool patch2_occupied();
218  bool patch2_dyn_terr();
219  bool patch2_ta16();
220  bool patch2_no_tas();
221  bool patch3_occupied();
222  bool patch3_dyn_terr();
223  bool patch3_ta16();
224  bool patch3_no_tas();
225  unsigned int unused();
226 
227  bool read(FILE* fp);
228  void describe();
229 
230  unsigned int offset();
231 
232  private:
233 
234  DtNetU32 data_start; // byte offset for patch group's data fromstart of all patch group data
235  DtNetU32 raw_bits;
236 };
237 
238 
240 {
241  public:
242 
243  c4b_patch_group_headers(unsigned int num_patch_groups);
244 
245  int num_in_x;
246  int num_in_y;
248 
250 
251  bool read(FILE* fp, bool debug = false);
252 };
253 
254 
255 
256 /*
257  * Topology -- Nodes.
258  */
260 {
261  public:
262 
263  bool is_bridge();
264  unsigned int padding();
265  DtU8 num_connections();
266 
267  void describe();
268 
269  private:
270  DtNetU32 raw_bits;
271 };
272 
274 {
275  public:
276 
277  int Node();
278  int Edge();
279 
280  bool read(FILE* fp);
281  void describe();
282 
283  private:
284 
285  DtNetInt32 node;
286  DtNetInt32 edge;
287 };
288 
290 {
291  public:
292 
293  DtFloat32 X();
294  DtFloat32 Y();
295  bool read(FILE* fp);
296  void describe();
297 
300 
301  private:
302 
303  DtNetFloat32 x;
304  DtNetFloat32 y;
305 };
306 
307 
308 /*
309  * Topology -- Edges.
310  */
312 {
313  public:
314 
315  unsigned int patch_offset();
316  unsigned int quad_offset();
317  bool reverse();
318  unsigned int padding();
319  bool is_abstract_feature();
320 
321  bool read(FILE *fp);
322  void describe();
323 
324  private:
325 
326  DtNetU32 patch_number;
327  DtNetU32 raw_bits;
328 };
329 
331 {
332  public:
333 
334  bool read(FILE *fp);
335  void describe();
336 
337  private:
338 
339  DtNetInt32 distance;
340  DtNetInt32 first_node;
341  DtNetInt32 last_node;
342  DtNetInt32 num_features;
343 
345 };
346 
347 
348 /*
349  * Abstract features.
350  */
352 {
353  public:
354 
355  bool read(FILE *fp);
356  void describe();
357 
358  private:
359 
360  DtNetU8 type_code;
361  DtNetU8 data_size; // 4 byte units
362  DtNetU16 num_vertices;
363 };
364 
365 
366 /*
367  * Feature data.
368  */
370 {
371  public:
372 
373  void describe();
374 
375  void SetVec(DtPoint &v);
376  double X();
377  double Y();
378 
379  private:
380 
381  DtNetU16 x;
382  DtNetU16 y;
383 };
384 
386 {
387  public:
388 
389  DtU16 Size();
390  void describe();
391 
392  private:
393 
394  DtNetU16 size; // number of CTDB_FEATURE_DATA things in this patch (incl this hdr)
395  DtNetU16 pad;
396 };
397 
398 
399 static const int FT_MICRO = 0;
400 static const int FT_BUILDING = 1;
401 static const int FT_TREE = 2;
402 static const int FT_CANOPY = 3;
403 static const int FT_LINEAR = 4;
404 
406 {
407  public:
408 
409  DtU8 FeatureType();
410  DtU8 Vertices();
411  unsigned int PostMask();
412  DtU8 MicroTerrainType();
413 
414  void describe();
415 
416  private:
417 
418  DtNetU32 raw_bits;
419 };
420 
421 
422 static const int CTDB_EDGE_KEY = 4096;
423 
425 {
426  public:
427 
428  double Width();
429  DtU8 Soil();
430  DtU16 EdgeKey();
431 
432  void describe();
433 
434  private:
435 
436  DtNetU16 width;
438 };
439 
440 
442 {
443  public:
444 
445  double Radius();
446  bool First();
447  bool Last();
448  double Height();
449  void describe();
450 
451  private:
452 
453  DtNetU16 radius;
455 };
456 
457 
459 {
460  public:
461 
462  DtU8 Soil0();
463  DtU8 Soil1();
464  DtU8 Vert0();
465  DtU8 Vert1();
466  DtU8 Vert2();
467 
468  void describe();
469 
470  private:
472  DtNetU8 vert0;
473  DtNetU8 vert1;
474  DtNetU8 vert2;
475 };
476 
477 
478 /*
479  * Grid post.
480  */
482 {
483  public:
484 
485  DtU8 soil_of_northern_tri();
486  DtU8 soil_of_southern_tri();
487  bool either_tri_has_features();
488  bool either_tri_has_buildings();
489  bool either_tri_has_trees_or_treelines();
490  bool either_tri_has_microterrain();
491  int scaled_elevation();
492 
493  bool read(FILE* fp);
494  void describe();
495 
496  private:
497 
498  DtNetU32 raw_bits;
499 };
500 
501 
502 /*
503  * Patch Terrain Elements.
504  */
506 {
507  public:
508 
509  void describe();
510 
511  DtU8 Blank1() { return((bvp&0xc0) >> 6); };
512  DtU8 Vertices() { return((bvp&0x30) >> 4); };
513  DtU8 PatchAdj() { return((bvp&0x0f)); };
514 
515  DtU8 Soil0() { return(soil0); };
516  DtU8 Soil1() { return(soil1); };
517  DtU8 AdjSides() { return(adj_sides); };
518 
519  private:
520 
521  DtNetU8 bvp;
522  DtNetU8 soil0;
523  DtNetU8 soil1;
524  DtNetU8 adj_sides;
525 };
526 
527 
528 
529 static const int TE_VERT_DIMENSION = 3;
530 static const int TE_ADJ_TRI_MAP_DIMENSION = 4;
531 template<class Type>class c4b_terrain_element
532 {
533  public:
534 
535  void describe()
536  {
537  DtInfo("template c4b_terrain_element::describe\n");
538 
539  DtInfo(" ");
540  pt.describe();
541 
542  double native_z = (double)z;
543  DtInfo(" ");DtInfo("z=%lf\n", native_z);
544 
545  DtInfo(" ");
546  vert.describe();
547 
548  DtInfo(" ");
549  info.describe();
550  }
551 
553  {
554  public:
555 
556  void describe()
557  {
558  DtInfo("c4b_assoc_vertex: ");
559 
560  for (int i = 0; i < TE_VERT_DIMENSION; i++)
561  {
562  DtInfo(" index[%d]=%u,", i, (DtU16) index[i]);
563  }
564  DtInfo("\n");
565  }
566 
568  Type padding1;
569  };
570 
572  DtNetFloat32 z;
576 };
577 
580 
581 
582 static const int CTDB_PATCHES_PER_GROUP = 4;
583 static const int CTDB_MAX_POSTS_PER_PATCH = 16;
584 /*
585  *
586  */
588 {
589 public:
590 
591  DtU16 Patch1Offset();
592  DtU16 Patch2Offset();
593  DtU16 Patch3Offset();
594  void describe();
595 
596 // private:
597 
598  DtNetFloat32 max_elev[CTDB_PATCHES_PER_GROUP];
599  // In 32-bit words.
600  DtNetU16 patch1_offset;
601  DtNetU16 patch2_offset;
602  DtNetU16 patch3_offset;
603  DtNetU16 unused;
604  DtNetU8 feature_present[CTDB_MAX_POSTS_PER_PATCH * 2];
605  DtNetU16 num_te[CTDB_PATCHES_PER_GROUP];
606  DtNetU32 te_offset[CTDB_PATCHES_PER_GROUP];
607  DtNetU8 te_vgrid_dim[CTDB_PATCHES_PER_GROUP];
608  DtNetU32 te_vgrid_offset[CTDB_PATCHES_PER_GROUP];
609 };
610 
611 
613 {
614 public:
615 
616  DtU16 Patch1Offset();
617  DtU16 Patch2Offset();
618  DtU16 Patch3Offset();
619  void describe();
620 
621 private:
622 
623  DtNetFloat32 max_elev[CTDB_PATCHES_PER_GROUP];
624  // In 32-bit words.
625  DtNetU16 patch1_offset;
626  DtNetU16 patch2_offset;
627  DtNetU16 patch3_offset;
628  DtNetU16 unused;
629 };
630 
631 
632 class C4B;
633 class DtC4bPatchGroup;
634 
636 {
637 public:
638 
639  void parse(C4B &c4b,
640  progressCallbackStartFunction *prog_start_fcnp,
641  progressCallbackSetValueFunction *prog_set_value_fcnp,
642  progressCallbackEndFunction *prog_end_fcnp);
643  void parse_soil_types(C4B &c4b);
644  void parse_grid_posts(C4B &c4b);
645  void xlate(C4B &c4b,
646  DtC4bReader* tdb,
647  progressCallbackStartFunction *prog_start_fcnp,
648  progressCallbackSetValueFunction *prog_set_value_fcnp,
649  progressCallbackEndFunction *prog_end_fcnp);
650  void xlate_soil_types(c4b_file_header &hdr);
651 
652  virtual DtC4bReader* reader() const;
653  virtual void setReader(DtC4bReader* reader);
654 
655  // increment the feature count of the terrain database as each new feature
656  // is created, and return the updated count.
657  int incrementTdbFeatureCount();
658 
661 
665 
668 
670  int myTdbFeatureCount; // feature count in terrain database.
671 };
672 
673 
674 inline DtC4bReader* DtC4b::reader() const
675 {
676  return myReader;
677 }
678 
679 
680 inline void DtC4b::setReader(DtC4bReader* reader)
681 {
682  assert(reader != 0);
683  myReader = reader;
684 }
685 
686 
688 {
689  return(++myTdbFeatureCount);
690 }
691 
692 
693 /*
694  *
695  */
697 {
698  public:
699 
700  bool read(FILE* fp,
701  progressCallbackStartFunction* prog_start_fcnp,
702  progressCallbackSetValueFunction* prog_set_value_fcnp,
703  progressCallbackEndFunction* prog_end_fcnp);
704  void describe();
705 
706  void xlate(DtC4bReader* tdb,
707  progressCallbackStartFunction* prog_start_fcnp,
708  progressCallbackSetValueFunction* prog_set_value_fcnp,
709  progressCallbackEndFunction* prog_end_fcnp);
710 
711  unsigned int patch0_number_from_patch_group_number(unsigned int patch_group_num);
712 
713  bool read_patch_group_headers(bool debug = false);
714  bool read_nodes(bool debug = false);
715  bool read_edges(bool debug = false);
716  bool read_feature_data();
717  bool read_grid_posts(bool debug = false);
718  bool read_all_patch_data(bool debug = false);
719 
720  // returns a pointer to a memory manager class that handles
721  // allocations of a group of objects (polygons, groups, grids,
722  // features, etc.)
723  virtual DtC4bReader* reader() const;
724 
725  FILE* fp;
726 
731 
733 
734  unsigned int num_grid_posts;
735 
736  DtU8* patch_data;
737 
738  // Derived stuff.
739  void unpack();
740  unsigned int num_pages;
741  unsigned int num_patches;
742  unsigned int num_patch_groups;
743  unsigned int num_patches_wide;
744  unsigned int num_patches_high;
745  unsigned int num_posts_wide;
746 
748 };
749 
750 
751 inline DtC4bReader* C4B::reader() const
752 {
753  return(parsed_c4b.reader());
754 }
755 
756 
757 
758 /*
759  * Compact Terrain Database Format 4
760  */
761 class DtMetafileRecord;
762 
764 {
765 public:
766 
767  DtC4bReader();
768 
769  virtual ~DtC4bReader();
770 
771  // Override to set ourselves as the reader in my_ctdb, after calling
772  // down to base class version.
773  virtual void init(const DtFilename& filename,
774  DtTerrainDatabase* terrain);
775 
776  // Loads terrain database file named filename, returning the data in
777  // terrain. The terrain pointer passed in must be initialized before calling
778  // loadTerrain.
779  virtual bool loadTerrain(const DtFilename& filename,
780  DtTerrainDatabase* terrain);
781 
782  // Loads terrain database file named filename, returning the data in
783  // terrain. The initializer object is used to pass in additional information
784  // about the terrain to be loaded. The terrain pointer passed in must be
785  // initialized before calling loadTerrain.
786  virtual bool loadTerrain(const DtFilename& filename,
787  DtTerrainDatabase* terrain,
788  const DtTerrainInitializer* initializer);
789 
790  // Returns "c4b"
791  virtual const DtString dataType() const;
792 
794 
795  static DtTerrainReader* create();
796 
797  // Returns only the coordinate system that would define this database. Should not load
798  // any polygonal or vector information
799  virtual Coordinate_System* coordinateSystem(const DtFilename& filename);
800 
801  virtual int optionalFileFlags(const DtFilename& filename)
802  {
803  return 0;
804  }
805 
806 protected:
807 
808  bool read(const DtFilename& filename);
809  bool import();
810 };
811 
812 #endif
813 

Document ID: Generated on Thu Apr 12 03:15:37 EDT 2018 from SVN revision 187986
Copyright © 2005-2018 VT MÄK. All Rights Reserved (www.mak.com)