Visualization Library 2.1.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
init_core.cpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
34 #include <vlX/Registry.hpp>
35 #include <vlCore/FileSystem.hpp>
37 #include <vlCore/Log.hpp>
38 #include <vlCore/Say.hpp>
39 #include <vlCore/Time.hpp>
40 #include <vlCore/Quaternion.hpp>
41 #include <vlCore/AABB.hpp>
42 #include <vlCore/Sphere.hpp>
44 #include <cassert>
45 
46 static void registerVLXCoreWrappers();
47 
48 using namespace vl;
49 
50 #include <vlX/WrappersCore.hpp>
51 #include <vlX/ioVLX.hpp>
52 
53 #if defined(VL_IO_2D_JPG)
54  #include <vlCore/plugins/ioJPG.hpp>
55 #endif
56 #if defined(VL_IO_2D_PNG)
57  #include <vlCore/plugins/ioPNG.hpp>
58 #endif
59 #if defined(VL_IO_2D_TIFF)
60  #include <vlCore/plugins/ioTIFF.hpp>
61 #endif
62 #if defined(VL_IO_2D_TGA)
63  #include <vlCore/plugins/ioTGA.hpp>
64 #endif
65 #if defined(VL_IO_2D_DAT)
66  #include <vlCore/plugins/ioDAT.hpp>
67 #endif
68 #if defined(VL_IO_2D_MHD)
69  #include <vlCore/plugins/ioMHD.hpp>
70 #endif
71 #if defined(VL_IO_2D_DDS)
72  #include <vlCore/plugins/ioDDS.hpp>
73 #endif
74 #if defined(VL_IO_2D_BMP)
75  #include <vlCore/plugins/ioBMP.hpp>
76 #endif
77 #if defined(VL_IO_2D_DICOM)
79 #endif
80 // ------------------------------------------------------------------------------
81 /*
82 VL_COMPILE_TIME_CHECK( sizeof(double) == 8 )
83 VL_COMPILE_TIME_CHECK( sizeof(float) == 4 )
84 VL_COMPILE_TIME_CHECK( sizeof(long long) == 8 )
85 VL_COMPILE_TIME_CHECK( sizeof(int) == 4 )
86 VL_COMPILE_TIME_CHECK( sizeof(short) == 2 )
87 VL_COMPILE_TIME_CHECK( sizeof(char) == 1 )
88 VL_COMPILE_TIME_CHECK( sizeof(wchar_t) >= 2 )
89 VL_COMPILE_TIME_CHECK( sizeof(vec2) == sizeof(real)*2 )
90 VL_COMPILE_TIME_CHECK( sizeof(vec3) == sizeof(real)*3 )
91 VL_COMPILE_TIME_CHECK( sizeof(vec4) == sizeof(real)*4 )
92 VL_COMPILE_TIME_CHECK( sizeof(mat2) == sizeof(real)*2*2 )
93 VL_COMPILE_TIME_CHECK( sizeof(mat3) == sizeof(real)*3*3 )
94 VL_COMPILE_TIME_CHECK( sizeof(mat4) == sizeof(real)*4*4 )
95 VL_COMPILE_TIME_CHECK( sizeof(quat) == sizeof(real)*4 )
96 VL_COMPILE_TIME_CHECK( sizeof(AABB) == sizeof(real)*6 )
97 VL_COMPILE_TIME_CHECK( sizeof(Sphere) == sizeof(real)*4 )
98 */
99 // ------------------------------------------------------------------------------
100 namespace
101 {
102  bool gInitializedCore = false;
103 };
104 // ------------------------------------------------------------------------------
105 bool VisualizationLibrary::isCoreInitialized() { return gInitializedCore; }
106 // ------------------------------------------------------------------------------
107 void VisualizationLibrary::initCore(bool log_info)
108 {
109  VL_CHECK( ! gInitializedCore );
110  if (gInitializedCore) {
111  Log::bug("VisualizationLibrary::initCore(): Visualization Library Core is already initialized!\n");
112  return;
113  }
114 
115  // Install globabl settings
117 
118  // Install default logger
119  ref<StandardLog> logger = new StandardLog;
120  logger->setLogFile( globalSettings()->defaultLogPath() );
121  setDefLogger( logger.get() );
122 
123  // Install default LoadWriterManager
125 
126  // Install default FileSystem
128  vl::defFileSystem()->directories().push_back( new DiskDirectory( globalSettings()->defaultDataPath() ) );
129 
130  // Install default MersenneTwister (seed done automatically)
132 
133  // Install default VLXRegistry
135 
136  // Register VLCore classes to VLX
137  registerVLXCoreWrappers();
138 
139  // Register VLCore modules
140 
141  // This is always present
143 
144  #if defined(VL_IO_2D_JPG)
146  #endif
147  #if defined(VL_IO_2D_PNG)
149  #endif
150  #if defined(VL_IO_2D_TIFF)
152  #endif
153  #if defined(VL_IO_2D_TGA)
155  #endif
156  #if defined(VL_IO_2D_BMP)
158  #endif
159  #if defined(VL_IO_2D_DDS)
161  #endif
162  #if defined(VL_IO_2D_DAT)
164  #endif
165  #if defined(VL_IO_2D_MHD)
167  #endif
168  #if defined(VL_IO_2D_DICOM)
170  #endif
171 
172  // Log VL and system information.
173  if (globalSettings()->verbosityLevel() && log_info) {
174  logSystemInfo();
175  }
176 
177  gInitializedCore = true;
178 }
179 //------------------------------------------------------------------------------
180 void VisualizationLibrary::shutdownCore()
181 {
182  if ( ! gInitializedCore ) {
183  Log::debug("VisualizationLibrary::shutdownCore(): VL Core not initialized.\n");
184  return;
185  }
186 
187  gInitializedCore = false;
188 
189  // Dispose default MersenneTwister
191 
192  // Dispose default VLXRegistry
194 
195  // Dispose default LoadWriterManager
196  defLoadWriterManager()->loadCallbacks().clear();
198  defLoadWriterManager()->loadWriters().clear();
200 
201  // Dispose default FileSystem
202  defFileSystem()->directories().clear();
204 
205  // Dispose default logger
206  Log::debug("VisualizationLibrary::shutdownCore()\n");
207 
208  // we keep the logger alive as much as we can.
209  // setDefLogger( NULL );
210 
211  // keep global settings (used by logger)
212  // gSettings = NULL;
213 }
214 //------------------------------------------------------------------------------
215 void registerVLXCoreWrappers()
216 {
217  // None yet.
218 }
219 //------------------------------------------------------------------------------
static void debug(const String &message)
Use this function to provide extra information useful to investigate and solve problems.
Definition: Log.cpp:145
std::vector< ref< VirtualDirectory > > & directories()
Returns the list of VirtualDirectory objects added to a FileSystem.
Definition: FileSystem.hpp:84
VLCORE_EXPORT FileSystem * defFileSystem()
Returns the default FileSystem used by VisualizationLibrary.
Definition: pimpl.cpp:97
const T * get() const
Definition: Object.hpp:128
VLCORE_EXPORT void logSystemInfo()
Logs VL and system information.
Definition: pimpl.cpp:159
const std::vector< ref< WriteCallback > > & writeCallbacks() const
static bool isCoreInitialized()
Returns true if VLCore library is initialized and shutdown has not been called.
Definition: init_core.cpp:105
The LoadWriterTGA class is a ResourceLoadWriter capable of reading TGA files.
Definition: ioTGA.hpp:57
void setLogFile(const String &file)
Definition: Log.cpp:203
Global application settings controlling how Visualization Library behaves.
const std::vector< ref< LoadCallback > > & loadCallbacks() const
The LoadWriterManager class loads and writes resources using the registered ResourceLoadWriter object...
The LoadWriterDDS class is a ResourceLoadWriter capable of reading DDS files.
Definition: ioDDS.hpp:55
A VirtualDirectory that operates on reguar disk directories.
The LoadWriterJPG class is a ResourceLoadWriter capable of reading JPG files.
Definition: ioJPG.hpp:58
VLCORE_EXPORT void setGlobalSettings(GlobalSettings *)
Sets VisulizationLibrary&#39;s global settings.
Definition: pimpl.cpp:56
Visualization Library main namespace.
The LoadWriterPNG class is a ResourceLoadWriter capable of reading PNG files.
Definition: ioPNG.hpp:57
The LoadWriterDICOM class is a ResourceLoadWriter capable of reading DICOM files (.dcm, .dicom, .dic, .ima, .ph, .mag) using GDCM 2.0 library.
Definition: ioDICOM.hpp:60
static void bug(const String &message)
Use this function to provide information about programming errors: wrong parameter initialization...
Definition: Log.cpp:175
The LoadWriterDAT class is a ResourceLoadWriter capable of reading DAT files.
Definition: ioDAT.hpp:55
Manages multiple VirtualDirectory objects.
Definition: FileSystem.hpp:58
A vl::ResourceLoadWriter capable of reading Visualization Library&#39;s VLT and VLB files.
Definition: ioVLX.hpp:67
The LoadWriterTIFF class is a ResourceLoadWriter capable of reading TIFF files.
Definition: ioTIFF.hpp:57
VLCORE_EXPORT void setDefFileSystem(FileSystem *fs)
Sets the default FileSystem used by VisualizationLibrary.
Definition: pimpl.cpp:101
std::vector< ref< ResourceLoadWriter > > & loadWriters()
Returns the set of registered ResourceLoadWriter objects.
#define NULL
Definition: OpenGLDefs.hpp:81
The StandardLog class outputs the log messages on the stdout device and optionally also on a specifie...
Definition: Log.hpp:228
VLCORE_EXPORT void setDefLoadWriterManager(LoadWriterManager *lwm)
Sets the default LoadWriterManager used by Visualization Library.
Definition: pimpl.cpp:86
Registry of vl::ClassWrapper objects, used by vl::VLXSerializer, see also vl::defVLXRegistry().
Definition: Registry.hpp:43
VLCORE_EXPORT void setDefLogger(Log *logger)
Installs the default logger used by Visualization Library. Setting this to NULL will disable logging...
Definition: pimpl.cpp:67
VLCORE_EXPORT void setDefMersenneTwister(MersenneTwister *)
Definition: pimpl.cpp:116
The ref<> class is used to reference-count an Object.
Definition: Object.hpp:55
The LoadWriterBMP class is a ResourceLoadWriter capable of reading BMP files.
Definition: ioBMP.hpp:55
The LoadWriterMHD class is a ResourceLoadWriter capable of reading MHD files.
Definition: ioMHD.hpp:55
#define VL_CHECK(expr)
Definition: checks.hpp:73
VLX_EXPORT void setDefVLXRegistry(Registry *reg)
Definition: pimpl.cpp:47
VLCORE_EXPORT LoadWriterManager * defLoadWriterManager()
Returs the default LoadWriterManager used by Visualization Library.
Definition: pimpl.cpp:82
VLCORE_EXPORT GlobalSettings * globalSettings()
Returns VisulizationLibrary&#39;s global settings.
Definition: pimpl.cpp:52
void registerLoadWriter(ResourceLoadWriter *rlw)
Utility function, equivalent to defLoadWriterManager()->registerLoadWriter(rlw).