planners/output/O_Bitmap.cpp

Go to the documentation of this file.
00001 #include <assert.h>
00002 #include "O_Bitmap.h"
00003 #include <stddef.h>
00004 #include <math/math2.h>
00005 
00006 #ifndef NOGL
00007 #include "opengl/glos.h"
00008 #include <gl/gl.h>
00009 #include <gl/glu.h>
00010 #endif
00011 
00012 
00013 O_Bitmap::O_Bitmap ()
00014       : bitmap(NULL), xRes(0), yRes(0), maxIntensity(0), minIntensity(0)
00015 {
00016 }
00017 
00018 
00019 O_Bitmap::~O_Bitmap()
00020 {
00021   //## begin O_Bitmap::~O_Bitmap%.body preserve=yes
00022   //## end O_Bitmap::~O_Bitmap%.body
00023   delete[] bitmap ;
00024 }
00025 
00026 
00027 
00028 //## Other Operations (implementation)
00029 void O_Bitmap::SetResolution (const unsigned int xRes, const unsigned int yRes)
00030 {
00031 #ifdef WIN32
00032         RECT rect ;
00033         RECT client ;
00034         this->GetWindowRect( &rect ) ;
00035         this->GetClientRect( &client ) ;
00036         int topPortion = ( rect.bottom - rect.top ) - ( client.bottom - client.top ) ;
00037         int rightPortion = ( rect.right - rect.left ) - ( client.right - client.left ) ;
00038         this->SetWindowPos( NULL, rect.left, rect.top, xRes + rightPortion, yRes + topPortion, SWP_NOMOVE ) ; 
00039 #endif
00040 
00041         //if the new resolution is the same as the old resolution, then quit
00042         float* newBitmap = NULL ;
00043         if( ( xRes != this->xRes ) || ( yRes != this->yRes ) )
00044         {
00045                 newBitmap = new float[ yRes * xRes ] ;
00046                 assert( newBitmap != NULL ) ;
00047         }
00048         else
00049         {
00050                 newBitmap = this->bitmap ;
00051         }
00052 
00053         unsigned int xMax = Min( xRes, this->xRes ) ;
00054         unsigned int yMax = Min( yRes, this->yRes ) ;
00055 
00056         for( unsigned int y = 0; y < yMax; y++ )
00057         {
00058                 for( unsigned int x = 0; x < xMax; x++ )
00059                 {
00060                         float oldValue = bitmap[ y * this->xRes + x ] ;
00061                         newBitmap[ y * xRes + x ] = oldValue ;
00062                 }
00063         }
00064                                                                                                         
00065         delete[] bitmap ;               
00066         bitmap = newBitmap ;                                                            
00067         this->xRes = xRes ;
00068         this->yRes = yRes ;     
00069 
00070   //delete[] bitmap ;           
00071         //bitmap = new float [xRes*yRes] ;
00072         //this->xRes = xRes ;
00073         //this->yRes = yRes ;   
00074   
00075   //## end O_Bitmap::SetResolution%933099176.body
00076 }
00077 
00078 void O_Bitmap::PutPixel (const unsigned int x, const unsigned int y, double intensity)
00079 {
00080   //## begin O_Bitmap::PutPixel%933099177.body preserve=yes
00081         assert( x < xRes ) ;
00082         assert( y < yRes ) ;
00083         bitmap[ y * xRes + x ] = static_cast< float >( intensity ) ;    //IMPROVE: should I be casting here?
00084         if( intensity > maxIntensity ) 
00085         {
00086                 maxIntensity = intensity ;
00087         }
00088         else if( intensity < minIntensity )
00089         {
00090                 minIntensity = intensity ;
00091         }
00092   //## end O_Bitmap::PutPixel%933099177.body
00093 }
00094 
00095 void O_Bitmap::Display ()
00096 {
00097   //## begin O_Bitmap::Display%933099178.body preserve=yes
00098 
00099 #ifdef WIN32
00100         CDC* pDC = this->GetDC() ;
00101         HGLRC hglrc = wglCreateContext ( pDC->m_hDC );  
00102         BOOL success = wglMakeCurrent (pDC->m_hDC, hglrc); // call OpenGL APIs as desired ... 
00103         if( success == FALSE )
00104         {
00105                 return ;
00106         }
00107         assert( success != FALSE ) ;
00108 #endif
00109 
00110 #ifndef NOGL
00111         glViewport( 0, 0, xRes, yRes );
00112 
00113         //this should already be the active openGL window
00114         glMatrixMode( GL_PROJECTION ) ;
00115         glLoadIdentity() ;
00116         gluOrtho2D( 0, xRes, 0, yRes ) ;
00117         //glBegin( GL_POINTS ) ;
00118         //for( unsigned int y = 0; y < yRes; y++ )
00119         //{
00120         //      for( unsigned int x = 0; x < xRes; x++ )
00121         //      {
00122         //              float intensity = bitmap[ y * xRes + x ] ;
00123         //              glColor3d( intensity, intensity, intensity ) ;
00124         //              glVertex2i( x, y ) ;
00125         //      }
00126         //}
00127         //glEnd() ;
00128         //glRasterPos2i( xRes/2, yRes/2 ) ;
00129         glRasterPos2i( 0, 0 ) ;
00130         glDrawPixels( xRes, yRes, GL_LUMINANCE, GL_FLOAT, bitmap ) ;
00131         glFlush() ;
00132 #endif
00133   //## end O_Bitmap::Display%933099178.body
00134 }
00135 
00136 void O_Bitmap::Clear ()
00137 {
00138   //## begin O_Bitmap::Clear%933099180.body preserve=yes
00139         for( unsigned int y = 0; y < yRes; y++ )
00140         {
00141                 for( unsigned int x = 0; x< xRes; x++ )
00142                 {
00143                         PutPixel( x, y, 0 ) ;
00144                 }
00145         }
00146   //## end O_Bitmap::Clear%933099180.body
00147 }
00148 
00149 #ifdef WIN32
00150 void O_Bitmap::OnLButtonDblClk(UINT nFlags, CPoint point) 
00151 {
00152         this->Display() ;
00153 }
00154 #endif

Generated on Sat Apr 1 21:30:44 2006 for Motion Planning Kernel by  doxygen 1.4.6-NO