示例#1
0
文件: searchTree.c 项目: Logan54/labs
int searchTree(struct edge ** edges, int M, int N, FILE * out) {
	int * set;
	int i, tmp;
	struct stack * st = NULL;
	
	set = malloc(sizeof(int) * N);
	if (NULL == set) {
		fprintf(stderr, ERROR_MEM);
		exit(0); //solution only for student
	}
	for (i = 0; i < N; ++i) {
		set[i] = i;
	}
	qsort(*edges, M, sizeof(struct edge), compare);
	for (i = 0; i < M; ++i) {
		if (master(set, (*edges)[i].from - 1) != master(set, (*edges)[i].to - 1)) {
			colored(set, N, set[(*edges)[i].from - 1], master(set, (*edges)[i].to - 1));
			push(&st, (*edges)[i].from, (*edges)[i].to);
		}
	}
	tmp = set[0];
	for (i = 0; i < N; ++i) {
		master(set, i);
		if (tmp != set[i]) {
			return(-1);
		}
	}
	for (i = 0; i < M && pop(&st, out); ++i) ;
	free(set);
	
	return(0);
}
示例#2
0
void PointCloudVBO::genColorBuffer()
// ----------------------------------------------------------------------------
//   Allocate new VBO for colors
// ----------------------------------------------------------------------------
{
    XL_ASSERT(colored());
    GL.GenBuffers(1, &colorVbo);
    IFTRACE(pointcloud)
        debug() << "Allocated VBO #" << colorVbo << " for colors\n";
}
示例#3
0
r_language_rep::r_language_rep (string name):
  language_rep (name), colored ("")
{ 
  eval ("(use-modules (utils misc tm-keywords))");
  list<string> l= as_list_string (eval ("(map symbol->string highlight-any)"));
  while (!is_nil (l)) {
    colored (l->item)= "blue";
    l= l->next;
  }
}
示例#4
0
string
scheme_language_rep::get_color (tree t, int start, int end) {
  static string none= "";
  if (start >= end) return none;
  string s= t->label;
  for (int i= max (0, start-1000); i <= start; i++)
    switch (s[i]) {
    case ';':
      if (i>1 && s[i-1] == '\\' && s[i-2] == '#')
        break;
      return decode_color ("scheme", encode_color ("comment"));
    case '\042':
      if (i>1 && s[i-1] == '\\' && s[i-2] == '#')
        break;
      i++;
      while (i <= start && s[i] != '\042')
	if (s[i] == '\\' && i < start) i += 2;
	else i++;
      if (i >= start)
        return decode_color ("scheme", encode_color ("constant_string"));
      break;
    }
  if (is_numeric (s[start]))
    return decode_color ("scheme", encode_color ("constant_number"));
  if (s[start] == '\042' || s[start] == '#')
    return decode_color ("scheme", encode_color ("constant_string"));
  if (s[start] == ':')
    return decode_color ("scheme", encode_color ("declare_category"));
  string r= s (start, end);
  if (!colored->contains (r)) {
    colored (r)= "";
    if (as_bool (call ("defined?", symbol_object (tm_decode (r)))))
      colored (r)= decode_color ("scheme",
				 encode_color ("variable_identifier"));
  }
  return colored[r];
}
示例#5
0
void PointCloudVBO::checkGLContext()
// ----------------------------------------------------------------------------
//   Do what's needed if GL context has changed
// ----------------------------------------------------------------------------
{
    if (QGLContext::currentContext() != context)
    {
        IFTRACE(pointcloud)
            debug() << "GL context changed\n";

        // Re-create VBO(s)
        genPointBuffer();
        if (colored())
            genColorBuffer();

        if (optimized)
        {
            IFTRACE(pointcloud)
                debug() << "GL context changed on optimized cloud\n";

            XL_ASSERT(file != "" || nbRandom != 0);

            if (file != "")
            {
                IFTRACE(pointcloud)
                    debug() << "Reloading file\n";
                text f = file;
                clear();
                loadData(f, sep, xi, yi, zi, colorScale, ri, gi, bi, ai);
            }
            else if (nbRandom != 0)
            {
                IFTRACE(pointcloud)
                    debug() << "Re-creating random points\n";
                unsigned n = nbRandom;
                clear();
                randomPoints(n, coloredRandom);
            }

            optimized = false;
            XL_ASSERT(!dirty);
        }
        else
            updateVbo();

        context = QGLContext::currentContext();
    }
}
 pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr TSDFVolumeOctree::renderColoredView (const Eigen::Affine3d& trans, int downsampleBy) const {
     pcl::PointCloud<pcl::PointNormal>::Ptr grayscale = renderView (trans, downsampleBy);
     pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr colored (new pcl::PointCloud<pcl::PointXYZRGBNormal> (grayscale->width, grayscale->height));
     colored->is_dense = false;
 #pragma omp parallel for
     for (size_t i = 0; i < colored->size(); ++i) {
         pcl::PointXYZRGBNormal& pt = colored->at(i);
         pt.getVector3fMap() = grayscale->at(i).getVector3fMap();
         pt.getNormalVector3fMap() = grayscale->at(i).getNormalVector3fMap();
         if (pcl_isnan (pt.z))
             continue;
         Eigen::Vector3f v_t = trans.cast<float> () * pt.getVector3fMap();
         const OctreeNode* voxel = octree_->getContainingVoxel (v_t (0), v_t (1), v_t (2));
         if (!voxel)
             continue;
         voxel->getRGB (pt.r, pt.g, pt.b);
     }
     return (colored);
 }
