コード例 #1
0
ファイル: ExtractEdges.cpp プロジェクト: hofsta/KVS
void ExtractEdges::calculate_colors( const kvs::VolumeObjectBase* volume )
{
    const T* value = reinterpret_cast<const T*>( volume->values().data() );
    const T* const end = value + volume->values().size();

    kvs::ValueArray<kvs::UInt8> colors( 3 * volume->numberOfNodes() );
    kvs::UInt8* color = colors.data();

    kvs::ColorMap cmap( BaseClass::colorMap() );

    if ( !volume->hasMinMaxValues() ) { volume->updateMinMaxValues(); }
    const kvs::Real64 min_value = volume->minValue();
    const kvs::Real64 max_value = volume->maxValue();

    const kvs::Real64 normalize_factor =
        static_cast<kvs::Real64>( cmap.resolution() - 1 ) / ( max_value - min_value );

    const size_t veclen = BaseClass::volume()->veclen();
    if ( veclen == 1 )
    {
        while ( value < end )
        {
            const kvs::UInt32 color_level =
                static_cast<kvs::UInt32>( normalize_factor * ( static_cast<kvs::Real64>( *( value++ ) ) - min_value ) );

            *( color++ ) = cmap[ color_level ].red();
            *( color++ ) = cmap[ color_level ].green();
            *( color++ ) = cmap[ color_level ].blue();
        }
    }
    else
    {
        while( value < end )
        {
            kvs::Real64 magnitude = 0.0;
            for ( size_t i = 0; i < veclen; ++i )
            {
                magnitude += kvs::Math::Square( static_cast<kvs::Real64>( *value ) );
                ++value;
            }
            magnitude = std::sqrt( magnitude );

            const kvs::UInt32 color_level =
                static_cast<kvs::UInt32>( normalize_factor * ( magnitude - min_value ) );

            *( color++ ) = cmap[ color_level ].red();
            *( color++ ) = cmap[ color_level ].green();
            *( color++ ) = cmap[ color_level ].blue();
        }
    }

    SuperClass::setColors( colors );
}
コード例 #2
0
ファイル: main.cpp プロジェクト: caomw/parallel-clustering
void PlotClusters(cv::Mat &dataset, const int *const medoids, const int *const assignment, int nData, int nMedoids)
{
    float minx = std::numeric_limits<float>::max();
    float miny = std::numeric_limits<float>::max();
    float maxx = 0;
    float maxy = 0;

    for(int i=0; i < dataset.rows; i++)
    {
        cv::Mat tmp = dataset.row(i);
        if(tmp.at<float>(0,0) < minx)
            minx = tmp.at<float>(0,0);
        if(tmp.at<float>(0,0) > maxx)
            maxx = tmp.at<float>(0,0);
        if(tmp.at<float>(0,1) < miny)
            miny = tmp.at<float>(0,1);
        if(tmp.at<float>(0,1) > maxy)
            maxy = tmp.at<float>(0,1);
    }
    float xdim = maxx - minx;
    float ydim = maxy - miny;

    Eigen::MatrixXd colors(nMedoids,3);

    ColorPicker picker(nMedoids);

    cv::Mat img = cv::Mat::ones(1024,1024,CV_8UC3);
    
    for(int i=0; i < dataset.rows-1; i++)
    {
        cv::Mat tmp = dataset.row(i);
        float x = ((tmp.at<float>(0,0) - minx)/xdim)*1024;
        float y = ((tmp.at<float>(0,1) - miny)/ydim)*1024;
        cv::Point2f a(x,y);
        Color c = picker.getColor(assignment[i]);
        cv::circle(img, a, 2, cv::Scalar(c.r_,c.g_,c.b_), -1 );
    }
    for(int i=0; i < nMedoids; i++)
    {
        int center_ind = medoids[i];
        cv::Mat tmp = dataset.row(medoids[i]);
        float x = ((tmp.at<float>(0,0) - minx)/xdim)*1024;
        float y = ((tmp.at<float>(0,1) - miny)/ydim)*1024;
        cv::Point2f a(x,y);
        Color c = picker.getColor(assignment[medoids[i]]);
        cv::circle(img, a, 10, cv::Scalar(c.r_,c.g_,c.b_), -1 );
    }

    cv::imwrite("Clusters.jpg", img);
//    cv::imshow("Clusters",img);
 //   cv::waitKey(0);

}
コード例 #3
0
ファイル: Topological-sort.cpp プロジェクト: yuandaxing/utils
bool topologicalSort(const AdjacentGraph& adjG, 
		veci &sortingVertice) {
	std::vector<int> colors(adjG.getSize(), White);
	std::vector<int> d(adjG.getSize(), NotAcess);
	std::vector<int> pai(adjG.getSize(), nil);
	std::vector<int> finish(adjG.getSize(), NotAcess);

	bool haveCircle = false;
	int time = 1;

	for( int i = 0; i < adjG.getSize(); i++ ) {
		if(colors[i] == White) {
			colors[i] = Gray;
			d[i] = time;
			time += 1;
			pai[i] = nil;
			std::cout << "visit " << i << std::endl;
			DFSAuxliary(adjG, colors, d, pai, finish, 
					i, time, haveCircle);
			if(haveCircle)
				return false;
		}
	}

	
	std::cout << "start " << d << std::endl;
	std::cout << "finish " << finish << std::endl;


	typedef std::pair<int, int> finishIndex;
	std::vector<finishIndex> tmp;

	for( int i = 0 ; static_cast<unsigned>(i) < finish.size() ; i++ )
	{
		tmp.push_back(std::make_pair(finish[i], i));
	}

	std::sort(tmp.begin(), tmp.end());

	for( int i = 0 ; static_cast<unsigned>(i) < tmp.size() ; i++ )
	{
		sortingVertice.push_back(tmp[i].second);
	}

	for( int i = 0, j = tmp.size() - 1 ;
		   	i < j ; i++, j-- )
	{
		std::swap(sortingVertice[i], sortingVertice[j]);
	}
	return true;

}
コード例 #4
0
QVector<triC> mutableSquareImageContainer::checkColorList() {

  if (colorListCheckNeeded_) {
    const grid gridImage(image_);
    const QVector<triC> colorsToRemove = ::findColors(gridImage, colors());
    removeColors(colorsToRemove);
    colorListCheckNeeded_ = false;
    return colorsToRemove;
  }
  else {
    return QVector<triC>();
  }
}
コード例 #5
0
ファイル: topologicalsort.cpp プロジェクト: lyoz/library
bool TopologicalSort(const Graph& g,vi& order)
{
	int size=g.size();
	order.clear();
	vi colors(size);
	rep(i,size){
		if(!Visit(g,i,colors,order)){
			order.clear();
			return false;
		}
	}
	reverse(all(order));
	return true;
}
コード例 #6
0
ファイル: SphereGlyph.cpp プロジェクト: fudy1129/kvs
/*===========================================================================*/
void SphereGlyph::attach_point( const kvs::PointObject* point )
{
    m_point = point;

    const size_t nvertices = point->numberOfVertices();

    BaseClass::setCoords( point->coords() );

    if ( BaseClass::directionMode() == BaseClass::DirectionByNormal )
    {
        if ( point->numberOfNormals() != 0 )
        {
            BaseClass::setDirections( point->normals() );
        }
    }

    if ( point->numberOfSizes() == 1 )
    {
        const kvs::Real32 size = point->size();
        kvs::ValueArray<kvs::Real32> sizes( nvertices );
        for ( size_t i = 0; i < nvertices; i++ ) sizes[i] = size;
        BaseClass::setSizes( sizes );
    }
    else
    {
        BaseClass::setSizes( point->sizes() );
    }

    if ( point->numberOfColors() == 1 )
    {
        const kvs::RGBColor color = point->color();
        kvs::ValueArray<kvs::UInt8> colors( nvertices * 3 );
        for ( size_t i = 0, j = 0; i < nvertices; i++, j += 3 )
        {
            colors[j]   = color.r();
            colors[j+1] = color.g();
            colors[j+2] = color.b();
        }
        BaseClass::setColors( colors );
    }
    else
    {
        BaseClass::setColors( point->colors() );
    }

    const kvs::UInt8 opacity = static_cast<kvs::UInt8>( 255 );
    kvs::ValueArray<kvs::UInt8> opacities( nvertices );
    for ( size_t i = 0; i < nvertices; i++ ) opacities[i] = opacity;
    BaseClass::setOpacities( opacities );
}
コード例 #7
0
ファイル: laser.cpp プロジェクト: Ranqing/HumanBodyLaser
void HumanBodyLaser::compute3DPoints()
{
	cout << "\nCompute 3D points from the disparity result." << endl;

	Mat mask = erodeMask(mskL, (stereoPyr[0]->GetWsize())*2);
	Mat disp = stereoPyr[0]->GetDisp();	

	vector<Point3f> points(0);
	vector<Vec3b> colors(0);
	vector<Vec3f> normals(0);

	float offsetD = stPointL.x - stPointR.x;
	int height = imSize.height;
	int width  = imSize.width;
	int validnum = 0;

	for(int y = 0; y < height; ++y)
	{
		float * pdsp = (float *)disp.ptr<float>(y);
		uchar * pmsk = (uchar *)mask.ptr<uchar>(y);

		for(int x = 0; x < width; ++x)
		{
			if (pmsk[x] == 0)
			{
				pdsp[x] = 0;
				continue;
			}

			if (pdsp[x] != 0)
			{
				pdsp[x] += offsetD;
				validnum ++;
			}
		}
	}

	Mat colorImL;
	imL.convertTo(colorImL, CV_8U, 255);   //RGB

	Disp2Point(disp, stPointL, colorImL, mask, QMatrix, points, colors, normals);

	//refine3DPoints(points, colors, validnum);

	//string savefn = outdir + "/pointcloud_" + camL + camR + "_" + frame + ".ply";
	string savefn = "d_pointcloud_" + camL + camR + "_" + frame + ".ply";
	writePLY(savefn, width, height, validnum, PT_HAS_COLOR|PT_HAS_NORMAL, points, colors, normals);
	cout << "\nsave " << savefn << " done. " << validnum << " Points." << endl;
}
コード例 #8
0
ファイル: Texture.cpp プロジェクト: GeorgievLab/CeCe-core
void Texture::resize(Size size, const Color& color)
{
    CECE_ASSERT(isInitialized());

    m_size = std::move(size);

    const auto width = m_size.getWidth();
    const auto height = m_size.getHeight();

    // Create initial buffer
    DynamicArray<Color> colors(width * height, color);

    gl(glBindTexture(GL_TEXTURE_2D, m_id));
    gl(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, ColorComponentType<Color::ComponentType>::value, colors.data()));
}
コード例 #9
0
ファイル: Texture.cpp プロジェクト: GustavoPB/CeCe
void Texture::resize(Size size, const Color& color)
{
    assert(isInitialized());

    m_size = std::move(size);

    const auto width = m_size.getWidth();
    const auto height = m_size.getHeight();

    // Create initial buffer
    DynamicArray<Color> colors(width * height, color);

    gl(glBindTexture(GL_TEXTURE_2D, m_id));
    gl(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_FLOAT, colors.data()));
}
コード例 #10
0
ファイル: Render.cpp プロジェクト: flosmn/AntiradianceCuts
void Renderer::DrawLights(const std::vector<Avpl>& avpls, CRenderTarget* target)
{	
	if(!m_confManager->GetConfVars()->DrawLights || avpls.size() == 0)
		return;

	std::vector<glm::vec3> positions(avpls.size());
	std::vector<glm::vec3> colors(avpls.size());
	for (int i = 0; i < avpls.size(); ++i) {
		positions[i] = avpls[i].getPosition();
		colors[i] = glm::vec3(1.f, 0.f, 1.f);
	}
	std::shared_ptr<PointCloud> pointCloud = std::make_shared<PointCloud>(positions, colors, m_ubTransform.get(), m_scene->getSceneExtent() / 100.f);

	CRenderTargetLock lock(target);
	pointCloud->Draw();
}
コード例 #11
0
ファイル: plotviewer.cpp プロジェクト: gtrosen/Vespucci
PlotViewer::PlotViewer(QWidget *parent, const arma::vec &x, const arma::vec &y, arma::vec z, QString x_label, QString y_label) :
    QDialog(parent),
    ui(new Ui::PlotViewer),
    context_menu_("Plot Options", this),
    directory_(QDir::homePath())
{
    ui->setupUi(this);
    plot_ = findChild<QCustomPlot *>("plot");
    plot_->setContextMenuPolicy(Qt::CustomContextMenu);
    connect(plot_, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(ShowContextMenu(QPoint)));
    AddContextMenuItems();
    typedef std::vector<double> stdvec;
    arma::field<arma::vec> x_parts;
    arma::field<arma::vec> y_parts;
    arma::vec unique_z = arma::unique(z);
    x_parts.set_size(unique_z.n_rows);
    y_parts.set_size(unique_z.n_rows);
    QVector<QColor> colors(unique_z.n_rows);
    colors.append(QColor(228,26,28));
    colors.append(QColor(55,126,184));
    colors.append(QColor(77,175,74));
    colors.append(QColor(152,78,163));
    colors.append(QColor(255,127,0));
    colors.append(QColor(255,255,51));
    colors.append(QColor(166,86,40));
    colors.append(QColor(247,129,191));
    colors.append(QColor(153,153,153));

    plot_->xAxis->setLabel(x_label);
    plot_->yAxis->setLabel(y_label);
    plot_->xAxis->setRange(x.min(), x.max());
    plot_->yAxis->setRange(y.min(), y.max());
    for (arma::uword i = 0; i < unique_z.n_rows; ++i){
        QPen pen(colors[i]);
        arma::uvec ind = arma::find(z == unique_z(i));
        QVector<double> x_qvec = QVector<double>::fromStdVector(arma::conv_to<stdvec>::from(x(ind)));
        QVector<double> y_qvec = QVector<double>::fromStdVector(arma::conv_to<stdvec>::from(y(ind)));
        plot_->addGraph();
        plot_->graph(i)->setName(QString::number(i));
        plot_->graph(i)->setData(x_qvec, y_qvec);
        plot_->graph(i)->setPen(pen);
        plot_->graph(i)->setScatterStyle(QCPScatterStyle::ssDisc);
        plot_->legend->setVisible(true);
        plot_->graph(i)->addToLegend();
    }
    plot_->replot();
}
コード例 #12
0
ファイル: Tuto11.cpp プロジェクト: fkanehiro/etc
osg::ref_ptr<osg::Drawable> myQuad ()
{
   osg::ref_ptr<osg::Geode> geode (new osg::Geode());
   osg::ref_ptr<osg::Geometry> geometry (new osg::Geometry());

   osg::ref_ptr<osg::Vec3Array> vertices (new osg::Vec3Array());

   vertices->push_back (osg::Vec3 ( 1.0, 0.0, 0.0));
   vertices->push_back (osg::Vec3 ( 1.0, 0.0, 1.0));
   vertices->push_back (osg::Vec3 ( 0.0, 0.0, 1.0));
   vertices->push_back (osg::Vec3 (0.0, 0.0, 0.0));

   geometry->setVertexArray (vertices.get());

   // All vertices are white this time (it's hard to see that we have two
   // textures with all the colors...)
   osg::ref_ptr<osg::Vec4Array> colors (new osg::Vec4Array());
   colors->push_back (osg::Vec4 (1.0f, 1.0f, 1.0f, 1.0f));
   geometry->setColorArray (colors.get());
   geometry->setColorBinding (osg::Geometry::BIND_OVERALL);

   osg::ref_ptr<osg::Vec3Array> normals (new osg::Vec3Array());
   normals->push_back (osg::Vec3 (0.0f, -1.0f, 0.0f));
   geometry->setNormalArray (normals.get());
   geometry->setNormalBinding (osg::Geometry::BIND_OVERALL);


   osg::ref_ptr<osg::Vec2Array> texCoords (new osg::Vec2Array());

   texCoords->push_back (osg::Vec2 (0.0, 0.0));
   texCoords->push_back (osg::Vec2 (0.0, 1.0));
   texCoords->push_back (osg::Vec2 (1.0, 1.0));
   texCoords->push_back (osg::Vec2 (1.0, 0.0));

   // Here, the two texture units (0 and 1) share the same texture coordinates.
   geometry->setTexCoordArray (0, texCoords.get());
   geometry->setTexCoordArray (1, texCoords.get());

   // Back to the usual: setup a primitive set and add the geometry to the geode.
   geometry->addPrimitiveSet(
      new osg::DrawArrays (osg::PrimitiveSet::QUADS, // how to render?
                           0,                            // index of first vertex
                           vertices->size()));           // how many vertices?
  // geode->addDrawable (geometry.get());

   return geometry.get();
}
コード例 #13
0
ファイル: QViewWidget.cpp プロジェクト: banduladh/levelfour
void ViewWidget::initGrids()
{
   const int numVertices = 2 * 2 * GRID_LINE_COUNT;
   osg::Vec3 vertices[numVertices];
   float length = (GRID_LINE_COUNT - 1) * GRID_LINE_SPACING;
   int ptr = 0;

   for(int i = 0; i < GRID_LINE_COUNT; ++i)
   {
      vertices[ptr++].set(-length / 2 + i * GRID_LINE_SPACING, length / 2, 0.0f);
      vertices[ptr++].set(-length / 2 + i * GRID_LINE_SPACING, -length / 2, 0.0f);
   }

   for (int i = 0; i < GRID_LINE_COUNT; ++i)
   {
      vertices[ptr++].set(length / 2, -length / 2 + i * GRID_LINE_SPACING, 0.0f);
      vertices[ptr++].set(-length / 2, -length / 2 + i * GRID_LINE_SPACING, 0.0f);
   }

   osg::ref_ptr<osg::Vec4Array> colors (new osg::Vec4Array());
   colors->push_back (osg::Vec4 (0.3, 0.3, 0.3, 1.0));

   osg::Geometry* geometry = new osg::Geometry;
   geometry->setVertexArray(new osg::Vec3Array(numVertices, vertices));
   geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, numVertices));
   geometry->setColorArray (colors.get());
   geometry->setColorBinding (osg::Geometry::BIND_PER_PRIMITIVE_SET);

   osg::Geode* geode = new osg::Geode;
   geode->addDrawable(geometry);
   geode->getOrCreateStateSet()->setMode(GL_LIGHTING, 0);

   mpXYGridTransform = new osg::MatrixTransform;
   mpXYGridTransform->addChild(geode);

   mpXZGridTransform = new osg::MatrixTransform;
   mpXZGridTransform->setMatrix(osg::Matrix::rotate(osg::PI_2, 1, 0, 0));

   mpXZGridTransform->addChild(geode);
   mpXZGridTransform->setNodeMask(0x0);

   mpYZGridTransform = new osg::MatrixTransform;
   mpYZGridTransform->setMatrix(osg::Matrix::rotate(osg::PI_2, 0, 1, 0));

   mpYZGridTransform->addChild(geode);
   mpYZGridTransform->setNodeMask(0x0);
}
コード例 #14
0
Peg_world_wrapper::Peg_world_wrapper(ros::NodeHandle &nh,
                                     const std::string& node_name,
                                     const std::string& path_sensor_model,
                                     const std::string& fixed_frame,
                                     const std::string table_link_name,
                                     const std::string socket_link_name,
                                     const std::string socket_link_box_name)
    :fixed_frame(fixed_frame),
     table_link_name(table_link_name),
     socket_link_name(socket_link_name),
     socket_link_box_name(socket_link_box_name)
{


    // Initialise the table wall
    initialise_table_wall(table_link_name);
    initialise_socket(socket_link_name,socket_link_box_name);


    world_publisher = std::shared_ptr<ww::Publisher>(new ww::Publisher( node_name + "/visualization_marker",&nh,&world_wrapper));
    world_publisher->init(fixed_frame);
    world_publisher->update_position();

   /// Visualise socket

    vis_socket = std::shared_ptr<obj::Vis_socket>(new  obj::Vis_socket(nh,world_wrapper.wrapped_objects.wsocket));
    vis_socket->initialise(25,0.01);


    /// Peg model (Cartesian points);

     peg_sensor_model = std::shared_ptr<Peg_sensor_model>(new Peg_sensor_model(path_sensor_model,fixed_frame,world_wrapper.wrapped_objects));


    vis_points = std::shared_ptr<opti_rviz::Vis_points>( new  opti_rviz::Vis_points(nh,"peg_model"));
    vis_points->scale = 0.005;
    vis_points->initialise(fixed_frame,peg_sensor_model->get_model());

    vis_vectors = std::shared_ptr<opti_rviz::Vis_vectors>(new opti_rviz::Vis_vectors(nh,"closest_features") );
    vis_vectors->scale = 0.005;
    std::vector<tf::Vector3> colors(2);
    colors[0] = tf::Vector3(1,0,0);
    colors[1] = tf::Vector3(0,0,1);
    vis_vectors->set_color(colors);
    vis_vectors->initialise(fixed_frame,peg_sensor_model->get_arrows());

}
コード例 #15
0
ファイル: output_nstd.c プロジェクト: thomasba/sudokuloeser
void nstd_ausgabe(sudoku* s,int color) {
    int i,j;
    for(i=0; i<9; i++) {
        if(i%3==0 && !color) printf("+-------+-------+-------+\n");
        for(j=0; j<9; j++) {
            if(j%3==0 && !color) printf("| ");
            if(color) {
                printf("%s%d \033[0m",colors(s->belegung[i][j]),s->feld[i][j]);
            } else
                printf("%d ",s->feld[i][j]);

        }
        if(!color) printf("|");
        printf("\n");
    }
    if(!color) printf("+-------+-------+-------+\n");
}
コード例 #16
0
ファイル: viewgfx.cpp プロジェクト: qwijibo/mame
static void ui_gfx_count_devices(running_machine &machine, ui_gfx_state &state)
{
	// count the palette devices
	state.palette.devcount = palette_interface_iterator(machine.root_device()).count();

	// set the pointer to the first palette
	if (state.palette.devcount > 0)
		palette_set_device(machine, state);

	// count the gfx devices
	state.gfxset.devcount = 0;
	for (device_gfx_interface &interface : gfx_interface_iterator(machine.root_device()))
	{
		// count the gfx sets in each device, skipping devices with none
		uint8_t count = 0;
		while (count < MAX_GFX_ELEMENTS && interface.gfx(count) != nullptr)
			count++;

		// count = index of first nullptr
		if (count > 0)
		{
			state.gfxdev[state.gfxset.devcount].interface = &interface;
			state.gfxdev[state.gfxset.devcount].setcount = count;
			for (uint8_t slot = 0; slot != count; slot++) {
				auto gfx = interface.gfx(slot);
				if (gfx->has_palette())
				{
					state.gfxdev[state.gfxset.devcount].palette[slot] = &gfx->palette();
					state.gfxdev[state.gfxset.devcount].color_count[slot] = gfx->colors();
				}
				else
				{
					state.gfxdev[state.gfxset.devcount].palette[slot] = state.palette.interface;
					state.gfxdev[state.gfxset.devcount].color_count[slot] = state.palette.interface->entries() / gfx->granularity();
					if (!state.gfxdev[state.gfxset.devcount].color_count[slot])
						state.gfxdev[state.gfxset.devcount].color_count[slot] = 1;
				}
			}
			if (++state.gfxset.devcount == MAX_GFX_DECODERS)
				break;
		}
	}

	state.started = true;
}
コード例 #17
0
ファイル: lgl_utils.cpp プロジェクト: tercatech/futuregl
	int draw_text(int corner_x, int corner_y, int size, string text, int color){
	
		if((size > 4 || size < 1) && size < 10 ){
			cerr << "FutureGL Error: FutureGL only supports 4 core font sizes\nPlease adapt your code. Sorry.\n";
			return -1;
		}
	
		colors(1, color);
		glTranslated(corner_x, corner_y, 0);
	
		// Create a texture font from a TrueType file.

		FTFont *font;
		bool font_loaded = false;

		for(int i = 0; i < num_fonts; i++){
			font = new FTTextureFont(fonts[i].c_str());
			if(!(font->Error())){
				font_loaded = true;
				break;
			}
		}

		
		if(!font_loaded){
			cerr << "FutureGL Error: Font not found\nTried:\n";
			for(int i = 0; i < num_fonts; i++) cerr << "\t" << fonts[i] << "\n";
			return -1;
		}
	
		// Set the font size and render a small text.
		
		if(size == 1) font->FaceSize(60);
		else if(size == 2) font->FaceSize(29);
		else if(size == 3) font->FaceSize(10);
		else if(size == 4) font->FaceSize(10);
		else font->FaceSize(size);
		font->Render(text.c_str());

		delete(font);

		glTranslated(-corner_x, -corner_y, 0);
	
		return 0;
	}
