示例#1
0
QT_BEGIN_NAMESPACE

QGLFormat QGLFormat::fromPlatformWindowFormat(const QPlatformWindowFormat &format)
{
    QGLFormat retFormat;
    retFormat.setAccum(format.accum());
    if (format.accumBufferSize() >= 0)
        retFormat.setAccumBufferSize(format.accumBufferSize());
    retFormat.setAlpha(format.alpha());
    if (format.alphaBufferSize() >= 0)
        retFormat.setAlphaBufferSize(format.alphaBufferSize());
    if (format.blueBufferSize() >= 0)
        retFormat.setBlueBufferSize(format.blueBufferSize());
    retFormat.setDepth(format.depth());
    if (format.depthBufferSize() >= 0)
        retFormat.setDepthBufferSize(format.depthBufferSize());
    retFormat.setDirectRendering(format.directRendering());
    retFormat.setDoubleBuffer(format.doubleBuffer());
    if (format.greenBufferSize() >= 0)
        retFormat.setGreenBufferSize(format.greenBufferSize());
    if (format.redBufferSize() >= 0)
        retFormat.setRedBufferSize(format.redBufferSize());
    retFormat.setRgba(format.rgba());
    retFormat.setSampleBuffers(format.sampleBuffers());
    retFormat.setSamples(format.sampleBuffers());
    retFormat.setStencil(format.stencil());
    if (format.stencilBufferSize() >= 0)
        retFormat.setStencilBufferSize(format.stencilBufferSize());
    retFormat.setStereo(format.stereo());
    retFormat.setSwapInterval(format.swapInterval());
    return retFormat;
}
示例#2
0
/*===========================================================================*/
void ScreenBase::create()
{
    KVS_ASSERT( m_id == -1 );

    // Initialize display mode.
    QGLFormat f = QGLFormat::defaultFormat();
    f.setDoubleBuffer( displayFormat().doubleBuffer() );
    f.setRgba( displayFormat().colorBuffer() );
    f.setDepth( displayFormat().depthBuffer() );
    f.setAccum( displayFormat().accumulationBuffer() );
    f.setStencil( displayFormat().stencilBuffer() );
    f.setStereo( displayFormat().stereoBuffer() );
    f.setSampleBuffers( displayFormat().multisampleBuffer() );
    f.setAlpha( displayFormat().alphaChannel() );
    QGLFormat::setDefaultFormat( f );

    // Set screen geometry.
    QWidget::setGeometry( BaseClass::x(), BaseClass::y(), BaseClass::width(), BaseClass::height() );

    QGLWidget::makeCurrent();

    // Initialize GLEW.
    GLenum result = glewInit();
    if ( result != GLEW_OK )
    {
        const GLubyte* message = glewGetErrorString( result );
        kvsMessageError( "GLEW initialization failed: %s.", message );
    }

    // Create window.
    static int counter = 0;
    m_id = counter++;
}
示例#3
0
文件: glformat.cpp 项目: hpicgs/cgsee
const QGLFormat GLFormat::asQGLFormat() const
{
    QGLFormat format;

    format.setVersion(m_majorVersion, m_minorVersion);
    
    switch(m_profile)
    {
    default:
    case NoProfile:
        format.setProfile(QGLFormat::NoProfile); 
        break;
    case CoreProfile:
        format.setProfile(QGLFormat::CoreProfile); 
        break;
    case CompatibilityProfile:
        format.setProfile(QGLFormat::CompatibilityProfile); 
        break;
    };

    format.setRedBufferSize    (m_redBufferSize);
    format.setGreenBufferSize  (m_greenBufferSize);
    format.setBlueBufferSize   (m_blueBufferSize);
    format.setAlphaBufferSize  (m_alphaBufferSize);

    format.setDepthBufferSize  (m_depthBufferSize);
    format.setStencilBufferSize(m_stencilBufferSize);
    format.setDoubleBuffer     (m_doubleBuffer);
    format.setStereo           (m_stereo);
    format.setSampleBuffers    (m_sampleBuffers);
    format.setSamples          (m_samples);
    format.setSwapInterval     (m_swapInterval);

    return format;
}
示例#4
0
QT_BEGIN_NAMESPACE

