예제 #1
0
bool ContinuousColorRange::contains(const QVariant &v, bool inclusive) const
{
    QColor clr;
    if( v.type() == QVariant::Double){
        clr =  ColorRangeBase::toColor(v.toULongLong(),defaultColorModel());
    } else
        clr = v.value<QColor>();
    if ( !clr.isValid())
        return false;

    double component1a, component2a, component3a,component4a;
    double component1b, component2b, component3b,component4b;
    double component1c, component2c, component3c,component4c;
    QColor limit1,limit2;

    switch (defaultColorModel()) {
    case ColorRangeBase::cmRGBA :
    case ColorRangeBase::cmGREYSCALE:
        clr.getRgbF(&component1a, &component2a, &component3a);
        _limit1.getRgbF(&component1b, &component2b, &component3b);
        _limit2.getRgbF(&component1c, &component2c, &component3c);
        break;
    case ColorRangeBase::cmHSLA :
        clr.getHslF(&component1a, &component2a, &component3a);
        _limit1.getHslF(&component1b, &component2b, &component3b);
        _limit2.getHslF(&component1c, &component2c, &component3c);
        break;
    case ColorRangeBase::cmCYMKA:
        clr.getCmykF(&component1a, &component2a, &component3a,&component4a);
        limit1 = QColor(_limit1);
        limit2 = QColor(_limit2);
        limit1.getCmykF(&component1b, &component2b, &component3b, &component4b);
        limit2.getCmykF(&component1c, &component2c, &component3c, &component4c);
        break;
    default:
        break;
    }
    switch(defaultColorModel()){
    case ColorRangeBase::cmGREYSCALE:{
        bool isGrey = component1a == component2a && component1a == component3a;
        if (!isGrey)
            return false;
    }
    case ColorRangeBase::cmRGBA :
    case ColorRangeBase::cmHSLA :
        return component1a >= component1b && component1a <= component1c &&
                component2a >= component2b && component2a <= component2c &&
                component3a >= component3b && component3a <= component3c;
    case ColorRangeBase::cmCYMKA:
        return component1a >= component1b && component1a <= component1c &&
                component2a >= component2b && component2a <= component2c &&
                component3a >= component3b && component3a <= component3c &&
                component4a >= component4b && component4a <= component4c;
    default:
        break;

    }
    return false;

}
예제 #2
0
파일: Gradient.C 프로젝트: Tyf0n/IQmol
// Performs a linear interpolation between two colors, delta \in [0.0,1.0]
QColor Function::interpolateRGB(double delta, QColor const& col1, QColor const& col2) const
{
   if (delta <= 0.0) return col1;
   if (delta >= 1.0) return col2;

   double r1, r2, g1, g2, b1, b2;
   col1.getRgbF(&r1, &g1, &b1);
   col2.getRgbF(&r2, &g2, &b2);

   r1 += delta*(r2-r1);
   g1 += delta*(g2-g1);
   b1 += delta*(b2-b1);

   QColor color;
   color.setRgbF(r1, g1, b1);
   return color;
}
예제 #3
0
파일: Utils.cpp 프로젝트: Htallon/QtHandles
Matrix toRgb (const QColor& c)
{
  Matrix rgb (1, 3);
  double* rgbData = rgb.fortran_vec ();

  c.getRgbF (rgbData, rgbData+1, rgbData+2);

  return rgb;
}
예제 #4
0
파일: canvas.cpp 프로젝트: hejtmy/ZSBS
void Canvas::setUniformColor(GLuint program, const QColor& color, double opacity)
{
    double r, g, b, a;
    color.getRgbF(&r, &g, &b, &a);
    a = opacity;

    GLuint location = gl()->glGetUniformLocation(program, "color");
    checkNotErrorCode(location, static_cast<GLuint>(-1), "glGetUniformLocation() failed.");
    gl()->glUniform4f(location, r, g, b, a);
}
예제 #5
0
inline floatVariant Convert(const QColor& c)
{
	floatVariant param;
	double rgba[4];
	c.getRgbF(rgba, rgba + 1, rgba + 2, rgba + 3);
	param.float4[0] = static_cast<float>(rgba[0]);
	param.float4[1] = static_cast<float>(rgba[1]);
	param.float4[2] = static_cast<float>(rgba[2]);
	param.float4[3] = static_cast<float>(rgba[3]);
	return param;
}
void vtkDataMeshInteractor::setColor(QColor color)
{
    if( ! color.isValid())
        color.setRgb(0,0,0);

    double r,g,b;
    color.getRgbF(&r, &g, &b);
    d->actorProperty->SetColor(r, g, b);

    d->render->Render();
}
void manualRegistrationLandmarkController::AddPoint(manualRegistrationLandmark * landmark,unsigned int i)
{
    ClearUselessLandmarks();

    int size;
    QColor colorPoint;
    qreal r,g,b,a;
    colorPoint = Colors.takeFirst();
    Colors.push_back(colorPoint);
    colorPoint.getRgbF(&r,&g,&b,&a);
    if (i) 
    {
        if (Points_Moving->size()<Points_Fixed->size())
            Points_Fixed->at(Points_Moving->size())->GetHandleRepresentation()->GetProperty()->GetColor(r,g,b);
        
        size = Points_Moving->size();
    }
    else
    {
        if (Points_Fixed->size()<Points_Moving->size())
            Points_Moving->at(Points_Fixed->size())->GetHandleRepresentation()->GetProperty()->GetColor(r,g,b);

        size = Points_Fixed->size();
    }

    if (size>=128)
    {
        medMessageController::instance()->showError("You cannot add any more landmarks.",3000);
        return;
    }

    vtkProperty2D * property2D = static_cast<vtkPointHandleRepresentation2D*>(landmark->GetHandleWidget()->GetRepresentation())->GetProperty();
    property2D->SetColor(r,g,b);
    property2D->SetPointSize(0.0);
    property2D->SetLineWidth(3.0);
    property2D->SetOpacity(1.0);

    if (i)
        Points_Moving->append(landmark);
    else 
        Points_Fixed->append(landmark);   

    if (!landmark->HasObserver (vtkCommand::DeleteEvent, this->Command) )
        landmark->AddObserver(vtkCommand::DeleteEvent, this->Command, 0);

    Tbx->updateGUI(Points_Fixed->size(),Points_Moving->size());
}
void MyMaterialEditor::selectColor(int id)
{
    colour *c;
    switch (id) {
    case 0: c = &m_material.ambient; break;
    case 1: c = &m_material.diffuse; break;
    case 2: c = &m_material.specular; break;
    case 3: c = &m_material.emission; break;
    }

    QColor initial = QColor::fromRgbF((*c)[0], (*c)[1], (*c)[2], (*c)[3]);
    QColor current = QColorDialog::getColor(initial, this, "Select Color",
                                            QColorDialog::ShowAlphaChannel);

    if (current.isValid()) {
        double r, g, b, a;
        current.getRgbF(&r, &g, &b, &a);
        c->set(r, g, b, a);
        updateButton(id, *c);
        emit materialChanged(m_material);
    }
}
예제 #9
0
inline FColor QColor_to_FColor( const QColor& theColor )
{
	qreal r,g,b,a;
	theColor.getRgbF( &r, &g, &b, &a );
	return FColor(r,g,b,a);
}
예제 #10
0
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);
        }
    }
}
예제 #11
0
void ImageRendererThread::run() {
  std::complex<double> z;
  double steoreographic_projection_ball_radius = .1;
  double ray_nums = 12;
  double log_base = 2;
  QColor pixelColor;
  double h, s, v;  // hue, sat, val
  double m;        // modulus (Betrag)
  double lambda, mu, nu, dummy;
  QRgb *sl;

  forever {
    mMutex.lock();
    PlotHelp::cs_params param = mCSP;
    double xmin = mXmin,
      ymin = mYmin,
      infT = mP.mInfinityThreshold,
      rayO  = mP.mRayOpacity,
      cirO  = mP.mCircleOpacity,
      rayT  = mP.mRayThickness,
      cirT  = mP.mCircleThickness;

    int iterations = mP.mIterations;
    // make a copy of the function object so we won't need thread locking
    // to slow us down
    MFC_t nf(*mP.mF);
    QImage *mImage = mP.mImage;

    // integer division
    int ystart = mThreadNumber*(param.winheight+1)/mP.mNThreads,
      yend = (mThreadNumber+1)*(param.winheight+1)/mP.mNThreads-1;
    mMutex.unlock();

    qDebug() << "Thread " << mThreadNumber << " from " << ystart << " to " << yend;

    if(nf.parseOk()) {
      for(int y=ystart; y <= yend; ++y) {
	mGMutex.lock();
	sl = reinterpret_cast<QRgb*>(mImage->scanLine(y));
	mGMutex.unlock();
	for(int x=0; x <= param.winwidth; ++x) {
	  if(mFinish)
	    return;
	  z.real(xmin + x/param.xstep);
	  z.imag(ymin + (param.winheight-y)/param.ystep);
	  for(int i=0; i<iterations; ++i)
	    z = nf(z);

	  m = std::sqrt(z.real()*z.real()+z.imag()*z.imag());
	  // log here is really ln, but that's unimportant
	  double l = log(m)/log(log_base);

	  h = std::atan2(z.imag(), z.real());
	  s = (m>infT) ? 0 : 1;

	  v = M_2_PI*std::atan(m/(2.0*steoreographic_projection_ball_radius));

	  lambda = exp(-8000/rayT*pow(remainder(h,2*M_PI/ray_nums),2));
	  h = fmod(h/(2*M_PI)+1,1);
	  pixelColor.setHsvF(h, s, v);

	  mu = fmod(modf(l, &dummy)+1, 1);
	  nu = exp(-10000/cirT*pow(remainder(modf(l, &dummy), 0.5),2));

	  qreal r[3];
	  pixelColor.getRgbF(&r[0], &r[1], &r[2]);

	  for(int i=0; i<3; ++i) {
	    r[i] *= (1-0.25*(1-mu*cirO));
	    r[i] = r[i]*(1-lambda*rayO) + lambda*rayO;
	    if(l>-.25 && l<.25) {
	       r[i] = r[i]*(1-nu*cirO) + nu*cirO*mP.mUnitCircleColor[i];
	    }
	    else
	      r[i] *= (1-nu*cirO);
	  }

	  /* Note: This is a dangerous play! setPixel is NOT thread-safe,
	   * yet the QImage-instance (mImage) is shared and written to by different
	   * threads which are all computing the image.
	   *
	   * It SEEMS to work --- probably, because each thread writes to DIFFERENT
	   * addresses of the image (i.e. each thread computes unique parts of the image).
	   * However, it is not guaranteed that one day this might somehow change in the
	   * Qt-implementation.
	   *
	   * Unfortunately, locking the resource with a mutex results in a drastic
	   * increase in computation time so we refrain from it at this point.
	   */
	  // mMutex.lock();
	  sl[x] = qRgb(r[0]*255, r[1]*255, r[2]*255);
	  // mMutex.unlock();
	}
      }
    }
    emit rendered();
    mMutex.lock();
    qDebug() << "Thread " << mThreadNumber << " about to sleep";
    condition.wait(&mMutex);
    qDebug() << "Thread " << mThreadNumber << " woken, continuing my work";
    mMutex.unlock();
  }
}