コード例 #18
0
ファイル: graphedge.cpp プロジェクト: KDE/kgraphviewer
const QString GraphEdge::color(uint i) 
{
  if (i >= (uint)m_colors.count() && m_attributes.find(KEY_COLOR) != m_attributes.end())
  {
    colors(m_attributes[KEY_COLOR]);
  }
  if (i < (uint)m_colors.count())
  {
//     std::cerr << "edge color " << i << " is " << m_colors[i] << std::endl;
//     kDebug() << fromNode()->id() << " -> " << toNode()->id() << "color" << i << "is" << m_colors[i];
    return m_colors[i];
  }
  else
  {
//     kDebug() << fromNode()->id() << " -> " << toNode()->id() << "no edge color " << i << ". returning " << DOT_DEFAULT_EDGE_COLOR;
    return DOT_DEFAULT_EDGE_COLOR;
  }
}
コード例 #19
0
BOOL CExtendedCPU5EAXAMD::OnInitDialog()
   {
    CExtendedCPU5AMD::OnInitDialog();

    c_Caption.SetWindowText(_T(""));

    ColorSet colors(TRUE);

    POSITION p;
    p = colors.GetFirstColorPosition();
    SETCOLOR(7_0);
    SETCOLOR(15_8);
    SETCOLOR(23_16);
    SETCOLOR(31_24);

    return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
   }
