source: osgVisual/trunk/src/vista2D/visual_vista2D.cpp @ 307

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

Updated copyright NOTICE
(No code changes)

File size: 6.8 KB
RevLine 
[221]1/* -*-c++-*- osgVisual - Copyright (C) 2009-2011 Torben Dannhauer
[31]2 *
3 * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * osgVisual requires for some proprietary modules a license from the correspondig manufacturer.
9 * You have to aquire licenses for all used proprietary modules.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * OpenSceneGraph Public License for more details.
15*/
16
17#include "visual_vista2D.h"
18
19
20using namespace osgVisual;
21
22visual_vista2D::visual_vista2D(void)
23{
[155]24        OSG_NOTIFY (osg::ALWAYS ) << "visual_vista2D instantiated." << std::endl;
25
[31]26   // Create a Vista2D View
27   view = new Vista2D::VistaView();
[156]28
29        vistaProjectfile = "";
30        paintBackground = false;
31        playanimation = false;
32        position_x = 0;
33        position_y = 0;
34        zoom = 1;
[31]35}
36
37visual_vista2D::~visual_vista2D(void)
38{
[156]39        view->stopView();
[31]40}
41
[156]42void visual_vista2D::startVista2D()
[153]43{
[31]44    /***************
45    load view
46    ***************/
[155]47        view->load( vistaProjectfile );
[153]48    view->setBackgroundMode(paintBackground);   // don't paint background
[156]49        view->setPosition( position_x, position_y);
[153]50        view->setZoom( zoom );
[31]51
52    /***************
53    start animation with
54    self running datasource
55    ***************/
[156]56    view->startView (playanimation);
[31]57}
58
[156]59bool visual_vista2D::processXMLConfiguration()
[31]60{
[153]61        // Init XML
62        xmlDoc* tmpDoc;
63        bool disabled;
[155]64        xmlNode* config = util::getModuleXMLConfig( configFileName, "vista2d", tmpDoc, disabled );
[153]65
66        if( disabled)
67        {
68                OSG_NOTIFY( osg::ALWAYS ) << "..disabled by XML configuration file." << std::endl;
69                return false;
70        }
71       
72        // extract configuration values
73        if(config)
74        {
75                xmlNode* a_node = config->children;
76
77                for (xmlNode *cur_node = a_node; cur_node; cur_node = cur_node->next)
78                {
79                std::string node_name=reinterpret_cast<const char*>(cur_node->name);
80                        //OSG_ALWAYS << "----visual_vista2D::processXMLConfiguration() - node type="<< cur_node->type <<", name=" << cur_node->name << std::endl;
81
82                        // Check for vista2d node
83                        if(cur_node->type == XML_ELEMENT_NODE && node_name == "vista2d")
84                        {
85                                // Check attributes
86                                xmlAttr  *attr = cur_node->properties;
87                                while ( attr ) 
88                                { 
89                                        std::string attr_name=reinterpret_cast<const char*>(attr->name);
90                                        std::string attr_value=reinterpret_cast<const char*>(attr->children->content);
91
92                                        if( attr_name == "filename" )
93                                        {
[155]94                                                vistaProjectfile=attr_value;
[153]95                                        }
96
97                                        if( attr_name == "paintBackground" )
98                                        {
99                                                paintBackground = (attr_value == "yes") ? true : false;
100                                        }
101
102                                        if( attr_name == "position_x" )
103                                        {
104                                                std::stringstream sstr(attr_value);
105                                                sstr >> position_x;
106                                        }
107
108                                        if( attr_name == "position_y" )
109                                        {
110                                                std::stringstream sstr(attr_value);
111                                                sstr >> position_y;
112                                        }
113
114                                        if( attr_name == "zoom" )
115                                        {
116                                                std::stringstream sstr(attr_value);
117                                                sstr >> zoom;
118                                        }
119
[156]120                                        if( attr_name == "playanimation" )
121                                        {
122                                                playanimation = (attr_value == "yes") ? true : false;
123                                        }
124
[153]125                                        attr = attr->next;
126                                }       // WHILE attr END
127                        }       // IF node == vista2d END
128                }       // FOR end
129       
130                // clean up
131                xmlFreeDoc(tmpDoc); xmlCleanupParser();
132                return true;
133        }       // IF Config valid END
134        else
135        {
136                OSG_WARN << "ERROR: visual_vista2D::processXMLConfiguration() - Module configuration not found" << std::endl;
137                return false;
138        }
139
140        return true;
141}
142
143bool visual_vista2D::init( osg::CoordinateSystemNode *sceneGraphRoot_, std::string configFileName )
144{
145        OSG_NOTIFY (osg::ALWAYS ) << "visual_vista2D initialize..";  // The sentence is finished by the init result...
146
[156]147        this->configFileName = configFileName;
[153]148
[155]149        // Process XML configuration
[156]150        if(!processXMLConfiguration())
[153]151                return false;   // Abort vista2D initialization.
152
[155]153        // Check if Vista2D project file exists
154        if ( !osgDB::fileExists(vistaProjectfile) )
[31]155        {
[155]156                OSG_ALWAYS << "WARNING: visual_vista2D::init() - Specified vista2D projectfile '"<< vistaProjectfile <<"' does not exist! Skip using Vista2D!" << std::endl;
[31]157                return false;
158        }
159
160   osg::Geode* vista2Dgeode = new osg::Geode();
161   // Projection node for defining view frustrum for the vista2D-SceneOverlay:
162   osg::Projection* vista2DProjectionMatrix = new osg::Projection;
163
164    // Initialize the projection matrix for viewing everything we
165   // will add as descendants of this node. Use screen coordinates
166   // to define the horizontal and vertical extent of the projection
167   // matrix. Positions described under this node will equate to
168   // pixel coordinates.
[145]169   vista2DProjectionMatrix->setMatrix(osg::Matrix::ortho2D(0,1600,0,900)); /** todo: use screen size dynamically. */
[31]170 
171   // For the HUD model view matrix use an identity matrix:
172   osg::MatrixTransform* vista2DModelViewMatrix = new osg::MatrixTransform;
173   vista2DModelViewMatrix->setMatrix(osg::Matrix::identity());
174
175   // Make sure the model view matrix is not affected by any transforms
176   // above it in the scene graph:
177   vista2DModelViewMatrix->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
178
179   // Set Stateset of vista2DGeode Renderbin to render quite late..
180        osg::StateSet* vista2DoverlayStateSet = vista2Dgeode->getOrCreateStateSet();
181        vista2DoverlayStateSet->setRenderBinDetails( 99, "RenderBin");
182
183   // Add the HUD projection matrix as a child of the root node
184   // and the HUD model view matrix as a child of the projection matrix
185   // Anything under this node will be viewed using this projection matrix
186   // and positioned with this model view matrix.
187   vista2DProjectionMatrix->addChild(vista2DModelViewMatrix);
188
189   // Add the Geometry node to contain HUD geometry as a child of the
190   // HUD model view matrix.
191   vista2DModelViewMatrix->addChild( vista2Dgeode );
192
193        // Add Payload: Vista2D                 
[156]194        startVista2D();
[31]195
[156]196        // Add this class to the scene Graph
197        this->setUseDisplayList( false );
198        vista2Dgeode->addDrawable( this );
[31]199
200        sceneGraphRoot_->addChild( vista2DProjectionMatrix );
201        return true;
202}
203
204void visual_vista2D::drawImplementation(osg::RenderInfo& renderInfo) const
205{
206        // save OSG-State
207        osg::ref_ptr<osg::StateSet> clonedStateSet = reinterpret_cast<osg::StateSet*>( renderInfo.getCurrentCamera()->getOrCreateStateSet()->clone(osg::CopyOp::DEEP_COPY_ALL) );
208
209        // Draw View
210    view->draw();
211
212        // restore OSG-State
213        renderInfo.getCurrentCamera()->setStateSet( clonedStateSet );
214
215}
216
217osg::Object* visual_vista2D::cloneType() const
218{
219        return NULL;
220}
221
222osg::Object* visual_vista2D::clone(const osg::CopyOp& copyop) const
223{ 
224        return NULL;
225}
Note: See TracBrowser for help on using the repository browser.