void View3D::addAnnotation(const QString& label, const QString& text, const Imath::V3d& pos) { GLuint programId = m_annotationShader->shaderProgram().programId(); auto annotation = std::make_shared<Annotation>(label, programId, text, pos); m_annotations.append(annotation); restartRender(); }
void View3D::setSelectionModel(QItemSelectionModel* selectionModel) { assert(selectionModel); if (selectionModel->model() != m_geometries) { assert(0 && "Attempt to set incompatible selection model"); return; } if (m_selectionModel) { disconnect(m_selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(restartRender())); } m_selectionModel = selectionModel; connect(m_selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(restartRender())); }
void View3D::removeAnnotations(const QRegExp& labelRegex) { QVector<std::shared_ptr<Annotation>> annotations; foreach (auto annotation, m_annotations) { if (!labelRegex.exactMatch(annotation->label())) annotations.append(annotation); } m_annotations = annotations; restartRender(); }
void View3D::mouseMoveEvent(QMouseEvent* event) { if (m_mouseButton == Qt::MidButton) return; bool zooming = m_mouseButton == Qt::RightButton; if(event->modifiers() & Qt::ControlModifier) { m_cursorPos = m_camera.mouseMovePoint(m_cursorPos, event->pos() - m_prevMousePos, zooming); restartRender(); } else m_camera.mouseDrag(m_prevMousePos, event->pos(), zooming); m_prevMousePos = event->pos(); }
//------------------------------------------------------------------------------ View3D::View3D(GeometryCollection* geometries, const QGLFormat& format, QWidget *parent) : QGLWidget(format, parent), m_camera(false, false), m_mouseButton(Qt::NoButton), m_explicitCursorPos(false), m_cursorPos(0), m_prevCursorSnap(0), m_backgroundColor(60, 50, 50), m_drawBoundingBoxes(true), m_drawCursor(true), m_drawAxes(true), m_drawGrid(false), m_badOpenGL(false), m_shaderProgram(), m_geometries(geometries), m_selectionModel(0), m_shaderParamsUI(0), m_incrementalFrameTimer(0), m_incrementalFramebuffer(0), m_incrementalDraw(false), m_drawAxesBackground(QImage(":/resource/axes.png")), m_drawAxesLabelX(QImage(":/resource/x.png")), m_drawAxesLabelY(QImage(":/resource/y.png")), m_drawAxesLabelZ(QImage(":/resource/z.png")), m_cursorVertexArray(0), m_axesVertexArray(0), m_gridVertexArray(0), m_quadVertexArray(0), m_quadLabelVertexArray(0), m_devicePixelRatio(1.0) { connect(m_geometries, SIGNAL(layoutChanged()), this, SLOT(geometryChanged())); //connect(m_geometries, SIGNAL(destroyed()), this, SLOT(modelDestroyed())); connect(m_geometries, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(geometryChanged())); connect(m_geometries, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(geometryInserted(const QModelIndex&, int,int))); connect(m_geometries, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(geometryChanged())); setSelectionModel(new QItemSelectionModel(m_geometries, this)); setFocusPolicy(Qt::StrongFocus); setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); setFocus(); m_camera.setClipFar(FLT_MAX*0.5f); //using FLT_MAX appears to cause issues under OS X for Qt to handle // Setting a good value for the near camera clipping plane is difficult // when trying to show a large variation of length scales: Setting a very // small value allows us to see objects very close to the camera; the // tradeoff is that this reduces the resolution of the z-buffer leading to // z-fighting in the distance. m_camera.setClipNear(1); connect(&m_camera, SIGNAL(projectionChanged()), this, SLOT(restartRender())); connect(&m_camera, SIGNAL(viewChanged()), this, SLOT(restartRender())); makeCurrent(); m_shaderProgram.reset(new ShaderProgram()); connect(m_shaderProgram.get(), SIGNAL(uniformValuesChanged()), this, SLOT(restartRender())); connect(m_shaderProgram.get(), SIGNAL(shaderChanged()), this, SLOT(restartRender())); connect(m_shaderProgram.get(), SIGNAL(paramsChanged()), this, SLOT(setupShaderParamUI())); m_incrementalFrameTimer = new QTimer(this); m_incrementalFrameTimer->setSingleShot(false); connect(m_incrementalFrameTimer, SIGNAL(timeout()), this, SLOT(updateGL())); }
void View3D::toggleDrawGrid() { m_drawGrid = !m_drawGrid; restartRender(); }
void View3D::toggleDrawAxes() { m_drawAxes = !m_drawAxes; restartRender(); }
void View3D::toggleDrawCursor() { m_drawCursor = !m_drawCursor; restartRender(); }
void View3D::toggleDrawBoundingBoxes() { m_drawBoundingBoxes = !m_drawBoundingBoxes; restartRender(); }
void View3D::setBackground(QColor col) { m_backgroundColor = col; restartRender(); }
void View3D::geometryChanged() { if (m_geometries->rowCount() == 1 && !m_explicitCursorPos) centerOnGeometry(m_geometries->index(0)); restartRender(); }
void View3D::geometryChanged() { restartRender(); }
//------------------------------------------------------------------------------ View3D::View3D(GeometryCollection* geometries, const QGLFormat& format, QWidget *parent) : QGLWidget(format, parent), m_camera(false, false), m_mouseButton(Qt::NoButton), m_explicitCursorPos(false), m_cursorPos(0), m_prevCursorSnap(0), m_backgroundColor(60, 50, 50), m_drawBoundingBoxes(true), m_drawCursor(true), m_drawAxes(true), m_drawGrid(false), m_drawAnnotations(true), m_badOpenGL(false), m_shaderProgram(), m_geometries(geometries), m_selectionModel(0), m_shaderParamsUI(0), m_incrementalFrameTimer(0), m_incrementalFramebuffer(), m_incrementalDraw(false), m_drawAxesBackground(QImage(":/resource/axes.png")), m_drawAxesLabelX(QImage(":/resource/x.png")), m_drawAxesLabelY(QImage(":/resource/y.png")), m_drawAxesLabelZ(QImage(":/resource/z.png")), m_cursorVertexArray(0), m_axesVertexArray(0), m_gridVertexArray(0), m_quadVertexArray(0), m_quadLabelVertexArray(0), m_devicePixelRatio(1.0) { connect(m_geometries, SIGNAL(layoutChanged()), this, SLOT(geometryChanged())); //connect(m_geometries, SIGNAL(destroyed()), this, SLOT(modelDestroyed())); connect(m_geometries, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(geometryChanged())); connect(m_geometries, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(dataChanged(QModelIndex,QModelIndex))); connect(m_geometries, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(geometryInserted(const QModelIndex&, int,int))); connect(m_geometries, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(geometryChanged())); setSelectionModel(new QItemSelectionModel(m_geometries, this)); setFocusPolicy(Qt::StrongFocus); setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); setFocus(); connect(&m_camera, SIGNAL(projectionChanged()), this, SLOT(restartRender())); connect(&m_camera, SIGNAL(viewChanged()), this, SLOT(restartRender())); makeCurrent(); m_shaderProgram.reset(new ShaderProgram()); connect(m_shaderProgram.get(), SIGNAL(uniformValuesChanged()), this, SLOT(restartRender())); connect(m_shaderProgram.get(), SIGNAL(shaderChanged()), this, SLOT(restartRender())); connect(m_shaderProgram.get(), SIGNAL(paramsChanged()), this, SLOT(setupShaderParamUI())); m_incrementalFrameTimer = new QTimer(this); m_incrementalFrameTimer->setSingleShot(false); connect(m_incrementalFrameTimer, SIGNAL(timeout()), this, SLOT(updateGL())); }
void View3D::toggleDrawAnnotations() { m_drawAnnotations = !m_drawAnnotations; restartRender(); }