コード例 #20
0
void DebugUpdateFrustum( const RenderablePtr& rend, const Frustum& box )
{
	std::vector<Vector3> pos;
	ADD_BOX_FRUSTUM( 0, 1, 3, 2 ) // Front
	ADD_BOX_FRUSTUM( 0, 1, 5, 4 ) // Top
	ADD_BOX_FRUSTUM( 4, 5, 7, 6 ) // Back
	ADD_BOX_FRUSTUM( 2, 3, 7, 6 ) // Bottom
	ADD_BOX_FRUSTUM( 0, 2, 6, 4 ) // Left
	ADD_BOX_FRUSTUM( 5, 1, 3, 7 ) // Right

	GeometryBuffer* gb = rend->getGeometryBuffer().get();
	gb->set( VertexAttribute::Position, pos );

	std::vector<Vector3> colors( pos.size(), Color::White );
	gb->set( VertexAttribute::Color, colors );

	gb->forceRebuild();
}
コード例 #21
0
    // nothing to inherit from GC really
    ColoredGraph solve(const Graph& gr) override {

        CoinModel coinModel;
        for (auto i = 0; i < gr.nodeCount(); ++i) {
            coinModel.addCol(0, nullptr, nullptr, 0, gr.nodeCount()-1, 1, nullptr, true);
        }
        OsiClpSolverInterface solver;
        solver.loadFromCoinModel(coinModel);

        CbcModel model(solver);
        model.setLogLevel(0);
        model.passInEventHandler(make_unique<GC_LP_EventHandler>(recoveryPath).get());

        if (use_heuristic) {
            GC_LP_Heuristic heuristic;
            model.addHeuristic(&heuristic);
        }

        AddRules(model, gr);

        if (use_parallel) {
            model.setNumberThreads(std::thread::hardware_concurrency());
        }

        if (max_seconds != 0) model.setMaximumSeconds(max_seconds);

        model.initialSolve();
        model.branchAndBound();

        if (model.maximumSecondsReached()) Println(cout, "max seconds reached");
        if (model.isSecondsLimitReached()) Println(cout, "seconds limit reached");

        seconds_passed_ = model.getCurrentSeconds();
        iterations_passed_ = model.getIterationCount();

        const double *solution = model.bestSolution();

        if (solution == nullptr) {
            vector<Color> colors(gr.nodeCount());
            iota(colors.begin(), colors.end(), 0);
            return {gr, colors};
        }
        return ColoredGraph(gr, {solution, solution+gr.nodeCount()});
    }
