ChessWindow.cpp

00001 #include "ChessWindow.hpp"
00002 
00003 
00007 void glutDrawString(float x, float y, const char *str)
00008 {
00009         glRasterPos2f(x,y);
00010 
00011         for (unsigned int i = 0; i < strlen(str); i++)
00012                 glutBitmapCharacter( GLUT_BITMAP_8_BY_13, str[i]);
00013 }
00014 
00015 void drawCross(float x, float y)
00016 {
00017 #define CROSS_SIZE .02
00018         glEnable(GL_LINE_SMOOTH);
00019         glEnable(GL_BLEND);
00020         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
00021         glBegin(GL_LINES);
00022                 glVertex2d(x+CROSS_SIZE,y+CROSS_SIZE);
00023                 glVertex2d(x-CROSS_SIZE,y-CROSS_SIZE);
00024                 glVertex2d(x-CROSS_SIZE,y+CROSS_SIZE);
00025                 glVertex2d(x+CROSS_SIZE,y-CROSS_SIZE);
00026         glEnd();
00027 }
00028 
00029 
00030 
00031 void ChessWindow::setImageView (bool bViewOriginal /* vs. thresholded version */ )
00032 {
00033         bDrawOriginal = bViewOriginal;
00034         redraw();
00035 }
00036 
00037 
00038 
00039 unsigned char ChessWindow::getCurrentThreshold() const
00040 {
00041         return (*chessPictures)[currentImageIndex].getThreshold();
00042 }
00043 
00044 
00045 
00046 void ChessWindow::setCurrentThreshold(unsigned char c)
00047 {
00048         (*chessPictures)[currentImageIndex].recalculateThresholdedImage(c);
00049 }
00050 
00051 
00052 
00053 void ChessWindow::draw()
00054 {
00055         glViewport(0,0,w(),h());
00056         glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00057 
00058         if (chessPictures->size() > currentImageIndex)
00059         {
00060                 if (bDrawOriginal)
00061                         chessPictures->at(currentImageIndex).drawOriginalTexture(-1,-1,2,2);
00062                 else
00063                         chessPictures->at(currentImageIndex).drawThresholdedTexture(-1,-1,2,2);
00064 
00065 
00066                 ImageCalibrator &imgCalib = (*chessPictures)[currentImageIndex].imgCalib;
00067 
00068                 for (unsigned int i = 0; i < imgCalib.points.size(); i++)
00069                 {
00070                         float x = (float)imgCalib.points[i].u / (*chessPictures)[currentImageIndex].imgThresholded.getWidth();
00071                         float y = 1.f - (float)imgCalib.points[i].v / (*chessPictures)[currentImageIndex].imgThresholded.getHeight();
00072                         
00073                         x = (x*2.f) - 1.f;
00074                         y = (y*2.f) - 1.f;
00075                         
00076                         glColor3f(1.f,0.f,.8f);
00077                         drawCross(x,y);
00078 #if 0
00079                         char str[256];
00080                         sprintf(str, "%d,%d", (int)(2.*imgCalib.points[i].x), (int)(2.*imgCalib.points[i].y));
00081                         glutDrawString(x,y, str);
00082 #endif
00083                 }
00084         }
00085 
00086 
00087         Fl_Gl_Window::draw();
00088 }
00089 
00090 int ChessWindow::handle(int event)
00091 {
00092         return Fl_Gl_Window::handle(event);
00093 }
00094 
00095 ChessWindow::~ChessWindow(void)
00096 {
00097 }

Generated on Mon May 26 11:19:28 2003 for CamChecker by doxygen1.3