示例#7
0
void PointCloudVBO::updateVbo()
// ----------------------------------------------------------------------------
//   Take into account a change in point data
// ----------------------------------------------------------------------------
{
    XL_ASSERT(!optimized);

    if (QThread::currentThread() != qApp->thread())
    {
        // OpenGL functions may be called only from the main thread, which
        // owns the GL context
        IFTRACE(pointcloud)
            debug() << "Not updating VBO (not main thread)\n";
        return;
    }

    IFTRACE(pointcloud)
        debug() << "Updating VBO #" << vbo << " (" << size() << " points)\n";

    GL.BindBuffer(GL_ARRAY_BUFFER, vbo);
    GL.BufferData(GL_ARRAY_BUFFER, size()*sizeof(Point), &points[0].x,
                 GL_STATIC_DRAW);
    GL.BindBuffer(GL_ARRAY_BUFFER, 0);

    if (colored())
    {
        if (colorVbo == 0)
            genColorBuffer();

        IFTRACE(pointcloud)
            debug() << "Updating VBO #" << colorVbo << " (" << size()
                    << " colors)\n";

        GL.BindBuffer(GL_ARRAY_BUFFER, colorVbo);
        GL.BufferData(GL_ARRAY_BUFFER, size()*sizeof(Color), &colors[0].r,
                     GL_STATIC_DRAW);
        GL.BindBuffer(GL_ARRAY_BUFFER, 0);
    }
    dirty = false;
}
示例#8
0
char* _colored_sprintf(char *buf, uint32_t max_size, int fg_color, const char *format, va_list args) {
	int n = vsnprintf(buf, max_size, format, args);
	if (n >= max_size) {
		char tmp_pbuf[100];
		colored(RED, sizeof(tmp_pbuf), tmp_pbuf, "WARNING! length of string is greater than the buffer length!!\n");
		fprintf(stderr, "%s", tmp_pbuf);
	}

	// Add color
	if (n < max_size &&  fg_color != NO_COLOR && !disable_colors) {
		size_t tmp_size = strlen(buf) + 30;
		char *tmp = (char*) malloc(tmp_size);
		if (tmp == NULL) {
			fprintf(stderr, "Failed to allocate memory (colored_sprintf)!\n");
			return 0;
		}
		strcpy(tmp, buf);
		n = _colored(fg_color, tmp_size, tmp, buf);
		strcpy(buf, tmp);
		free(tmp);
	}
	return buf;
}
示例#9
0
void bild()
{
char datum[9], zeit[9], s[80];
  MFORE=WHITE; MBACK=BLUE;
  _clearscreen(0);
  for(i=0;i<80;i++) printf("-");
  colored(); _settextposition(2,1);
  for(i=0;i<14;i++)
  {
    sprintf(s,"%c",0xf9);
    _outtext(s);
  }
  sprintf(s,"STOMA%cVersion%c%1.1f%c-%cCopyright%c(C)%c1993,94%cRalf%cBensmann\
",0xf9,0xf9,stoma_ver,0xf9,0xf9,0xf9,0xf9,0xf9,0xf9);
  _outtext(s);
  for(i=0;i<11;i++) { sprintf(s,"%c",0xf9); _outtext(s); }
  uncolored();
  for(i=0;i<80;i++) printf("-");
  _strdate(datum); _strtime(zeit);
  _settextposition(6,1); printf("Datum: %s",datum);
  _settextposition(6,67); printf("Zeit: %s",zeit);
  _settextposition(7,1); printf("MS-DOS: %s",dosversion());
  MFORE=WHITE; MBACK=RED;
}
示例#10
0
void PointCloudVBO::draw()
// ----------------------------------------------------------------------------
//   Draw cloud
// ----------------------------------------------------------------------------
{
    if (!useVbo())
        return PointCloud::draw();

    PointCloudFactory * fact = PointCloudFactory::instance();

    checkGLContext();

    if (size() == 0)
        return;

    if (dirty)
        updateVbo();

    if (colored())
    {
        GL.EnableClientState(GL_COLOR_ARRAY);
        GL.BindBuffer(GL_ARRAY_BUFFER, colorVbo);
        GL.ColorPointer(4, GL_FLOAT, sizeof(Color), 0);
    }
    else
    {
        // Activate current document color
        fact->tao->SetFillColor();
    }

    if (pointSize > 0)
    {
        glPushAttrib(GL_POINT_BIT);
        GL.PointSize(pointSize * fact->tao->DevicePixelRatio());
    }
    if (pointSprites)
    {
        GL.Enable(GL_POINT_SPRITE);
        GL.TexEnv(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
        GL.PointParameter(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT);
        fact->tao->SetTextures();
    }
    if (pointProgrammableSize)
        GL.Enable(GL_VERTEX_PROGRAM_POINT_SIZE);

    GL.EnableClientState(GL_VERTEX_ARRAY);
    GL.BindBuffer(GL_ARRAY_BUFFER, vbo);
    GL.VertexPointer(3, GL_FLOAT, sizeof(Point), 0);
    GL.DrawArrays(GL_POINTS, 0, size());
    GL.BindBuffer(GL_ARRAY_BUFFER, 0);
    GL.DisableClientState(GL_VERTEX_ARRAY);
    if (colored())
        GL.DisableClientState(GL_COLOR_ARRAY);

    if (pointProgrammableSize)
        GL.Disable(GL_VERTEX_PROGRAM_POINT_SIZE);
    if (pointSprites)
    {
        GL.Disable(GL_POINT_SPRITE);
        GL.TexEnv(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_FALSE);
        GL.PointParameter(GL_POINT_SPRITE_COORD_ORIGIN, GL_UPPER_LEFT);
    }
    if (pointSize > 0)
        glPopAttrib();

}