/*!
    Returns an OpenGL format for the window format specified by \a format.
*/
QGLFormat QGLFormat::fromSurfaceFormat(const QSurfaceFormat &format)
{
    QGLFormat retFormat;
    if (format.alphaBufferSize() >= 0)
        retFormat.setAlphaBufferSize(format.alphaBufferSize());
    if (format.blueBufferSize() >= 0)
        retFormat.setBlueBufferSize(format.blueBufferSize());
    if (format.greenBufferSize() >= 0)
        retFormat.setGreenBufferSize(format.greenBufferSize());
    if (format.redBufferSize() >= 0)
        retFormat.setRedBufferSize(format.redBufferSize());
    if (format.depthBufferSize() >= 0)
        retFormat.setDepthBufferSize(format.depthBufferSize());
    if (format.samples() > 1) {
        retFormat.setSampleBuffers(format.samples());
        retFormat.setSamples(true);
    }
    if (format.stencilBufferSize() > 0) {
        retFormat.setStencil(true);
        retFormat.setStencilBufferSize(format.stencilBufferSize());
    }
    retFormat.setDoubleBuffer(format.swapBehavior() != QSurfaceFormat::SingleBuffer);
    retFormat.setStereo(format.stereo());
    return retFormat;
}
示例#5
0
int main(int argc, char** argv)
{
  char *flnm;

  QApplication application(argc,argv);
  
  QGLFormat glFormat;
  glFormat.setSampleBuffers(true);
  glFormat.setDoubleBuffer(true);
  glFormat.setRgba(true);
  glFormat.setAlpha(true);

//  //-----------------------------
//  // did not work - still getting 8bit buffers
//  glFormat.setAlphaBufferSize(16);
//  glFormat.setRedBufferSize(16);
//  glFormat.setGreenBufferSize(16);
//  glFormat.setBlueBufferSize(16);
//  //-----------------------------

  flnm = argv[1];
  if (QString::compare(argv[1], "-stereo", Qt::CaseInsensitive) == 0)
    {
      flnm = argv[2];
      glFormat.setStereo(true);
    }
  QGLFormat::setDefaultFormat(glFormat);

  MainWindow mainwindow;
  mainwindow.show();
  
  // Run main loop.
  return application.exec();
}
示例#6
0
bool video_output_qt::supports_stereo() const
{
    QGLFormat fmt = _format;
    fmt.setStereo(true);
    QGLWidget *tmpwidget = new QGLWidget(fmt);
    bool ret = tmpwidget->format().stereo();
    delete tmpwidget;
    return ret;
}
示例#7
0
void *QGLContext::chooseVisual()
{
    static int bufDepths[] = { 8, 4, 2, 1 };	// Try 16, 12 also?
    //todo: if pixmap, also make sure that vi->depth == pixmap->depth
    void* vis = 0;
    int i = 0;
    bool fail = FALSE;
    QGLFormat fmt = format();
    bool tryDouble = !fmt.doubleBuffer();  // Some GL impl's only have double
    bool triedDouble = FALSE;
    while( !fail && !( vis = tryVisual( fmt, bufDepths[i] ) ) ) {
	if ( !fmt.rgba() && bufDepths[i] > 1 ) {
	    i++;
	    continue;
	}
	if ( tryDouble ) {
	    fmt.setDoubleBuffer( TRUE );
	    tryDouble = FALSE;
	    triedDouble = TRUE;
	    continue;
	}
	else if ( triedDouble ) {
	    fmt.setDoubleBuffer( FALSE );
	    triedDouble = FALSE;
	}
	if ( fmt.stereo() ) {
	    fmt.setStereo( FALSE );
	    continue;
	}
	if ( fmt.accum() ) {
	    fmt.setAccum( FALSE );
	    continue;
	}
	if ( fmt.stencil() ) {
	    fmt.setStencil( FALSE );
	    continue;
	}
	if ( fmt.alpha() ) {
	    fmt.setAlpha( FALSE );
	    continue;
	}
	if ( fmt.depth() ) {
	    fmt.setDepth( FALSE );
	    continue;
	}
	if ( fmt.doubleBuffer() ) {
	    fmt.setDoubleBuffer( FALSE );
	    continue;
	}
	fail = TRUE;
    }
    glFormat = fmt;
    return vis;
}
QGLFormat QtCanvas::getQGLFormat(const Buffers buffers) {
    QGLFormat format = QGLFormat();
    format.setAlpha(buffers & GLCanvas::ALPHA_BUFFER);
    format.setDepth(buffers & GLCanvas::DEPTH_BUFFER);
    format.setDoubleBuffer(buffers & GLCanvas::DOUBLE_BUFFER);
    format.setStencil(buffers & GLCanvas::STENCIL_BUFFER);
    format.setAccum(buffers & GLCanvas::ACCUM_BUFFER);
    format.setStereo(buffers & GLCanvas::STEREO_VIEWING);
    format.setSampleBuffers(buffers & GLCanvas::MULTISAMPLING);

    return format;
}
示例#9
0
int main(int argc, char** argv)
{
  QApplication application(argc,argv);

  // Set the default OpenGL format with stereo capabilities.
  // An alternative is to pass this parameter to the QGLWidget constructor.
  QGLFormat format;
  format.setStereo(true);
  QGLFormat::setDefaultFormat(format);

  Viewer viewer;

  viewer.setWindowTitle("stereoViewer");

  viewer.show();

  return application.exec();
}
示例#10
0
// Updates "format" with the parameters of the selected configuration.
void qt_glformat_from_eglconfig(QGLFormat& format, const EGLConfig config)
{
    EGLint redSize     = 0;
    EGLint greenSize   = 0;
    EGLint blueSize    = 0;
    EGLint alphaSize   = 0;
    EGLint depthSize   = 0;
    EGLint stencilSize = 0;
    EGLint sampleCount = 0;
    EGLint level       = 0;

    EGLDisplay display = QEgl::display();
    eglGetConfigAttrib(display, config, EGL_RED_SIZE,     &redSize);
    eglGetConfigAttrib(display, config, EGL_GREEN_SIZE,   &greenSize);
    eglGetConfigAttrib(display, config, EGL_BLUE_SIZE,    &blueSize);
    eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE,   &alphaSize);
    eglGetConfigAttrib(display, config, EGL_DEPTH_SIZE,   &depthSize);
    eglGetConfigAttrib(display, config, EGL_STENCIL_SIZE, &stencilSize);
    eglGetConfigAttrib(display, config, EGL_SAMPLES,      &sampleCount);
    eglGetConfigAttrib(display, config, EGL_LEVEL,        &level);

    format.setRedBufferSize(redSize);
    format.setGreenBufferSize(greenSize);
    format.setBlueBufferSize(blueSize);
    format.setAlphaBufferSize(alphaSize);
    format.setDepthBufferSize(depthSize);
    format.setStencilBufferSize(stencilSize);
    format.setSamples(sampleCount);
    format.setPlane(level);
    format.setDirectRendering(true); // All EGL contexts are direct-rendered
    format.setRgba(true);            // EGL doesn't support colour index rendering
    format.setStereo(false);         // EGL doesn't support stereo buffers
    format.setAccumBufferSize(0);    // EGL doesn't support accululation buffers
    format.setDoubleBuffer(true);    // We don't support single buffered EGL contexts

    // Clear the EGL error state because some of the above may
    // have errored out because the attribute is not applicable
    // to the surface type.  Such errors don't matter.
    eglGetError();
}
示例#11
0
Scene :: Scene( Game* const apNewGame, QWidget* apPwgt ) : QGLWidget( apPwgt )
{
    QGLFormat fmt;

    mpGame = apNewGame;
    setMouseTracking( false  );
    for ( int i = 0; i < 4; i++	    )
    {
	mAmbientLight[ i ] = 0.0f;
        mDiffuseLight[ i ] = 0.0f;
	mSpecularLight[ i ] = 0.0f;
    }

    mWidth  = STANDART_SCENE_WIDTH;
    mHeight = STANDART_SCENE_HEIGHT;

    mCameraPosition = SphericalCoor( Geometry :: pi / 4, Geometry :: pi / 8 );
    GetCameraPosition();
    SetViewVectors();

    mRatio              = HEIGHT_RATIO / ( float )WIDTH_RATIO;
    mFrustumAperture    = 45.0f / 180.0f * Geometry :: pi;
    mFrustumNearPlane	= 60;
    mFrustumFarPlane	= 1000;
    mFrustumHalfWidth   = mFrustumNearPlane * tan( mFrustumAperture );
    mFrustumFocalLength = (mFrustumFarPlane + mFrustumNearPlane) * 0.8f;
    mFrustumEyeSep      = mFrustumFocalLength / 30.0f;
    mShowHelp           = true;
    mIsStereo           = false;

    fmt.setStereo( true );
    setFormat( fmt );

    for ( int i = 0; i < RENDER_MESSAGES_CNT; i++ )
        mRenderMessages[ i ] = Game :: EMPTY;

}
示例#12
0
    void GridsPlugin::initDockWidget()
    {
        // create and add doc widget
        _dock_widget = new QDockWidget(QObject::tr("Grid Viewer"));
        _dock_widget->setAllowedAreas(Qt::RightDockWidgetArea);
        _dock_widget->setObjectName("gridViewerDock");

        QGLFormat format;
        format.setVersion(2, 1);
        format.setDoubleBuffer(true);
        format.setDepth(true);
        format.setRgba(true);
        format.setAlpha(false);
        format.setAccum(false);
        format.setStencil(false);
        format.setStereo(false);
        format.setDirectRendering(true);
        format.setOverlay(false);

        _viewer = new GridViewer(format);
        _viewer->setMinimumSize(250, 0);
        _viewer->setObjectName("gridViewer");

        QVBoxLayout *layout = new QVBoxLayout();
        layout->addWidget(_viewer);

        QWidget *widget = new QWidget();
        widget->setLayout(layout);

        _dock_widget->setWidget(widget);

        NeuroGui::MainWindow::instance()->addDockWidget(Qt::RightDockWidgetArea, _dock_widget);

        // add to view menu
        NeuroGui::MainWindow::instance()->toolBarsMenu()->addAction(_dock_widget->toggleViewAction());
    }
