void lable_curve_Occurrence(){
    
    
    float numbs[SIZE];
    int idx;
    int n=77;
    int count=0;
    
    std::cout << "( "<< "Z values" << ", "<< " Occurrence " << " )"<< std::endl;

    for(idx = 0; idx<n; idx++)
        numbs[idx] = ver[idx][5];
    
	for (int i = 0; i < n; i++)
	{
		bool matching = false;
		for (int j = 0; (j < i) && (matching == false); j++) {
            
            if (numbs[i] == numbs[j]) {
                
                matching = true;
            }
            
        }
		if (!matching){
            for(idx = 0; idx<n; idx++) {
                
                if (numbs[idx]==numbs[i]) {
                    count++;
                }
                
            }
            
            
            //Lable Occurrence
                        std::cout << "( "<< numbs[i] << ", "<< count << " )"<< std::endl;
            
            
            
            glPushMatrix();
            glTranslatef(0.5, 0, numbs[i]/4);
            bitmap_output (0,0,0, "0" , GLUT_BITMAP_TIMES_ROMAN_24);
            glPopMatrix();
            
            count = 0 ;
            
            
        }
    }
    
    
    
    
    
}
Exemple #2
0
/*
 =======================================================================================================================
    Display function. Where the magic happens and everything is drawn.
 =======================================================================================================================
 */
