# Visualization Library

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

[Home] [Tutorials] [All Classes] [Grouped Classes]

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# D:/VL/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vlCore/init_core.cpp

Go to the documentation of this file.

    00001 /**************************************************************************************/
    00002 /*                                                                                    */
    00003 /*  Visualization Library                                                             */
    00004 /*  http://www.visualizationlibrary.com                                               */
    00005 /*                                                                                    */
    00006 /*  Copyright (c) 2005-2010, Michele Bosi                                             */
    00007 /*  All rights reserved.                                                              */
    00008 /*                                                                                    */
    00009 /*  Redistribution and use in source and binary forms, with or without modification,  */
    00010 /*  are permitted provided that the following conditions are met:                     */
    00011 /*                                                                                    */
    00012 /*  - Redistributions of source code must retain the above copyright notice, this     */
    00013 /*  list of conditions and the following disclaimer.                                  */
    00014 /*                                                                                    */
    00015 /*  - Redistributions in binary form must reproduce the above copyright notice, this  */
    00016 /*  list of conditions and the following disclaimer in the documentation and/or       */
    00017 /*  other materials provided with the distribution.                                   */
    00018 /*                                                                                    */
    00019 /*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND   */
    00020 /*  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED     */
    00021 /*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE            */
    00022 /*  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR  */
    00023 /*  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    */
    00024 /*  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;      */
    00025 /*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON    */
    00026 /*  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT           */
    00027 /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS     */
    00028 /*  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                      */
    00029 /*                                                                                    */
    00030 /**************************************************************************************/
    00031
    00032 #include <vlCore/VisualizationLibrary.hpp>
    00033 #include <vlCore/VLSettings.hpp>
    00034 #include <vlCore/FileSystem.hpp>
    00035 #include <vlCore/LoadWriterManager.hpp>
    00036 #include <vlCore/Log.hpp>
    00037 #include <vlCore/Say.hpp>
    00038 #include <vlCore/Quaternion.hpp>
    00039 #include <vlCore/AABB.hpp>
    00040 #include <vlCore/Sphere.hpp>
    00041 #include <vlCore/version.hpp>
    00042 #include <cassert>
    00043
    00044 using namespace vl;
    00045
    00046 #if defined(VL_IO_2D_JPG)
    00047   #include "plugins/vlJPG.hpp"
    00048 #endif
    00049 #if defined(VL_IO_2D_PNG)
    00050   #include "plugins/vlPNG.hpp"
    00051 #endif
    00052 #if defined(VL_IO_2D_TIFF)
    00053   #include "plugins/vlTIFF.hpp"
    00054 #endif
    00055 #if defined(VL_IO_2D_TGA)
    00056   #include "plugins/vlTGA.hpp"
    00057 #endif
    00058 #if defined(VL_IO_2D_DAT)
    00059   #include "plugins/vlDAT.hpp"
    00060 #endif
    00061 #if defined(VL_IO_2D_DDS)
    00062   #include "plugins/vlDDS.hpp"
    00063 #endif
    00064 #if defined(VL_IO_2D_BMP)
    00065   #include "plugins/vlBMP.hpp"
    00066 #endif
    00067 #if defined(VL_IO_2D_DICOM)
    00068   #include "plugins/vlDICOM.hpp"
    00069 #endif
    00070
    00071 //------------------------------------------------------------------------------
    00072 VL_COMPILE_TIME_CHECK( sizeof(double)    == 8 )
    00073 VL_COMPILE_TIME_CHECK( sizeof(float)     == 4 )
    00074 VL_COMPILE_TIME_CHECK( sizeof(long long) == 8 )
    00075 VL_COMPILE_TIME_CHECK( sizeof(int)       == 4 )
    00076 VL_COMPILE_TIME_CHECK( sizeof(short)     == 2 )
    00077 VL_COMPILE_TIME_CHECK( sizeof(char)      == 1 )
    00078 VL_COMPILE_TIME_CHECK( sizeof(wchar_t)   >= 2 )
    00079 VL_COMPILE_TIME_CHECK( sizeof(vec2)      == sizeof(Real)*2 )
    00080 VL_COMPILE_TIME_CHECK( sizeof(vec3)      == sizeof(Real)*3 )
    00081 VL_COMPILE_TIME_CHECK( sizeof(vec4)      == sizeof(Real)*4 )
    00082 VL_COMPILE_TIME_CHECK( sizeof(mat2)      == sizeof(Real)*2*2 )
    00083 VL_COMPILE_TIME_CHECK( sizeof(mat3)      == sizeof(Real)*3*3 )
    00084 VL_COMPILE_TIME_CHECK( sizeof(mat4)      == sizeof(Real)*4*4 )
    00085 VL_COMPILE_TIME_CHECK( sizeof(quat)      == sizeof(Real)*4 )
    00086 VL_COMPILE_TIME_CHECK( sizeof(AABB)      == sizeof(Real)*6 )
    00087 VL_COMPILE_TIME_CHECK( sizeof(Sphere)    == sizeof(Real)*4 )
    00088 //------------------------------------------------------------------------------
    00089 // VL misc
    00090 //------------------------------------------------------------------------------
    00091 namespace
    00092 {
    00093   std::string gVersionString = String( Say("%n.%n.%n") << VL_Major << VL_Minor << VL_Build ).toStdString();
    00094   bool gInitializedCore = false;
    00095 };
    00096 //------------------------------------------------------------------------------
    00097 bool VisualizationLibrary::isCoreInitialized() { return gInitializedCore; }
    00098 //------------------------------------------------------------------------------
    00099 const char* VisualizationLibrary::versionString() { return gVersionString.c_str(); }
    00100 //------------------------------------------------------------------------------
    00101 // Global VLSettings
    00102 //------------------------------------------------------------------------------
    00103 namespace
    00104 {
    00105   ref<VLSettings> gSettings = NULL;
    00106 }
    00107 VLSettings* vl::globalSettings()
    00108 {
    00109   return gSettings.get();
    00110 }
    00111 //------------------------------------------------------------------------------
    00112 // Default logger
    00113 //------------------------------------------------------------------------------
    00114 namespace
    00115 {
    00116   ref<Log> gDefaultLogger;
    00117 }
    00118 void vl::setDefLogger(Log* logger)
    00119 {
    00120   gDefaultLogger = logger;
    00121 }
    00122 Log* vl::defLogger()
    00123 {
    00124   return gDefaultLogger.get();
    00125 }
    00126 //------------------------------------------------------------------------------
    00127 // Default LoadWriterManager
    00128 //------------------------------------------------------------------------------
    00129 namespace
    00130 {
    00131   ref<LoadWriterManager> gDefaultLoadWriterManager = NULL;
    00132 }
    00133 LoadWriterManager* vl::defLoadWriterManager()
    00134 {
    00135   return gDefaultLoadWriterManager.get();
    00136 }
    00137 void vl::setDefLoadWriterManager(LoadWriterManager* lwm)
    00138 {
    00139   gDefaultLoadWriterManager = lwm;
    00140 }
    00141 //-----------------------------------------------------------------------------
    00142 // Default FileSystem
    00143 //-----------------------------------------------------------------------------
    00144 namespace
    00145 {
    00146   ref<FileSystem> gDefaultFileSystem = NULL;;
    00147 }
    00148 FileSystem* vl::defFileSystem()
    00149 {
    00150   return gDefaultFileSystem.get();
    00151 }
    00152 void vl::setDefFileSystem(FileSystem* fs)
    00153 {
    00154   gDefaultFileSystem = fs;
    00155 }
    00156 //------------------------------------------------------------------------------
    00157 void VisualizationLibrary::initCore(bool log_info)
    00158 {
    00159   VL_CHECK(!gInitializedCore);
    00160   if (gInitializedCore)
    00161   {
    00162     Log::bug("VisualizationLibrary::initCore(): Visualization Library Core is already initialized!\n");
    00163     return;
    00164   }
    00165
    00166   // --- Init Core ---
    00167
    00168   // Install globabl settings
    00169   gSettings = new VLSettings;
    00170
    00171   // Install default logger
    00172   ref<StandardLog> logger = new StandardLog;
    00173   logger->setLogFile( globalSettings()->defaultLogPath() );
    00174   setDefLogger( logger.get() );
    00175
    00176   // Install default LoadWriterManager
    00177   gDefaultLoadWriterManager = new LoadWriterManager;
    00178
    00179   // Install default FileSystem
    00180   gDefaultFileSystem = new FileSystem;
    00181   gDefaultFileSystem->directories()->push_back( new DiskDirectory( globalSettings()->defaultDataPath() ) );
    00182
    00183   // Register 2D modules
    00184   #if defined(VL_IO_2D_JPG)
    00185     registerLoadWriter(new LoadWriterJPG);
    00186   #endif
    00187   #if defined(VL_IO_2D_PNG)
    00188     registerLoadWriter(new LoadWriterPNG);
    00189   #endif
    00190   #if defined(VL_IO_2D_TIFF)
    00191     registerLoadWriter(new LoadWriterTIFF);
    00192   #endif
    00193   #if defined(VL_IO_2D_TGA)
    00194     registerLoadWriter(new LoadWriterTGA);
    00195   #endif
    00196   #if defined(VL_IO_2D_BMP)
    00197     registerLoadWriter(new LoadWriterBMP);
    00198   #endif
    00199   #if defined(VL_IO_2D_DDS)
    00200     registerLoadWriter(new LoadWriterDDS);
    00201   #endif
    00202   #if defined(VL_IO_2D_DAT)
    00203     registerLoadWriter(new LoadWriterDAT);
    00204   #endif
    00205   #if defined(VL_IO_2D_DICOM)
    00206     registerLoadWriter(new LoadWriterDICOM);
    00207   #endif
    00208
    00209   // Log VL and system information.
    00210   if (globalSettings()->verbosityLevel() && log_info)
    00211     Log::logSystemInfo();
    00212
    00213   // Initialized = on
    00214   gInitializedCore = true;
    00215 }
    00216 //------------------------------------------------------------------------------
    00217 void VisualizationLibrary::shutdownCore()
    00218 {
    00219   // Initialized = off
    00220   gInitializedCore = false;
    00221
    00222   // --- Dispose Core ---
    00223
    00224   // Dispose default LoadWriterManager
    00225   gDefaultLoadWriterManager->loadCallbacks()->clear();
    00226   gDefaultLoadWriterManager->writeCallbacks()->clear();
    00227   gDefaultLoadWriterManager->loadWriters()->clear();
    00228   gDefaultLoadWriterManager = NULL;
    00229
    00230   // Dispose default FileSystem
    00231   gDefaultFileSystem->directories()->clear();
    00232   gDefaultFileSystem = NULL;
    00233
    00234   // Dispose default logger
    00235   if (globalSettings()->verbosityLevel())
    00236   {
    00237     Log::print("Visualization Library shutdown.\n");
    00238   }
    00239   // we keep the logger alive as much as we can.
    00240   // setDefLogger( NULL );
    00241
    00242   // keep global settings (used by logger)
    00243   // gSettings = NULL;
    00244 }
    00245 //------------------------------------------------------------------------------
    00246 #if defined(_WIN32)
    00247   // console includes
    00248   #include <stdio.h>
    00249   #include <io.h>
    00250   #include <fcntl.h>
    00251   #include <commdlg.h>
    00252 #endif
    00253
    00254 void vl::showWin32Console()
    00255 {
    00256   #if defined(_WIN32)
    00257     AllocConsole();
    00258     // stdout
    00259     HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
    00260     int hCrt = _open_osfhandle((intptr_t)handle_out, _O_TEXT);
    00261     FILE* hf_out = _fdopen(hCrt, "w");
    00262     setvbuf(hf_out, NULL, _IONBF, 1);
    00263     *stdout = *hf_out;
    00264     // stderr
    00265     handle_out = GetStdHandle(STD_ERROR_HANDLE);
    00266     hCrt = _open_osfhandle((intptr_t)handle_out, _O_TEXT);
    00267     hf_out = _fdopen(hCrt, "w");
    00268     setvbuf(hf_out, NULL, _IONBF, 1);
    00269     *stderr = *hf_out;
    00270   #endif
    00271 }
    00272 //------------------------------------------------------------------------------

Visualization Library v2011.05.1142 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu May 26 2011 22:51:20.
Permission is granted to use this page to write and publish articles regarding Visualization Library.