コード例 #22
0
      static void 
      run(const DistributedGraph& g,
          typename graph_traits<DistributedGraph>::vertex_descriptor s,
          PredecessorMap predecessor, DistanceMap distance, 
          Lookahead lookahead, WeightMap weight, IndexMap index_map, 
          ::boost::param_not_found,
          Compare compare, Combine combine, DistInf inf, DistZero zero,
          DijkstraVisitor vis)
      {
        typedef typename graph_traits<DistributedGraph>::vertices_size_type
          vertices_size_type;

        vertices_size_type n = num_vertices(g);
        std::vector<default_color_type> colors(n, white_color);

        run_impl(g, s, predecessor, distance, lookahead, weight, index_map,
                 make_iterator_property_map(colors.begin(), index_map),
                 compare, combine, inf, zero, vis);
      }
    void onPreDraw(SkCanvas* canvas) override {
        // Left to right
        SkPoint points[2] = {
            SkPoint::Make(0,        kSize/2),
            SkPoint::Make(kSize-1,  kSize/2),
        };

        constexpr int kNumColorChoices = 4;
        SkColor color_choices[kNumColorChoices] = {
            SK_ColorRED,
            SK_ColorGREEN,
            SK_ColorBLUE,
            SK_ColorYELLOW,
        };

        // Alternate between different choices
        SkAutoTArray<SkColor> colors(fColorCount);
        for (int i = 0; i < fColorCount; i++) {
            colors[i] = color_choices[i % kNumColorChoices];
        }

        // Create requisite number of hard stops, and evenly
        // space positions after that
        SkAutoTArray<SkScalar> positions(fColorCount);
        int k = 0;
        for (int i = 0; i < fHardStopCount; i++) {
            float val = k/2.0f;
            positions[k++] = val / fColorCount;
            positions[k++] = val / fColorCount;
        }
        for (int i = k; i < fColorCount; i++) {
            positions[i] = i / (fColorCount - 1.0f);
        }

        fPaint.setShader(SkGradientShader::MakeLinear(points,
                                                      colors.get(),
                                                      positions.get(),
                                                      fColorCount,
                                                      SkShader::kClamp_TileMode,
                                                      0,
                                                      nullptr));
    }
