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::statNTriangles)->set(0);
00232 getStatistics()->getElem(Drawable::statNLines)->set(0);
00233 getStatistics()->getElem(Drawable::statNPoints)->set(0);
00234 getStatistics()->getElem(Drawable::statNVertices)->set(0);
00235 getStatistics()->getElem(Drawable::statNPrimitives)->set(0);
00236 }
00237
00238
00239
00240 return Action::Continue;
00241 }
00242
00243 Action::ResultE DrawActionBase::stop(Action::ResultE res)
00244 {
00245 if ( getVolumeDrawing() )
00246 drawVolume( _frustum );
00247
00248 getStatistics()->getElem(statTravTime)->stop();
00249
00250 #if 0 // Altered for last frame time
00251 if(_ownStat)
00252 {
00253 delete _statistics;
00254 _statistics = NULL;
00255 }
00256 else
00257 {
00258 _ownStat = false;
00259 }
00260 #endif
00261
00262 return res;
00263 }
00264
00265
00266
00267 void DrawActionBase::setViewport(Viewport *viewport)
00268 {
00269 _viewport = viewport;
00270 }
00271
00272 void DrawActionBase::setCamera(Camera *cam)
00273 {
00274 _camera = cam;
00275 }
00276
00277 void DrawActionBase::setBackground(Background *background)
00278 {
00279 _background = background;
00280 }
00281
00282 void DrawActionBase::setWindow(Window *window)
00283 {
00284 _window = window;
00285 }
00286
00287 void DrawActionBase::setStatistics(StatCollector *statistics)
00288 {
00289 #if 0 // Altered for last frame time
00290 _statistics = statistics;
00291 _ownStat = false;
00292 #else
00293 if (_ownStat) {
00294 delete _statistics;
00295 }
00296 _statistics = statistics;
00297 _ownStat = false;
00298 #endif
00299 }
00300
00301
00302
00303
00304
00305 void DrawActionBase::setFrustumCulling(bool frustumCulling)
00306 {
00307 _frustumCulling = frustumCulling;
00308 }
00309
00310
00311
00312
00313 void DrawActionBase::setAutoFrustum(bool autoFrustum)
00314 {
00315 _autoFrustum = autoFrustum;
00316 }
00317
00318
00319
00320
00321 void DrawActionBase::setVolumeDrawing(bool volumeDrawing)
00322 {
00323 _volumeDrawing = volumeDrawing;
00324 }
00325
00326
00327
00328 void DrawActionBase::setFrustum(FrustumVolume &frustum)
00329 {
00330 _frustum = frustum;
00331 }
00332
00333
00334 UInt32 DrawActionBase::selectVisibles(void)
00335 {
00336 if(getFrustumCulling() == false)
00337 return getNNodes();
00338
00339 useNodeList();
00340
00341 Color3f col;
00342
00343 UInt32 count = 0;
00344 for ( UInt32 i = 0; i < getNNodes(); i++ )
00345 {
00346 if ( isVisible( getNode(i).getCPtr() ) )
00347 {
00348 col.setValuesRGB(0,1,0);
00349 addNode( getNode(i) );
00350 ++count;
00351 }
00352 else
00353 col.setValuesRGB(1,0,0);
00354
00355 if(getVolumeDrawing())
00356 {
00357 dropVolume(this, getNode(i), col);
00358 }
00359 }
00360
00361 return count;
00362 }
00363
00364