00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024
00025 #include <math.h>
00026 #include <iostream>
00027 #include <qvdefines.h>
00028
00029 #include <QMouseEvent>
00030 #include <QPainter>
00031 #include <QScrollArea>
00032 #include <QScrollBar>
00033 #include <QGLWidget>
00034 #include <QToolButton>
00035 #include <QStatusBar>
00036 #include <QHBoxLayout>
00037 #include <QGridLayout>
00038
00039 #include <math.h>
00040
00041 #include <QVImage>
00042 #include "qvcanvas.h"
00043
00044 #ifdef QVQWT
00045 #include <qwt_scale_widget.h>
00046 #include <qwt_scale_engine.h>
00047 #include <qwt_scale_div.h>
00048 #endif
00049
00050 #include <GL/glu.h>
00051
00052 QList<QVImageArea *> image_areas;
00053
00054
00055 void QVPainter::drawQVImage(QVGenericImage *image,bool adaptSize,float low,float high)
00056 {
00057 imageArea->drawQVImage(image,adaptSize,low,high);
00058 }
00059
00060
00061 void QVPainter::drawTextUnscaled(const QPointF & position, const QString & text)
00062 {
00063 save();
00064 resetMatrix();
00065 translate(-imageArea->topLeft);
00066 drawText(imageArea->zoom*position,text);
00067 restore();
00068 }
00069
00070 void QVPainter::drawTextUnscaled(const QPoint & position, const QString & text)
00071 {
00072 save();
00073 resetMatrix();
00074 translate(-imageArea->topLeft);
00075 drawText(imageArea->zoom*position,text);
00076 restore();
00077 }
00078
00079 void QVPainter::drawTextUnscaled(const QRectF & rectangle, int flags,
00080 const QString & text, QRectF * boundingRect)
00081 {
00082 save();
00083 resetMatrix();
00084 translate(-imageArea->topLeft);
00085 drawText(QRectF(imageArea->zoom*rectangle.topLeft(),
00086 imageArea->zoom*rectangle.size()),flags,text,boundingRect);
00087 if(boundingRect != 0)
00088 *boundingRect = QRectF(imageArea->zoom*boundingRect->topLeft(),
00089 imageArea->zoom*boundingRect->size());
00090 restore();
00091 }
00092
00093 void QVPainter::drawTextUnscaled(const QRect & rectangle, int flags,
00094 const QString & text, QRect * boundingRect)
00095 {
00096 save();
00097 resetMatrix();
00098 translate(-imageArea->topLeft);
00099 drawText(QRect(imageArea->zoom*rectangle.topLeft(),
00100 imageArea->zoom*rectangle.size()),flags,text,boundingRect);
00101 if(boundingRect != 0)
00102 *boundingRect = QRect(imageArea->zoom*boundingRect->topLeft(),
00103 imageArea->zoom*boundingRect->size());
00104 restore();
00105 }
00106
00107 void QVPainter::drawTextUnscaled(int x, int y, const QString & text)
00108 {
00109 save();
00110 resetMatrix();
00111 translate(-imageArea->topLeft);
00112 drawText(imageArea->zoom*x,imageArea->zoom*y,text);
00113 restore();
00114 }
00115
00116 void QVPainter::drawTextUnscaled(int x, int y, int width, int height, int flags,
00117 const QString & text, QRect * boundingRect)
00118 {
00119 save();
00120 resetMatrix();
00121 translate(-imageArea->topLeft);
00122 drawText(imageArea->zoom*x,imageArea->zoom*y,imageArea->zoom*width,
00123 imageArea->zoom*height,flags,text,boundingRect);
00124 if(boundingRect != 0)
00125 *boundingRect = QRect(imageArea->zoom*boundingRect->topLeft(),
00126 imageArea->zoom*boundingRect->size());
00127 restore();
00128 }
00129
00130 void QVPainter::drawTextUnscaled(const QRectF & rectangle, const QString & text,
00131 const QTextOption & option)
00132 {
00133 save();
00134 resetMatrix();
00135 translate(-imageArea->topLeft);
00136 drawText(QRectF(imageArea->zoom*rectangle.topLeft(),
00137 imageArea->zoom*rectangle.size()),text,option);
00138 restore();
00139 }
00140
00141
00142 void QVImageArea::initObject(int w, int h)
00143 {
00144 zoom = 1;
00145 origwidth = w;
00146 origheight = h;
00147 topLeft = QPoint(0,0);
00148 selRect = QRect();
00149 zoomRect = QRect();
00150 selPoly = QVPolyline();
00151 setAttribute(Qt::WA_NoSystemBackground);
00152 setMouseTracking(TRUE);
00153 setMinimumSize(qMin(w,max_zoom),qMin(h,max_zoom));
00154 setMaximumSize(w,h);
00155 resize(w,h);
00156 mouseMode = NONE;
00157 polyMode = LIST;
00158 dragging = FALSE;
00159 drawSel= TRUE;
00160 emit newGeometry(origwidth,origheight,topLeft.x(),topLeft.y(),width(),height(),zoom);
00161 }
00162
00163 QVImageArea::QVImageArea(int w, int h,QWidget *parent)
00164 : QGLWidget(QGLFormat(QGL::DoubleBuffer|QGL::NoDepthBuffer|
00165 QGL::DirectRendering|QGL::HasOverlay), parent), max_zoom(128)
00166 {
00167 initObject(w,h);
00168 }
00169
00170 QVImageArea::QVImageArea(int w, int h,QWidget *parent,QGLWidget *other)
00171 : QGLWidget(parent,other), max_zoom(128)
00172 {
00173 initObject(w,h);
00174 }
00175
00176 void QVImageArea::centerZoom(int zoom)
00177 {
00178 if((zoom != this->zoom) and (zoom >= 1) and (zoom <= max_zoom)) {
00179 int old_zoom = this->zoom;
00180 this->zoom = zoom;
00181 setMaximumSize(zoom*origwidth,zoom*origheight);
00182 QPoint newTopLeft = zoom*(topLeft+QPoint(width(),height())/2)/old_zoom
00183 - QPoint(width(),height())/2;
00184 if(newTopLeft.x() < 0)
00185 newTopLeft.setX(0);
00186 if(newTopLeft.y() < 0)
00187 newTopLeft.setY(0);
00188 if(newTopLeft.x()+width() > origwidth*zoom)
00189 newTopLeft.setX(origwidth*zoom-width());
00190 if(newTopLeft.y()+height() > origheight*zoom)
00191 newTopLeft.setY(origheight*zoom-height());
00192 topLeft = newTopLeft;
00193 makeCurrent();
00194 update();
00195 emit newGeometry(origwidth,origheight,topLeft.x(),topLeft.y(),width(),height(),zoom);
00196 }
00197 }
00198
00199 void QVImageArea::resizeGL(int width, int height)
00200 {
00201 QPoint newTopLeft = topLeft,newBottomRight = topLeft+QPoint(width,height);
00202 if(newBottomRight.x() > origwidth*zoom)
00203 newTopLeft.setX(origwidth*zoom-width);
00204 if(newBottomRight.y() > origheight*zoom)
00205 newTopLeft.setY(origheight*zoom-height);
00206 topLeft = newTopLeft;
00207 makeCurrent();
00208 update();
00209 emit newGeometry(origwidth,origheight,topLeft.x(),topLeft.y(),width,height,zoom);
00210 }
00211
00212
00213 void QVImageArea::wheelEvent(QWheelEvent *event)
00214 {
00215 if (event->delta() > 0) {
00216 centerZoom(2*zoom);
00217 } else {
00218 centerZoom(zoom/2);
00219 }
00220 }
00221
00222
00223
00224 QRectF QVImageArea::intuitiveRect(QRect rect)
00225 {
00226
00227
00228 return QRectF(rect.x(),rect.y(),rect.width()-1.0/zoom,rect.height()-1.0/zoom);
00229 }
00230
00231
00232 QRect QVImageArea::innerRect()
00233 {
00234 QPoint q1(static_cast<int>(ceilf(static_cast<float>(topLeft.x())/zoom)),
00235 static_cast<int>(ceilf(static_cast<float>(topLeft.y())/zoom))),
00236 q2(static_cast<int>(floor(static_cast<float>((topLeft.x()+width()))/zoom)-1),
00237 (static_cast<int>(floor(static_cast<float>(topLeft.y()+height()))/zoom))-1);
00238 return QRect(q1,q2);
00239 }
00240
00241 QRect QVImageArea::outerRect()
00242 {
00243 QPoint q1(static_cast<int>(ceilf(static_cast<float>(topLeft.x())/zoom)-1),
00244 static_cast<int>(ceilf(static_cast<float>(topLeft.y())/zoom))-1),
00245 q2(static_cast<int>(floor(static_cast<float>((topLeft.x()+width()))/zoom)),
00246 (static_cast<int>(floor(static_cast<float>(topLeft.y()+height()))/zoom)));
00247
00248 return QRect(q1,q2) & QRect(0,0,origwidth,origheight);
00249 }
00250
00251 void QVImageArea::paintEvent(QPaintEvent *event)
00252 {
00253 Q_UNUSED(event);
00254
00255 painter = new QVPainter(this);
00256
00257 painter->begin(this);
00258
00259
00260 painter->setViewport(0,0,width(),height());
00261 painter->resetMatrix();
00262 painter->translate(-topLeft);
00263 painter->scale(zoom,zoom);
00264
00265
00266 QVCanvas *image_viewer = qobject_cast<QVCanvas *>(parent());
00267 if(image_viewer == 0) {
00268 qFatal("Internal error: parent of QVImageArea must be a QVCanvas.");
00269 } else {
00270 glClearColor(0,0,1,0);
00271 glClear(GL_COLOR_BUFFER_BIT);
00272 image_viewer->viewer();
00273 }
00274
00275
00276 if(drawSel) {
00277 if(selRect != QRect()) {
00278 painter->setPen(QColor(Qt::red));
00279
00280
00281 painter->drawRect(intuitiveRect(selRect));
00282 }
00283 if(zoomRect != QRect()) {
00284 painter->setPen(QColor(Qt::blue));
00285
00286
00287 painter->drawRect(intuitiveRect(zoomRect));
00288 }
00289 if(selPoly != QVPolyline()) {
00290 painter->setPen(QColor(Qt::green));
00291 QPointF pointoffset = (zoom==1?QPointF(0.0,0.0):QPointF(+0.5,+0.5));
00292 for (int i = selPoly.size()-1; i>=0; i--){
00293 painter->drawLine(selPoly.at(i)+QPointF(-2.0,+0.0) + pointoffset,
00294 selPoly.at(i)+QPointF(+2.0,+0.0) + pointoffset);
00295 painter->drawLine(selPoly.at(i)+QPointF(+0.0,-2.0) + pointoffset,
00296 selPoly.at(i)+QPointF(+0.0,+2.0) + pointoffset);
00297 if( (polyMode == LINE or polyMode == CLOSED) and (i!=0) )
00298 painter->drawLine(selPoly.at(i-1) + pointoffset,selPoly.at(i) + pointoffset);
00299 }
00300 if (polyMode == CLOSED)
00301 painter->drawLine(selPoly.at(0) + pointoffset, selPoly.at(selPoly.size() -1) + pointoffset);
00302 }
00303 }
00304
00305 if(zoom >= 32) {
00306 painter->setPen(QColor(Qt::green));
00307 QRect outer = outerRect();
00308 for(int j=outer.y();j<outer.y()+outer.height();j++) {
00309 for(int i=outer.x();i<outer.x()+outer.width();i++) {
00310 if(not imageList.isEmpty()) {
00311 QString value_string;
00312 int k;
00313 for(k=0;k<imageList.size();k++) {
00314 QRect img_rect = QRect(imageList[k]->getAnchor()+imageList[k]->getROI().topLeft(),
00315 QSize(imageList[k]->getROI().width(),imageList[k]->getROI().height()));
00316 if(i>=img_rect.left() and i<=img_rect.right() and j>=img_rect.top() and j<=img_rect.bottom()) {
00317
00319 if(imageList[k]->isCompatibleWith("QVImage<uChar,1>")) {
00320 if(zoom >= 32) {
00321 value_string = QString("%1").arg((*(QVImage<uChar,1>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y()));
00322 }
00323 }
00324 else if(imageList[k]->isCompatibleWith("QVImage<uShort,1>")) {
00325 if(zoom >= 64) {
00326 value_string = QString("%1").arg((*(QVImage<uShort,1>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y()));
00327 }
00328 }
00329 else if(imageList[k]->isCompatibleWith("QVImage<sShort,1>")) {
00330 if(zoom >= 64) {
00331 value_string = QString("%1").arg((*(QVImage<sShort,1>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y()));
00332 }
00333 }
00334 else if(imageList[k]->isCompatibleWith("QVImage<sInt,1>")) {
00335 if(zoom >= 64) {
00336 value_string = QString("%1").arg((*(QVImage<sInt,1>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y()));
00337 }
00338 }
00339 else if(imageList[k]->isCompatibleWith("QVImage<sFloat,1>")) {
00340 if(zoom >= 64) {
00341 value_string = QString("%1").arg((*(QVImage<sFloat,1>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y()));
00342 }
00343 }
00344 else if(imageList[k]->isCompatibleWith("QVImage<uChar,3>")) {
00345 int red,green,blue;
00346 if(zoom >= 64) {
00347 red = (*(QVImage<uChar,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),0);
00348 green = (*(QVImage<uChar,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),1);
00349 blue = (*(QVImage<uChar,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),2);
00350 value_string = QString("R:%1\nG:%2\nB:%3").arg(red).arg(green).arg(blue);
00351 }
00352 }
00353 else if(imageList[k]->isCompatibleWith("QVImage<uShort,3>")) {
00354 int red,green,blue;
00355 if(zoom >= 64) {
00356 red = (*(QVImage<uShort,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),0);
00357 green = (*(QVImage<uShort,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),1);
00358 blue = (*(QVImage<uShort,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),2);
00359 value_string = QString("R:%1\nG:%2\nB:%3").arg(red).arg(green).arg(blue);
00360 }
00361 }
00362 else if(imageList[k]->isCompatibleWith("QVImage<sShort,3>")) {
00363 int red,green,blue;
00364 if(zoom >= 64) {
00365 red = (*(QVImage<sShort,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),0);
00366 green = (*(QVImage<sShort,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),1);
00367 blue = (*(QVImage<sShort,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),2);
00368 value_string = QString("R:%1\nG:%2\nB:%3").arg(red).arg(green).arg(blue);
00369 }
00370 }
00371 else if(imageList[k]->isCompatibleWith("QVImage<sInt,3>")) {
00372 int red,green,blue;
00373 if(zoom >= 64) {
00374 red = (*(QVImage<sInt,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),0);
00375 green = (*(QVImage<sInt,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),1);
00376 blue = (*(QVImage<sInt,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),2);
00377 value_string = QString("R:%1\nG:%2\nB:%3").arg(red).arg(green).arg(blue);
00378 }
00379 }
00380 else if(imageList[k]->isCompatibleWith("QVImage<sFloat,3>")) {
00381 float red,green,blue;
00382 if(zoom >= 64) {
00383 red = (*(QVImage<sFloat,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),0);
00384 green = (*(QVImage<sFloat,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),1);
00385 blue = (*(QVImage<sFloat,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),2);
00386 value_string = QString("R:%1\nG:%2\nB:%3").arg(red).arg(green).arg(blue);
00387 }
00388 }
00389 else {
00390
00391 qFatal("Type of QVGenericImage still not supported in paintEvent");
00392 }
00393 break;
00394 }
00395 }
00396 if(k==imageList.size()) {
00397 value_string = QString("X");
00398 }
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420 painter->drawTextUnscaled(
00421 QRect(QPoint(i,j),QSize(1,1)),
00422 Qt::AlignCenter|Qt::TextDontClip,value_string);
00423 }
00424 }
00425 }
00426 }
00427
00428
00429 painter->end();
00430 delete painter;
00431
00432
00433 while (!imageList.isEmpty())
00434 delete imageList.takeFirst();
00435 }
00436
00437 void QVImageArea::resizeImageArea(int w,int h)
00438 {
00439 if(w != origwidth or h != origheight) {
00440 zoom = 1;
00441 origwidth = w;
00442 origheight = h;
00443 topLeft = QPoint(0,0);
00444 selRect = QRect();
00445 zoomRect = QRect();
00446 selPoly = QVPolyline();
00447 setMinimumSize(qMin(w,max_zoom),qMin(h,max_zoom));
00448 setMaximumSize(w,h);
00449 resize(w,h);
00450 emit newGeometry(origwidth,origheight,topLeft.x(),topLeft.y(),width(),height(),zoom);
00451 }
00452 }
00453
00454 void QVImageArea::drawQVImage(QVGenericImage *image,bool adaptSize,float low, float high)
00455 {
00456
00457 QVGenericImage *imagecopy=NULL;
00458 if(image->isCompatibleWith("QVImage<uChar,1>")) {
00459 imagecopy = new QVImage<uChar,1>;
00460 *(dynamic_cast<QVImage<uChar,1>*>(imagecopy)) = *(dynamic_cast<QVImage<uChar,1>*>(image));
00461 }
00462 else if(image->isCompatibleWith("QVImage<uShort,1>")) {
00463 imagecopy = new QVImage<uShort,1>;
00464 *(dynamic_cast<QVImage<uShort,1>*>(imagecopy)) = *(dynamic_cast<QVImage<uShort,1>*>(image));
00465 }
00466 else if(image->isCompatibleWith("QVImage<sShort,1>")) {
00467 imagecopy = new QVImage<sShort,1>;
00468 *(dynamic_cast<QVImage<sShort,1>*>(imagecopy)) = *(dynamic_cast<QVImage<sShort,1>*>(image));
00469 }
00470 else if(image->isCompatibleWith("QVImage<sInt,1>")) {
00471 imagecopy = new QVImage<sInt,1>;
00472 *(dynamic_cast<QVImage<sInt,1>*>(imagecopy)) = *(dynamic_cast<QVImage<sInt,1>*>(image));
00473 }
00474 else if(image->isCompatibleWith("QVImage<sFloat,1>")) {
00475 imagecopy = new QVImage<sFloat,1>;
00476 *(dynamic_cast<QVImage<sFloat,1>*>(imagecopy)) = *(dynamic_cast<QVImage<sFloat,1>*>(image));
00477 }
00478 else if(image->isCompatibleWith("QVImage<uChar,3>")) {
00479 imagecopy = new QVImage<uChar,3>;
00480 *(dynamic_cast<QVImage<uChar,3>*>(imagecopy)) = *(dynamic_cast<QVImage<uChar,3>*>(image));
00481 }
00482 else if(image->isCompatibleWith("QVImage<uShort,3>")) {
00483 imagecopy = new QVImage<uShort,3>;
00484 *(dynamic_cast<QVImage<uShort,3>*>(imagecopy)) = *(dynamic_cast<QVImage<uShort,3>*>(image));
00485 }
00486 else if(image->isCompatibleWith("QVImage<sShort,3>")) {
00487 imagecopy = new QVImage<sShort,3>;
00488 *(dynamic_cast<QVImage<sShort,3>*>(imagecopy)) = *(dynamic_cast<QVImage<sShort,3>*>(image));
00489 }
00490 else if(image->isCompatibleWith("QVImage<sInt,3>")) {
00491 imagecopy = new QVImage<sInt,3>;
00492 *(dynamic_cast<QVImage<sInt,3>*>(imagecopy)) = *(dynamic_cast<QVImage<sInt,3>*>(image));
00493 }
00494 else if(image->isCompatibleWith("QVImage<sFloat,3>")) {
00495 imagecopy = new QVImage<sFloat,3>;
00496 *(dynamic_cast<QVImage<sFloat,3>*>(imagecopy)) = *(dynamic_cast<QVImage<sFloat,3>*>(image));
00497 }
00498 else {
00499
00500 qFatal("Type of QVGenericImage still not supported in drawQVImage");
00501 }
00502
00503
00504 imageList.push_front(imagecopy);
00505
00506
00508 if(adaptSize) {
00509 this->resizeImageArea(image->getAnchor().x()+image->getROI().x()+image->getROI().width(),image->getAnchor().y()+image->getROI().y()+image->getROI().height());
00510 }
00511
00512
00513
00514 glPushAttrib(GL_ALL_ATTRIB_BITS);
00515 glPushClientAttrib(GL_ALL_ATTRIB_BITS);
00516 glMatrixMode(GL_PROJECTION);
00517 glPushMatrix();
00518 glMatrixMode(GL_MODELVIEW);
00519 glPushMatrix();
00520
00521
00522
00523 glViewport(0,0,width(),height());
00524 glMatrixMode(GL_PROJECTION);
00525 glLoadIdentity();
00526 glOrtho(topLeft.x(),topLeft.x()+width(),
00527 topLeft.y()+height(),topLeft.y(),-1,1);
00528 glMatrixMode(GL_MODELVIEW);
00529 glLoadIdentity();
00530
00531
00532 QRect final_rect,outer_rect = outerRect(),
00533 img_rect = QRect(imagecopy->getAnchor()+imagecopy->getROI().topLeft(),
00534 QSize(imagecopy->getROI().width(),imagecopy->getROI().height()));
00535 final_rect = outer_rect & img_rect;
00536
00537
00538
00539
00540 QPoint where,dirty;
00541 if(outer_rect.topLeft().x() >= img_rect.topLeft().x()) {
00542 where.setX(outer_rect.topLeft().x());
00543 dirty.setX(1);
00544 } else {
00545 where.setX(img_rect.topLeft().x());
00546 dirty.setX(0);
00547 }
00548 if(outer_rect.topLeft().y() >= img_rect.topLeft().y()) {
00549 where.setY(outer_rect.topLeft().y());
00550 dirty.setY(1);
00551 } else {
00552 where.setY(img_rect.topLeft().y());
00553 dirty.setY(0);
00554 }
00555
00556 glRasterPos2f(zoom*(where.x()+dirty.x()+0.0001),zoom*(where.y()+dirty.y()+0.0001));
00557 glBitmap(0, 0, 0, 0, -zoom*dirty.x(), +zoom*dirty.y(), NULL);
00558
00559
00560 QRect what;
00561 int img_step = imagecopy->getStep();
00562 glPixelZoom(zoom,-zoom);
00563 if(outer_rect.topLeft().x() >= img_rect.topLeft().x()) {
00564 what.setX(outer_rect.topLeft().x() - img_rect.topLeft().x() + imagecopy->getROI().topLeft().x());
00565 } else {
00566 what.setX(imagecopy->getROI().topLeft().x());
00567 }
00568 what.setWidth(final_rect.width());
00569 if(outer_rect.topLeft().y() >= img_rect.topLeft().y()) {
00570 what.setY(outer_rect.topLeft().y() - img_rect.topLeft().y() + imagecopy->getROI().topLeft().y());
00571 } else {
00572 what.setY(imagecopy->getROI().topLeft().y());
00573 }
00574 what.setHeight(final_rect.height());
00575
00576 if(image->isCompatibleWith("QVImage<uChar,1>")) {
00577 glPixelStorei(GL_UNPACK_ROW_LENGTH,img_step);
00578 glDrawPixels(what.width(),what.height(),
00579 GL_LUMINANCE,GL_UNSIGNED_BYTE,
00580 static_cast<QVImage<uchar,1> *>(imagecopy)->getReadData() +
00581 what.y()*img_step+what.x());
00582 }
00583 else if(image->isCompatibleWith("QVImage<uShort,1>")) {
00584 glPixelStorei(GL_UNPACK_ROW_LENGTH,img_step/sizeof(uShort));
00585 glDrawPixels(what.width(),what.height(),
00586 GL_LUMINANCE,GL_UNSIGNED_SHORT,
00587 static_cast<QVImage<uShort,1> *>(imagecopy)->getReadData() +
00588 what.y()*img_step/sizeof(uShort)+what.x());
00589 }
00590 else if(image->isCompatibleWith("QVImage<sShort,1>")) {
00591 glPixelStorei(GL_UNPACK_ROW_LENGTH,img_step/sizeof(sShort));
00592
00593 float scale=1.0/(high-low),bias=-low*scale;
00594 glPixelTransferf(GL_RED_BIAS,bias);
00595 glPixelTransferf(GL_GREEN_BIAS,bias);
00596 glPixelTransferf(GL_BLUE_BIAS,bias);
00597 glPixelTransferf(GL_RED_SCALE,scale);
00598 glPixelTransferf(GL_GREEN_SCALE,scale);
00599 glPixelTransferf(GL_BLUE_SCALE,scale);
00600
00601 glDrawPixels(what.width(),what.height(),
00602 GL_LUMINANCE,GL_SHORT,
00603 static_cast<QVImage<sShort,1> *>(imagecopy)->getReadData() +
00604 what.y()*img_step/sizeof(sShort)+what.x());
00605 }
00606 else if(image->isCompatibleWith("QVImage<sInt,1>")) {
00607 glPixelStorei(GL_UNPACK_ROW_LENGTH,img_step/sizeof(sInt));
00608
00609 float scale=1.0/(high-low),bias=-low*scale;
00610 glPixelTransferf(GL_RED_BIAS,bias);
00611 glPixelTransferf(GL_GREEN_BIAS,bias);
00612 glPixelTransferf(GL_BLUE_BIAS,bias);
00613 glPixelTransferf(GL_RED_SCALE,scale);
00614 glPixelTransferf(GL_GREEN_SCALE,scale);
00615 glPixelTransferf(GL_BLUE_SCALE,scale);
00616
00617 glDrawPixels(what.width(),what.height(),
00618 GL_LUMINANCE,GL_INT,
00619 static_cast<QVImage<sInt,1> *>(imagecopy)->getReadData() +
00620 what.y()*img_step/sizeof(sInt)+what.x());
00621 }
00622 else if(image->isCompatibleWith("QVImage<sFloat,1>")) {
00623 glPixelStorei(GL_UNPACK_ROW_LENGTH,img_step/sizeof(sFloat));
00624
00625 float scale=1.0/(high-low),bias=-low*scale;
00626
00627 glPixelTransferf(GL_RED_BIAS,bias);
00628 glPixelTransferf(GL_GREEN_BIAS,bias);
00629 glPixelTransferf(GL_BLUE_BIAS,bias);
00630 glPixelTransferf(GL_RED_SCALE,scale);
00631 glPixelTransferf(GL_GREEN_SCALE,scale);
00632 glPixelTransferf(GL_BLUE_SCALE,scale);
00633
00634
00635
00636
00637
00638
00639 glDrawPixels(what.width(),what.height(),
00640 GL_LUMINANCE,GL_FLOAT,
00641 static_cast<QVImage<sFloat,1> *>(imagecopy)->getReadData() +
00642 what.y()*img_step/sizeof(sFloat)+what.x());
00643 }
00644 else if(image->isCompatibleWith("QVImage<uChar,3>")) {
00645 glPixelStorei(GL_UNPACK_ROW_LENGTH,img_step/3);
00646 glDrawPixels(what.width(),what.height(),
00647 GL_RGB,GL_UNSIGNED_BYTE,
00648 static_cast<QVImage<uchar,3> *>(imagecopy)->getReadData() +
00649 what.y()*img_step+3*what.x());
00650 }
00651 else if(image->isCompatibleWith("QVImage<uShort,3>")) {
00652 glPixelStorei(GL_UNPACK_ROW_LENGTH,img_step/(sizeof(uShort)*3));
00653 glDrawPixels(what.width(),what.height(),
00654 GL_RGB,GL_UNSIGNED_SHORT,
00655 static_cast<QVImage<uShort,3> *>(imagecopy)->getReadData() +
00656 what.y()*img_step/sizeof(uShort)+3*what.x());
00657 }
00658 else if(image->isCompatibleWith("QVImage<sShort,3>")) {
00659 glPixelStorei(GL_UNPACK_ROW_LENGTH,img_step/(sizeof(sShort)*3));
00660
00661 float scale=1.0/(high-low),bias=-low*scale;
00662 glPixelTransferf(GL_RED_BIAS,bias);
00663 glPixelTransferf(GL_GREEN_BIAS,bias);
00664 glPixelTransferf(GL_BLUE_BIAS,bias);
00665 glPixelTransferf(GL_RED_SCALE,scale);
00666 glPixelTransferf(GL_GREEN_SCALE,scale);
00667 glPixelTransferf(GL_BLUE_SCALE,scale);
00668
00669 glDrawPixels(what.width(),what.height(),
00670 GL_RGB,GL_SHORT,
00671 static_cast<QVImage<sShort,3> *>(imagecopy)->getReadData() +
00672 what.y()*img_step/sizeof(sShort)+3*what.x());
00673 }
00674 else if(image->isCompatibleWith("QVImage<sInt,3>")) {
00675 glPixelStorei(GL_UNPACK_ROW_LENGTH,img_step/(sizeof(sInt)*3));
00676
00677 float scale=1.0/(high-low),bias=-low*scale;
00678 glPixelTransferf(GL_RED_BIAS,bias);
00679 glPixelTransferf(GL_GREEN_BIAS,bias);
00680 glPixelTransferf(GL_BLUE_BIAS,bias);
00681 glPixelTransferf(GL_RED_SCALE,scale);
00682 glPixelTransferf(GL_GREEN_SCALE,scale);
00683 glPixelTransferf(GL_BLUE_SCALE,scale);
00684
00685 glDrawPixels(what.width(),what.height(),
00686 GL_RGB,GL_INT,
00687 static_cast<QVImage<sInt,3> *>(imagecopy)->getReadData() +
00688 what.y()*img_step/sizeof(sInt)+3*what.x());
00689 }
00690 else if(image->isCompatibleWith("QVImage<sFloat,3>")) {
00691 glPixelStorei(GL_UNPACK_ROW_LENGTH,img_step/(sizeof(sFloat)*3));
00692
00693 float scale=1.0/(high-low),bias=-low*scale;
00694 glPixelTransferf(GL_RED_BIAS,bias);
00695 glPixelTransferf(GL_GREEN_BIAS,bias);
00696 glPixelTransferf(GL_BLUE_BIAS,bias);
00697 glPixelTransferf(GL_RED_SCALE,scale);
00698 glPixelTransferf(GL_GREEN_SCALE,scale);
00699 glPixelTransferf(GL_BLUE_SCALE,scale);
00700
00701 glDrawPixels(what.width(),what.height(),
00702 GL_RGB,GL_FLOAT,
00703 static_cast<QVImage<sFloat,3> *>(imagecopy)->getReadData() +
00704 what.y()*img_step/sizeof(sFloat)+3*what.x());
00705 }
00706 else {
00707
00708 qFatal("Type of QVGenericImage still not supported in drawQVImage");
00709 }
00710
00711
00712
00713 glPopClientAttrib();
00714 glPopAttrib();
00715 glMatrixMode(GL_MODELVIEW);
00716 glPopMatrix();
00717 glMatrixMode(GL_PROJECTION);
00718 glPopMatrix();
00719 }
00720
00721
00722
00723
00724
00725 void QVImageArea::beginDrawWorldFromCamera(const double fx, const double fy, const QVCameraPose &cameraPosition)
00726 {
00727
00728 #ifdef QT_MIN_VERSION_4_6
00729 painter->beginNativePainting();
00730 #else
00731 std::cerr << "[QVImageArea::beginDrawWorldFromCamera] Qt version >= 4.6 is required for augmented reality functionality" << std::endl;
00732 #endif
00733
00734
00735 glMatrixMode(GL_PROJECTION);
00736 glPushMatrix();
00737 glMatrixMode(GL_MODELVIEW);
00738 glPushMatrix();
00739
00740
00741
00742
00743
00744 float w_p = origwidth,h_p = origheight, zm = zoom;
00745 float x = static_cast<float>(topLeft.x())/zm,y = static_cast<float>(topLeft.y())/zm;
00746 float w = width(), h = height();
00747 float fov = 2*atan2((float)h_p/2,(float)fy)*180/PI;
00748 float asp_rat = w_p/h_p;
00749
00750
00751 glMatrixMode(GL_PROJECTION);
00752 glLoadIdentity();
00753 glTranslatef((w_p-w)/w,-(h_p-h)/h,0);
00754 glScalef(zm,zm,1);
00755 glScalef(w_p/w,h_p/h,1);
00756 glTranslatef(-(x-(w_p/2-(w_p/2)/zm))/(w_p/2),(y-(h_p/2-(h_p/2)/zm))/(h_p/2),0);
00757 qvGluPerspective(fov,asp_rat*fy/fx,0.1,15.0);
00758
00759
00760 QV3DPointF C = cameraPosition.getCenter();
00761 QVMatrix R = cameraPosition.getOrientation().toRotationMatrix();
00762 QV3DPointF T = -R * C;
00763 QV3DPointF rotVect = lnSO3(R);
00764 float angle = rotVect.norm2();
00765 QV3DPointF axis = rotVect/angle;
00766
00767
00768 glMatrixMode(GL_MODELVIEW);
00769 glLoadIdentity();
00770 glTranslatef(T.x(),-T.y(),-T.z());
00771 glRotatef(angle*180/PI,axis.x(),-axis.y(),-axis.z());
00772 glScalef(1,-1,-1);
00773 }
00774
00775
00776 void QVImageArea::endDrawWorldFromCamera(void)
00777 {
00778
00779 glMatrixMode(GL_PROJECTION);
00780 glPopMatrix();
00781 glMatrixMode(GL_MODELVIEW);
00782 glPopMatrix();
00783
00784
00785 #ifdef QT_MIN_VERSION_4_6
00786 painter->endNativePainting();
00787 #else
00788 std::cerr << "[QVImageArea::endDrawWorldFromCamera] Qt version >= 4.6 is required for augmented reality functionality" << std::endl;
00789 #endif
00790 }
00791
00792 void QVImageArea::mousePressEvent(QMouseEvent *event)
00793 {
00794 firstPos = event->pos();
00795 dragging = TRUE;
00796 if(mouseMode == DRAG) {
00797 setCursor(Qt::ClosedHandCursor);
00798 }
00799
00800 if ( (mouseMode == SEL) && (event->button() == Qt::RightButton) ) {
00801 selRect = QRect();
00802 emit rectSelected(QRect());
00803 }
00804
00805
00806 if (mouseMode == POLY) {
00807 if (event->button() == Qt::RightButton) {
00808 selPoly = QVPolyline();
00809 emit polySelected(QPoint(), true, polyMode);
00810 } else {
00811 QPoint pos = event->pos();
00812 QPoint point(qRound(-0.5+static_cast<float>(pos.x()+topLeft.x())/zoom), qRound(-0.5+static_cast<float>(pos.y()+topLeft.y())/zoom));
00813 selPoly.append(point);
00814 emit polySelected(point, false, polyMode);
00815 }
00816 }
00817 makeCurrent();
00818 update();
00819 }
00820
00821 void QVImageArea::mouseMoveEvent(QMouseEvent *event)
00822 {
00823 if(dragging) {
00824 lastPos = event->pos();
00825 switch(mouseMode) {
00826 case DRAG: {
00827 QPoint minDesp = -topLeft,
00828 maxDesp = QPoint(origwidth*zoom,origheight*zoom) -
00829 (topLeft + QPoint(width(),height()));
00830 QPoint desp = firstPos-lastPos,
00831 boundDesp = QPoint(qBound(minDesp.x(),desp.x(),maxDesp.x()),
00832 qBound(minDesp.y(),desp.y(),maxDesp.y()));
00833 if(boundDesp != QPoint(0,0)) {
00834 topLeft = topLeft+boundDesp;
00835 makeCurrent();
00836 update();
00837 emit newGeometry(origwidth,origheight,topLeft.x(),topLeft.y(),width(),height(),zoom);
00838 }
00839 firstPos = lastPos;
00840 emit mouseLeavesImageArea(FALSE);
00841 emit newMousePosition(static_cast<float>(event->x()+topLeft.x())/zoom,static_cast<float>(event->y()+topLeft.y())/zoom);
00842 break;
00843 }
00844 case ZOOM: {
00845 QPoint p1(qRound(static_cast<float>(firstPos.x()+topLeft.x())/zoom),
00846 qRound(static_cast<float>(firstPos.y()+topLeft.y())/zoom)),
00847 p2(qRound(static_cast<float>(lastPos.x()+topLeft.x())/zoom)-1,
00848 qRound(static_cast<float>(lastPos.y()+topLeft.y())/zoom)-1);
00849
00850
00851
00852
00853 zoomRect = QRect(p1,p2) & innerRect();
00854 emit mouseLeavesImageArea(FALSE);
00855 emit newMousePosition(lastPos.x()>firstPos.x()?zoomRect.right():zoomRect.left(), lastPos.y()>firstPos.y()?zoomRect.bottom():zoomRect.top());
00856 makeCurrent();
00857 update();
00858 break;
00859 }
00860 case SEL: {
00861 QPoint p1(qRound(static_cast<float>(firstPos.x()+topLeft.x())/zoom),
00862 qRound(static_cast<float>(firstPos.y()+topLeft.y())/zoom)),
00863 p2(qRound(static_cast<float>(lastPos.x()+topLeft.x())/zoom)-1,
00864 qRound(static_cast<float>(lastPos.y()+topLeft.y())/zoom)-1);
00865
00866 selRect = QRect(p1,p2) & innerRect();
00867 emit rectSelected(selRect);
00868 emit mouseLeavesImageArea(FALSE);
00869 emit newMousePosition(lastPos.x()>firstPos.x()?selRect.right():selRect.left(), lastPos.y()>firstPos.y()?selRect.bottom():selRect.top());
00870 makeCurrent();
00871 update();
00872 break;
00873 }
00874 case POLY: {
00875 break;
00876 }
00877 case NONE: {
00878 break;
00879 }
00880 }
00881 } else {
00882 emit mouseLeavesImageArea(FALSE);
00883 emit newMousePosition(static_cast<float>(event->x()+topLeft.x())/zoom,static_cast<float>(event->y()+topLeft.y())/zoom);
00884 }
00885 }
00886
00887
00888 void QVImageArea::mouseReleaseEvent(QMouseEvent *event)
00889 {
00890
00891 if(mouseMode == DRAG) {
00892 setCursor(Qt::OpenHandCursor);
00893 }
00894 dragging = FALSE;
00895 lastPos = event->pos();
00896 switch(mouseMode) {
00897 case DRAG: {
00898 break;
00899 }
00900 case ZOOM: {
00901 int newzoom = zoom;
00902
00903 if (zoomRect.width() < 1 or zoomRect.height() < 1)
00904 newzoom = max_zoom + 1;
00905 else {
00906 do {
00907 if (newzoom < 2) newzoom++;
00908 else newzoom = 2*newzoom;
00909 }
00910 while(newzoom*zoomRect.width() < minimumWidth() or newzoom*zoomRect.height() < minimumHeight());
00911 }
00912
00913 if(newzoom <= max_zoom) {
00914 zoom = newzoom;
00915 topLeft = zoom*zoomRect.topLeft();
00916 setMaximumSize(zoom*origwidth,zoom*origheight);
00917 resize(zoom*zoomRect.width(),zoom*zoomRect.height());
00918 zoomRect = QRect();
00919 makeCurrent();
00920 update();
00921 emit newGeometry(origwidth,origheight,topLeft.x(),topLeft.y(),width(),height(),zoom);
00922 } else {
00923 zoomRect = QRect();
00924 makeCurrent();
00925 update();
00926 }
00927 break;
00928 }
00929 case SEL: {
00930 if(event->button() == Qt::RightButton) {
00931 selRect = QRect();
00932 emit rectSelected(QRect());
00933 makeCurrent();
00934 update();
00935 }
00936 break;
00937 }
00938 case POLY: {
00939 break;
00940 }
00941 case NONE: {
00942 break;
00943 }
00944 }
00945 }
00946
00947 void QVImageArea::leaveEvent(QEvent *event)
00948 {
00949 Q_UNUSED(event);
00950 emit mouseLeavesImageArea(TRUE);
00951 }
00952
00953
00954
00955
00956 void QVCanvas::resizeEvent(QResizeEvent *event)
00957 {
00958 QFontMetrics fm(font());
00959
00960 int w = event->size().width() - scaleWidgetsFixedWidth - 1;
00961 int h = event->size().height() - scaleWidgetsFixedWidth - statusBarWidgetFixedHeight - 1;
00962 imageArea->setGeometry(scaleWidgetsFixedWidth,scaleWidgetsFixedWidth,w,h);
00963 }
00964
00965 QString QVCanvas::statusMessage()
00966 {
00967 if(mouseIsOut) {
00968 return QString("z=%1").arg(imageArea->zoom);
00969 } else {
00970 return QString("(%1,%2) z=%3").arg(mousePosX).arg(mousePosY).arg(imageArea->zoom);
00971 }
00972 }
00973
00974 QVCanvas::QVCanvas(QWidget *parent) : QWidget(parent)
00975 {
00976 mouseIsOut = TRUE;
00977 int w = 1, h = 1;
00978
00979 QFontMetrics fm(font());
00980 scaleWidgetsFixedWidth = 5*fm.height()/3;
00981
00982 #ifdef QVQWT
00983
00984 scaleWidgetX = new QwtScaleWidget(QwtScaleDraw::TopScale,this);
00985
00986 scaleWidgetX->setLabelAlignment(Qt::AlignHCenter|Qt::AlignTop);
00987 scaleWidgetX->setMargin(1);
00988
00989
00990
00991 scaleWidgetX->setBorderDist(scaleWidgetsFixedWidth,scaleWidgetsFixedWidth);
00992
00993 scaleWidgetY = new QwtScaleWidget(QwtScaleDraw::LeftScale,this);
00994 scaleWidgetY->setLabelRotation(-90.0);
00995 scaleWidgetY->setLabelAlignment(Qt::AlignVCenter|Qt::AlignTop);
00996 scaleWidgetY->setMargin(1);
00997
00998
00999
01000 scaleWidgetY->setBorderDist(scaleWidgetsFixedWidth,scaleWidgetsFixedWidth);
01001
01002
01003 scaleEngineX = new QwtLinearScaleEngine;
01004 scaleEngineY = new QwtLinearScaleEngine;
01005 #endif
01006
01007
01008 if(image_areas.isEmpty()) {
01009
01010 imageArea = new QVImageArea(w,h,this);
01011 }
01012 else {
01013
01014 imageArea = new QVImageArea(w,h,this,image_areas.first());
01015 }
01016
01017 image_areas.append(imageArea);
01018
01019 statusBar = new QStatusBar(this);
01020 statusBar->addPermanentWidget(buttonDrawSel = new QToolButton(statusBar));
01021 statusBar->addPermanentWidget(buttonZoomIn = new QToolButton(statusBar));
01022 statusBar->addPermanentWidget(buttonZoomOut = new QToolButton(statusBar));
01023 statusBar->addPermanentWidget(buttonZoomOriginal = new QToolButton(statusBar));
01024 statusBar->addPermanentWidget(buttonZoomRect = new QToolButton(statusBar));
01025 statusBar->addPermanentWidget(buttonselPoly = new QToolButton(statusBar));
01026 statusBar->addPermanentWidget(buttonSelRect = new QToolButton(statusBar));
01027 statusBar->addPermanentWidget(buttonDrag = new QToolButton(statusBar));
01028 buttonDrawSel->setCheckable(TRUE);
01029 buttonDrawSel->setIcon(QIcon(":/images/drawsel.png"));
01030 buttonDrawSel->setChecked(TRUE);
01031 buttonZoomIn->setCheckable(FALSE);
01032 buttonZoomIn->setIcon(QIcon(":/images/zoom-in.png"));
01033 buttonZoomOut->setCheckable(FALSE);
01034 buttonZoomOut->setIcon(QIcon(":/images/zoom-out.png"));
01035 buttonZoomOriginal->setCheckable(FALSE);
01036 buttonZoomOriginal->setIcon(QIcon(":/images/zoom-original.png"));
01037 buttonZoomRect->setCheckable(TRUE);
01038 buttonZoomRect->setIcon(QIcon(":/images/zoom-best-fit.png"));
01039 buttonselPoly->setCheckable(TRUE);
01040 buttonselPoly->setIcon(QIcon(":/images/list.png"));
01041 menuselPoly = new QMenu();
01042 menuselPoly->addAction(QIcon(":/images/list.png"), "points", this, SLOT(selPolyChangedToList()));
01043 menuselPoly->addAction(QIcon(":/images/poly.png"), "polyline", this, SLOT(selPolyChangedToLine()));
01044 menuselPoly->addAction(QIcon(":/images/polyclosed.png"), "closed polyline", this, SLOT(selPolyChangedToClosed()));
01045 buttonselPoly->setMenu(menuselPoly);
01046 polyMode = LIST;
01047 buttonSelRect->setCheckable(TRUE);
01048 buttonSelRect->setIcon(QIcon(":/images/select.png"));
01049 buttonDrag->setCheckable(TRUE);
01050 buttonDrag->setIcon(QIcon(":/images/hand.png"));
01051
01052 statusBar->showMessage(statusMessage());
01053 statusBarWidgetFixedHeight = statusBar->height();
01054
01055 setMinimumSize(scaleWidgetsFixedWidth + imageArea->minimumWidth() + 1,
01056 scaleWidgetsFixedWidth + imageArea->minimumHeight() + 1 +
01057 statusBarWidgetFixedHeight);
01058 setMaximumSize(scaleWidgetsFixedWidth + w + 1,
01059 scaleWidgetsFixedWidth + h + 1 +
01060 statusBarWidgetFixedHeight);
01061 resize(scaleWidgetsFixedWidth + w + 1,
01062 scaleWidgetsFixedWidth + h + 1 +
01063 statusBarWidgetFixedHeight);
01064 connect(imageArea,SIGNAL(newGeometry(int,int,int,int,int,int,int)),
01065 this,SLOT(setGeometry(int,int,int,int,int,int,int)));
01066 connect(imageArea,SIGNAL(newMousePosition(float,float)),
01067 this,SLOT(newMousePositionSlot(float,float)));
01068 connect(imageArea,SIGNAL(mouseLeavesImageArea(bool)),
01069 this,SLOT(mouseLeavesImageAreaSlot(bool)));
01070 connect(imageArea, SIGNAL(rectSelected(QRect)),
01071 this, SLOT(rectSelectedSlot(QRect)));
01072 connect(imageArea, SIGNAL(polySelected(QPoint,bool,TPolyMode)),
01073 this, SLOT(polySelectedSlot(QPoint,bool,TPolyMode)));
01074 connect(buttonDrawSel,SIGNAL(clicked(bool)),this,SLOT(drawSelClicked(bool)));
01075 connect(buttonZoomRect,SIGNAL(clicked(bool)),this,SLOT(zoomRectClicked(bool)));
01076 connect(buttonselPoly,SIGNAL(clicked(bool)),this,SLOT(selPolyClicked(bool)));
01077 connect(buttonSelRect,SIGNAL(clicked(bool)),this,SLOT(selRectClicked(bool)));
01078 connect(buttonDrag,SIGNAL(clicked(bool)),this,SLOT(dragClicked(bool)));
01079 connect(buttonZoomIn,SIGNAL(clicked()),this,SLOT(zoomInClicked()));
01080 connect(buttonZoomOut,SIGNAL(clicked()),this,SLOT(zoomOutClicked()));
01081 connect(buttonZoomOriginal,SIGNAL(clicked()),this,SLOT(zoomOriginalClicked()));
01082
01083 }
01084
01085 void QVCanvas::drawSelClicked(bool checked) {
01086 imageArea->drawSel = checked;
01087 refreshImageArea();
01088 }
01089
01090 void QVCanvas::zoomInClicked() {
01091 imageArea->centerZoom(2*imageArea->zoom);
01092 }
01093
01094 void QVCanvas::zoomOutClicked() {
01095 imageArea->centerZoom(imageArea->zoom/2);
01096 }
01097
01098 void QVCanvas::zoomOriginalClicked() {
01099
01100 int w = imageArea->origwidth, h = imageArea->origheight;
01101 imageArea->origwidth = imageArea->origheight = 0;
01102 QRect saveSelRect = imageArea->selRect;
01103 QVPolyline saveSelPoly = imageArea->selPoly;
01104 imageArea->resizeImageArea(w,h);
01105 imageArea->selRect = saveSelRect;
01106 imageArea->selPoly = saveSelPoly;
01107 refreshImageArea();
01108 }
01109
01110
01111 void QVCanvas::zoomRectClicked(bool checked) {
01112 if(checked)
01113 imageArea->setCursor(Qt::CrossCursor);
01114 else
01115 imageArea->setCursor(Qt::ArrowCursor);
01116 imageArea->mouseMode = (checked ? QVImageArea::ZOOM : QVImageArea::NONE);
01117 buttonselPoly->setChecked(false);
01118 buttonSelRect->setChecked(false);
01119 buttonDrag->setChecked(false);
01120 }
01121
01122 void QVCanvas::selPolyClicked(bool checked) {
01123 if(checked)
01124 imageArea->setCursor(Qt::CrossCursor);
01125 else
01126 imageArea->setCursor(Qt::ArrowCursor);
01127
01128 if (checked) {
01129 imageArea->mouseMode = QVImageArea::POLY;
01130 imageArea->polyMode = polyMode;
01131 } else {
01132 imageArea->mouseMode = QVImageArea::NONE;
01133 }
01134 buttonZoomRect->setChecked(false);
01135 buttonSelRect->setChecked(false);
01136 buttonDrag->setChecked(false);
01137 }
01138
01139 void QVCanvas::selPolyChangedToList() {
01140 polyMode = LIST;
01141 if(imageArea->polyMode != LIST) {
01142 imageArea->polyMode = polyMode;
01143 imageArea->selPoly = QVPolyline();
01144 polySelectedSlot(QPoint(), true, polyMode);
01145 refreshImageArea();
01146 }
01147 buttonselPoly->setIcon(QIcon(":/images/list.png"));
01148 selPolyClicked(true);
01149 buttonselPoly->setChecked(true);
01150 }
01151
01152 void QVCanvas::selPolyChangedToLine() {
01153 polyMode = LINE;
01154 if(imageArea->polyMode != LINE) {
01155 imageArea->polyMode = polyMode;
01156 imageArea->selPoly = QVPolyline();
01157 polySelectedSlot(QPoint(), true, polyMode);
01158 refreshImageArea();
01159 }
01160 buttonselPoly->setIcon(QIcon(":/images/poly.png"));
01161 selPolyClicked(true);
01162 buttonselPoly->setChecked(true);
01163 }
01164
01165 void QVCanvas::selPolyChangedToClosed() {
01166 polyMode = CLOSED;
01167 if(imageArea->polyMode != CLOSED) {
01168 imageArea->polyMode = polyMode;
01169 imageArea->selPoly = QVPolyline();
01170 polySelectedSlot(QPoint(), true, polyMode);
01171 refreshImageArea();
01172 }
01173 buttonselPoly->setIcon(QIcon(":/images/polyclosed.png"));
01174 selPolyClicked(true);
01175 buttonselPoly->setChecked(true);
01176 }
01177
01178 void QVCanvas::selRectClicked(bool checked) {
01179 if(checked)
01180 imageArea->setCursor(Qt::CrossCursor);
01181 else
01182 imageArea->setCursor(Qt::ArrowCursor);
01183 imageArea->mouseMode = (checked ? QVImageArea::SEL : QVImageArea::NONE);
01184 buttonZoomRect->setChecked(false);
01185 buttonselPoly->setChecked(false);
01186 buttonDrag->setChecked(false);
01187 if (!checked) {
01188 imageArea->selRect = QRect();
01189 refreshImageArea();
01190 emit imageArea->rectSelected(QRect());
01191 }
01192 }
01193
01194 void QVCanvas::dragClicked(bool checked) {
01195 if(checked)
01196 imageArea->setCursor(Qt::OpenHandCursor);
01197 else
01198 imageArea->setCursor(Qt::ArrowCursor);
01199
01200 imageArea->mouseMode = (checked ? QVImageArea::DRAG : QVImageArea::NONE);
01201 buttonselPoly->setChecked(false);
01202 buttonSelRect->setChecked(false);
01203 buttonZoomRect->setChecked(false);
01204 }
01205
01206
01207 void QVCanvas::newMousePositionSlot(float x,float y) {
01208 mousePosX = x;
01209 mousePosY = y;
01210 statusBar->showMessage(statusMessage());
01211 }
01212
01213 void QVCanvas::mouseLeavesImageAreaSlot(bool leaves) {
01214
01215
01216
01217
01218 mouseIsOut = leaves;
01219 statusBar->showMessage(statusMessage());
01220 }
01221
01222
01223 QVCanvas::~QVCanvas()
01224 {
01225 #ifdef QVQWT
01226 delete scaleEngineX;
01227 delete scaleEngineY;
01228 #endif
01229
01230
01231 image_areas.removeAll(imageArea);
01232
01233 delete imageArea;
01234 }
01235
01236 void QVCanvas::refreshImageArea()
01237 {
01238 imageArea->makeCurrent();
01239 imageArea->update();
01240 }
01241
01242
01243 void QVCanvas::setGeometry(int origwidth,int origheight,int topleftx,int toplefty,int width,int height, int zoom)
01244 {
01245 Q_UNUSED(origwidth);
01246 Q_UNUSED(origheight);
01247
01248 QFontMetrics fm(font());
01249
01250
01251
01252 #ifdef QVQWT
01253 QwtScaleDiv scaleDivX = scaleEngineX->divideScale(
01254 ((double)topleftx)/zoom,((double)(topleftx+width))/zoom,
01255 qMin(width/zoom+1,static_cast<int>(width/(fm.width("999")))),
01256 10,0);
01257 scaleWidgetX->setScaleDiv(scaleEngineX->transformation(),scaleDivX);
01258
01259 QwtScaleDiv scaleDivY = scaleEngineY->divideScale(
01260 ((double)toplefty+height)/zoom,((double)(toplefty))/zoom,
01261 qMin(height/zoom+1,static_cast<int>(height/(fm.width("999")))),
01262 10,0);
01263 scaleWidgetY->setScaleDiv(scaleEngineY->transformation(),scaleDivY);
01264
01265
01266
01267
01268 scaleWidgetX->setGeometry(0,0,
01269 2*scaleWidgetsFixedWidth+width+1,scaleWidgetsFixedWidth);
01270 scaleWidgetY->setGeometry(0,0,
01271 scaleWidgetsFixedWidth,2*scaleWidgetsFixedWidth+height+1);
01272 #endif
01273
01274 setMinimumSize(scaleWidgetsFixedWidth + imageArea->minimumWidth() + 1,
01275 scaleWidgetsFixedWidth + imageArea->minimumHeight() + 1 +
01276 statusBarWidgetFixedHeight);
01277
01278 setMaximumSize(scaleWidgetsFixedWidth+zoom*imageArea->origwidth + 1 +1,
01279 scaleWidgetsFixedWidth+zoom*imageArea->origheight + 1 +
01280 statusBarWidgetFixedHeight + 1);
01281
01282 resize(scaleWidgetsFixedWidth+width+1,
01283 scaleWidgetsFixedWidth+height+1+statusBarWidgetFixedHeight);
01284
01285 statusBar->setGeometry(
01286 0,scaleWidgetsFixedWidth+height+1,
01287 scaleWidgetsFixedWidth+width+1,statusBarWidgetFixedHeight);
01288
01289 statusBar->showMessage(statusMessage());
01290 }
01291
01292