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

Document ID: Generated on Thu Oct 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)