示例#13
0
QGLGraphicsSystem::QGLGraphicsSystem(bool useX11GL)
    : QGraphicsSystem(), m_useX11GL(useX11GL)
{
#if defined(Q_WS_X11) && !defined(QT_OPENGL_ES)
    // only override the system defaults if the user hasn't already
    // picked a visual
    if (X11->visual == 0 && X11->visual_id == -1 && X11->visual_class == -1) {
        // find a double buffered, RGBA visual that supports OpenGL
        // and set that as the default visual for windows in Qt
        int i = 0;
        int spec[16];
        spec[i++] = GLX_RGBA;
        spec[i++] = GLX_DOUBLEBUFFER;

        if (!qgetenv("QT_GL_SWAPBUFFER_PRESERVE").isNull()) {
            spec[i++] = GLX_DEPTH_SIZE;
            spec[i++] = 8;
            spec[i++] = GLX_STENCIL_SIZE;
            spec[i++] = 8;
            spec[i++] = GLX_SAMPLE_BUFFERS_ARB;
            spec[i++] = 1;
            spec[i++] = GLX_SAMPLES_ARB;
            spec[i++] = 4;
        }

        spec[i++] = XNone;

        XVisualInfo *vi = glXChooseVisual(X11->display, X11->defaultScreen, spec);
        if (vi) {
            X11->visual_id = vi->visualid;
            X11->visual_class = vi->c_class;

            QGLFormat format;
            int res;
            glXGetConfig(X11->display, vi, GLX_LEVEL, &res);
            format.setPlane(res);
            glXGetConfig(X11->display, vi, GLX_DOUBLEBUFFER, &res);
            format.setDoubleBuffer(res);
            glXGetConfig(X11->display, vi, GLX_DEPTH_SIZE, &res);
            format.setDepth(res);
            if (format.depth())
                format.setDepthBufferSize(res);
            glXGetConfig(X11->display, vi, GLX_RGBA, &res);
            format.setRgba(res);
            glXGetConfig(X11->display, vi, GLX_RED_SIZE, &res);
            format.setRedBufferSize(res);
            glXGetConfig(X11->display, vi, GLX_GREEN_SIZE, &res);
            format.setGreenBufferSize(res);
            glXGetConfig(X11->display, vi, GLX_BLUE_SIZE, &res);
            format.setBlueBufferSize(res);
            glXGetConfig(X11->display, vi, GLX_ALPHA_SIZE, &res);
            format.setAlpha(res);
            if (format.alpha())
                format.setAlphaBufferSize(res);
            glXGetConfig(X11->display, vi, GLX_ACCUM_RED_SIZE, &res);
            format.setAccum(res);
            if (format.accum())
                format.setAccumBufferSize(res);
            glXGetConfig(X11->display, vi, GLX_STENCIL_SIZE, &res);
            format.setStencil(res);
            if (format.stencil())
                format.setStencilBufferSize(res);
            glXGetConfig(X11->display, vi, GLX_STEREO, &res);
            format.setStereo(res);
            glXGetConfig(X11->display, vi, GLX_SAMPLE_BUFFERS_ARB, &res);
            format.setSampleBuffers(res);
            if (format.sampleBuffers()) {
                glXGetConfig(X11->display, vi, GLX_SAMPLES_ARB, &res);
                format.setSamples(res);
            }

            QGLWindowSurface::surfaceFormat = format;
            XFree(vi);

            printf("using visual class %x, id %x\n", X11->visual_class, X11->visual_id);
        }
    }
#elif defined(Q_WS_WIN)
    QGLWindowSurface::surfaceFormat.setDoubleBuffer(true);

    qt_win_owndc_required = true;
#endif
}
示例#14
0
/*
  See qgl.cpp for qdoc comment.
 */
