OSGAlgorithmStage.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 #include <cstdlib>
00040 #include <cstdio>
00041
00042 #include <sstream>
00043 #include <fstream>
00044
00045 #include "OSGConfig.h"
00046
00047 #include "OSGAction.h"
00048 #include "OSGCamera.h"
00049 #include "OSGRenderAction.h"
00050 #include "OSGSceneFileHandler.h"
00051 #include "OSGVolumeDraw.h"
00052 #include "OSGAlgorithm.h"
00053
00054 #include "OSGAlgorithmStage.h"
00055
00056 #include "OSGFrameBufferObject.h"
00057 #include "OSGFrameBufferAttachment.h"
00058
00059 #include "OSGMatrixUtility.h"
00060
00061 OSG_USING_NAMESPACE
00062
00063 // Documentation for this class is emited in the
00064 // OSGAlgorithmStageBase.cpp file.
00065 // To modify it, please change the .fcd file (OSGAlgorithmStage.fcd) and
00066 // regenerate the base file.
00067
00068 /*-------------------------------------------------------------------------*/
00069 /*                               Sync                                      */
00070
00071 void AlgorithmStage::changed(ConstFieldMaskArg whichField,
00072                              UInt32            origin,
00073                              BitVector         details)
00074 {
00075     Inherited::changed(whichField, origin, details);
00076 }
00077
00078 /*-------------------------------------------------------------------------*/
00079 /*                               Dump                                      */
00080
00081 void AlgorithmStage::dump(      UInt32    OSG_CHECK_ARG(uiIndent),
00082                           const BitVector OSG_CHECK_ARG(bvFlags )) const
00083 {
00084     SLOG << "Dump VisitSubTree NI" << std::endl;
00085 }
00086
00087 /*-------------------------------------------------------------------------*/
00088 /*                            Constructors                                 */
00089
00090 AlgorithmStage::AlgorithmStage(void) :
00091     Inherited()
00092 {
00093 }
00094
00095 AlgorithmStage::AlgorithmStage(const AlgorithmStage &source) :
00096     Inherited(source)
00097 {
00098 }
00099
00100 /*-------------------------------------------------------------------------*/
00101 /*                             Destructor                                  */
00102
00103 AlgorithmStage::~AlgorithmStage(void)
00104 {
00105 }
00106
00107 void AlgorithmStage::execute(DrawEnv *pDrawEnv)
00108 {
00109     Algorithm *pAlgorithm = getAlgorithm();
00110
00111     if(pAlgorithm != NULL)
00112     {
00113         pAlgorithm->execute(pDrawEnv);
00114     }
00115 }
00116
00117
00118 /*-------------------------------------------------------------------------*/
00119 /*                               loading                                   */
00120
00121 ActionBase::ResultE AlgorithmStage::renderEnter(Action *action)
00122 {
00123     RenderAction *a = dynamic_cast<RenderAction *>(action);
00124
00125
00126     UInt32 uiCopyOnPush = RenderPartition::CopyVPCamera;
00127
00128     if(this->getCopyViewing() == true)
00129     {
00130         uiCopyOnPush |= RenderPartition::CopyViewing;
00131     }
00132
00133     a->pushPartition(uiCopyOnPush,
00134                      RenderPartition::SimpleCallback);
00135     {
00136         RenderPartition *pPart  = a->getActivePartition();
00137
00138         pPart->setWindow(a->getWindow());
00139
00140         if(this->getProjectionMode() != AlgorithmStage::Ignore)
00141         {
00142             Viewport *pPort = a->getViewport();
00143
00144             if(pPort != NULL)
00145             {
00146 //                pPart->setViewport(pPort         );
00147
00148                 pPart->calcViewportDimension(pPort->getLeft  (),
00149                                              pPort->getBottom(),
00150                                              pPort->getRight (),
00151                                              pPort->getTop   (),
00152
00153                                              a->getWindow()->getWidth (),
00154                                              a->getWindow()->getHeight());
00155
00156                 Matrix m, t;
00157
00158                 m.setIdentity();
00159                 t.setIdentity();
00160
00161                 switch(this->getProjectionMode())
00162                 {
00163                     case AlgorithmStage::ZeroOne:
00164                         MatrixOrthogonal( m,
00165                                           0.f, 1.f,
00166                                           0.f, 1.f,
00167                                          -1.f, 1.f);
00168
00169                         break;
00170
00171                     case AlgorithmStage::CenterOne:
00172                         MatrixOrthogonal( m,
00173                                          -1.f, 1.f,
00174                                          -1.f, 1.f,
00175                                          -1.f, 1.f);
00176
00177                         break;
00178
00179                     case AlgorithmStage::ZeroSize:
00180                         MatrixOrthogonal( m,
00181                                           0.f, pPart->getViewportWidth(),
00182                                           0.f, pPart->getViewportHeight(),
00183                                          -1.f, 1.f);
00184
00185                         break;
00186
00187                     case AlgorithmStage::CenterSize:
00188                     {
00189                         Real32 rWHalf =
00190                             Real32(pPart->getViewportWidth()) / 2.f;
00191                         Real32 rHHalf =
00192                             Real32(pPart->getViewportWidth()) / 2.f;
00193
00194                         MatrixOrthogonal( m,
00195                                          -rWHalf, rWHalf,
00196                                          -rHHalf, rHHalf,
00197                                          -1.f, 1.f);
00198                     }
00199                     break;
00200
00201                     case AlgorithmStage::StoredMatrix:
00202
00203                         m = this->getProjectionMatrix();
00204
00205                         break;
00206                 }
00207
00208                 pPart->setSetupMode(RenderPartition::FullSetup);
00209                 pPart->setupProjection(m, t);
00210             }
00211             else
00212             {
00213                 pPart->setSetupMode(RenderPartition::EmptySetup);
00214             }
00215         }
00216         else
00217         {
00218             pPart->setSetupMode(RenderPartition::EmptySetup);
00219         }
00220
00221         RenderPartition::SimpleDrawCallback f;
00222
00223         f = boost::bind(&AlgorithmStage::execute, this, _1);
00224
00225         pPart->dropFunctor(f);
00226
00227         Algorithm *pAlgorithm = getAlgorithm();
00228
00229         if(pAlgorithm != NULL)
00230         {
00231             pAlgorithm->renderEnter(a);
00232         }
00233     }
00234     a->popPartition();
00235
00236     return Action::Skip;
00237 }
00238
00239 ActionBase::ResultE AlgorithmStage::renderLeave(Action *a)
00240 {
00241     Algorithm *pAlgorithm = getAlgorithm();
00242
00243     if(pAlgorithm != NULL)
00244     {
00245         pAlgorithm->renderLeave(a);
00246     }
00247
00248     return Action::Skip;
00249 }
00250
00251
00252 /*-------------------------------------------------------------------------*/
00253 /*                               Init                                      */
00254
00255 void AlgorithmStage::initMethod(InitPhase ePhase)
00256 {
00257     Inherited::initMethod(ePhase);
00258
00259     if(ePhase == TypeObject::SystemPost)
00260     {
00261         RenderAction::registerEnterDefault(
00262             AlgorithmStage::getClassType(),
00263             reinterpret_cast<Action::Callback>(&AlgorithmStage::renderEnter));
00264
00265         RenderAction::registerLeaveDefault(
00266             AlgorithmStage::getClassType(),
00267             reinterpret_cast<Action::Callback>(&AlgorithmStage::renderLeave));
00268     }
00269 }
00270