VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtCDBUtils.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2026 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 #pragma once
10 
11 #include "DtCDBExport.h"
12 #include <Cee_Errors.h>
13 #include <osgEarth/Notify>
14 #include <osgEarth/MapNodeObserver>
15 #include <osgEarth/Map>
16 #include <osgEarth/Feature>
17 #include <string>
18 #include <cstdint> // added for int64_t
19 using namespace com_cae::Cee;
20 
21 namespace makVrv { namespace oe { namespace CDB {
22 
23  class CDBTileCache;
24 
25  using CacheVectorDataMap = std::map<std::string, osgEarth::FeatureList>;
26 
30  {
31  public:
33  DtCDBUtils() {};
34 
42  static bool createEarthMtfFilesForCDB(const std::string& cdbRoot,
43  const std::string& terrainConfigPath, const std::string& appDataPath, std::string& earthOutputFile, std::string& mtfOutputFile, bool overwrite);
44 
46  static void moreInfoOnCDBError(unsigned int caeCdbErrorCode, const char* cdbRoot);
47 
58  static std::int64_t makeCdbFeatureUniqueId(int dsCode,
59  int cs1,
60  int cs2,
61  int lod,
62  int uref,
63  int rref,
64  double latitude,
65  double longitude);
66 
67  // Helper comparator for CDB tile filenames.
68  // Ordering:
69  // 1) "_LC<digits>" group first, descending numeric (LC9, LC8, ... LC1, LC0)
70  // 2) "_L<digits>" group next, ascending numeric (L00, L01, ...)
71  // 3) Others last, lexicographical.
72  // Note: Must be strict weak ordering (no two distinct elements compare equal).
74  {
75  static std::tuple<int, int, std::string> classify(const std::string& s)
76  {
77  // category: 0=LC*, 1=L*, 2=other
78  // key: ordering key within category.
79  auto extractNumber = [](const std::string& str, size_t start)->int
80  {
81  int val = 0; bool found = false;
82  while (start < str.size() && std::isdigit(static_cast<unsigned char>(str[start])))
83  {
84  val = val * 10 + (str[start] - '0');
85  ++start;
86  found = true;
87  }
88  return found ? val : -1;
89  };
90 
91  size_t pos = s.find("_LC");
92  if (pos != std::string::npos)
93  {
94  int num = extractNumber(s, pos + 3);
95  if (num >= 0) {
96  // Larger LC number should come first, so invert sign for ascending tuple.
97  return { 0, -num, s };
98  }
99  return { 0, -9999, s };
100  }
101 
102  pos = s.find("_L");
103  if (pos != std::string::npos)
104  {
105  // Ensure not "_LC"
106  if ((pos + 2) < s.size() && s[pos + 2] != 'C' && std::isdigit(static_cast<unsigned char>(s[pos + 2])))
107  {
108  int num = extractNumber(s, pos + 2);
109  if (num >= 0)
110  {
111  return { 1, num, s };
112  }
113  }
114  }
115 
116  return { 2, 0, s };
117  }
118 
119  bool operator()(const std::string& a, const std::string& b) const
120  {
121  if (a == b) return false;
122  auto ca = classify(a);
123  auto cb = classify(b);
124  if (ca < cb) return true;
125  if (cb < ca) return false;
126  return a < b; // stable tie-break
127  }
128  };
129 
130  // Ordered set alias
131  using CdbTileOrderedSet = std::set<std::string, CdbTileFilenameComparator>;
132 
133  protected:
134 
136  static std::string createMtfFile(const std::string& terrainConfigPath, const std::string& earthFile, const std::string& cdbRoot, const std::string& cdbFileName);
138  static void addElevationDataset(std::ofstream& earthFile, const std::string& cdbRoot, const std::string& cdbFileName, bool bathymetry);
140  static void addImageryDataset(std::ofstream& earthFile, const std::string& cdbRoot, const std::string& cdbFileName);
142  static void addImageryLightMapDataset(std::ofstream& earthFile, const std::string& cdbRoot, const std::string& cdbFileName);
143  // \brief Add model dataset entry to the earth file
144  static void addModelDataset(std::ofstream& earthFile, const std::string& cdbRoot, const std::string& cdbFileName, const std::string& datasetName,
145  unsigned int dataset, unsigned int componentSelector1, unsigned int componentSelector2, bool enabled);
146  // \brief Add vector feature dataset entry to the earth file
147  static void addFeatureDataset(std::ofstream& earthFile, const std::string& cdbRoot, const std::string& cdbFileName, const std::string& datasetName,
148  const std::string& vrfLayer, unsigned int dataset, unsigned int componentSelector1, unsigned int componentSelector2, bool enabled);
149 
150 
151 
152  // TODO ADD LANDCOVER OR BIOME FOR CDB DATASETS
153  // ****************
154  };
155 
156 
158  class DT_DLL_OSGEARTH_CDB_UTILS DtSceneGraphFrameNumberCallback : public osg::NodeCallback
178  {
179  public:
182 
184  void operator()(osg::Node* node, osg::NodeVisitor* nv) override;
185 
186  unsigned myFrameNumber;
188  };
189 
191 
195  {
196  public:
199 
201  void operator()(osg::Node*, osg::NodeVisitor*) override;
202 
203  osg::ref_ptr<DtCdbGroupNodeProgress> myGroupNodeProgressArray[4];
204  };
205 
209  class DT_DLL_OSGEARTH_CDB_UTILS DtCdbGroupNodeProgress : public osg::Referenced
210  {
211  public:
213 
216  bool isCanceled() const;
217 
219  void touch(const osg::FrameStamp* stamp);
220 
223  osg::observer_ptr<DtSceneGraphFrameNumberCallback> myScenegraphFrameNumberCallback;
224  };
226 
227 
228  // Functions for Python bindings
229  extern "C" {
230 
232  bool DT_DLL_OSGEARTH_CDB_UTILS isCdbFolder(const char* cdbRoot);
233 
235  int DT_DLL_OSGEARTH_CDB_UTILS getDatasetMaxLod(const char* appDataPath, const char* cdbRoot, unsigned int dataset, unsigned int componentSelector1, unsigned int componentSelector2);
236 
238  void DT_DLL_OSGEARTH_CDB_UTILS earthFileHeader(const char* cdbRoot, char* out);
239 
242 
244  void DT_DLL_OSGEARTH_CDB_UTILS elevationDataset(const char* cdbName, bool bathymetry, char* out);
245 
247  void DT_DLL_OSGEARTH_CDB_UTILS imageryDataset(const char* cdbName, char* out);
248 
250  void DT_DLL_OSGEARTH_CDB_UTILS rasterMaterialDataset(const char* cdbName, unsigned int max_cdb_elevation, unsigned int max_cdb_rasterMaterial,
251  bool use_procedural_imagery, bool use_procedural_vegetation, char* out);
252 
254  void DT_DLL_OSGEARTH_CDB_UTILS imagerySensorFxDataset(const char* cdbName, char* out);
255 
257  void DT_DLL_OSGEARTH_CDB_UTILS imageryLightMapDataset(const char* cdbName, char* out);
258 
260  void DT_DLL_OSGEARTH_CDB_UTILS modelDataset(const char* cdbName, const char* datasetName,
261  unsigned int dataset, unsigned int componentSelector1, unsigned int componentSelector2, bool vrfEnable, bool sensorFxEnable, char* out);
262 
264  void DT_DLL_OSGEARTH_CDB_UTILS featureDataset(const char* cdbName, const char* datasetName, const char* vrfLayer, const char* color,
265  unsigned int dataset, unsigned int componentSelector1, unsigned int componentSelector2, bool vrvEnable, char* out);
266 
268  void DT_DLL_OSGEARTH_CDB_UTILS mtfFile(const char* terrainConfigPath, const char* earthFile, const char* cdbName, bool dynamicOcean, char* out);
269 
272 
273  }
274 
275 }}} // namespace mak::osgEarth::CDB
276 
void DT_DLL_OSGEARTH_CDB_UTILS imageryLightMapDataset(const char *cdbName, char *out)
Output the CDB imagery lightmap dataset information of the earth file.
void DT_DLL_OSGEARTH_CDB_UTILS rasterMaterialDataset(const char *cdbName, unsigned int max_cdb_elevation, unsigned int max_cdb_rasterMaterial, bool use_procedural_imagery, bool use_procedural_vegetation, char *out)
Output the CDB raster material dataset information of the earth file.
void DT_DLL_OSGEARTH_CDB_UTILS imageryDataset(const char *cdbName, char *out)
Output the CDB imagery dataset information of the earth file.
void DT_DLL_OSGEARTH_CDB_UTILS mtfFile(const char *terrainConfigPath, const char *earthFile, const char *cdbName, bool dynamicOcean, char *out)
Output the CDB vector feature dataset information of the earth file.
void DT_DLL_OSGEARTH_CDB_UTILS elevationDataset(const char *cdbName, bool bathymetry, char *out)
Output the CDB elevation/bathymetry dataset information of the earth file.
#define DT_DLL_OSGEARTH_CDB_UTILS
Definition: DtCDBExport.h:18
Class used to find CDB Tiles information.
Definition: DtCDBUtils.h:29
Definition: featureContext.h:36
std::map< std::string, osgEarth::FeatureList > CacheVectorDataMap
Definition: DtCDBUtils.h:25
bool myCanCancel
Definition: DtCDBUtils.h:187
void DT_DLL_OSGEARTH_CDB_UTILS modelDataset(const char *cdbName, const char *datasetName, unsigned int dataset, unsigned int componentSelector1, unsigned int componentSelector2, bool vrfEnable, bool sensorFxEnable, char *out)
Output the CDB model dataset information of the earth file.
static std::tuple< int, int, std::string > classify(const std::string &s)
Definition: DtCDBUtils.h:75
std::set< std::string, CdbTileFilenameComparator > CdbTileOrderedSet
Definition: DtCDBUtils.h:131
&quot;Progress&quot; and cancellation callbacks, defined as if the frame number on the callback has been update...
Definition: DtCDBUtils.h:177
int DT_DLL_OSGEARTH_CDB_UTILS getDatasetMaxLod(const char *appDataPath, const char *cdbRoot, unsigned int dataset, unsigned int componentSelector1, unsigned int componentSelector2)
Get the maximum LOD available for a given dataset and component selectors in the CDB.
DtCDBUtils()
CTOR.
Definition: DtCDBUtils.h:33
osg::observer_ptr< DtSceneGraphFrameNumberCallback > myScenegraphFrameNumberCallback
Definition: DtCDBUtils.h:223
The DtCdbGroupNodeProgressthat gets passed to createPagedNode() to use. It will report cancellation i...
Definition: DtCDBUtils.h:209
Paged LOD callback touches DtCdbGroupNodeProgress for each of its (up to) four children.
Definition: DtCDBUtils.h:194
void DT_DLL_OSGEARTH_CDB_UTILS earthFileHeader(const char *cdbRoot, char *out)
Create and output the CDB file header information.
unsigned myFrameNumber
Definition: DtCDBUtils.h:186
bool operator()(const std::string &a, const std::string &b) const
Definition: DtCDBUtils.h:119
bool DT_DLL_OSGEARTH_CDB_UTILS isCdbFolder(const char *cdbRoot)
Check if the given folder is a valid CDB root folder.
unsigned myLastTouchedFrame
Definition: DtCDBUtils.h:222
bool myCanCancel
Definition: DtCDBUtils.h:221
void DT_DLL_OSGEARTH_CDB_UTILS featureDataset(const char *cdbName, const char *datasetName, const char *vrfLayer, const char *color, unsigned int dataset, unsigned int componentSelector1, unsigned int componentSelector2, bool vrvEnable, char *out)
Output the CDB feature dataset information of the earth file.
void DT_DLL_OSGEARTH_CDB_UTILS earthFileFooter(char *out)
Create and output the CDB file footer information.
void DT_DLL_OSGEARTH_CDB_UTILS imagerySensorFxDataset(const char *cdbName, char *out)
Output the CDB imagery dataset information of the earth file.
void DT_DLL_OSGEARTH_CDB_UTILS cdbTileCacheInit()
R-initialize the CDB tile cache (when we change CDB root)

Document ID: Generated on Thu Oct 15 21:27:02 EDT 2026 from SVN revision 296421
Copyright © 2005-2026 MAK Technologies. All Rights Reserved (www.mak.com)