Rev Author Line No. Line
178 kaklik 1 #include "calibrateWidget.hh"
2  
3 using namespace std;
4 using namespace mimas;
5  
6 CalibrateWidget::CalibrateWidget( QWidget *parent, Qt::WFlags f ):
7 QGLWidget( parent, 0, f ), pattern(0)
8 {
9 }
10  
11 CalibrateWidget::CalibrateWidget
12 ( const image< unsigned char > &_projectedPattern,
13 QWidget *parent, Qt::WFlags f ):
14 QGLWidget( parent ), projectedPattern( _projectedPattern ),
15 pattern(0)
16 {
17 }
18  
19 void CalibrateWidget::initializeGL(void)
20 {
21 qglClearColor( Qt::black );
22 }
23  
24 void CalibrateWidget::resizeGL( int w, int h )
25 {
26 glViewport( 0, 0, (GLint)w, (GLint)h );
27 glMatrixMode( GL_PROJECTION );
28 glLoadIdentity();
29 glOrtho( 0, width(), height(), 0, -1, 1 );
30 }
31  
32 void CalibrateWidget::paintGL(void)
33 {
34 glClear( GL_COLOR_BUFFER_BIT );
35 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
36 if ( projectedPattern.initialised() && pattern >= 1 && pattern <= 5 ) {
37 glPixelZoom( 1, -1 );
38 Vector pos( getPos( pattern ) );
39 glRasterPos2d( pos[0] - projectedPattern.getWidth() / 2,
40 pos[1] - projectedPattern.getHeight() / 2 );
41 glDrawPixels( projectedPattern.getWidth(), projectedPattern.getHeight(),
42 GL_LUMINANCE, GL_UNSIGNED_BYTE,
43 projectedPattern.rawData() );
44 };
45 };
46  
47 CalibrateWidget::Vector CalibrateWidget::getPos( int i )
48 {
49 assert( projectedPattern.initialised() );
50 assert( pattern >= 1 && pattern <= 5 );
51 int
52 xmax = width() - projectedPattern.getWidth(),
53 ymax = height() - projectedPattern.getHeight(),
54 x,
55 y;
56 switch ( pattern ) {
57 case 1:
58 x = 0;
59 y = 0;
60 break;
61 case 2:
62 x = xmax;
63 y = 0;
64 break;
65 case 3:
66 x = 0;
67 y = ymax;
68 break;
69 case 4:
70 x = xmax;
71 y = ymax;
72 break;
73 default:
74 x = xmax / 2;
75 y = ymax / 2;
76 };
77 Vector retVal( 3 );
78 retVal[ 0 ] = x + projectedPattern.getWidth() / 2;
79 retVal[ 1 ] = y + projectedPattern.getHeight() / 2;
80 retVal[ 2 ] = 1.0;
81 return retVal;
82 }
83  
84 void CalibrateWidget::setPattern( int _pattern )
85 {
86 if ( pattern != _pattern ) {
87 pattern = _pattern;
88 update();
89 };
90 }