static inline QVector4D qt_sRGB_to_linear_RGB(const QVector4D &color) { return QVector4D(qt_sRGB_to_linear_RGB(color.x()), qt_sRGB_to_linear_RGB(color.y()), qt_sRGB_to_linear_RGB(color.z()), color.w()); }
QVector<float> UniformItem::getGlData() const { QVector<float> glData; if (type == UniformType::SPHERICAL_3D) { QVector4D cartesian = CoordinateConversions::sphericalToCartesian(data[0], data[1], data[2], 0.0); glData.push_back(cartesian.x()); glData.push_back(cartesian.y()); glData.push_back(cartesian.z()); } else if (type == UniformType::SPHERICAL_4D) { QVector4D cartesian = CoordinateConversions::sphericalToCartesian(data[0], data[1], data[2], data[3]); glData.push_back(cartesian.x()); glData.push_back(cartesian.y()); glData.push_back(cartesian.z()); glData.push_back(cartesian.w()); } else if (type == UniformType::COLOR) { glData.push_back(data[0] / 255.0f); glData.push_back(data[1] / 255.0f); glData.push_back(data[2] / 255.0f); } else if (type == UniformType::COLOR_ALPHA) { glData.push_back(data[0] / 255.0f); glData.push_back(data[1] / 255.0f); glData.push_back(data[2] / 255.0f); glData.push_back(data[3] / 255.0f); } else { glData = data; } return glData; }
colour4::colour4( QVector4D in ) : vectorX( 4 ) { r() = in.x(); g() = in.y(); b() = in.z(); a() = in.w(); }
QDebug operator<<(QDebug dbg, const QVector4D &vector) { dbg.nospace() << "QVector4D(" << vector.x() << ", " << vector.y() << ", " << vector.z() << ", " << vector.w() << ')'; return dbg.space(); }
QDebug operator<<(QDebug dbg, const QVector4D &vector) { QDebugStateSaver saver(dbg); dbg.nospace() << "QVector4D(" << vector.x() << ", " << vector.y() << ", " << vector.z() << ", " << vector.w() << ')'; return dbg; }
void rpnoc::Cell::setBackGroundColor( QVector4D iColor ) { mBackgroundColor = iColor; GLfloat color[4] = { iColor.x(), iColor.y(), iColor.z(), iColor.w() }; Vertex< 4 > oVertex[4] = { color, color, color, color }; mPanel->setColor( oVertex ); }
static QVector3D unproject( QVector3D v, const QMatrix4x4 &modelView, const QMatrix4x4 &projection, QRect viewport ) { // Reimplementation of QVector3D::unproject() - see qtbase/src/gui/math3d/qvector3d.cpp // The only difference is that the original implementation uses tolerance 1e-5 // (see qFuzzyIsNull()) as a protection against division by zero. For us it is however // common to get lower values (e.g. as low as 1e-8 when zoomed out to the whole Earth with web mercator). QMatrix4x4 inverse = QMatrix4x4( projection * modelView ).inverted(); QVector4D tmp( v, 1.0f ); tmp.setX( ( tmp.x() - float( viewport.x() ) ) / float( viewport.width() ) ); tmp.setY( ( tmp.y() - float( viewport.y() ) ) / float( viewport.height() ) ); tmp = tmp * 2.0f - QVector4D( 1.0f, 1.0f, 1.0f, 1.0f ); QVector4D obj = inverse * tmp; if ( qgsDoubleNear( obj.w(), 0, 1e-10 ) ) obj.setW( 1.0f ); obj /= obj.w(); return obj.toVector3D(); }
QVector4D GLScene::unproject(const QVector3D & screen){ GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); const qreal xNorm = (2.0f * ((screen.x() - viewport[0]) / (viewport[2] - viewport[0]))) - 1.0f; const qreal yNorm = 1.0f - (2.0f * ((screen.y() - viewport[1]) / (viewport[3] - viewport[1]))); QMatrix4x4 pvMatrixInv = camera().projViewProduct().inverted(); QVector4D worldPoint = pvMatrixInv * QVector4D(xNorm, yNorm, screen.z(), 1); if (worldPoint.w() == 0){ return QVector4D(0,0,0,0); } worldPoint.setW(1 / worldPoint.w()); worldPoint.setX(worldPoint.x() * worldPoint.w()); worldPoint.setY(worldPoint.y() * worldPoint.w()); return worldPoint; }
QT_BEGIN_NAMESPACE #ifndef GL_FRAMEBUFFER_SRGB #define GL_FRAMEBUFFER_SRGB 0x8DB9 #endif static inline QVector4D qsg_premultiply(const QVector4D &c, float globalOpacity) { float o = c.w() * globalOpacity; return QVector4D(c.x() * o, c.y() * o, c.z() * o, o); }
Ogre::String toString(const QVector4D &v) { Ogre::String s="<QVector4D "; s+="w="+Ogre::StringConverter::toString((float)v.w())+", "; s+="x="+Ogre::StringConverter::toString((float)v.x())+", "; s+="y="+Ogre::StringConverter::toString((float)v.y())+", "; s+="z="+Ogre::StringConverter::toString((float)v.z()); s+=">"; return s; }
bool QQuickVector4DValueType::fuzzyEquals(const QVector4D &vec, qreal epsilon) const { qreal absEps = qAbs(epsilon); if (qAbs(v.x() - vec.x()) > absEps) return false; if (qAbs(v.y() - vec.y()) > absEps) return false; if (qAbs(v.z() - vec.z()) > absEps) return false; if (qAbs(v.w() - vec.w()) > absEps) return false; return true; }
void GLWidget::rotateSelected(float x, float y, float z, float angle) { obj.rotateSelected(x, y, z, angle); QQuaternion rotate = QQuaternion::fromAxisAndAngle(x, y, z, angle); QVector4D qrotate = rotate.toVector4D(); Matrix3d mat3 = Quaterniond(qrotate.w(),qrotate.x(), qrotate.y(), qrotate.z()).toRotationMatrix(); Matrix4d mat4 = Matrix4d::Identity(); mat4.block(0,0,3,3) = mat3; pd.InterTransform(obj.getSelectVertexIds(),rotate); qDebug() << "update!!"; update(); }
void MainWindow::on_configurationTreeView_doubleClicked(const QModelIndex &index) { QModelIndex &intermediateIndex = const_cast<QModelIndex &>(index); currentIndex = &intermediateIndex; if (treeModel->isFileNameItem(index)) { QString fileName = QFileDialog::getOpenFileName(this); if (!fileName.isEmpty()) { treeModel->setData(index, QVariant::fromValue(fileName)); on_configurationTreeView_clicked(index); } } else if (treeModel->isPositionItem(index)) { QVector4D value = qvariant_cast<QVector4D>(treeModel->getItemData(index)); QVector4D spherical = CoordinateConversions::cartesianToSpherical(value); SphericalDialog *editor = new SphericalDialog(this); editor->setValues(spherical.x(), spherical.y(), spherical.z(), spherical.w()); editor->setModal(true); editor->show(); connect(editor, SIGNAL(valueChanged(double,int,int,double)), this, SLOT(currentPositionChanged(double,int,int,double))); } else if (treeModel->isUniformConfigurationItem(index)) {
/** * copied from https://searchcode.com/codesearch/view/35195518/ * qt3d /src/threed/painting/qglpainter.cpp * no changes in the code */ static inline uint outcode( QVector4D v ) { // For a discussion of outcodes see pg 388 Dunn & Parberry. // For why you can't just test if the point is in a bounding box // consider the case where a view frustum with view-size 1.5 x 1.5 // is tested against a 2x2 box which encloses the near-plane, while // all the points in the box are outside the frustum. // TODO: optimise this with assembler - according to D&P this can // be done in one line of assembler on some platforms uint code = 0; if ( v.x() < -v.w() ) code |= 0x01; if ( v.x() > v.w() ) code |= 0x02; if ( v.y() < -v.w() ) code |= 0x04; if ( v.y() > v.w() ) code |= 0x08; if ( v.z() < -v.w() ) code |= 0x10; if ( v.z() > v.w() ) code |= 0x20; return code; }
QMatrix4x4 iPolacion::getMatrizRotacion(QVector4D q){ QMatrix4x4 m = QMatrix4x4((1-(2*((q.y()*q.y())+(q.z()*q.z())))), ((2*q.x()*q.y())-(2*q.w()*q.z())), ((2*q.w()*q.y())+(2*q.x()*q.z())), 0 , ((2*q.x()*q.y())+(2*q.w()*q.z())), (1-(2*((q.x()*q.x())+(q.z()*q.z())))), ((-2*q.w()*q.x())+(2*q.y()*q.z())), 0 , ((-2*q.w()*q.y())+(2*q.x()*q.z())), ((2*q.w()*q.x())+(2*q.y()*q.z())), (1-(2*((q.x()*q.x())+(q.y()*q.y())))), 0 , 0,0,0,1); return m; }
void ClipPlanes::drawViewportBorders(QGLViewer *viewer) { int ow = viewer->width(); int oh = viewer->height(); float aspectRatio = viewer->aspectRatio(); viewer->startScreenCoordinatesSystem(); for (int i=0; i<m_clips.count(); i++) { QVector4D vp = m_clips[i]->viewport(); // render only when textured plane and viewport active if (m_clips[i]->tfset() >= 0 && m_clips[i]->tfset() < Global::lutSize() && vp.x() >= 0.0) { int vx, vy, vh, vw; vx = vp.x()*ow; vy = oh-vp.y()*oh; vw = vp.z()*ow; vh = vp.w()*oh; vx+=1; vy+=1; vw-=2; vh-=2; glLineWidth(2); if (m_clips[i]->viewportGrabbed()) { glLineWidth(3); glColor3f(0.0, 1.0, 0.3); } else { Vec clipColor = m_clips[i]->color(); glColor3dv(clipColor); } glBegin(GL_LINE_STRIP); glVertex2i(vx, vy); glVertex2i(vx, vy-vh); glVertex2i(vx+vw, vy-vh); glVertex2i(vx+vw, vy); glVertex2i(vx, vy); glEnd(); if (m_clips[i]->viewportGrabbed()) { glLineWidth(2); glColor3f(0.8, 0.8, 0.8); } else { glLineWidth(1); glColor3f(0.2, 0.2, 0.2); } glBegin(GL_LINE_STRIP); glVertex2i(vx, vy); glVertex2i(vx, vy-vh); glVertex2i(vx+vw, vy-vh); glVertex2i(vx+vw, vy); glVertex2i(vx, vy); glEnd(); } } viewer->stopScreenCoordinatesSystem(); }
Ogre::Quaternion convert(const QVector4D &v) { return Ogre::Quaternion(v.w(),v.x(),v.y(),v.z()); }
QVariant PropertyMatrixModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); if (role != Qt::DisplayRole && role != Qt::EditRole) return QVariant(); switch (m_matrix.type()) { case QVariant::Matrix: { const QMatrix value = m_matrix.value<QMatrix>(); switch (index.row() << 4 | index.column()) { case 0x00: return value.m11(); case 0x01: return value.m12(); case 0x10: return value.m21(); case 0x11: return value.m22(); case 0x20: return value.dx(); case 0x21: return value.dy(); } break; } case QVariant::Transform: { const QTransform value = m_matrix.value<QTransform>(); switch (index.row() << 4 | index.column()) { case 0x00: return value.m11(); case 0x01: return value.m12(); case 0x02: return value.m13(); case 0x10: return value.m21(); case 0x11: return value.m22(); case 0x12: return value.m23(); case 0x20: return value.m31(); case 0x21: return value.m32(); case 0x22: return value.m33(); } break; } case QVariant::Matrix4x4: { const QMatrix4x4 value = m_matrix.value<QMatrix4x4>(); return value(index.row(), index.column()); } case QVariant::Vector2D: { const QVector2D value = m_matrix.value<QVector2D>(); switch (index.row()) { case 0: return value.x(); case 1: return value.y(); } break; } case QVariant::Vector3D: { const QVector3D value = m_matrix.value<QVector3D>(); switch (index.row()) { case 0: return value.x(); case 1: return value.y(); case 2: return value.z(); } break; } case QVariant::Vector4D: { const QVector4D value = m_matrix.value<QVector4D>(); switch (index.row()) { case 0: return value.x(); case 1: return value.y(); case 2: return value.z(); case 3: return value.w(); } break; } #if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0) case QVariant::Quaternion: { float pitch, yaw, roll; const QQuaternion value = m_matrix.value<QQuaternion>(); value.getEulerAngles(&pitch, &yaw, &roll); switch (index.row()) { case 0: return pitch; case 1: return yaw; case 2: return roll; } break; } #endif default: break; } return QVariant(); }
srcCornerPoints << transaction.originalTopLeft(); srcCornerPoints << transaction.originalTopRight(); srcCornerPoints << transaction.originalBottomLeft(); srcCornerPoints << transaction.originalBottomRight(); dstCornerPoints.clear(); Q_FOREACH (const QPointF &pt, srcCornerPoints) { dstCornerPoints << transform.map(pt); } QMatrix4x4 realMatrix(transform); QVector4D v; v = QVector4D(1, 0, 0, 0); v = realMatrix * v; transformedHandles.xVanishingExists = !qFuzzyCompare(v.w(), 0); transformedHandles.xVanishing = v.toVector2DAffine().toPointF(); v = QVector4D(0, 1, 0, 0); v = realMatrix * v; transformedHandles.yVanishingExists = !qFuzzyCompare(v.w(), 0); transformedHandles.yVanishing = v.toVector2DAffine().toPointF(); } void KisPerspectiveTransformStrategy::setTransformFunction(const QPointF &mousePos, bool perspectiveModifierActive) { Q_UNUSED(perspectiveModifierActive); QPolygonF transformedPolygon = m_d->transform.map(QPolygonF(m_d->transaction.originalRect())); StrokeFunction defaultFunction = transformedPolygon.containsPoint(mousePos, Qt::OddEvenFill) ? MOVE : NONE; KisTransformUtils::HandleChooser<StrokeFunction>
// Parse a Python object as a sequence of either QVector[234]D instances or a // sequence of sequence of floats and return an array that can be passed to // QGLShaderProgram::setAttributeArray(). The array is destroyed only when the // shader is garbage collected or when replaced by another array. const GLfloat *qpyopengl_attribute_array(PyObject *values, PyObject *shader, PyObject *key, int *tsize, sipErrorState *estate) { // Check the key was created correctly. if (!key) { *estate = sipErrorFail; return 0; } // Get the dict that holds the converted arrays. PyObject *dict = ((sipSimpleWrapper *)shader)->user; if (!dict) { dict = PyDict_New(); if (!dict) { Py_DECREF(key); *estate = sipErrorFail; return 0; } ((sipSimpleWrapper *)shader)->user = dict; } // Check that values is a non-empty sequence. values = PySequence_Fast(values, "an attribute array must be a sequence"); if (!values) { Py_DECREF(key); *estate = sipErrorContinue; return 0; } SIP_SSIZE_T nr_items = PySequence_Fast_GET_SIZE(values); if (nr_items < 1) { PyErr_SetString(PyExc_TypeError, "an attribute array must have at least one element"); Py_DECREF(key); Py_DECREF(values); *estate = sipErrorFail; return 0; } // The first element determines the type expected. PyObject *itm = PySequence_Fast_GET_ITEM(values, 0); const sipTypeDef *td; SIP_SSIZE_T nr_dim; if (sipCanConvertToType(itm, sipType_QVector2D, SIP_NOT_NONE)) { td = sipType_QVector2D; nr_dim = 2; } else if (sipCanConvertToType(itm, sipType_QVector3D, SIP_NOT_NONE)) { td = sipType_QVector3D; nr_dim = 3; } else if (sipCanConvertToType(itm, sipType_QVector4D, SIP_NOT_NONE)) { td = sipType_QVector4D; nr_dim = 4; } else if (PySequence_Check(itm) && (nr_dim = PySequence_Size(itm)) >= 1) { td = 0; } else { PyErr_SetString(PyExc_TypeError, "an attribute array must be a sequence of QVector2D, " "QVector3D, QVector4D, or a sequence of sequences of floats"); Py_DECREF(key); Py_DECREF(values); *estate = sipErrorFail; return 0; } // Create the array that will be returned. GLfloat *array = new GLfloat[nr_items * nr_dim]; // Convert the values. GLfloat *ap = array; for (SIP_SSIZE_T i = 0; i < nr_items; ++i) { int iserr = 0; itm = PySequence_Fast_GET_ITEM(values, i); if (td) { void *cpp; cpp = sipForceConvertToType(itm, td, 0, SIP_NOT_NONE | SIP_NO_CONVERTORS, 0, &iserr); if (iserr) { PyErr_Format(PyExc_TypeError, "attribute array elements should all be '%s', not '%s'", sipTypeAsPyTypeObject(td)->tp_name, Py_TYPE(itm)->tp_name); } else if (td == sipType_QVector2D) { QVector2D *v = reinterpret_cast<QVector2D *>(cpp); *ap++ = v->x(); *ap++ = v->y(); } else if (td == sipType_QVector3D) { QVector3D *v = reinterpret_cast<QVector3D *>(cpp); *ap++ = v->x(); *ap++ = v->y(); *ap++ = v->z(); } else if (td == sipType_QVector4D) { QVector4D *v = reinterpret_cast<QVector4D *>(cpp); *ap++ = v->x(); *ap++ = v->y(); *ap++ = v->z(); *ap++ = v->w(); } } else { itm = PySequence_Fast(itm, "attribute array elements should all be sequences"); if (itm) { if (PySequence_Fast_GET_SIZE(itm) != nr_dim) { PyErr_Format(PyExc_TypeError, "attribute array elements should all be sequences " #if PY_VERSION_HEX >= 0x02050000 "of length %zd", #else "of length %d", #endif nr_dim); Py_DECREF(itm); iserr = 1; } else { PyErr_Clear(); for (SIP_SSIZE_T j = 0; j < nr_dim; ++j) *ap++ = PyFloat_AsDouble( PySequence_Fast_GET_ITEM(itm, j)); if (PyErr_Occurred()) { PyErr_SetString(PyExc_TypeError, "attribute array elements should all be " "sequences of floats"); Py_DECREF(itm); iserr = 1; } } } else { iserr = 1; } } if (iserr) { Py_DECREF(key); Py_DECREF(values); delete[] array; *estate = sipErrorFail; return 0; } } Py_DECREF(values); *tsize = nr_dim; // Wrap the array in a Python object so that it won't leak. #if defined(SIP_USE_PYCAPSULE) PyObject *array_obj = PyCapsule_New(array, 0, array_dtor); #else PyObject *array_obj = PyCObject_FromVoidPtr(array, array_dtor); #endif if (!array_obj) { Py_DECREF(key); delete[] array; *estate = sipErrorFail; return 0; } int rc = PyDict_SetItem(dict, key, array_obj); Py_DECREF(key); Py_DECREF(array_obj); if (rc < 0) { *estate = sipErrorFail; return 0; } return array; }
void tvalue2json(rapidjson::Value & output, const QVariant & input, rapidjson::Value::AllocatorType & allocator) { switch(input.type()) { case QVariant::Invalid: { output.SetNull(); break; } case QVariant::Bool: { output.SetBool(input.toBool()); break; } case QVariant::Int: { output.SetInt64(input.toInt()); break; } case QVariant::LongLong: { output.SetInt64(input.toLongLong()); break; } case QVariant::Double: { output.SetDouble(input.toDouble()); break; } case QVariant::String: { QByteArray str = input.toString().toUtf8(); output.SetString(str.data(), str.size(), allocator); break; } case QVariant::StringList: { QStringList list = input.toStringList(); output.SetArray(); output.Reserve(list.size(), allocator); rapidjson::Value temp; for(QStringList::const_iterator it = list.begin(); it != list.end(); ++it) { QByteArray str = it->toUtf8(); temp.SetString(str.data(), str.size(), allocator); output.PushBack(temp, allocator); } break; } case QVariant::List: { QList<QVariant> list = input.toList(); output.SetArray(); output.Reserve(list.size(), allocator); rapidjson::Value temp; for(QList<QVariant>::const_iterator it = list.begin(); it != list.end(); ++it) { tvalue2json(temp, *it, allocator); output.PushBack(temp, allocator); } break; } case QVariant::Map: { output.SetObject(); rapidjson::Value tempK, tempV; QMap<QString, QVariant> qmap = input.toMap(); for(QMap<QString, QVariant>::const_iterator it = qmap.begin(); it != qmap.end(); ++it) { tvalue2json(tempK, it.key(), allocator); tvalue2json(tempV, it.value(), allocator); output.AddMember(tempK, tempV, allocator); } break; } case QVariant::Point: { QPoint pt = input.toPoint(); output.SetArray(); output.Reserve(2, allocator); output.PushBack(pt.x(), allocator); output.PushBack(pt.y(), allocator); break; } case QVariant::PointF: { QPointF pt = input.toPointF(); output.SetArray(); output.Reserve(2, allocator); output.PushBack(pt.x(), allocator); output.PushBack(pt.y(), allocator); break; } case QVariant::Size: { QSize pt = input.toSize(); output.SetArray(); output.Reserve(2, allocator); output.PushBack(pt.width(), allocator); output.PushBack(pt.height(), allocator); break; } case QVariant::SizeF: { QSizeF pt = input.toSizeF(); output.SetArray(); output.Reserve(2, allocator); output.PushBack(pt.width(), allocator); output.PushBack(pt.height(), allocator); break; } case QVariant::Rect: { QRect pt = input.toRect(); output.SetArray(); output.Reserve(4, allocator); output.PushBack(pt.x(), allocator); output.PushBack(pt.y(), allocator); output.PushBack(pt.width(), allocator); output.PushBack(pt.height(), allocator); break; } case QVariant::RectF: { QRectF pt = input.toRectF(); output.SetArray(); output.Reserve(4, allocator); output.PushBack(pt.x(), allocator); output.PushBack(pt.y(), allocator); output.PushBack(pt.width(), allocator); output.PushBack(pt.height(), allocator); break; } case QVariant::Vector2D: { QVector2D pt = input.value<QVector2D>(); output.SetArray(); output.Reserve(2, allocator); output.PushBack(pt.x(), allocator); output.PushBack(pt.y(), allocator); break; } case QVariant::Vector3D: { QVector3D pt = input.value<QVector3D>(); output.SetArray(); output.Reserve(3, allocator); output.PushBack(pt.x(), allocator); output.PushBack(pt.y(), allocator); output.PushBack(pt.z(), allocator); break; } case QVariant::Vector4D: { QVector4D pt = input.value<QVector4D>(); output.SetArray(); output.Reserve(4, allocator); output.PushBack(pt.x(), allocator); output.PushBack(pt.y(), allocator); output.PushBack(pt.z(), allocator); output.PushBack(pt.w(), allocator); break; } case QVariant::Color: { QColor pt = input.value<QColor>(); output.SetArray(); output.Reserve(4, allocator); output.PushBack(pt.red(), allocator); output.PushBack(pt.green(), allocator); output.PushBack(pt.blue(), allocator); output.PushBack(pt.alpha(), allocator); break; } default: { output.SetNull(); assert(false && "shuldn't execute to here."); } } }