VR-Forces 4.1 Class Documentation
mgwrapper.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2011 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 #pragma once
6 
9 #include "flt/fltTerrainInit.h"
10 #include "flt/tdbflt.h"
11 #include "geometry/gdbColor.h"
12 #include "geometry/point.h"
13 #include <string>
14 #include "vlutil/vlString.h"
15 #include "gdb/group.h"
16 
17 struct mgrec;
18 
20 {
21 public:
22  DtMgWrapper();
23  virtual ~DtMgWrapper();
24  virtual bool readDfdFile(DtFilename filename, DtDfadData &data) const;
25  // Given an OpenFlight filename, this returns the "translated" file.
26  virtual DtGdbNode* xlateOpenFlightFile(const DtFilename& filename);
27 
28  static void initMGAPI();
29  static void exitMGAPI();
30 
31  virtual void setUseFltPath(const DtString&);
32  virtual const DtString& useFltPath() const;
33 
34 protected:
35 
36  typedef enum
37  {
38  FlatEarth = 0, // = 0
39  Trapezoidal, // = 1
40  RoundEarth, // = 2
41  Lambert, // = 3
42  UTM, // = 4
43  Geocentric, // = 5
44  Geodetic // = 6
45  } DtFltProjectionType;
46 
47  typedef enum
48  {
49  Meters = 0,
50  Kilometers = 1,
51  Feet = 4,
52  Inches = 5,
53  NauticalMiles = 8
54  } DtFltVertexCoordinateUnits;
55 
56  typedef enum
57  {
58  // The OpenFlight 15.8 docs claim that user defined is supposed to be 5,
59  // but I just confirmed with their tech support that it is actually -1.
60  UserDefinedEllipsoid = -1,
61  WGS_1984 = 0,
65  NAD_1927
66  } DtFltEarthEllipsoidModel;
67 
68  // This routine will take a flt load path and translate it into a tree that
69  // can be referenced when loading flt nodes. Any node that does not appear
70  // in the tree will not be loaded. The results are placed into the myFltPath
71  // member
72  virtual void parseFltPathIntoPathTree(const std::string& fltPath,
73  DtFltPathMap* fltPathMap);
74 
75 
76  // The reason we index by name instead of pattern# is that I THINK
77  // different externally-referenced databases may have different pattern#s
78  // (palette indices) for a given texture, but are unlikely to use
79  // different names.
80  //
81  bool rememberColorFromTextureName(const DtFilename& name, DtColor& color);
82 
83  // Book-keeping for already opened and translated databases.
84  // DtGdbNode* lookupAlreadyTranslatedDatabase(const DtFilename& filename,
85  // double lodDistance);
86 
87  // void addTranslatedDatabase(const DtFilename& fname, DtGdbNode* n,
88  // double lodDistance);
89 
90  bool computeColorFromTexture(mgrec* mgdb, int texturePatternNumber,
91  DtColor& color);
92  bool computeAndRememberColorFromTexture(mgrec* mgdb,
93  const DtFilename& tex_name, int texture_pattern_number, DtColor& color);
94  FlightTextureNameToColorListItem* lookupAlreadyAveragedColor(const DtFilename&);
95 
96  // Performs color-averaging of texture, and sets color appropriately.
97  bool setColorFromTexture(mgrec* mgdb, int texturePatternNumber, DtColor& color);
98 
99  // If you're using a TM projection that's not UTM and you made your
100  // flight file with Creator, then you'll need this function;
101  // Converts your garden variety UTM coord into an exotic coord as specified
102  // by the mapdatum and projection scale you defined in you flight map file.
103  void changeFromUTMToUserDefinedProjection(const DtPoint &v0, DtPoint &result);
104 
105  // Returns true if the node passes the path check (it has no children,
106  // there is no path, or it is in the path). Pass in iterator if want to
107  // receive children of that node
108  virtual bool passPathCheck(mgrec* node, const DtFltPathMap& fltPathMap,
109  DtFltPathMap::const_iterator* iter = 0);
110 
111  // Converts from source units to meters. Supported types are inches, ft, km and nmi
112  virtual void convertFromSourceToMeters(const DtPoint& in, DtPoint& out);
113 
114  // General entry point to process any primitive present in a mesh node
115  // \return A boolean indicating whether or not the primitive could be processed.
116  bool processPrimitive(mgrec* mgmesh, DtGroup* parentGroup, unsigned int ithPrimitive);
117 
118  // Processes a triangle strip primitive, which is typically present in mesh nodes
119  bool processTriangleStrip(mgrec* mgmesh, DtGroup* parentGroup, unsigned int ithPrimitive);
120 
121 
122  // Each of these translates a particular type of OpenFlight "bead" or record.
123 
124  DtGdbNode* xlate_eFltLod(mgrec* mgdb, mgrec* mglod, const DtFltPathMap& path);
125  DtGdbNode* xlate_eFltXref(mgrec* mgdb, mgrec* mgexternalref);
126  DtGdbNode* xlate_eFltObject(mgrec* mgdb, mgrec* mgobject, const DtFltPathMap& path);
127  DtGdbNode* xlate_eFltGroup(mgrec* mgdb, mgrec* mggroup, const DtFltPathMap& path);
128  DtGdbNode* xlate_eFltSwitch(mgrec* mgdb, mgrec* mggroup, const DtFltPathMap& path);
129  DtGdbNode* xlate_eFltDof(mgrec* mgdb, mgrec* mggroup, const DtFltPathMap& path);
130  DtGdbNode* xlate_eFltHeader(mgrec* mgdb, mgrec* mgheader, const DtFltPathMap& path);
131  DtGdbNode* xlate_eFltMesh(mgrec* mgdb, mgrec* mgnode);
132 
133  // returns a DtGdbNode because it may return either an indirect polygon or triangle
134  DtGdbNode* xlate_poly(mgrec* mgdb,
135  mgrec* mgpolygon,
136  mgrec* mgv0,
137  mgrec* mgv1,
138  mgrec* mgv2,
139  mgrec* mgv3 = 0);
140 
141  DtGdbNode* xlate_eFltPolygon(mgrec* mgdb, mgrec* mgpolygon);
142  DtGdbNode* xlate_eFltIbead(mgrec* mgdb, mgrec* mgpolygon, const DtFltPathMap&);
143 
144  // Given any OpenFlight bead we know about, this calls the right translator
145  // routine.
146  DtGdbNode* xlateOpenFlightNode(mgrec* mgdb, mgrec* node, const DtFltPathMap&);
147 
148  // Prepends static coord sys to already_translated_m if mgrec has general
149  // transformation.
150 
151  DtGdbNode* xlate_fltMatrixIfAny(mgrec* m, DtGdbNode* already_translated_m);
152 
153 
154  // If there are any group children, this function adds them as children of the
155  // specified parentGroup. If the parentGroup parameter is 0, then a new
156  // DtGroup node is allocated. If the desiredChildIndex is specifed to anything
157  // other than 0, then only the child node at the specified index will be imported,
158  // if it exists.
159  //
160  // \return The number of successfully imported children, if any.
161  unsigned int xlateGroupChildrenIfAny(mgrec* mgdb, mgrec* mggroup,
162  DtGroup*& parentGroup, const DtFltPathMap& flightPathMap,
163  unsigned int desiredChildIndex = 0);
164 
165  // Tests the specified child index against the specified desired child index.
166  // If the desired index is 0, or if the specified child index matches the
167  // specified non-zero desired index, then the child should be imported and the
168  // function returns true. If the child index does not match the desired index,
169  // then the child is skipped.
170  // \note When importing normal group nodes, the desired index defaults to zero
171  // so that we import all child nodes. However, when importing switch nodes,
172  // if the user has specified a specific child as the one to import, then that
173  // is the only one imported.
174  bool importChild(unsigned int childIndex, unsigned int desiredIndex) const;
175 
176 
177  static bool myInitMgApi;
178  unsigned char myUnits;
179 
180  //FlightTranslatedDatabaseListItem* myAlreadyXlatedDatabases;
181 
185  // If path is specified in flt initializer, that will be used if this path is empty
188  // List of all surfaces that were not found during load
189  std::map<DtString, int> myErrorSurfaces;
190 
191  std::map<DtString, bool> myAlreadyColorWarned;
192 };
193 
195 {
196  return (DtMgWrapperInterface*) new DtMgWrapper();
197 }
198 
200 {
201  delete mwi;
202 }

Document ID: Generated on Tue Jan 29 18:21:16 EST 2013 from SVN revision 123193
Copyright © 2005-2013 VT MÄK Inc. All Rights Reserved (www.mak.com)