コード例 #24
0
void QImageTextureGlyphCache::createTextureData(int width, int height)
{
    switch (m_type) {
    case QFontEngineGlyphCache::Raster_Mono:
        m_image = QImage(width, height, QImage::Format_Mono);
        break;
    case QFontEngineGlyphCache::Raster_A8: {
        m_image = QImage(width, height, QImage::Format_Indexed8);
        m_image.fill(0);
        QVector<QRgb> colors(256);
        QRgb *it = colors.data();
        for (int i=0; i<256; ++i, ++it)
            *it = 0xff000000 | i | (i<<8) | (i<<16);
        m_image.setColorTable(colors);
        break;   }
    case QFontEngineGlyphCache::Raster_RGBMask:
        m_image = QImage(width, height, QImage::Format_RGB32);
        break;
    }
}
コード例 #25
0
BOOL CExtendedCPU6Intel::OnInitDialog()
   {
    CLeaves::OnInitDialog();

    ColorSet colors(TRUE);

    POSITION p;
    p = colors.GetFirstColorPosition();
    SETCOLOR(LineSize);                 // 7..0
    SETRESERVEDCOLOR(Reserved1);        // 11..8
    SETCOLOR(Associativity);            // 15..12
    SETCOLOR(CacheSize);                // 31..16

    SetFixedFont(c_EAX);
    SetFixedFont(c_EBX);
    SetFixedFont(c_EDX);

    return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
   }