void display(void)
{
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	/* adjust for zoom value */
	gluPerspective(50 * zoom, (float) glutGet(GLUT_WINDOW_WIDTH) / (float) glutGet(GLUT_WINDOW_HEIGHT), 0.001, 40.0);
	glMatrixMode(GL_MODELVIEW);

	/* do rotation things */
	alpha = alpha + (float) inc;
	if(alpha > (float) 360.0) alpha -= (float) 360.0;
	beta = beta + (float) inc2;
	if(beta > (float) 360.0) beta -= (float) 360.0;

	/* normalise any normals which aren't in unit form */
	glEnable(GL_NORMALIZE);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	/* draw the fog */
	fog();
	glPushMatrix();

	/* translate whole scene so we can actually see it */
	glTranslatef((float) 0.0, -(float) 0.5, -(float) 5);

	/* rotate by rotation values */
	glRotatef(beta, (float) 1.0, (float) 0.0, (float) 0.0);
	glRotatef(-alpha, (float) 0.0, (float) 1.0, (float) 0.0);

	/* it was a bit big... */
	glScalef(0.50, 0.50, 0.50);

	/* set shade mode */
	glShadeModel(shademode);
	glPushMatrix();

	/* draw the floor */
	glScalef(scale * 5, scale * 5, scale * 5);
	glRotatef(180, 0, 1.0, 1.0);
	drawCheck(20, 20, BLUE, YELLOW);	/* draw ground */
	glPopMatrix();

	/* set up the lights */
	glTranslatef(0.3, 0, 1.25);
	glEnable(GL_LIGHTING);

	/* this is a positioned light */
	glEnable(GL_LIGHT0);

	/* this is a directed light */
	glEnable(GL_LIGHT1);

	/* this is a spotlight (not initiated til later) */
	glEnable(GL_LIGHT2);

	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
	/* set the ambient light */
	GLfloat ambientColor[] = { 0.2, 0.2, 0.2, 1.0 };
	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor);

	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
	GLfloat lightColor0[] = { 0.5, 0.5, 0.5, 1.0 };
	GLfloat lightPos0[] = { 0.0f, 1.5f, -1.0f, 0.0f };
	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor0);
	glLightfv(GL_LIGHT0, GL_POSITION, lightPos0);

	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
	GLfloat lightColor1[] = { 0.8f, 0.8f, 0.8f, 1.0f };
	GLfloat lightPos1[] = { 1.0f, 2.0f, -2.0f, 0.0f };
	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	glLightfv(GL_LIGHT1, GL_DIFFUSE, lightColor1);
	glLightfv(GL_LIGHT1, GL_POSITION, lightPos1);

	/* draw the table */
	glPushMatrix();
	glTranslatef(-0.3, 0, -1.25);
	glRotatef(180, 0, 1.0, 1.0);

	/*~~~~~~~~~~~~~~~~~~~~~~~*/
	float	cylbase = 0.60;
	float	cyltop = 0.15;
	float	cylheight = 1.0;
	float	tableheight = 0.10;
	float	tablecirc = 0.90;
	/*~~~~~~~~~~~~~~~~~~~~~~~*/

	setMaterial(finTable);
	setColor(TABLE2);
	gluCylinder(quadratic, cylbase, cyltop, cylheight, splines * LOD, splines * LOD);
	glTranslatef(0, 0, cylheight);
	gluDisk(quadratic, 0.0, cyltop, splines * LOD, splines * LOD);
	gluCylinder(quadratic, tablecirc, tablecirc, tableheight, splines * LOD, splines * LOD);
	gluDisk(quadratic, 0.0, tablecirc, splines * LOD, splines * LOD);
	glTranslatef(0, 0, tableheight);
	gluDisk(quadratic, 0.0, tablecirc, splines * LOD, splines * LOD);
	setMaterial(finDefault);
	glPopMatrix();
	glPushMatrix();

	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
	/* initiate the spotlight */
	GLfloat light_ambient2[] = { 0.0, 0.0, 0.0, 1.0 };
	GLfloat light_diffuse2[] = { 0.0, 0.3, 0, 1.0 };
	GLfloat light_specular2[] = { 0.0, 0.3, 0, 1.0 };
	GLfloat lightPos2[] = { 0.0f, 3.0f, 0.0f, 0.0f };
	GLfloat spot_direction[] = { 0, -1.0, 0 };
	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	glLightfv(GL_LIGHT2, GL_AMBIENT, light_ambient2);
	glLightfv(GL_LIGHT2, GL_DIFFUSE, light_diffuse2);
	glLightfv(GL_LIGHT2, GL_SPECULAR, light_specular2);
	glLightf(GL_LIGHT2, GL_SPOT_CUTOFF, 30.0);
	glLightfv(GL_LIGHT2, GL_POSITION, lightPos2);
	glLightfv(GL_LIGHT2, GL_SPOT_DIRECTION, spot_direction);

	/* draw the chairs and rotate them around the table */
	glRotatef(270, 0.0, 1.0, 0.0);
	glTranslatef(-1.5, 0, 1.5);
	glPushMatrix();
	glRotatef(90, 0, 1.0, 0.0);
	chair();
	glPopMatrix();
	glPushMatrix();
	glTranslatef(0.3, 0, -1.25);
	glRotatef(90, 0, 1.0, 0.0);
	glTranslatef(-0.3, 0, 1.25);
	glRotatef(90, 0, 1.0, 0.0);
	chair();
	glPopMatrix();
	glPushMatrix();
	glTranslatef(0.3, 0, -1.25);
	glRotatef(180, 0, 1.0, 0.0);
	glTranslatef(-0.3, 0, 1.25);
	glRotatef(90, 0, 1.0, 0.0);
	chair();
	glPopMatrix();
	glPushMatrix();
	glTranslatef(0.3, 0, -1.25);
	glRotatef(270, 0, 1.0, 0.0);
	glTranslatef(-0.3, 0, 1.25);
	glRotatef(90, 0, 1.0, 0.0);
	chair();
	glPopMatrix();

	/* draw the cups/forks and rotate around the table */
	glPushMatrix();
	glTranslatef(0.35, 1.1, -0.25);
	cups();
	glPushMatrix();
	glTranslatef(-0.05, 0, -1.0);
	glRotatef(90, 0, 1.0, 0);
	glTranslatef(0.05, 0, 1.0);
	cups();
	glPopMatrix();
	glPushMatrix();
	glTranslatef(-0.05, 0, -1.0);
	glRotatef(180, 0, 1.0, 0);
	glTranslatef(0.05, 0, 1.0);
	cups();
	glPopMatrix();
	glPushMatrix();
	glTranslatef(-0.05, 0, -1.0);
	glRotatef(270, 0, 1.0, 0);
	glTranslatef(0.05, 0, 1.0);
	cups();
	glPopMatrix();
	glPopMatrix();

	/* draw the teapot */
	glPushMatrix();

	/* put on table */
	glTranslatef(0.3, 1.3, -1.25);

	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
	/* trans values for animation */
	static int		rotateval = 1;
	static int		rotatevalx = 0;
	static float	transvaly = 0;
	static float	transvalx = 0;
	/* clock values for animation */
	static int		beginslow = 0;
	static int		slowclock = 0;
	static int		pourclock = 0;
	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	/* only animate when playing */
	if(ani_play)
	{
		{
			/*~~~*/
			int ii;
			/*~~~*/

			for(ii = 0; ii < speed; ii++)
			{
				{

					/* section where teapot slows */
					if((beginslow))
					{
						{
							if(((20 - slowclock / 10) > 0))
							{
								rotateval = rotateval + (20 - slowclock / 10);
								slowclock++;
							}
							else
							{
								{

									/* section where teapot is pouring */
									if(pourclock < 90)
									{
										{
											rotatevalx = pourclock / 2;
											transvaly = ((double) pourclock) / (double) 200;
											transvalx = ((double) pourclock) / (double) 400;
										}
									}
									else if(pourclock < 135)
									{	/* teapot in mid air */
										rotatevalx = 45;
										transvaly = 90.0 / 200;
										transvalx = 90.0 / 400;
									}
									else if(pourclock < 225)
									{
										{	/* teapot is being set down */
											rotatevalx = 45 - (pourclock - 135) / 2;
											transvaly = 90.0 / 200 - ((double) pourclock - 135) / (double) 200;
											transvalx = 90.0 / 400 - ((double) pourclock - 135) / (double) 400;
										}
									}
									else if(pourclock < 300)
									{		/* teapot is back on table */
										rotatevalx = 0;
										transvaly = 0;
										transvalx = 0;
									}
									else
									{
										{	/* reset variables for next play */
											ani_play = 0;
											ani_clock = 0;
											rotateval = 1;
											ani_direction = 0;
											slowclock = 0;
											pourclock = -speed;
											beginslow = 0;
											rotatevalx = 0;
											transvaly = 0;
											transvalx = 0;
										}
									}

									pourclock++;
								}
							}
						}
					}
					else if(ani_clock < 200)
					{			/* teapot is speeding up it's spin */
						rotateval = rotateval + ani_clock / 10;
					}
					else if(ani_clock < 500)
					{
						{		/* teapot is at constant spin */
							rotateval = rotateval + 20;
							if(ani_clock == 300)
							{	/* choose the cup it will stop at */
								ani_direction = rand() % 4 + 1;
							}
						}
					}

					if(rotateval > 360) rotateval -= 360;
					if
					(
						(!beginslow)
					&&	(ani_direction != 0)
					&&	(
							(
								(rotateval >= ani_direction * 90 - SLOWMAGIC - 20)
							&&	(rotateval <= ani_direction * 90 - SLOWMAGIC)
							)
						||	(
									(rotateval >= ani_direction * 90 - SLOWMAGIC + 340)
								&&	(rotateval <= ani_direction * 90 - SLOWMAGIC + 360)
								)
						)
					)
					{			/* choose opportune moment to slow down */
						beginslow = 1;
						rotateval = ani_direction * 90 - SLOWMAGIC + 360;
						if(rotateval > 360) rotateval -= 360;
					}

					ani_clock++;
				}
			}
		}	/* apply transformations */
	}

	glRotatef(rotateval, 0, 1.0, 0);
	glTranslatef(transvalx, transvaly, 0);
	glRotatef(-rotatevalx, 0, 0, 1.0);

	/* apply texture */
	glBindTexture(GL_TEXTURE_2D, texture[1]);
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	glEnable(GL_TEXTURE_2D);

	/* apply finish */
	setMaterial(finPot);
	glutSolidTeapot(0.2);
	setMaterial(finDefault);
	glDisable(GL_TEXTURE_2D);
	glPopMatrix();
	glPopMatrix();
	glPopMatrix();

	/* 3D stuff is done */
	glFlush();

	/* draw text overlay */
	glDisable(GL_NORMALIZE);
	glDisable(GL_LIGHTING);
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glOrtho(0, glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT), 0, -1, 1);
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();

	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
	char	speedstring[20];
	char	str[500] = "<Z> and <z>: zoom in/out\n<X> or <x>: Start/Stop X rotation\n<Y> or <y> Start/Stop Y Rotation\n<A> or <a>: Start animation\n<F> or <f>: Speed up animation\n<S> or <s>: Slow down animation\n<T> or <t>: Pause animation\n<C> or <c>: Resume the animation\n<p>: switch the rendering to the flat shaded polygonization.\n<P> switch the rendering to the smooth shaded polygonization.\n<q> or <Q>: change fog mode\nspeed: ";
	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	sprintf(speedstring, "%d", speed);
	strcat(str, speedstring);
	strcat(str, "\nLOD: ");
	sprintf(speedstring, "%d", LOD);
	strcat(str, speedstring);
	strcat(str, "\nFog Mode: ");
	switch(fogfilter)
	{
		{
		case 0: strcat(str, "GL_EXP"); break;
		case 1: strcat(str, "GL_EXP2"); break;
		case 2: strcat(str, "GL_LINEAR"); break;
		case 3: strcat(str, "NO FOG"); break;
		}
	}

	bitmap_output(30, 30, str, GLUT_BITMAP_HELVETICA_12);
	glPopMatrix();
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();

	/* draw transparent box for text */
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glOrtho(0, glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT), 0, -1, 1);
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glColor4f((float) 0, (float) 0, (float) 0, (float) 0.6);
	glRecti(30 - 10, 30 - 20, 40 + 350, 30 + 250);
	glPopMatrix();
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glFlush();
	glutSwapBuffers();
}