Exemplo n.º 1
0
void QGCodeViewer::init() 
{
    setShortcut(DISPLAY_FPS, Qt::CTRL+Qt::Key_F);
    setShortcut(DRAW_GRID, 0);
    
    setManipulatedFrame(new ManipulatedFrame());

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glEnable(GL_DEPTH_TEST);
    glDrawBuffer(GL_BACK);
    //glDisable(GL_CULL_FACE);
    //glLineStipple(2, 0xFFFF);
    glDisable(GL_LIGHTING);
    glClearColor(0.25,0.25,0.25,0);
    //glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    //glLineWidth(3);
  
    //setGridIsDrawn();
    
    if (!restoreStateFromFile()) {
        showEntireScene();
    }
    
    setMouseBinding(Qt::AltModifier, Qt::RightButton, SHOW_ENTIRE_SCENE, true, Qt::MidButton);

    clear();

    //startAnimation();
}
Exemplo n.º 2
0
void WZMOpenGLWidget::setModel(MODEL *model)
{
	double dimension;

	if (!model)
	{
		return;
	}
	prepareModel(model);
	gl_errors();
	psModel = model;

	// Calculate best z offset
	for (int i = 0; i < psModel->meshes; i++)
	{
		MESH *psMesh = &psModel->mesh[i];

		for (int j = 0; j < psMesh->vertices * 3; j++)
		{
			dimension = MAX(fabs(psMesh->vertexArray[j]), dimension);
		}
	}
	setSceneRadius(dimension);
	showEntireScene();
	timer.start();
}
Exemplo n.º 3
0
	void QglviewerRenderer::init()
	{
		glInfo* info = glInfo::getInstance();
		info->initAllOpenGL();
		setMouseTracking(true);
		setFocusPolicy(Qt::StrongFocus);
		setShortcut(DISPLAY_FPS,Qt::CTRL+Qt::Key_F);

		glEnable(GL_DEPTH_TEST);
		glDepthFunc(GL_LEQUAL);
		glCullFace(GL_BACK);
		glEnable(GL_CULL_FACE);
		glPolygonMode(GL_FRONT,GL_FILL);
		//glFrontFace(GL_CW);
		glClearColor(0.0,0.0,0.0,1);
		glEnable(GL_LINE_SMOOTH);
		glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
		glShadeModel(GL_SMOOTH);
		this->setSceneRadius(20);
		showEntireScene();
		glDisable(GL_COLOR_MATERIAL);
		//glEnable(GL_MULTISAMPLE);	
		setAnimationPeriod(15);
		startAnimation();

		initBackgroundTexture();
	}
