OpenWalnut 1.3.1
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WKERNEL_H 00026 #define WKERNEL_H 00027 00028 #include <string> 00029 #include <vector> 00030 00031 #include <boost/shared_ptr.hpp> 00032 00033 #include "../common/WTimer.h" 00034 #include "../common/WLogger.h" 00035 #include "../graphicsEngine/WGraphicsEngine.h" 00036 00037 #include "WBatchLoader.h" 00038 00039 00040 00041 // forward declarations 00042 class WGUI; 00043 class WModule; 00044 class WModuleContainer; 00045 class WModuleFactory; 00046 class WROIManager; 00047 class WSelectionManager; 00048 class WThreadedRunner; 00049 00050 /** 00051 * \defgroup kernel Kernel 00052 * 00053 * \brief 00054 * This library implements the central part of OpenWalnut that manages 00055 * the interaction between GUI, GraphicsEngine and DataHandler. 00056 */ 00057 00058 /** 00059 * OpenWalnut kernel, managing modules and interaction between 00060 * GUI, GE and DataHandler 00061 * \ingroup kernel 00062 */ 00063 class WKernel: public WThreadedRunner 00064 { 00065 public: 00066 /** 00067 * Returns pointer to the running kernel or a new if no kernel was there. 00068 * If a running kernel exists the function return it and does not check if 00069 * ge and gui of the running kernel are equivalent to the ones given as parameters. 00070 * 00071 * \param ge initialized graphics engine. 00072 * \param gui initialized gui. 00073 * \return the kernel instance. 00074 */ 00075 static WKernel* instance( boost::shared_ptr< WGraphicsEngine > ge, boost::shared_ptr< WGUI > gui ); 00076 00077 /** 00078 * Destructor. 00079 */ 00080 virtual ~WKernel(); 00081 00082 /** 00083 * Stops execution of the modules in the root container. Note that this does not wait for the kernel thread since this could 00084 * cause a dead lock. This is actually an alias for getRootContainer()->stop(). 00085 */ 00086 void finalize(); 00087 00088 /** 00089 * Returns pointer to currently running instance of graphics engine. 00090 * 00091 * \return the graphics engine instance. 00092 */ 00093 boost::shared_ptr< WGraphicsEngine > getGraphicsEngine() const; 00094 00095 /** 00096 * Returns pointer to the currently running kernel. 00097 * 00098 * \return the kernel instance. 00099 */ 00100 static WKernel* getRunningKernel(); 00101 00102 /** 00103 * Determines whether all threads should finish. 00104 * 00105 * \return true if so. 00106 */ 00107 const WBoolFlag& isFinishRequested() const; 00108 00109 /** 00110 * Load specified datasets. It immediately returns and starts another thread, which actually loads the data. 00111 * 00112 * \param filenames list of filenames to load. The registered notification handler for the root container will get notified on 00113 * error and success. 00114 * \param suppressColormaps if true, the data modules are instructed to avoid registration of colormaps. This can be very handy if you 00115 * combine multiple data loaders into one new data loader or data set 00116 * 00117 * \return the batch loader responsible for loading. Can be queried for the list of data modules. 00118 */ 00119 WBatchLoader::SPtr loadDataSets( std::vector< std::string > filenames, bool suppressColormaps = false ); 00120 00121 /** 00122 * Loads the specified files synchronously. 00123 * 00124 * \param filenames list of filenames to load. The registered notification handler for the root container will get notified on 00125 * error and success. 00126 * \param suppressColormaps if true, the data modules are instructed to avoid registration of colormaps. This can be very handy if you 00127 * combine multiple data loaders into one new data loader or data set 00128 * 00129 * \return the batch loader responsible for loading. Can be queried for the list of data modules. 00130 */ 00131 WBatchLoader::SPtr loadDataSetsSynchronously( std::vector< std::string > filenames, bool suppressColormaps = false ); 00132 00133 /** 00134 * Function combines to modules. This is a simple alias for "getRootContainer()->applyModule". It runs synchronously, which 00135 * could freeze the calling thread for a couple of time. 00136 * 00137 * \param applyOn the module which already has to be in the container and to apply the other one on. 00138 * \param prototype the prototype of the module to apply on the other one specified. 00139 * 00140 * \return the newly created module connected with the one specified in applyOn. 00141 */ 00142 boost::shared_ptr< WModule > applyModule( boost::shared_ptr< WModule > applyOn, boost::shared_ptr< WModule > prototype ); 00143 00144 /** 00145 * Returns the root module container. This is the actual module graph container. 00146 * 00147 * \return the root container. 00148 */ 00149 boost::shared_ptr< WModuleContainer > getRootContainer() const; 00150 00151 /** 00152 * Getter for the associated GUI. 00153 * 00154 * \return the GUI. 00155 */ 00156 boost::shared_ptr< WGUI > getGui() const; 00157 00158 /** 00159 * get for roi manager 00160 * 00161 * \return Pointer to the ROI manager. 00162 */ 00163 boost::shared_ptr< WROIManager> getRoiManager(); 00164 00165 /** 00166 * get for selection manager 00167 * 00168 * \return Pointer to the selection manager. 00169 */ 00170 boost::shared_ptr< WSelectionManager> getSelectionManager(); 00171 00172 /** 00173 * Returns the system timer. If you need timing for animations and similar, use this one. This timer can change to frame based timing if the 00174 * user plays back some animation. So, everything which uses this timer can always do accurate per-frame animations even if frame time and 00175 * real-time differ. 00176 * 00177 * \return the timer 00178 */ 00179 WTimer::ConstSPtr getTimer() const; 00180 00181 protected: 00182 /** 00183 * Constructor is protected because this class is a singleton. Awaits an INITIALIZED graphics engine an gui. 00184 * 00185 * \param ge initialized graphics engine. 00186 * \param gui initialized gui. 00187 */ 00188 WKernel( boost::shared_ptr< WGraphicsEngine > ge, boost::shared_ptr< WGUI > gui ); 00189 00190 /** 00191 * Function that has to be overwritten for execution. It gets executed in a separate thread after run() 00192 * has been called. 00193 */ 00194 virtual void threadMain(); 00195 00196 /** 00197 * The Gui. 00198 */ 00199 boost::shared_ptr< WGUI > m_gui; 00200 00201 /** 00202 * Pointer to an initialized graphics engine. 00203 */ 00204 boost::shared_ptr< WGraphicsEngine > m_graphicsEngine; 00205 00206 /** 00207 * Pointer to a roi manager 00208 */ 00209 boost::shared_ptr< WROIManager >m_roiManager; 00210 00211 /** 00212 * pointer to a selection manager 00213 */ 00214 boost::shared_ptr< WSelectionManager >m_selectionManager; 00215 00216 /** 00217 * The module factory to use. 00218 */ 00219 boost::shared_ptr< WModuleFactory > m_moduleFactory; 00220 00221 /** 00222 * The container containing the modules. 00223 */ 00224 boost::shared_ptr< WModuleContainer > m_moduleContainer; 00225 00226 private: 00227 /** 00228 * Loads all the modules it can find. 00229 */ 00230 void loadModules(); 00231 00232 /** 00233 * Initializes the graphics engine, data handler and so on. 00234 */ 00235 void init(); 00236 00237 /** 00238 * Pointer to the unique instance of this singleton class. 00239 */ 00240 static WKernel* m_kernel; 00241 00242 /** 00243 * The ow system timer. 00244 */ 00245 WTimer::SPtr m_timer; 00246 }; 00247 00248 #endif // WKERNEL_H 00249