Exemple #1
0
void test_conversion_functions(void) {
    chunk_size memsiz = 1 Mb;
    Priv_mem new_mem = malloc(sizeof(priv_mem));
    new_mem->as = malloc(sizeof(addressspace));
    new_mem->as->start = malloc(memsiz);
    new_mem->as->end = new_mem->as->start + memsiz;
    new_mem->lists = create_lists(new_mem->as->start, memsiz, ASCENDING_SIZE);
    new_mem->functions.manual.alloc        = &manual_alloc;
    new_mem->functions.manual.avail        = &avail;
    new_mem->functions.manual.free         = &priv_free;

    Manual new_manual = (Manual) priv_to_style((Priv_mem) new_mem);

    CU_ASSERT(new_manual->alloc == &manual_alloc);
    CU_ASSERT(new_manual->avail == &avail);
    CU_ASSERT(new_manual->free  == &priv_free);

    Priv_mem compare_priv = (Priv_mem) style_to_priv((Memory) new_manual);

    CU_ASSERT(new_mem->as->start == compare_priv->as->start);
    CU_ASSERT(new_mem->as->end   == compare_priv->as->end);
    CU_ASSERT(new_mem->lists == compare_priv->lists);
    CU_ASSERT(new_mem->functions.manual.alloc == compare_priv->functions.manual.alloc);
    CU_ASSERT(new_mem->functions.manual.avail == compare_priv->functions.manual.avail);
    CU_ASSERT(new_mem->functions.manual.free  == compare_priv->functions.manual.free);

    free_lists(new_mem->lists);
    free(new_mem->as->start);
    free(new_mem);
}
void CL_EarClipTriangulator_Impl::end_hole()
{
	create_lists(false);

	target_array = &vertices;

	// To be able to triangulate holes the inner and outer vertice arrays are connected
	// so that there isn't actually any hole, just a single polygon with a small gap
	// eliminating the hole.
	//
	// 1. find point on inner contour closest to a vertice on the outer contour.
	//
	// 2. Create bridge start and end points by offsetting the new vertices a bit along the edges to the next and prev vertices.
	// 

	LinkedVertice *outer_vertice = 0;
	LinkedVertice *segment_start;
	LinkedVertice *segment_end;
	CL_Pointf inner_point;
	float inner_point_rel;
	float distance = FLT_MAX;

	for (unsigned int vertex_cnt = 0; vertex_cnt < vertices.size(); vertex_cnt++)
	{
		CL_Pointf tmp_outer_point = CL_Pointf(vertices[vertex_cnt]->x,vertices[vertex_cnt]->y);

		for (unsigned int hole_cnt = 0; hole_cnt < hole.size(); hole_cnt++)
		{

			CL_Pointf tmp_line_start(hole[hole_cnt]->x, hole[hole_cnt]->y);
			CL_Pointf tmp_line_end(hole[hole_cnt]->next->x, hole[hole_cnt]->next->y);
			
			CL_Pointf tmp_inner_point = CL_LineMath::closest_point(tmp_outer_point, tmp_line_start, tmp_line_end);
			
			float tmp_distance = tmp_inner_point.distance(tmp_outer_point);
			
			if( tmp_distance < distance  )
			{
				inner_point_rel = CL_LineMath::closest_point_relative(tmp_outer_point, tmp_line_start, tmp_line_end);
				distance = tmp_distance;
				outer_vertice = vertices[vertex_cnt];
				inner_point = tmp_inner_point;
				segment_start = hole[hole_cnt];
				segment_end = hole[hole_cnt]->next;
			}
		}
	}

	LinkedVertice *outer_bridge_start = new LinkedVertice();
	LinkedVertice *outer_bridge_end = new LinkedVertice();
	LinkedVertice *inner_bridge_start = new LinkedVertice();
	LinkedVertice *inner_bridge_end = new LinkedVertice();

	//  offset new points along old edges
	CL_Pointf outer_point(outer_vertice->x, outer_vertice->y);

	set_bridge_vertice_offset( outer_bridge_start, outer_point, 0.0,             outer_vertice, outer_vertice->previous, 1 );
	set_bridge_vertice_offset( outer_bridge_end,   outer_point, 0.0,             outer_vertice, outer_vertice->next, 1 );
	set_bridge_vertice_offset( inner_bridge_start, inner_point, inner_point_rel, segment_start, segment_end, 1 );
	set_bridge_vertice_offset( inner_bridge_end,   inner_point, inner_point_rel, segment_start, segment_end, -1 );

	// update next pointers to ignore old vertices

	// connections between inner and outer contours
	outer_bridge_start->next = inner_bridge_start;
	inner_bridge_end->next = outer_bridge_end;

	// connections between new and old vertices: outer contour
	outer_bridge_end->next = outer_vertice->next;
	outer_vertice->previous->next = outer_bridge_start;

	// connections between new and old vertices: inner contour
	inner_bridge_start->next = segment_end;
	segment_start->next = inner_bridge_end;

	delete outer_vertice;
	outer_vertice = 0;

	if( inner_point_rel == 0.0 ) // if split point is at line end, remove inner vertex
	{
		segment_start->previous->next = inner_bridge_end;
		delete segment_start;
		segment_start = 0;
	}
	if( inner_point_rel == 1.0 ) // if split point is at line end, remove inner vertex
	{
		inner_bridge_start->next = segment_end->next;
		delete segment_end;
		segment_end = 0;
	}

	hole.clear();

	// rebuild the vector...
	vertices.clear();

	LinkedVertice *test = inner_bridge_start;
	do
	{
		vertices.push_back(test);
		test = test->next;
	} while( test != inner_bridge_start );

	// print the bridge start and end points:
/*	cl_write_console_line("outer_point: %1 %2", outer_point.x, outer_point.y );
	cl_write_console_line("inner_point: %1 %2", inner_point.x, inner_point.y );
	cl_write_console_line("inner_bridge_end: %1 %2", inner_bridge_end->x, inner_bridge_end->y );
	cl_write_console_line("outer_bridge_end: %1 %2", outer_bridge_end->x, outer_bridge_end->y );
	cl_write_console_line("inner_bridge_start: %1 %2", inner_bridge_start->x, inner_bridge_start->y );
	cl_write_console_line("outer_bridge_start: %1 %2", outer_bridge_start->x, outer_bridge_start->y );
*/
}
Exemple #3
0
int main() {
    Display *dpy;
    int fbattrib[] = {
        GLX_DOUBLEBUFFER, True,
        GLX_RED_SIZE, 8,
        GLX_GREEN_SIZE, 8,
        GLX_BLUE_SIZE, 8,
        GLX_ALPHA_SIZE, 8,
        GLX_SAMPLE_BUFFERS, 1,
        GLX_SAMPLES, 1,
        None
    };

    int eventbase, errorbase;
    int screen;
    Window root, win;
    XVisualInfo *visinfo;
    XSetWindowAttributes attr;
    GLXContext ctx;
    GLXFBConfig *fbconfig;
    int i, numfbconfig, maxsample = 0;
    int bestfbi = 0, value;

    dpy = XOpenDisplay(NULL);

    if(NULL == dpy) {
        fprintf(stderr, "error: unable to open display!\n");
        return EXIT_FAILURE;
    }

    if(!glXQueryExtension(dpy, &eventbase, &errorbase)) {
        fprintf(stderr, "GLX is not available!\n");
        return EXIT_FAILURE;
    }

    screen = DefaultScreen(dpy);
    root = RootWindow(dpy, screen);

    fbconfig = glXChooseFBConfig(dpy, screen, fbattrib, &numfbconfig);

    if(NULL == fbconfig) {
        fprintf(stderr, "error: choosing GLXFBConfig!\n");
        return EXIT_FAILURE;
    }

    for(i = 0; i < numfbconfig; ++i) {
        glXGetFBConfigAttrib(dpy, fbconfig[i], GLX_SAMPLES, &value);

        if(value > maxsample) {
            bestfbi = i;
            maxsample = value;
        }
    }

    glXGetFBConfigAttrib(dpy, fbconfig[bestfbi], GLX_SAMPLES, &value);
    printf("peak GLX_SAMPLES %d\n", value);

    visinfo = glXGetVisualFromFBConfig(dpy, fbconfig[bestfbi]);

    if (!visinfo) {
        fprintf(stderr, "error: couldn't get an RGBA, double-buffered visual!\n");
        return EXIT_FAILURE;
    }

    printf("visinfo->visualid %lx\n", visinfo->visualid);

    glXGetFBConfigAttrib(dpy, fbconfig[bestfbi], GLX_FBCONFIG_ID, &value);

    printf("fbconfig id 0x%x\n", value);


    attr.background_pixel = 0;
    attr.border_pixel = 0;
    attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
    attr.event_mask = StructureNotifyMask | ExposureMask;

    win = XCreateWindow(dpy, root, /*x*/ 0, /*y*/ 0,
                        /*width*/ 400, /*height*/ 400,
                        0, visinfo->depth, InputOutput,
                        visinfo->visual,
                        CWBackPixel | CWBorderPixel | CWColormap | CWEventMask,
                        &attr);

    ctx = glXCreateNewContext(dpy, fbconfig[bestfbi], GLX_WINDOW_BIT,
                              NULL, True);

    if (!ctx) {
        fprintf(stderr, "error: glXCreateNewContext failed!\n");
        return EXIT_FAILURE;
    }

    XMapWindow(dpy, win);

    if(!glXMakeCurrent(dpy, win, ctx)) {
        fprintf(stderr, "error: making context current!\n");
        return EXIT_FAILURE;
    }

    printf("GL_RENDERER %s\n", (char *) glGetString(GL_RENDERER));

    glEnable(GL_MULTISAMPLE);

    create_lists();

    {
        GLint alpha, red, green;
        GLboolean dbuf;

        glGetIntegerv(GL_RED_BITS, &red);
        printf("glGetIntegerv(GL_RED_BITS) %d\n", red);

        glGetIntegerv(GL_GREEN_BITS, &green);
        printf("glGetIntegerv(GL_GREEN_BITS) %d\n", green);

        glGetIntegerv(GL_ALPHA_BITS, &alpha);
        printf("glGetIntegerv(GL_ALPHA_BITS) %d\n", alpha);

        glGetBooleanv(GL_DOUBLEBUFFER, &dbuf);
        printf("glGetBooleanv(GL_DOUBLEBUFFER) %d\n", dbuf);

        GLint aux;
        glGetIntegerv(GL_AUX_BUFFERS, &aux);
        printf("aux buffers %d\n", aux);

        GLint ared;
        glGetIntegerv(GL_ACCUM_RED_BITS, &ared);
        printf("accum red bits %d\n", ared);
    }

    event_loop(dpy);

    return EXIT_SUCCESS;
}
CL_EarClipResult CL_EarClipTriangulator_Impl::triangulate()
{
	create_lists(true);

	int num_triangles = vertices.size()-2;
	int tri_count = 0;
	
	CL_EarClipResult result(num_triangles);
	
	while( tri_count < num_triangles )
	{
		if( ear_list.empty() ) // something went wrong, but lets not crash anyway. 
			break;

		LinkedVertice *v = ear_list.back();
		ear_list.pop_back();
 
		CL_EarClipTriangulator_Triangle tri;

		tri.x1 = v->x;
		tri.y1 = v->y;

		tri.x2 = v->previous->x;
		tri.y2 = v->previous->y;

		tri.x3 = v->next->x;
		tri.y3 = v->next->y;

		result.get_triangles().push_back(tri);

		v->next->previous = v->previous;
		v->previous->next = v->next;

		if( is_ear(*v->next) )
		{
			if( v->next->is_ear == false ) // not marked as an ear yet. Mark it, and add to the list.
			{
				v->next->is_ear = true;
				ear_list.push_back(v->next);
			}
		}
		else
		{
			if( v->next->is_ear == true ) // Not an ear any more. Delete from ear list.
			{
				v->next->is_ear = false;
				
				std::vector<LinkedVertice*>::iterator it;
				for( it = ear_list.begin(); it != ear_list.end(); ++it )
				{
					if( (*it) == v->next )
					{
						ear_list.erase(it);
						break;
					}
				}
			}
		}

		if( is_ear(*v->previous) )
		{
			if( v->previous->is_ear == false ) // not marked as an ear yet. Mark it, and add to the list.
			{
				v->previous->is_ear = true;
				ear_list.push_back(v->previous);
			}
		}
		else
		{
			if( v->previous->is_ear == true ) // Not an ear any more. Delete from ear list.
			{
				v->previous->is_ear = false;
				
				std::vector<LinkedVertice*>::iterator it;
				for( it = ear_list.begin(); it != ear_list.end(); ++it )
				{
					if( (*it) == v->previous )
					{
						ear_list.erase(it);
						break;
					}
				}
			}
		}

/*		cl_write_console_line("Ear list:");
		for( std::vector<LinkedVertice*>::iterator it = ear_list.begin(); it != ear_list.end(); ++it )
		{
			cl_write_console_line("    (%1,%2)", (*it)->x, (*it)->y );
		}
		cl_write_console_line("");
*/

		tri_count++;

	}

	// cl_write_console_line("num triangles - final: %1", tri_count ); 

	return result;
}
int main(int argc, char **argv)
{
        glutInit(&argc,argv);
	my_setup(canvas_Width,canvas_Height,canvas_Name);

vector <int >new_fan;


  if(argc!=2){
    cout<<"<usuage>:mismatched arguments"<<endl;
    exit(0);
  }

  ifstream mesh_input(argv[1]);

  if(mesh_input.is_open())
    read_input_mesh(mesh_input,v_count,f_count,d_vb,d_ib);
  else{
    cout<<"Cannot open input mesh"<<endl;
    exit(0);
  }

  mesh_input.close();//Finised with reading mesh data


  vector < vector<int> >fan(v_count);
   vector < vector<edge> >e(v_count);
  
  create_lists(e,d_ib,f_count);


  
  //delete[]d_ib;//done with index buffer list
   triangle_fan_create(e,d_vb,fan);


  output=new vertex_buffer[v_count];

size=fan[0].size();

  for(int i=0;i<fan.size();i++){
    for(int j=0;j<size;j++){
        new_fan.push_back(fan[i][j]);
        }
  }

  test=&new_fan[0];

  clock_t start=clock();
  for(int i=0;i<10;i++)	
  zhou_shimada(d_vb,output,test,fan[0].size(),v_count);
  clock_t stop=clock();

  cout<<"Elapsed time="<<(double)((stop-start))/CLOCKS_PER_SEC<<endl;

//  print_output(output,v_count);  
  glutDisplayFunc(display_func);
  glutKeyboardFunc(keyboard);
  glutMainLoop();


return 0;
}