Exemplo n.º 4
0
void SFMViewer::init() {
	// Restore previous viewer state.
	restoreStateFromFile();

    setFPSIsDisplayed();

	setSceneBoundingBox(qglviewer::Vec(-50,-50,-50), qglviewer::Vec(50,50,50));

	showEntireScene();
}
Exemplo n.º 5
0
void Viewer::import(const std::string& surfaceMesh)
{
	cgogn::io::import_surface<Vec3>(map, surfaceMesh);

	vertex_position_ = map.get_attribute<Vec3, Map2::VERTEX>("position");
	vertex_normal_ = map.add_attribute<Vec3, Map2::VERTEX>("normal");

	cgogn::geometry::compute_normal_vertices<Vec3>(map, vertex_position_, vertex_normal_);
	cgogn::geometry::compute_bounding_box(vertex_position_, bb_);

	setSceneRadius(bb_.diag_size());
	Vec3 center = bb_.center();
	setSceneCenter(qoglviewer::Vec(center[0], center[1], center[2]));
	showEntireScene();
}
Exemplo n.º 6
0
void
Viewer::setGridSize(int d, int w, int h)
{
  m_depth = d;
  m_width = w;
  m_height = h;

  m_minDSlice = 0;
  m_minWSlice = 0;
  m_minHSlice = 0;

  m_maxDSlice = d;
  m_maxWSlice = w;
  m_maxHSlice = h;

  setSceneBoundingBox(Vec(0,0,0), Vec(m_height, m_width, m_depth));
  showEntireScene();
}
Exemplo n.º 7
0
void SW::GLViewer::viewAll()
{
    //计算所有Mesh的整体BoundingBox
    Mesh::Point tempVertex = meshes[0].point(*(meshes[0].vertices_begin()));
    float maxX = tempVertex[0], minX = tempVertex[0];
    float maxY = tempVertex[1], minY = tempVertex[1];
    float maxZ = tempVertex[2], minZ = tempVertex[2];
    int meshNum = meshes.size();
    for(int meshIndex = 0; meshIndex < meshNum; meshIndex++)
    {
        for(Mesh::VertexIter vertexIter = meshes[meshIndex].vertices_begin(); vertexIter != meshes[meshIndex].vertices_end(); vertexIter++)
        {
            tempVertex = meshes[meshIndex].point(*vertexIter);
            if(tempVertex[0] > maxX)
            {
                maxX = tempVertex[0];
            }
            else if(tempVertex[0] < minX)
            {
                minX = tempVertex[0];
            }
            if(tempVertex[1] > maxY)
            {
                maxY = tempVertex[1];
            }
            else if(tempVertex[1] < minY)
            {
                minY = tempVertex[1];
            }
            if(tempVertex[2] > maxZ)
            {
                maxZ = tempVertex[2];
            }
            else if(tempVertex[2] < minZ)
            {
                minZ = tempVertex[2];
            }
        }
    }

    setSceneBoundingBox(qglviewer::Vec(minX, minY, minZ), qglviewer::Vec(maxX, maxY, maxZ));
    showEntireScene();
    updateGL();
}
Exemplo n.º 8
0
void QGCodeViewer::update() 
{
    // qDebug() << "QGCodeViewer::update";

    Vec c((aabb[0] + aabb[3])/2, (aabb[1] + aabb[4])/2, (aabb[2] + aabb[5])/2);
    double radius = qMax(aabb[0] + aabb[3], aabb[1] + aabb[4]);
    radius = qMax(radius, aabb[2] + aabb[5]) / 2;
    
    setSceneRadius(radius);

    qDebug() << "radius" << radius;

    if (_autoZoom)
        showEntireScene();

    if (dirty) {
        dirty = false;
        updateGL();
    }
}
Exemplo n.º 9
0
  virtual void init(){
		restoreStateFromFile();
		glDisable(GL_LIGHTING);
		setGridIsDrawn(false);
		//help(); 
		setAnimationPeriod(0); // fast as possible
		startAnimation();
		showEntireScene();
		
		// Make world axis visible
		setAxisIsDrawn(true);
		
		// Move camera according to viewer type (on X, Y or Z axis)
		camera()->setPosition(qglviewer::Vec(2.0,2.0,2.0));
		camera()->setUpVector(qglviewer::Vec(0.0,0.0,1.0));
		camera()->lookAt(sceneCenter());
		
		/*
		// Forbid rotation
		qglviewer::WorldConstraint* constraint = new qglviewer::WorldConstraint();
		constraint->setRotationConstraintType(qglviewer::AxisPlaneConstraint::FORBIDDEN);
		camera()->frame()->setConstraint(constraint);
		*/
	}