void *QGLContext::chooseVisual()
{
    Q_D(QGLContext);
    static const int bufDepths[] = { 8, 4, 2, 1 };        // Try 16, 12 also?
    //todo: if pixmap, also make sure that vi->depth == pixmap->depth
    void* vis = 0;
    int i = 0;
    bool fail = false;
    QGLFormat fmt = format();
    bool tryDouble = !fmt.doubleBuffer();  // Some GL impl's only have double
    bool triedDouble = false;
    bool triedSample = false;
    if (fmt.sampleBuffers())
        fmt.setSampleBuffers(QGLExtensions::glExtensions & QGLExtensions::SampleBuffers);
    while(!fail && !(vis = tryVisual(fmt, bufDepths[i]))) {
        if (!fmt.rgba() && bufDepths[i] > 1) {
            i++;
            continue;
        }
        if (tryDouble) {
            fmt.setDoubleBuffer(true);
            tryDouble = false;
            triedDouble = true;
            continue;
        } else if (triedDouble) {
            fmt.setDoubleBuffer(false);
            triedDouble = false;
        }
        if (!triedSample && fmt.sampleBuffers()) {
            fmt.setSampleBuffers(false);
            triedSample = true;
            continue;
        }
        if (fmt.stereo()) {
            fmt.setStereo(false);
            continue;
        }
        if (fmt.accum()) {
            fmt.setAccum(false);
            continue;
        }
        if (fmt.stencil()) {
            fmt.setStencil(false);
            continue;
        }
        if (fmt.alpha()) {
            fmt.setAlpha(false);
            continue;
        }
        if (fmt.depth()) {
            fmt.setDepth(false);
            continue;
        }
        if (fmt.doubleBuffer()) {
            fmt.setDoubleBuffer(false);
            continue;
        }
        fail = true;
    }
    d->glFormat = fmt;
    return vis;
}
示例#15
0
//Create a CGLWin widget
CGLWin::CGLWin(void):
	QMainWindow( 0, "View3D", WDestructiveClose), 
	m_pListViews(NULL)
{
	int i;

	// Data members;
	CGLDrawParms tDraw;
	_drawParms = tDraw;

	m_nTimeDelay = 0;

	for (i=0; i<VIEW3D_MAX_OBJ_COUNT; i++) _pCia3dObjs[i] = NULL;

	// setup printer
	m_pPrinter = new QPrinter;

	// GUI members, create a toolbar;
	m_pToolBar = _createToolBar();		

    // populate a menu with all actions
	m_pMenuBar = menuBar();
	assert(m_pMenuBar!=NULL);

	//====================File options ==========================
	{
		QPopupMenu * file = new QPopupMenu( this );
		menuBar()->insertItem( "&File  ", file );
		_fileNewAction->addTo( file );
		_fileOpenAction->addTo( file );
		_fileSaveAction->addTo( file );
		file->insertSeparator();
		file->insertItem( "Open Background", this,  SLOT(openBackgroundImage()), NULL);
		file->insertItem( "Load Camera", this,  SLOT(loadCamera()), NULL);
		file->insertItem( "Save Camera", this,  SLOT(saveCamera()), NULL);
		file->insertSeparator();	//===========================
		file->insertItem( "Export Povray", this,  SLOT(exportPovray()), NULL);
		file->insertItem( "Export STL", this,  SLOT(saveSTLFile()), NULL);
		file->insertItem( "Export TXT", this,  SLOT(saveTXTFile()), NULL);
		file->insertItem( "Export EPS", this,  SLOT(exportEps()), NULL);
	    file->insertSeparator();	//===========================
		_filePrintAction->addTo( file );
	    file->insertSeparator();	//===========================
		file->insertItem( "E&xit", qApp,  SLOT(closeAllWindows()), NULL);
	}


	//================ Tools Options ================================
	{
		QPopupMenu * pMenuTools = new QPopupMenu( this );
		menuBar()->insertItem( "&Tools", pMenuTools );
		pMenuTools->insertItem( "Show Entire Scene", this,  SLOT(show_entirescene()));
		pMenuTools->insertItem( "Dupe Current Object", this,  SLOT(dupe_currentobj()));
		pMenuTools->insertItem( "Dupe Current Object N", this,  SLOT(dupe_currentobjN()));

		{// Animation options
			pMenuTools->insertSeparator();	//=======================
			QPopupMenu * pAnimOption = new QPopupMenu( this );
			pMenuTools->insertItem( "&Prepare Animation", pAnimOption);
			pAnimOption->insertItem( "Setup", this,  SLOT(create_animation()));

		    QAction* startAction = new QAction(QPixmap(play_xpm), "&Start Animation", Qt::Key_F10, this);
			connect(startAction, SIGNAL(activated()), this, SLOT(startAnimation()));
		    startAction->addTo( pAnimOption );

			pAnimOption->insertItem( "Stop Animation", this,  SLOT(stopAnimation()), Qt::Key_F11);
			pAnimOption->insertItem( "Change Delay Time", this,  SLOT(editDelayTime()));

			{//toggle fast draw mode
				m_pActRepeatPlay = new QAction("Repeat", CTRL+Key_T, this);
				connect(m_pActRepeatPlay, SIGNAL(activated()), this, SLOT(toggleRepeatPlay()));
				m_pActRepeatPlay->setToggleAction(true);
				m_pActRepeatPlay->setOn(false);
				m_pActRepeatPlay->addTo( pAnimOption );
			}
		}
		pMenuTools->insertSeparator();	//=======================
		{// Stereo options
			QPopupMenu * pStereoOption = new QPopupMenu( this );
			pMenuTools->insertItem( "&Stereo", pStereoOption);

			QAction* m_pActToggleStereo = new QAction("Stereo Mode", Qt::Key_F12, this);
			connect(m_pActToggleStereo, SIGNAL(activated()), this, SLOT(toggleStereo()));
			m_pActToggleStereo->setToggleAction(true);
			m_pActToggleStereo->setOn(false);
			m_pActToggleStereo->addTo( pStereoOption );

			pStereoOption->insertItem( "Increase Eye Distance", this,  SLOT(incEyeDistance()), Qt::Key_Plus);
			pStereoOption->insertItem( "Decrease Eye Distance", this,  SLOT(decEyeDistance()), Qt::Key_Minus);
		}

		//pMenuTools->insertItem( "Rotation Axis", this,  SLOT(InputRotationAxis()), NULL);
		//pMenuTools->insertItem( "Mirror Plane", this,  SLOT(InputMirrorPlane()), NULL);
		//pMenuTools->insertSeparator();
		//pMenuTools->insertItem( "Vector Hidden Line Removal", this,  SLOT(hidden_line()), CTRL+Key_H);
		//pMenuTools->insertSeparator();	//=======================

		pMenuTools->insertSeparator();	//=======================
		pMenuTools->insertItem( "Set Mirror Plane", this,  SLOT(InputMirrorPlane()));
		pMenuTools->insertItem( "Set Rotation Axis", this,  SLOT(InputRotationAxis()));
	}

	//================ Rendering options ================================
	{
		QPopupMenu * pMenuOption = new QPopupMenu( this );
		menuBar()->insertItem( "&Options", pMenuOption );
		pMenuOption->insertItem( "Global Setting", this,  SLOT(OptionGlobalSetting()));
		pMenuOption->insertItem( "Surface Rendering", this,  SLOT(OptionRendering()));
		pMenuOption->insertItem( "Volume Rendering", this,  SLOT(OptionVolumeRendering()));
		pMenuOption->insertSeparator();	//=======================
		{
			QPopupMenu * pPickOption = new QPopupMenu( this );
			pMenuOption->insertItem( "&Picking Types", pPickOption);
			pPickOption->insertItem( "Pick an Object", this,  SLOT(set_obj_picking()));
			pPickOption->insertItem( "Pick a Polygon", this,  SLOT(set_face_picking()));
			pPickOption->insertItem( "Pick a Line", this,  SLOT(set_line_picking()));
		}

		QAction* act_mirroring = new QAction("Mirroring", 0, this);
		connect( act_mirroring, SIGNAL(activated()), this, SLOT(OptionMirroring()));
		act_mirroring->setToggleAction(true);
		act_mirroring->setOn(false);
		act_mirroring->addTo( pMenuOption );
		m_pMirroringAction = act_mirroring;

		QPopupMenu * pRotOption = new QPopupMenu( this );
		pMenuOption->insertItem( "&Rotation Types", pRotOption);
		QAction* act_rot0obj = new QAction("Rotate 90 Degree", 0, this);
		connect( act_rot0obj, SIGNAL(activated()), this, SLOT(OptionRotate90()));
		act_rot0obj->addTo( pRotOption );
		QAction* act_rot1obj = new QAction("Rotate 180 Degree", 0, this);
		connect( act_rot1obj, SIGNAL(activated()), this, SLOT(OptionRotate180()));
		act_rot1obj->addTo( pRotOption );
		QAction* act_rot2obj = new QAction("Rotate 270 Degree", 0, this);
		connect( act_rot2obj, SIGNAL(activated()), this, SLOT(OptionRotate270()));
		act_rot2obj->addTo( pRotOption );
		m_pRot90Action = act_rot0obj;
		m_pRot180Action = act_rot1obj;
		m_pRot270Action = act_rot2obj;
		m_pRot90Action->setToggleAction(true);
		m_pRot90Action->setOn(false);
		m_pRot180Action->setToggleAction(true);
		m_pRot180Action->setOn(false);
		m_pRot270Action->setToggleAction(true);
		m_pRot270Action->setOn(false);

		//show background image buttion
		QAction* act_showbgimg = new QAction("Background Image", 0, this);
		connect( act_showbgimg, SIGNAL(activated()), this, SLOT(ShowBackgroundImage()));
		act_showbgimg->setToggleAction(true);
		act_showbgimg->setOn(false);
		act_showbgimg->addTo( pMenuOption );
		m_pBGImageAction = act_showbgimg;

		//show floor plane buttion
		QAction* act_showfloor = new QAction(QString::fromLocal8Bit("Floor Plane"), 0, this);
		connect( act_showfloor, SIGNAL(activated()), this, SLOT(ShowFloor()));
		act_showfloor->setToggleAction(true);
		act_showfloor->setOn(false);
		act_showfloor->addTo( pMenuOption );
		m_pFloorAction = act_showfloor;

		{//Toggle fast draw mode
			m_pActFastDraw = new QAction("Fast Drawing", 0, this);
			connect(m_pActFastDraw, SIGNAL(activated()), this, SLOT(toggleFastDraw()));
			m_pActFastDraw->setToggleAction(true);
			m_pActFastDraw->setOn(false);
			m_pActFastDraw->addTo( pMenuOption );
		}

	}


	//========change opengl window size ==========================
	{
		QPopupMenu * pMenuGLWinsize = new QPopupMenu( this );
		menuBar()->insertItem( "&Window", pMenuGLWinsize );
		pMenuGLWinsize->insertItem( "320x200", this,  SLOT(setGLWinSize320x200()), CTRL+Qt::Key_3);
		pMenuGLWinsize->insertItem( "400x400", this,  SLOT(setGLWinSize400x400()), CTRL+Qt::Key_4);
		pMenuGLWinsize->insertItem( "500x400", this,  SLOT(setGLWinSize500x400()), CTRL+Qt::Key_5);
		pMenuGLWinsize->insertItem( "500x500", this,  SLOT(setGLWinSize500x500()), CTRL+Qt::Key_2 );
		pMenuGLWinsize->insertItem( "640x480", this,  SLOT(setGLWinSize640x480()), CTRL+Qt::Key_6);
		pMenuGLWinsize->insertItem( "800x600", this,  SLOT(setGLWinSize800x600()), CTRL+Qt::Key_8);
		pMenuGLWinsize->insertItem( "1024x768", this,  SLOT(setGLWinSize1024x768()), CTRL+Qt::Key_1);
		pMenuGLWinsize->insertSeparator();
		pMenuGLWinsize->insertItem( "Swap Width/Height", this,  SLOT(swapWidthHeight()), CTRL+Key_W);
		pMenuGLWinsize->insertItem( "Input Width/Height", this,  SLOT(inputWidthHeight()), CTRL+Key_I);
	}


/*
	{
		QPopupMenu * pPopMenu = new QPopupMenu( this );
		menuBar()->insertItem( "&My Research", pPopMenu );
		pPopMenu->insertItem( "Bar Recons", this,  SLOT(detail_recon_bar()));
		pPopMenu->insertItem( "Vase Recons", this,  SLOT(detail_recon_vase()));
		pPopMenu->insertSeparator();
		pPopMenu->insertItem( "Letter Size Plate", this,  SLOT(detail_recon_a4plate()));
		pPopMenu->insertSeparator();
		pPopMenu->insertItem( "Detail Recon Dialog", this,  SLOT(detail_recon_anyobj()));
	} 
*/

	//================ end Rendering options ================================
	QGLFormat format;
	format.setStereo( true );
    m_pGLUIWin = new Viewer(format, this, "Viewer3D"); 
	assert(m_pGLUIWin!=NULL);
    statusBar()->setFixedHeight( fontMetrics().height() + 6 );
    statusBar()->message( "Viewer ready", 3000 );

    setCentralWidget(m_pGLUIWin);
	m_pGLUIWin->setDrawingData(&_drawParms);
	m_pGLUIWin->m_SceneGraph.hookObject(m_pGLUIWin);
	m_pGLUIWin->m_SceneGraph.hookGLWindow(m_pGLUIWin);

	//================ dock window==================
	QString appDir;
    m_pFemBar=_createDockWidgetBar(this, appDir);

}
示例#16
0
MainWindow::MainWindow()
{
    fullScreen_ = false;

    // Set Title and window properties
    setWindowTitle(tr("Examinationroom"));
    QMainWindow::setDockOptions(AnimatedDocks | AllowNestedDocks | AllowTabbedDocks);

    // Add Dock Widgets
    dockDesign_ = new DesignWidget("Design", this);
    dockCode_ = new CodeWidget("Code", this);
    dockConsole_ = new ConsoleWidget("Console", this);
    dockDesign_->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
    dockCode_->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
    dockConsole_->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
    addDockWidget(Qt::RightDockWidgetArea, dockDesign_);
    addDockWidget(Qt::RightDockWidgetArea, dockCode_);
    addDockWidget(Qt::RightDockWidgetArea, dockConsole_);
    tabifyDockWidget(dockDesign_, dockCode_);
    tabifyDockWidget(dockDesign_, dockConsole_);

    // Set up logging early
    LogTool::initLogFile();
    LogTool::setConsoleWidget(dockConsole_);

    // File dialogs
#ifdef Q_WS_MACX
    Qt::WindowFlags dialogFlags = Qt::Sheet;
    QString defaultPath = QString("res/");
#else
    Qt::WindowFlags dialogFlags = Qt::Dialog;
    QString defaultPath = QString("res/");
#endif
    loadDialog_ = new QFileDialog(this, dialogFlags);
    loadDialog_->setFilter("Lua Scene File (*.lua)");
    loadDialog_->setWindowTitle("Open Lua Scene...");
    loadDialog_->setDirectory(defaultPath);
    storeDialog_ = new QFileDialog(this, dialogFlags);
    storeDialog_->setAcceptMode(QFileDialog::AcceptSave);
    storeDialog_->setFilter("Lua Scene File (*.lua)");
    storeDialog_->setWindowTitle("Save Lua Scene...");
    storeDialog_->setDirectory(defaultPath);
    storeDialog_->setDefaultSuffix("lua");
    connect(loadDialog_, SIGNAL(fileSelected(const QString &)), this, SLOT(loadLuaFile(const QString &)));
    connect(storeDialog_, SIGNAL(fileSelected(const QString &)), this, SLOT(storeLuaFile(const QString &)));

    // Create GL Widgets
    QGLFormat glFormat = QGLFormat::defaultFormat();
    // Stereo Buffering seems to work in SnowLeopard...
    // but is incompatible with other renderers and might cause problems.
    // enable at your own risk
    glFormat.setStereo(false);
    glFormat.setSwapInterval(1); // Enable VSync on platforms that support it
    QGLFormat::setDefaultFormat(glFormat);

    // Checking for errors here leads to a crash on OS X
    // Probably because OpenGL was not initialized yet?
    //ErrorTool::getErrors("MainWindow::MainWindow:1");
    mainGlWidget_ = new GLWidget(this);
    fsGlWidget_ = new GLWidget(0, mainGlWidget_);
    fsGlWidget_->setCursor(Qt::BlankCursor);
    mainGlWidget_->setStyle(GLWidget::single);
    fsGlWidget_->setStyle(GLWidget::single);
    mainGlWidget_->makeCurrent();
    GlErrorTool::getErrors("MainWindow::MainWindow:2");
    GlErrorTool::logVersionStrings();

    aboutWindow_ = 0;

    // Add menu
    QMenu *menu = menuBar()->addMenu(tr("&File"));
    menu->addAction(tr("&About Examinationroom..."),
                    this, SLOT(showAbout()));
    menu->addAction(tr("&Open Scene..."),
                    loadDialog_, SLOT(open()),
                    QKeySequence(QKeySequence::Open));
    menu->addAction(tr("Close Scene"),
                    this, SLOT(newScene()),
                    QKeySequence(QKeySequence::Close));
    menu->addAction(tr("&Save Copy As..."),
                    storeDialog_, SLOT(open()),
                    QKeySequence(QKeySequence::Save));
    menu->addAction(tr("&Revert Scene"),
                    this, SLOT(revert()));
    menu->addSeparator();
    menu->addAction(tr("&Quit"), this, SLOT(close()),
                    QKeySequence(tr("ctrl-Q")));

    // Signal mapper for display types
    signalMapper_ = new QSignalMapper(this);

    // Add display menu
    QAction * action;
    menu = menuBar()->addMenu(tr("&Output Mode"));

    action = menu->addAction(tr("&Fullscreen"),
                             this, SLOT(toggleFullscreen()),
                             QKeySequence(Qt::Key_F | Qt::CTRL));
    fsGlWidget_->addAction(action);

    menu->addSeparator();

    action = menu->addAction(tr("&Anaglyph"));
    action->setShortcut(QKeySequence(Qt::Key_1 | Qt::CTRL));
    connect(action, SIGNAL(triggered()), signalMapper_, SLOT(map()));
    signalMapper_->setMapping(action, GLWidget::anaglyph);
    fsGlWidget_->addAction(action);

    action = menu->addAction(tr("&Side by Side"));
    action->setShortcut(QKeySequence(Qt::Key_2 | Qt::CTRL));
    connect(action, SIGNAL(triggered()), signalMapper_, SLOT(map()));
    signalMapper_->setMapping(action, GLWidget::sidebyside);
    fsGlWidget_->addAction(action);

    action = menu->addAction(tr("&Line interlacing (Experimental)"));
    action->setShortcut(QKeySequence(Qt::Key_3 | Qt::CTRL));
    connect(action, SIGNAL(triggered()), signalMapper_, SLOT(map()));
    signalMapper_->setMapping(action, GLWidget::line);
    fsGlWidget_->addAction(action);

    action = menu->addAction(tr("Quad Buffering (Experimental)"));
    action->setShortcut(QKeySequence(Qt::Key_4 | Qt::CTRL));
    connect(action, SIGNAL(triggered()), signalMapper_, SLOT(map()));
    signalMapper_->setMapping(action, GLWidget::quad);
    fsGlWidget_->addAction(action);

    action = menu->addAction(tr("Matrix Anaglyph (Experimental)"));
    action->setShortcut(QKeySequence(Qt::Key_5 | Qt::CTRL));
    connect(action, SIGNAL(triggered()), signalMapper_, SLOT(map()));
    signalMapper_->setMapping(action, GLWidget::matrix);
    fsGlWidget_->addAction(action);

    menu->addSeparator();

    action = menu->addAction(tr("&Shader (Line interlacing)"));
    action->setShortcut(QKeySequence(Qt::Key_6 | Qt::CTRL));
    connect(action, SIGNAL(triggered()), signalMapper_, SLOT(map()));
    signalMapper_->setMapping(action, GLWidget::shaderLine);
    fsGlWidget_->addAction(action);

    action = menu->addAction(tr("&Shader (Mayan)"));
    action->setShortcut(QKeySequence(Qt::Key_7 | Qt::CTRL));
    connect(action, SIGNAL(triggered()), signalMapper_, SLOT(map()));
    signalMapper_->setMapping(action, GLWidget::shaderMayan);
    fsGlWidget_->addAction(action);

    menu->addSeparator();

    action = menu->addAction(tr("Si&ngle"));
    action->setShortcut(QKeySequence(Qt::Key_0 | Qt::CTRL));
    connect(action, SIGNAL(triggered()), signalMapper_, SLOT(map()));
    signalMapper_->setMapping(action, GLWidget::single);
    fsGlWidget_->addAction(action);

    connect(signalMapper_, SIGNAL(mapped(int)), this, SLOT(setDrawStyle(int)));

    // Object Creation Menu and signal mapper
    objectMenu_ = menuBar()->addMenu(tr("&Create Object"));
    objectMapper_ = new QSignalMapper(this);
    connect(objectMapper_, SIGNAL(mapped(int)), this, SLOT(onObjectCreate(int)));

#ifdef Q_WS_MACX
    // Make menu bar the default menu bar
    menuBar()->setParent(0);
#endif

    // Set up layout
    setFocusPolicy(Qt::StrongFocus);
    setCentralWidget(mainGlWidget_);

    // Create Scene
    setProgram(Program::create());

    // Set up redraw timer
    timer_ = new QTimer(this);
    connect(timer_, SIGNAL(timeout()), this, SLOT(onTimeout()));
    timer_->start(15); // ~60 fps
}
示例#17
0
int main(int argc,char* argv[]) {

    qRegisterMetaType<medDataIndex>("medDataIndex");

    // this needs to be done before creating the QApplication object, as per the
    // Qt doc, otherwise there are some edge cases where the style is not fully applied
    QApplication::setStyle("plastique");
    medApplication application(argc,argv);
    medSplashScreen splash(QPixmap(":/pixmaps/medInria-splash.png"));
    setlocale(LC_NUMERIC, "C");

    if (dtkApplicationArgumentsContain(&application, "-h") || dtkApplicationArgumentsContain(&application, "--help")) {
        qDebug() << "Usage: medInria [--fullscreen|--no-fullscreen] [--stereo] "
        #ifdef ACTIVATE_WALL_OPTION
        "[--wall] [--tracker=URL] "
        #endif
        "[--view] [files]]";
        return 1;
    }

    // Do not show the splash screen in debug builds because it hogs the
    // foreground, hiding all other windows. This makes debugging the startup
    // operations difficult.

    #if !defined(_DEBUG)
    bool show_splash = true;
    #else
    bool show_splash = false;
    #endif

    medSettingsManager* mnger = medSettingsManager::instance();

    QStringList posargs;
    for (int i=1;i<application.argc();++i) {
        const QString arg = application.argv()[i];
        if (arg.startsWith("--")) {
            bool valid_option = false;
            const QStringList options = (QStringList()
                    << "--fullscreen"
                    << "--no-fullscreen"
                    << "--wall" 
                    << "--tracker" 
                    << "--stereo"
                    << "--view");
            for (QStringList::const_iterator opt=options.constBegin();opt!=options.constEnd();++opt)
                if (arg.startsWith(*opt))
                    valid_option = true;
            if (!valid_option) { qDebug() << "Ignoring unknown option " << arg; }
            continue;
        }
        posargs.append(arg);
    }

    const bool DirectView = dtkApplicationArgumentsContain(&application,"--view") || posargs.size()!=0;
    int runningMedInria = 0;
    if (DirectView) {
        show_splash = false;
        for (QStringList::const_iterator i=posargs.constBegin();i!=posargs.constEnd();++i) {
            const QString& message = QString("/open ")+*i;
            runningMedInria = application.sendMessage(message);
        }
    } else {
        runningMedInria = application.sendMessage("");
    }

    if (runningMedInria)
        return 0;

    if (show_splash) {

        QObject::connect(medDatabaseController::instance().data(),
                         SIGNAL(copyMessage(QString,int,QColor)),
                         &splash,SLOT(showMessage(QString,int, QColor)));

        application.setMsgColor(Qt::white);
        application.setMsgAlignment(Qt::AlignLeft|Qt::AlignBottom);

        QObject::connect(medPluginManager::instance(),SIGNAL(loadError(const QString&)),
                         &application,SLOT(redirectMessageToSplash(const QString&)) );
        QObject::connect(medPluginManager::instance(),SIGNAL(loaded(QString)),
                         &application,SLOT(redirectMessageToSplash(QString)) );
        QObject::connect(&application,SIGNAL(showMessage(const QString&, int, const QColor&)),
                         &splash,SLOT(showMessage(const QString&, int, const QColor&)) );
        splash.show();
        splash.showMessage("Loading plugins...",Qt::AlignLeft|Qt::AlignBottom,Qt::white);
    }

    //  DATABASE INITIALISATION.
    //  First compare the current with the new data location

    QString currentLocation = medStorage::dataLocation();

    //  If the user configured a new location for the database in the settings editor, we'll need to move it

    QString newLocation = mnger->value("medDatabaseSettingsWidget", "new_database_location").toString();
    if (!newLocation.isEmpty()) {

        //  If the locations are different we need to move the db to the new location

        if (currentLocation.compare(newLocation)!=0) {
            if (!medDatabaseController::instance()->moveDatabase(newLocation)) {
                qDebug() << "Failed to move the database from " << currentLocation << " to " << newLocation;
                //  The new location is invalid so set it to zero
                newLocation = "";
            }
            mnger->setValue("medDatabaseSettingsWidget", "actual_database_location",newLocation);

            //  We need to reset the new Location to prevent doing it all the time

            mnger->setValue("medDatabaseSettingsWidget", "new_database_location","");
        }
    }
    // END OF DATABASE INITIALISATION

    medPluginManager::instance()->initialize();

    medMainWindow mainwindow;
    if (DirectView)
        mainwindow.setStartup(medMainWindow::WorkSpace,posargs);

    forceShow(mainwindow);

    bool fullScreen = medSettingsManager::instance()->value("startup", "fullscreen", false).toBool();

    const bool hasFullScreenArg   = application.arguments().contains("--fullscreen");
    const bool hasNoFullScreenArg = application.arguments().contains("--no-fullscreen");
    const bool hasWallArg         = application.arguments().contains("--wall");

    const int conflict = static_cast<int>(hasFullScreenArg)+static_cast<int>(hasNoFullScreenArg)+ static_cast<int>(hasWallArg);

    if (conflict>1)
        dtkWarn() << "Conflicting command line parameters between --fullscreen, --no-fullscreen and -wall. Ignoring.";
    else {
        if (hasWallArg) {
            mainwindow.setWallScreen(true);
            fullScreen = false;
        }

        if (hasFullScreenArg)
            fullScreen = true;

        if (hasNoFullScreenArg)
            fullScreen = false;
    }

    mainwindow.setFullScreen(fullScreen);


    if(application.arguments().contains("--stereo")) {
       QGLFormat format;
       format.setAlpha(true);
       format.setDoubleBuffer(true);
       format.setStereo(true);
       format.setDirectRendering(true);
       QGLFormat::setDefaultFormat(format);
    }

    if (show_splash)
        splash.finish(&mainwindow);

    if (medPluginManager::instance()->plugins().isEmpty()) {
        QMessageBox::warning(&mainwindow,
                             QObject::tr("No plugin loaded"),
                             QObject::tr("Warning : no plugin loaded successfully."));
    }

    //  Handle signals for multiple medInria instances.

    QObject::connect(&application,SIGNAL(messageReceived(const QString&)),
                     &mainwindow,SLOT(onNewInstance(const QString&)));

    application.setActivationWindow(&mainwindow);
    application.setMainWindow(&mainwindow);

    //  Start main loop.

    const int status = application.exec();

    medPluginManager::instance()->uninitialize();

    return status;
}