00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045
00046 #include <OSGConfig.h>
00047 #include <OSGNodePtr.h>
00048 #include <OSGWindow.h>
00049 #include <OSGCamera.h>
00050 #include <OSGViewport.h>
00051 #include <OSGGeometry.h>
00052 #include <OSGDrawable.h>
00053
00054 #include <OSGGL.h>
00055 #include <OSGVolumeDraw.h>
00056
00057 #include <OSGDrawActionBase.h>
00058
00059 OSG_USING_NAMESPACE
00060
00061
00062
00063
00064
00065
00073
00074
00075
00076
00077 char DrawActionBase::cvsid[] = "@(#)$Id: $";
00078
00079 StatElemDesc<StatTimeElem>
00080 DrawActionBase::statTravTime ("travTime", "time for traversal");
00081
00082 StatElemDesc<StatIntElem>
00083 DrawActionBase::statCullTestedNodes("cullTestedNodes", "nodes tested");
00084
00085 StatElemDesc<StatIntElem>
00086 DrawActionBase::statCulledNodes("culledNodes", "nodes culled from frustum");
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00122 DrawActionBase::DrawActionBase(void) :
00123 Inherited ( ),
00124 _camera (NULL ),
00125 _background (NULL ),
00126 _window (NULL ),
00127 _viewport (NULL ),
00128 _statistics (NULL ),
00129 _ownStat (false),
00130 _frustumCulling(true ),
00131 _volumeDrawing (false),
00132 _autoFrustum (true ),
00133 _frustum ( ),
00134 _pMaterial ( ),
00135 _pMaterialNode ( ),
00136 _mCameraToWorld( )
00137 {
00138 }
00139
00140
00141 DrawActionBase::DrawActionBase(const DrawActionBase &source) :
00142 Inherited (source ),
00143 _camera (source._camera ),
00144 _background (source._background ),
00145 _window (source._window ),
00146 _viewport (source._viewport ),
00147 _statistics (source._statistics ),
00148 _ownStat (source._ownStat ),
00149 _frustumCulling(source._frustumCulling ),
00150 _volumeDrawing (source._volumeDrawing ),
00151 _autoFrustum (source._autoFrustum ),
00152 _frustum (source._frustum ),
00153 _pMaterial (source._pMaterial ),
00154 _pMaterialNode (source._pMaterialNode ),
00155 _mCameraToWorld(source._mCameraToWorld )
00156 {
00157 }
00158
00162 DrawActionBase::~DrawActionBase(void)
00163 {
00164 #if 0 // Altered for last frame time
00165
00166 #else
00167 if (_ownStat) {
00168 delete _statistics;
00169 }
00170 #endif
00171 }
00172
00173
00174
00175 void DrawActionBase::setMaterial(Material *pMaterial, NodePtr node)
00176 {
00177 _pMaterial = pMaterial;
00178 _pMaterialNode = node;
00179 }
00180
00181
00182 Action::ResultE DrawActionBase::start(void)
00183 {
00184 if(getFrustumCulling() == true &&
00185 getAutoFrustum () == true &&
00186 getCamera () != NULL &&
00187 getViewport () != NULL)
00188 {
00189 getCamera()->getFrustum( _frustum, *getViewport() );
00190
00191 }
00192
00193 if(_camera != NULL && getViewport() != NULL)
00194 {
00195 _camera->getViewing( _mCameraToWorld,
00196 getViewport()->getPixelWidth(),
00197 getViewport()->getPixelHeight() );
00198 _mCameraToWorld.invert();
00199 }
00200
00201
00202
00203
00204
00205
00206 #if 0 // Altered for last frame time
00207 if(_statistics == NULL)
00208 {
00209 _statistics = StatCollector::create();
00210 _ownStat = true;
00211 }
00212 else
00213 {
00214 _ownStat = false;
00215 }
00216 #else
00217 if(_statistics == NULL)
00218 {
00219 _statistics = StatCollector::create();
00220 _ownStat = true;
00221 }
00222 #endif
00223
00224 getStatistics()->getElem(statTravTime)->start();
00225 getStatistics()->getElem(statCullTestedNodes)->reset();
00226 getStatistics()->getElem(statCulledNodes)->reset();
00227
00228
00229 if(getStatistics()->getElem(Drawable::statNTriangles,false))
00230 {
00231 getStatistics()->getElem(Drawable::statNGeoBytes)->reset();
00232 getStatistics()->getElem(Drawable::statNTriangles)->set(0);
00233 getStatistics()->getElem(Drawable::statNLines)->set(0);
00234 getStatistics()->getElem(Drawable::statNPoints)->set(0);
00235 getStatistics()->getElem(Drawable::statNVertices)->set(0);
00236 getStatistics()->getElem(Drawable::statNPrimitives)->set(0);
00237 }
00238
00239
00240
00241 return Action::Continue;
00242 }
00243
00244 Action::ResultE DrawActionBase::stop(Action::ResultE res)
00245 {
00246 if ( getVolumeDrawing() )
00247 drawVolume( _frustum );
00248
00249 getStatistics()->getElem(statTravTime)->stop();
00250
00251 #if 0 // Altered for last frame time
00252 if(_ownStat)
00253 {
00254 delete _statistics;
00255 _statistics = NULL;
00256 }
00257 else
00258 {
00259 _ownStat = false;
00260 }
00261 #else
00262 if(_ownStat)
00263 {
00264 delete _statistics;
00265 _statistics = NULL;
00266 }
00267 #endif
00268
00269 return res;
00270 }
00271
00272
00273
00274 void DrawActionBase::setViewport(Viewport *viewport)
00275 {
00276 _viewport = viewport;
00277 }
00278
00279 void DrawActionBase::setCamera(Camera *cam)
00280 {
00281 _camera = cam;
00282 }
00283
00284 void DrawActionBase::setBackground(Background *background)
00285 {
00286 _background = background;
00287 }
00288
00289 void DrawActionBase::setWindow(Window *window)
00290 {
00291 _window = window;
00292 }
00293
00294 void DrawActionBase::setStatistics(StatCollector *statistics)
00295 {
00296 #if 0 // Altered for last frame time
00297 _statistics = statistics;
00298 _ownStat = false;
00299 #else
00300 if (_ownStat) {
00301 delete _statistics;
00302 }
00303 _statistics = statistics;
00304 _ownStat = false;
00305 #endif
00306 }
00307
00308
00309
00310
00311
00312 void DrawActionBase::setFrustumCulling(bool frustumCulling)
00313 {
00314 _frustumCulling = frustumCulling;
00315 }
00316
00317
00318
00319
00320 void DrawActionBase::setAutoFrustum(bool autoFrustum)
00321 {
00322 _autoFrustum = autoFrustum;
00323 }
00324
00325
00326
00327
00328 void DrawActionBase::setVolumeDrawing(bool volumeDrawing)
00329 {
00330 _volumeDrawing = volumeDrawing;
00331 }
00332
00333
00334
00335 void DrawActionBase::setFrustum(FrustumVolume &frustum)
00336 {
00337 _frustum = frustum;
00338 }
00339
00340
00341 UInt32 DrawActionBase::selectVisibles(void)
00342 {
00343 if(getFrustumCulling() == false)
00344 return getNNodes();
00345
00346 useNodeList();
00347
00348 Color3f col;
00349
00350 UInt32 count = 0;
00351 for ( UInt32 i = 0; i < getNNodes(); i++ )
00352 {
00353 if ( isVisible( getNode(i).getCPtr() ) )
00354 {
00355 col.setValuesRGB(0,1,0);
00356 addNode( getNode(i) );
00357 ++count;
00358 }
00359 else
00360 col.setValuesRGB(1,0,0);
00361
00362 if(getVolumeDrawing())
00363 {
00364 dropVolume(this, getNode(i), col);
00365 }
00366 }
00367
00368 return count;
00369 }
00370
00371