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

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 (void)
00068 {
00069 }
00070 
00071 
00072 /***************************************************************************\
00073  *                           Instance methods                              *
00074 \***************************************************************************/
00075 
00076 /*-------------------------------------------------------------------------*\
00077  -  private                                                                 -
00078 \*-------------------------------------------------------------------------*/
00079 
00080 /*----------------------- constructors & destructors ----------------------*/
00081 
00082 ImageComposer::ImageComposer(void) :
00083     Inherited()
00084 {
00085 }
00086 
00087 ImageComposer::ImageComposer(const ImageComposer &source) :
00088     Inherited(source)
00089 {
00090 }
00091 
00092 ImageComposer::~ImageComposer(void)
00093 {
00094 }
00095 
00096 /*----------------------------- class specific ----------------------------*/
00097 
00098 void ImageComposer::changed(BitVector whichField, UInt32 origin)
00099 {
00100     Inherited::changed(whichField, origin);
00101 }
00102 
00103 void ImageComposer::dump(      UInt32    , 
00104                          const BitVector ) const
00105 {
00106     SLOG << "Dump ImageComposer NI" << std::endl;
00107 }
00108 
00109 /*----------------------------- setup ------------------------------------*/
00110 
00113 void ImageComposer::setup(bool             isClient,
00114                           UInt32           clusterId,
00115                           WindowPtr        localWindow, 
00116                           ClusterWindowPtr clusterWindow)
00117 {
00118     _isClient = isClient;
00119     _clusterId = clusterId;
00120     _localWindow = localWindow;
00121     _clusterWindow = clusterWindow;
00122     _clusterSize = clusterWindow->getServers().size()+1;
00123     _serverCount = clusterWindow->getServers().size();
00124 }
00125 
00126 /*----------------------------- composition ------------------------------*/
00127 
00130 void ImageComposer::open( void )
00131 {
00132 }
00133 
00136 void ImageComposer::composeViewport( ViewportPtr port )
00137 {
00138 }
00139 
00142 void ImageComposer::composeWindow( void )
00143 {
00144 }
00145 
00148 void ImageComposer::close( void )
00149 {
00150 }
00151 
00152 /*----------------------------- features ---------------------------------*/
00153 
00158 bool ImageComposer::getClientRendering()
00159 {
00160     return true;
00161 }
00162 
00165 UInt32 ImageComposer::getUsableServers()
00166 {
00167     return serverCount();
00168 }
00169 
00170 /*----------------------------- helpers ----------------------------------*/
00171 
00176 bool ImageComposer::getScreenAlignedBBox(NodePtr node,ViewportPtr vp,
00177                                          UInt32 &l,UInt32 &b,
00178                                          UInt32 &r,UInt32 &t,
00179                                          UInt32 &front,UInt32 &back)
00180 {
00181     UInt32 width     = vp->getPixelWidth();
00182     UInt32 height    = vp->getPixelHeight();
00183     Matrix viewing;
00184     Matrix projection;
00185     Real32 rNear     = vp->getCamera()->getNear();
00186     Vec3f              vol[2];
00187     Pnt3f              pnt;
00188     Real32             minx=0,miny=0,minz=0;
00189     Real32             maxx=0,maxy=0,maxz=0;
00190     Matrix            *p;
00191 
00192     vp->getCamera()->getViewing(viewing,width,height);
00193     vp->getCamera()->getProjection(projection,width,height);
00194 
00195     // default
00196     l=b=r=t=0;
00197     // get whole transformation
00198     Matrix m=node->getToWorld();
00199     m.multLeft(viewing);
00200     // get transformed volume
00201     node->updateVolume();
00202     DynamicVolume volume=node->getVolume();
00203     // bug in osg base
00204     /*
00205     if(volume.isEmpty())
00206     {
00207         _visible=false;
00208         return;
00209     }
00210     */
00211     volume.transform(m);
00212     // get min,max
00213     volume.getBounds(vol[0], vol[1]);
00214     // min < rNear
00215     if(vol[0][2] > -rNear)
00216         return false;
00217     if(vol[1][2] > -rNear)
00218     {
00219         // volume lays on the fron clipping plane
00220         vol[1][2] = -rNear;
00221         p=&projection;
00222     }
00223     else
00224     {
00225         // volume lays on the visible side of the clipping plane
00226         node->getVolume().getBounds(vol[0], vol[1]);
00227         m.multLeft(projection);
00228         p=&m;
00229     }
00230     // create corners of a bounding box
00231     for(int i=0;i<8;++i)
00232     {
00233         p->multFullMatrixPnt(Pnt3f( vol[ (i   )&1 ][0] ,
00234                                     vol[ (i>>1)&1 ][1] ,
00235                                     vol[ (i>>2)&1 ][2]) , pnt);
00236         if(i>0)
00237         {
00238             if(minx > pnt[0]) minx = pnt[0];
00239             if(miny > pnt[1]) miny = pnt[1];
00240             if(minz > pnt[2]) minz = pnt[2];
00241             if(maxx < pnt[0]) maxx = pnt[0];
00242             if(maxy < pnt[1]) maxy = pnt[1];
00243             if(maxz < pnt[2]) maxz = pnt[2];
00244         }
00245         else
00246         {
00247             maxx = minx = pnt[0];
00248             maxy = miny = pnt[1];
00249             maxz = minz = pnt[2];
00250         }
00251     }
00252 
00253     // visible ?
00254     if(maxx<-1 || maxy<-1 ||
00255        minx> 1 || miny> 1)
00256     {
00257         return false;
00258     }
00259     else
00260     {
00261         minx=width  * ( minx + 1.0 ) / 2.0 - .5;
00262         maxx=width  * ( maxx + 1.0 ) / 2.0 + .5;
00263         miny=height * ( miny + 1.0 ) / 2.0 - .5;
00264         maxy=height * ( maxy + 1.0 ) / 2.0 + .5;
00265 
00266         if(minx <  0     ) minx = 0;
00267         if(maxx >= width ) maxx = width-1;
00268 
00269         if(miny <  0     ) miny = 0;
00270         if(maxy >= height) maxy = height-1;
00271 
00272         l=(Int32)minx;
00273         b=(Int32)miny;
00274         r=(Int32)maxx;
00275         t=(Int32)maxy;
00276 
00277 /*
00278         maxz = 1 / (2.0 / (maxz+1));
00279         minz = 1 / (2.0 / (minz+1));
00280 */
00281 
00282         front = (UInt32)( (double)(((UInt64)1)<<32) * (minz+1) / 2);
00283         back  = (UInt32)( (double)(((UInt64)1)<<32) * (maxz+1) / 2);
00284     }
00285 
00286 #if 0
00287         glPushMatrix();
00288         glLoadIdentity();
00289         glMatrixMode(GL_PROJECTION);
00290         glPushMatrix();
00291         glLoadIdentity();
00292         glOrtho(0,width,
00293                 0,height,
00294                 -1,1);
00295         glDisable(GL_DEPTH_TEST);
00296         glEnable(GL_COLOR_MATERIAL);
00297         glBegin(GL_LINE_LOOP);
00298         glColor3f(1, 1, 0);
00299         glVertex2f(l,b);
00300         glVertex2f(r,b);
00301         glVertex2f(r,t);
00302         glVertex2f(l,t);
00303         glEnd();
00304         glDisable(GL_COLOR_MATERIAL);
00305         glEnable(GL_DEPTH_TEST);
00306         glPopMatrix();
00307         glMatrixMode(GL_MODELVIEW);
00308         glPopMatrix();
00309         glPopAttrib();
00310 #endif
00311 
00312     return true;
00313 }
00314 
00315 /*------------------------------------------------------------------------*/
00316 /*                              cvs id's                                  */
00317 
00318 #ifdef OSG_SGI_CC
00319 #pragma set woff 1174
00320 #endif
00321 
00322 #ifdef OSG_LINUX_ICC
00323 #pragma warning( disable : 177 )
00324 #endif
00325 
00326 namespace
00327 {
00328     static Char8 cvsid_cpp       [] = "@(#)$Id: $";
00329     static Char8 cvsid_hpp       [] = OSGIMAGECOMPOSERBASE_HEADER_CVSID;
00330     static Char8 cvsid_inl       [] = OSGIMAGECOMPOSERBASE_INLINE_CVSID;
00331 
00332     static Char8 cvsid_fields_hpp[] = OSGIMAGECOMPOSERFIELDS_HEADER_CVSID;
00333 }
00334 
00335 #ifdef __sgi
00336 #pragma reset woff 1174
00337 #endif
00338 

Generated on Thu Aug 25 04:06:14 2005 for OpenSG by  doxygen 1.4.3