コード例 #26
0
ファイル: katewordcompletion.cpp プロジェクト: UIKit0/kate
KateWordCompletionView::KateWordCompletionView( KTextEditor::View *view, KActionCollection* ac )
  : QObject( view ),
    m_view( view ),
    m_dWCompletionModel( KateGlobal::self()->wordCompletionModel() ),
    d( new KateWordCompletionViewPrivate )
{
  d->isCompleting = false;
  d->dcRange = KTextEditor::Range::invalid();

  d->liRange = static_cast<KateDocument*>(m_view->document())->newMovingRange(KTextEditor::Range::invalid(), KTextEditor::MovingRange::DoNotExpand);

  KColorScheme colors(QPalette::Active);
  KTextEditor::Attribute::Ptr a = KTextEditor::Attribute::Ptr( new KTextEditor::Attribute() );
  a->setBackground( colors.background(KColorScheme::ActiveBackground) );
  a->setForeground( colors.foreground(KColorScheme::ActiveText) ); // ### this does 0
  d->liRange->setAttribute( a );

  KTextEditor::CodeCompletionInterface *cci = qobject_cast<KTextEditor::CodeCompletionInterface *>(view);

  KAction *action;

  if (cci)
  {
    cci->registerCompletionModel( m_dWCompletionModel );

    action = new KAction( i18n("Shell Completion"), this );
    ac->addAction( "doccomplete_sh", action );
    connect( action, SIGNAL(triggered()), this, SLOT(shellComplete()) );
  }


  action = new KAction( i18n("Reuse Word Above"), this );
  ac->addAction( "doccomplete_bw", action );
  action->setShortcut( Qt::CTRL+Qt::Key_8 );
  connect( action, SIGNAL(triggered()), this, SLOT(completeBackwards()) );

  action = new KAction( i18n("Reuse Word Below"), this );
  ac->addAction( "doccomplete_fw", action );
  action->setShortcut( Qt::CTRL+Qt::Key_9 );
  connect( action, SIGNAL(triggered()), this, SLOT(completeForwards()) );
}
コード例 #27
0
        RotateGizmo::RotateGizmo(Engine::Component* c, const Core::Transform &worldTo, const Core::Transform& t, Mode mode)
                : Gizmo(c, worldTo, t, mode), m_initialPix(Core::Vector2::Zero()), m_selectedAxis(-1)
        {
            constexpr Scalar torusOutRadius = 0.1f;
            constexpr Scalar torusAspectRatio = 0.1f;
            // For x,y,z
            for (uint i = 0; i < 3; ++i)
            {
                Core::TriangleMesh torus = Core::MeshUtils::makeParametricTorus<32>(torusOutRadius, torusAspectRatio*torusOutRadius);
                // Transform the torus from z-axis to axis i.
                if (i < 2)
                {
                    for (auto& v: torus.m_vertices)
                    {
                        std::swap( v[2], v[i]);
                    }
                }

                Core::Color torusColor= Core::Color::Zero();
                torusColor[i] = 1.f;
                Core::Vector4Array colors(torus.m_vertices.size(), torusColor);

                std::shared_ptr<Engine::Mesh> mesh( new Engine::Mesh("Gizmo Arrow") );
                mesh->loadGeometry(torus);
                mesh->addData(Engine::Mesh::VERTEX_COLOR, colors);

                Engine::RenderObject* arrowDrawable = new Engine::RenderObject("Gizmo Arrow", m_comp,
                                                                               Engine::RenderObjectType::UI);

                Engine::RenderTechnique* rt = new Engine::RenderTechnique;
                rt->shaderConfig = Ra::Engine::ShaderConfigurationFactory::getConfiguration("Plain");
                rt->material = new Ra::Engine::Material("Default material");
                arrowDrawable->setRenderTechnique(rt);
                arrowDrawable->setMesh( mesh );

                updateTransform(m_worldTo, m_transform);

                m_renderObjects.push_back(m_comp->addRenderObject(arrowDrawable));

            }
        }
