本文整理汇总了C++中QVector::data方法的典型用法代码示例。如果您正苦于以下问题:C++ QVector::data方法的具体用法?C++ QVector::data怎么用?C++ QVector::data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVector
的用法示例。
在下文中一共展示了QVector::data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buildLinDiv
bool ScaleDiv::buildLinDiv(int maxMajSteps, int maxMinSteps, double step)
{
int nMaj, nMin, minSize, i0,i,k;
double val, mval;
double firstTick, lastTick;
double minStep;
QVector<double> buffer;
bool rv = true;
// parameter range check
maxMajSteps = MusECore::qwtMax(1, maxMajSteps);
maxMinSteps = MusECore::qwtMax(0, maxMinSteps);
step = MusECore::qwtAbs(step);
// reset vectors
d_minMarks.resize(0);
d_majMarks.resize(0);
if (d_lBound == d_hBound) return true;
//
// Set up major divisions
//
if (step == 0.0)
d_majStep = MusECore::qwtCeil125(MusECore::qwtAbs(d_hBound - d_lBound) * 0.999999
/ double(maxMajSteps));
else
d_majStep = step;
if (d_majStep == 0.0) return true;
firstTick = ceil( (d_lBound - step_eps * d_majStep) / d_majStep) * d_majStep;
lastTick = floor( (d_hBound + step_eps * d_majStep) / d_majStep) * d_majStep;
nMaj = MusECore::qwtMin(10000, int(rint((lastTick - firstTick) / d_majStep)) + 1);
d_majMarks.resize(nMaj);
MusECore::qwtLinSpace(d_majMarks.data(), d_majMarks.size(), firstTick, lastTick);
//
// Set up minor divisions
//
if (maxMinSteps < 1) // no minor divs
return true;
minStep = MusECore::qwtCeil125( d_majStep / double(maxMinSteps) );
if (minStep == 0.0) return true;
nMin = MusECore::qwtAbs(int(rint(d_majStep / minStep))) - 1; // # minor steps per interval
// Do the minor steps fit into the interval?
if ( MusECore::qwtAbs(double(nMin + 1) * minStep - d_majStep) > step_eps * d_majStep)
{
nMin = 1;
minStep = d_majStep * 0.5;
}
// Are there minor ticks below the first major tick?
if (d_majMarks[0] > d_lBound )
i0 = -1;
else
i0 = 0;
// resize buffer to the maximum possible number of minor ticks
buffer.resize(nMin * (nMaj + 1));
// calculate minor ticks
if (rv)
{
minSize = 0;
for (i = i0; i < (int)d_majMarks.size(); i++)
{
if (i >= 0)
val = d_majMarks[i];
else
val = d_majMarks[0] - d_majStep;
for (k=0; k< nMin; k++)
{
mval = (val += minStep);
if (limRange(mval, d_lBound, d_hBound, border_eps))
{
buffer[minSize] = mval;
minSize++;
}
}
}
//d_minMarks.duplicate(buffer.data(), minSize);
d_minMarks.resize(minSize);
qCopy(buffer.data(), buffer.data() + minSize, d_minMarks.begin());
}
return rv;
}
示例2: loadMesh
Mesh* ModelInterface::loadMesh(aiMesh* ai_mesh, aiMaterial* ai_material, const int index)
{
Q_UNUSED(index)
Mesh* mesh = new Mesh();
QVector3D* vertices = new QVector3D[ai_mesh->mNumVertices];
QVector3D* normals = new QVector3D[ai_mesh->mNumVertices];
QVector3D* tangent = new QVector3D[ai_mesh->mNumVertices];
QVector2D* texCoords = new QVector2D[ai_mesh->mNumVertices];
QVector4D* boneIDs = new QVector4D[ai_mesh->mNumVertices];
QVector4D* weight = new QVector4D[ai_mesh->mNumVertices];
QVector<uint> indices;
if(ai_mesh->HasBones() && bones)
{
for(uint i = 0; i < ai_mesh->mNumBones; ++i)
{
for(uint j = 0; j < ai_mesh->mBones[i]->mNumWeights; ++j)
{
QString boneName(ai_mesh->mBones[i]->mName.data);
aiVertexWeight w = ai_mesh->mBones[i]->mWeights[j];
int vertexId = w.mVertexId;
float weightValue = w.mWeight;
int boneID = bones->getBone(boneName)->getId();
addWeightData(&boneIDs[vertexId], &weight[vertexId], boneID, weightValue);
}
}
}
for(uint i = 0; i < ai_mesh->mNumVertices; ++i)
{
vertices[i] = QVector3D(ai_mesh->mVertices[i].x, ai_mesh->mVertices[i].y, ai_mesh->mVertices[i].z);
normals[i] = QVector3D(ai_mesh->mNormals[i].x, ai_mesh->mNormals[i].y, ai_mesh->mNormals[i].z);
if(ai_mesh->mTangents)
tangent[i] = QVector3D(ai_mesh->mTangents[i].x, ai_mesh->mTangents[i].y, ai_mesh->mTangents[i].z);
else
tangent[i] = QVector3D(1.0f, 0.0f, 0.0f);
if(ai_mesh->mTextureCoords[0])
texCoords[i] = QVector2D(ai_mesh->mTextureCoords[0][i].x, ai_mesh->mTextureCoords[0][i].y);
else
texCoords[i] = QVector2D(0.0f, 0.0f);
}
for(uint i = 0; i < ai_mesh->mNumFaces; ++i)
{
aiFace face = ai_mesh->mFaces[i];
for(uint j = 0; j < face.mNumIndices; ++j)
indices.push_back(face.mIndices[j]);
}
loadMaterial(ai_material, mesh);
mesh->createVertexArrayObject();
mesh->createBuffer(Mesh::Vertices, vertices, sizeof(QVector3D) * ai_mesh->mNumVertices);
mesh->createBuffer(Mesh::Normals, normals, sizeof(QVector3D) * ai_mesh->mNumVertices);
mesh->createBuffer(Mesh::TexCoords, texCoords, sizeof(QVector2D) * ai_mesh->mNumVertices);
mesh->createBuffer(Mesh::Tangent, tangent, sizeof(QVector3D) * ai_mesh->mNumVertices);
mesh->createBuffer(Mesh::Bones, boneIDs, sizeof(QVector4D) * ai_mesh->mNumVertices);
mesh->createBuffer(Mesh::Weight, weight, sizeof(QVector4D) * ai_mesh->mNumVertices);
mesh->createBuffer(Mesh::Index, indices.data(), sizeof(int) * indices.size());
mesh->setNumFaces(indices.size());
delete[] vertices;
delete[] normals;
delete[] tangent;
delete[] texCoords;
delete[] weight;
delete[] boneIDs;
return mesh;
}
示例3: initTextures
bool GLWidgetRendererPrivate::initTextures(const VideoFormat &fmt)
{
// isSupported(pixfmt)
if (!fmt.isValid())
return false;
video_format.setPixelFormatFFmpeg(fmt.pixelFormatFFmpeg());
//http://www.berkelium.com/OpenGL/GDC99/internalformat.html
//NV12: UV is 1 plane. 16 bits as a unit. GL_LUMINANCE4, 8, 16, ... 32?
//GL_LUMINANCE, GL_LUMINANCE_ALPHA are deprecated in GL3, removed in GL3.1
//replaced by GL_RED, GL_RG, GL_RGB, GL_RGBA? for 1, 2, 3, 4 channel image
//http://www.gamedev.net/topic/634850-do-luminance-textures-still-exist-to-opengl/
//https://github.com/kivy/kivy/issues/1738: GL_LUMINANCE does work on a Galaxy Tab 2. LUMINANCE_ALPHA very slow on Linux
//ALPHA: vec4(1,1,1,A), LUMINANCE: (L,L,L,1), LUMINANCE_ALPHA: (L,L,L,A)
/*
* To support both planar and packed use GL_ALPHA and in shader use r,g,a like xbmc does.
* or use Swizzle_mask to layout the channels: http://www.opengl.org/wiki/Texture#Swizzle_mask
* GL ES2 support: GL_RGB, GL_RGBA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA
* http://stackoverflow.com/questions/18688057/which-opengl-es-2-0-texture-formats-are-color-depth-or-stencil-renderable
*/
if (!fmt.isPlanar()) {
GLint internal_fmt;
GLenum data_fmt;
GLenum data_t;
if (!OpenGLHelper::videoFormatToGL(fmt, &internal_fmt, &data_fmt, &data_t)) {
qWarning("no opengl format found");
return false;
}
internal_format = QVector<GLint>(fmt.planeCount(), internal_fmt);
data_format = QVector<GLenum>(fmt.planeCount(), data_fmt);
data_type = QVector<GLenum>(fmt.planeCount(), data_t);
} else {
internal_format.resize(fmt.planeCount());
data_format.resize(fmt.planeCount());
data_type = QVector<GLenum>(fmt.planeCount(), GL_UNSIGNED_BYTE);
if (fmt.isPlanar()) {
/*!
* GLES internal_format == data_format, GL_LUMINANCE_ALPHA is 2 bytes
* so if NV12 use GL_LUMINANCE_ALPHA, YV12 use GL_ALPHA
*/
qDebug("///////////bpp %d", fmt.bytesPerPixel());
internal_format[0] = data_format[0] = GL_LUMINANCE; //or GL_RED for GL
if (fmt.planeCount() == 2) {
internal_format[1] = data_format[1] = GL_LUMINANCE_ALPHA;
} else {
if (fmt.bytesPerPixel(1) == 2) {
// read 16 bits and compute the real luminance in shader
internal_format.fill(GL_LUMINANCE_ALPHA); //vec4(L,L,L,A)
data_format.fill(GL_LUMINANCE_ALPHA);
} else {
internal_format[1] = data_format[1] = GL_LUMINANCE; //vec4(L,L,L,1)
internal_format[2] = data_format[2] = GL_ALPHA;//GL_ALPHA;
}
}
for (int i = 0; i < internal_format.size(); ++i) {
// xbmc use bpp not bpp(plane)
//internal_format[i] = GetGLInternalFormat(data_format[i], fmt.bytesPerPixel(i));
//data_format[i] = internal_format[i];
}
} else {
//glPixelStorei(GL_UNPACK_ALIGNMENT, fmt.bytesPerPixel());
// TODO: if no alpha, data_fmt is not GL_BGRA. align at every upload?
}
}
for (int i = 0; i < fmt.planeCount(); ++i) {
//qDebug("format: %#x GL_LUMINANCE_ALPHA=%#x", data_format[i], GL_LUMINANCE_ALPHA);
if (fmt.bytesPerPixel(i) == 2 && fmt.planeCount() == 3) {
//data_type[i] = GL_UNSIGNED_SHORT;
}
int bpp_gl = OpenGLHelper::bytesOfGLFormat(data_format[i], data_type[i]);
int pad = qCeil((qreal)(texture_size[i].width() - effective_tex_width[i])/(qreal)bpp_gl);
texture_size[i].setWidth(qCeil((qreal)texture_size[i].width()/(qreal)bpp_gl));
texture_upload_size[i].setWidth(qCeil((qreal)texture_upload_size[i].width()/(qreal)bpp_gl));
effective_tex_width[i] /= bpp_gl; //fmt.bytesPerPixel(i);
//effective_tex_width_ratio =
qDebug("texture width: %d - %d = pad: %d. bpp(gl): %d", texture_size[i].width(), effective_tex_width[i], pad, bpp_gl);
}
/*
* there are 2 fragment shaders: rgb and yuv.
* only 1 texture for packed rgb. planar rgb likes yuv
* To support both planar and packed yuv, and mixed yuv(NV12), we give a texture sample
* for each channel. For packed, each (channel) texture sample is the same. For planar,
* packed channels has the same texture sample.
* But the number of actural textures we upload is plane count.
* Which means the number of texture id equals to plane count
*/
if (textures.size() != fmt.planeCount()) {
glDeleteTextures(textures.size(), textures.data());
qDebug("delete %d textures", textures.size());
textures.clear();
textures.resize(fmt.planeCount());
glGenTextures(textures.size(), textures.data());
}
if (!hasGLSL) {
initTexture(textures[0], internal_format[0], data_format[0], data_type[0], texture_size[0].width(), texture_size[0].height());
// more than 1?
qWarning("Does not support GLSL!");
return false;
//.........这里部分代码省略.........
示例4: paintEvent
void SpeedPlotView::paintEvent(QPaintEvent *)
{
QPainter painter(viewport());
QRect fullRect = viewport()->rect();
QRect rect = viewport()->rect();
QFontMetrics fontMetrics = painter.fontMetrics();
rect.adjust(4, 4, 0, -4); // Add padding
int maxY = maxYValue();
rect.adjust(0, fontMetrics.height(), 0, 0); // Add top padding for top speed text
// draw Y axis speed labels
QVector<QString> speedLabels = {
Utils::Misc::friendlyUnit(maxY, true),
Utils::Misc::friendlyUnit(0.75 * maxY, true),
Utils::Misc::friendlyUnit(0.5 * maxY, true),
Utils::Misc::friendlyUnit(0.25 * maxY, true),
Utils::Misc::friendlyUnit(0, true)
};
int yAxeWidth = 0;
for (const QString &label : speedLabels)
if (fontMetrics.width(label) > yAxeWidth)
yAxeWidth = fontMetrics.width(label);
int i = 0;
for (const QString &label : speedLabels) {
QRectF labelRect(rect.topLeft() + QPointF(-yAxeWidth, (i++) * 0.25 * rect.height() - fontMetrics.height()),
QSizeF(2 * yAxeWidth, fontMetrics.height()));
painter.drawText(labelRect, label, Qt::AlignRight | Qt::AlignTop);
}
// draw grid lines
rect.adjust(yAxeWidth + 4, 0, 0, 0);
QPen gridPen;
gridPen.setStyle(Qt::DashLine);
gridPen.setWidthF(1);
gridPen.setColor(QColor(128, 128, 128, 128));
painter.setPen(gridPen);
painter.drawLine(fullRect.left(), rect.top(), rect.right(), rect.top());
painter.drawLine(fullRect.left(), rect.top() + 0.25 * rect.height(), rect.right(), rect.top() + 0.25 * rect.height());
painter.drawLine(fullRect.left(), rect.top() + 0.50 * rect.height(), rect.right(), rect.top() + 0.50 * rect.height());
painter.drawLine(fullRect.left(), rect.top() + 0.75 * rect.height(), rect.right(), rect.top() + 0.75 * rect.height());
painter.drawLine(fullRect.left(), rect.bottom(), rect.right(), rect.bottom());
painter.drawLine(rect.left(), fullRect.top(), rect.left(), fullRect.bottom());
painter.drawLine(rect.left() + 0.2 * rect.width(), fullRect.top(), rect.left() + 0.2 * rect.width(), fullRect.bottom());
painter.drawLine(rect.left() + 0.4 * rect.width(), fullRect.top(), rect.left() + 0.4 * rect.width(), fullRect.bottom());
painter.drawLine(rect.left() + 0.6 * rect.width(), fullRect.top(), rect.left() + 0.6 * rect.width(), fullRect.bottom());
painter.drawLine(rect.left() + 0.8 * rect.width(), fullRect.top(), rect.left() + 0.8 * rect.width(), fullRect.bottom());
// Set antialiasing for graphs
painter.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing);
// draw graphs
rect.adjust(3, 0, 0, 0); // Need, else graphs cross left gridline
double yMultiplier = (maxY == 0) ? 0.0 : static_cast<double>(rect.height()) / maxY;
double xTickSize = static_cast<double>(rect.width()) / m_viewablePointsCount;
boost::circular_buffer<PointData> &queue = getCurrentData();
for (int id = UP; id < NB_GRAPHS; ++id) {
if (!m_properties[static_cast<GraphID>(id)].enable)
continue;
QVector<QPoint> points;
for (int i = int(queue.size()) - 1, j = 0; i >= 0 && j <= m_viewablePointsCount; --i, ++j) {
int new_x = rect.right() - j * xTickSize;
int new_y = rect.bottom() - queue[i].y[id] * yMultiplier;
points.push_back(QPoint(new_x, new_y));
}
painter.setPen(m_properties[static_cast<GraphID>(id)].pen);
painter.drawPolyline(points.data(), points.size());
}
// draw legend
QPoint legendTopLeft(rect.left() + 4, fullRect.top() + 4);
double legendHeight = 0;
int legendWidth = 0;
for (const auto &property : m_properties) {
if (!property.enable)
continue;
if (fontMetrics.width(property.name) > legendWidth)
legendWidth = fontMetrics.width(property.name);
legendHeight += 1.5 * fontMetrics.height();
}
//.........这里部分代码省略.........
示例5: meshName
//! Create 3DRep from a Lib3dsNode
GLC_3DRep GLC_3dsToWorld::create3DRep(Lib3dsMesh* p3dsMesh)
{
QString meshName(p3dsMesh->name);
if (m_LoadedMeshes.contains(meshName))
{
// This mesh as been already loaded
QList<GLC_3DViewInstance*> instancesList(m_pWorld->collection()->instancesHandle());
GLC_3DViewInstance* pCurrentInstance= NULL;
int currentIndex= -1;
do
{
pCurrentInstance= instancesList[++currentIndex];
} while (pCurrentInstance->name() != meshName);
// return an instance.
//qDebug() << "instance";
return pCurrentInstance->representation();
}
GLC_Mesh * pMesh= new GLC_Mesh();
pMesh->setName(p3dsMesh->name);
// The mesh normals
const int normalsNumber= p3dsMesh->faces * 3;
Lib3dsVector *normalL= new Lib3dsVector[normalsNumber];
lib3ds_mesh_calculate_normals(p3dsMesh, normalL);
// Position vector
QVector<float> position(normalsNumber * 3);
// Normal Vector
QVector<float> normal(normalsNumber * 3);
memcpy((void*)normal.data(), normalL, normalsNumber * 3 * sizeof(float));
// Texel Vector
QVector<float> texel;
if (p3dsMesh->texels > 0)
{
texel.resize(normalsNumber * 2);
}
int normalIndex= 0;
for (unsigned int i= 0; i < p3dsMesh->faces; ++i)
{
IndexList triangleIndex;
Lib3dsFace *p3dsFace=&p3dsMesh->faceL[i];
for (int i=0; i < 3; ++i)
{
triangleIndex.append(normalIndex);
// Add vertex coordinate
memcpy((void*)&(position.data()[normalIndex * 3]), &p3dsMesh->pointL[p3dsFace->points[i]], 3 * sizeof(float));
// Add texel
if (p3dsMesh->texels > 0)
{
memcpy((void*)&(texel.data()[normalIndex * 2]), &p3dsMesh->texelL[p3dsFace->points[i]], 2 * sizeof(float));
}
++normalIndex;
}
// Load the material
// The material current face index
GLC_Material* pCurMaterial= NULL;
if (p3dsFace->material[0])
{
Lib3dsMaterial* p3dsMat=lib3ds_file_material_by_name(m_pLib3dsFile, p3dsFace->material);
if (NULL != p3dsMat)
{
// Check it this material as already been loaded
const QString materialName(p3dsFace->material);
if (!m_Materials.contains(materialName))
{ // Material not already loaded, load it
loadMaterial(p3dsMat);
}
pCurMaterial= m_Materials.value(materialName);
}
}
pMesh->addTriangles(pCurMaterial, triangleIndex);
}
pMesh->addVertice(position);
pMesh->addNormals(normal);
if (p3dsMesh->texels > 0)
{
pMesh->addTexels(texel);
}
// free normal memmory
delete[] normalL;
// Compute loading progress
++m_CurrentMeshNumber;
m_CurrentQuantumValue = static_cast<int>((static_cast<double>(m_CurrentMeshNumber) / m_NumberOfMeshes) * (100 - m_InitQuantumValue)) + m_InitQuantumValue;
if (m_CurrentQuantumValue > m_PreviousQuantumValue)
{
emit currentQuantum(m_CurrentQuantumValue);
}
m_PreviousQuantumValue= m_CurrentQuantumValue;
pMesh->finish();
return GLC_3DRep(pMesh);
}
示例6: toConformalInverted
void UwMath::toConformalInverted(QVector<QPointF> &object) {
QPointF * data = object.data();
for(int i = 0; i < object.size(); i++)
data[i] = UwMath::toConformalInverted(object.at(i));
}
示例7: loadUnitData
bool QmcUnit::loadUnitData(QDataStream &stream)
{
char *qmlUnitPtr = new char[header->sizeQmlUnit];
qmlUnit = reinterpret_cast<QV4::CompiledData::QmlUnit*>(qmlUnitPtr);
if (!qmlUnit)
return false;
compilationUnit->data = unit = &(qmlUnit->header);
if (!readData(qmlUnitPtr, header->sizeQmlUnit, stream))
return false;
// load imports
for (int i = 0; i < (int)header->imports; i++) {
QV4::CompiledData::Import import;
if (!readData((char *)&import, sizeof(QV4::CompiledData::Import), stream))
return false;
if (import.uriIndex >= header->strings || import.qualifierIndex >= header->strings)
return false;
imports.append(import);
}
for (int i = 0; i < (int)header->strings; i++) {
QString string;
if (!readString(string, stream))
return false;
strings.append(string);
}
for (int i = 0; i < (int)header->namespaces; i++) {
QString ns;
if (!readString(ns, stream))
return false;
namespaces.append(ns);
}
for (int i = 0; i < (int)header->typeReferences; i++) {
QmcUnitTypeReference typeRef;
if (!readData((char *)&typeRef, sizeof (QmcUnitTypeReference), stream))
return false;
typeReferences.append(typeRef);
}
for (int i = 0; i < (int)header->scriptReferences; i++) {
QString string;
if (!readString(string, stream))
return false;
scriptReferences.append(string);
}
// coderefs
codeRefSizes.resize(header->codeRefs);
for (int i = 0; i < (int)header->codeRefs; i++) {
if (!readData((char *)&exceptionReturnLabel, sizeof(QmcUnitExceptionReturnLabel), stream))
return false;
exceptionPropagationJumps.clear();
quint32 exceptionPropagationJumpsCount = 0;
if (!readData((char *)&exceptionPropagationJumpsCount, sizeof(quint32), stream))
return false;
for (uint j = 0; j < exceptionPropagationJumpsCount; j++) {
QmcUnitExceptionPropagationJump jump;
if (!readData((char *)&jump, sizeof (QmcUnitExceptionPropagationJump), stream))
return false;
exceptionPropagationJumps.append(jump);
}
#if CPU(ARM_THUMB2)
linkRecords.clear();
quint32 linkRecordsCount = 0;
if (!readData((char *)&linkRecordsCount, sizeof(quint32), stream))
return false;
if (linkRecordsCount > QMC_UNIT_MAX_LINK_RECORDS)
return false;
for (uint j = 0; j < linkRecordsCount; j++) {
QmcUnitLinkRecord record;
if (!readData((char *)&record, sizeof (QmcUnitLinkRecord), stream))
return false;
linkRecords.append(record);
}
#endif
quint32 codeRefLen = 0;
if (!readData((char *)&codeRefLen, sizeof(quint32), stream))
return false;
if (codeRefLen > QMC_UNIT_MAX_CODE_REF_SIZE)
return false;
//qDebug() << "Codereflen" << QString("%1").arg(codeRefLen, 0, 16);
if (codeRefLen == 0) {
JSC::MacroAssemblerCodeRef codeRef;
compilationUnit->codeRefs.append(codeRef);
QVector<QmcUnitCodeRefLinkCall> linkData;
linkCalls.append(linkData);
QVector<QV4::Primitive> constData;
constantVectors.append(constData);
continue;
}
//.........这里部分代码省略.........
示例8: populate
void QSGTextMaskMaterial::populate(const QPointF &p,
const QVector<quint32> &glyphIndexes,
const QVector<QPointF> &glyphPositions,
QSGGeometry *geometry,
QRectF *boundingRect,
QPointF *baseLine,
const QMargins &margins)
{
Q_ASSERT(m_font.isValid());
QVector<QFixedPoint> fixedPointPositions;
for (int i=0; i<glyphPositions.size(); ++i)
fixedPointPositions.append(QFixedPoint::fromPointF(glyphPositions.at(i)));
QTextureGlyphCache *cache = glyphCache();
QRawFontPrivate *fontD = QRawFontPrivate::get(m_font);
cache->populate(fontD->fontEngine, glyphIndexes.size(), glyphIndexes.constData(),
fixedPointPositions.data());
cache->fillInPendingGlyphs();
int margin = fontD->fontEngine->glyphMargin(cache->cacheType());
Q_ASSERT(geometry->indexType() == GL_UNSIGNED_SHORT);
geometry->allocate(glyphIndexes.size() * 4, glyphIndexes.size() * 6);
QVector4D *vp = (QVector4D *)geometry->vertexDataAsTexturedPoint2D();
Q_ASSERT(geometry->sizeOfVertex() == sizeof(QVector4D));
ushort *ip = geometry->indexDataAsUShort();
QPointF position(p.x(), p.y() - m_font.ascent());
bool supportsSubPixelPositions = fontD->fontEngine->supportsSubPixelPositions();
for (int i=0; i<glyphIndexes.size(); ++i) {
QFixed subPixelPosition;
if (supportsSubPixelPositions)
subPixelPosition = fontD->fontEngine->subPixelPositionForX(QFixed::fromReal(glyphPositions.at(i).x()));
QTextureGlyphCache::GlyphAndSubPixelPosition glyph(glyphIndexes.at(i), subPixelPosition);
const QTextureGlyphCache::Coord &c = cache->coords.value(glyph);
QPointF glyphPosition = glyphPositions.at(i) + position;
int x = qFloor(glyphPosition.x()) + c.baseLineX - margin;
int y = qFloor(glyphPosition.y()) - c.baseLineY - margin;
*boundingRect |= QRectF(x + margin, y + margin, c.w, c.h);
float cx1 = x - margins.left();
float cx2 = x + c.w + margins.right();
float cy1 = y - margins.top();
float cy2 = y + c.h + margins.bottom();
float tx1 = c.x - margins.left();
float tx2 = c.x + c.w + margins.right();
float ty1 = c.y - margins.top();
float ty2 = c.y + c.h + margins.bottom();
if (baseLine->isNull())
*baseLine = glyphPosition;
vp[4 * i + 0] = QVector4D(cx1, cy1, tx1, ty1);
vp[4 * i + 1] = QVector4D(cx2, cy1, tx2, ty1);
vp[4 * i + 2] = QVector4D(cx1, cy2, tx1, ty2);
vp[4 * i + 3] = QVector4D(cx2, cy2, tx2, ty2);
int o = i * 4;
ip[6 * i + 0] = o + 0;
ip[6 * i + 1] = o + 2;
ip[6 * i + 2] = o + 3;
ip[6 * i + 3] = o + 3;
ip[6 * i + 4] = o + 1;
ip[6 * i + 5] = o + 0;
}
}
示例9: populate
void QSGTextMaskMaterial::populate(const QPointF &p,
const QVector<quint32> &glyphIndexes,
const QVector<QPointF> &glyphPositions,
QSGGeometry *geometry,
QRectF *boundingRect,
QPointF *baseLine,
const QMargins &margins)
{
Q_ASSERT(m_font.isValid());
QVector<QFixedPoint> fixedPointPositions;
for (int i=0; i<glyphPositions.size(); ++i)
fixedPointPositions.append(QFixedPoint::fromPointF(glyphPositions.at(i)));
QTextureGlyphCache *cache = glyphCache();
QRawFontPrivate *fontD = QRawFontPrivate::get(m_font);
cache->populate(fontD->fontEngine, glyphIndexes.size(), glyphIndexes.constData(),
fixedPointPositions.data());
cache->fillInPendingGlyphs();
int margin = fontD->fontEngine->glyphMargin(cache->glyphFormat());
qreal glyphCacheScaleX = cache->transform().m11();
qreal glyphCacheScaleY = cache->transform().m22();
qreal glyphCacheInverseScaleX = 1.0 / glyphCacheScaleX;
qreal glyphCacheInverseScaleY = 1.0 / glyphCacheScaleY;
Q_ASSERT(geometry->indexType() == GL_UNSIGNED_SHORT);
geometry->allocate(glyphIndexes.size() * 4, glyphIndexes.size() * 6);
QVector4D *vp = (QVector4D *)geometry->vertexDataAsTexturedPoint2D();
Q_ASSERT(geometry->sizeOfVertex() == sizeof(QVector4D));
ushort *ip = geometry->indexDataAsUShort();
QPointF position(p.x(), p.y() - m_font.ascent());
bool supportsSubPixelPositions = fontD->fontEngine->supportsSubPixelPositions();
for (int i=0; i<glyphIndexes.size(); ++i) {
QFixed subPixelPosition;
if (supportsSubPixelPositions)
subPixelPosition = fontD->fontEngine->subPixelPositionForX(QFixed::fromReal(glyphPositions.at(i).x()));
QTextureGlyphCache::GlyphAndSubPixelPosition glyph(glyphIndexes.at(i), subPixelPosition);
const QTextureGlyphCache::Coord &c = cache->coords.value(glyph);
QPointF glyphPosition = glyphPositions.at(i) + position;
// On a retina screen the glyph positions are not pre-scaled (as opposed to
// eg. the raster paint engine). To ensure that we get the same behavior as
// the raster engine (and CoreText itself) when it comes to rounding of the
// coordinates, we need to apply the scale factor before rounding, and then
// apply the inverse scale to get back to the coordinate system of the node.
qreal x = (qFloor(glyphPosition.x() * glyphCacheScaleX) * glyphCacheInverseScaleX) +
(c.baseLineX * glyphCacheInverseScaleX) - margin;
qreal y = (qRound(glyphPosition.y() * glyphCacheScaleY) * glyphCacheInverseScaleY) -
(c.baseLineY * glyphCacheInverseScaleY) - margin;
qreal w = c.w * glyphCacheInverseScaleX;
qreal h = c.h * glyphCacheInverseScaleY;
*boundingRect |= QRectF(x + margin, y + margin, w, h);
float cx1 = x - margins.left();
float cx2 = x + w + margins.right();
float cy1 = y - margins.top();
float cy2 = y + h + margins.bottom();
float tx1 = c.x - margins.left();
float tx2 = c.x + c.w + margins.right();
float ty1 = c.y - margins.top();
float ty2 = c.y + c.h + margins.bottom();
if (baseLine->isNull())
*baseLine = glyphPosition;
vp[4 * i + 0] = QVector4D(cx1, cy1, tx1, ty1);
vp[4 * i + 1] = QVector4D(cx2, cy1, tx2, ty1);
vp[4 * i + 2] = QVector4D(cx1, cy2, tx1, ty2);
vp[4 * i + 3] = QVector4D(cx2, cy2, tx2, ty2);
int o = i * 4;
ip[6 * i + 0] = o + 0;
ip[6 * i + 1] = o + 2;
ip[6 * i + 2] = o + 3;
ip[6 * i + 3] = o + 3;
ip[6 * i + 4] = o + 1;
ip[6 * i + 5] = o + 0;
}
}
示例10: AMnDIndex
bool AMExporter2DAscii::prepareDataSources()
{
// This is a much stricter function than AMExporterGeneralAscii. Only 2D data sources are allowed (and when we figure out the spectra files, then also 3D).
mainTableDataSources_.clear();
mainTableIncludeX_.clear();
separateSectionDataSources_.clear();
separateSectionIncludeX_.clear();
separateFileDataSources_.clear();
separateFileIncludeX_.clear();
if (option_->includeAllDataSources() && option_->firstColumnOnly()){
bool includeFirstColumn = true;
for (int i = 0; i < currentScan_->dataSourceCount(); i++){
switch(currentScan_->dataSourceAt(i)->rank()){
// No 0D or 1D data sources.
case 0:
case 1:
return false;
case 2:
mainTableDataSources_ << i;
mainTableIncludeX_ << includeFirstColumn; // X and Y.
if (includeFirstColumn)
includeFirstColumn = false;
break;
case 3:
if (option_->includeHigherDimensionSources())
separateFileDataSources_ << i;
break;
}
}
int xRange = currentScan_->scanSize(0);
int yRange = currentScan_->scanSize(1);
QVector<double> fillerData = QVector<double>(yRange);
currentScan_->dataSourceAt(0)->values(AMnDIndex(xRange-1,0), AMnDIndex(xRange-1, yRange-1), fillerData.data());
for (int j = 0; j < yRange && yRange_ == -1; j++)
if (fillerData.at(j) == -1)
yRange_ = j+1; // The +1 is because we want the next row.
if (yRange_ != -1){
fillerData = QVector<double>(xRange);
currentScan_->dataSourceAt(0)->values(AMnDIndex(0, yRange_-1), AMnDIndex(xRange-1, yRange_-1), fillerData.data());
for (int i = 0; i < xRange && xIndex_ == -1; i++)
if (fillerData.at(i) == -1)
xIndex_ = i;
}
}
// There isn't much to a simple 2D map. Put the X and Y in the first column and then put all the rest of the data. I don't have any other options right now.
else
return false;
return true;
}
示例11: initializeVertexBuffer
void QGLView::initializeVertexBuffer(ModelType type, const QVector<ModelVertex> &vertices)
{
initializeVertexBuffer(type, vertices.data(), vertices.length() * sizeof(ModelVertex));
}
示例12: dmga_master_loop
void US_MPI_Analysis::dmga_master_loop( void )
{
static const double DIGIT_FIT = 1.0e+4;
static const int min_generation = 10;
static const int _KS_BASE_ = 6;
static const int _KS_STEP_ = 3;
QString dbgtext = parameters[ "debug_text" ];
QString s_ksbase = par_key_value( dbgtext, "ksame_base" );
QString s_ksstep = par_key_value( dbgtext, "ksame_step" );
int ks_base = s_ksbase.isEmpty() ? _KS_BASE_ : s_ksbase.toInt();
int ks_step = s_ksstep.isEmpty() ? _KS_STEP_ : s_ksstep.toInt();
ks_base = qMax( 2, ks_base );
ks_step = qMax( 1, ks_step );
// static const int max_same_count = my_workers * 5;
int max_same_count = ( ks_base + ( nfloatc / ks_step ) * ks_step )
* my_workers;
int avg_generation = 0;
bool early_termination = false;
int fitness_same_count = 0;
double best_overall_fitness = LARGE;
int tag;
int workers = my_workers;
DbgLv(1) << "dmga_master start loop: gcores_count fitsize" << gcores_count
<< best_fitness.size() << "best_overall" << best_overall_fitness;
DbgLv(0) << "dmga_master start loop: nfloatc max_same_count"
<< nfloatc << max_same_count << "ks_base ks_step" << ks_base << ks_step;
// Reset best fitness for each worker
for ( int i = 0; i < gcores_count; i++ )
{
best_fitness[ i ].fitness = LARGE;
best_fitness[ i ].index = i;
}
QList < DGene > emigres; // Holds genes passed as emmigrants
QVector< int > v_generations( gcores_count, 0 );
int sum = 0;
int avg = 0;
long rsstotal = 0L;
double fit_power = 5;
double fit_digit = 1.0e4;
double fitness_round = 1.0e5;
while ( workers > 0 )
{
MPI_GA_MSG msg;
MPI_Status status;
int worker;
MPI_Recv( &msg, // Get a message MPI #1
sizeof( msg ),
MPI_BYTE,
MPI_ANY_SOURCE,
MPI_ANY_TAG,
my_communicator,
&status );
worker = status.MPI_SOURCE;
max_rss();
switch ( status.MPI_TAG )
{
case GENERATION:
v_generations[ worker ] = msg.generation;
sum = 0;
for ( int i = 1; i <= my_workers; i++ )
sum += v_generations[ i ];
avg = qRound( (double)sum / (double)my_workers ) + 1;
if ( avg > avg_generation )
{
avg_generation = avg;
int mc_iter = mgroup_count < 2 ? ( mc_iteration + 1 )
: mc_iteration;
QString progress =
"Avg. Generation: " + QString::number( avg_generation );
if ( data_sets.size() > 1 )
{
if ( datasets_to_process == 1 )
progress += "; Dataset: "
+ QString::number( current_dataset + 1 )
+ " of " + QString::number( count_datasets );
else
progress += "; Datasets: "
+ QString::number( datasets_to_process );
}
progress += "; MonteCarlo: " + QString::number( mc_iter );
if ( best_overall_fitness != LARGE && best_overall_fitness > 0.0 )
progress += "; RMSD: "
+ QString::number( sqrt( best_overall_fitness ) );
send_udp( progress );
}
//.........这里部分代码省略.........
示例13: RenderContour
void SegmentGL::RenderContour(Segment *seg, QMatrix4x4 projection, QMatrix4x4 modelview, int width, int height)
{
QVector3D vec;
QVector3D pos;
QVector<GLfloat> positions;
QEci qeci;
CalculateSegmentContour(&positions, seg->cornerpointfirst1.latitude, seg->cornerpointfirst1.longitude, seg->cornerpointlast1.latitude, seg->cornerpointlast1.longitude);
CalculateSegmentContour(&positions,seg->cornerpointlast1.latitude, seg->cornerpointlast1.longitude, seg->cornerpointlast2.latitude, seg->cornerpointlast2.longitude);
CalculateSegmentContour(&positions, seg->cornerpointlast2.latitude, seg->cornerpointlast2.longitude, seg->cornerpointfirst2.latitude, seg->cornerpointfirst2.longitude);
CalculateSegmentContour(&positions,seg->cornerpointfirst2.latitude, seg->cornerpointfirst2.longitude, seg->cornerpointfirst1.latitude, seg->cornerpointfirst1.longitude);
seg->qsgp4->getPosition(seg->minutes_since_state_vector, qeci);
QGeodetic qgeo = qeci.ToGeo();
double lat1 = qgeo.latitude;
double lon1 = qgeo.longitude;
seg->qsgp4->getPosition(seg->minutes_since_state_vector + seg->minutes_sensing, qeci);
qgeo = qeci.ToGeo();
double lat2 = qgeo.latitude;
double lon2 = qgeo.longitude;
CalculateSegmentContour(&positions, lat1, lon1, lat2, lon2);
positionsBuf.bind();
positionsBuf.write(0, positions.data(), positions.size() * sizeof(GLfloat));
positionsBuf.release();
QOpenGLVertexArrayObject::Binder vaoBinder(&vao);
program->bind();
program->setUniformValue("MVP", projection * modelview);
QColor rendercolor(opts.satsegmentcolor);
QColor rendercolorsel(opts.satsegmentcolorsel);
if((*seg).segmentselected)
program->setUniformValue("outcolor", QVector4D(rendercolorsel.redF(), rendercolorsel.greenF(), rendercolorsel.blueF(), 1.0f));
else
program->setUniformValue("outcolor", QVector4D(rendercolor.redF(), rendercolor.greenF(), rendercolor.blueF(), 1.0f));
QMatrix3x3 norm = modelview.normalMatrix();
program->setUniformValue("NormalMatrix", norm);
glDrawArrays(GL_LINE_LOOP, 0, nbrOfVertices - 10);
glDrawArrays(GL_LINE_STRIP, nbrOfVertices - 10, 10);
float mvmatrix[16], projmatrix[16];
QMatrix4x4 MVP;
MVP = projection * modelview;
float *ptr = modelview.data();
for(int i = 0; i < 16; i++)
mvmatrix[i] = *(ptr + i);
ptr = projection.data();
for(int i = 0; i < 16; i++)
projmatrix[i] = *(ptr + i);
QVector2D win;
LonLat2PointRad((float)seg->cornerpointfirst1.latitude, (float)seg->cornerpointfirst1.longitude, &vec, 1.0);
win = glhProjectf (vec, mvmatrix, projmatrix, width, height);
seg->winvecend1 = win;
LonLat2PointRad((float)seg->cornerpointfirst2.latitude, (float)seg->cornerpointfirst2.longitude, &vec, 1.0);
win = glhProjectf (vec, mvmatrix, projmatrix, width, height);
seg->winvecend2 = win;
LonLat2PointRad((float)seg->cornerpointlast1.latitude, (float)seg->cornerpointlast1.longitude, &vec, 1.0);
win = glhProjectf (vec, mvmatrix, projmatrix, width, height);
seg->winvecend3 = win;
LonLat2PointRad((float)seg->cornerpointlast2.latitude, (float)seg->cornerpointlast2.longitude, &vec, 1.0);
win = glhProjectf (vec, mvmatrix, projmatrix, width, height);
seg->winvecend4 = win;
win = glhProjectf (seg->vec1, mvmatrix, projmatrix, width, height);
seg->winvec1 = win;
win = glhProjectf (seg->vec2, mvmatrix, projmatrix, width, height);
seg->winvec2 = win;
}
示例14: buildLogDiv
bool ScaleDiv::buildLogDiv(int maxMajSteps, int maxMinSteps, double majStep)
{
double firstTick, lastTick;
double lFirst, lLast;
double val, sval, minStep, minFactor;
int nMaj, nMin, minSize, i, k, k0, kstep, kmax, i0;
bool rv = true;
double width;
QVector<double> buffer;
// Parameter range check
maxMajSteps = MusECore::qwtMax(1, MusECore::qwtAbs(maxMajSteps));
maxMinSteps = MusECore::qwtMax(0, MusECore::qwtAbs(maxMinSteps));
majStep = MusECore::qwtAbs(majStep);
// boundary check
limRange(d_hBound, LOG_MIN, LOG_MAX);
limRange(d_lBound, LOG_MIN, LOG_MAX);
// reset vectors
d_minMarks.resize(0);
d_majMarks.resize(0);
if (d_lBound == d_hBound) return true;
// scale width in decades
width = log10(d_hBound) - log10(d_lBound);
// scale width is less than one decade -> build linear scale
if (width < 1.0)
{
rv = buildLinDiv(maxMajSteps, maxMinSteps, 0.0);
// convert step width to decades
if (d_majStep > 0)
d_majStep = log10(d_majStep);
return rv;
}
//
// Set up major scale divisions
//
if (majStep == 0.0)
d_majStep = MusECore::qwtCeil125( width * 0.999999 / double(maxMajSteps));
else
d_majStep = majStep;
// major step must be >= 1 decade
d_majStep = MusECore::qwtMax(d_majStep, 1.0);
lFirst = ceil((log10(d_lBound) - step_eps * d_majStep) / d_majStep) * d_majStep;
lLast = floor((log10(d_hBound) + step_eps * d_majStep) / d_majStep) * d_majStep;
firstTick = pow10(lFirst);
lastTick = pow10(lLast);
nMaj = MusECore::qwtMin(10000, int(rint(MusECore::qwtAbs(lLast - lFirst) / d_majStep)) + 1);
d_majMarks.resize(nMaj);
MusECore::qwtLogSpace(d_majMarks.data(), d_majMarks.size(), firstTick, lastTick);
//
// Set up minor scale divisions
//
if ((d_majMarks.size() < 1) || (maxMinSteps < 1)) return true; // no minor marks
if (d_majStep < 1.1) // major step width is one decade
{
if (maxMinSteps >= 8)
{
k0 = 2;
kmax = 9;
kstep = 1;
minSize = (d_majMarks.size() + 1) * 8;
}
else if (maxMinSteps >= 4)
{
k0 = 2;
kmax = 8;
kstep = 2;
minSize = (d_majMarks.size() + 1) * 4;
}
else if (maxMinSteps >= 2)
{
k0 = 2;
kmax = 5;
kstep = 3;
minSize = (d_majMarks.size() + 1) * 2;
}
else
{
k0 = 5;
kmax = 5;
kstep = 1;
minSize = (d_majMarks.size() + 1);
//.........这里部分代码省略.........
示例15: updateStatus
bool
PowerTapDevice::download( const QDir &tmpdir,
QList<DeviceDownloadFile> &files,
QString &err)
{
if (!dev->open(err)) {
err = tr("ERROR: open failed: ") + err;
return false;
}
// make several attempts at reading the version
int attempts = 3;
int veridx = -1;
int version_len;
char vbuf[256];
QByteArray version;
do {
if (!doWrite(dev, 0x56, false, err)) // 'V'
return false;
emit updateStatus( tr("Reading version...") );
if(m_Cancelled) {
err = tr("download cancelled");
return false;
}
version_len = readUntilNewline(dev, vbuf, sizeof(vbuf), err);
if (version_len < 0) {
err = tr("Error reading version: ") + err;
return false;
}
if (PT_DEBUG) {
printf("read version \"%s\"\n",
cEscape(vbuf, version_len).toLatin1().constData());
}
version = QByteArray(vbuf, version_len);
// We expect the version string to be something like
// "VER 02.21 PRO...", so if we see two V's, it's probably
// because there's a hardware echo going on.
veridx = version.indexOf("VER");
} while ((--attempts > 0) && (veridx < 0));
if (veridx < 0) {
err = QString(tr("Unrecognized version \"%1\""))
.arg(cEscape(vbuf, version_len));
return false;
}
bool hwecho = version.indexOf('V') < veridx;
if (PT_DEBUG) printf("hwecho=%s\n", hwecho ? "true" : "false");
emit updateStatus( tr("Reading header...") );
if(m_Cancelled) {
err = tr("download cancelled");
return false;
}
if (!doWrite(dev, 0x44, hwecho, err)) // 'D'
return false;
unsigned char header[6];
int header_len = dev->read(header, sizeof(header), err);
if (header_len != 6) {
if (header_len < 0)
err = tr("ERROR: reading header: ") + err;
else
err = tr("ERROR: timeout reading header");
return false;
}
if (PT_DEBUG) {
printf("read header \"%s\"\n",
cEscape((char*) header,
sizeof(header)).toLatin1().constData());
}
QVector<unsigned char> records;
for (size_t i = 0; i < sizeof(header); ++i)
records.append(header[i]);
emit updateStatus( tr("Reading data...") );
if(m_Cancelled) {
err = tr("download cancelled");
return false;
}
double recIntSecs = 0.0;
fflush(stdout);
while (true) {
if (PT_DEBUG) printf("reading block\n");
unsigned char buf[256 * 6 + 1];
int n = dev->read(buf, 2, err);
if (n < 2) {
if (n < 0)
err = tr("ERROR: reading first two: ") + err;
else
err = tr("ERROR: timeout reading first two");
return false;
}
if (PT_DEBUG) {
printf("read 2 bytes: \"%s\"\n",
cEscape((char*) buf, 2).toLatin1().constData());
//.........这里部分代码省略.........