OSGImageComposer.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 #include "OSGCamera.h"
00048
00049 #include "OSGImageComposer.h"
00050
00051 OSG_USING_NAMESPACE
00052
00064 /*-------------------------------------------------------------------------*/
00065 /*                          window functions                               */
00066
00067 void ImageComposer::initMethod(InitPhase ePhase)
00068 {
00069     Inherited::initMethod(ePhase);
00070 }
00071
00072 void ImageComposer::exitMethod(InitPhase ePhase)
00073 {
00074     Inherited::exitMethod(ePhase);
00075 }
00076
00077
00078 /***************************************************************************\
00079  *                           Instance methods                              *
00080 \***************************************************************************/
00081
00082 /*-------------------------------------------------------------------------*\
00083  -  private                                                                 -
00084 \*-------------------------------------------------------------------------*/
00085
00086 /*----------------------- constructors & destructors ----------------------*/
00087
00088 ImageComposer::ImageComposer(void) :
00089     Inherited()
00090 {
00091 }
00092
00093 ImageComposer::ImageComposer(const ImageComposer &source) :
00094     Inherited(source)
00095 {
00096 }
00097
00098 ImageComposer::~ImageComposer(void)
00099 {
00100 }
00101
00102 /*----------------------------- class specific ----------------------------*/
00103
00104 void ImageComposer::changed(ConstFieldMaskArg whichField,
00105                             UInt32            origin,
00106                             BitVector         details)
00107 {
00108     Inherited::changed(whichField, origin, details);
00109 }
00110
00111 void ImageComposer::dump(      UInt32    ,
00112                          const BitVector ) const
00113 {
00114     SLOG << "Dump ImageComposer NI" << std::endl;
00115 }
00116
00117 /*----------------------------- setup ------------------------------------*/
00118
00121 void ImageComposer::setup(bool           isClient,
00122                           UInt32         clusterId,
00123                           Window        *localWindow,
00124                           ClusterWindow *clusterWindow)
00125 {
00126     _isClient      = isClient;
00127     _clusterId     = clusterId;
00128     _localWindow   = localWindow;
00129     _clusterWindow = clusterWindow;
00130     _clusterSize   = clusterWindow->getMFServers()->size()+1;
00131     _serverCount   = clusterWindow->getMFServers()->size();
00132 }
00133
00134 /*----------------------------- composition ------------------------------*/
00135
00138 void ImageComposer::open(void)
00139 {
00140 }
00141
00144 void ImageComposer::startFrame(void)
00145 {
00146 }
00147
00151 void ImageComposer::startViewport(Viewport *)
00152 {
00153 }
00154
00157 void ImageComposer::composeViewport(Viewport *port)
00158 {
00159 }
00160
00163 void ImageComposer::composeWindow(void)
00164 {
00165 }
00166
00169 void ImageComposer::close(void)
00170 {
00171 }
00172
00173 /*----------------------------- features ---------------------------------*/
00174
00180 bool ImageComposer::getClientRendering(void)
00181 {
00182     return true;
00183 }
00184
00188 UInt32 ImageComposer::getUsableServers(void)
00189 {
00190     return serverCount();
00191 }
00192
00193 /*----------------------------- helpers ----------------------------------*/
00194
00199 bool ImageComposer::getScreenAlignedBBox(Node     *node,
00200                                          Viewport *vp,
00201                                          UInt32   &l,
00202                                          UInt32   &b,
00203                                          UInt32   &r,
00204                                          UInt32   &t,
00205                                          UInt32   &front,
00206                                          UInt32   &back)
00207 {
00208     UInt32 width     = vp->getPixelWidth();
00209     UInt32 height    = vp->getPixelHeight();
00210     Matrix viewing;
00211     Matrix projection;
00212     Real32 rNear     = vp->getCamera()->getNear();
00213     Vec3f              vol[2];
00214     Pnt3f              pnt;
00215     Real32             minx=0,miny=0,minz=0;
00216     Real32             maxx=0,maxy=0,maxz=0;
00217     Matrix            *p;
00218
00219     vp->getCamera()->getViewing   (viewing,width,height);
00220     vp->getCamera()->getProjection(projection,width,height);
00221
00222     // default
00223     l=b=r=t=0;
00224     // get whole transformation
00225     Matrix m=node->getToWorld();
00226     m.multLeft(viewing);
00227     // get transformed volume
00228     node->updateVolume();
00229     BoxVolume volume = node->getVolume();
00230     // bug in osg base
00231     /*
00232     if(volume.isEmpty())
00233     {
00234         _visible=false;
00235         return;
00236     }
00237     */
00238     volume.transform(m);
00239     // get min,max
00240     volume.getBounds(vol[0], vol[1]);
00241     // min < rNear
00242     if(vol[0][2] > -rNear)
00243         return false;
00244     if(vol[1][2] > -rNear)
00245     {
00246         // volume lays on the fron clipping plane
00247         vol[1][2] = -rNear;
00248         p=&projection;
00249     }
00250     else
00251     {
00252         // volume lays on the visible side of the clipping plane
00253         node->getVolume().getBounds(vol[0], vol[1]);
00254         m.multLeft(projection);
00255         p=&m;
00256     }
00257     // create corners of a bounding box
00258     for(int i=0;i<8;++i)
00259     {
00260         p->multFull(Pnt3f( vol[ (i   )&1 ][0] ,
00261                            vol[ (i>>1)&1 ][1] ,
00262                            vol[ (i>>2)&1 ][2]) , pnt);
00263         if(i>0)
00264         {
00265             if(minx > pnt[0]) minx = pnt[0];
00266             if(miny > pnt[1]) miny = pnt[1];
00267             if(minz > pnt[2]) minz = pnt[2];
00268             if(maxx < pnt[0]) maxx = pnt[0];
00269             if(maxy < pnt[1]) maxy = pnt[1];
00270             if(maxz < pnt[2]) maxz = pnt[2];
00271         }
00272         else
00273         {
00274             maxx = minx = pnt[0];
00275             maxy = miny = pnt[1];
00276             maxz = minz = pnt[2];
00277         }
00278     }
00279
00280     // visible ?
00281     if(maxx<-1 || maxy<-1 ||
00282        minx> 1 || miny> 1)
00283     {
00284         return false;
00285     }
00286     else
00287     {
00288         minx=width  * ( minx + 1.0 ) / 2.0 - .5;
00289         maxx=width  * ( maxx + 1.0 ) / 2.0 + .5;
00290         miny=height * ( miny + 1.0 ) / 2.0 - .5;
00291         maxy=height * ( maxy + 1.0 ) / 2.0 + .5;
00292
00293         if(minx <  0     ) minx = 0;
00294         if(maxx >= width ) maxx = width-1;
00295
00296         if(miny <  0     ) miny = 0;
00297         if(maxy >= height) maxy = height-1;
00298
00299         l= Int32(minx);
00300         b= Int32(miny);
00301         r= Int32(maxx);
00302         t= Int32(maxy);
00303
00304 /*
00305         maxz = 1 / (2.0 / (maxz+1));
00306         minz = 1 / (2.0 / (minz+1));
00307 */
00308
00309         front = UInt32( double((UInt64(1))<<32) * (minz+1) / 2);
00310         back  = UInt32( double((UInt64(1))<<32) * (maxz+1) / 2);
00311     }
00312
00313 #if 0
00314         glPushMatrix();
00315         glLoadIdentity();
00316         glMatrixMode(GL_PROJECTION);
00317         glPushMatrix();
00318         glLoadIdentity();
00319         glOrtho(0,width,
00320                 0,height,
00321                 -1,1);
00322         glDisable(GL_DEPTH_TEST);
00323         glEnable(GL_COLOR_MATERIAL);
00324         glBegin(GL_LINE_LOOP);
00325         glColor3f(1, 1, 0);
00326         glVertex2f(l,b);
00327         glVertex2f(r,b);
00328         glVertex2f(r,t);
00329         glVertex2f(l,t);
00330         glEnd();
00331         glDisable(GL_COLOR_MATERIAL);
00332         glEnable(GL_DEPTH_TEST);
00333         glPopMatrix();
00334         glMatrixMode(GL_MODELVIEW);
00335         glPopMatrix();
00336         glPopAttrib();
00337 #endif
00338 
00339     return true;
00340 }
00341