VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtOsgFileCache.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2025 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvOsg/vrvOsg.h>
13 
18 
19 #include <vrvCore/DtFileCache.h>
20 
22 #include <vrvUtil/signalslib.h>
23 
24 #include <osgDB/ReaderWriter>
25 
26 #define _WINSOCKAPI_
27 
28 #include <tbb/spin_rw_mutex.h>
29 
30 #include <atomic>
31 #include <unordered_map>
32 
33 namespace osg
34 {
35  class Drawable;
36  class GraphicsContext;
37  class Node;
38  class Texture;
39  class Object;
40 }
41 
42 namespace makVrv
43 {
44  class DtMeifConverter;
45  class DtMetaFileManager;
46  class DtOsgShaderManager;
47  class DtOsgShaderFilesCache;
48  class DtEffectControllerFactory;
49  class DtReadFileCallback;
50  class DtModelDefinition;
51 
57  {
58  public:
59 
62  friend class DtOsgFileCacheCreator;
63 
65  virtual ~DtOsgFileCache();
66 
69  virtual void initSingletonDependencies();
70 
72  virtual void releaseResources()
73  {
74  releaseResources(0);
75  }
76 
78  virtual void releaseResources(osg::State* state);
79 
81  virtual void setFromRecord( const makArchives::DtCacheSettingsRecord& rec );
82 
86  static void optimizeNodeGeometry(osg::Node* node);
87 
91  osg::Node* readNodeFile( const std::string& inputFilename,
92  const LoadFileOptions& loadFileOptions);
93 
96  inline osg::ref_ptr<osg::Node> findNodeFile( const std::string& inputFilename )
97  {
98  return ts_findNodeFile(inputFilename);
99  }
100 
104  osg::Image* readImageFile( const std::string& inputFilename,
105  const LoadFileOptions& loadFileOptions);
106 
109  virtual osg::Texture* getTextureInstance(const std::string& filePath,
110  osg::Texture::FilterMode minFilter, osg::Texture::FilterMode magFilter,
111  osg::Texture::WrapMode s, osg::Texture::WrapMode t,
112  const LoadFileOptions& loadFileOptions);
113 
117  virtual void ts_getTextureInstance(const std::string& filePath,
118  osg::Texture::FilterMode minFilter, osg::Texture::FilterMode magFilter,
119  osg::Texture::WrapMode s, osg::Texture::WrapMode t,
120  const LoadFileOptions& loadFileOptions, osg::ref_ptr<osg::Texture>& texture);
121 
126  virtual bool getOrLoadTexture( DtTextureInterface* textureWrapper, const std::string& filename,
127  const DtFileCache::LoadFileOptions& loadFileOptions ) override;
128 
130  virtual void runMergeDuplicateTextureVisitor(osg::Node& node);
131 
133  virtual void encodeOptionsString(const LoadFileOptions& loadFileOptions,
134  osgDB::ReaderWriter::Options& options) const;
135 
137  virtual void decodeOptions(const osgDB::ReaderWriter::Options& options,
138  LoadFileOptions& loadFileOptions) const;
139 
141  DtMetaFileManager* metaFileManager();
142 
146  void cleanDataFilePathList(FilePathList& fileList);
147 
152  boost::signalslib::signal<void (osg::Node*, const std::string& origFileName,
153  const std::string& actualFileName)> signal_nodeFileLoaded;
154 
159  boost::signalslib::signal<void (osg::Image*, const std::string& origFileName,
160  const std::string& actualFileName)> signal_imageFileLoaded;
161 
166  boost::signalslib::signal<void(osg::Object*, const std::string& origFileName,
167  const std::string& actualFileName)> signal_objectFileLoaded;
168 
172  boost::signalslib::signal<void (const std::string& filename,
173  osgDB::ReaderWriter::ReadResult&,const osgDB::ReaderWriter::Options*)>
175 
179  boost::signalslib::signal<void (const std::string& filename,
180  osgDB::ReaderWriter::ReadResult&,const osgDB::ReaderWriter::Options*)>
182 
186  boost::signalslib::signal<void(const std::string& filename,
187  osgDB::ReaderWriter::ReadResult&, const osgDB::ReaderWriter::Options*)>
189 
191  virtual const DtOsgShaderFilesCache& shaderFilesCache(void) const;
192 
196  virtual const std::string& loadShaderSource(const std::string& shaderFile) const;
197 
200  virtual std::string ts_getTextureFilePathAndSetNameIfNotSet(const osg::Texture* baseTexture) const;
201 
203  virtual void ts_setEffectTextureName(osg::ref_ptr<osg::Texture>& effectTexture, const std::string& validFile) const;
204 
206  virtual void ts_setEffectTextureFilterAndHardwareMipMapGen(osg::Texture* effectTexture, osg::Texture::FilterMode minFilter, osg::Texture::FilterMode magFilter, bool hardwareMipMapGen) const;
207 
209  virtual void ts_compareAndSwapIgnoreHint(osg::Texture* effectTexture, bool oldVal, bool newVal) const;
210 
215  virtual bool ts_checkAndSetIgnoreHint(osg::Object* obj, bool val, const char* hint) const;
216 
219  virtual bool ts_ignore(osg::Object* obj, const char* hint) const;
220 
222  virtual const DtEffectControllerShaderCache& effectControllerShaderCache(void) const;
223 
225  virtual void setNumActivePagerThreads(int active);
226 
228  virtual int numActivePagerThreads() const;
229 
231  virtual int numImageProcessingTasks() const;
232 
234  virtual void setNumDiguyWorkerThreads(int num);
235 
238  virtual void incrementNumSleepingPagerThreads();
239 
241  virtual void decrementNumSleepingPagerThreads();
242 
244  virtual DtOsgShaderManager& shaderManager(void);
245 
247  virtual const DtOsgShaderManager& shaderManager(void) const;
248 
250  virtual void ts_flushInstancingCache(bool multipass,
251  bool flushNodes, bool flushTextures, bool flushImages);
252 
254  virtual int numNodes() const;
255 
257  virtual int numTextures() const;
258 
260  virtual int numImages() const;
261  protected:
262 
263  friend class DtReadFileCallback;
264 
266  virtual osg::ref_ptr<osg::Node> ts_readNodeFile( const std::string& inputFilename,
267  const LoadFileOptions& loadFileOptions, const osg::UserDataContainer *optionsUserData);
268 
270  virtual osg::ref_ptr<osg::Node> ts_readCdbNodeFile(const std::string& inputFilename,
271  const LoadFileOptions& loadFileOptions, const osg::UserDataContainer *optionsUserData);
272 
274  virtual osg::ref_ptr<osg::Node> ts_findNodeFile( const std::string& inputFilename );
275 
277  virtual osg::ref_ptr<osg::Image> ts_readImageFile( const std::string& inputFilename,
278  const LoadFileOptions& loadFileOptions,
279  const osg::UserDataContainer* optionsUserData =0L);
280 
282  virtual osg::ref_ptr<osg::Image> ts_readCdbImageFile(const std::string& inputFilename,
283  const LoadFileOptions& loadFileOptions,
284  const osg::UserDataContainer* optionsUserData = 0L);
285 
287  virtual void compressCdbImage( osg::Image* image, const LoadFileOptions& loadFileOptions, const std::string& ext, const std::string& acceleratedFilename,
288  const std::string& zipTextureName, const std::string& fileToLoad, bool loadAccelerated, bool writeAcceleratedFile, DtCVMarkerSeries& objectCreation );
289 
291  virtual void setKeysForCdbImage( osg::Image* image, const std::string& acceleratedFilename, const std::string& absoluteInputFilename,
292  const std::string& zipTextureName, const std::string& fileToLoad );
293 
295  virtual osg::ref_ptr<osg::Object> ts_readObject(
296  const std::string& filename, const osgDB::ReaderWriter::Options* options);
297 
299  void ts_encryptImage( const std::string& inputFileName,
300  const std::string& outputFilename, const osgDB::ReaderWriter::Options* options, bool printToConsole);
301 
303  bool ts_resolveRelativeFilename( const LoadFileOptions& loadFileOptions,
304  std::string& absoluteInputFilename );
305 
307  virtual void ts_clearInstancingCache();
308 
309 
311  virtual void applyEffectTexture(osg::Node* node, const std::string& extension,
312  bool isCdb, osgDB::ReaderWriter::Options* option);
313 
315  DtOsgFileCache(DtDe& de);
316 
319  virtual bool save(const std::string& origFilename,
320  const std::string& cachedFilename, bool optimize);
321 
323  bool saveToAcceleratedFile( const std::string& origFileName,
324  osg::Node* nodeRef, const std::string& cachedFilename,
325  bool writeExternalReferences);
326 
328  virtual void addMetaFlightOptions(std::string& optionsString);
329 
331  virtual bool needsShaderGeneration(const std::string& extension, const LoadFileOptions& options) const;
332 
334  virtual void updateGlobalOptions();
335 
337  virtual void slot_onDdsFlipChanged(bool flip);
338 
340  virtual void slot_instancingChanged(bool enabled);
341 
342  // check if an attrData object is in the cache (only for FLT and CDB)
343  virtual bool getAttrFromLocalCache(const std::string& filename, osg::Object** attrData);
344 
346  virtual void writeCacheFile(osg::ref_ptr<osg::Node> node, const std::string& acceleratedFileLocation, DtCVMarkerSeries& series);
347 
349  virtual void shadersGeneration(osg::ref_ptr<osg::Node> node, const std::string& fileToLoad);
350 
353  virtual void squishImage(const std::string& fileToLoad, const std::string& acceleratedFilename, DtCVMarkerSeries& objectCreation,
354  osg::ref_ptr<osg::Image> image, bool writeAcceleratedFile, bool isCDB, bool generateDDS = false );
355 
360  virtual void saveImageFilename(const std::string& absoluteInputFilename, osg::Image* image);
361 
363  virtual osg::ref_ptr<osg::Image> getCachedImage(const std::string& cacheKey, const std::string& inputExtension, const LoadFileOptions& loadFileOptions);
364 
365  // ********* CDB sensor FX functions and structure (below) **********
366 
369  {
370  osg::Vec4f myRGB1;
371  osg::Vec4f myRGB2;
372  };
373 
375  typedef std::map<unsigned int, color2DArray> mcodColorMap;
376 
378  {
379  std::string myBaseMat;
380  float myWeight;
381  };
382  typedef std::vector<baseMaterial> materialListType;
383  std::map<unsigned int, materialListType> materialMap;
384 
386  {
388  {
389  }
390  primarySubstrateInfo(const materialListType& baseMaterialList)
391  :myBaseMaterialList(baseMaterialList)
392  {
393  }
396  };
397 
399  virtual std::string getRasterMaterialFilename(const std::string& modelFilename);
400 
402  virtual void readCdbRasterMaterialFile(const std::string& modelMaterialFile, mcodColorMap& mcodMap, const std::string& mcodCDBMaterialString);
403 
405  virtual void createCdbEmatImages(mcodColorMap& mcodMap, const std::string& fileToLoad, const osg::Image* cdbMaterialImage, osg::Image* imageEmat2, osg::Image* imageEmat3);
406 
408  virtual bool processRasterMaterialCreateEmat(osgDB::ReaderWriter::ReadResult& rasterMaterial, const std::string& optionString, const std::string& fileToLoad,
409  osg::ref_ptr<osg::Image>& imageEmat2, osg::ref_ptr<osg::Image>& imageEmat3);
410 
412  virtual void compressCdbEmatImage( osg::Image* imageEmat, const std::string& ext, const LoadFileOptions& loadFileOptions, const std::string& cdbZipFile,
413  const std::string& zipTextureName, bool cacheCDB, bool writeAcceleratedFile, DtCVMarkerSeries& objectCreation );
414 
415  // ********* CDB sensor FX functions and structure (above) **********
416 
417  protected:
418 
419  typedef std::unordered_map<std::string,std::string> RelativePathCache;
420 
424  typedef std::map< std::string, osg::ref_ptr<osg::Object> > AttrCacheMap;
426 
427  tbb::spin_rw_mutex myRelativePathMutex;
431 
435 
436  // effect controller shader cache
438 
441 
442  // determines threading behavior
444  std::atomic<int> myNumSleepingPagerThreads;
445  std::atomic<int> myNumDiguyWorkerThreads;
446 
447  // CDB specific driver
448  osgDB::ReaderWriter* myFltDriver;
449  osgDB::ReaderWriter* myFltCdbDriver;
450  osgDB::ReaderWriter* myMedfDriver;
451  // CDB specific driver
452  osgDB::ReaderWriter* myRgbDriver;
453  osgDB::ReaderWriter* myTiffDriver;
454  osgDB::ReaderWriter* myMeifDriver;
455  osgDB::ReaderWriter* myCDBZipDriver;
456  };
457 
461  {
462 
463  public:
464 
466  virtual DtFileCache* create(DtDe& de);
467 
468  };
469 }
470 
471 // Include the inl to solve a circular dependency problem for gcc
472 #include <vrvOsg/DtOsgReferencedCollection.inl>
473 
tbb::spin_rw_mutex myRelativePathMutex
Definition: DtOsgFileCache.h:427
RelativePathCache myRelativePathCache
Definition: DtOsgFileCache.h:428
Contains makVrv::DtTextureCollection class.
materialListType myBaseMaterialList
Definition: DtOsgFileCache.h:394
virtual void releaseResources()
Release all rendering resources.
Definition: DtOsgFileCache.h:72
primarySubstrateInfo()
Definition: DtOsgFileCache.h:387
std::map< std::string, osg::ref_ptr< osg::Object > > AttrCacheMap
Definition: DtOsgFileCache.h:424
color2DArray myMcodColors
Definition: DtOsgFileCache.h:395
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
Class responsible for converting images into MAK encrypted image files.
Definition: DtMeifConverter.h:25
AttrCacheMap myAttrCacheMap
Definition: DtOsgFileCache.h:425
DtOsgReferencedCollection< osg::Node > myNodeCollection
Definition: DtOsgFileCache.h:421
Creates a series/span line in the CV tool.
Definition: DtConcurrencyViewerMacros.h:27
std::string myBaseMat
Definition: DtOsgFileCache.h:379
The abstract creator for the abstract DtFileCache class.
Definition: DtFileCache.h:259
std::map< unsigned int, materialListType > materialMap
Definition: DtOsgFileCache.h:383
brief DtEffectControllerShaderCache is a cache for shaders used by effect texture controller ...
Definition: DtEffectControllerShaderCache.h:26
Interface for a texture. Used to pass in a texture to vrvGraphics.
Definition: DtTextureInterface.h:24
osg::ref_ptr< osg::Node > findNodeFile(const std::string &inputFilename)
Find a node file. If the file was already cached then a copy will be returned.
Definition: DtOsgFileCache.h:96
osg::Vec4f myRGB1
Definition: DtOsgFileCache.h:370
Definition: DtOsgFileCache.h:377
class for holding loader shader files, so that they are not repeatedly loaded from disk ...
Definition: DtOsgShaderFilesCache.h:27
primarySubstrateInfo(const materialListType &baseMaterialList)
Definition: DtOsgFileCache.h:390
boost::signalslib::signal< void(const std::string &filename, osgDB::ReaderWriter::ReadResult &, const osgDB::ReaderWriter::Options *)> signal_readObjectCallback
Signaled emitted when osg calls readObject. This signal is emitted every time read object is called r...
Definition: DtOsgFileCache.h:188
Definition: DtOsgFileCache.h:385
The DtOsgFileCache creator..
Definition: DtOsgFileCache.h:460
boost::signalslib::signal< void(const std::string &filename, osgDB::ReaderWriter::ReadResult &, const osgDB::ReaderWriter::Options *)> signal_readNodeCallback
Signaled emitted when osg calls readNodeFile. This signal is emitted every time read image is called ...
Definition: DtOsgFileCache.h:174
osg::Vec4f myRGB2
Definition: DtOsgFileCache.h:371
Handles the set up and processing of .meta files. Meta files contain extra information about nodes in...
Definition: DtMetaFileManager.h:36
int myNumActivePagerThreads
Definition: DtOsgFileCache.h:443
std::atomic< int > myNumDiguyWorkerThreads
Definition: DtOsgFileCache.h:445
Contains makVrv::DtFileCache class.
The OSG implementation of makVrv::DtOsgFileCache. This will cache files as .ive&#39;s for quicker load ti...
Definition: DtOsgFileCache.h:56
DtOsgReferencedCollection< osg::Image > myImageCollection
Definition: DtOsgFileCache.h:423
boost::signalslib::signal< void(const std::string &filename, osgDB::ReaderWriter::ReadResult &, const osgDB::ReaderWriter::Options *)> signal_readImageCallback
Signaled emitted when osg calls readImageFile. This signal is emitted every time read image is called...
Definition: DtOsgFileCache.h:181
std::atomic< int > myNumSleepingPagerThreads
Definition: DtOsgFileCache.h:444
osgDB::ReaderWriter * myFltCdbDriver
Definition: DtOsgFileCache.h:449
structure for converting CDB material to emat colors
Definition: DtOsgFileCache.h:368
osgDB::ReaderWriter * myFltDriver
Definition: DtOsgFileCache.h:448
Contains the DtEffectControllerShaderCache class declaration.
DtOsgShaderManager & myShaderManager
Definition: DtOsgFileCache.h:432
IMGUI_API void Image(ImTextureID user_texture_id, const ImVec2 &size, const ImVec2 &uv0=ImVec2(0, 0), const ImVec2 &uv1=ImVec2(1, 1), const ImVec4 &tint_col=ImVec4(1, 1, 1, 1), const ImVec4 &border_col=ImVec4(0, 0, 0, 0))
boost::signalslib::signal< void(osg::Node *, const std::string &origFileName, const std::string &actualFileName)> signal_nodeFileLoaded
Signal emitted whenever a Node file is loaded from disk. When instancing is enabled then each file wi...
Definition: DtOsgFileCache.h:153
DtOsgShaderFilesCache & myShaderFilesCache
Definition: DtOsgFileCache.h:433
Class to manage disconnection of boost connections on deletion.
Definition: DtSignalConnectionManager.h:20
DtEffectControllerShaderCache myEffectControllerShaderCache
Definition: DtOsgFileCache.h:437
DtMetaFileManager * myMetaFileManager
Definition: DtOsgFileCache.h:430
Definition: DtFileCache.h:45
osg::ref_ptr< DtReadFileCallback > myReadFileCallback
Definition: DtOsgFileCache.h:439
DtOsgShaderManager injects custom shaders into the scenes, and keeps their uniform parameters set to ...
Definition: DtOsgShaderManager.h:41
Record for the settings associated with the VRV caching.
Definition: DtCacheSettingsRecord.h:17
Definition: DtReadFileCallback.h:22
DtEffectControllerFactory & myEffectControllerFactory
Definition: DtOsgFileCache.h:434
float myWeight
Definition: DtOsgFileCache.h:380
boost::signalslib::signal< void(osg::Image *, const std::string &origFileName, const std::string &actualFileName)> signal_imageFileLoaded
Signal emitted whenever an image file is loaded from disk. When instancing is enabled then each file ...
Definition: DtOsgFileCache.h:160
The scene object creators are registered with the scene object factory for accessing DtSceneObjectCre...
Definition: DtEffectControllerFactory.h:31
DtMeifConverter * myImageCompressor
Definition: DtOsgFileCache.h:429
osgDB::ReaderWriter * myMedfDriver
Definition: DtOsgFileCache.h:450
Contains DLL export macros.
osgDB::ReaderWriter * myRgbDriver
Definition: DtOsgFileCache.h:452
std::vector< baseMaterial > materialListType
Definition: DtOsgFileCache.h:382
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:76
boost::signalslib::signal< void(osg::Object *, const std::string &origFileName, const std::string &actualFileName)> signal_objectFileLoaded
Signal emitted whenever an object file is loaded from disk. When instancing is enabled then each file...
Definition: DtOsgFileCache.h:167
osgDB::ReaderWriter * myMeifDriver
Definition: DtOsgFileCache.h:454
std::map< unsigned int, color2DArray > mcodColorMap
CDB Composite material index and emat2/emat3 colors.
Definition: DtOsgFileCache.h:375
Contains makVrv::DtOsgReferencedCollection class.
Contains the DtCVMarkerSeries and DtCVMarkerSeries class declarations responsible for wrapping up to ...
Handles the caching of files. Includes functions for excluding files with certain extensions from bei...
Definition: DtFileCache.h:37
DtOsgReferencedCollection< DtTextureCollection > myTextureCollection
Definition: DtOsgFileCache.h:422
DtSignalConnectionManager myConnections
Definition: DtOsgFileCache.h:440
osgDB::ReaderWriter * myCDBZipDriver
Definition: DtOsgFileCache.h:455
Contains the DtEffectControllerContainer class.
osgDB::ReaderWriter * myTiffDriver
Definition: DtOsgFileCache.h:453
std::unordered_map< std::string, std::string > RelativePathCache
Definition: DtOsgFileCache.h:419

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)