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
00022
00023 delete[] bitmap ;
00024 }
00025
00026
00027
00028
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
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
00071
00072
00073
00074
00075
00076 }
00077
00078 void O_Bitmap::PutPixel (const unsigned int x, const unsigned int y, double intensity)
00079 {
00080
00081 assert( x < xRes ) ;
00082 assert( y < yRes ) ;
00083 bitmap[ y * xRes + x ] = static_cast< float >( intensity ) ;
00084 if( intensity > maxIntensity )
00085 {
00086 maxIntensity = intensity ;
00087 }
00088 else if( intensity < minIntensity )
00089 {
00090 minIntensity = intensity ;
00091 }
00092
00093 }
00094
00095 void O_Bitmap::Display ()
00096 {
00097
00098
00099 #ifdef WIN32
00100 CDC* pDC = this->GetDC() ;
00101 HGLRC hglrc = wglCreateContext ( pDC->m_hDC );
00102 BOOL success = wglMakeCurrent (pDC->m_hDC, hglrc);
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
00114 glMatrixMode( GL_PROJECTION ) ;
00115 glLoadIdentity() ;
00116 gluOrtho2D( 0, xRes, 0, yRes ) ;
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 glRasterPos2i( 0, 0 ) ;
00130 glDrawPixels( xRes, yRes, GL_LUMINANCE, GL_FLOAT, bitmap ) ;
00131 glFlush() ;
00132 #endif
00133
00134 }
00135
00136 void O_Bitmap::Clear ()
00137 {
00138
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
00147 }
00148
00149 #ifdef WIN32
00150 void O_Bitmap::OnLButtonDblClk(UINT nFlags, CPoint point)
00151 {
00152 this->Display() ;
00153 }
00154 #endif