Exemplo n.º 10
0
int QGLViewer::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QGLWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: viewerInitialized(); break;
        case 1: drawNeeded(); break;
        case 2: drawFinished((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 3: animateNeeded(); break;
        case 4: helpRequired(); break;
        case 5: axisIsDrawnChanged((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 6: gridIsDrawnChanged((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 7: FPSIsDisplayedChanged((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 8: textIsEnabledChanged((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 9: cameraIsEditedChanged((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 10: stereoChanged((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 11: pointSelected((*reinterpret_cast< const QMouseEvent*(*)>(_a[1]))); break;
        case 12: mouseGrabberChanged((*reinterpret_cast< qglviewer::MouseGrabber*(*)>(_a[1]))); break;
        case 13: setAxisIsDrawn((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 14: setAxisIsDrawn(); break;
        case 15: setGridIsDrawn((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 16: setGridIsDrawn(); break;
        case 17: setFPSIsDisplayed((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 18: setFPSIsDisplayed(); break;
        case 19: setTextIsEnabled((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 20: setTextIsEnabled(); break;
        case 21: setCameraIsEdited((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 22: setCameraIsEdited(); break;
        case 23: toggleAxisIsDrawn(); break;
        case 24: toggleGridIsDrawn(); break;
        case 25: toggleFPSIsDisplayed(); break;
        case 26: toggleTextIsEnabled(); break;
        case 27: toggleCameraIsEdited(); break;
        case 28: setBackgroundColor((*reinterpret_cast< const QColor(*)>(_a[1]))); break;
        case 29: setForegroundColor((*reinterpret_cast< const QColor(*)>(_a[1]))); break;
        case 30: setSceneRadius((*reinterpret_cast< float(*)>(_a[1]))); break;
        case 31: setSceneCenter((*reinterpret_cast< const qglviewer::Vec(*)>(_a[1]))); break;
        case 32: setSceneBoundingBox((*reinterpret_cast< const qglviewer::Vec(*)>(_a[1])),(*reinterpret_cast< const qglviewer::Vec(*)>(_a[2]))); break;
        case 33: showEntireScene(); break;
        case 34: setCamera((*reinterpret_cast< qglviewer::Camera*const(*)>(_a[1]))); break;
        case 35: setManipulatedFrame((*reinterpret_cast< qglviewer::ManipulatedFrame*(*)>(_a[1]))); break;
        case 36: setMouseGrabber((*reinterpret_cast< qglviewer::MouseGrabber*(*)>(_a[1]))); break;
        case 37: setFullScreen((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 38: setFullScreen(); break;
        case 39: setStereoDisplay((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 40: setStereoDisplay(); break;
        case 41: toggleFullScreen(); break;
        case 42: toggleStereoDisplay(); break;
        case 43: toggleCameraMode(); break;
        case 44: saveSnapshot((*reinterpret_cast< bool(*)>(_a[1])),(*reinterpret_cast< bool(*)>(_a[2]))); break;
        case 45: saveSnapshot((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 46: saveSnapshot(); break;
        case 47: saveSnapshot((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< bool(*)>(_a[2]))); break;
        case 48: saveSnapshot((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 49: setSnapshotFileName((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 50: setSnapshotFormat((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 51: setSnapshotCounter((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 52: setSnapshotQuality((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 53: { bool _r = openSnapshotFormatDialog();
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 54: snapshotToClipboard(); break;
        case 55: copyBufferToTexture((*reinterpret_cast< GLint(*)>(_a[1])),(*reinterpret_cast< GLenum(*)>(_a[2]))); break;
        case 56: copyBufferToTexture((*reinterpret_cast< GLint(*)>(_a[1]))); break;
        case 57: setAnimationPeriod((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 58: startAnimation(); break;
        case 59: stopAnimation(); break;
        case 60: animate(); break;
        case 61: toggleAnimation(); break;
        case 62: help(); break;
        case 63: aboutQGLViewer(); break;
        case 64: select((*reinterpret_cast< const QMouseEvent*(*)>(_a[1]))); break;
        case 65: select((*reinterpret_cast< const QPoint(*)>(_a[1]))); break;
        case 66: setSelectBufferSize((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 67: setSelectRegionWidth((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 68: setSelectRegionHeight((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 69: setSelectedName((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 70: setShortcut((*reinterpret_cast< KeyboardAction(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break;
        case 71: setKeyboardAccelerator((*reinterpret_cast< KeyboardAction(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break;
        case 72: setKeyDescription((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        case 73: setKeyFrameKey((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break;
        case 74: setPlayKeyFramePathStateKey((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 75: setPlayPathStateKey((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 76: setAddKeyFrameStateKey((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 77: setPathKey((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break;
        case 78: setPathKey((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 79: setPlayPathKeyboardModifiers((*reinterpret_cast< QtKeyboardModifiers(*)>(_a[1]))); break;
        case 80: setAddKeyFrameKeyboardModifiers((*reinterpret_cast< QtKeyboardModifiers(*)>(_a[1]))); break;
        case 81: setMouseBinding((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< MouseHandler(*)>(_a[2])),(*reinterpret_cast< MouseAction(*)>(_a[3])),(*reinterpret_cast< bool(*)>(_a[4]))); break;
        case 82: setMouseBinding((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< MouseHandler(*)>(_a[2])),(*reinterpret_cast< MouseAction(*)>(_a[3]))); break;
        case 83: setWheelBinding((*reinterpret_cast< QtKeyboardModifiers(*)>(_a[1])),(*reinterpret_cast< MouseHandler(*)>(_a[2])),(*reinterpret_cast< MouseAction(*)>(_a[3])),(*reinterpret_cast< bool(*)>(_a[4]))); break;
        case 84: setWheelBinding((*reinterpret_cast< QtKeyboardModifiers(*)>(_a[1])),(*reinterpret_cast< MouseHandler(*)>(_a[2])),(*reinterpret_cast< MouseAction(*)>(_a[3]))); break;
        case 85: setHandlerKeyboardModifiers((*reinterpret_cast< MouseHandler(*)>(_a[1])),(*reinterpret_cast< QtKeyboardModifiers(*)>(_a[2]))); break;
        case 86: setHandlerStateKey((*reinterpret_cast< MouseHandler(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break;
        case 87: setMouseStateKey((*reinterpret_cast< MouseHandler(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break;
        case 88: initFromDOMElement((*reinterpret_cast< const QDomElement(*)>(_a[1]))); break;
        case 89: saveStateToFile(); break;
        case 90: { bool _r = restoreStateFromFile();
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 91: setStateFileName((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 92: saveToFile((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 93: saveToFile(); break;
        case 94: { bool _r = restoreFromFile((*reinterpret_cast< const QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 95: { bool _r = restoreFromFile();
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 96: resetVisualHints(); break;
        case 97: delayedFullScreen(); break;
        case 98: hideMessage(); break;
        default: ;
        }
        _id -= 99;
    }
    return _id;
}
Exemplo n.º 11
0
void GL_widget_3::set_window_to_boundingbox() {
	showEntireScene();
}
Exemplo n.º 12
0
void Drawing::init()
{
	setSceneRadius(5.0);
	setSceneCenter(qoglviewer::Vec(0.0,0.0,0.0));
	showEntireScene();
	glClearColor(0.1f,0.1f,0.3f,0.0f);

	this->makeCurrent();

	if (m_first!=this)
	{
		drawer_ = m_first->drawer_;
		drawer2_ = m_first->drawer2_;
		wp_ = m_first->wp_;
		button_ = m_first->button_;

		drawer_rend_ = drawer_->generate_renderer();
		drawer2_rend_ = drawer2_->generate_renderer();
		wp_rend_ = wp_->generate_renderer();
		button_rend_ = button_->generate_renderer();
		return;
	}

	wp_ = std::make_shared<cgogn::rendering::WallPaper>(QImage(QString(DEFAULT_MESH_PATH) + QString("../images/cgogn2.png")));
	button_ = std::make_shared<cgogn::rendering::WallPaper>(QImage(QString(DEFAULT_MESH_PATH) + QString("../images/igg.png")));
//	button_->set_local_position(this->width(),this->height(),10,10,50,50);
	button_->set_local_position(0.1f,0.1f,0.2f,0.2f);

	wp_rend_ = wp_->generate_renderer();
	button_rend_ = button_->generate_renderer();

	// drawer for simple old-school g1 rendering
	drawer_ = std::make_shared<cgogn::rendering::DisplayListDrawer>();
	drawer_rend_ = drawer_->generate_renderer();
	drawer_->new_list();
	drawer_->line_width(2.0);
	drawer_->begin(GL_LINE_LOOP);
		drawer_->color3f(1.0,0.0,0.0);
		drawer_->vertex3f(0.0,0.0,0.0);
		drawer_->color3f(0.0,1.0,1.0);
		drawer_->vertex3f(1,0,0);
		drawer_->color3f(1.0,0.0,1.0);
		drawer_->vertex3f(1.0f,1.0f,0.0f);
		drawer_->color3f(1.0,1.0,0.0);
		drawer_->vertex3f(0,1,0);
	drawer_->end();
	drawer_->line_width_aa(3.0);
	drawer_->begin(GL_LINES);
		drawer_->color3f(0.0,0.8,0.0);
		drawer_->vertex3fv(Vec3(-1,2,0));
		drawer_->color3f(0.0,0.0,0.8);
		drawer_->vertex3fv(Vec3(-1.3,0,0));
		drawer_->color3f(0.0,0.0,0.8);
		drawer_->vertex3fv(Vec3(-2,1,0));
		drawer_->color3f(0.8,0.0,0.0);
		drawer_->vertex3fv(Vec3(-2.3,3,0));
	drawer_->end();

	drawer_->begin(GL_TRIANGLES);
		drawer_->color3f(1.0,0.0,0.0);
		drawer_->vertex3fv({{2,2,0}});
		drawer_->color3f(0.0,1.0,0.0);
		drawer_->vertex3fv({{4,3,0}});
		drawer_->color3f(0.0,0.0,1.0);
		drawer_->vertex3fv({{2.5,1,0}});
	drawer_->end();

	drawer_->point_size_aa(7.0);
	drawer_->begin(GL_POINTS);
	for (float a=0.0f; a < 1.0f; a+= 0.1f)
	{
		Vec3 P(4.0+std::cos(6.28*a),-2.0+std::sin(6.28*a),0.0);
		Vec3 C(a,0.5,1.0-a);
		drawer_->color3fv(C);
		drawer_->vertex3fv(P);
	}
	drawer_->end();

	drawer_->ball_size(0.1f);
	drawer_->begin(GL_POINTS);
	for (float a=0.05f; a < 1.0f; a+= 0.1f)
	{
		Vec3 P(4.0+std::cos(6.28*a)*1.2,-2.0+ std::sin(6.28*a)*1.2, std::sin(6.28*a)*0.2 );
		Vec3 C(a,0.5,1.0-a);
		drawer_->color3fv(C);
		drawer_->vertex3fv(P);
	}

	drawer_->end();
	drawer_->end_list();

	drawer2_ = std::make_shared<cgogn::rendering::DisplayListDrawer>();
	drawer2_rend_ = drawer2_->generate_renderer();
	drawer2_->new_list();
	drawer2_->point_size_aa(5.0);
	drawer2_->begin(GL_POINTS);
	drawer2_->color3f(1.0,1.0,1.0);
	for (float z=-1.0f; z < 1.0f; z+= 0.1f)
		for (float y=-2.0f; y < 0.0f; y+= 0.1f)
			for (float x=0.0f; x < 2.0f; x+= 0.1f)
			{
				drawer2_->vertex3f(x,y,z);
			}
	drawer2_->end();

	drawer2_->ball_size(0.03f);
	drawer2_->begin(GL_POINTS);
	drawer2_->color3f(1.0,1.0,1.0);
	for (float z=-1.0f; z < 1.0f; z+= 0.2f)
		for (float y=-2.0f; y < 0.0f; y+= 0.2f)
			for (float x=-3.0f; x < -1.0f; x+= 0.2f)
			{
				drawer2_->vertex3f(x,y,z);
			}
	drawer2_->end();

	drawer2_->end_list();

}