示例#1
0
void VtkVisPipeline::setBGColor(const QColor &color)
{
    QSettings settings;
    settings.setValue("VtkBackgroundColor", color);
    _renderer->SetBackground(color.redF(), color.greenF(), color.blueF());
}
void QVGPixmapColorizeFilter::draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect) const
{
    if (src.isNull())
        return;

    if (src.pixmapData()->classId() != QPixmapData::OpenVGClass) {
        // The pixmap data is not an instance of QVGPixmapData, so fall
        // back to the default colorize filter implementation.
        QPixmapColorizeFilter::draw(painter, dest, src, srcRect);
        return;
    }

    QVGPixmapData *pd = static_cast<QVGPixmapData *>(src.pixmapData());

    VGImage srcImage = pd->toVGImage();
    if (srcImage == VG_INVALID_HANDLE)
        return;

    QSize size = pd->size();
    VGImage dstImage = QVGImagePool::instance()->createTemporaryImage
        (VG_sARGB_8888_PRE, size.width(), size.height(),
         VG_IMAGE_QUALITY_FASTER, pd);
    if (dstImage == VG_INVALID_HANDLE)
        return;

    // Determine the weights for the matrix from the color and strength.
    QColor c = color();
    VGfloat strength = this->strength();
    VGfloat weights[3];
    VGfloat invweights[3];
    VGfloat alpha = c.alphaF();
    weights[0] = c.redF() * alpha;
    weights[1] = c.greenF() * alpha;
    weights[2] = c.blueF() * alpha;
    invweights[0] = (1.0f - weights[0]) * strength;
    invweights[1] = (1.0f - weights[1]) * strength;
    invweights[2] = (1.0f - weights[2]) * strength;

    // Grayscale weights.
    static const VGfloat redGray = 11.0f / 32.0f;
    static const VGfloat greenGray = 16.0f / 32.0f;
    static const VGfloat blueGray = 1.0f - (redGray + greenGray);

    VGfloat matrix[5][4];
    matrix[0][0] = redGray * invweights[0] + (1.0f - strength);
    matrix[0][1] = redGray * invweights[1];
    matrix[0][2] = redGray * invweights[2];
    matrix[0][3] = 0.0f;
    matrix[1][0] = greenGray * invweights[0];
    matrix[1][1] = greenGray * invweights[1] + (1.0f - strength);
    matrix[1][2] = greenGray * invweights[2];
    matrix[1][3] = 0.0f;
    matrix[2][0] = blueGray * invweights[0];
    matrix[2][1] = blueGray * invweights[1];
    matrix[2][2] = blueGray * invweights[2] + (1.0f - strength);
    matrix[2][3] = 0.0f;
    matrix[3][0] = 0.0f;
    matrix[3][1] = 0.0f;
    matrix[3][2] = 0.0f;
    matrix[3][3] = 1.0f;
    matrix[4][0] = weights[0] * strength;
    matrix[4][1] = weights[1] * strength;
    matrix[4][2] = weights[2] * strength;
    matrix[4][3] = 0.0f;

    vgColorMatrix(dstImage, srcImage, matrix[0]);

    VGImage child = VG_INVALID_HANDLE;

    if (srcRect.isNull() ||
        (srcRect.topLeft().isNull() && srcRect.size() == size)) {
        child = dstImage;
    } else {
        QRect src = srcRect.toRect();
        child = vgChildImage(dstImage, src.x(), src.y(), src.width(), src.height());
    }

    qt_vg_drawVGImage(painter, dest, child);

    if(child != dstImage)
        vgDestroyImage(child);
    QVGImagePool::instance()->releaseImage(0, dstImage);
}
示例#3
0
 void setColor(QColor c) {
   float alpha = c.alphaF();
   glColor4f(c.redF() * alpha, c.greenF() * alpha, c.blueF() * alpha, alpha);
 }
void KoRgbU16ColorSpace::fromQColor(const QColor& c, quint8 *dst, const KoColorProfile * /*profile*/) const
{
    QVector<float> channelValues;
    channelValues << c.blueF() << c.greenF() << c.redF() << c.alphaF();
    fromNormalisedChannelsValue(dst, channelValues);
}
示例#5
0
	// copied from openframeworks superfast blur and modified
	void applyTo(QImage &mask, const QColor &color, int radius) {
		if (radius < 1 || mask.isNull())
			return;
		setSize(mask.size());
		setRadius(radius);
		const int w = s.width();
		const int h = s.height();

		uchar *a = valpha.data();
		const uchar *inv = vinv.constData();
		int *min = vmin.data();
		int *max = vmax.data();

		const int xmax = mask.width()-1;
		for (int x=0; x<w; ++x) {
			min[x] = qMin(x + radius + 1, xmax);
			max[x] = qMax(x - radius, 0);
		}

		const uchar *c_bits = mask.constBits()+3;
		uchar *it = a;
		for (int y=0; y<h; ++y, c_bits += (mask.width() << 2)) {
			int sum = 0;
			for(int i=-radius; i<=radius; ++i)
				sum += c_bits[qBound(0, i, xmax) << 2];
			for (int x=0; x<w; ++x, ++it) {
				sum += c_bits[min[x] << 2];
				sum -= c_bits[max[x] << 2];
				*it = inv[sum];
			}
		}

		const int ymax = mask.height()-1;
		for (int y=0; y<h; ++y){
			min[y] = qMin(y + radius + 1, ymax)*w;
			max[y] = qMax(y - radius, 0)*w;
		}

		uchar *bits = mask.bits();
		const double coef = color.alphaF();
		const double r = color.redF()*coef;
		const double g = color.greenF()*coef;
		const double b = color.blueF()*coef;
		const uchar *c_it = a;
		for (int x=0; x<w; ++x, ++c_it){
			int sum = 0;
			int yp = -radius*w;
			for(int i=-radius; i<=radius; ++i, yp += w)
				sum += c_it[qMax(0, yp)];
			uchar *p = bits + (x << 2);
			for (int y=0; y<h; ++y, p += (xmax << 2)){
				const uchar a = inv[sum];
				if (p[3] < 255) {
					*p++ = a*b;
					*p++ = a*g;
					*p++ = a*r;
					*p++ = a*coef;
				} else {
					p += 4;
				}
				sum += c_it[min[y]];
				sum -= c_it[max[y]];
			}
		}
	}
