00001 #include "QVolRendCanvas.h"
00002 #include "VQuaternion.h"
00003
00004 bool isfirstframe = true;
00005
00006
00007 QVolRendCanvas::QVolRendCanvas(QWidget* parent ) :
00008 QObject(parent),
00009 QGLWidget(parent),
00010 m_TransferFunction(NULL),
00011 m_ArrowTransferFunction(NULL),
00012 m_StreamLineTransferFunction(NULL),
00013 m_FramebufferObject(NULL),
00014 m_LicTransferFunction(NULL),
00015 m_SaveImageFBO(NULL),
00016 m_MouseLastPos(0.0f,0.0f,0.0f),
00017 m_LookAtPoint(0.0f, 0.0f, 0.0f),
00018 m_CamDat(0.0f, 0.0f, 2.0f),
00019 m_lightDir(0.0f, 1.0f, 0.0f),
00020 m_modifyLight(false),
00021 m_IsSaving(false),
00022 m_SaveFileName(""),
00023 m_FlowData(),
00024 m_FlowRenderer(),
00025 mArrowSize( 0.5f ),
00026 mArrowSpacing( 0.5f ),
00027 mStreamSeedSpacing( 0.5f ),
00028 mStreamTestSpacing( 0.2f ),
00029 mStremSteps( 0.5f ),
00030 mStreamDT( 0.5 ),
00031 m_EnableSeedpointsSetting( false ),
00032 m_EnableEvenSeedpointsSetting( false ),
00033 lic_activated(false),
00034 m_EnableIconSetting(false),
00035 tapering_activated( false )
00036 {
00037 glInit ();
00038 data_loaded = false;
00039 sliceview_active = true;
00040 apply_tf_in_sv = 0;
00041 apply_tf_in_vv = 0;
00042
00043 m_MouseState = NO_DRAGGING;
00044 m_vecPosition = getSphereProjection(0.0f, 0.0f);
00045 m_LookAt = VVector(0.0f, 0.0f, 0.0f);
00046 m_Position = VVector(0.0f, 0.0f, -10.0f);
00047 m_Distance = 20.0f;
00048 m_PanOffset = VVector(5.0f, 0.0f, 0.0f);
00049 m_Rotation = VVector(0.0f, 0.0f, 0.0f);
00050 m_fAngle = 0.0f;
00051
00052 view = VVector(0.0, 0.0, 1.0);
00053 up = VVector(0.0, 1.0, 0.0);
00054
00055 side = view.getCross(up);
00056 side.normalize();
00057 up = side.getCross(view);
00058 up.normalize();
00059
00060 lview = VVector(0.0, 0.0, 1.0);
00061 lup = VVector(0.0, 1.0, 0.0);
00062
00063 lside = lview.getCross(lup);
00064 lside.normalize();
00065 lup = lside.getCross(lview);
00066 lup.normalize();
00067
00068
00069
00070
00071
00072 arrows_activated = false;
00073 streamlines_activated = false;
00074 timestep_activated = 1;
00075 coloring_property = 1;
00076 }
00077
00078
00079 QVolRendCanvas::~QVolRendCanvas()
00080 {
00081 if(m_FramebufferObject)
00082 {
00083 delete m_FramebufferObject;
00084 }
00085 m_TransferFunction = NULL;
00086
00087
00088 m_ArrowsColor = NULL;
00089 m_StreamlinesColor = NULL;
00090
00091
00092 }
00093
00094 void QVolRendCanvas::setObjectName(const QString &name)
00095 {
00096 }
00097
00098 void QVolRendCanvas::timestep_changed_event( int val)
00099 {
00100 timestep_activated = val;
00101 m_FlowData.setTimeStep( val - 1 );
00102 if ( m_EnableIconSetting )
00103 {
00104 m_FlowData.computeIcons( );
00105 }
00106 repaint();
00107
00108 }
00109
00110 void QVolRendCanvas::coloringproperty_changed_event( int val)
00111 {
00112 coloring_property = val;
00113 m_FlowRenderer.setCurrentShader( val );
00114 repaint();
00115
00116 }
00117
00118
00119 void QVolRendCanvas::setStreamlinesColorPtr(VVector *v)
00120 {
00121 m_StreamlinesColor = v;
00122 m_FlowRenderer.setStreamlinesColorPtr(v);
00123 }
00124
00125
00126 void QVolRendCanvas::setArrowsColorPtr(VVector *v)
00127 {
00128 m_ArrowsColor =v;
00129 m_FlowRenderer.setArrowColorPtr(v);
00130 }
00131
00132
00133 void QVolRendCanvas::initializeGL()
00134 {
00135 this->makeCurrent();
00136
00137
00138 glClearColor( 0.0, 0.0, 0.0, 0.0 );
00139 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00140 glEnable(GL_DEPTH_TEST);
00141
00142 }
00143
00144 void QVolRendCanvas::resizeGL( int w, int h )
00145 {
00146 this->makeCurrent();
00147 glViewport(0, 0, w, h);
00148
00149 if(m_FramebufferObject)
00150 {
00151 delete m_FramebufferObject;
00152 m_FramebufferObject = NULL;
00153 }
00154
00155 m_FramebufferObject = new VFramebufferObject(width(), height(), GL_RGBA);
00156 m_FramebufferObject->init();
00157 m_FlowRenderer.resize(w, h);
00158
00159 if( data_loaded )
00160 {
00161 m_PanOffset = m_FlowData.getFlowCenter();
00162 m_Position.setZ(-m_FlowData.getFlowExtends().getMagnitude());
00163 VVector extends = m_FlowData.getFlowExtends();
00164 float halfExdends = (extends.getX() < extends.getY()) ? extends.getY() : extends.getX();
00165 if( halfExdends == extends.getY())
00166 {
00167 halfExdends /= 2.0f;
00168 }
00169 else
00170 {
00171 halfExdends /= 2.0f;
00172 halfExdends /= m_FlowRenderer.getCameraAspect();
00173 }
00174
00175 float fov = m_FlowRenderer.getCameraFOV();
00176 fov /= 2.0f;
00177
00178
00179 m_Distance = halfExdends / tan(fov * 3.14159265f / 180.0f);
00180 m_FlowRenderer.processGuiInput(m_Distance, m_Position + m_PanOffset, view, up, m_LookAt + m_PanOffset);
00181 }
00182 }
00183
00184 VVector QVolRendCanvas::getSphereProjection(float x, float y)
00185 {
00186 VVector vecResult;
00187 vecResult.setX(cos(x) * sin(y));
00188 vecResult.setY(sin(x) * sin(y));
00189 const float fD = sqrtf(vecResult.getX() * vecResult.getX() + vecResult.getY() * vecResult.getY());
00190 vecResult.setZ(cosf((3.14159265f / 2.0f) * ((fD < 1.0f) ? fD : 1.0f)));
00191
00192 vecResult.normalize();
00193 return vecResult;
00194 }
00195
00196 VVector QVolRendCanvas::getPlaneProjection(float x, float y)
00197 {
00198 VVector vecResult;
00199 vecResult.setX(x);
00200 vecResult.setY(y);
00201 vecResult.setZ(0.0f);
00202
00203 return vecResult;
00204 }
00205
00206 void QVolRendCanvas::paintGL()
00207 {
00208 makeCurrent();
00209
00210 if(m_TransferFunction)
00211 {
00212
00213 m_FlowRenderer.setTransferFunctionHandle(m_TransferFunction->getGLHandle());
00214 }
00215
00216 if(m_ArrowTransferFunction)
00217 {
00218 m_FlowRenderer.setArrowTransferFunctionHandle(m_ArrowTransferFunction->getGLHandle());
00219 }
00220
00221 if(m_StreamLineTransferFunction)
00222 {
00223 m_FlowRenderer.setStreamLineTransferFunctionHandle(m_StreamLineTransferFunction->getGLHandle());
00224 }
00225
00226 if(m_LicTransferFunction)
00227 {
00228 m_FlowRenderer.setLicTransferFunctionHandle(m_LicTransferFunction->getGLHandle());
00229 }
00230
00231 if(!m_FlowRenderer.getProgramLoaded())
00232 {
00233 m_FlowRenderer.loadProgram();
00234 }
00235
00236 if(sliceview_active)
00237 {
00238 glClearColor(0.0f,0.0f,0.0f,0.0f);
00239 }
00240
00241
00242 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00243 glEnable(GL_DEPTH_TEST);
00244
00245
00246 if(m_IsSaving && data_loaded)
00247 {
00248
00249
00250 bool finished = true;
00251
00252 if(!m_FlowData.getTexturesGenerated())
00253 {
00254 m_FlowData.generateTextures();
00255
00256 }
00257
00258 m_SaveImageFBO->bind();
00259
00260 glDisable(GL_DEPTH_TEST);
00261
00262 m_FlowRenderer.draw( timestep_activated - 1 );
00263
00264 if( lic_activated )
00265 {
00266 m_FlowRenderer.drawLic( timestep_activated - 1 );
00267 }
00268
00269 if( arrows_activated )
00270 {
00271 m_FlowRenderer.drawGlyphes( timestep_activated - 1 );
00272 }
00273 if (streamlines_activated)
00274 {
00275 m_FlowRenderer.drawStreamLines( );
00276 }
00277
00278 if( m_EnableIconSetting )
00279 {
00280 m_FlowRenderer.drawIcons();
00281 }
00282
00283
00284 glEnable(GL_DEPTH_TEST);
00285
00286 m_SaveImageFBO->unbind();
00287
00288 glDisable(GL_CULL_FACE);
00289
00290 m_SaveImageFBO->renderToFullScreen();
00291
00292 m_SaveImageFBO->saveImage(m_SaveFileName);
00293 m_IsSaving = false;
00294 m_SaveFileName = "";
00295 m_SaveImageFBO->destroy();
00296 delete m_SaveImageFBO;
00297 m_SaveImageFBO = NULL;
00298 }
00299 else
00300 {
00301 if(!m_FramebufferObject)
00302 {
00303 m_FramebufferObject = new VFramebufferObject(width(), height(), GL_RGBA);
00304 m_FramebufferObject->init();
00305 }
00306
00307
00308
00309 if(data_loaded)
00310 {
00311 if(!m_FlowData.getTexturesGenerated())
00312 {
00313 m_FlowData.generateTextures();
00314
00315 }
00316
00317
00318
00319 m_FramebufferObject->bind();
00320
00321 glDisable(GL_DEPTH_TEST);
00322
00323 m_FlowRenderer.draw( timestep_activated - 1 );
00324
00325 if( lic_activated )
00326 {
00327 m_FlowRenderer.drawLic( timestep_activated - 1 );
00328 }
00329
00330 if( arrows_activated )
00331 {
00332 m_FlowRenderer.drawGlyphes( timestep_activated - 1 );
00333 }
00334 if (streamlines_activated)
00335 {
00336 m_FlowRenderer.drawStreamLines();
00337 }
00338
00339 if( m_EnableIconSetting )
00340 {
00341 m_FlowRenderer.drawIcons();
00342 }
00343
00344 glEnable(GL_DEPTH_TEST);
00345
00346 m_FramebufferObject->unbind();
00347
00348 }
00349
00350
00351 const GLenum glError = glGetError();
00352
00353 if (glError != GL_NO_ERROR)
00354 std::cout << "Error Rendering Scene to FBO " << gluErrorString(glError) << std::endl;
00355
00356 glDisable(GL_CULL_FACE);
00357
00358 m_FramebufferObject->renderToFullScreen();
00359 }
00360
00361 if(data_loaded)
00362 {
00363
00364
00365 }
00366
00367
00368
00369
00370
00371
00372 }
00373
00374 void QVolRendCanvas::paintEvent( QPaintEvent *e )
00375 {
00376 QGLWidget::paintEvent(e);
00377 };
00378
00379 void QVolRendCanvas::mousePressEvent ( QMouseEvent * e )
00380 {
00381
00382 const VMouseEvent me(getMouseEvent(e));
00383
00384 float x = me.getPosition().getX();
00385 float y = me.getPosition().getY();
00386
00387 if(me.getModifiers() == me.MODIFIER_ALT && ( m_EnableSeedpointsSetting || m_EnableEvenSeedpointsSetting || m_EnableIconSetting) )
00388 {
00389 setCursor(QCursor(Qt::CursorShape::CrossCursor));
00390
00391 VMatrix proj = m_FlowRenderer.getCameraProjMatrix();
00392 VMatrix view = m_FlowRenderer.getCameraViewMatrix();
00393
00394 VMatrix iviewproj = ( proj * view).getInverse();
00395
00396
00397 if ( m_EnableSeedpointsSetting )
00398 {
00399
00400 VVector p1 = iviewproj * VVector( x, y, 1.0 );
00401 VVector p2 = iviewproj * VVector( x, y, -1.0 );
00402
00403 m_PanOffset;
00404
00405
00406 float sumz = p2.getZ() - p1.getZ();
00407 VVector pintersect = VVector( p1.getX() * p2.getZ() / sumz + p2.getX() * ( - p1.getZ() / sumz ),
00408 p1.getY() * p2.getZ() / sumz + p2.getY() * ( - p1.getZ() / sumz ),
00409 0.0f );
00410 m_FlowData.addManualSeedpoint( pintersect.getX(), pintersect.getY() );
00411 m_FlowData.drawStreamlinesFromSeedpoints( timestep_activated - 1, mStremSteps );
00412 }
00413 else if( m_EnableIconSetting )
00414 {
00415
00416 VVector p1 = iviewproj * VVector( x, y, 1.0 );
00417 VVector p2 = iviewproj * VVector( x, y, -1.0 );
00418
00419 m_PanOffset;
00420
00421
00422 float sumz = p2.getZ() - p1.getZ();
00423 VVector pintersect = VVector( p1.getX() * p2.getZ() / sumz + p2.getX() * ( - p1.getZ() / sumz ),
00424 p1.getY() * p2.getZ() / sumz + p2.getY() * ( - p1.getZ() / sumz ),
00425 0.0f );
00426 m_FlowData.addIconPoint( pintersect.getX(), pintersect.getY() );
00427 }
00428 else
00429 {
00431
00432
00433
00434
00435
00437
00438
00439
00440
00441
00442
00444
00445 }
00446
00447 }
00448
00449
00450 if(me.getLeftState())
00451 {
00452 m_MouseState = PAN;
00453 m_vecPosition = getPlaneProjection(x,y);
00454
00455 }
00456
00457
00458
00459
00460
00461 else
00462 {
00463 m_MouseState = ZOOM;
00464 m_vecPosition = getPlaneProjection(x,y);
00465 }
00466 if(m_FramebufferObject)
00467 {
00468 delete m_FramebufferObject;
00469 m_FramebufferObject = NULL;
00470
00471 m_FramebufferObject = new VFramebufferObject(256, 256, GL_RGBA);
00472 m_FramebufferObject->init();
00473 }
00474
00475 };
00476
00477 void QVolRendCanvas::mouseReleaseEvent ( QMouseEvent * e )
00478 {
00479 isfirstframe = true;
00480
00481 if ( !m_EnableSeedpointsSetting && ! m_EnableEvenSeedpointsSetting)
00482 {
00483 setCursor(QCursor(Qt::CursorShape::OpenHandCursor));
00484 }
00485 else
00486 {
00487 setCursor(QCursor(Qt::CursorShape::CrossCursor));
00488 }
00489
00490
00491 m_MouseState = NO_DRAGGING;
00492
00493 delete m_FramebufferObject;
00494 m_FramebufferObject = NULL;
00495 m_FramebufferObject = new VFramebufferObject(width(), height(), GL_RGBA);
00496 m_FramebufferObject->init();
00497
00498
00499 };
00500
00501 void QVolRendCanvas::mouseMoveEvent ( QMouseEvent * e )
00502 {
00503
00504
00505 const VMouseEvent me(getMouseEvent(e));
00506
00507 const VVector v = me.getPosition();
00508
00509 if(me.getModifiers() == me.MODIFIER_ALT ) return;
00510
00511 setCursor(QCursor(Qt::CursorShape::ClosedHandCursor));
00512
00513 float x = v.getX();
00514 float y = v.getY();
00515
00516 float ny = 0.0f;
00517 float nx = 0.0f;
00518
00519 switch (m_MouseState)
00520 {
00521
00522 case PAN:
00523 {
00524 const VVector vecPosition = getPlaneProjection(x,y);
00525 const VVector vecDifference = vecPosition - m_vecPosition;
00526
00527 VVector side = -m_FlowRenderer.getCameraSideVector() * vecDifference.getX();
00528 VVector up = -m_FlowRenderer.getCameraUpVector() * vecDifference.getY();
00529
00530 m_PanOffset += side + up;
00531
00532 m_vecPosition = vecPosition;
00533 }
00534 break;
00535
00536 case ZOOM:
00537 {
00538 VVector vecPosition = getPlaneProjection(x,y);
00539 VVector vecDifference = vecPosition - m_vecPosition;
00540
00541 vecDifference.setX(vecDifference.getX());
00542 vecDifference.setY(vecDifference.getY());
00543 vecDifference.setZ(0.0);
00544
00545 float offset = (vecDifference.getY() > 0.0) ? sqrt(vecDifference.getDot(vecDifference)) : -sqrt(vecDifference.getDot(vecDifference));
00546 m_Distance += -offset;
00547
00548 m_vecPosition = vecPosition;
00549 }
00550 break;
00551
00552 }
00553
00554
00555 m_FlowRenderer.processGuiInput(m_Distance, m_Position + m_PanOffset, view, up, m_LookAt + m_PanOffset);
00556
00557
00558
00559 };
00560
00561 void QVolRendCanvas::mouseDoubleClickEvent ( QMouseEvent * e )
00562 {
00563
00564 const VMouseEvent me(getMouseEvent(e));
00565 const VVector v = me.getPosition();
00566
00567
00568
00569
00570 };
00571
00572 void QVolRendCanvas::keyPressEvent ( QKeyEvent * e )
00573 {
00574
00575
00576 };
00577
00578 void QVolRendCanvas::keyReleaseEvent ( QKeyEvent * e )
00579 {
00580
00581
00582 };
00583
00584 const VMouseEvent QVolRendCanvas::getMouseEvent (QMouseEvent *e)
00585 {
00586 const VVector vecPosition( (2.0f * float(e->x()) - float(width())) / float(width()),
00587 ( float(height()) - 2.0f * float(e->y())) / float(height()),
00588 0.0f);
00589 const int iButton =
00590 ((e->button() == Qt::LeftButton) ? VMouseEvent::BUTTON_LEFT :
00591 ((e->button() == Qt::MidButton) ? VMouseEvent::BUTTON_MIDDLE :
00592 ((e->button() == Qt::RightButton) ? VMouseEvent::BUTTON_RIGHT : VMouseEvent::BUTTON_NONE)));
00593
00594 const int iStateLeft = (e->buttons () & Qt::LeftButton) ? VMouseEvent::STATE_DOWN : VMouseEvent::STATE_UP;
00595 const int iStateMiddle = (e->buttons () & Qt::MidButton) ? VMouseEvent::STATE_DOWN : VMouseEvent::STATE_UP;
00596 const int iStateRight = (e->buttons () & Qt::RightButton) ? VMouseEvent::STATE_DOWN : VMouseEvent::STATE_UP;
00597
00598 const int iModifiers = ((e->modifiers() & Qt::ShiftModifier) ? VKeyboardEvent::MODIFIER_SHIFT : 0)
00599 | ((e->modifiers() & Qt::ControlModifier) ? VKeyboardEvent::MODIFIER_CTRL : 0)
00600 | ((e->modifiers() & Qt::AltModifier) ? VKeyboardEvent::MODIFIER_ALT : 0);
00601
00602 return VMouseEvent(vecPosition,iButton,iStateLeft,iStateMiddle,iStateRight,iModifiers);
00603
00604 };
00605
00606 const VKeyboardEvent QVolRendCanvas::getKeyboardEvent (QKeyEvent *e)
00607 {
00608 const int iKey = e->key();
00609
00610 const int iModifiers = ((e->modifiers() & Qt::ShiftModifier) ? VKeyboardEvent::MODIFIER_SHIFT : 0)
00611 | ((e->modifiers() & Qt::ControlModifier) ? VKeyboardEvent::MODIFIER_CTRL : 0)
00612 | ((e->modifiers() & Qt::AltModifier) ? VKeyboardEvent::MODIFIER_ALT : 0);
00613
00614 return VKeyboardEvent(iKey,iModifiers);
00615
00616 };
00617
00618 void QVolRendCanvas::redraw()
00619 {
00620 makeCurrent();
00621 paintGL();
00622 }
00623
00624 bool QVolRendCanvas::load_data(QString filename, int *data)
00625 {
00626 if(data_loaded)
00627 {
00628 m_FlowData = VFlowData();
00629 data_loaded = false;
00630 }
00631
00632 makeCurrent();
00633
00634 std::string tmp(filename.toAscii());
00635
00636 data_loaded = m_FlowData.loadData(tmp);
00637 m_FlowRenderer.setFlowData(&m_FlowData);
00638 if (!data_loaded) return false;
00639
00640 computeGlyphs();
00641
00642
00643
00644 m_PanOffset = m_FlowData.getFlowCenter();
00645 m_Position.setZ(-m_FlowData.getFlowExtends().getMagnitude());
00646 VVector extends = m_FlowData.getFlowExtends();
00647
00648
00649
00650 float halfExdends = (extends.getX() < extends.getY()) ? extends.getY() : extends.getX();
00651 if( halfExdends == extends.getY())
00652 {
00653 halfExdends /= 2.0f;
00654 }
00655 else
00656 {
00657 halfExdends /= 2.0f;
00658 halfExdends /= m_FlowRenderer.getCameraAspect();
00659 }
00660
00661 float fov = m_FlowRenderer.getCameraFOV();
00662 fov /= 2.0f;
00663
00664
00665 m_Distance = halfExdends / tan(fov * 3.14159265f / 180.0f);
00666 m_FlowRenderer.processGuiInput(m_Distance, m_Position + m_PanOffset, view, up, m_LookAt + m_PanOffset);
00667
00668 repaint();
00669 return true;
00670
00671 }
00672
00673 bool QVolRendCanvas::load_single_data(QString filename, QString datfilename)
00674 {
00675 if(data_loaded)
00676 {
00677 m_FlowData = VFlowData();
00678 data_loaded = false;
00679 }
00680
00681 makeCurrent();
00682
00683 std::string tmp(filename.toAscii());
00684 std::string dtmp(datfilename.toAscii());
00685
00686 data_loaded = m_FlowData.loadData(tmp, dtmp);
00687 m_FlowRenderer.setFlowData(&m_FlowData);
00688 if (!data_loaded) return false;
00689
00690 computeGlyphs();
00691
00692
00693
00694 m_PanOffset = m_FlowData.getFlowCenter();
00695 m_Position.setZ(-m_FlowData.getFlowExtends().getMagnitude());
00696 VVector extends = m_FlowData.getFlowExtends();
00697
00698
00699
00700 float halfExdends = (extends.getX() < extends.getY()) ? extends.getY() : extends.getX();
00701 if( halfExdends == extends.getY())
00702 {
00703 halfExdends /= 2.0f;
00704 }
00705 else
00706 {
00707 halfExdends /= 2.0f;
00708 halfExdends /= m_FlowRenderer.getCameraAspect();
00709 }
00710
00711 float fov = m_FlowRenderer.getCameraFOV();
00712 fov /= 2.0f;
00713
00714
00715 m_Distance = halfExdends / tan(fov * 3.14159265f / 180.0f);
00716 m_FlowRenderer.processGuiInput(m_Distance, m_Position + m_PanOffset, view, up, m_LookAt + m_PanOffset);
00717
00718 repaint();
00719 return true;
00720 }
00721
00722 bool QVolRendCanvas::save_data(std::string filename)
00723 {
00724 return false;
00725 }
00726
00727 void QVolRendCanvas::setOrthoProjection(bool m_orth)
00728 {
00729
00730 }
00731
00732 void QVolRendCanvas::setArrowTransferFunctionPtr(VTransferFunction *transfunc)
00733 {
00734 m_ArrowTransferFunction = transfunc;
00735 m_ArrowTransferFunction->setMainCanvas(this);
00736 }
00737
00738 void QVolRendCanvas::setStreamLineTransferFunctionPtr(VTransferFunction *transfunc)
00739 {
00740 m_StreamLineTransferFunction = transfunc;
00741 m_StreamLineTransferFunction->setMainCanvas(this);
00742 }
00743
00744 void QVolRendCanvas::setLicTransferFunctionPtr(VTransferFunction *transfunc)
00745 {
00746 m_LicTransferFunction = transfunc;
00747 m_LicTransferFunction->setMainCanvas(this);
00748 }
00749
00750 void QVolRendCanvas::setTransferFunctionPtr(VTransferFunction *transfunc)
00751 {
00752 m_TransferFunction = transfunc;
00753 m_TransferFunction->setMainCanvas(this);
00754 }
00755
00756 void QVolRendCanvas::setArrowTF(bool val)
00757 {
00758 m_FlowRenderer.enableArrowTF(val);
00759 }
00760
00761 void QVolRendCanvas::setLicTF(bool val)
00762 {
00763 m_FlowRenderer.enableLicTF(val);
00764 }
00765
00766 void QVolRendCanvas::animateLic(bool val)
00767 {
00768 m_FlowRenderer.animateLic(val);
00769 }
00770
00771 void QVolRendCanvas::setStrTF(bool val)
00772 {
00773 m_FlowRenderer.enableStrTF(val);
00774 }
00775
00776 void QVolRendCanvas::saveImage(std::string filename)
00777 {
00778 makeCurrent();
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791 if(data_loaded)
00792 {
00793 m_FramebufferObject->saveImage(filename);
00794 }
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807 std::cout << "Saving Image finished" << std::endl;
00808
00809
00810 }
00811
00812 void QVolRendCanvas::saveBigImage(std::string filename)
00813 {
00814 if(!m_SaveImageFBO)
00815 {
00816 m_SaveImageFBO = new VFramebufferObject(3000, 3000, GL_RGBA);
00817 m_SaveImageFBO->init();
00818 }
00819 m_SaveImageFBO->bind();
00820 m_SaveImageFBO->unbind();
00821
00822 m_IsSaving = true;
00823 m_SaveFileName = filename;
00824 }
00825
00826
00827 void QVolRendCanvas::saveStreamLines(std::string filename)
00828 {
00829 if( data_loaded )
00830 {
00831 m_FlowData.saveStreamLines( filename );
00832 }
00833 }
00834
00835 void QVolRendCanvas::loadStreamLines(std::string filename)
00836 {
00837 if( data_loaded )
00838 {
00839 m_FlowData.loadStreamLines( filename );
00840 }
00841 }
00842
00843 void QVolRendCanvas::arrowscale_valuechanged(int val)
00844 {
00845 mArrowSize = (float)val / 100.0f;
00846 computeGlyphs();
00847 }
00848
00849 void QVolRendCanvas::iconscale_valuechanged(int val)
00850 {
00851 m_FlowData.setIconScale(val);
00852 }
00853
00854 void QVolRendCanvas::icontail_valuechanged(int val)
00855 {
00856 m_FlowData.setTailLength(val);
00857 }
00858
00859 void QVolRendCanvas::arrowspacing_valuechanged(int val)
00860 {
00861 mArrowSpacing = (float)val / 1000.0f;
00862 computeGlyphs();
00863 }
00864
00865 void QVolRendCanvas::arrowalpha_changed_event(float val)
00866 {
00867 m_FlowRenderer.setArrowAlpha(val);
00868 }
00869
00870 void QVolRendCanvas::salpha_changed_event(float val)
00871 {
00872 m_FlowRenderer.setStreamLineAlpha(val);
00873 }
00874
00875 void QVolRendCanvas::licalpha_changed_event(float val)
00876 {
00877 m_FlowRenderer.setLicAlpha(val);
00878 }
00879
00880 void QVolRendCanvas::licsteps_changed_event(int val)
00881 {
00882 m_FlowRenderer.setLicSteps(val);
00883 }
00884
00885 void QVolRendCanvas::licstepsize_changed_event(int val)
00886 {
00887 m_FlowRenderer.setLicStepSize(val);
00888 }
00889
00890
00891
00892 void QVolRendCanvas::dsep_valuechanged(int val)
00893 {
00894 mStreamSeedSpacing = (float)val/ 100.0f;
00895
00896
00897 m_FlowData.setStreamlinesSeedSeparation( mStreamSeedSpacing );
00898
00899
00900 }
00901
00902 void QVolRendCanvas::dtest_valuechanged(int val)
00903 {
00904 mStreamTestSpacing = (float)val/ 100.0f;
00905
00906
00907 m_FlowData.setStreamlinesTestSeparation( mStreamTestSpacing );
00908
00909
00910 }
00911
00912 void QVolRendCanvas::steps_valuechanged(int val)
00913 {
00914 mStremSteps = (float)val / 100.0f;
00915
00916
00917 m_FlowData.setStreamlinesSteps( mStremSteps );
00918
00919
00920 }
00921
00922 void QVolRendCanvas::dt_valuechanged(int val)
00923 {
00924 mStreamDT = (float)val/ 100.0f;
00925
00926
00927 m_FlowData.setStreamlinesDt( mStreamDT );
00928
00929 }
00930
00931 void QVolRendCanvas::setGlyph( bool val )
00932 {
00933 m_FlowRenderer.setGlyph(val);
00934 }
00935
00936 void QVolRendCanvas::computeGlyphs()
00937 {
00938 if(!data_loaded)
00939 {
00940 return;
00941 }
00942 VVector extends = m_FlowData.getExtends();
00943
00944 float smallestSize;
00945 if(extends.getX() < extends.getY())
00946 {
00947 smallestSize = extends.getX();
00948 }
00949 else
00950 {
00951 smallestSize = extends.getY();
00952 }
00953
00954 float minGlyphSize = smallestSize / 10.0f;
00955
00956 float glyphSize = minGlyphSize + mArrowSize * (smallestSize - minGlyphSize);
00957 float glyphSpacing = 0.0f + mArrowSpacing * glyphSize;
00958
00959 float factorX = (extends.getX() < 1.0f) ? (1.0f / extends.getX()) : extends.getX();
00960 float factorY = (extends.getY() < 1.0f) ? (1.0f / extends.getY()) : extends.getY();
00961
00962 float numGlyphX = ((extends.getX() - glyphSpacing) / (glyphSize + glyphSpacing)) * factorX;
00963 float numGlyphY = ((extends.getY() - glyphSpacing) / (glyphSize + glyphSpacing)) * factorY;
00964
00965 m_FlowData.generateGlyphIndices((int)round(numGlyphX + 0.5f, 0), (int)round((numGlyphY + 0.5f),0));
00966 m_FlowRenderer.setBasicGlyphSize(glyphSize);
00967 }