VR-Forces 4.0.4 Class Documentation
include/mgwrapper/mgwrapper.h
Go to the documentation of this file.
00001 /*******************************************************************************
00002 ** Copyright (c) 2011 MAK Technologies, Inc.
00003 ** All rights reserved.
00004 *******************************************************************************/
00005 #pragma once
00006 
00007 #include "mgwrapper/mgwrapperDefines.h"
00008 #include "flt/mgWrapperInterface.h"
00009 #include "flt/fltTerrainInit.h"
00010 #include "flt/tdbflt.h"
00011 #include "geometry/gdbColor.h"
00012 #include "geometry/point.h"
00013 #include <string>
00014 #include "vlutil/vlString.h"
00015 #include "gdb/group.h"
00016 
00017 struct mgrec;
00018 
00019 class DT_DLL_mgwrapper DtMgWrapper : public DtMgWrapperInterface
00020 {
00021 public:
00022    DtMgWrapper();
00023    virtual ~DtMgWrapper();
00024    virtual bool readDfdFile(DtFilename filename, DtDfadData &data) const;
00025    // Given an OpenFlight filename, this returns the "translated" file.
00026    virtual DtGdbNode* xlateOpenFlightFile(const DtFilename& filename);
00027 
00028    static void initMGAPI();
00029    static void exitMGAPI();
00030 
00031    virtual void setUseFltPath(const DtString&);
00032    virtual const DtString& useFltPath() const;
00033 
00034 protected:
00035 
00036    typedef enum
00037    {
00038       FlatEarth = 0,    // = 0
00039       Trapezoidal,      // = 1
00040       RoundEarth,       // = 2
00041       Lambert,          // = 3
00042       UTM,              // = 4
00043       Geocentric,       // = 5
00044       Geodetic          // = 6
00045    } DtFltProjectionType;
00046 
00047    typedef enum
00048    {
00049       Meters = 0,
00050       Kilometers = 1,
00051       Feet = 4,
00052       Inches = 5,
00053       NauticalMiles = 8
00054    } DtFltVertexCoordinateUnits;
00055 
00056    typedef enum
00057    {
00058       // The OpenFlight 15.8 docs claim that user defined is supposed to be 5,
00059       // but I just confirmed with their tech support that it is actually -1.
00060       UserDefinedEllipsoid = -1,
00061       WGS_1984 = 0,
00062       WGS_1972,
00063       Bessel,
00064       Clark,
00065       NAD_1927
00066    } DtFltEarthEllipsoidModel;
00067 
00068    // This routine will take a flt load path and translate it into a tree that 
00069    // can be referenced when loading flt nodes.  Any node that does not appear 
00070    // in the tree will not be loaded.  The results are placed into the myFltPath 
00071    // member
00072    virtual void parseFltPathIntoPathTree(const std::string& fltPath, 
00073       DtFltPathMap* fltPathMap);
00074 
00075 
00076    // The reason we index by name instead of pattern# is that I THINK
00077    // different externally-referenced databases may have different pattern#s
00078    // (palette indices) for a given texture, but are unlikely to use
00079    // different names.
00080    //
00081    bool rememberColorFromTextureName(const DtFilename& name, DtColor& color);
00082 
00083    // Book-keeping for already opened and translated databases.
00084    //   DtGdbNode* lookupAlreadyTranslatedDatabase(const DtFilename& filename,
00085    //      double lodDistance);
00086 
00087    //   void addTranslatedDatabase(const DtFilename& fname, DtGdbNode* n,
00088    //      double lodDistance);
00089 
00090    bool computeColorFromTexture(mgrec* mgdb, int texturePatternNumber,
00091       DtColor& color);
00092    bool computeAndRememberColorFromTexture(mgrec* mgdb,
00093       const DtFilename& tex_name, int texture_pattern_number, DtColor& color);
00094    FlightTextureNameToColorListItem* lookupAlreadyAveragedColor(const DtFilename&);
00095 
00096    // Performs color-averaging of texture, and sets color appropriately.
00097    bool setColorFromTexture(mgrec* mgdb, int texturePatternNumber, DtColor& color);
00098 
00099    // If you're using a TM projection that's not UTM and you made your
00100    // flight file with Creator, then you'll need this function;
00101    // Converts your garden variety UTM coord into an exotic coord as specified
00102    // by the mapdatum and projection scale you defined in you flight map file.
00103    void changeFromUTMToUserDefinedProjection(const DtPoint &v0, DtPoint &result);
00104 
00105    // Returns true if the node passes the path check (it has no children, 
00106    // there is no path, or it is in the path).  Pass in iterator if want to 
00107    // receive children of that node
00108    virtual bool passPathCheck(mgrec* node, const DtFltPathMap& fltPathMap, 
00109       DtFltPathMap::const_iterator* iter = 0);
00110 
00111    // Converts from source units to meters.  Supported types are inches, ft, km and nmi
00112    virtual void convertFromSourceToMeters(const DtPoint& in, DtPoint& out);
00113 
00114    // General entry point to process any primitive present in a mesh node
00115    // \return A boolean indicating whether or not the primitive could be processed.
00116    bool processPrimitive(mgrec* mgmesh, DtGroup* parentGroup, unsigned int ithPrimitive);
00117 
00118    // Processes a triangle strip primitive, which is typically present in mesh nodes
00119    bool processTriangleStrip(mgrec* mgmesh, DtGroup* parentGroup, unsigned int ithPrimitive);
00120 
00121 
00122    // Each of these translates a particular type of OpenFlight "bead" or record.
00123 
00124    DtGdbNode* xlate_eFltLod(mgrec* mgdb, mgrec* mglod, const DtFltPathMap& path);
00125    DtGdbNode* xlate_eFltXref(mgrec* mgdb, mgrec* mgexternalref);
00126    DtGdbNode* xlate_eFltObject(mgrec* mgdb, mgrec* mgobject, const DtFltPathMap& path);
00127    DtGdbNode* xlate_eFltGroup(mgrec* mgdb, mgrec* mggroup, const DtFltPathMap& path);
00128    DtGdbNode* xlate_eFltSwitch(mgrec* mgdb, mgrec* mggroup, const DtFltPathMap& path);
00129    DtGdbNode* xlate_eFltDof(mgrec* mgdb, mgrec* mggroup, const DtFltPathMap& path);
00130    DtGdbNode* xlate_eFltHeader(mgrec* mgdb, mgrec* mgheader, const DtFltPathMap& path);
00131    DtGdbNode* xlate_eFltMesh(mgrec* mgdb, mgrec* mgnode);
00132 
00133    // returns a DtGdbNode because it may return either an indirect polygon or triangle 
00134    DtGdbNode* xlate_poly(mgrec* mgdb, 
00135       mgrec* mgpolygon,
00136       mgrec* mgv0, 
00137       mgrec* mgv1, 
00138       mgrec* mgv2, 
00139       mgrec* mgv3 = 0);
00140 
00141    DtGdbNode* xlate_eFltPolygon(mgrec* mgdb, mgrec* mgpolygon);
00142    DtGdbNode* xlate_eFltIbead(mgrec* mgdb, mgrec* mgpolygon, const DtFltPathMap&);
00143 
00144    // Given any OpenFlight bead we know about, this calls the right translator
00145    // routine.
00146    DtGdbNode* xlateOpenFlightNode(mgrec* mgdb, mgrec* node, const DtFltPathMap&);
00147 
00148    // Prepends static coord sys to already_translated_m if mgrec has general
00149    // transformation.
00150 
00151    DtGdbNode* xlate_fltMatrixIfAny(mgrec* m, DtGdbNode* already_translated_m);
00152 
00153 
00154    // If there are any group children, this function adds them as children of the
00155    // specified parentGroup.  If the parentGroup parameter is 0, then a new
00156    // DtGroup node is allocated.  If the desiredChildIndex is specifed to anything
00157    // other than 0, then only the child node at the specified index will be imported,
00158    // if it exists.  
00159    // 
00160    // \return The number of successfully imported children, if any.
00161    unsigned int xlateGroupChildrenIfAny(mgrec* mgdb, mgrec* mggroup, 
00162       DtGroup*& parentGroup, const DtFltPathMap& flightPathMap, 
00163       unsigned int desiredChildIndex = 0);
00164 
00165    // Tests the specified child index against the specified desired child index.
00166    // If the desired index is 0, or if the specified child index matches the 
00167    // specified non-zero desired index, then the child should be imported and the
00168    // function returns true.  If the child index does not match the desired index,
00169    // then the child is skipped.  
00170    // \note When importing normal group nodes, the desired index defaults to zero
00171    // so that we import all child nodes.  However, when importing switch nodes,
00172    // if the user has specified a specific child as the one to import, then that
00173    // is the only one imported.
00174    bool importChild(unsigned int childIndex, unsigned int desiredIndex) const;
00175 
00176 
00177    static bool myInitMgApi;
00178    unsigned char myUnits;
00179 
00180    //FlightTranslatedDatabaseListItem* myAlreadyXlatedDatabases;
00181 
00182    double myCurrentOffsetX;
00183    double myCurrentOffsetY;
00184    double myCurrentOffsetZ;
00185    // If path is specified in flt initializer, that will be used if this path is empty
00186    DtString       myUseFlightPath;
00187    DtFltPathMap   myFlightPath;
00188    // List of all surfaces that were not found during load
00189    std::map<DtString, int> myErrorSurfaces;
00190 
00191    std::map<DtString, bool> myAlreadyColorWarned;
00192 };
00193 
00194 extern "C" DT_DLL_mgwrapper DtMgWrapperInterface* DtCreateMgWrapperObject()
00195 {
00196    return (DtMgWrapperInterface*) new DtMgWrapper();
00197 }
00198 
00199 extern "C" DT_DLL_mgwrapper void DtDestroyMgWrapperObject(DtMgWrapperInterface* mwi)
00200 {
00201    delete mwi;
00202 }

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)