示例#6
0
void XMLizer::writeFilter( QDomDocument &document, QDomNode &parent, bool audio, QSharedPointer<Filter> f )
{
	QString s = audio ? "AudioFilter" : "VideoFilter";
	QDomElement n1 = document.createElement( s );
	parent.appendChild( n1 );

	createText( document, n1, "Name", f->getIdentifier() );
	createDouble( document, n1, "PosInTrack", f->getPosition() );
	if ( f->getPositionOffset() > 0 )
		createDouble( document, n1, "PosOffset", f->getPositionOffset() );
	createDouble( document, n1, "Length", f->getLength() );
	createInt( document, n1, "SnapMode", f->getSnap() );
	
	QList<Parameter*> params = f->getParameters();
	for ( int i = 0; i < params.count(); ++i ) {
		Parameter *p = params[i];
		QDomElement pel = document.createElement( "Parameter" );
		n1.appendChild( pel );
		pel.setAttribute( "name", p->id );
		switch ( p->type ) {
			case Parameter::PDOUBLE: {
				pel.setAttribute( "type", "double" );
				pel.setAttribute( "value", QString::number( p->value.toDouble(), 'e', 17 ) );
				break;
			}
			case Parameter::PINPUTDOUBLE: {
				pel.setAttribute( "type", "inputdouble" );
				pel.setAttribute( "value", QString::number( p->value.toDouble(), 'e', 17 ) );
				break;
			}
			case Parameter::PINT: {
				pel.setAttribute( "type", "int" );
				pel.setAttribute( "value", QString::number( p->value.toInt() ) );
				break;
			}
			case Parameter::PBOOL: {
				pel.setAttribute( "type", "bool" );
				pel.setAttribute( "value", QString::number( p->value.toInt() ) );
				break;
			}
			case Parameter::PRGBCOLOR: {
				pel.setAttribute( "type", "rgb" );
				pel.setAttribute( "value", p->value.value<QColor>().name() );
				break;
			}
			case Parameter::PRGBACOLOR: {
				QColor col = p->value.value<QColor>();
				pel.setAttribute( "type", "rgba" );
				pel.setAttribute( "value", col.name() + "." + QString::number( col.alpha() ) );
				break;
			}
			case Parameter::PCOLORWHEEL: {
				QColor col = p->value.value<QColor>();
				pel.setAttribute( "type", "colorwheel" );
				pel.setAttribute( "value", QString::number( col.blueF(), 'e', 17 ) );
				pel.setAttribute( "hue", QString::number( col.redF(), 'e', 17 ) );
				pel.setAttribute( "saturation", QString::number( col.greenF(), 'e', 17 ) );
				break;
			}
			case Parameter::PSTRING: {
				pel.setAttribute( "type", "string" );
				pel.setAttribute( "value", p->value.toString().replace( "\n", QString::fromUtf8("¶") ) );
				break;
			}
			case Parameter::PSHADEREDIT: {
				pel.setAttribute( "type", "shader" );
				pel.setAttribute( "value", Parameter::getShaderName( p->value.toString() ) );
				break;
			}
			case Parameter::PSTATUS: {
				pel.setAttribute( "type", "status" );
				pel.setAttribute( "value", "" );
				break;
			}
		}
		
		for ( int i = 0; i < p->graph.keys.count(); ++i ) {
			QDomElement ke = document.createElement( "Key" );
			pel.appendChild( ke );
			QString type;
			switch ( p->graph.keys[i].keyType ) {
				case AnimationKey::CONSTANT: type = "constant"; break;
				case AnimationKey::CURVE: type = "curve"; break;
				default: type = "linear";
			}
			ke.setAttribute( "type", type );
			ke.setAttribute( "position", QString::number( p->graph.keys[i].x, 'e', 17 ) );
			ke.setAttribute( "value", QString::number( p->getUnnormalizedKeyValue( i ), 'e', 17 ) );
		}
	}
}
示例#7
0
void AdaptiveGrid::setColor(const QColor & color)
{
	m_program->bind();
    m_program->setUniformValue("color", QVector3D(color.redF(), color.greenF(), color.blueF()));
	m_program->release();
}
示例#8
0
QString GLC_WorldTo3dxml::colorToString(const QColor& color)
{
	return QString('[' + QString::number(color.redF()) + ',' + QString::number(color.greenF()) + ',' + QString::number(color.blueF()) + ']');
}
void tst_QColor::setRgb()
{
    QColor color;

    for (int A = 0; A <= USHRT_MAX; ++A) {
        {
            // 0-255
            int a = A >> 8;
            QRgb rgb = qRgba(0, 0, 0, a);

            color.setRgb(0, 0, 0, a);
            QCOMPARE(color.alpha(), a);
            QCOMPARE(color.rgb(),  qRgb(0, 0, 0));

            color.setRgb(rgb);
            QCOMPARE(color.alpha(), 255);
            QCOMPARE(color.rgb(),   qRgb(0, 0, 0));

            int r, g, b, a2;
            color.setRgb(0, 0, 0, a);
            color.getRgb(&r, &g, &b, &a2);
            QCOMPARE(a2, a);

            QColor c(0, 0, 0);
            c.setAlpha(a);
            QCOMPARE(c.alpha(), a);
        }

        {
            // 0.0-1.0
            qreal a = A / qreal(USHRT_MAX);
            color.setRgbF(0.0, 0.0, 0.0, a);
            QCOMPARE(color.alphaF(), a);

            qreal r, g, b, a2;
            color.getRgbF(&r, &g, &b, &a2);
            QCOMPARE(a2, a);

            QColor c(0, 0, 0);
            c.setAlphaF(a);

            QCOMPARE(c.alphaF(), a);
        }
    }

    for (int R = 0; R <= USHRT_MAX; ++R) {
        {
            // 0-255
            int r = R >> 8;
            QRgb rgb = qRgb(r, 0, 0);

            color.setRgb(r, 0, 0);
            QCOMPARE(color.red(), r);
            QCOMPARE(color.rgb(), rgb);

            color.setRgb(rgb);
            QCOMPARE(color.red(), r);
            QCOMPARE(color.rgb(), rgb);

            int r2, g, b, a;
            color.getRgb(&r2, &g, &b, &a);
            QCOMPARE(r2, r);
        }

        {
            // 0.0-1.0
            qreal r = R / qreal(USHRT_MAX);
            color.setRgbF(r, 0.0, 0.0);
            QCOMPARE(color.redF(), r);

            qreal r2, g, b, a;
            color.getRgbF(&r2, &g, &b, &a);
            QCOMPARE(r2, r);
        }
    }

    for (int G = 0; G <= USHRT_MAX; ++G) {
        {
            // 0-255
            int g = G >> 8;
            QRgb rgb = qRgb(0, g, 0);

            color.setRgb(0, g, 0);
            QCOMPARE(color.green(), g);
            QCOMPARE(color.rgb(),   rgb);

            color.setRgb(rgb);
            QCOMPARE(color.green(), g);
            QCOMPARE(color.rgb(),   rgb);

            int r, g2, b, a;
            color.getRgb(&r, &g2, &b, &a);
            QCOMPARE(g2, g);
        }

        {
            // 0.0-1.0
            qreal g = G / qreal(USHRT_MAX);
            color.setRgbF(0.0, g, 0.0);
            QCOMPARE(color.greenF(), g);

            qreal r, g2, b, a;
            color.getRgbF(&r, &g2, &b, &a);
            QCOMPARE(g2, g);
        }
    }

    for (int B = 0; B <= USHRT_MAX; ++B) {
        {
            // 0-255
            int b = B >> 8;
            QRgb rgb = qRgb(0, 0, b);

            color.setRgb(0, 0, b);
            QCOMPARE(color.blue(),  b);
            QCOMPARE(color.rgb(),   rgb);

            color.setRgb(rgb);
            QCOMPARE(color.blue(),  b);
            QCOMPARE(color.rgb(),   rgb);

            int r, g, b2, a;
            color.getRgb(&r, &g, &b2, &a);
            QCOMPARE(b2, b);
        }

        {
            // 0.0-1.0
            qreal b = B / qreal(USHRT_MAX);
            color.setRgbF(0.0, 0.0, b);
            QCOMPARE(color.blueF(), b);

            qreal r, g, b2, a;
            color.getRgbF(&r, &g, &b2, &a);
            QCOMPARE(b2, b);
        }
    }
}
示例#10
0
QString ShaderCodeGenerator::writeVarName(const DinSocket *insocket)
{
    if(!insocket->getCntdSocket()){
        QString value;
        QColor col;
        double fl;
        int i;
        Vector v;
        switch(insocket->getType().getType())
        {
            case COLOR:
                col = insocket->getProperty().getData<QColor>();
                value = "color(";
                value += QString::number(col.redF()) + ", ";
                value += QString::number(col.greenF()) + ", ";
                value += QString::number(col.blueF()) + ")";
                break;
            case FLOAT:
                fl = insocket->getProperty().getData<float>();
                value = QString::number(fl);
                break;
            case STRING:
                value = insocket->getProperty().getData<QString>();
                break;
            case INTEGER:
                i = insocket->getProperty().getData<int>();
                value = QString::number(i);
                break;
            case VECTOR:
                v = insocket->getProperty().getData<Vector>();
                value = "vector(";
                value += QString::number(v.x) + ", ";
                value += QString::number(v.y) + ", ";
                value += QString::number(v.z) + ")";
                break;
            case POINT:
                v = insocket->getProperty().getData<Vector>();
                value = "point(";
                value += QString::number(v.x) + ", ";
                value += QString::number(v.y) + ", ";
                value += QString::number(v.z) + ")";
                break;
            case NORMAL:
                v = insocket->getProperty().getData<Vector>();
                value = "normal(";
                value += QString::number(v.x) + ", ";
                value += QString::number(v.y) + ", ";
                value += QString::number(v.z) + ")";
                break;
            default:
                break;
        }
        return value;
    }

    const DoutSocket *prevsocket = insocket->getCntdSocket();
    const DNode *node = prevsocket->getNode();

    switch(node->getNodeType())
    {
        case COLORNODE:
            return writeColor(prevsocket);
        case FLOATNODE:
            return writeFloat(prevsocket);
        case STRINGNODE:
            return writeString(prevsocket);
        case VECTORNODE:
            return writeVector(prevsocket);
        case ADD:
        case SUBTRACT:
        case MULTIPLY:
        case DIVIDE:
        case DOTPRODUCT:
            return createMath(prevsocket);
        case GREATERTHAN:
        case SMALLERTHAN:
        case EQUAL:
        case AND:
        case OR:
        case NOT:
            return createCondition(prevsocket);
        case CONTAINER:
            return writeVarName(node->getDerivedConst<ContainerNode>()->getSocketInContainer(prevsocket)->toIn());
        case INSOCKETS:
            return writeVarName(node->getDerivedConst<SocketNode>()->getContainer()->getSocketOnContainer(prevsocket)->toIn());
        default:
            return getVariable(prevsocket);
    }
}
示例#11
0
void
TextRenderer::renderText(float x,
                         float y,
                         float scalex,
                         float scaley,
                         const QString &text,
                         const QColor &color,
                         const QFont &font) const
{
    glCheckError();
    boost::shared_ptr<TextRendererPrivate> p;
    FontRenderers::iterator it = _imp->renderers.find(font);
    if ( it != _imp->renderers.end() ) {
        p  = (*it).second;
    } else {
        p = boost::shared_ptr<TextRendererPrivate>( new TextRendererPrivate(font) );
        _imp->renderers[font] = p;
    }
    assert(p);

    GLuint savedTexture;
    glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint*)&savedTexture);
    {
        GLProtectAttrib a(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT | GL_TRANSFORM_BIT);
        GLProtectMatrix pr(GL_MODELVIEW);

        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glEnable(GL_TEXTURE_2D);
        GLuint texture = 0;

        glTranslatef(x, y, 0);
        glColor4f( color.redF(), color.greenF(), color.blueF(), color.alphaF() );
        for (int i = 0; i < text.length(); ++i) {
            CharBitmap *c = p->createCharacter(text[i]);
            if (!c) {
                continue;
            }
            if (texture != c->texID) {
                texture = c->texID;
                glBindTexture(GL_TEXTURE_2D, texture);
                assert( glIsTexture(texture) );
            }
            glCheckError();
            glBegin(GL_QUADS);
            glTexCoord2f(c->xTexCoords[0], c->yTexCoords[0]);
            glVertex2f(0, 0);
            glTexCoord2f(c->xTexCoords[1], c->yTexCoords[0]);
            glVertex2f(c->w * scalex, 0);
            glTexCoord2f(c->xTexCoords[1], c->yTexCoords[1]);
            glVertex2f(c->w * scalex, c->h * scaley);
            glTexCoord2f(c->xTexCoords[0], c->yTexCoords[1]);
            glVertex2f(0, c->h * scaley);
            glEnd();
            glCheckErrorIgnoreOSXBug();
            glTranslatef(c->w * scalex, 0, 0);
            glCheckError();
        }
    } // GLProtectAttrib a(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT | GL_TRANSFORM_BIT);
    glBindTexture(GL_TEXTURE_2D, savedTexture);

    glCheckError();
} // renderText
示例#12
0
void iA3DLabelledVolumeVis::renderLengthDistribution( vtkColorTransferFunction* ctFun, vtkFloatArray* extents, double halfInc, int filterID, double const * range )
{
	// clear existing points
	oTF->RemoveAllPoints();
	cTF->RemoveAllPoints();
	cTF->AddRGBPoint(0, 0.0, 0.0, 0.0);

	for ( size_t objID = 0; objID < m_objectTable->GetNumberOfRows(); ++objID )
	{
		double ll = m_objectTable->GetValue(objID, m_columnMapping->value(iACsvConfig::Length)).ToDouble();
		QColor color = getLengthColor( ctFun, objID );

		if ( filterID == iAFeatureScoutObjectType::Fibers )
		{
			if ( ll >= range[0] && ll < extents->GetValue( 0 ) + halfInc )
			{
				oTF->AddPoint( objID + 1 - 0.5, 0.0 );
				oTF->AddPoint( objID + 1 + 0.3, 0.0 );
				oTF->AddPoint( objID + 1, 1.0 );
			}
			else if ( ll >= extents->GetValue( 0 ) + halfInc && ll < extents->GetValue( 1 ) + halfInc )
			{
				oTF->AddPoint( objID + 1 - 0.5, 0.0 );
				oTF->AddPoint( objID + 1 + 0.3, 0.0 );
				oTF->AddPoint( objID + 1, 0.03 );
			}
			else if ( ll >= extents->GetValue( 1 ) + halfInc && ll < extents->GetValue( 2 ) + halfInc )
			{
				oTF->AddPoint( objID + 1 - 0.5, 0.0 );
				oTF->AddPoint( objID + 1 + 0.3, 0.0 );
				oTF->AddPoint( objID + 1, 0.03 );
			}
			else if ( ll >= extents->GetValue( 2 ) + halfInc && ll < extents->GetValue( 5 ) + halfInc )
			{
				oTF->AddPoint( objID + 1 - 0.5, 0.0 );
				oTF->AddPoint( objID + 1 + 0.3, 0.0 );
				oTF->AddPoint( objID + 1, 0.015 );
			}
			else if ( ll >= extents->GetValue( 5 ) + halfInc && ll <= extents->GetValue( 7 ) + halfInc )
			{
				oTF->AddPoint( objID + 1 - 0.5, 0.0 );
				oTF->AddPoint( objID + 1 + 0.3, 0.0 );
				oTF->AddPoint( objID + 1, 1.0 );
			}
		}
		else
		{
			if ( ll >= range[0] && ll < extents->GetValue( 0 ) + halfInc )
			{
				oTF->AddPoint( objID + 1 - 0.5, 0.0 );
				oTF->AddPoint( objID + 1 + 0.3, 0.0 );
				oTF->AddPoint( objID + 1, 0.5 );
			}
			else if ( ll >= extents->GetValue( 0 ) + halfInc && ll < extents->GetValue( 1 ) + halfInc )
			{
				oTF->AddPoint( objID + 1 - 0.5, 0.0 );
				oTF->AddPoint( objID + 1 + 0.3, 0.0 );
				oTF->AddPoint( objID + 1, 0.5 );
			}
			else if ( ll >= extents->GetValue( 5 ) + halfInc && ll <= extents->GetValue( 2 ) + halfInc )
			{
				oTF->AddPoint( objID + 1 - 0.5, 0.0 );
				oTF->AddPoint( objID + 1 + 0.3, 0.0 );
				oTF->AddPoint( objID + 1, 0.5 );
			}
		}
		cTF->AddRGBPoint( objID + 1, color.redF(), color.greenF(), color.blueF() );
		cTF->AddRGBPoint( objID + 1 - 0.5, color.redF(), color.greenF(), color.blueF() );
		cTF->AddRGBPoint( objID + 1 + 0.3, color.redF(), color.greenF(), color.blueF() );
	}
	updateRenderer();
}
示例#13
0
void iA3DLabelledVolumeVis::renderSelection( std::vector<size_t> const & sortedSelInds, int classID, QColor const & classColor, QStandardItem* activeClassItem )
{
	QColor BackColor(128, 128, 128, 0);
	double backRGB[3];
	backRGB[0] = BackColor.redF(); backRGB[1] = BackColor.greenF(); backRGB[2] = BackColor.blueF(); // background color
	double red = 0.0, green = 0.0, blue = 0.0, alpha = 0.5, backAlpha = 0.00, classRGB[3], selRGB[3];
	selRGB[0] = SelectedColor.redF();
	selRGB[1] = SelectedColor.greenF();
	selRGB[2] = SelectedColor.blueF();
	classRGB[0] = classColor.redF();
	classRGB[1] = classColor.greenF();
	classRGB[2] = classColor.blueF();

	// clear existing points
	oTF->RemoveAllPoints();
	cTF->RemoveAllPoints();
	oTF->ClampingOff();
	cTF->ClampingOff();
	oTF->AddPoint( 0, backAlpha, 0.5, 1.0 );
	cTF->AddRGBPoint( 0, backRGB[0], backRGB[1], backRGB[2], 0.5, 1.0 );

	int hid = 0, next_hid = 1, prev_hid = -1, selectionIndex = 0, previous_selectionIndex = 0;
	bool starting = false, hid_isASelection = false, previous_hid_isASelection = false;

	int countClass = activeClassItem->rowCount();
	int countSelection = sortedSelInds.size();
	for ( size_t j = 0; j < countClass; ++j )
	{
		hid = activeClassItem->child( j )->text().toInt();

		if ( countSelection > 0 )
		{
			if (hid-1 == sortedSelInds[selectionIndex] )
			{
				hid_isASelection = true;
				red = SelectedColor.redF(), green = SelectedColor.greenF(), blue = SelectedColor.blueF();

				if ( selectionIndex + 1 < sortedSelInds.size() )
					selectionIndex++;
			}
			else
			{
				hid_isASelection = false;
				red = classRGB[0]; green = classRGB[1]; blue = classRGB[2];
			}

			if ( prev_hid > 0 )
			{
				if (prev_hid-1 == sortedSelInds[previous_selectionIndex])
				{
					previous_hid_isASelection = true;

					if ( previous_selectionIndex + 1 < sortedSelInds.size())
						previous_selectionIndex++;
				}
				else
					previous_hid_isASelection = false;
			}
		}
		else
		{
			red = classRGB[0]; green = classRGB[1]; blue = classRGB[2];
		}

		// If we are not yet at the last object (of the class) get the next hid
		if ( ( j + 1 ) < countClass )
		{
			next_hid = activeClassItem->child( j + 1 )->text().toInt();
		}
		else	// If hid = the last object (of the class) we have to set the last object points
		{
			if ( starting )	// If we are in a sequence we have to set the ending (\)
			{
				oTF->AddPoint( hid - 1 + 0.3, alpha, 0.5, 1.0 );
				oTF->AddPoint( hid - 0.5, alpha, 0.5, 1.0 );
				oTF->AddPoint( hid, alpha, 0.5, 1.0 );
				oTF->AddPoint( hid + 0.3, backAlpha, 0.5, 1.0 );

				if ( hid_isASelection )
				{
					cTF->AddRGBPoint( hid - 0.5, 1.0, 0.0, 0.0, 0.5, 1.0 );
					cTF->AddRGBPoint( hid, 1.0, 0.0, 0.0, 0.5, 1.0 );
					cTF->AddRGBPoint( hid + 0.3, backRGB[0], backRGB[1], backRGB[2], 0.5, 1.0 );
				}
				else
				{
					cTF->AddRGBPoint( hid - 0.5, classRGB[0], classRGB[1], classRGB[2], 0.5, 1.0 );
					cTF->AddRGBPoint( hid, classRGB[0], classRGB[1], classRGB[2], 0.5, 1.0 );
					cTF->AddRGBPoint( hid + 0.3, backRGB[0], backRGB[1], backRGB[2], 0.5, 1.0 );
				}

				if ( previous_hid_isASelection )
					cTF->AddRGBPoint( hid - 1 + 0.3, 1.0, 0.0, 0.0, 0.5, 1.0 );
				else
					cTF->AddRGBPoint( hid - 1 + 0.3, classRGB[0], classRGB[1], classRGB[2], 0.5, 1.0 );
				break;
			}
			else	// if we are not in a sequence we have to create the last tooth (/\)
			{
				oTF->AddPoint( hid - 0.5, backAlpha, 0.5, 1.0 );
				oTF->AddPoint( hid, alpha, 0.5, 1.0 );
				oTF->AddPoint( hid + 0.3, backAlpha, 0.5, 1.0 );

				cTF->AddRGBPoint( hid - 0.5, backRGB[0], backRGB[1], backRGB[2], 0.5, 1.0 );
				cTF->AddRGBPoint( hid, red, green, blue, 0.5, 1.0 );
				cTF->AddRGBPoint( hid + 0.3, backRGB[0], backRGB[1], backRGB[2], 0.5, 1.0 );
				break;
			}
		}

		if ( next_hid > hid + 1 && !starting )		//Create one single tooth
		{
			oTF->AddPoint( hid - 0.5, backAlpha, 0.5, 1.0 );
			oTF->AddPoint( hid, alpha, 0.5, 1.0 );
			oTF->AddPoint( hid + 0.3, backAlpha, 0.5, 1.0 );
			cTF->AddRGBPoint( hid - 0.5, backRGB[0], backRGB[1], backRGB[2], 0.5, 1.0 );
			cTF->AddRGBPoint( hid, red, green, blue, 0.5, 1.0 );
			cTF->AddRGBPoint( hid + 0.3, backRGB[0], backRGB[1], backRGB[2], 0.5, 1.0 );
		}
		else if ( next_hid == hid + 1 && !starting )	//Creates the beginning of a sequence (/)
		{
			starting = true;
			oTF->AddPoint( hid - 0.5, backAlpha, 0.5, 1.0 );
			oTF->AddPoint( hid, alpha, 0.5, 1.0 );
			cTF->AddRGBPoint( hid - 0.5, backRGB[0], backRGB[1], backRGB[2], 0.5, 1.0 );
			cTF->AddRGBPoint( hid, red, green, blue, 0.5, 1.0 );
		}
		else if ( next_hid == hid + 1 && starting )	//Continues the started sequence (-)
		{
			if ( !hid_isASelection && previous_hid_isASelection )
			{
				cTF->AddRGBPoint( hid - 1 + 0.3, selRGB[0], selRGB[1], selRGB[2], 0.5, 1.0 );
				cTF->AddRGBPoint( hid - 0.5, classRGB[0], classRGB[1], classRGB[2], 0.5, 1.0 );
				cTF->AddRGBPoint( hid + 0.3, classRGB[0], classRGB[1], classRGB[2], 0.5, 1.0 );

				oTF->AddPoint( hid - 1 + 0.3, alpha, 0.5, 1.0 );
				oTF->AddPoint( hid - 0.5, alpha, 0.5, 1.0 );
				oTF->AddPoint( hid + 0.3, alpha, 0.5, 1.0 );
			}
			else if ( hid_isASelection && !previous_hid_isASelection )
			{
				cTF->AddRGBPoint( hid - 0.5, selRGB[0], selRGB[1], selRGB[2], 0.5, 1.0 );
				cTF->AddRGBPoint( hid + 0.3, selRGB[0], selRGB[1], selRGB[2], 0.5, 1.0 );
				cTF->AddRGBPoint( hid - 1 + 0.3, classRGB[0], classRGB[1], classRGB[2], 0.5, 1.0 );

				oTF->AddPoint( hid - 0.5, alpha, 0.5, 1.0 );
				oTF->AddPoint( hid + 0.3, alpha, 0.5, 1.0 );
				oTF->AddPoint( hid - 1 + 0.3, alpha, 0.5, 1.0 );
			}
		}
		else if ( next_hid > hid + 1 && starting )	//  (\)
		{
			starting = false;

			oTF->AddPoint( hid - 1 + 0.3, alpha, 0.5, 1.0 );
			oTF->AddPoint( hid - 0.5, alpha, 0.5, 1.0 );
			oTF->AddPoint( hid, alpha, 0.5, 1.0 );
			oTF->AddPoint( hid + 0.3, backAlpha, 0.5, 1.0 );

			if ( previous_hid_isASelection )
				cTF->AddRGBPoint( hid - 1 + 0.3, selRGB[0], selRGB[1], selRGB[2], 0.5, 1.0 );
			else
				cTF->AddRGBPoint( hid - 1 + 0.3, classRGB[0], classRGB[1], classRGB[2], 0.5, 1.0 );

			cTF->AddRGBPoint( hid - 0.5, red, green, blue, 0.5, 1.0 );
			cTF->AddRGBPoint( hid, red, green, blue, 0.5, 1.0 );
			cTF->AddRGBPoint( hid + 0.3, backRGB[0], backRGB[1], backRGB[2], 0.5, 1.0 );
		}
		prev_hid = hid;
	}

	if ( hid < m_objectTable->GetNumberOfRows() )	// Creates the very last points (for all objects)  if it's not created yet
	{
		oTF->AddPoint( m_objectTable->GetNumberOfRows() + 0.3, backAlpha, 0.5, 1.0 );
		cTF->AddRGBPoint( m_objectTable->GetNumberOfRows() + 0.3, backRGB[0], backRGB[1], backRGB[2], 0.5, 1.0 );
	}
	updateRenderer();
}
示例#14
0
void iA3DLabelledVolumeVis::renderSingle( int labelID, int classID, QColor const & classColor, QStandardItem* activeClassItem )
{
	int itemL = activeClassItem->rowCount();
	double red   = classColor.redF(),
		   green = classColor.greenF(),
		   blue  = classColor.blueF(),
		   alpha = 0.5,
		   backAlpha = 0.0,
		   backRGB[3] = { 0.0, 0.0, 0.0 };

	// clear existing points
	oTF->RemoveAllPoints();
	cTF->RemoveAllPoints();

	// set background opacity and color with clamping off
	oTF->ClampingOff();
	cTF->ClampingOff();
	oTF->AddPoint(0, backAlpha);
	cTF->AddRGBPoint(0, backRGB[0], backRGB[1], backRGB[2]);
	if ( labelID > 0 ) // for single object selection
	{
		if ( (labelID - 1) >= 0)
		{
			oTF->AddPoint(labelID - 0.5, backAlpha);
			oTF->AddPoint(labelID - 0.49, alpha);
			cTF->AddRGBPoint(labelID - 0.5, backRGB[0], backRGB[1], backRGB[2]);
			cTF->AddRGBPoint(labelID - 0.49, red, green, blue);
		}
		oTF->AddPoint(labelID, alpha);
		cTF->AddRGBPoint(labelID, red, green, blue);
		if ((labelID + 1) <= m_objectTable->GetNumberOfRows())
		{
			oTF->AddPoint(labelID + 0.3, backAlpha);
			oTF->AddPoint(labelID + 0.29, alpha);
			cTF->AddRGBPoint(labelID + 0.3, backRGB[0], backRGB[1], backRGB[2]);
			cTF->AddRGBPoint(labelID + 0.29, red, green, blue);
		}
	}
	else // for single class selection
	{
		int hid = 0, next_hid = 1;
		bool starting = false;
		for ( int j = 0; j < itemL; ++j )
		{
			hid = activeClassItem->child( j, 0 )->text().toInt();

			if ( j + 1 < itemL )
				next_hid = activeClassItem->child( j + 1, 0 )->text().toInt();
			else
			{
				if ( starting )
				{
					oTF->AddPoint( hid, alpha, 0.5, 1.0 );
					oTF->AddPoint( hid + 0.3, backAlpha, 0.5, 1.0 );
					cTF->AddRGBPoint( hid, red, green, blue, 0.5, 1.0 );
					cTF->AddRGBPoint( hid + 0.3, backRGB[0], backRGB[1], backRGB[2], 0.5, 1.0 );
					break;
				}
				else
				{
					oTF->AddPoint( hid - 0.5, backAlpha, 0.5, 1.0 );
					oTF->AddPoint( hid, alpha, 0.5, 1.0 );
					cTF->AddRGBPoint( hid - 0.5, backRGB[0], backRGB[1], backRGB[2], 0.5, 1.0 );
					cTF->AddRGBPoint( hid, red, green, blue, 0.5, 1.0 );
					oTF->AddPoint( hid + 0.3, backAlpha, 0.5, 1.0 );
					cTF->AddRGBPoint( hid + 0.3, backRGB[0], backRGB[1], backRGB[2], 0.5, 1.0 );
					break;
				}
			}

			//Create one single tooth
			if ( next_hid > hid + 1 && !starting )
			{
				oTF->AddPoint( hid - 0.5, backAlpha, 0.5, 1.0 );
				oTF->AddPoint( hid, alpha, 0.5, 1.0 );
				oTF->AddPoint( hid + 0.3, backAlpha, 0.5, 1.0 );
				cTF->AddRGBPoint( hid - 0.5, backRGB[0], backRGB[1], backRGB[2], 0.5, 1.0 );
				cTF->AddRGBPoint( hid, red, green, blue, 0.5, 1.0 );
				cTF->AddRGBPoint( hid + 0.3, backRGB[0], backRGB[1], backRGB[2], 0.5, 1.0 );
			}
			else if ( next_hid == hid + 1 && !starting )
			{
				starting = true;
				oTF->AddPoint( hid - 0.5, backAlpha, 0.5, 1.0 );
				oTF->AddPoint( hid, alpha, 0.5, 1.0 );
				cTF->AddRGBPoint( hid - 0.5, backRGB[0], backRGB[1], backRGB[2], 0.5, 1.0 );
				cTF->AddRGBPoint( hid, red, green, blue, 0.5, 1.0 );
			}
			else if ( next_hid == hid + 1 && starting )
				continue;
			else if ( next_hid > hid + 1 && starting )
			{
				starting = false;
				oTF->AddPoint( hid, alpha, 0.5, 1.0 );
				oTF->AddPoint( hid + 0.3, backAlpha, 0.5, 1.0 );
				cTF->AddRGBPoint( hid, red, green, blue, 0.5, 1.0 );
				cTF->AddRGBPoint( hid + 0.3, backRGB[0], backRGB[1], backRGB[2], 0.5, 1.0 );
			}
		}

		if ( hid < m_objectTable->GetNumberOfRows() )
		{
			oTF->AddPoint( m_objectTable->GetNumberOfRows() + 0.3, backAlpha, 0.5, 1.0 );
			cTF->AddRGBPoint( m_objectTable->GetNumberOfRows() + 0.3, backRGB[0], backRGB[1], backRGB[2], 0.5, 1.0 );
		}
	}
	updateRenderer();
}
示例#15
0
inline void glColor( const QColor & color )	{ glColor( color.redF(), color.greenF(), color.blueF(), color.alphaF() ); }
示例#16
0
 QVector4D ToVectorRGBA(QColor color)
 {
     return QVector4D(color.redF(), color.greenF(), color.blueF(), color.alphaF());
 }
