Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGDrawAction.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 //---------------------------------------------------------------------------
00040 //  Includes
00041 //---------------------------------------------------------------------------
00042 
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045 
00046 #include "OSGConfig.h"
00047 
00048 #include <OSGLog.h>
00049 #include <OSGFieldContainer.h>
00050 #include <OSGFieldContainerPtr.h>
00051 #include <OSGNode.h>
00052 #include <OSGNodeCore.h>
00053 #include "OSGAction.h"
00054 #include "OSGDrawAction.h"
00055 
00056 #include <OSGGL.h>
00057 #include <OSGVolumeDraw.h>
00058 
00059 OSG_USING_NAMESPACE
00060 
00061 /***************************************************************************\
00062  *                            Description                                  *
00063 \***************************************************************************/
00064 
00072 /***************************************************************************\
00073  *                               Types                                     *
00074 \***************************************************************************/
00075 
00076 /***************************************************************************\
00077  *                           Class variables                               *
00078 \***************************************************************************/
00079 
00080 char DrawAction::cvsid[] = "@(#)$Id: $";
00081 
00082 DrawAction * DrawAction::_prototype = NULL;
00083 
00084 std::vector<Action::Functor> *DrawAction::_defaultEnterFunctors = NULL;
00085 std::vector<Action::Functor> *DrawAction::_defaultLeaveFunctors = NULL;
00086 
00087 /***************************************************************************\
00088  *                           Class methods                                 *
00089 \***************************************************************************/
00090 
00091 
00092 
00093 /*-------------------------------------------------------------------------*\
00094  -  public                                                                 -
00095 \*-------------------------------------------------------------------------*/
00096 
00097 void DrawAction::registerEnterDefault(  const FieldContainerType &type, 
00098                                         const Action::Functor &func )
00099 {
00100     if ( ! _defaultEnterFunctors )
00101         _defaultEnterFunctors = new std::vector<Action::Functor>;
00102 
00103     while(type.getId() >= _defaultEnterFunctors->size())
00104     {
00105         _defaultEnterFunctors->push_back( 
00106             osgTypedFunctionFunctor2CPtrRef<
00107                 ResultE, 
00108                 CNodePtr,
00109                 Action *                   >(&Action::_defaultEnterFunction));
00110     }
00111     
00112     (*_defaultEnterFunctors)[ type.getId() ] = func;
00113 }
00114 
00115 void DrawAction::registerLeaveDefault(  const FieldContainerType &type, 
00116                                         const Action::Functor &func )
00117 {
00118     if ( ! _defaultLeaveFunctors )
00119         _defaultLeaveFunctors = new std::vector<Action::Functor>;
00120 
00121     while(type.getId() >= _defaultLeaveFunctors->size())
00122     {
00123         _defaultLeaveFunctors->push_back( 
00124             osgTypedFunctionFunctor2CPtrRef<
00125                 ResultE, 
00126                 CNodePtr,
00127                 Action *                   >(&Action::_defaultLeaveFunction));
00128     }
00129     
00130     (*_defaultLeaveFunctors)[ type.getId() ] = func;
00131 }
00132 
00133 
00134 void DrawAction::setPrototype( DrawAction * proto )
00135 {
00136     _prototype = proto;
00137 }
00138 
00139 DrawAction *DrawAction::getPrototype( void )
00140 {
00141     return _prototype;
00142 }
00143 
00144 /*-------------------------------------------------------------------------*\
00145  -  protected                                                              -
00146 \*-------------------------------------------------------------------------*/
00147 
00148 
00149 /*-------------------------------------------------------------------------*\
00150  -  private                                                                -
00151 \*-------------------------------------------------------------------------*/
00152 
00153 
00154 
00155 /***************************************************************************\
00156  *                           Instance methods                              *
00157 \***************************************************************************/
00158 
00159 /*-------------------------------------------------------------------------*\
00160  -  public                                                                 -
00161 \*-------------------------------------------------------------------------*/
00162 
00163 /*------------- constructors & destructors --------------------------------*/
00164 
00168 DrawAction::DrawAction(void) :
00169      Inherited (),
00170     _lightCount(0)
00171 {
00172     if ( _defaultEnterFunctors )
00173         _enterFunctors = *_defaultEnterFunctors;
00174 
00175     if ( _defaultLeaveFunctors )
00176         _leaveFunctors = *_defaultLeaveFunctors;
00177 }
00178 
00179 
00183 DrawAction::DrawAction( const DrawAction & source ) :
00184      Inherited (source),
00185     _lightCount(source._lightCount)
00186 {
00187 }
00188 
00192 DrawAction * DrawAction::create( void )
00193 {
00194     DrawAction * act;
00195     
00196     if ( _prototype )
00197         act = new DrawAction( *_prototype );
00198     else
00199         act = new DrawAction();
00200     
00201     return act;
00202 }
00203 
00204 
00208 DrawAction::~DrawAction(void)
00209 {
00210 }
00211 
00212 /*------------------------------ access -----------------------------------*/
00213 
00214 /*-------------------------- your_category---------------------------------*/
00215 
00216 
00217 Action::ResultE DrawAction::start( void )
00218 {
00219     Inherited::start();
00220     
00221     _lightCount = 0;
00222     
00223     return Continue;
00224 }
00225 
00226 bool DrawAction::isVisible( Node* node )
00227 {
00228     if ( getFrustumCulling() == false )
00229         return true;
00230         
00231     getStatistics()->getElem(statCullTestedNodes)->inc();
00232     
00233     DynamicVolume vol;
00234     node->getWorldVolume( vol );
00235 
00236     if ( _frustum.intersect( vol ) )
00237     {
00238 // fprintf(stderr,"%p: node 0x%p vis\n", Thread::getCurrent(), node);
00239         return true;
00240     }
00241     
00242     getStatistics()->getElem(statCulledNodes)->inc();
00243 
00244 // fprintf(stderr,"%p: node 0x%p invis\n", Thread::getCurrent(), node);
00245 // _frustum.dump();            
00246     return false;
00247 }
00248 
00249 /*-------------------------- assignment -----------------------------------*/
00250 
00254 /*
00255 
00256 DrawAction& DrawAction::operator = (const DrawAction &source)
00257 {
00258     if (this == &source)
00259         return *this;
00260 
00261     // copy parts inherited from parent
00262     *(static_cast<Inherited *>(this)) = source;
00263 
00264     // free mem alloced by members of 'this'
00265 
00266     // alloc new mem for members
00267 
00268     // copy 
00269 }
00270 
00271 */
00272 
00273 /*-------------------------- comparison -----------------------------------*/
00274 
00278 bool DrawAction::operator < (const DrawAction &other) const
00279 {
00280     return this < &other;
00281 }
00282 
00286 bool DrawAction::operator == (const DrawAction &OSG_CHECK_ARG(other)) const
00287 {
00288     return false;
00289 }
00290 
00294 bool DrawAction::operator != (const DrawAction &other) const
00295 {
00296     return ! (*this == other);
00297 }
00298 
00299 
00300 /*-------------------------------------------------------------------------*\
00301  -  protected                                                              -
00302 \*-------------------------------------------------------------------------*/
00303 
00304 
00305 std::vector<DrawAction::Functor>* DrawAction::getDefaultEnterFunctors( void )
00306 {
00307     return _defaultEnterFunctors;
00308 }
00309 
00310 std::vector<DrawAction::Functor>* DrawAction::getDefaultLeaveFunctors( void )
00311 {
00312     return _defaultLeaveFunctors;
00313 }
00314 
00315 /*-------------------------------------------------------------------------*\
00316  -  private                                                                -
00317 \*-------------------------------------------------------------------------*/
00318 
00319 
00320 
00324 //:  Example for the head comment of a function
00327 //p: Paramaters: 
00328 //p: 
00330 //g: GlobalVars:
00331 //g: 
00333 //r: Return:
00334 //r: 
00336 //c: Caution:
00337 //c: 
00339 //a: Assumptions:
00340 //a: 
00342 //d: Description:
00343 //d: 
00345 //s: SeeAlso:
00346 //s: 
00348 

Generated on Thu Aug 25 04:03:08 2005 for OpenSG by  doxygen 1.4.3