VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtOsgUtils.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2023 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <osg/Quat>
13 #include <osg/Texture2DArray>
14 #include <osg/Depth>
15 #include <osg/Camera>
16 #include <osg/MatrixTransform>
17 #include <osg/Geometry>
18 #include <osg/BoundingBox>
19 
20 #include <osgEarth/MapNode>
21 #include <osgEarth/DecalLayer>
22 #include <osgEarth/FeatureSource>
23 
27 
29 
30 #include <set>
31 #include <map>
32 
33 class DtTaitBryan;
34 
35 namespace osgEarth
36 {
37  class MetadataNode;
38 }
39 
40 namespace osg
41 {
42  class TextureBuffer;
43 }
44 
45 namespace makVrv
46 {
47 
48  // see the <mappings> for the decal coverage raster layer
49 #define COVERAGE_MAPPING_VALUE_CRATER 11
50 #define COVERAGE_MAPPING_VALUE_SCRAPE 11
51 #define COVERAGE_MAPPING_VALUE_DITCH 11
52 
53  class DtGlSimpleTexture;
54  class DtDynamicTerrainGeometry;
55  class DtDynamicTerrainChange;
56  class DtDynamicTerrainSphere;
57  class DtIntersector;
58 
61  class DtOsgDebugFrustum : public osg::Referenced
62  {
63  public:
64  DtOsgDebugFrustum(const osg::Vec4 & color);
65  void updateDebugFrustum(osg::Vec3d * frustumVertices);
66 
69  };
70 
72  {
73  public:
75  static osg::Camera* CreateTextureQuadOverlay(DtGlSimpleTexture* texture,
76  float x, float y, float w, float h);
77 
79  static osg::Camera* CreateTextureQuadOverlay(osg::Texture* texture,
80  float x, float y, float w, float h);
81 
83  static osg::Camera* CreateTextureQuadOverlay(const std::string& shader_root, osg::Texture2DArray* textureArray,
84  float x, float y, float w, float h);
85  };
86 
90  {
91  public:
92 
93  // Get values for crater
94  static const std::string CRATER_MAJOR_AXIS;
95  static const std::string CRATER_MINOR_AXIS;
96  static const std::string CRATER_HEADING;
97  static const std::string CRATER_EFFECT_ENUM;
98  static const std::string CRATER_SOIL_TYPE;
99  static const std::string CRATER_DEPTH;
100  static const std::string CRATER_TYPE;
101  static const std::string MODELDEFINITION_PROPS;
102 
103  // static const std::string CRATER_LAND_COVER = "crater-land-cover";
104  static const std::string COMMAND_UID;
105  // Deprecated, but still set (to the same value as CRATER_MAJOR_AXIS)
106  static const std::string CRATER_RADIUS;
107 
108  static const std::string TerrainDamageName;
109  static const std::string TerrainDamageSlight;
110  static const std::string TerrainDamageModerate;
111  static const std::string TerrainDamageDestroyed;
112 
113  // Get values for the tracks (others are in keyValuePairDefinitions.h)
114  static const std::string TRACKS_LINE_WIDTH;
115  static const std::string TRACKS_TERRAIN_TIME;
116 
117  static const std::string EffectMapTextureUniformName;
118  static const std::string EffectMapTextureMatrixUniformName;
119  static const std::string TrackModelDefinitionSchema;
120  static const std::string TrackTypeParameterName;
121  static const std::string TrackSoilTypeParameterName;
122  static const std::string TrackDepthParameterName;
123  static const std::string TrackPointAParameterName;
124  static const std::string TrackPointBParameterName;
125  static const std::string TrackTexureParameterName;
126  static const std::string TrackSegmentSpacingParameterName;
127 
128  // Get values for other terrain deformation (ditch/berm/tank scrape,..)
129  static const std::string TERRAIN_DEFORMATION_ENUM;
130  static const std::string TERRAIN_DEFORMATION_LANDCOVER_OVERRIDE;
131  static const std::string TERRAIN_DEFORMATION_WIDTH;
132  static const std::string TERRAIN_DEFORMATION_HEIGHT;
133  static const std::string TERRAIN_DEFORMATION_RESOLUTION;
134 
136  {
137  DtTerrainDeformationNone = 0,
138  DtTerrainDeformationBerm = 1,
139  DtTerrainDeformationDitch = 2,
140  DtTerrainDeformationTankScrape = 3,
141  DtTerrainDeformationHill = 4
142  };
143 
144  // Used to map from vrfVrlinkExt enum DtTerrainCraterEffectEnum32 which is what's provided
145  // in string form in CRATER_EFFECT_ENUM
147  {
152  DtTerrainCraterAerodromeEffect = 4
153  };
154 
156  static void makeRotate(osg::Quat& q, const double& angle, const double& x, const double& y, const double& z);
157 
159  static osg::Matrixf toOsgRotation(const DtTaitBryan& orientation);
160 
164  static void quatMult(osg::Quat& lhs, const osg::Quat& rhs);
165 
167  static osg::MatrixTransform * create_axis_primitive();
168 
171 
174  static osg::Matrix getOrthoMatrix(bool useReverseZ, double left, double right,
175  double bottom, double top, double zNear, double zFar);
176 
179  static osg::Matrix getProjMatrix(bool useReverseZ, double left, double right,
180  double bottom, double top, double zNear, double zFar);
181 
183  static osg::Matrixd getRevZOrthoMatrix(double left, double right, double bottom,
184  double top, double zNear, double zFar);
185 
188  static bool getRevZPerspectiveMatrixAsFrustum(const osg::Matrix& mat, double& left,
189  double& right, double& bottom, double& top, double& zNear, double& zFar);
190 
193  static bool getRevZOrthoMatrixAsFrustum(const osg::Matrix& orthoMat, double& left,
194  double& right, double& bottom, double& top, double& zNear, double& zFar);
195 
198  static bool getRevZPerspective(const osg::Matrix& mat, double& fovy,
199  double& aspectRatio, double& zNear, double& zFar);
200 
203  static osg::Matrix makeRevZPerspective(double fovy, double aspectRatio,
204  double zNear, double zFar);
205 
207  static void getYPR(const osg::Matrix& m, double& yaw, double& pitch, double& roll);
208 
210  static void osgPolytopeToFrustum(Frustum_64& frustum, const osg::Polytope& polytope, bool hasNearFar);
211 
213  static void debugDumpShaderState(osg::State* state);
214 
216  static void debugDumpUniformState(const osg::Node* node);
217 
219 
220  static osg::Vec2 rotateVec2( const osg::Vec2& v, double rad );
222 
224  static osg::Vec2 translateVec2( const osg::Vec2& v, const osg::Vec2& translation );
225 
227  static osg::Vec2 scaleVec2( const osg::Vec2& v, double s );
228 
230  static osg::Vec2 scaleVec2( const osg::Vec2& v, double xScale, double yScale );
232 
234  static bool clipLine( double xMin, double xMax, double yMin, double yMax,
235  double x0src, double y0src, double x1src, double y1src,
236  double &x0clip, double &y0clip, double &x1clip, double &y1clip );
237 
239  static void clipPolygon( double xMin, double xMax, double yMin, double yMax,
240  std::vector<osg::Vec2>& vertices );
241 
242  // Adapted from VR-Link DtModPerLo [matrix/modper.cxx]
243  template <class VecType> static VecType DtModPerLoVec3( const VecType& in, double min, double max )
244  {
245  VecType result;
246  double per = max - min;
247 
248  for( int i = 0; i < 3; ++i )
249  {
250  if( min <= in[i] && in[i] < max )
251  {
252  result[i] = in[i];
253  }
254  else
255  {
256  result[i] = fmod( in[i] - min, per );
257 
258  if( result[i] < 0.0 )
259  {
260  result[i] += per;
261  }
262 
263  result[i] += min;
264  }
265  }
266  return result;
267  }
268 
275  static bool insideTriangulate( const std::vector<osg::Vec2>& contour, std::vector<int>& results );
276 
277  static osg::Matrixd calculateRevZProjectionMatrix(double left, double right
278  , double bottom, double top
279  , double zNear, double zFar);
280 
281  static osg::Matrixd calculateOrthoMatrix(double left, double right
282  , double bottom, double top
283  , double zNear, double zFar);
284 
285  static osg::Matrixd calculateRevZProjectionMatrixWithRevZAsNegativeOneForRttCamera(double left, double right
286  , double bottom, double top
287  , double zNear, double zFar);
288 
290  static void dynamicTerrainLineToFeature(const DtDynamicTerrainLine* line, osgEarth::Feature* feature,
292 
293  static void dumpCommandValues(const DtDynamicTerrainChange& command);
294 
299  {
300  public:
301  OSMBuildingInfo(osgEarth::MetadataNode* metadataNode, const std::set<int>& objectIndexList) :
302  myMetadataNode(metadataNode),
303  myObjectIndexList(objectIndexList)
304  {
305  }
306 
307  osgEarth::MetadataNode* myMetadataNode;
309  std::set<int> myObjectIndexList;
310  };
311 
313  typedef std::map<osgEarth::MetadataNode*, DtOsgUtils::OSMBuildingInfo> MetadaNodeMap;
314 
316  typedef std::map<std::string, DtOsgUtils::MetadaNodeMap> ChangeIdMetadaNodeMap;
317 
320  {
321  public:
322  FidMetadataNode(long long FID, osgEarth::MetadataNode* metadataNode, int objectIndex):
323  myFID(FID),
324  myMetadataNode(metadataNode),
325  myObjectIndex(objectIndex)
326  {
327  }
328  long long myFID;
329  osgEarth::MetadataNode* myMetadataNode;
331  };
332 
334  typedef std::map<long long, osg::BoundingBoxd> Fid2DebrisMapType;
335 
337  {
338  DebrisPositionStruct(const DtVector& position, const std::string& modelDefinition):
339  myPosition(position),
340  myModelDefinition(modelDefinition)
341  {
342  }
343 
345  std::string myModelDefinition;
346  };
347 
349  typedef std::vector<DebrisPositionStruct> DebrisPositionListType;
350 
352  static void getGeometriesFID(osg::ref_ptr<osgEarth::MapNode> mapNode, const makVrv::DtDynamicTerrainSphere* sphere, std::set<long long>& OsmFidList, DtOsgUtils::Fid2DebrisMapType* fid2DebrisMap);
353 
356  static void hideGeometries(osg::ref_ptr<osgEarth::MapNode> mapNode, osg::BoundingSphere bs, const std::set<long long>& FidList, std::vector<DtOsgUtils::FidMetadataNode>& dataList);
357 
360  static void showGeometries(osg::ref_ptr<osgEarth::MapNode> mapNode, osg::BoundingSphere bs, const std::set<long long>& FidList);
361 
363  static void getDebrisModels(DtDe* de, const DtOsgUtils::Fid2DebrisMapType& fid2DebrisMap, DtOsgUtils::DebrisPositionListType& debrisPositionList, DtIntersector* intersector = nullptr);
364 
368  static bool addCraterState(
369  const DtDynamicTerrainChange& command,
371  DtDynamicTerrainRasterLibrary* rasterLibrary,
372  osg::ref_ptr<osgEarth::LandCoverDictionary> landCoverDictionary_Splat,
377  osg::ref_ptr<osgEarth::Contrib::DecalImageLayer> decalCoverageRasterLayer,
378  unsigned coverageMappingValue,
379  std::string& info,
380  std::string& warn,
381  osgEarth::GeoExtent& out_feature_extent,
382  std::string& craterModelDefinition,
383  int minInvalidateLod = -1);
384 
388  static bool addLinearStateDeformation(
389  const DtDynamicTerrainChange& command,
391  DtDynamicTerrainRasterLibrary* rasterLibrary,
392  osg::ref_ptr<osgEarth::LandCoverDictionary> landCoverDictionary_Splat,
397  osg::ref_ptr<osgEarth::Contrib::DecalImageLayer> decalCoverageRasterLayer,
398  unsigned coverageMappingValue,
399  std::string& info,
400  std::string& warn,
401  osgEarth::GeoExtent& out_feature_extent);
402 
406  static bool addTankScrapeState(
407  const DtDynamicTerrainChange& command,
409  DtDynamicTerrainRasterLibrary* rasterLibrary,
410  osg::ref_ptr<osgEarth::LandCoverDictionary> landCoverDictionary_Splat,
415  osg::ref_ptr<osgEarth::Contrib::DecalImageLayer> decalCoverageRasterLayer,
416  unsigned coverageMappingValue,
417  std::string& info,
418  std::string& warn,
419  osgEarth::GeoExtent& out_feature_extent,
420  double start_angle = 0.0,
421  int minInvalidateLod = -1);
422 
424  static std::string osmFidStringFromList(std::set<long long>& osmFidList);
425 
427  static void osmFidStringToList(const std::string& osmFidString, std::set<long long>& osmFidList);
428 
430  static int getObjectID(unsigned int instance, osg::TextureBuffer* tbo);
431 
432  protected:
434  static bool snipTriangle( const std::vector<osg::Vec2>& contour, int u, int v, int w, int n, int *V );
436  static bool insideTriangle( float Ax, float Ay, float Bx, float By, float Cx, float Cy, float Px, float Py );
438  static float triangulateAreaSize( const std::vector<osg::Vec2> &contour );
439 
440 
441  };
442 }
443 
static VecType DtModPerLoVec3(const VecType &in, double min, double max)
Definition: DtOsgUtils.h:243
void updateDebugFrustum(osg::Vec3d *frustumVertices)
static const std::string CRATER_HEADING
Definition: DtOsgUtils.h:96
static const std::string EffectMapTextureUniformName
Definition: DtOsgUtils.h:117
static const std::string CRATER_MAJOR_AXIS
Definition: DtOsgUtils.h:94
Contains makVrv::DtDynamicTerrainLine class.
static const std::string EffectMapTextureMatrixUniformName
Definition: DtOsgUtils.h:118
Contains makVrv::DtOsgShaderUtils class.
DtDynamicTerrainRasterLibrary This class is used to managed rasters and out-the-window images appl...
Definition: DtDynamicTerrainRasterLibrary.h:95
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
FidMetadataNode(long long FID, osgEarth::MetadataNode *metadataNode, int objectIndex)
Definition: DtOsgUtils.h:322
Definition: DtOsgUtils.h:336
DtIntersector is an abstract class that provides the interface for requesting intersections with the ...
Definition: DtIntersector.h:25
static const std::string TerrainDamageDestroyed
Definition: DtOsgUtils.h:111
Definition: terrainCraterGeometry.h:26
Wrapper for OpenGL Texture.
Definition: DtGlSimpleTexture.h:36
static const std::string CRATER_MINOR_AXIS
Definition: DtOsgUtils.h:95
Definition: terrainCraterGeometry.h:23
static const std::string TerrainDamageSlight
Definition: DtOsgUtils.h:109
Definition: terrainCraterGeometry.h:24
static const std::string TrackModelDefinitionSchema
Definition: DtOsgUtils.h:119
std::map< long long, osg::BoundingBoxd > Fid2DebrisMapType
map of FID and bounding sphere debris
Definition: DtOsgUtils.h:334
static const std::string TERRAIN_DEFORMATION_LANDCOVER_OVERRIDE
Definition: DtOsgUtils.h:130
static const std::string TRACKS_TERRAIN_TIME
Definition: DtOsgUtils.h:115
osg::ref_ptr< osg::MatrixTransform > myTransform
Definition: DtOsgUtils.h:67
std::map< osgEarth::MetadataNode *, DtOsgUtils::OSMBuildingInfo > MetadaNodeMap
map between a metadataNode and OSM object indexes (used to display/hide buildings) ...
Definition: DtOsgUtils.h:313
static const std::string TrackPointAParameterName
Definition: DtOsgUtils.h:123
static const std::string TrackDepthParameterName
Definition: DtOsgUtils.h:122
Camera forward declarations.
static const std::string TERRAIN_DEFORMATION_ENUM
Definition: DtOsgUtils.h:129
DtCraterEffect
Definition: DtOsgUtils.h:146
static const std::string TrackSoilTypeParameterName
Definition: DtOsgUtils.h:121
osgEarth::MetadataNode * myMetadataNode
Definition: DtOsgUtils.h:307
Definition: DtOsgUtils.h:71
static const std::string CRATER_RADIUS
Definition: DtOsgUtils.h:106
long long myFID
Definition: DtOsgUtils.h:328
OSMBuildingInfo(osgEarth::MetadataNode *metadataNode, const std::set< int > &objectIndexList)
Definition: DtOsgUtils.h:301
Structure to map a pair between a MetadataNode and list of OSM object index This class is used to tra...
Definition: DtOsgUtils.h:298
static const std::string TrackPointBParameterName
Definition: DtOsgUtils.h:124
DtDynamicTerrainLine is used to represent a collection of vertices for a linear dynamic terrain objec...
Definition: DtDynamicTerrainLine.h:24
static const std::string TrackSegmentSpacingParameterName
Definition: DtOsgUtils.h:126
static const std::string TERRAIN_DEFORMATION_WIDTH
Definition: DtOsgUtils.h:131
DT_DLL_vrfutil double angle(double vec1[3], double vec2[3])
osgEarth::MetadataNode * myMetadataNode
Definition: DtOsgUtils.h:329
helper class, random osg debug helpers and math
Definition: DtOsgUtils.h:89
static const std::string TerrainDamageModerate
Definition: DtOsgUtils.h:110
std::string myModelDefinition
Definition: DtOsgUtils.h:345
static const std::string CRATER_EFFECT_ENUM
Definition: DtOsgUtils.h:97
static const std::string CRATER_TYPE
Definition: DtOsgUtils.h:100
Definition: terrainCraterGeometry.h:25
osg::ref_ptr< osg::Geometry > myGeometry
Definition: DtOsgUtils.h:68
int myObjectIndex
Definition: DtOsgUtils.h:330
static const std::string CRATER_SOIL_TYPE
Definition: DtOsgUtils.h:98
DtTerrainDeformation
Definition: DtOsgUtils.h:135
std::vector< DebrisPositionStruct > DebrisPositionListType
list of position / debris model definition
Definition: DtOsgUtils.h:349
static const std::string CRATER_DEPTH
Definition: DtOsgUtils.h:99
static const std::string TRACKS_LINE_WIDTH
Definition: DtOsgUtils.h:114
DtOsgDebugFrustum(const osg::Vec4 &color)
DtDynamicTerrainSphere is used to represent a sphere of impact for a dynamic terrain event...
Definition: DtDynamicTerrainSphere.h:21
std::set< int > myObjectIndexList
List of OSM object index under the associated MetadataNode.
Definition: DtOsgUtils.h:309
Command which can be given to the dynamic terrain system to perform some change. This class is a simp...
Definition: DtDynamicTerrainChange.h:42
static const std::string COMMAND_UID
Definition: DtOsgUtils.h:104
static const std::string MODELDEFINITION_PROPS
Definition: DtOsgUtils.h:101
std::map< std::string, DtOsgUtils::MetadaNodeMap > ChangeIdMetadaNodeMap
map between a crater change ID and MetadaNodeMap changes (hidden OSM buildings)
Definition: DtOsgUtils.h:316
DebrisPositionStruct(const DtVector &position, const std::string &modelDefinition)
Definition: DtOsgUtils.h:338
static const std::string TrackTypeParameterName
Definition: DtOsgUtils.h:120
helper for visualizing debug frustra
Definition: DtOsgUtils.h:61
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer, DtDeCommunicator, as well as a DtDisplay and other things.
Definition: DtDe.h:72
DtVector myPosition
Definition: DtOsgUtils.h:344
static const std::string TERRAIN_DEFORMATION_RESOLUTION
Definition: DtOsgUtils.h:133
static const std::string TERRAIN_DEFORMATION_HEIGHT
Definition: DtOsgUtils.h:132
map between FID and MetadataNode
Definition: DtOsgUtils.h:319
static const std::string TrackTexureParameterName
Definition: DtOsgUtils.h:125
static const std::string TerrainDamageName
Definition: DtOsgUtils.h:108
Definition: dfadData.h:59

Document ID: Generated on Tue Sep 24 19:28:17 EDT 2024 from SVN revision 269799
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)