source: osgVisual/trunk/include/dataIO/visual_dataIO.h @ 221

Last change on this file since 221 was 221, checked in by Torben Dannhauer, 13 years ago

Updated copyright NOTICE
(No code changes)

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