[32] | 1 | #pragma once |
---|
| 2 | /* -*-c++-*- osgVisual - Copyright (C) 2009-2010 Torben Dannhauer |
---|
| 3 | * |
---|
| 4 | * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under |
---|
| 5 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or |
---|
| 6 | * (at your option) any later version. The full license is in LICENSE file |
---|
| 7 | * included with this distribution, and on the openscenegraph.org website. |
---|
| 8 | * |
---|
| 9 | * osgVisual requires for some proprietary modules a license from the correspondig manufacturer. |
---|
| 10 | * You have to aquire licenses for all used proprietary modules. |
---|
| 11 | * |
---|
| 12 | * This library is distributed in the hope that it will be useful, |
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | * OpenSceneGraph Public License for more details. |
---|
| 16 | */ |
---|
| 17 | |
---|
[86] | 18 | #include <osg/Notify> |
---|
| 19 | #include <osg/Referenced> |
---|
[32] | 20 | #include <osg/ArgumentParser> |
---|
| 21 | |
---|
| 22 | #include <osgViewer/Viewer> |
---|
| 23 | |
---|
[157] | 24 | // Cluster |
---|
[58] | 25 | #ifdef USE_CLUSTER_ASIO_TCP_IOSTREAM |
---|
| 26 | #include <dataIO_clusterAsioTcpIostream.h> |
---|
| 27 | #endif |
---|
[85] | 28 | #ifdef USE_CLUSTER_ENET |
---|
| 29 | #include <dataIO_clusterENet.h> |
---|
| 30 | #endif |
---|
[32] | 31 | #ifdef USE_CLUSTER_DUMMY |
---|
| 32 | #include <dataIO_clusterDummy.h> |
---|
| 33 | #endif |
---|
| 34 | |
---|
[58] | 35 | |
---|
[157] | 36 | //ExtLink |
---|
[32] | 37 | #ifdef USE_EXTLINK_DUMMY |
---|
| 38 | #include <dataIO_extLinkDummy.h> |
---|
| 39 | #endif |
---|
| 40 | #ifdef USE_EXTLINK_VCL |
---|
| 41 | #include <dataIO_extLinkVCL.h> |
---|
| 42 | #endif |
---|
| 43 | |
---|
| 44 | |
---|
[157] | 45 | // Slot and transportContainer definitions |
---|
[32] | 46 | #include <dataIO_slot.h> |
---|
| 47 | #include <dataIO_transportContainer.h> |
---|
| 48 | |
---|
[157] | 49 | // XML Parser |
---|
| 50 | #include <stdio.h> |
---|
| 51 | #include <libxml/parser.h> |
---|
| 52 | #include <libxml/tree.h> |
---|
| 53 | |
---|
| 54 | // C++ stl libraries |
---|
[32] | 55 | #include <vector> |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | namespace osgVisual { |
---|
| 61 | |
---|
| 62 | /** |
---|
| 63 | * \brief Zentrale Klasse für Datenanbindung des Sichtsystemnodes an das Gesamtsichtsystem bzw. dem Simulator. |
---|
| 64 | * |
---|
| 65 | * Damit nur eine Klasse instantiiert werden kann, ist diese Klasse als Singleton realisiert. |
---|
| 66 | * |
---|
| 67 | * |
---|
| 68 | * @author Torben Dannhauer |
---|
| 69 | * @date Nov 2009 |
---|
| 70 | */ |
---|
| 71 | class visual_dataIO : public osg::Referenced |
---|
| 72 | { |
---|
[88] | 73 | #include <leakDetection.h> |
---|
[32] | 74 | private: |
---|
| 75 | class dataIO_eventCallback : public osg::NodeCallback |
---|
| 76 | { |
---|
| 77 | public: |
---|
| 78 | /** |
---|
| 79 | * \brief Constructor, for setting the member variables. |
---|
| 80 | * |
---|
| 81 | * @param viewer_ : Pointer to the viewer. |
---|
| 82 | * @param sceneCamera_ : Pointer to the scene camera. |
---|
| 83 | */ |
---|
| 84 | dataIO_eventCallback(visual_dataIO* dataIO_):dataIO(dataIO_){}; |
---|
| 85 | |
---|
| 86 | /** |
---|
| 87 | * \brief This function is execute d as callback during update traversal. |
---|
| 88 | * |
---|
| 89 | */ |
---|
| 90 | virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); |
---|
| 91 | private: |
---|
| 92 | visual_dataIO* dataIO; |
---|
| 93 | }; |
---|
| 94 | osg::ref_ptr<dataIO_eventCallback> eventCallback; |
---|
| 95 | |
---|
| 96 | class dataIO_finalDrawCallback : public osg::Camera::DrawCallback |
---|
| 97 | { |
---|
| 98 | public: |
---|
| 99 | /** |
---|
| 100 | * \brief Constructor |
---|
| 101 | * |
---|
| 102 | */ |
---|
[96] | 103 | dataIO_finalDrawCallback(visual_dataIO* dataIO_):dataIO(dataIO_){}; |
---|
[32] | 104 | |
---|
| 105 | /** |
---|
| 106 | * \brief Operator executed at callback |
---|
| 107 | * |
---|
| 108 | */ |
---|
| 109 | virtual void operator () (const osg::Camera& camera) const; |
---|
| 110 | private: |
---|
| 111 | visual_dataIO* dataIO; |
---|
| 112 | }; |
---|
| 113 | |
---|
| 114 | osg::ref_ptr<dataIO_finalDrawCallback> finalDrawCallback; |
---|
| 115 | |
---|
[157] | 116 | /** |
---|
| 117 | * \brief Constructor: It is private to prevent creating instances via ptr* = new ..(). |
---|
| 118 | * |
---|
| 119 | */ |
---|
[32] | 120 | visual_dataIO(); |
---|
[157] | 121 | |
---|
| 122 | /** |
---|
| 123 | * \brief Copy-Constuctor: It is private to prevent getting instances via copying dataIO instance. |
---|
| 124 | * |
---|
| 125 | * @param cc : Instance to copy from. |
---|
| 126 | */ |
---|
[32] | 127 | visual_dataIO(const visual_dataIO& cc); |
---|
| 128 | |
---|
[157] | 129 | /** |
---|
| 130 | * \brief This function parses the XML config file for dataIO relevant parameters. |
---|
| 131 | * |
---|
| 132 | * @return : True if parsing was successful. |
---|
| 133 | */ |
---|
| 134 | bool processXMLConfiguration(); |
---|
| 135 | |
---|
| 136 | /** |
---|
| 137 | * \brief Todo: required? |
---|
| 138 | * |
---|
| 139 | * @return |
---|
| 140 | */ |
---|
[81] | 141 | osg::Matrixd calcViewMatrix(); |
---|
[157] | 142 | |
---|
| 143 | /** |
---|
| 144 | * Pointer to the base class of the extLink implementation. |
---|
| 145 | */ |
---|
[32] | 146 | osg::ref_ptr<dataIO_extLink> extLink; |
---|
[157] | 147 | |
---|
| 148 | /** |
---|
| 149 | * Pointer to the base class of the cluster implementation. |
---|
| 150 | */ |
---|
[32] | 151 | osg::ref_ptr<dataIO_cluster> cluster; |
---|
| 152 | |
---|
| 153 | /** |
---|
[157] | 154 | * Referenced pointer to the applications viewer. |
---|
[32] | 155 | */ |
---|
| 156 | osg::ref_ptr<osgViewer::Viewer> viewer; |
---|
| 157 | |
---|
[157] | 158 | /** |
---|
| 159 | * Referenced pointer transport contained user to transport the set of all slots to all rendering machines. |
---|
| 160 | */ |
---|
[32] | 161 | osg::ref_ptr<osgVisual::dataIO_transportContainer> slotContainer; |
---|
| 162 | |
---|
| 163 | /** |
---|
| 164 | * List of SLOT variables dataIO provides. |
---|
| 165 | */ |
---|
[118] | 166 | std::vector<dataIO_slot*> dataSlots; |
---|
[32] | 167 | |
---|
[157] | 168 | /** |
---|
| 169 | * Flag to indicate if dataIO is initialized. |
---|
| 170 | */ |
---|
| 171 | bool initialized; |
---|
| 172 | |
---|
| 173 | /** |
---|
[158] | 174 | * Curent clustermode of the application. Can be MASTER, SLAVE or STANDALONE. |
---|
| 175 | */ |
---|
| 176 | osgVisual::dataIO_cluster::clustermode clusterMode; |
---|
| 177 | |
---|
| 178 | /** |
---|
[157] | 179 | * The eventCallback-class is friend to be able to work with all dataIO members without setters/getters. |
---|
| 180 | */ |
---|
[96] | 181 | friend class dataIO_eventCallback; |
---|
[157] | 182 | |
---|
| 183 | /** |
---|
| 184 | * The FinalDrawCallback-class is friend to be able to work with all dataIO members without setters/getters. |
---|
| 185 | */ |
---|
[96] | 186 | friend class dataIO_finalDrawCallback; |
---|
[32] | 187 | |
---|
| 188 | public: |
---|
[157] | 189 | /** |
---|
| 190 | * \brief Public destructor to allow singleton cleanup from extern |
---|
| 191 | * |
---|
| 192 | */ |
---|
[32] | 193 | ~visual_dataIO(); |
---|
| 194 | |
---|
| 195 | /** |
---|
[158] | 196 | * \brief This function returns an pointer to the singleton instance of dataIO. If no instance exist, it will be instantiated silently. |
---|
[32] | 197 | * |
---|
| 198 | * After instantiation, dataIO still needs to bei initiialized to configure working mode etc! |
---|
| 199 | * |
---|
| 200 | * @return : Pointer to the instance. |
---|
| 201 | */ |
---|
| 202 | static visual_dataIO* getInstance(); |
---|
| 203 | |
---|
[144] | 204 | void init(osgViewer::Viewer* viewer_,osg::ArgumentParser& arguments_, std::string configFileName); |
---|
[32] | 205 | void shutdown(); |
---|
| 206 | bool isMaster(){if (clusterMode==osgVisual::dataIO_cluster::MASTER) return true; else return false;}; |
---|
| 207 | bool isSlave(){if (clusterMode==osgVisual::dataIO_cluster::SLAVE) return true; else return false;}; |
---|
| 208 | bool isStandalone(){if (clusterMode==osgVisual::dataIO_cluster::STANDALONE) return true; else return false;}; |
---|
| 209 | |
---|
| 210 | // SLOT Access functions |
---|
| 211 | void* getSlotPointer(std::string slotName_, osgVisual::dataIO_slot::dataDirection direction_, osgVisual::dataIO_slot::varType variableTyp_ ); |
---|
| 212 | double getSlotDataAsDouble(std::string variableName_, osgVisual::dataIO_slot::dataDirection direction_ ); |
---|
| 213 | std::string getSlotDataAsString(std::string variableName_, osgVisual::dataIO_slot::dataDirection direction_ ); |
---|
[116] | 214 | osgVisual::dataIO_slot* setSlotData(std::string variableName_, osgVisual::dataIO_slot::dataDirection direction_, std::string sValue_ ); |
---|
| 215 | osgVisual::dataIO_slot* setSlotData(std::string variableName_, osgVisual::dataIO_slot::dataDirection direction_, double value_ ); |
---|
[32] | 216 | |
---|
| 217 | int getSlotNum() {return dataSlots.size();} |
---|
| 218 | |
---|
| 219 | }; |
---|
| 220 | |
---|
| 221 | |
---|
| 222 | } // END namespace osgVisual |
---|