예제 #1
0
//-----------------------------------------------------------------------------
void ddDrakeModel::setLinkColor(const QString& linkName, const QColor& color)
{
  double red = color.redF();
  double green = color.greenF();
  double blue = color.blueF();
  double alpha = color.alphaF();


  std::vector<ddMeshVisual::Ptr> visuals = this->Internal->Model->meshVisuals();
  for (size_t i = 0; i < visuals.size(); ++i)
  {
    if (visuals[i]->Name == linkName.toAscii().data())
    {
      visuals[i]->Actor->GetProperty()->SetColor(red, green, blue);
      visuals[i]->Actor->GetProperty()->SetOpacity(alpha);

      if (visuals[i]->ShadowActor)
      {
        visuals[i]->ShadowActor->GetProperty()->SetOpacity(alpha);
      }
    }
  }
  emit this->displayChanged();
}
예제 #2
0
void QtGradientStopsControllerPrivate::slotChangeAlpha(const QColor &color)
{
    QtGradientStop *stop = m_model->currentStop();
    if (!stop)
        return;
    m_model->changeStop(stop, color);
    QList<QtGradientStop *> stops = m_model->selectedStops();
    QListIterator<QtGradientStop *> itStop(stops);
    while (itStop.hasNext()) {
        QtGradientStop *s = itStop.next();
        if (s != stop) {
            QColor c = s->color();
            if (m_ui->hsvRadioButton->isChecked()) {
                c.setHsvF(c.hueF(), c.saturationF(), c.valueF(), color.alphaF());
                int hue = c.hue();
                if (hue == 360 || hue == -1)
                    c.setHsvF(0.0, c.saturationF(), c.valueF(), c.alphaF());
            } else {
                c.setRgbF(c.redF(), c.greenF(), c.blueF(), color.alphaF());
            }
            m_model->changeStop(s, c);
        }
    }
}
예제 #3
0
void MonoFaceShader::renderMesh(QColor meshColor,
                                QVector<QVector3D>& vertices,
                                QVector<QVector3D>& normals)
{
    if (vertices.size() != normals.size())
        throw runtime_error("vertex and normal array not same size MonoFaceShader::renderMesh");

    _program->setUniformValue(_uniforms["sourceColor"],
                  meshColor.redF(),
                  meshColor.greenF(),
                  meshColor.blueF(),
                  1.0f);

    GLuint normalAttr = _attributes["normal"];
    GLuint vertexAttr = _attributes["vertex"];

    _program->setAttributeArray(vertexAttr, vertices.constData());
    _program->setAttributeArray(normalAttr, normals.constData());
    _program->enableAttributeArray(normalAttr);
    _program->enableAttributeArray(vertexAttr);
    glDrawArrays(GL_TRIANGLES, 0, vertices.size());
    _program->disableAttributeArray(normalAttr);
    _program->disableAttributeArray(vertexAttr);
}
예제 #4
0
파일: glutils.cpp 프로젝트: phg1024/CSCE641
void GLUtils::setColor(const QColor &c)
{
    glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF());
}
예제 #5
0
ClipInformation
ClipInformation::interpolate(const ClipInformation clipInfo1,
			     const ClipInformation clipInfo2,
			     float frc)
{
  ClipInformation clipInfo;


  clipInfo.show = clipInfo1.show;
  clipInfo.applyFlip = clipInfo1.applyFlip;
  clipInfo.apply = clipInfo1.apply;
  clipInfo.imageName = clipInfo1.imageName;
  clipInfo.captionText = clipInfo1.captionText;
  clipInfo.tfSet = clipInfo1.tfSet;
  clipInfo.solidColor = clipInfo1.solidColor;
  clipInfo.showSlice = clipInfo1.showSlice;
  clipInfo.showOtherSlice = clipInfo1.showOtherSlice;
  clipInfo.showThickness = clipInfo1.showThickness;
  clipInfo.viewportType = clipInfo1.viewportType;

  // interpolate the rest
  for(int ci=0;
      ci<qMin(clipInfo1.pos.size(),
	      clipInfo2.pos.size());
      ci++)
    {
      Vec pos;
      Quaternion rot;
      pos = clipInfo1.pos[ci] + frc*(clipInfo2.pos[ci]-
				     clipInfo1.pos[ci]);
      rot = Quaternion::slerp(clipInfo1.rot[ci], clipInfo2.rot[ci], frc);

      float st, op, scl1, scl2;
      st = clipInfo1.stereo[ci] + frc*(clipInfo2.stereo[ci]-
					clipInfo1.stereo[ci]);
      op = clipInfo1.opacity[ci] + frc*(clipInfo2.opacity[ci]-
					clipInfo1.opacity[ci]);
      scl1 = clipInfo1.scale1[ci] + frc*(clipInfo2.scale1[ci]-
					 clipInfo1.scale1[ci]);
      scl2 = clipInfo1.scale2[ci] + frc*(clipInfo2.scale2[ci]-
					 clipInfo1.scale2[ci]);
      int grdx = clipInfo1.gridX[ci] + frc*(clipInfo2.gridX[ci]-
					    clipInfo1.gridX[ci]);
      int grdy = clipInfo1.gridY[ci] + frc*(clipInfo2.gridY[ci]-
					    clipInfo1.gridY[ci]);

      int frm;
      frm = clipInfo1.imageFrame[ci] + frc*(clipInfo2.imageFrame[ci]-
					    clipInfo1.imageFrame[ci]);

      Vec pcolor;
      pcolor = clipInfo1.color[ci] + frc*(clipInfo2.color[ci]-
					  clipInfo1.color[ci]);

      QVector4D vp;
      vp = clipInfo1.viewport[ci] + frc*(clipInfo2.viewport[ci]-
					 clipInfo1.viewport[ci]);

      float vps;
      vps = clipInfo1.viewportScale[ci] + frc*(clipInfo2.viewportScale[ci]-
					       clipInfo1.viewportScale[ci]);

      int thick;
      thick = clipInfo1.thickness[ci] + frc*(clipInfo2.thickness[ci]-
					     clipInfo1.thickness[ci]);

      QFont cfont = clipInfo1.captionFont[ci];
      QColor ccolor = clipInfo1.captionColor[ci];
      QColor chcolor = clipInfo1.captionHaloColor[ci];
      if (clipInfo1.captionText[ci] == clipInfo2.captionText[ci])
	{
	  QFont cfont2 = clipInfo1.captionFont[ci];

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

	  // interpolate color
	  float r1 = ccolor.redF();
	  float g1 = ccolor.greenF();
	  float b1 = ccolor.blueF();
	  float a1 = ccolor.alphaF();	  
	  QColor c = clipInfo2.captionColor[ci];
	  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;	  	  
	  ccolor = QColor(r*255, g*255, b*255, a*255);


	  r1 = chcolor.redF();
	  g1 = chcolor.greenF();
	  b1 = chcolor.blueF();
	  a1 = chcolor.alphaF();	  
	   c = clipInfo2.captionHaloColor[ci];
	  r2 = c.redF();
	  g2 = c.greenF();
	  b2 = c.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;	  	  
	  chcolor = QColor(r*255, g*255, b*255, a*255);
	}

      
      clipInfo.pos.append(pos);
      clipInfo.rot.append(rot);
      clipInfo.opacity.append(op);
      clipInfo.stereo.append(st);
      clipInfo.scale1.append(scl1);
      clipInfo.scale2.append(scl2);
      clipInfo.gridX.append(grdx);
      clipInfo.gridY.append(grdy);
      clipInfo.imageFrame.append(frm);
      clipInfo.captionFont.append(cfont);
      clipInfo.captionColor.append(ccolor);
      clipInfo.captionHaloColor.append(chcolor);
      clipInfo.color.append(pcolor);
      clipInfo.viewport.append(vp);
      clipInfo.viewportScale.append(vps);
      clipInfo.thickness.append(thick);
    }

//  if (clipInfo1.pos.size() < clipInfo2.pos.size())
//    {
//      for(int ci=clipInfo1.pos.size();
//	  ci < clipInfo2.pos.size();
//	  ci++)
//	{
//	  clipInfo.pos.append(clipInfo2.pos[ci]);
//	  clipInfo.rot.append(clipInfo2.rot[ci]);
//	}
//    }
  if (clipInfo2.pos.size() < clipInfo1.pos.size())
    {
      for(int ci=clipInfo2.pos.size();
	  ci < clipInfo1.pos.size();
	  ci++)
	{
	  clipInfo.pos.append(clipInfo1.pos[ci]);
	  clipInfo.rot.append(clipInfo1.rot[ci]);
	  clipInfo.opacity.append(clipInfo1.opacity[ci]);
	  clipInfo.stereo.append(clipInfo1.stereo[ci]);
	  clipInfo.scale1.append(clipInfo1.scale1[ci]);
	  clipInfo.scale2.append(clipInfo1.scale2[ci]);
	  clipInfo.imageFrame.append(clipInfo1.imageFrame[ci]);
	  clipInfo.captionFont.append(clipInfo1.captionFont[ci]);
	  clipInfo.captionColor.append(clipInfo1.captionColor[ci]);
	  clipInfo.captionHaloColor.append(clipInfo1.captionHaloColor[ci]);
	  clipInfo.color.append(clipInfo1.color[ci]);
	  clipInfo.viewport.append(clipInfo1.viewport[ci]);
	  clipInfo.viewportScale.append(clipInfo1.viewportScale[ci]);
	  clipInfo.thickness.append(clipInfo1.thickness[ci]);
	}
    }
  
  return clipInfo;
}
예제 #6
0
bool
ClipObject::processCommand(QString cmd)
{
  bool ok;
  cmd = cmd.toLower();
  QStringList list = cmd.split(" ", QString::SkipEmptyParts);
  
  if (list[0] == "mop")
    {
      if (list.size() == 2 && list[1] == "clip")
	{
	  m_mopClip = true;
	  return true;
	}
      else
	return false;
    }
  else if (list[0] == "tfset")
    {
      int tf = 1000;
      if (list.size() == 2) tf = qMax(0, list[1].toInt());
      m_tfset = tf;
      return true;
    }
  else if (list[0] == "reorientcamera")
    {
      m_reorientCamera = true;
      return true;
    }
  else if (list[0] == "color")
    {
      QColor dcolor = QColor::fromRgbF(m_color.x,
				       m_color.y,
				       m_color.z);
      QColor color = DColorDialog::getColor(dcolor);
      if (color.isValid())
	{
	  float r = color.redF();
	  float g = color.greenF();
	  float b = color.blueF();
	  m_color = Vec(r,g,b);
	}
    }
  else if (list[0] == "solidcolor")
    {
      if (list.size() == 2 &&
	  list[1] == "no")
	m_solidColor = false;
      else
	m_solidColor = true;
      return true;
    }
  else if (list[0] == "savesliceimage")
    {
      m_resliceSubsample = 1;
      m_saveSliceImage = true;
      if (list.size() == 2) m_resliceSubsample = qMax(1, list[1].toInt(&ok));
      return true;
    }
  else if (list[0] == "reslice")
    {
      m_resliceSubsample = 1;
      m_resliceTag = -1;
      m_resliceVolume = true;
      if (list.size() > 1) m_resliceSubsample = qMax(1, list[1].toInt(&ok));
      if (list.size() > 2) m_resliceTag = list[2].toInt(&ok);
      return true;
    }
  else if (list[0] == "grid")
    {
      if (list.size() == 1)
	{
	  m_gridX = m_gridY = 10;
	}
      else if (list.size() == 2 && list[1] == "no")
	{
	  m_gridX = m_gridY = 0;
	}
      else if (list.size() == 3)
	{
	  m_gridX = list[1].toInt();
	  m_gridY = list[2].toInt();
	}
      return true;
    }
  else if (list[0] == "image")
    {
      if (list.size() == 2 &&
	  list[1] == "no")
	clearImage();
      else
	loadImage();
      return true;
    }
  else if (list[0] == "imageframe")
    {
      if (list.size() == 2)
	{
	  int frm = list[1].toInt(&ok);
	  if (frm >= 0)
	    {
	      loadImage(m_imageName, frm);
	    }
	  else
	    QMessageBox::information(0, "Error",
				     "ImageFrame not changed.  Positive values required");
	}
      else
	QMessageBox::information(0, "Error",
				 "Please specify ImageFrame number for the clipplane");
      return true;
    }
  else if (list[0] == "caption")
    {
      if (list.count() == 2 &&
	  list[1] == "no")
	clearCaption();
      else
	loadCaption();

      return true;
    }
  else if (list[0] == "vscale" ||
	   list[0] == "scale")
    {
      if (list.size() > 1)
	{
	  float scl1, scl2;
	  if (list.size() == 2)
	    {
	      scl1 = list[1].toFloat(&ok);
	      scl2 = scl1;
	    }
	  else
	    {
	      scl1 = list[1].toFloat(&ok);
	      scl2 = list[2].toFloat(&ok);
	    }
	  if (list[0] == "scale")
	    {
	      m_scale1 = -qAbs(scl1);
	      m_scale2 = -qAbs(scl2);
	    }
	  else
	    {
	      m_scale1 = scl1;
	      m_scale2 = scl2;
	    }
	}
      else
	QMessageBox::information(0, "Error",
				 "Please specify both scalings for the clipplane");
      return true;
    }
  else if (list[0] == "opacity")
    {
      if (list.size() == 2)
	{
	  float scl = list[1].toFloat(&ok);
	  if (scl >= 0 && scl <= 1)
	    {
	      m_opacity = scl;
	      m_opacity = qMax(0.02f, qMin(1.0f, m_opacity));
	    }
	  else
	    QMessageBox::information(0, "Error",
				     "Opacity not changed.  Value between 0 and 1 required");
	}
      else
	QMessageBox::information(0, "Error",
				 "Please specify opacity for the clipplane");
      return true;
    }
  else if (list[0] == "translate" ||
	   list[0] == "translatex" ||
	   list[0] == "translatey" ||
	   list[0] == "translatez" ||
	   list[0] == "move" ||
	   list[0] == "movex" ||
	   list[0] == "movey" ||
	   list[0] == "movez")
    {
      Vec pos;
      float x=0,y=0,z=0;

      if (list[0] == "translate" || list[0] == "move")
	{
	  if (list.size() > 1) x = list[1].toFloat(&ok);
	  if (list.size() > 2) y = list[2].toFloat(&ok);
	  if (list.size() > 3) z = list[3].toFloat(&ok);
	  pos = Vec(x,y,z);
	}
      else
	{
	  float v=0;
	  if (list.size() > 1) v = list[1].toFloat(&ok);
	  if (list[0] == "translatex" || list[0] == "movex")
	    pos = Vec(v,0,0);
	  else if (list[0] == "translatey" || list[0] == "movey")
	    pos = Vec(0,v,0);
	  else if (list[0] == "translatez" || list[0] == "movez")
	    pos = Vec(0,0,v);
	}

      if (list[0].contains("move"))
	{
	  Vec cpos = position();
	  pos = pos + cpos;
	}
      setPosition(pos);
      return true;
    }
  else if (list[0] == "rotatea" ||
	   list[0] == "rotateb" ||
	   list[0] == "rotatec")
    {
      float angle = 0;
      if (list.size() > 1)
	{
	  angle = list[1].toFloat(&ok);
	  if (list[0] == "rotatea") rotate(m_xaxis, angle);
	  if (list[0] == "rotateb") rotate(m_yaxis, angle);
	  if (list[0] == "rotatec") rotate(m_tang, angle);
	}
      else
	{
	  QMessageBox::information(0, "", "No angle specified");
	}       
      return true;
    }
  else if (list[0] == "movea" ||
	   list[0] == "moveb" ||
	   list[0] == "movec")
    {
      float shift = 0;
      if (list.size() > 1)
	{
	  shift = list[1].toFloat(&ok);
	  if (list[0] == "movea") translate(shift*m_xaxis);
	  if (list[0] == "moveb") translate(shift*m_yaxis);
	  if (list[0] == "movec") translate(shift*m_tang);
	}
      else
	{
	  QMessageBox::information(0, "", "No distance specified");
	}       
      return true;
    }
  else if (list[0] == "rotate" ||
	   list[0] == "rotatex" ||
	   list[0] == "rotatey" ||
	   list[0] == "rotatez" ||
	   list[0] == "addrotation" ||
	   list[0] == "addrotationx" ||
	   list[0] == "addrotationy" ||
	   list[0] == "addrotationz")
    {
      Quaternion rot;
      float x=0,y=0,z=0,a=0;
      if (list[0] == "rotate" || list[0] == "addrotation")
	{
	  if (list.size() > 1) x = list[1].toFloat(&ok);
	  if (list.size() > 2) y = list[2].toFloat(&ok);
	  if (list.size() > 3) z = list[3].toFloat(&ok);
	  if (list.size() > 4) a = list[4].toFloat(&ok);
	  rot = Quaternion(Vec(x,y,z), DEG2RAD(a));
	}
      else
	{
	  float a=0;
	  if (list.size() > 1) a = list[1].toFloat(&ok);
	  if (list[0] == "rotatex" || list[0] == "addrotationx")
	    rot = Quaternion(Vec(1,0,0), DEG2RAD(a));
	  else if (list[0] == "rotatey" || list[0] == "addrotationy")
	    rot = Quaternion(Vec(0,1,0), DEG2RAD(a));
	  else if (list[0] == "rotatez" || list[0] == "addrotationz")
	    rot = Quaternion(Vec(0,0,1), DEG2RAD(a));
	}

      if (list[0].contains("addrotation"))
	{
	  Quaternion orot = orientation();
	  rot = rot*orot;
	}
      setOrientation(rot);
      return true;
    }
  else
    QMessageBox::information(0, "Error",
			     QString("Cannot understand the command : ") +
			     cmd);

  return false;
}
예제 #7
0
qreal KHCY::luma(const QColor &color)
{
    return lumag(gamma(color.redF()),
                 gamma(color.greenF()),
                 gamma(color.blueF()));
}
예제 #8
0
파일: Mask.cpp 프로젝트: 5Y5TEM/MultiFusion
void Mask::mask_slot(){
    int countSel = gsri->countSelected();
    GObjectInterface *iObj, *endObj=gsri->selected(gsri->countSelected()-1);//создаём контейнер с выделенными рамкой объектами
    qreal k_h, k_w, width_iObj, width_endObj = endObj->boundingRect().width(),
    height_iObj, height_endObj = endObj->boundingRect().height();
    QBrush endObjBrush = endObj->brush();
    if(endObjBrush.style() == Qt::RadialGradientPattern
            || endObjBrush.style() == Qt::ConicalGradientPattern
                || endObjBrush.style() == Qt::LinearGradientPattern){
        for (int i=0; i<countSel-1; i++){
            iObj = gsri->selected(i);
            QBrush inters = iObj->brush();
            qreal iObjAlpha = inters.color().alphaF();
            QGradient qg = *endObjBrush.gradient();
            height_iObj = iObj->boundingRect().height();
            width_iObj = iObj->boundingRect().width();
            k_h = height_endObj/height_iObj;//считаем коэффициенты пропорциональности фигур для умножения-->
            k_w = width_endObj/width_iObj;//-->на точки градиента(чтобы градиенты не зависели от размеров фигур).

            int d_x = iObj->boundingRect().x() - endObj->boundingRect().x();//вычисляем расстояния между левыми краями фигур
            int d_y = iObj->boundingRect().y() - endObj->boundingRect().y();
            qreal k_shift_x = ( d_x / width_endObj) * k_w,//вычисляем коэффициенты сдвига градиента по ширине-->
                    k_shift_y = (d_y / height_endObj) * k_h;//--> и по высотке

            QGradientStops grStops(qg.stops());//копируем точки/цвета задаваемого градиента.

            QColor BrushColor = inters.gradient()->stops()[0].second;

            for(int j=0; j<grStops.count(); j++){
                grStops[j].second.setRgbF( BrushColor.redF(), BrushColor.greenF(), BrushColor.blueF(),
                                           grStops[j].second.alphaF()*iObjAlpha);
            }

            if(qg.type() == QGradient::LinearGradient){
                QLinearGradient qlg = *static_cast<const QLinearGradient *>(endObjBrush.gradient());
                QLinearGradient qlgLinear(qlg.start().x() * k_w - k_shift_x, qlg.start().y() * k_h - k_shift_y,
                                         qlg.finalStop().x() * k_w - k_shift_x, qlg.finalStop().y() * k_h - k_shift_y);
                qlgLinear.setStops(grStops);
                iObj->setBrush(qlgLinear);
            }

            if(qg.type() == QGradient::RadialGradient){
                for(int j=0; j<grStops.count(); j++)
                    grStops[j].first *= k_w;
                QRadialGradient qlg = *static_cast<const QRadialGradient *>(endObjBrush.gradient());
                QRadialGradient qlgRadial(QPointF(qlg.center().x()*k_w - k_shift_x, qlg.center().y()*k_h - k_shift_y),
                     qlg.radius(), QPointF(qlg.focalPoint().x()*k_w - k_shift_x, qlg.focalPoint().y()*k_h - k_shift_y),
                     qlg.focalRadius());
                qlgRadial.setStops(grStops);
                iObj->setBrush(qlgRadial);
            }

            if(qg.type() == QGradient::ConicalGradient){
                QConicalGradient qlg = *static_cast<const QConicalGradient *>(endObjBrush.gradient());
                QConicalGradient qlgConical(QPointF(qlg.center().x()*k_w - k_shift_x, qlg.center().y()*k_h - k_shift_y),
                                          qlg.angle());
                qlgConical.setStops(grStops);
                iObj->setBrush(qlgConical);
            }
        }
        endObj->setVisible(false);
    }
    else{
        QMessageBox m;
        m.setText(tr("upper figure does not contain a gradient"));
        m.exec();
    }
    gsri->reset();

}
예제 #9
0
void SurfaceROI::SetColor( const QColor& color )
{
  m_color = color;
  m_actorOutline->GetProperty()->SetColor( color.redF(), color.greenF(), color.blueF() );
  emit ColorChanged( color );
}
예제 #10
0
파일: Viewer.cpp 프로젝트: WalrusCow/gfx
void Viewer::setSpecularColour(const QColor& c) {
  sphereShaders.setUniformValue(specularColourLoc, c.redF(), c.greenF(), c.blueF());
}
예제 #11
0
파일: run.cpp 프로젝트: trtikm/E2
void Renderer::render(xqtgl::window* const  surface, xqtgl::opengl_api* const f)
{
    QColor color = QColor(100, 255, 0);

    QSize viewSize = surface->size();

    f->glViewport(0, 0, viewSize.width() * surface->devicePixelRatio(), viewSize.height() * surface->devicePixelRatio());
    f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    f->glClearColor(m_backgroundColor.redF(), m_backgroundColor.greenF(), m_backgroundColor.blueF(), m_backgroundColor.alphaF());
    f->glFrontFace(GL_CW);
    f->glCullFace(GL_FRONT);
    f->glEnable(GL_CULL_FACE);
    f->glEnable(GL_DEPTH_TEST);

    std::vector<GLchar const*> const vshader_lines = {
        "#version 420\n",
        "in vec4  vertex;\n",
        "void main(void)\n",
        "{\n",
        "    gl_Position = vertex;\n",
        "}\n",
    };
    GLuint const  vshader = f->glCreateShader(GL_VERTEX_SHADER);
    f->glShaderSource(vshader, (GLsizei)vshader_lines.size(), (GLchar const**)&vshader_lines.at(0), nullptr);
    f->glCompileShader(vshader);
    GLuint const  vshader_program = f->glCreateProgram();
    f->glProgramParameteri(vshader_program, GL_PROGRAM_SEPARABLE, GL_TRUE);
    f->glAttachShader(vshader_program, vshader);
    f->glLinkProgram(vshader_program);
    f->glDetachShader(vshader_program, vshader);
    f->glDeleteShader(vshader);

    std::vector<GLchar const*> const fshader_lines = {
        "#version 420\n",
        "out vec4  out_colour;\n",
        "void main(void)\n",
        "{\n",
        "    out_colour = vec4(1.0f, 1.0f, 1.0f, 1.0f);\n",
        "}\n",
    };
    GLuint const  fshader = f->glCreateShader(GL_FRAGMENT_SHADER);
    f->glShaderSource(fshader, (GLsizei)fshader_lines.size(), (GLchar const**)&fshader_lines.at(0), nullptr);
    f->glCompileShader(fshader);
    GLuint const  fshader_program = f->glCreateProgram();
    f->glProgramParameteri(fshader_program, GL_PROGRAM_SEPARABLE, GL_TRUE);
    f->glAttachShader(fshader_program, fshader);
    f->glLinkProgram(fshader_program);
    f->glDetachShader(fshader_program, fshader);
    f->glDeleteShader(fshader);

    GLuint  pipeline_id = 0;
    f->glGenProgramPipelines(1U, &pipeline_id);
    f->glUseProgramStages(pipeline_id, GL_VERTEX_SHADER_BIT, vshader_program);
    f->glUseProgramStages(pipeline_id, GL_FRAGMENT_SHADER_BIT, fshader_program);
    f->glBindProgramPipeline(pipeline_id);

    GLint const  vdata_position = f->glGetAttribLocation(vshader_program, "vertex");

    std::array<float_32_bit, 12> const  vbuffer_data = {
            0.0f, 0.0f, 0.0f, 1.0f,
            1.0f, 0.0f, 0.0f, 1.0f,
            0.0f, 1.0f, 0.0f, 1.0f,
    };

    GLuint  vbuffer_id = 0U;
    f->glGenBuffers(1U, &vbuffer_id);
    f->glBindBuffer(GL_ARRAY_BUFFER, vbuffer_id);
    f->glBufferData(GL_ARRAY_BUFFER,
                    (GLsizeiptr)(vbuffer_data.size() * sizeof(float_32_bit)),
                    (GLvoid const*)vbuffer_data.data(),
                    GL_STATIC_DRAW);

    GLuint  barrays_id = 0;
    f->glGenVertexArrays(1U, &barrays_id);
    f->glBindVertexArray(barrays_id);

    f->glBindBuffer(GL_ARRAY_BUFFER, vbuffer_id);
    f->glEnableVertexAttribArray(vdata_position);
    f->glVertexAttribPointer(
            vdata_position,
            4,
            GL_FLOAT,
            GL_FALSE,
            0U,
            nullptr
            );

    f->glBindVertexArray(barrays_id);

    f->glDrawArrays(GL_TRIANGLES, 0, 3);

    f->glBindProgramPipeline(0);
    f->glBindVertexArray(0);

    f->glDeleteVertexArrays(1U, &barrays_id);
    f->glDeleteBuffers(1U, &vbuffer_id);

    f->glDeleteProgramPipelines(1, &pipeline_id);
    f->glDeleteProgram(vshader_program);
    f->glDeleteProgram(fshader_program);
}
예제 #12
0
파일: roaddrawer.cpp 프로젝트: baidut/ITS
bool operator<(const QColor & a, const QColor & b) {
   return a.redF() < b.redF()
       || a.greenF() < b.greenF()
       || a.blueF() < b.blueF()
       || a.alphaF() < b.alphaF();
}
QImage SpecularmapGenerator::calculateSpecmap(QImage input, double scale, double contrast) {
    QImage result(input.width(), input.height(), QImage::Format_ARGB32);

    //generate contrast lookup table
    unsigned short contrastLookup[256];
    double newValue = 0;

    for(int i = 0; i < 256; i++) {
        newValue = (double)i;
        newValue /= 255.0;
        newValue -= 0.5;
        newValue *= contrast;
        newValue += 0.5;
        newValue *= 255;

        if(newValue < 0)
            newValue = 0;
        if(newValue > 255)
            newValue = 255;

        contrastLookup[i] = (unsigned short)newValue;
    }

    #pragma omp parallel for  // OpenMP
    //for every row of the image
    for(int y = 0; y < result.height(); y++) {
        QRgb *scanline = (QRgb*) result.scanLine(y);

        //for every column of the image
        for(int x = 0; x < result.width(); x++) {
            double r, g, b, a;
            double intensity = 0.0;

            QColor pxColor = QColor(input.pixel(x, y));

            r = pxColor.redF() * redMultiplier;
            g = pxColor.greenF() * greenMultiplier;
            b = pxColor.blueF() * blueMultiplier;
            a = pxColor.alphaF() * alphaMultiplier;

            if(mode == IntensityMap::AVERAGE) {
                //take the average out of all selected channels
                double multiplierSum = (redMultiplier + greenMultiplier + blueMultiplier + alphaMultiplier);

                if(multiplierSum == 0.0)
                    multiplierSum = 1.0;

                intensity = (r + g + b + a) / multiplierSum;
            }
            else if(mode == IntensityMap::MAX) {
                //take the maximum out of all selected channels
                double tempMaxRG = std::max(r, g);
                double tempMaxBA = std::max(b, a);
                intensity = std::max(tempMaxRG, tempMaxBA);
            }

            //apply scale (brightness)
            intensity *= scale;

            if(intensity > 1.0)
                intensity = 1.0;

            //convert intensity to the 0-255 range
            int c = (int)(255.0 * intensity);

            //apply contrast
            c = (int)contrastLookup[c];

            //write color into image pixel
            scanline[x] = qRgba(c, c, c, pxColor.alpha());
        }
    }

    return result;
}
예제 #14
0
RGB toRGB(QColor& col){
    return RGB(col.redF(), col.greenF(), col.blueF());
}
예제 #15
0
void ShaderLibrary::setUniformVariable(GLuint /*program*/, GLint location, QColor const& color)
{
   glUniform4f(location, color.redF(), color.greenF(), color.blueF(), 
      color.alphaF()); 
}
예제 #16
0
void
ScaleSliderQWidget::paintEvent(QPaintEvent* /*e*/)
{
    if (_imp->mustInitializeSliderPosition) {
        centerOn(_imp->minimum, _imp->maximum);
        _imp->mustInitializeSliderPosition = false;
        seekScalePosition(_imp->value);
        _imp->initialized = true;
    }

    ///fill the background with the appropriate style color
    QStyleOption opt;
    opt.init(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);

    double txtR,txtG,txtB;
    appPTR->getCurrentSettings()->getTextColor(&txtR, &txtG, &txtB);
    QColor textColor;
    textColor.setRgbF(Natron::clamp(txtR), Natron::clamp(txtG), Natron::clamp(txtB));
    
    QColor scaleColor;
    scaleColor.setRgbF(textColor.redF() / 2., textColor.greenF() / 2., textColor.blueF() / 2.);
    
    QFontMetrics fontM(*_imp->font);
    p.setPen(scaleColor);

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

    if ( btmLeft.x() == topRight.x() ) {
        return;
    }

    /*drawing X axis*/
    double lineYpos = height() - 1 - fontM.height()  - TICK_HEIGHT / 2;
    p.drawLine(0, lineYpos, width() - 1, lineYpos);

    double tickBottom = _imp->zoomCtx.toZoomCoordinates( 0,height() - 1 - fontM.height() ).y();
    double tickTop = _imp->zoomCtx.toZoomCoordinates(0,height() - 1 - fontM.height()  - TICK_HEIGHT).y();
    const double smallestTickSizePixel = 5.; // tick size (in pixels) for alpha = 0.
    const double largestTickSizePixel = 1000.; // tick size (in pixels) for alpha = 1.
    std::vector<double> acceptedDistances;
    acceptedDistances.push_back(1.);
    acceptedDistances.push_back(5.);
    acceptedDistances.push_back(10.);
    acceptedDistances.push_back(50.);
    const double rangePixel =  width();
    const double range_min = btmLeft.x();
    const double range_max =  topRight.x();
    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 = fontM.width( QString("00") ); // 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);
        QColor color(textColor);
        color.setAlphaF(alpha);
        QPen pen(color);
        pen.setWidthF(1.9);
        p.setPen(pen);

        QPointF tickBottomPos = _imp->zoomCtx.toWidgetCoordinates(value, tickBottom);
        QPointF tickTopPos = _imp->zoomCtx.toWidgetCoordinates(value, tickTop);

        p.drawLine(tickBottomPos,tickTopPos);

        bool renderText = _imp->dataType == eDataTypeDouble || std::abs(std::floor(0.5 + value) - value) == 0.;
        if (renderText && tickSize > minTickSizeText) {
            const int tickSizePixel = rangePixel * tickSize / range;
            const QString s = QString::number(value);
            const int sSizePixel =  fontM.width(s);
            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;
                }
                QColor c = _imp->readOnly || !isEnabled() ? Qt::black : textColor;
                c.setAlphaF(alphaText);
                p.setFont(*_imp->font);
                p.setPen(c);

                QPointF textPos = _imp->zoomCtx.toWidgetCoordinates( value, btmLeft.y() );

                p.drawText(textPos, s);
            }
        }
    }
    double positionValue = _imp->zoomCtx.toWidgetCoordinates(_imp->value,0).x();
    QPointF sliderBottomLeft(positionValue - SLIDER_WIDTH / 2,height() - 1 - fontM.height() / 2);
    QPointF sliderTopRight(positionValue + SLIDER_WIDTH / 2,height() - 1 - fontM.height() / 2 - SLIDER_HEIGHT);

    /*draw the slider*/
    p.setPen(_imp->sliderColor);
    p.fillRect(sliderBottomLeft.x(), sliderBottomLeft.y(), sliderTopRight.x() - sliderBottomLeft.x(), sliderTopRight.y() - sliderBottomLeft.y(),_imp->sliderColor);

    /*draw a black rect around the slider for contrast*/
    p.setPen(Qt::black);

    p.drawLine( sliderBottomLeft.x(),sliderBottomLeft.y(),sliderBottomLeft.x(),sliderTopRight.y() );
    p.drawLine( sliderBottomLeft.x(),sliderTopRight.y(),sliderTopRight.x(),sliderTopRight.y() );
    p.drawLine( sliderTopRight.x(),sliderTopRight.y(),sliderTopRight.x(),sliderBottomLeft.y() );
    p.drawLine( sliderTopRight.x(),sliderBottomLeft.y(),sliderBottomLeft.x(),sliderBottomLeft.y() );
} // paintEvent
예제 #17
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);
        }
    }
}
예제 #18
0
void
ScaleSliderQWidget::paintEvent(QPaintEvent* /*e*/)
{
    if (_imp->mustInitializeSliderPosition) {
        if (_imp->minimum < _imp->maximum) {
            centerOn(_imp->minimum, _imp->maximum);
        }
        _imp->mustInitializeSliderPosition = false;
        seekScalePosition(_imp->value);
        _imp->initialized = true;
    }

    ///fill the background with the appropriate style color
    QStyleOption opt;
    opt.init(this);
    QPainter p(this);
    p.setOpacity(1);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);

    double txtR, txtG, txtB;
    if (_imp->altered) {
        appPTR->getCurrentSettings()->getAltTextColor(&txtR, &txtG, &txtB);
    } else {
        appPTR->getCurrentSettings()->getTextColor(&txtR, &txtG, &txtB);
    }

    QColor textColor;
    textColor.setRgbF( Image::clamp<qreal>(txtR, 0., 1.),
                       Image::clamp<qreal>(txtG, 0., 1.),
                       Image::clamp<qreal>(txtB, 0., 1.) );

    QColor scaleColor;
    scaleColor.setRgbF(textColor.redF() / 2., textColor.greenF() / 2., textColor.blueF() / 2.);

    QFontMetrics fontM(_imp->font, 0);

    if (!_imp->useLineColor) {
        p.setPen(scaleColor);
    } else {
        p.setPen(_imp->lineColor);
    }

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

    if ( btmLeft.x() == topRight.x() ) {
        return;
    }

    /*drawing X axis*/
    double lineYpos = height() - 1 - fontM.height()  - TO_DPIY(TICK_HEIGHT) / 2;
    p.drawLine(0, lineYpos, width() - 1, lineYpos);

    double tickBottom = _imp->zoomCtx.toZoomCoordinates( 0, height() - 1 - fontM.height() ).y();
    double tickTop = _imp->zoomCtx.toZoomCoordinates( 0, height() - 1 - fontM.height()  - TO_DPIY(TICK_HEIGHT) ).y();
    const double smallestTickSizePixel = 10.; // tick size (in pixels) for alpha = 0.
    const double largestTickSizePixel = 1000.; // tick size (in pixels) for alpha = 1.
    const double rangePixel =  width();
    const double range_min = btmLeft.x();
    const double range_max =  topRight.x();
    const double range = range_max - range_min;
    double smallTickSize;
    bool half_tick;
    ticks_size(range_min, range_max, rangePixel, smallestTickSizePixel, &smallTickSize, &half_tick);
    if ( (_imp->dataType == eDataTypeInt) && (smallTickSize < 1.) ) {
        smallTickSize = 1.;
        half_tick = false;
    }
    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 = fontM.width( QLatin1String("00") ); // 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);
        QColor color(textColor);
        color.setAlphaF(alpha);
        QPen pen(color);
        pen.setWidthF(1.9);
        p.setPen(pen);

        // for Int slider, because smallTickSize is at least 1, isFloating can never be true
        bool isFloating = std::abs(std::floor(0.5 + value) - value) != 0.;
        assert( !(_imp->dataType == eDataTypeInt && isFloating) );
        bool renderFloating = _imp->dataType == eDataTypeDouble || !isFloating;

        if (renderFloating) {
            QPointF tickBottomPos = _imp->zoomCtx.toWidgetCoordinates(value, tickBottom);
            QPointF tickTopPos = _imp->zoomCtx.toWidgetCoordinates(value, tickTop);

            p.drawLine(tickBottomPos, tickTopPos);
        }

        if ( renderFloating && (tickSize > minTickSizeText) ) {
            const int tickSizePixel = rangePixel * tickSize / range;
            const QString s = QString::number(value);
            const int sSizePixel =  fontM.width(s);
            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;
                }
                QColor c = _imp->readOnly || !isEnabled() ? Qt::black : textColor;
                c.setAlphaF(alphaText);
                p.setFont(_imp->font);
                p.setPen(c);

                QPointF textPos = _imp->zoomCtx.toWidgetCoordinates( value, btmLeft.y() );

                p.drawText(textPos, s);
            }
        }
    }
    double positionValue = _imp->zoomCtx.toWidgetCoordinates(_imp->value, 0).x();
    QPointF sliderBottomLeft(positionValue - TO_DPIX(SLIDER_WIDTH) / 2, height() - 1 - fontM.height() / 2);
    QPointF sliderTopRight( positionValue + TO_DPIX(SLIDER_WIDTH) / 2, height() - 1 - fontM.height() / 2 - TO_DPIY(SLIDER_HEIGHT) );

    /*draw the slider*/
    p.setPen(_imp->sliderColor);
    p.fillRect(sliderBottomLeft.x(), sliderBottomLeft.y(), sliderTopRight.x() - sliderBottomLeft.x(), sliderTopRight.y() - sliderBottomLeft.y(), _imp->sliderColor);

    /*draw a black rect around the slider for contrast or orange when focused*/
    if ( !hasFocus() ) {
        p.setPen(Qt::black);
    } else {
        QPen pen = p.pen();
        pen.setColor( QColor(243, 137, 0) );
        QVector<qreal> dashStyle;
        qreal space = 2;
        dashStyle << 1 << space;
        pen.setDashPattern(dashStyle);
        p.setOpacity(0.8);
        p.setPen(pen);
    }

    p.drawLine( sliderBottomLeft.x(), sliderBottomLeft.y(), sliderBottomLeft.x(), sliderTopRight.y() );
    p.drawLine( sliderBottomLeft.x(), sliderTopRight.y(), sliderTopRight.x(), sliderTopRight.y() );
    p.drawLine( sliderTopRight.x(), sliderTopRight.y(), sliderTopRight.x(), sliderBottomLeft.y() );
    p.drawLine( sliderTopRight.x(), sliderBottomLeft.y(), sliderBottomLeft.x(), sliderBottomLeft.y() );
} // paintEvent
예제 #19
0
파일: GLMHelpers.cpp 프로젝트: disigma/hifi
glm::vec4 toGlm(const QColor& color) {
    return glm::vec4(color.redF(), color.greenF(), color.blueF(), color.alphaF());
}
예제 #20
0
QPixmap
KnobGuiButton::loadPixmapInternal(bool checked, bool applyColorOverlay, const QColor& overlayColor)
{
    KnobGuiPtr knobUI = getKnobGui();
    KnobButtonPtr knob = _knob.lock();
    EffectInstancePtr isEffect = toEffectInstance( knob->getHolder() );
    KnobTableItemPtr isTableItem = toKnobTableItem(knob->getHolder());
    if (isTableItem) {
        isEffect = isTableItem->getModel()->getNode()->getEffectInstance();
    }

    QString filePath;
    if (knobUI->getLayoutType() == KnobGui::eKnobLayoutTypeViewerUI) {
        filePath = QString::fromUtf8( knob->getInViewerContextIconFilePath(checked).c_str() );
    } else {
        filePath = QString::fromUtf8( knob->getIconLabel(checked).c_str() );
    }
    if ( !filePath.isEmpty() && !QFile::exists(filePath) ) {
        if (isEffect) {
            //Prepend the resources path
            QString resourcesPath = QString::fromUtf8( isEffect->getNode()->getPluginResourcesPath().c_str() );
            if ( !resourcesPath.endsWith( QLatin1Char('/') ) ) {
                resourcesPath += QLatin1Char('/');
            }
            filePath.prepend(resourcesPath);
        }
    }

    if ( !filePath.isEmpty() ) {
#if 0
        QPixmap pix;
        if (pix.load(filePath)) {
            return pix;
        }
#else
        QImage img;
        if ( img.load(filePath) ) {
            if (applyColorOverlay) {

                int depth = img.depth();
                if (depth != 32) {
                    img = img.convertToFormat(QImage::Format_ARGB32);
                }
                depth = img.depth();
                assert(depth == 32);
                for (int y = 0; y < img.height(); ++y) {
                    QRgb* pix = (QRgb*)img.scanLine(y);
                    for (int x = 0; x < img.width(); ++x) {
                        QRgb srcPix = pix[x];
                        double a = qAlpha(srcPix) / 255.f;
                        double r = qRed(srcPix) / 255.f * a;
                        double g = qGreen(srcPix) / 255.f * a;
                        double b = qBlue(srcPix) / 255.f * a;

                        r = Image::clamp(overFunctor(overlayColor.redF(), r, overlayColor.alphaF()), 0., 1.);
                        g = Image::clamp(overFunctor(overlayColor.greenF(), g, overlayColor.alphaF()), 0., 1.);
                        b = Image::clamp(overFunctor(overlayColor.blueF(), b, overlayColor.alphaF()), 0., 1.);
                        a = Image::clamp(overFunctor(overlayColor.alphaF(), a, overlayColor.alphaF()) * a, 0., 1.);

                        QRgb p = qRgba(r * 255, g * 255, b * 255, a * 255);
                        img.setPixel(x, y, p);
                    }
                }
            }
            QPixmap pix = QPixmap::fromImage(img);
            return pix;
        }
#endif
    }
    return QPixmap();
} // loadPixmapInternal
예제 #21
0
void GLC_Viewport::clearBackground(const QColor& color) const
{
	glClearColor(color.redF(), color.greenF(), color.blueF(), 1.0f);
}
예제 #22
0
// call when the user changes directory where *.stl files are saved
void SimGui::environmentSetup()
{
  // get name and file path for each object
  QList<QString> objectBaseName = settings->getObjectBaseName();
  QList<QString> objectFilePath = settings->getObjectFilePath();

  qDebug() << "File paths to objects: " << objectFilePath;

  //
  // QListWidgetItem - for toggling objects on and off
  //

  // clear and then add items to the object list 
  ui->objectListWidget->clear();
  ui->objectListWidget->addItems( QStringList(objectBaseName) );

  // make all items in the list checkable
  QList<QListWidgetItem*> itemList 
    = ui->objectListWidget->findItems(QString("*"), Qt::MatchWrap | Qt::MatchWildcard);
  for( auto item : itemList ){
    item->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
    item->setCheckState( Qt::CheckState::Checked );
  }

  //
  // QAction - for changing object color
  //

  QList<QAction*> actionList = ui->objectListWidget->actions();
  for( auto action : actionList ){
    ui->objectListWidget->removeAction( action );
  }

  QString contextMenuTitle;
  QAction *action;
  for( auto baseName : objectBaseName ){
    contextMenuTitle = "Change color: " + baseName;
    action = new QAction( contextMenuTitle, this );
    action->setObjectName( baseName );
    ui->objectListWidget->addAction( action );
    connect( action, &QAction::triggered, this, &SimGui::changeObjectColor );
  }

  // context menu item to change the color of the background
  action = new QAction( "Change color: background", this );
  action->setObjectName( "background" );
  ui->objectListWidget->addAction( action );
  connect( action, &QAction::triggered, this, &SimGui::changeObjectColor );

  //
  // MabdiSimulatedSensor - add object to the simulated sensor and set color
  //

  for(auto filePath : objectFilePath ){
    engine.sensor.addObject( filePath.toStdString().c_str() );
  }

  QList<QColor> objectColorList 
    = settings->getSetting( SimGuiSettings::Key::ObjectColor ).value< QList<QColor> >();
  int count = 0;
  for( auto c : objectColorList ){
    engine.sensor.setObjectColor( count, c.redF(), c.greenF(), c.blueF() );
    count++;
  }

  // background color
  QColor c = settings->getSetting( SimGuiSettings::Key::ScenarioViewBackgroundColor ).value<QColor>();
  engine.sensor.setBackgroundColor( c.redF(), c.greenF(), c.blueF() );
}
예제 #23
0
DAVA::Color QColorToColor(const QColor &qcolor)
{
	return Color(qcolor.redF(), qcolor.greenF(), qcolor.blueF(), qcolor.alphaF());
}
예제 #24
0
void GraphicsPainter::setColor(const QColor &color)
{
    d->drawColor = color;
    glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF());
}
예제 #25
0
bool
ClipObject::commandEditor()
{
  PropertyEditor propertyEditor;
  QMap<QString, QVariantList> plist;
  QVariantList vlist;
  vlist.clear();
  plist["command"] = vlist;


  vlist.clear();
  vlist << QVariant("double");
  vlist << QVariant(m_opacity);
  vlist << QVariant(0.0);
  vlist << QVariant(1.0);
  vlist << QVariant(0.1); // singlestep
  vlist << QVariant(1); // decimals
  plist["opacity"] = vlist;
  
  vlist.clear();
  vlist << QVariant("color");
  Vec pcolor = m_color;
  QColor dcolor = QColor::fromRgbF(pcolor.x,
				   pcolor.y,
				   pcolor.z);
  vlist << dcolor;
  plist["color"] = vlist;
  
  vlist.clear();
  vlist << QVariant("checkbox");
  vlist << QVariant(m_apply);
  plist["apply clipping"] = vlist;

  vlist.clear();
  vlist << QVariant("int");
  vlist << QVariant(m_tfset);
  vlist << QVariant(-1);
  vlist << QVariant(15);
  plist["tfset"] = vlist;

  vlist.clear();
  vlist << QVariant("int");
  vlist << QVariant(m_thickness);
  vlist << QVariant(0);
  vlist << QVariant(200);
  plist["thickness"] = vlist;

  vlist.clear();
  vlist << QVariant("checkbox");
  vlist << QVariant(m_solidColor);
  plist["solid color"] = vlist;

  vlist.clear();
  vlist << QVariant("checkbox");
  vlist << QVariant(m_showSlice);
  plist["show slice"] = vlist;

  vlist.clear();
  vlist << QVariant("checkbox");
  vlist << QVariant(m_showThickness);
  plist["show thickness"] = vlist;

  vlist.clear();
  vlist << QVariant("combobox");
  if (m_viewportType)
    vlist << QVariant(1);
  else
    vlist << QVariant(0);
  vlist << QVariant("orthographic");
  vlist << QVariant("perspective");
  plist["camera type"] = vlist;

  vlist.clear();
  vlist << QVariant("double");
  vlist << QVariant(m_stereo);
  vlist << QVariant(0.0);
  vlist << QVariant(1.0);
  vlist << QVariant(0.1); // singlestep
  vlist << QVariant(1); // decimals
  plist["stereo"] = vlist;
  
  vlist.clear();
  vlist << QVariant("checkbox");
  vlist << QVariant(m_showOtherSlice);
  plist["show other slice"] = vlist;


  QString vpstr = QString("%1 %2 %3 %4").\
                  arg(m_viewport.x()).\
                  arg(m_viewport.y()).\
                  arg(m_viewport.z()).\
                  arg(m_viewport.w());
  vlist.clear();
  vlist << QVariant("string");
  vlist << QVariant(vpstr);
  plist["viewport"] = vlist;

  vlist.clear();
  vlist << QVariant("double");
  vlist << QVariant(m_viewportScale);
  vlist << QVariant(0.5);
  vlist << QVariant(30.0);
  vlist << QVariant(0.1); // singlestep
  vlist << QVariant(1); // decimals
  plist["viewport scale"] = vlist;  


  vlist.clear();
  QFile helpFile(":/clipobject.help");
  if (helpFile.open(QFile::ReadOnly))
    {
      QTextStream in(&helpFile);
      QString line = in.readLine();
      while (!line.isNull())
	{
	  if (line == "#begin")
	    {
	      QString keyword = in.readLine();
	      QString helptext;
	      line = in.readLine();
	      while (!line.isNull())
		{
		  helptext += line;
		  helptext += "\n";
		  line = in.readLine();
		  if (line == "#end") break;
		}
	      vlist << keyword << helptext;
	    }
	  line = in.readLine();
	}
    }
  
  plist["commandhelp"] = vlist;
  
  //---------------------
  vlist.clear();
  QString mesg;
  if (m_scale1 < 0 || m_scale2 < 0)
    mesg += QString("scales : %1 %2\n").arg(-m_scale1).arg(-m_scale2);
  else
    mesg += QString("vscales : %1 %2\n").arg(m_scale1).arg(m_scale2);

  mesg += QString("opacity : %1\n").arg(m_opacity);
  mesg += QString("position : %1 %2 %3\n").			\
    arg(m_position.x).arg(m_position.y).arg(m_position.z);

  Quaternion q = orientation();
  Vec axis;
  qreal angle;
  q.getAxisAngle(axis, angle);
  mesg += QString("rotation : %1 %2 %3 : %4\n").			\
    arg(axis.x).arg(axis.y).arg(axis.z).arg(RAD2DEG(angle));
  
  
  mesg += QString("Red axis : %1 %2 %3\n").		\
    arg(m_xaxis.x).arg(m_xaxis.y).arg(m_xaxis.z);
  mesg += QString("Green axis : %1 %2 %3\n").		\
    arg(m_yaxis.x).arg(m_yaxis.y).arg(m_yaxis.z);
  mesg += QString("Blue axis : %1 %2 %3\n").		\
    arg(m_tang.x).arg(m_tang.y).arg(m_tang.z);
  
  vlist << mesg;
  
  plist["message"] = vlist;
  //---------------------



  QStringList keys;
  keys << "apply clipping";
  keys << "solid color";
  keys << "show slice";
  keys << "show thickness";
  keys << "show other slice";
  keys << "gap";
  keys << "color";
  keys << "opacity";
  keys << "gap";
  keys << "viewport";
  keys << "tfset";
  keys << "thickness";
  keys << "viewport scale";
  keys << "camera type";
  keys << "stereo";
  keys << "gap";
  keys << "command";
  keys << "commandhelp";
  keys << "message";
  
  propertyEditor.set("Clip Plane Dialog", plist, keys);
  
  QMap<QString, QPair<QVariant, bool> > vmap;

  if (propertyEditor.exec() == QDialog::Accepted)
    vmap = propertyEditor.get();
  else
    return true;
	      
  keys = vmap.keys();

  for(int ik=0; ik<keys.count(); ik++)
    {
      QPair<QVariant, bool> pair = vmap.value(keys[ik]);
      
      
      if (pair.second)
	{
	  if (keys[ik] == "color")
	    {
	      QColor color = pair.first.value<QColor>();
	      float r = color.redF();
	      float g = color.greenF();
	      float b = color.blueF();
	      m_color = Vec(r,g,b);
	    }
	  else if (keys[ik] == "opacity")
	    m_opacity = pair.first.toDouble();
	  else if (keys[ik] == "solid color")
	    m_solidColor = pair.first.toBool();
	  else if (keys[ik] == "apply clipping")
	    m_apply = pair.first.toBool();
	  else if (keys[ik] == "show slice")
	    m_showSlice = pair.first.toBool();
	  else if (keys[ik] == "show thickness")
	    m_showThickness = pair.first.toBool();
	  else if (keys[ik] == "show other slice")
	    m_showOtherSlice = pair.first.toBool();
	  else if (keys[ik] == "tfset")
	    m_tfset = pair.first.toInt();
	  else if (keys[ik] == "thickness")
	    m_thickness = pair.first.toInt();
	  else if (keys[ik] == "viewport scale")
	    m_viewportScale = pair.first.toDouble();
	  else if (keys[ik] == "camera type")
	    m_viewportType = (pair.first.toInt() == 1);
	  else if (keys[ik] == "stereo")
	    m_stereo = pair.first.toDouble();
	  else if (keys[ik] == "viewport")
	    {
	      vpstr = pair.first.toString();
	      QStringList list = vpstr.split(" ", QString::SkipEmptyParts);
	      if (list.count() == 4)
		{
		  float x = list[0].toFloat();
		  float y = list[1].toFloat();
		  float z = list[2].toFloat();
		  float w = list[3].toFloat();
		  if (x < 0.0f || x > 1.0f ||
		      y < 0.0f || y > 1.0f ||
		      z < 0.0f || z > 1.0f ||
		      w < 0.0f || w > 1.0f)
		    QMessageBox::information(0, "",
		      QString("Values for viewport must be between 0.0 and 1.0 : %1 %2 %3 %4").\
					     arg(x).arg(y).arg(z).arg(w));
		  else
		    m_viewport = QVector4D(x,y,z,w);
		}
	      else if (list.count() == 3)
		{
		  float x = list[0].toFloat();
		  float y = list[1].toFloat();
		  float z = list[2].toFloat();
		  if (x < 0.0f || x > 1.0f ||
		      y < 0.0f || y > 1.0f ||
		      z < 0.0f || z > 1.0f)
		    QMessageBox::information(0, "",
		      QString("Values for viewport must be between 0.0 and 1.0 : %1 %2 %3").\
					     arg(x).arg(y).arg(z));
		  else
		    m_viewport = QVector4D(x,y,z,z);
		}
	      else if (list.count() == 2)
		{
		  float x = list[0].toFloat();
		  float y = list[1].toFloat();
		  if (x < 0.0f || x > 1.0f ||
		      y < 0.0f || y > 1.0f)
		    QMessageBox::information(0, "",
		      QString("Values for viewport must be between 0.0 and 1.0 : %1 %2").\
					     arg(x).arg(y));
		  else
		    m_viewport = QVector4D(x,y,0.5,0.5);
		}
	      else
		{
		  QMessageBox::information(0, "", "Switching off the viewport");
		  m_viewport = QVector4D(-1,-1,-1,-1);
		}
	    }
	}
    }

  QString cmd = propertyEditor.getCommandString();
  if (!cmd.isEmpty())
    return processCommand(cmd);
  else
    return true;

//  if (propertyEditor.exec() == QDialog::Accepted)
//    {
//      QString cmd = propertyEditor.getCommandString();
//      if (!cmd.isEmpty())
//	return processCommand(cmd);
//    }
//  else
//    return true;
}
예제 #26
0
void Viewer::drawEdge(const Point_3& from, const Point_3& to, const QColor& clr, float r)
{
  /* Draw regular lines */
  if( m_isFlat ) {
    // disable lighting
    ::glDisable( GL_LIGHTING );

    ::glLineWidth(1.0);
  	qglColor( clr );

    ::glBegin(GL_LINES);
    ::glVertex3f( from.x(), from.y(), from.z() );
    ::glVertex3f( to.x(), to.y(), to.z() );
    ::glEnd();

    // resume lighting
    ::glEnable( GL_LIGHTING );

    return;
  }

  /* Draw edges as 3D cylinders */
  GLboolean lighting, colorMaterial;
  ::glGetBooleanv( GL_LIGHTING, &lighting );
  ::glGetBooleanv( GL_COLOR_MATERIAL, &colorMaterial );
  ::glEnable( GL_LIGHTING );
  ::glDisable(GL_COLOR_MATERIAL);

  float color[4];
  color[0] = clr.redF();
  color[1] = clr.greenF();
  color[2] = clr.blueF();
  color[3] = clr.alphaF();

  Vector_3 v = to - from;

  // compute the length of the edge
  // method 1:
//  float length = sqrt( CGAL::squared_distance( from, to ) );
  // method 2:
  float length = sqrt( v.squared_length() );

  // normalize
  v = v / length;
  // compute the angle: cos theta = v.z/1.0
  GLfloat angle = acos( v.z() ) / 3.1415927 * 180;

  ::glPushMatrix();

  // move to "from" point
  ::glTranslatef( from.x(), from.y(), from.z() );
  // rotate from z-axis to from-->to
  //  axis: cross product of z-axis and from-->to
  ::glRotatef( angle, -v.y(), v.x(), 0.0f );
  // draw
  GLUquadricObj* quadratic = ::gluNewQuadric();	// Create A Pointer To The Quadric Object
  ::gluQuadricNormals( quadratic, GLU_SMOOTH );	// Create Smooth Normals
  ::glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color );
  // gluCylinder draws a cylinder oriented along the z-axis
  ::gluCylinder( quadratic, r, r, length, 16, 4 );

  // move back to origin
  ::glPopMatrix();

  if ( colorMaterial )
    ::glEnable( GL_COLOR_MATERIAL );
  if ( !lighting )
    ::glDisable( GL_LIGHTING );
}
예제 #27
0
void VtkVisTabWidget::on_edgeColorPickerButton_colorPicked( QColor color )
{
	static_cast<vtkActor*>(_item->actor())->GetProperty()->SetEdgeColor(
	        color.redF(), color.greenF(), color.blueF());
	emit requestViewUpdate();
}
예제 #28
0
void GraphicsLayer11::setClearColor(const QColor& color)
{
	glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF());
}
예제 #29
0
파일: glutils.cpp 프로젝트: phg1024/CSCE641
void GLUtils::setColor(const QColor &c, const float& alpha)
{
    glColor4f(c.redF(), c.greenF(), c.blueF(), alpha);
}
예제 #30
0
void GraphicsLayer13::setColor(const QColor& color)
{
	glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF());
}