コード例 #28
0
ファイル: PlaneSet.cpp プロジェクト: jefferis/rgl
PlaneSet::PlaneSet(Material& in_material, int in_nnormal, double* in_normal, int in_noffset, double* in_offset)
 : 
   TriangleSet(in_material,true, false/* true */),
   nPlanes(max(in_nnormal, in_noffset)),
   normal(in_nnormal, in_normal), 
   offset(in_noffset, in_offset)
{
  /* We'll set up 4 triangles per plane, in case we need to render
     a hexagon.  Each triangle has 3 vertices (so 12 for the plane), and each vertex
     gets 3 color components and 1 alpha component. */
  ARRAY<int> colors(36*nPlanes);
  ARRAY<double> alphas(12*nPlanes);

  if (material.colors.getLength() > 1) {
    material.colors.recycle(nPlanes); 
  
    for (int i=0; i<nPlanes; i++) {
      Color color=material.colors.getColor(i);
      for (int j=0; j<12; j++) {
        colors.ptr[36*i+3*j+0] = color.getRedub();
        colors.ptr[36*i+3*j+1] = color.getGreenub();
        colors.ptr[36*i+3*j+2] = color.getBlueub();
        alphas.ptr[12*i+j]     = color.getAlphaf();
      }
    }
    material.colors.set(12*nPlanes, colors.ptr, 12*nPlanes, alphas.ptr);
    material.colorPerVertex(true, 12*nPlanes);
  }
  
  ARRAY<double> vertices(36*nPlanes),
                normals(36*nPlanes);
  for (int i=0; i<vertices.size(); i++)
    vertices.ptr[i] = NA_REAL;
  for (int i=0; i<nPlanes; i++)
    for (int j=0; j<12; j++) {
      normals.ptr[36*i+3*j+0] = normal.getRecycled(i).x;
      normals.ptr[36*i+3*j+1] = normal.getRecycled(i).y;
      normals.ptr[36*i+3*j+2] = normal.getRecycled(i).z;
    }  
  initFaceSet(12*nPlanes, vertices.ptr, normals.ptr, NULL);
}
コード例 #29
0
	static void on_trackbar(int, void*)
	{
	    Mat bw = threshval < 128 ? (img < threshval) : (img > threshval);
	    Mat labelImage(img.size(), CV_32S);
	    int nLabels = connectedComponents(bw, labelImage, 8);
	    std::vector<Vec3b> colors(nLabels);
	    colors[0] = Vec3b(0, 0, 0);//background
	    for(int label = 1; label < nLabels; ++label){
	        colors[label] = Vec3b( (rand()&255), (rand()&255), (rand()&255) );
	    }
	    Mat dst(img.size(), CV_8UC3);
	    for(int r = 0; r < dst.rows; ++r){
	        for(int c = 0; c < dst.cols; ++c){
	            int label = labelImage.at<int>(r, c);
	            Vec3b &pixel = dst.at<Vec3b>(r, c);
	            pixel = colors[label];
	         }
	     }
	
	    imshow( "Connected Components", dst );
	}
コード例 #30
0
RenderablePtr DebugBuildRay( const Ray& pickRay, float length )
{
	std::vector<Vector3> vertex;
	vertex.push_back( pickRay.origin );
	vertex.push_back( pickRay.getPoint(length) );

	std::vector<Vector3> colors( 2, Color::Red );

	GeometryBuffer* gb = AllocateHeap(GeometryBuffer);
	gb->set( VertexAttribute::Position, vertex );
	gb->set( VertexAttribute::Color, colors );

	MaterialHandle material = MaterialCreate(AllocatorGetHeap(), "RayDebug");

	Renderable* renderable = AllocateHeap(Renderable);
	renderable->setPrimitiveType(PrimitiveType::Lines);
	renderable->setGeometryBuffer(gb);
	renderable->setMaterial(material);
	
	return renderable;
}