void QGCodeViewer::appendCanonLine(canonLine *l) { //QMutexLocker locker(&mutex); lines.push_back(l); dirty = true; // for updateGL() if (l->isMotion()) { Point pos1 = l->point(0); Point pos2 = l->point(1); double oaabbmin[3], oaabbmax[3]; oaabbmin[0] = qMin(pos1.x, pos2.x); oaabbmin[1] = qMin(pos1.y, pos2.y); oaabbmin[2] = qMin(pos1.z, pos2.z); oaabbmax[0] = qMax(pos1.x, pos2.x); oaabbmax[1] = qMax(pos1.y, pos2.y); oaabbmax[2] = qMax(pos1.z, pos2.z); for (int i = 0; i < 3; ++i) { aabb[ i] = qMin(aabb[ i], oaabbmin[i]); aabb[3+i] = qMax(aabb[3+i], oaabbmax[i]); } //qDebug() << "getAABB()" << aabb[0] << aabb[1] << aabb[2] << aabb[3] << aabb[4] << aabb[5]; Vec c((aabb[0] + aabb[3])/2, (aabb[1] + aabb[4])/2, (aabb[2] + aabb[5])/2); setSceneCenter(c); } }
void TrackballViewer::init() { std::cout << "Initialize Trackball Viewer.\n"; BasicViewer::init(); // Set shader glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); //glEnable(GL_CULL_FACE); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glShadeModel(GL_FLAT); qglClearColor(QColor(Qt::white)); setBackgroundColor(QColor(Qt::white)); setForegroundColor(QColor(Qt::white)); setSceneCenter(qglviewer::Vec(0, 0, 0)); setSceneRadius(50); camera()->fitSphere(qglviewer::Vec(0, 0, 0), 5); camera()->setType(qglviewer::Camera::Type::PERSPECTIVE); camera()->setFlySpeed(0.5); setWheelandMouse(); }
void TrackballViewer::resetCamera() { // assume only one dispObjects MainCanvas exist here Bound* scene_bounds = dynamic_cast<TrackballCanvas*>(dispObjects[0])->getBoundBox(); qglviewer::Vec scene_center; scene_center = qglviewer::Vec((scene_bounds->minX + scene_bounds->maxX) / 2, (scene_bounds->minY + scene_bounds->maxY) / 2, (scene_bounds->minZ + scene_bounds->maxZ) / 2); setSceneCenter(scene_center); float x_span = (scene_bounds->maxX - scene_bounds->minX) / 2; float y_span = (scene_bounds->maxY - scene_bounds->minY) / 2; float z_span = (scene_bounds->maxZ - scene_bounds->minZ) / 2; float scene_radius = x_span>y_span ? (x_span > z_span ? x_span : z_span) : (y_span > z_span ? y_span : z_span); scene_radius *= 1.5; setSceneRadius(scene_radius); camera()->fitSphere(scene_center, scene_radius); setStateFileName(QString((dynamic_cast<TrackballCanvas*>(dispObjects[0])->getFilePath()+"/camera_info.xml").c_str())); if (restoreStateFromFile()) std::cout << "Load camera info successes...\n"; else std::cout << "Load camera info failed...\n"; // set the scene in MainCanvasViewer syncCamera(); main_canvas_viewer->setSceneCenter(sceneCenter()); main_canvas_viewer->setSceneRadius(sceneRadius()); main_canvas_viewer->camera()->setZClippingCoefficient(camera()->zClippingCoefficient()); }
void KnotsViewer::set_scene(Bbox_3 &box) { Mesh::Point bbMin(box.xmin(), box.ymin(), box.zmin()); Mesh::Point bbMax(box.xmax(), box.ymax(), box.zmax()); Mesh::Point center= (bbMin + bbMax)*0.5; double radius=0.5*(bbMin - bbMax).norm(); setSceneCenter(Vec(center[0], center[1], center[2])); setSceneRadius(radius); camera()->showEntireScene(); }
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(); }
void Viewer::initializeGL() { qglClearColor(Qt::black); glShadeModel(GL_FLAT); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glDisable(GL_LIGHTING); pCamera->setPosition(qglviewer::Vec(0,0,-2)); pCamera->setViewDirection(qglviewer::Vec(0,0,1)); pCamera->setUpVector(qglviewer::Vec(0,1,0)); setCamera(pCamera); setSceneRadius(1.0); setSceneCenter(qglviewer::Vec(0,0,0)); camera()->showEntireScene(); QGLViewer::initializeGL(); }
void Viewer::init() { if (bFirstInit) { // - init GLEW OpenGL::init(); fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION)); // Restore previous viewer state. //restoreStateFromFile(); // Set position of light's camera qgl_cam_light.setPosition( qglviewer::Vec(0, 50, 0) ); qgl_cam_light.fitBoundingBox( qglviewer::Vec(-1, -1, -1), qglviewer::Vec(+1, +1, +1) ); // Add a manipulated frame to the viewer. setManipulatedFrame( qgl_cam_light.frame() ); setAnimationPeriod(0.); setSceneCenter(qglviewer::Vec(0, 0, 0)); setSceneRadius(10.f); } initAll( !bFirstInit ); if (bFirstInit) { qgl_mf_vbo.setPosition( -qglviewer::Vec(ts->getCenter()) ); f_scale_vbo = 1.f / ( ts->getRadius() ); } bFirstInit = false; // On vérifie les erreurs MSG_CHECK_GL; }
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; }
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(); }