示例#17
0
void S52References::print(void) {
  qDebug() << "";
  qDebug() << "Color Tables";
  qDebug() << "------------------------";
  qDebug() << "";
  for (int i = 0; i < color_tables.keys().size(); i++) {
    QString table_key =  color_tables.keys()[i];
    ColorTable* ct = color_tables[table_key];

    qDebug() << ct->name;
    qDebug() << ct->graphics_file;
    for (int j = 0; j < ct->colors.keys().size(); j++) {
      QString color_key =  ct->colors.keys()[j];
      QColor c = ct->colors[color_key];
      qDebug() << color_key << " (" << c.redF() << ", "
               << c.greenF() << ", " << c.blueF() << ")";
    }

    qDebug() << "";
  }

  qDebug() << "";
  qDebug() << "Lookups";
  qDebug() << "------------------------";
  qDebug() << "";
  for (int i = 0; i < lookups.keys().size(); i++) {
    int table_key =  lookups.keys()[i];
    LookUp* lp = lookups[table_key];

    qDebug() << lp->name;
    qDebug() << "id: " << lp->id;
    qDebug() << "rcid: " << lp->rcid;
    qDebug() << "type: " << lp->type;
    qDebug() << "disp_prio: " << lp->disp_prio;
    qDebug() << "radar_prio: " << lp->radar_prio;
    qDebug() << "table_name: " << lp->table_name;
    qDebug() << "instruction: " << lp->instruction;
    qDebug() << "display_cat: " << lp->display_cat;
    qDebug() << "comment: " << lp->comment;
    qDebug() << "attr_refs: " << lp->attr_refs;
    qDebug() << "";
  }

  qDebug() << "";
  qDebug() << "Line styles";
  qDebug() << "------------------------";
  qDebug() << "";
  for (int i = 0; i < line_styles.keys().size(); i++) {
    int table_key =  line_styles.keys()[i];
    LineStyle* ls = line_styles[table_key];

    qDebug() << ls->name;
    qDebug() << "rcid: " << ls->rcid;
    qDebug() << "description: " << ls->description;
    qDebug() << "color_ref: " << ls->color_ref;
    qDebug() << "vector size: " << ls->vector.size;
    qDebug() << "vector distance: " << ls->vector.distance;
    qDebug() << "vector origin: " << ls->vector.origin;
    qDebug() << "vector pivot: " << ls->vector.pivot;
    qDebug() << "vector hpgl: " << ls->vector.hpgl;

    qDebug() << "";
  }

  qDebug() << "";
  qDebug() << "Patterns";
  qDebug() << "------------------------";
  qDebug() << "";
  for (int i = 0; i < patterns.keys().size(); i++) {
    int table_key =  patterns.keys()[i];
    Pattern* pt = patterns[table_key];

    qDebug() << pt->name;
    qDebug() << "rcid: " << pt->rcid;
    qDebug() << "description: " << pt->description;
    qDebug() << "color_ref: " << pt->color_ref;
    qDebug() << "definition: " << pt->definition;
    qDebug() << "filltype: " << pt->filltype;
    qDebug() << "spacing: " << pt->spacing;
    qDebug() << "vector size: " << pt->vector.size;
    qDebug() << "vector distance: " << pt->vector.distance;
    qDebug() << "vector origin: " << pt->vector.origin;
    qDebug() << "vector pivot: " << pt->vector.pivot;
    qDebug() << "vector hpgl: " << pt->vector.hpgl;

    qDebug() << "";
  }

  qDebug() << "";
  qDebug() << "Symbols";
  qDebug() << "------------------------";
  qDebug() << "";
  for (int i = 0; i < symbols.keys().size(); i++) {
    QString table_key =  symbols.keys()[i];
    Symbol* sl = symbols[table_key];

    qDebug() << sl->name;
    qDebug() << "rcid: " << sl->rcid;
    qDebug() << "description: " << sl->description;
    qDebug() << "color_ref: " << sl->color_ref;
    qDebug() << "definition: " << sl->definition;

    qDebug() << "vector size: " << sl->vector.size;
    qDebug() << "vector distance: " << sl->vector.distance;
    qDebug() << "vector origin: " << sl->vector.origin;
    qDebug() << "vector pivot: " << sl->vector.pivot;
    qDebug() << "vector hpgl: " << sl->vector.hpgl;

    qDebug() << "bitmap size: " << sl->bitmap.size;
    qDebug() << "bitmap distance: " << sl->bitmap.distance;
    qDebug() << "bitmap origin: " << sl->bitmap.origin;
    qDebug() << "bitmap pivot: " << sl->bitmap.pivot;
    qDebug() << "bitmap graphics loc: " << sl->bitmap.graphics_location;

    qDebug() << "";
  }
}
void QSGTextMaskMaterialData::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect)
{
    Q_ASSERT(oldEffect == 0 || newEffect->type() == oldEffect->type());
    QSGTextMaskMaterial *material = static_cast<QSGTextMaskMaterial *>(newEffect);
    QSGTextMaskMaterial *oldMaterial = static_cast<QSGTextMaskMaterial *>(oldEffect);

    if (oldMaterial == 0 || material->color() != oldMaterial->color() || state.isOpacityDirty()) {
        QColor c = material->color();
        QVector4D color(c.redF(), c.greenF(), c.blueF(), c.alphaF());
        color *= state.opacity();
        program()->setUniformValue(m_color_id, color);

        if (oldMaterial == 0 || material->color() != oldMaterial->color()) {
            state.context()->functions()->glBlendColor(c.redF(),
                                                       c.greenF(),
                                                       c.blueF(),
                                                       c.alphaF());
        }
    }

    bool updated = material->ensureUpToDate();
    Q_ASSERT(material->texture());

    Q_ASSERT(oldMaterial == 0 || oldMaterial->texture());
    if (updated
            || oldMaterial == 0
            || oldMaterial->texture()->textureId() != material->texture()->textureId()) {
        program()->setUniformValue(m_textureScale_id, QVector2D(1.0 / material->cacheTextureWidth(),
                                                               1.0 / material->cacheTextureHeight()));
        glBindTexture(GL_TEXTURE_2D, material->texture()->textureId());

        // Set the mag/min filters to be nearest. We only need to do this when the texture
        // has been recreated.
        if (updated) {
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        }
    }

    if (state.isMatrixDirty()) {
        QMatrix4x4 transform = state.modelViewMatrix();
        qreal xTranslation = transform(0, 3);
        qreal yTranslation = transform(1, 3);

        // Remove translation and check identity to see if matrix is only translating.
        // If it is, we can round the translation to make sure the text is pixel aligned,
        // which is the only thing that works with GL_NEAREST filtering. Adding rotations
        // and scales to native rendered text is not a prioritized use case, since the
        // default rendering type is designed for that.
        transform(0, 3) = 0.0;
        transform(1, 3) = 0.0;
        if (transform.isIdentity()) {
            transform(0, 3) = qRound(xTranslation);
            transform(1, 3) = qRound(yTranslation);

            transform = state.projectionMatrix() * transform;
            program()->setUniformValue(m_matrix_id, transform);
        } else {
            program()->setUniformValue(m_matrix_id, state.combinedMatrix());
        }
    }
}
void GLC_Viewport::clearBackground(const QColor& color) const
{
	glClearColor(color.redF(), color.greenF(), color.blueF(), 1.0f);
}
QColor daltonize(const QColor & color, ColorVisionDeficiency deficiency)
{
    // http://www.daltonize.org/2010/05/there-is-not-just-one-color-blindness.html
    // http://www.color-blindness.com/2007/01/23/confusion-lines-of-the-cie-1931-color-space/
    // http://jfly.iam.u-tokyo.ac.jp/color

    struct CIEDeficiency
    {
        CIEDeficiency()
        : clm(0.0f)
        , clyi(0.0f)
        {
        }

        CIEDeficiency(const QVector2D & dcp, const QVector2D & begin, const QVector2D & end)
        : dcp(dcp)
        , begin(begin)
        , end(end)
        , clm((end[1] - begin[1]) / (end[0] - begin[0]))
        , clyi(begin[1] - begin[0] * clm)
        {
        }

        QVector2D dcp;  // dichromatic convergence points
        QVector2D begin;
        QVector2D end;
        float     clm;
        float     clyi; // "y-intercept" of axis (actually on the v-axis)
    };


    /* The following algorithm is based on: http://colorlab.wickline.org/colorblind/colorlab/

        The color_blind_sims() JavaScript function in the is copyright(c) 2000-2001
        by Matthew Wickline and the Human-Computer Interaction Resource Network (http://hcirn.com)
    */

    static const auto gamma = 2.2f;

    // D65 white point xyz coords http://en.wikipedia.org/wiki/Standard_illuminant
    static const QVector3D D65(0.312713f, 0.329016f, 0.358271f);

    // sRGB to/from XYZ for D65 http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
    static const auto XYZ = QMatrix4x4 {    // converts sRGB to XYZ
         0.4124564f,  0.3575761f,  0.1804375f,  0.f,
         0.2126729f,  0.7151522f,  0.0721750f,  0.f,
         0.0193339f,  0.1191920f,  0.9503041f,  0.f,
         0.0000000f,  0.0000000f,  0.0000000f,  1.f };
    static const auto RGB = QMatrix4x4{    // converts XYZ to sRGB
         3.2404542f, -1.5371385f, -0.4985314f,  0.f,
        -0.9692660f,  1.8760108f,  0.0415560f,  0.f,
         0.0556434f, -0.2040259f,  1.0572252f,  0.f,
         0.0000000f,  0.0000000f,  0.0000000f,  1.f };

    CIEDeficiency CIED;
    switch (deficiency)
    {
    case ColorVisionDeficiency::Protanope:
        CIED = CIEDeficiency({ 0.735f, 0.265f }, { 0.115807f, 0.073581f }, { 0.471899f, 0.527051f });
        break;
    case ColorVisionDeficiency::Deuteranope:
        CIED = CIEDeficiency({ 1.14f, -0.14f },  { 0.102776f, 0.102864f }, { 0.505845f, 0.493211f });
        break;
    case ColorVisionDeficiency::Tritanope:
        CIED = CIEDeficiency({ 0.171f, -0.003f }, { 0.045391f, 0.294976f }, { 0.665764f, 0.334011f });
        break;
    case ColorVisionDeficiency::Grayscale:
        {
            const auto gray = float{ qGray(color.rgb()) / 255.f };
            return QColor::fromRgbF(gray, gray, gray, color.alphaF());
        }
    case ColorVisionDeficiency::None:
    default:
        return color;
    };

    const auto crgb = QVector3D(pow(color.redF(), gamma), pow(color.greenF(), gamma), pow(color.blueF(), gamma));

    auto cxyz = QVector3D{ XYZ * crgb };
    const auto csum = 1.f / (cxyz[0] + cxyz[1] + cxyz[2]);

    const auto cuvY = QVector3D{ cxyz[0] * csum, cxyz[1] * csum, 0.f };

    // find neutral grey at this luminosity
    auto nxyz = QVector3D{ D65[0], 0.f, D65[2] };
    nxyz *= cxyz[1] / D65[1];

    // retrieve confusion line between color and the deficiency confusion point
    float clm;
    if (cuvY[0] < CIED.dcp[0])
        clm = (CIED.dcp[1] - cuvY[1]) / (CIED.dcp[0] - cuvY[0]);
    else
        clm = (cuvY[1] - CIED.dcp[1]) / (cuvY[0] - CIED.dcp[0]);

    const auto clyi = cuvY[1] - cuvY[0] * clm;

    // find the change in the u and v dimensions (no Y change)
    auto duvY = QVector3D{ 0.f, 0.f, 0.f };
    duvY[0] = (CIED.clyi - clyi) / (clm - CIED.clm);
    duvY[1] = (clm * duvY[0]) + clyi;

    // find the simulated color's XYZ coords
    const auto sxyz = QVector3D{ duvY[0] * cxyz[1] / duvY[1], cxyz[1], (1.f - (duvY[0] + duvY[1])) * cxyz[1] / duvY[1] };
    auto srgb = RGB * sxyz;

    // note the RGB differences between sim color and our neutral color
    const auto drgb = RGB * QVector3D(nxyz[0] - sxyz[0], 0.f, nxyz[2] - sxyz[2]);

    // find out how much to shift sim color toward neutral to fit in RGB space
    QVector3D argb;
    argb[0] = drgb[0] ? ((srgb[0] < 0 ? 0.f : 1.f) - srgb[0]) / drgb[0] : 0.f;
    argb[0] = drgb[1] ? ((srgb[1] < 0 ? 0.f : 1.f) - srgb[1]) / drgb[1] : 0.f;
    argb[0] = drgb[2] ? ((srgb[2] < 0 ? 0.f : 1.f) - srgb[2]) / drgb[2] : 0.f;

    const auto adjust = qMax<float>(qMax<float>(
        (argb[0] > 1.f || argb[0] < 0.f) ? 0.f : argb[0],
        (argb[1] > 1.f || argb[1] < 0.f) ? 0.f : argb[1]),
        (argb[2] > 1.f || argb[2] < 0.f) ? 0.f : argb[2]);

    // now shift *all* three proportional to the greatest shift...
    srgb += adjust * drgb;

    srgb[0] = pow(qBound<float>(0.f, srgb[0], 1.f), 1.f / gamma);
    srgb[1] = pow(qBound<float>(0.f, srgb[1], 1.f), 1.f / gamma);
    srgb[2] = pow(qBound<float>(0.f, srgb[2], 1.f), 1.f / gamma);

    return QColor::fromRgbF(srgb[0], srgb[1], srgb[2], color.alphaF());
}
QString colorToString(const QColor &color, ColorFormat format)
{
    QString ret;

    QString prefix;
    QString colorComponents;

    if (format == ColorFormat::QCssRgbUCharFormat) {
        prefix = QLatin1String("rgb(");
        colorComponents = QString::number(color.red()) + QLatin1String(", ")
                + QString::number(color.green()) + QLatin1String(", ")
                + QString::number(color.blue());

        qreal alpha = color.alphaF();
        if (alpha < 1.0) {
            prefix.insert(3, QLatin1Char('a'));
            colorComponents += QLatin1String(", ") + colorDoubleToQString(color.alphaF());
        }
    }
    if (format == ColorFormat::QCssRgbPercentFormat) {
        int rP = qRound(color.redF() * 100);
        int gP = qRound(color.greenF() * 100);
        int bP = qRound(color.blueF() * 100);

        prefix = QLatin1String("rgb(");
        colorComponents = QString::number(rP) + QChar::fromLatin1('%') + QLatin1String(", ")
                + QString::number(gP) + QChar::fromLatin1('%') + QLatin1String(", ")
                + QString::number(bP) + QChar::fromLatin1('%');

        qreal alpha = color.alphaF();

        if (alpha < 1.0) {
            prefix.insert(3, QLatin1Char('a'));
            colorComponents += QLatin1String(", ") + colorDoubleToQString(alpha);
        }
    }
    else if (format == ColorFormat::QssHsvFormat) {
        prefix = QLatin1String("hsv(");
        colorComponents = QString::number(color.hsvHue()) + QLatin1String(", ")
                + QString::number(color.hsvSaturation()) + QLatin1String(", ")
                + QString::number(color.value());

        int aP = qRound(color.alphaF() * 100);

        if (aP < 100) {
            prefix.insert(3, QLatin1Char('a'));
            colorComponents += QLatin1String(", ") + colorDoubleToQString(aP);
        }
    }
    else if (format == ColorFormat::CssHslFormat) {
        prefix = QLatin1String("hsl(");

        int sP = qRound(color.hslSaturationF() * 100);
        int lP = qRound(color.lightnessF() * 100);

        colorComponents = QString::number(color.hslHue()) + QLatin1String(", ")
                + QString::number(sP) + QChar::fromLatin1('%') + QLatin1String(", ")
                + QString::number(lP) + QChar::fromLatin1('%');

        qreal alpha = color.alphaF();
        if (alpha < 1.0) {
            prefix.insert(3, QLatin1Char('a'));
            colorComponents += QLatin1String(", ") + colorDoubleToQString(color.alphaF());
        }
    }
    else if (format == ColorFormat::QmlRgbaFormat) {
        prefix = QLatin1String("Qt.rgba(");
        colorComponents = colorDoubleToQString(color.redF()) + QLatin1String(", ")
                + colorDoubleToQString(color.greenF()) + QLatin1String(", ")
                + colorDoubleToQString(color.blueF()) + QLatin1String(", ")
                + colorDoubleToQString(color.alphaF());
    }
    else if (format == ColorFormat::QmlHslaFormat) {
        prefix = QLatin1String("Qt.hsla(");
        colorComponents = colorDoubleToQString(color.hueF()) + QLatin1String(", ")
                + colorDoubleToQString(color.saturationF()) + QLatin1String(", ")
                + colorDoubleToQString(color.lightnessF()) + QLatin1String(", ")
                + colorDoubleToQString(color.alphaF());
    }
    else if (format == ColorFormat::GlslFormat) {
        prefix = QLatin1String("vec");

        colorComponents = colorDoubleToQString(color.redF()) + QLatin1String(", ")
                + colorDoubleToQString(color.greenF()) + QLatin1String(", ")
                + colorDoubleToQString(color.blueF());

        qreal alpha = color.alphaF();
        if (alpha < 1.0) {
            prefix.append(QLatin1Char('4'));
            colorComponents += QLatin1String(", ") + colorDoubleToQString(color.alphaF());
        } else {
            prefix.append(QLatin1Char('3'));
        }

        prefix.append(QLatin1Char('('));
    }
    else if (format == ColorFormat::HexFormat) {
        prefix = QLatin1String("#");

        int alpha = color.alpha();

        if (alpha < 255)
            colorComponents.sprintf("%02x%02x%02x%02x", alpha, color.red(), color.green(), color.blue());
        else
            colorComponents.sprintf("%02x%02x%02x", color.red(), color.green(), color.blue());

        colorComponents = colorComponents.toUpper();
    }

    Q_ASSERT(!prefix.isNull());
    Q_ASSERT(!colorComponents.isNull());

    ret = prefix + colorComponents;

    if (format != ColorFormat::HexFormat)
        ret += QChar::fromLatin1(')');

    Q_ASSERT_X(!ret.isNull(), Q_FUNC_INFO, "The string version of the color is invalid");

    return ret;
}
void QExperimental3DViewer::setBackgroundColor(QColor color)
{
    m_renderer->SetBackground(color.redF(), color.greenF(), color.blueF());
    render();
}
示例#23
0
Color BaseMetadata::QTColorToDAVAColor(const QColor& qtColor) const
{
    return Color(qtColor.redF(), qtColor.greenF(), qtColor.blueF(), qtColor.alphaF());
}
void
AnimationModuleViewPrivate::drawCurveEditorScale()
{
    glCheckError(GL_GPU);
    // always running in the main thread
    assert( qApp && qApp->thread() == QThread::currentThread() );

    QPointF btmLeft = curveEditorZoomContext.toZoomCoordinates(0, _publicInterface->height() - 1);
    QPointF topRight = curveEditorZoomContext.toZoomCoordinates(_publicInterface->width() - 1, 0);

    ///don't attempt to draw a scale on a widget with an invalid height/width
    if ( (_publicInterface->height() <= 1) || (_publicInterface->width() <= 1) ) {
        return;
    }

    QFontMetrics fontM = _publicInterface->fontMetrics();
    const double smallestTickSizePixel = 10.; // tick size (in pixels) for alpha = 0.
    const double largestTickSizePixel = 500.; // tick size (in pixels) for alpha = 1.
    double gridR, gridG, gridB;
    SettingsPtr sett = appPTR->getCurrentSettings();
    sett->getAnimationModuleEditorGridColor(&gridR, &gridG, &gridB);


    double scaleR, scaleG, scaleB;
    sett->getAnimationModuleEditorScaleColor(&scaleR, &scaleG, &scaleB);

    QColor scaleColor;
    scaleColor.setRgbF( Image::clamp(scaleR, 0., 1.),
                        Image::clamp(scaleG, 0., 1.),
                        Image::clamp(scaleB, 0., 1.) );


    {
        GLProtectAttrib<GL_GPU> a(GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT);

        GL_GPU::Enable(GL_BLEND);
        GL_GPU::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

        for (int axis = 0; axis < 2; ++axis) {
            const double rangePixel = (axis == 0) ? _publicInterface->width() : _publicInterface->height(); // AXIS-SPECIFIC
            const double range_min = (axis == 0) ? btmLeft.x() : btmLeft.y(); // AXIS-SPECIFIC
            const double range_max = (axis == 0) ? topRight.x() : topRight.y(); // AXIS-SPECIFIC
            const double range = range_max - range_min;
            double smallTickSize;
            bool half_tick;
            ticks_size(range_min, range_max, rangePixel, smallestTickSizePixel, &smallTickSize, &half_tick);
            int m1, m2;
            const int ticks_max = 1000;
            double offset;
            ticks_bounds(range_min, range_max, smallTickSize, half_tick, ticks_max, &offset, &m1, &m2);
            std::vector<int> ticks;
            ticks_fill(half_tick, ticks_max, m1, m2, &ticks);
            const double smallestTickSize = range * smallestTickSizePixel / rangePixel;
            const double largestTickSize = range * largestTickSizePixel / rangePixel;
            const double minTickSizeTextPixel = (axis == 0) ? fontM.width( QLatin1String("00") ) : fontM.height(); // AXIS-SPECIFIC
            const double minTickSizeText = range * minTickSizeTextPixel / rangePixel;
            for (int i = m1; i <= m2; ++i) {
                double value = i * smallTickSize + offset;
                const double tickSize = ticks[i - m1] * smallTickSize;
                const double alpha = ticks_alpha(smallestTickSize, largestTickSize, tickSize);

                glCheckError(GL_GPU);
                GL_GPU::Color4f(gridR, gridG, gridB, alpha);

                GL_GPU::Begin(GL_LINES);
                if (axis == 0) {
                    GL_GPU::Vertex2f( value, btmLeft.y() ); // AXIS-SPECIFIC
                    GL_GPU::Vertex2f( value, topRight.y() ); // AXIS-SPECIFIC
                } else {
                    GL_GPU::Vertex2f(btmLeft.x(), value); // AXIS-SPECIFIC
                    GL_GPU::Vertex2f(topRight.x(), value); // AXIS-SPECIFIC
                }
                GL_GPU::End();
                glCheckErrorIgnoreOSXBug(GL_GPU);

                if (tickSize > minTickSizeText) {
                    const int tickSizePixel = rangePixel * tickSize / range;
                    const QString s = QString::number(value);
                    const int sSizePixel = (axis == 0) ? fontM.width(s) : fontM.height(); // AXIS-SPECIFIC
                    if (tickSizePixel > sSizePixel) {
                        const int sSizeFullPixel = sSizePixel + minTickSizeTextPixel;
                        double alphaText = 1.0; //alpha;
                        if (tickSizePixel < sSizeFullPixel) {
                            // when the text size is between sSizePixel and sSizeFullPixel,
                            // draw it with a lower alpha
                            alphaText *= (tickSizePixel - sSizePixel) / (double)minTickSizeTextPixel;
                        }
                        alphaText = std::min(alphaText, alpha); // don't draw more opaque than tcks
                        QColor c = scaleColor;
                        c.setAlpha(255 * alphaText);
                        if (axis == 0) {
                            _publicInterface->renderText(value, btmLeft.y(), s.toStdString(), c.redF(), c.greenF(), c.blueF(), c.alphaF(), Qt::AlignHCenter);
                        } else {
                            _publicInterface->renderText(btmLeft.x(), value, s.toStdString(), c.redF(), c.greenF(), c.blueF(), c.alphaF(), Qt::AlignVCenter);
                        }
                    }
                }
            }
        }
    } // GLProtectAttrib a(GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT);


    glCheckError(GL_GPU);
    GL_GPU::Color4f(gridR, gridG, gridB, 1.);
    GL_GPU::Begin(GL_LINES);
    GL_GPU::Vertex2f(AXIS_MIN, 0);
    GL_GPU::Vertex2f(AXIS_MAX, 0);
    GL_GPU::Vertex2f(0, AXIS_MIN);
    GL_GPU::Vertex2f(0, AXIS_MAX);
    GL_GPU::End();


    glCheckErrorIgnoreOSXBug(GL_GPU);
} // drawCurveEditorScale
示例#25
0
/**
 * Add a mesh for the specified edge.
 */
