Ejemplo n.º 1
0
void Sky::insertGrad()
{
    ColorScale gradient;
    gradient.insert(0.0,sf::Color(mColUp.r,mColUp.g,mColUp.b,mColUp.a));
    gradient.insert(1.0,sf::Color(mColDown.r,mColDown.g,mColDown.b,mColDown.a));

    //LOG(mColUp.r);

    gradient.fillTab(tab,size);

    sf::Image img;
    img.create(size,size);

    for(int i=0; i<size; ++i)
    {
        for(int j=0; j<size; ++j)
        {
            img.setPixel(i,j,this->tab[j]);
        }
    }

    texture.loadFromImage(img);
    sprite.setTexture(texture);

}
/**
 * Fills the tab with gradient color.
 */
void AbstractFractaleAlgo::fillTabWithGradient() {
    ColorScale gradient;

    // Choose colors for the gradient
    gradient.insert(0.0,sf::Color::Black);
    gradient.insert(1.0,sf::Color::Green);
    gradient.insert(2.0,sf::Color::Magenta);
    gradient.insert(3.0,sf::Color::Yellow);

    // Fill a table with this gradient
    gradient.fillTab(colorTab, TAB_SIZE);
}
Ejemplo n.º 3
0
void ColorScaleButton::paintScale(QPainter *painter, const QRect &baseRect,
                                  const ColorScale &colorScale) {
  QRect rect = baseRect;
  rect.setX(rect.x() + 2);
  rect.setY(rect.y() + 2);
  rect.setWidth(rect.width() - 4);
  rect.setHeight(rect.height() - 4);

  QLinearGradient grad(QPointF(rect.x(), rect.y()), QPointF(rect.x() + rect.width(), rect.y()));
  std::map<float, Color> stops = colorScale.getColorMap();

  for (std::map<float, Color>::iterator it = stops.begin(); it != stops.end(); ++it)
    grad.setColorAt(it->first, colorToQColor(it->second));

  painter->setBrush(QBrush(grad));

  painter->drawRect(rect);
}
Ejemplo n.º 4
0
void 
Launch::addMetric(int context,
		      const QString &source,
		      const QString &host,
		      const QString &metric,
		      const char *instance,
		      const QmcDesc &desc,
		      const ColorScale &scale,
		      bool useSocks)
{
    int		i;
    QString	str(128);
    QString	col;

    if (_groupMetric == -1) {
#ifdef PCP_DEBUG
	if (pmDebug & DBG_TRACE_APPL1)
	    cerr << "Launch::addMetric: Called before startGroup."
		 << " Adding a group." << endl;
#endif
	startGroup();
    }

    preColor(context, source, host, metric, useSocks, str);
    str.append(" D ");

    MetricList::toString(scale[0].color(), col);
    str.append(col).append(',').setNum(scale[0].min());
    for (i = 1; i < scale.numSteps(); i++) {
	MetricList::toString(scale[i].color(), col);
	str.append(',').append(col).append(',');
	str.setNum(scale[i].min());
    }
    str.append(' ');

    postColor(desc, instance, str);
    _strings.append(str);
}
int 
main(int argc, char * argv[])
{
    FluidSimulation2D clFluidSim("OpenCL FluidSimulation2D");
    me = &clFluidSim;

    // create color scale
    bluewhite.AddPoint(0.0, 0, 0, 0);
    bluewhite.AddPoint(0.2, 0, 0, 1);
    bluewhite.AddPoint(0.4, 0, 1, 1);
    bluewhite.AddPoint(0.8, 0, 1, 0);
    bluewhite.AddPoint(1.6, 1, 1, 0);
    bluewhite.AddPoint(3.2, 1, 0, 0);

    // Initialize
    if(clFluidSim.initialize() != SDK_SUCCESS)
        return SDK_FAILURE;

    if(clFluidSim.parseCommandLine(argc, argv) != SDK_SUCCESS)
        return SDK_FAILURE;

    if(clFluidSim.isDumpBinaryEnabled())
    {
        return clFluidSim.genBinaryImage();
    }
    else
    {
        // Setup
        int status = clFluidSim.setup();
        if(status != SDK_SUCCESS)
        {
            if(status == SDK_EXPECTED_FAILURE)
                return SDK_SUCCESS;
            else
                return SDK_FAILURE;
        }

        // Run
        if(clFluidSim.run() != SDK_SUCCESS)
            return SDK_FAILURE;

        // VerifyResults
        if(clFluidSim.verifyResults() != SDK_SUCCESS)
            return SDK_FAILURE;

        clFluidSim.printStats();

        if(display)
        {
            // Run in  graphical window if requested 
            glutInit(&argc, argv);
            glutInitWindowPosition(100,10);
            glutInitWindowSize(400,400); 
            glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
            glutCreateWindow("LBM simulation"); 
            GLInit(); 
            glutDisplayFunc(render);
            glutIdleFunc(update);
            glutMouseFunc(mouse);
            glutMotionFunc(motion);
            glutReshapeFunc(reshape);
            glutKeyboardFunc(keyboard);

            std::cout << "Use Left-Mouse button to move the fluid\n";
            std::cout << "Use Right-Mouse button to draw boundary\n";
            std::cout << "Press r to reset the simulation\n";

            glutMainLoop();
        }

        // Cleanup
        if(clFluidSim.cleanup()!=SDK_SUCCESS)
            return SDK_FAILURE;
    }

    return SDK_SUCCESS;
}
void render()
{
    glClear(GL_COLOR_BUFFER_BIT);

    glBindTexture(GL_TEXTURE_2D, texnum);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

    unsigned char bitmap[LBWIDTH * LBHEIGHT * 4]; // rgba unsigned bytes

    double m, r, g, b;

    for(int y = 0; y < LBHEIGHT; y++)
    {
        for(int x = 0; x < LBWIDTH; x++)
        {
            if(me->isBoundary(x , y))
            {
                r = g = b = 0;
            }
            else
            {
                cl_double2 vel = me->getVelocity(x, y);
                m = sqrt(vel.s[0] * vel.s[0] + vel.s[1] * vel.s[1]);
                bluewhite.GetColor(m * 20, r, g, b);
            }

            bitmap[(x + y * LBWIDTH) * 4 + 0] = (unsigned char)(r * 255);
            bitmap[(x + y * LBWIDTH) * 4 + 1] = (unsigned char)(g * 255);
            bitmap[(x + y * LBWIDTH) * 4 + 2] = (unsigned char)(b * 255);
            bitmap[(x + y * LBWIDTH) * 4 + 3] = 255;
        }
    }

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, LBWIDTH, LBHEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, bitmap);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    glEnable(GL_TEXTURE_2D);

    // setup 2d pixel plotting camera
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.0f, (GLdouble) winwidth, 0.0f, (GLdouble) winheight, 0.0f, 1.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glViewport(0, 0, winwidth, winheight);

    glBegin(GL_QUADS);

    glColor3f(1.0, 1.0, 1.0);

    glTexCoord2f(0.0, 0.0);
    glVertex2i(0, 0);

    glTexCoord2f(1.0, 0.0);
    glVertex2i(winwidth, 0);

    glTexCoord2f(1.0, 1.0);
    glVertex2i(winwidth, winheight);

    glTexCoord2f(0.0, 1.0);
    glVertex2i(0, winheight);

    glEnd();

    glDisable(GL_TEXTURE_2D);

    glFlush();
    glutSwapBuffers();
}
Ejemplo n.º 7
0
void
BarObj::finishedAdd()
{
    const ColorSpec	*colSpec = NULL;
    SoNode		*object = ViewObj::object(_shape);
    SoSeparator		*labelSep = NULL;
    SoSeparator		*metricSep = NULL;
    SoSeparator		*instSep = NULL;
    SoSeparator		*barSep = new SoSeparator;
    SoSeparator		*baseSep = new SoSeparator;
    SoTranslation	*objTran = new SoTranslation;
    SoTranslation	*barTran = new SoTranslation;
    SoTranslation	*baseTran = new SoTranslation;
    SoTranslation	*modTran = new SoTranslation;
    ColorScale		*colScale = NULL;
    LabelSide		metSide = left;
    LabelSide		instSide = left;
    Text		**metText = NULL;
    Text		**instText = NULL;
    int			i;
    int			max = 0;
    int			numMetLabels = 0;
    int			numInstLabels = 0;

#ifdef PCP_DEBUG
    if (pmDebug & DBG_TRACE_APPL0)
	cerr << "BarObj::finishedAdd:" << endl;
#endif

    if (_metrics.numMetrics() == 0) {
	BaseObj::addBase(_root);
	pmprintf("%s: Error: Bar object has no metrics\n",
		 pmProgname);
	_length = 0;
	_width = baseWidth();
	_depth = baseDepth();
	return;
    }

    _root->addChild(objTran);

    if (_metLabels->size() || _instLabels->size()) {
	labelSep = new SoSeparator;
	_root->addChild(labelSep);
	SoBaseColor *base = new SoBaseColor;
	base->rgb.setValue(_labelColor[0], _labelColor[1], _labelColor[2]);
	labelSep->addChild(base);
    }
    _root->addChild(barSep);
    barSep->addChild(barTran);
    barSep->addChild(baseSep);
    baseSep->addChild(baseTran);
    barSep->addChild(modTran);
    BaseObj::addBase(baseSep);

    // Determine color mapping

    if (_colors.size())
	colSpec = theColorLists.list((const char *)_colors.toLatin1());

    if (colSpec != NULL) {
        if (colSpec->_scale) {
	    if (_mod == BarMod::yScale) {
		pmprintf("%s: Warning: Color scale ignored for Y-Scale Bar object.\n",
			 pmProgname);
	    }
	    else {
		if (colSpec->_list.size() == 0)
		    colScale = new ColorScale(0.0, 0.0, 1.0);
		else {
		    colScale = new ColorScale(*(colSpec->_list[0]));
		    for (i = 1; i < colSpec->_list.size(); i++)
			colScale->add(new ColorStep(*(colSpec->_list[i]),
							colSpec->_max[i]));
		}
	    }
	}
        else if (_mod == BarMod::color || _mod == BarMod::colYScale) {
	    pmprintf("%s: Warning: Expected color scale for color modulated Bar object.\n",
		     pmProgname);

	    if (colSpec->_list.size() == 0)
		colScale = new ColorScale(0.0, 0.0, 1.0);
	    else
		colScale = new ColorScale(*(colSpec->_list[0]));
	}
    }
    else {
        pmprintf("%s: Warning: No colours specified for Bar objects, defaulting to blue.\n",
                 pmProgname);

	if (_mod == BarMod::color || _mod == BarMod::colYScale)
	    colScale = new ColorScale(0.0, 0.0, 1.0);
    }

    if (_mod == BarMod::yScale) {
	if (colSpec != NULL)
	    for (i = 0; i < colSpec->_list.size(); i++)
		_metrics.add(*(colSpec->_list)[i]);
	_metrics.resolveColors(MetricList::perMetric);
    }

    // Generate Bar Modulate Object
    if (_mod == BarMod::yScale)
	_bars = new BarMod(&_metrics, object, _dir, _group,
			   (float)_length, (float)_maxHeight, (float)_length,
			   (float)_xSpace, (float)_zSpace);
    else {
	_bars = new BarMod(&_metrics, *colScale, object, _dir, _mod, _group,
			   (float)_length, (float)_maxHeight, (float)_length,
			   (float)_xSpace, (float)_zSpace);	
    }

    barSep->addChild(_bars->root());
    BaseObj::add(_bars);

    // Generate Labels

    if (_metLabels->size()) {
	if (_dir == BarMod::instPerRow)
	    if (_metDir == away)
		metSide = below;
	    else
		metSide = above;
	else
	    if (_metDir == away)
		metSide = right;
	    else
		metSide = left;

	metricSep = new SoSeparator;
	labelSep->addChild(metricSep);

	if (_metLabels->size() < _metrics.numMetrics())
	    numMetLabels = _metLabels->size();
	else
	    numMetLabels = _metrics.numMetrics();

	metText = calcLabels(*_metLabels, metSide, numMetLabels);
    }

    if (_instLabels->size()) {
	if (_dir == BarMod::instPerCol) {
	    max = _bars->cols();
	    if (_instDir == away)
		instSide = below;
	    else
		instSide = above;
	}
	else {
	    max = _bars->rows();
	    if (_instDir == away)
		instSide = right;
	    else
		instSide = left;
	}

	instSep = new SoSeparator;
	labelSep->addChild(instSep);

	if (_instLabels->size() < max)
	    numInstLabels = _instLabels->size();
	else
	    numInstLabels = max;

	instText = calcLabels(*_instLabels, instSide, numInstLabels);
    }

    // Width and depth of bars only, effects of labels added later

    _width = _bars->width();
    _depth = _bars->depth();

    // Insert the labels

    if (numMetLabels)
	metricSep->addChild(doLabels(metText, metSide, numMetLabels));

    if (numInstLabels)
	instSep->addChild(doLabels(instText, instSide, numInstLabels));

    // Work out where the bars live

    _bars->regenerate(_length, _length, _xSpace, _zSpace);
    _width = _bars->width();
    _depth = _bars->depth();

    baseTran->translation.setValue(_width / 2.0, 0.0, _depth / 2.0);
    
    _width += (u_int32_t)(baseWidth() + _margins[left] + _margins[right]+0.5);
    _depth += (u_int32_t)(baseDepth() + _margins[above] + _margins[below]+0.5);

    objTran->translation.setValue((_width / -2.0), 0.0, (_depth / -2.0));

    barTran->translation.setValue(_margins[left] + borderX(), 0.0,
				  _margins[above] + borderZ());


    modTran->translation.setValue(0.0, 
				  (BaseObj::state() ? baseHeight() : 0.0),
				  0.0);

#ifdef PCP_DEBUG
    if (pmDebug & DBG_TRACE_APPL0)
	cerr << "BarObj::finishedAdd: metric list = " << endl
	     << _metrics << endl;
#endif

    if (_metrics.numMetrics())
	ViewObj::theNumModObjects++;

    // Cleanup

    if (colScale)
	delete colScale;
    delete _metLabels;
    delete _instLabels;
}