00001 #include "VolumeBuffer.h"
00002 #include <QtGui>
00003 #include <QtOpenGL>
00004
00005 #include <math.h>
00006
00007 #include "pcwidget.h"
00008 #include <GL/gl.h>
00009 #include <GL/glu.h>
00010 #include <GL/glut.h>
00011
00012
00013 pcWidget::pcWidget(QWidget *parent)
00014 : QGLWidget(parent)
00015 {
00016 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
00017 m_data_available = 0;
00018
00019 m_current_slice = 0;
00020
00021 m_selection_quad.first = QPointF(0.0f,0.0f);
00022 m_selection_quad.second = QPointF(0.0f,0.0f);
00023
00024 m_tfimg = QImage(256, 4, QImage::Format_ARGB32_Premultiplied);
00025 m_tfimg.fill(0);
00026 }
00027
00028 pcWidget::~pcWidget()
00029 {
00030 makeCurrent();
00031 }
00032
00033 QSize pcWidget::minimumSizeHint() const
00034 {
00035 return QSize(50, 50);
00036 }
00037
00038 QSize pcWidget::sizeHint() const
00039 {
00040 return QSize(256, 512);
00041 }
00042
00043 void pcWidget::initializeGL()
00044 {
00045
00046 qglClearColor(QColor::fromRgb(255,255,255));
00047 glShadeModel (GL_FLAT);
00048 glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
00049 gluOrtho2D(0.0, 256.0, 0.0, 512.0);
00050 glEnable(GL_BLEND);
00051 }
00052
00053 void pcWidget::paintGL()
00054 {
00055 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00056
00057 glLoadIdentity();
00058
00059 glTranslated(0.0, 0.0, 0.0);
00060
00061 glColor3f(0.0f,0.0f,0.0f);
00062
00063 glBegin(GL_LINES);
00064 glVertex2f(0, 64);
00065 glVertex2f(256, 64);
00066
00067 glVertex2f(0, 192);
00068 glVertex2f(256, 192);
00069
00070 glVertex2f(0, 320);
00071 glVertex2f(256, 320);
00072
00073 glVertex2f(0, 448);
00074 glVertex2f(256, 448);
00075 glEnd();
00076
00077 glEnable(GL_BLEND);
00078 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00079
00080
00081
00082
00083
00084
00085 QListIterator<ParralelCoordinatesLine> pc_lineslist_i(pc_lines_list);
00086 ParralelCoordinatesLine pc_line;
00087 QList<QPointF> pc_line_vertices;
00088 QColor pc_line_color;
00089 while(pc_lineslist_i.hasNext())
00090 {
00091 pc_line = pc_lineslist_i.next();
00092 pc_line_vertices = pc_line.first;
00093 pc_line_color = pc_line.second;
00094
00095
00096 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
00097
00098
00099 qglColor(pc_line_color);
00100
00101
00102 glBegin(GL_POLYGON);
00103 QListIterator<QPointF> i(pc_line_vertices);
00104 QPointF poly_vertex;
00105 while (i.hasNext())
00106 {
00107 poly_vertex = (QPointF)i.next();
00108
00109
00110 if(i.hasNext())
00111 glEdgeFlag(GL_TRUE);
00112 else
00113 glEdgeFlag(GL_FALSE);
00114
00115 glVertex2f(poly_vertex.x(),poly_vertex.y());
00116 }
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 glEnd();
00130 }
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 glFlush ();
00159
00160 }
00161
00162 void pcWidget::resizeGL(int width, int height)
00163 {
00164 int side = qMin(width, height);
00165
00166 glViewport (0, 0, (GLsizei) width, (GLsizei) height);
00167 glMatrixMode (GL_PROJECTION);
00168 glLoadIdentity ();
00169 }
00170
00171 void pcWidget::readPCLines()
00172 {
00173 int v0,v1,v2,v3;
00174
00175 QPointF l0,l1,l2,l3;
00176 QColor line_color;
00177
00178
00179
00180 if(m_data_available)
00181 {
00182 pc_lines_list.clear();
00183
00184 int vw= m_vb->getWidth();
00185 int vh= m_vb->getHeight();
00186 int vd= m_vb->getDepth();
00187
00188
00189
00190
00191 int start_y = qMin(m_selection_quad.first.x(), m_selection_quad.second.x());
00192 int end_y = qMax(m_selection_quad.first.x(), m_selection_quad.second.x());
00193 int start_x = qMin(m_selection_quad.first.y(), m_selection_quad.second.y());
00194 int end_x = qMax(m_selection_quad.first.y(), m_selection_quad.second.y());
00195
00196 int ix, iy, iz;
00197 iz=m_current_slice;
00198
00199 for (iy = start_y; iy < end_y; iy++)
00200 {
00201 for (ix = start_x; ix <= end_x; ix++)
00202 {
00203 v0 = m_vb->m_volume_data_raw[(vh*vw)*iz + (vw)*iy + ix];
00204 v1 = m_vb->m_scale1_raw[(vh*vw)*iz + (vw)*iy + ix];
00205 v2 = m_vb->m_scale2_raw[(vh*vw)*iz + (vw)*iy + ix];
00206 v3 = m_vb->m_scale3_raw[(vh*vw)*iz + (vw)*iy + ix];
00207
00208 l0 = QPointF(v0, 64.0);
00209 l1 = QPointF(v1, 192.0);
00210 l2 = QPointF(v2, 320.0);
00211 l3 = QPointF(v3, 448.0);
00212
00213
00214 QRgb lc0 = m_tfimg.pixel(v0,0);
00215 QRgb lc1 = m_tfimg.pixel(v1,1);
00216 QRgb lc2 = m_tfimg.pixel(v2,2);
00217 QRgb lc3 = m_tfimg.pixel(v3,3);
00218
00219 int rlc0 = qRed(lc0);
00220 int glc0 = qGreen(lc0);
00221 int blc0 = qBlue(lc0);
00222 int alc0 = qAlpha(lc0);
00223 float p0 = (float)alc0/255;
00224
00225 int rlc1 = qRed(lc1);
00226 int glc1 = qGreen(lc1);
00227 int blc1 = qBlue(lc1);
00228 int alc1 = qAlpha(lc1);
00229 float p1 = (float)alc1/255;
00230
00231 int rlc2 = qRed(lc2);
00232 int glc2 = qGreen(lc2);
00233 int blc2 = qBlue(lc2);
00234 int alc2 = qAlpha(lc2);
00235 float p2 = (float)alc2/255;
00236
00237 int rlc3 = qRed(lc3);
00238 int glc3 = qGreen(lc3);
00239 int blc3 = qBlue(lc3);
00240 int alc3 = qAlpha(lc3);
00241 float p3 = (float)alc3/255;
00242
00243 float pi = 1.0f;
00244 int rlc=0,glc=0,blc=0,alc=0;
00245 if((rlc0 > 0) || (glc0 > 0) || (blc0>0))
00246 {
00247 rlc = rlc0;
00248 glc = glc0;
00249 blc = blc0;
00250 pi = pi*p0;
00251 }
00252
00253 if((rlc1 > 0) || (glc1 > 0) || (blc1>0))
00254 {
00255 rlc = rlc1;
00256 glc = glc1;
00257 blc = blc1;
00258 pi = pi*p1;
00259 }
00260
00261 if((rlc2 > 0) || (glc2 > 0) || (blc2>0))
00262 {
00263 rlc = rlc2;
00264 glc = glc2;
00265 blc = blc2;
00266 pi = pi*p2;
00267 }
00268
00269 if((rlc3 > 0) || (glc3 > 0) || (blc3>0))
00270 {
00271 rlc = rlc3;
00272 glc = glc3;
00273 blc = blc3;
00274 pi = pi*p3;
00275 }
00276
00277 alc = (int)255*pi;
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297 line_color = QColor(rlc,glc,blc,alc);
00298
00299
00300
00301 QList<QPointF> vertices;
00302 vertices.append(l0);
00303 vertices.append(l1);
00304 vertices.append(l2);
00305 vertices.append(l3);
00306
00307 pc_lines_list.append(qMakePair(vertices,line_color));
00308 }
00309 }
00310 }
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350 }
00351
00352 void pcWidget::mousePressEvent(QMouseEvent *event)
00353 {
00354 }
00355
00356 void pcWidget::mouseMoveEvent(QMouseEvent *event)
00357 {
00358 }
00359
00360 void pcWidget::set_pc_data(VolumeBuffer *vb1)
00361 {
00362
00363 makeCurrent();
00364
00365 std::cout << "Parallel data changed...\n";
00366
00367 m_vb = vb1;
00368
00369 m_data_available = 1;
00370
00371 updateGL();
00372 }
00373
00374 void pcWidget::setSlice(int slice)
00375 {
00376 makeCurrent();
00377 m_current_slice = slice;
00378 readPCLines();
00379 updateGL();
00380 }
00381
00382 void pcWidget::sedSelectionQuad(QPair<QPointF,QPointF> &sel_quad)
00383 {
00384 makeCurrent();
00385 m_selection_quad = sel_quad;
00386
00387 readPCLines();
00388 updateGL();
00389 }
00390
00391 void pcWidget::setTFtexture(QImage &tfimg)
00392 {
00393 makeCurrent();
00394 int ix = 0;
00395
00396 for (ix = 0; ix < m_tfimg.width(); ix++)
00397 m_tfimg.setPixel(ix, 0, tfimg.pixel(ix,0));
00398
00399 readPCLines();
00400 updateGL();
00401 }
00402
00403 void pcWidget::setTFtexture1(QImage &tfimg)
00404 {
00405 makeCurrent();
00406 int ix = 0;
00407
00408 for (ix = 0; ix < m_tfimg.width(); ix++)
00409 m_tfimg.setPixel(ix, 1, tfimg.pixel(ix,0));
00410
00411 readPCLines();
00412 updateGL();
00413 }
00414
00415 void pcWidget::setTFtexture2(QImage &tfimg)
00416 {
00417 makeCurrent();
00418 int ix = 0;
00419
00420 for (ix = 0; ix < m_tfimg.width(); ix++)
00421 m_tfimg.setPixel(ix, 2, tfimg.pixel(ix,0));
00422
00423 readPCLines();
00424 updateGL();
00425 }
00426
00427 void pcWidget::setTFtexture3(QImage &tfimg)
00428 {
00429 makeCurrent();
00430 int ix = 0;
00431
00432 for (ix = 0; ix < m_tfimg.width(); ix++)
00433 m_tfimg.setPixel(ix, 3, tfimg.pixel(ix,0));
00434
00435 readPCLines();
00436 updateGL();
00437 }