void RoadGraph::addMeshFromEdge(RenderablePtr renderable, RoadEdgePtr edge, float widthBase, QColor color, float height) {
	Vertex v;

	// define the width of the road segment
	float width;
	switch (edge->type) {
	case RoadEdge::TYPE_HIGHWAY:
		width = widthBase * 2.0f;
		break;
	case RoadEdge::TYPE_BOULEVARD:
	case RoadEdge::TYPE_AVENUE:
		width = widthBase * 1.5f;
		break;
	case RoadEdge::TYPE_STREET:
		width = widthBase * 1.0f;
		break;
	}

	int num = edge->polyline.size();

	// draw the edge
	for (int i = 0; i < num - 1; ++i) {
		QVector2D pt1 = edge->polyline[i];
		QVector2D pt2 = edge->polyline[i + 1];
		QVector2D vec = pt2 - pt1;
		vec = QVector2D(-vec.y(), vec.x());
		vec.normalize();

		QVector2D p0 = pt1 + vec * width * 0.5f;
		QVector2D p1 = pt1 - vec * width * 0.5f;
		QVector2D p2 = pt2 - vec * width * 0.5f;
		QVector2D p3 = pt2 + vec * width * 0.5f;

		v.color[0] = color.redF();
		v.color[1] = color.greenF();
		v.color[2] = color.blueF();
		v.color[3] = color.alphaF();
		v.normal[0] = 0.0f;
		v.normal[1] = 0.0f;
		v.normal[2] = 1.0f;

		v.location[2] = height;

		v.location[0] = p0.x();
		v.location[1] = p0.y();
		renderable->vertices.push_back(v);

		v.location[0] = p1.x();
		v.location[1] = p1.y();
		renderable->vertices.push_back(v);

		v.location[0] = p2.x();
		v.location[1] = p2.y();
		renderable->vertices.push_back(v);

		v.location[0] = p0.x();
		v.location[1] = p0.y();
		renderable->vertices.push_back(v);

		v.location[0] = p2.x();
		v.location[1] = p2.y();
		renderable->vertices.push_back(v);

		v.location[0] = p3.x();
		v.location[1] = p3.y();
		renderable->vertices.push_back(v);
	}
}
示例#26
0
/*!
    Sets argument \a index for this kernel to \a value.

    The argument is assumed to have been declared with the
    type \c float4 as is passed the red, green, blue, and
    alpha components of \a value as floating-point values
    between 0 and 1.
*/
void QCLKernel::setArg(int index, const QColor &value)
{
    float values[4] =
    {value.redF(), value.greenF(), value.blueF(), value.alphaF()};
    clSetKernelArg(m_kernelId, index, sizeof(values), values);
}
示例#27
0
void
SplineInformation::save(fstream &fout)
{
  char keyword[100];
  int len;
  float *p;

  memset(keyword, 0, 100);
  sprintf(keyword, "splineinfostart");
  fout.write((char*)keyword, strlen(keyword)+1);

  memset(keyword, 0, 100);
  sprintf(keyword, "name");
  fout.write((char*)keyword, strlen(keyword)+1);
  len = m_name.size()+1;
  fout.write((char*)&len, sizeof(int));
  fout.write((char*)m_name.toAscii().data(), len*sizeof(char));

  memset(keyword, 0, 100);
  sprintf(keyword, "on");
  fout.write((char*)keyword, strlen(keyword)+1);
  len = m_on.count();
  fout.write((char*)&len, sizeof(int));
  for(int i=0; i<len; i++)
    fout.write((char*)&m_on[i], sizeof(bool));

  memset(keyword, 0, 100);
  sprintf(keyword, "points");
  fout.write((char*)keyword, strlen(keyword)+1);
  len = m_points.count();
  fout.write((char*)&len, sizeof(int));
  p = new float [2*len];
  for(int i=0; i<len; i++)
    {
      p[2*i] = m_points[i].x();
      p[2*i+1] = m_points[i].y();
    }
  fout.write((char*)p, 2*len*sizeof(float));
  delete [] p;


  memset(keyword, 0, 100);
  sprintf(keyword, "normalwidths");
  fout.write((char*)keyword, strlen(keyword)+1);
  len = m_points.count();
  fout.write((char*)&len, sizeof(int));
  p = new float [2*len];
  for(int i=0; i<len; i++)
    {
      p[2*i] = m_normalWidths[i].x();
      p[2*i+1] = m_normalWidths[i].y();
    }
  fout.write((char*)p, 2*len*sizeof(float));
  delete [] p;

  memset(keyword, 0, 100);
  sprintf(keyword, "normalrotations");
  fout.write((char*)keyword, strlen(keyword)+1);
  len = m_points.count();
  fout.write((char*)&len, sizeof(int));
  p = new float [len];
  for(int i=0; i<len; i++)
    {
      p[i] = m_normalRotations[i];
    }
  fout.write((char*)p, len*sizeof(float));
  delete [] p;

  memset(keyword, 0, 100);
  sprintf(keyword, "gradientstops");
  fout.write((char*)keyword, strlen(keyword)+1);
  len = m_gradientStops.count();
  fout.write((char*)&len, sizeof(int));
  p = new float [5*len];
  for(int i=0; i<len; i++)
    {
      float pos = m_gradientStops[i].first;
      QColor color = m_gradientStops[i].second;
      p[5*i] = pos;
      p[5*i+1] = color.redF();
      p[5*i+2] = color.greenF();
      p[5*i+3] = color.blueF();
      p[5*i+4] = color.alphaF();
    }
  fout.write((char*)p, 5*len*sizeof(float));
  delete [] p;


  memset(keyword, 0, 100);
  sprintf(keyword, "splineinfoend");
  fout.write((char*)keyword, strlen(keyword)+1);
}
示例#28
0
CaptionObject
CaptionObject::interpolate(CaptionObject& cap1,
			   CaptionObject& cap2,
			   float frc)
{
  bool ok = false;

  QString finalText = cap1.text();


  QStringList regExprs;
  regExprs << "\\$[n|N]\\(\\d*\\.*\\d*\\)";
  regExprs << "\\$[d|D]\\(\\d*\\.*\\d*\\)";
  for (int nr=0; nr<regExprs.count(); nr++)
    {
      QRegExp rx(regExprs[nr]);
      QStringList rem;
      QString txt;

      float val1;
      rx.indexIn(cap1.text());      
      txt = rx.cap();
      rem = txt.split(QRegExp("\\(|\\)"));
      if (rem.count() > 1) val1 = rem[1].toFloat();

      float val2;
      rx.indexIn(cap2.text());      
      txt = rx.cap();
      rem = txt.split(QRegExp("\\(|\\)"));
      if (rem.count() > 1) val2 = rem[1].toFloat();

      float val = (1-frc)*val1 + frc*val2;

      QString ftxt = QString("%1").arg(val, 0, 'f', Global::floatPrecision());
      if (Global::floatPrecision() > 0)
	{
	  QStringList frem = ftxt.split(".");
	  float fraction = frem[1].toFloat();
	  if (fraction < 0.00001)
	    ftxt = frem[0];
	}

      if (nr == 0)
	finalText.replace(rx, ftxt);
      else
	finalText.replace(rx, "$d("+ftxt+")");
      ok = true;
    }

  if (!ok &&
      cap1.text() != cap2.text())
    {
      // apply fadein-fadeout
      CaptionObject cap;

      if (frc <= 0.5)
	cap.setCaption(cap1);
      else
	cap.setCaption(cap2);
      
//      QColor c = cap.color();
//      float r = c.redF();
//      float g = c.greenF();
//      float b = c.blueF();
//      float a;
//
//      if (frc <= 0.5)
//	a = (1-frc)*c.alphaF();
//      else
//	a = frc*c.alphaF();      
//      c = QColor::fromRgbF(r,g,b,a);      
//      cap.setColor(c);
//
//      QColor hc = cap.haloColor();
//      r = hc.redF();
//      g = hc.greenF();
//      b = hc.blueF();
//      if (frc <= 0.5)
//	a = (1-frc)*hc.alphaF();
//      else
//	a = frc*hc.alphaF();
//      hc = QColor::fromRgbF(r,g,b,a);      
//      cap.setHaloColor(hc);

      return cap;
    }

  // interpolate position, color and font

  CaptionObject cap;

  QFont fnt = cap1.font();
  QFont fnt2 = cap2.font();

  if (fnt.family() == fnt2.family())
    {
      // interpolate pointsize
      int pt1 = fnt.pointSize();
      int pt2 = fnt2.pointSize();
      int pt = (1-frc)*pt1 + frc*pt2;
      fnt.setPointSize(pt);
    }

  // interpolate position
  QPointF pos1 = cap1.position();
  QPointF pos2 = cap2.position();
  QPointF pos = pos1-pos2;  
  if (fabs(pos.x()) > 5 || fabs(pos.y()) > 5 ) // more than 5 pixel change
    pos = (1-frc)*pos1 + frc*pos2;
  else
    {
      if (frc <0.5)
	pos = pos1;
      else
	pos = pos2;
    }

  // interpolate color
  QColor c = cap1.color();
  float r1 = c.redF();
  float g1 = c.greenF();
  float b1 = c.blueF();
  float a1 = c.alphaF();
  c = cap2.color();
  float r2 = c.redF();
  float g2 = c.greenF();
  float b2 = c.blueF();
  float a2 = c.alphaF();
  float r = (1-frc)*r1 + frc*r2;
  float g = (1-frc)*g1 + frc*g2;
  float b = (1-frc)*b1 + frc*b2;
  float a = (1-frc)*a1 + frc*a2;
  c = QColor(r*255, g*255, b*255, a*255);

  // interpolate halocolor
  QColor hc = cap1.haloColor();
  r1 = hc.redF();
  g1 = hc.greenF();
  b1 = hc.blueF();
  a1 = hc.alphaF();
  hc = cap2.haloColor();
  r2 = hc.redF();
  g2 = hc.greenF();
  b2 = hc.blueF();
  a2 = c.alphaF();
  r = (1-frc)*r1 + frc*r2;
  g = (1-frc)*g1 + frc*g2;
  b = (1-frc)*b1 + frc*b2;
  a = (1-frc)*a1 + frc*a2;
  hc = QColor(r*255, g*255, b*255, a*255);

  float angle = (1-frc)*cap1.angle() + frc*cap2.angle();
  cap.set(pos,
	  finalText,
	  fnt,
	  c, hc,
	  angle);

  return cap;
}
示例#29
0
void
CurveGui::drawCurve(int curveIndex,
                    int curvesCount)
{
    // always running in the main thread
    assert( qApp && qApp->thread() == QThread::currentThread() );

    AnimItemBasePtr item = _imp->item.lock();
    if (!item) {
        return;
    }

    std::vector<float> vertices, exprVertices;
    const double widgetWidth = _imp->curveWidget->width();
    KeyFrameSet keyframes;
    bool hasDrawnExpr = false;
    if (item->hasExpression(_imp->dimension, _imp->view)) {

        //we have no choice but to evaluate the expression at each time
        for (int i = 0; i < widgetWidth; ++i) {
            double x = _imp->curveWidget->toZoomCoordinates(i, 0).x();
            double y = evaluate(true /*useExpr*/, x);
            exprVertices.push_back(x);
            exprVertices.push_back(y);
        }
        hasDrawnExpr = true;

    }


    QPointF btmLeft = _imp->curveWidget->toZoomCoordinates(0, _imp->curveWidget->height() - 1);
    QPointF topRight = _imp->curveWidget->toZoomCoordinates(_imp->curveWidget->width() - 1, 0);

    


    bool isPeriodic = false;
    std::pair<double,double> parametricRange = std::make_pair(-std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity());

    keyframes = getInternalCurve()->getKeyFrames_mt_safe();
    isPeriodic = getInternalCurve()->isCurvePeriodic();
    parametricRange = getInternalCurve()->getXRange();

    if ( keyframes.empty() ) {
        // Add a horizontal line for constant knobs, except string knobs.
        KnobIPtr isKnob = boost::dynamic_pointer_cast<KnobI>(item->getInternalAnimItem());

        if (isKnob) {
            KnobStringBasePtr isString = boost::dynamic_pointer_cast<KnobStringBase>(isKnob);
            if (!isString) {
                double value = evaluate(false, 0);
                vertices.push_back(btmLeft.x() + 1);
                vertices.push_back(value);
                vertices.push_back(topRight.x() - 1);
                vertices.push_back(value);
            }
        }
    } else {
        try {
            double x1 = 0;
            double x2;

            bool isX1AKey = false;
            KeyFrame x1Key;
            KeyFrameSet::const_iterator lastUpperIt = keyframes.end();

            while ( x1 < (widgetWidth - 1) ) {
                double x, y;
                if (!isX1AKey) {
                    x = _imp->curveWidget->toZoomCoordinates(x1, 0).x();
                    y = evaluate(false, x);
                } else {
                    x = x1Key.getTime();
                    y = x1Key.getValue();
                }

                vertices.push_back( (float)x );
                vertices.push_back( (float)y );
                nextPointForSegment(x, keyframes, isPeriodic, parametricRange.first, parametricRange.second,  &lastUpperIt, &x2, &x1Key, &isX1AKey);
                x1 = x2;
            }
            //also add the last point
            {
                double x = _imp->curveWidget->toZoomCoordinates(x1, 0).x();
                double y = evaluate(false, x);
                vertices.push_back( (float)x );
                vertices.push_back( (float)y );
            }
        } catch (...) {
        }
    }

    // No Expr curve or no vertices for the curve, don't draw anything else
    if (exprVertices.empty() && vertices.empty()) {
        return;
    }

    AnimationModuleSelectionModelPtr selectionModel = item->getModel()->getSelectionModel();
    assert(selectionModel);
    const AnimItemDimViewKeyFramesMap& selectedKeys = selectionModel->getCurrentKeyFramesSelection();


    const KeyFrameSet* foundThisCurveSelectedKeys = 0;
    {
        AnimItemDimViewIndexID k;
        k.item = item;
        k.dim = _imp->dimension;
        k.view = _imp->view;
        AnimItemDimViewKeyFramesMap::const_iterator foundDimView = selectedKeys.find(k);

        if (foundDimView != selectedKeys.end()) {
            foundThisCurveSelectedKeys = &foundDimView->second;
        }
    }


    {
        GLProtectAttrib<GL_GPU> a(GL_HINT_BIT | GL_ENABLE_BIT | GL_LINE_BIT | GL_COLOR_BUFFER_BIT | GL_POINT_BIT | GL_CURRENT_BIT);

        // If this is the only curve selected, draw min/max
        if (foundThisCurveSelectedKeys && selectedKeys.size()) {

            // Draw y min/max axis so the user understands why the value is clamped
            Curve::YRange curveYRange = getCurveYRange();
            if (curveYRange.min != INT_MIN &&
                curveYRange.min != -std::numeric_limits<double>::infinity() &&
                curveYRange.max != INT_MAX &&
                curveYRange.max != std::numeric_limits<double>::infinity() ) {
                QColor minMaxColor;
                minMaxColor.setRgbF(0.398979, 0.398979, 0.398979);
                GL_GPU::Color4d(minMaxColor.redF(), minMaxColor.greenF(), minMaxColor.blueF(), 1.);
                GL_GPU::Begin(GL_LINES);
                GL_GPU::Vertex2d(btmLeft.x(), curveYRange.min);
                GL_GPU::Vertex2d(topRight.x(), curveYRange.min);
                GL_GPU::Vertex2d(btmLeft.x(), curveYRange.max);
                GL_GPU::Vertex2d(topRight.x(), curveYRange.max);
                GL_GPU::End();
                GL_GPU::Color4d(1., 1., 1., 1.);

                double xText = _imp->curveWidget->toZoomCoordinates(10, 0).x();

                _imp->curveWidget->renderText( xText, curveYRange.min, tr("min").toStdString(), minMaxColor.redF(), minMaxColor.greenF(), minMaxColor.blueF(), minMaxColor.alphaF());
                _imp->curveWidget->renderText( xText, curveYRange.max, tr("max").toStdString(), minMaxColor.redF(), minMaxColor.greenF(), minMaxColor.blueF(), minMaxColor.alphaF());
            }
        }


        GL_GPU::Color4f(_imp->color[0], _imp->color[1], _imp->color[2], _imp->color[3]);
        GL_GPU::PointSize(_imp->lineWidth);
        GL_GPU::Enable(GL_BLEND);
        GL_GPU::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        GL_GPU::Enable(GL_LINE_SMOOTH);
        GL_GPU::Hint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
        GL_GPU::LineWidth(1.5);
        glCheckError(GL_GPU);
        if (hasDrawnExpr) {
            drawLineStrip(exprVertices, btmLeft, topRight);
            GL_GPU::LineStipple(2, 0xAAAA);
            GL_GPU::Enable(GL_LINE_STIPPLE);
        }
        drawLineStrip(vertices, btmLeft, topRight);
        if (hasDrawnExpr) {
            GL_GPU::Disable(GL_LINE_STIPPLE);
        }

        glCheckErrorIgnoreOSXBug(GL_GPU);

        //render the name of the curve
        GL_GPU::Color4f(1.f, 1.f, 1.f, 1.f);


        double interval = ( topRight.x() - btmLeft.x() ) / (double)curvesCount;
        double textX = _imp->curveWidget->toZoomCoordinates(15, 0).x() + interval * (double)curveIndex;
        double textY;

        CurvePtr internalCurve = _imp->internalCurve.lock();
        QString curveName = getName();
        QColor thisColor;
        thisColor.setRgbF(Image::clamp(_imp->color[0], 0., 1.),
                          Image::clamp(_imp->color[1], 0., 1.),
                          Image::clamp(_imp->color[2], 0., 1.));

        try {
            // Use expression to place the text if the curve is not animated
            textY = evaluate(internalCurve && !internalCurve->isAnimated(), textX);
        } catch (...) {
            // if it fails attempt without expression, this will most likely return a constant value
            textY = evaluate(false /*useExpression*/, textX);
        }

        if ( ( textX >= btmLeft.x() ) && ( textX <= topRight.x() ) && ( textY >= btmLeft.y() ) && ( textY <= topRight.y() ) ) {
            _imp->curveWidget->renderText( textX, textY, curveName.toStdString(), thisColor.redF(), thisColor.greenF(), thisColor.blueF(), thisColor.alphaF());
        }
        GL_GPU::Color4f(_imp->color[0], _imp->color[1], _imp->color[2], _imp->color[3]);

        //draw keyframes
        GL_GPU::PointSize(7.f);
        GL_GPU::Enable(GL_POINT_SMOOTH);


        KeyFrameSet::const_iterator foundSelectedKey;
        if (foundThisCurveSelectedKeys) {
            foundSelectedKey = foundThisCurveSelectedKeys->end();
        }
        for (KeyFrameSet::const_iterator k = keyframes.begin(); k != keyframes.end(); ++k) {
            const KeyFrame & key = (*k);

            // Do not draw keyframes out of range
            if ( ( key.getTime() < btmLeft.x() ) || ( key.getTime() > topRight.x() ) || ( key.getValue() < btmLeft.y() ) || ( key.getValue() > topRight.y() ) ) {
                continue;
            }

            GL_GPU::Color4f(_imp->color[0], _imp->color[1], _imp->color[2], _imp->color[3]);

            bool drawKeySelected = false;
            if (foundThisCurveSelectedKeys) {
                KeyFrameSet::const_iterator start = foundSelectedKey == foundThisCurveSelectedKeys->end() ? foundThisCurveSelectedKeys->begin() : foundSelectedKey;
                foundSelectedKey = std::find_if(start, foundThisCurveSelectedKeys->end(), KeyFrameWithStringTimePredicate(key.getTime()));
                drawKeySelected = foundSelectedKey != foundThisCurveSelectedKeys->end();
                if (!drawKeySelected) {
                    // Also draw the keyframe as selected if it is inside the selection rectangle (but not yet selected)
                    RectD selectionRect = _imp->curveWidget->getSelectionRectangle();
                    drawKeySelected |= _imp->curveWidget->_imp->eventTriggeredFromCurveEditor && (!selectionRect.isNull() && selectionRect.contains(key.getTime(), key.getValue()));
                }
            }
            // If the key is selected change its color
            if (drawKeySelected) {
                GL_GPU::Color4f(0.8f, 0.8f, 0.8f, 1.f);
            }


            RectD keyframeBbox = _imp->curveWidget->_imp->getKeyFrameBoundingRectCanonical(_imp->curveWidget->_imp->curveEditorZoomContext, key.getTime(), key.getValue());

            // draw texture of the keyframe
            {
                AnimationModuleViewPrivate::KeyframeTexture texType = AnimationModuleViewPrivate::kfTextureFromKeyframeType( key.getInterpolation(), drawKeySelected);
                if (texType != AnimationModuleViewPrivate::kfTextureNone) {
                    _imp->curveWidget->_imp->drawTexturedKeyframe(texType, keyframeBbox, false /*drawdimed*/);
                }
            }

            
            // Draw tangents if not constant
            bool drawTangents = drawKeySelected && internalCurve->isYComponentMovable() && (key.getInterpolation() != eKeyframeTypeConstant);
            if (drawTangents) {
                QFontMetrics m( _imp->curveWidget->font());


                // If interpolation is not free and not broken display with dashes the tangents lines
                if ( (key.getInterpolation() != eKeyframeTypeFree) && (key.getInterpolation() != eKeyframeTypeBroken) ) {
                    GL_GPU::LineStipple(2, 0xAAAA);
                    GL_GPU::Enable(GL_LINE_STIPPLE);
                }
                
                QPointF leftTanPos, rightTanPos;
                _imp->curveWidget->getKeyTangentPoints(k, keyframes, &leftTanPos, &rightTanPos);

                // Draw the derivatives lines
                GL_GPU::Begin(GL_LINES);
                GL_GPU::Color4f(1., 0.35, 0.35, 1.);
                GL_GPU::Vertex2f( leftTanPos.x(), leftTanPos.y() );
                GL_GPU::Vertex2f(key.getTime(), key.getValue());
                GL_GPU::Vertex2f(key.getTime(), key.getValue());
                GL_GPU::Vertex2f( rightTanPos.x(), rightTanPos.y());
                GL_GPU::End();
                if ( (key.getInterpolation() != eKeyframeTypeFree) && (key.getInterpolation() != eKeyframeTypeBroken) ) {
                    GL_GPU::Disable(GL_LINE_STIPPLE);
                }


                // Draw the tangents handles
                GL_GPU::Begin(GL_POINTS);
                GL_GPU::Vertex2f( leftTanPos.x(), leftTanPos.y() );
                GL_GPU::Vertex2f( rightTanPos.x(), rightTanPos.y());
                GL_GPU::End();

                // If only one keyframe is selected, also draw the coordinates
                if (selectedKeys.size() == 1 && foundThisCurveSelectedKeys && foundThisCurveSelectedKeys->size() == 1) {
                    double rounding = std::pow(10., CURVEWIDGET_DERIVATIVE_ROUND_PRECISION);
                    QString leftDerivStr = QString::fromUtf8("l: %1").arg(std::floor( (key.getLeftDerivative() * rounding) + 0.5 ) / rounding);
                    QString rightDerivStr = QString::fromUtf8("r: %1").arg(std::floor( (key.getRightDerivative() * rounding) + 0.5 ) / rounding);
                    double yLeftWidgetCoord = _imp->curveWidget->toWidgetCoordinates(0, leftTanPos.y()).y();
                    yLeftWidgetCoord += (m.height() + 4);

                    double yRightWidgetCoord = _imp->curveWidget->toWidgetCoordinates(0, rightTanPos.y()).y();
                    yRightWidgetCoord += (m.height() + 4);

                    GL_GPU::Color4f(1., 1., 1., 1.);
                    glCheckFramebufferError(GL_GPU);
                    _imp->curveWidget->renderText( leftTanPos.x(), _imp->curveWidget->toZoomCoordinates(0, yLeftWidgetCoord).y(),
                                              leftDerivStr.toStdString(), 0.9, 0.9, 0.9, 1.);
                    _imp->curveWidget->renderText( rightTanPos.x(), _imp->curveWidget->toZoomCoordinates(0, yRightWidgetCoord).y(),
                                                  rightDerivStr.toStdString(), 0.9, 0.9, 0.9, 1.);


                    QString coordStr = QString::fromUtf8("x: %1, y: %2");
                    coordStr = coordStr.arg(key.getTime()).arg(key.getValue());
                    double yWidgetCoord = _imp->curveWidget->toWidgetCoordinates( 0, key.getValue() ).y();
                    yWidgetCoord += (m.height() + 4);
                    GL_GPU::Color4f(1., 1., 1., 1.);
                    glCheckFramebufferError(GL_GPU);
                    _imp->curveWidget->renderText( key.getTime(), _imp->curveWidget->toZoomCoordinates(0, yWidgetCoord).y(),
                                                  coordStr.toStdString(), 0.9, 0.9, 0.9, 1.);

                }

            } // drawTangents

        } // for (KeyFrameSet::const_iterator k = keyframes.begin(); k != keyframes.end(); ++k) {
    } // GLProtectAttrib(GL_HINT_BIT | GL_ENABLE_BIT | GL_LINE_BIT | GL_COLOR_BUFFER_BIT | GL_POINT_BIT | GL_CURRENT_BIT);

    glCheckError(GL_GPU);
} // drawCurve
void PropertiesDialog::backgroundColorChanged(const QColor & color)
{
    backgroundColor = App::Color(color.redF(), color.greenF(), color.blueF(), color.alphaF());
}