Commit ec5c92d4 authored by Taddeüs Kroes's avatar Taddeüs Kroes

- Finished graphics ass8.

parent f5c7e003
We did the following measurements with out program.
+----------------+-----+-----------------------+---------------------+-------------+
| dataset | iso | framerate unoptimized | framerate optimized | improvement |
| | | (points/cubes) | (points/cubes) | ratio |
+----------------+-----+-----------------------+---------------------+-------------+
| frog.small.vtk | 78 | 80 / 19 | 670 / 235 | 8.4 / 12.4 |
+----------------+-----+-----------------------+---------------------+-------------+
| knee.vtk | 60 | 58 / 2 | 362 / 29 | 6.2 / 14.5 |
+----------------+-----+-----------------------+---------------------+-------------+
| mummy.128.vtk | 50 | 40 / 5 | 515 / 86 | 12.9 / 17.2 |
+----------------+-----+-----------------------+---------------------+-------------+
We can see that the improvement in performance is very large, especially for
the cubes. This makes sense, because when not using arrays, all of the cubes
have to be translated and transformed whereas the points only have to be
calculated. Still, the optimization certainly also pays off for the points.
......@@ -5,14 +5,10 @@
* Date ............ 29.10.2008
* Created by ...... Paul Melis
*
* Student name ....
* Student email ...
* Collegekaart ....
* Date ............
* Comments ........
*
*
* (always fill in these fields before submitting!!)
* Student name .... Sander van Veen & Taddeus Kroes
* Student email ... sandervv@gmail.com & taddeuskroes@hotmail.com
* Collegekaart .... 6167969 & 6054129
* Date ............ 07.11.2010
*/
#include <stdio.h>
......@@ -42,8 +38,6 @@ int entered_number=0;
int display_fps_counter=0;
int backface_culling=0;
int show_normals=0;
#define MAX_VERTICES_IN_ARRAY 5000000
int num_vertices_in_array=0;
......@@ -54,7 +48,8 @@ void SetupCamera(void);
void DrawVolumeAxes(void);
void DrawVolumeUsingCurrentDisplayMode(void);
#define TIMER_FRAMERATE 15
/* Some definitions and global variables for use in the filled-in functions */
#define TIMER_FRAMERATE 30
#define POINT_SIZE 1.0
int timer = TIMER_FRAMERATE + 1;
......@@ -69,6 +64,7 @@ void DrawVolumeAsPoints(void)
int x, y, z;
char value;
/* Initialize global help variables */
if( x_center == 0.0 || y_center == 0.0 || z_center == 0.0 )
{
x_center = .5 * sizex;
......@@ -76,6 +72,8 @@ void DrawVolumeAsPoints(void)
z_center = .5 * sizez;
}
/* Go through all voxels and compare them to the volume dataset. If the
* the value is in the specified range, draw a point at that location. */
glBegin(GL_POINTS);
for( x = 0; x < nx; x++ )
......@@ -95,6 +93,7 @@ void DrawVolumeAsCubes(void)
int x, y, z;
char value;
/* Initialize global help variables */
if( x_center == 0.0 || y_center == 0.0 || z_center == 0.0 )
{
x_center = .5 * sizex;
......@@ -102,6 +101,8 @@ void DrawVolumeAsCubes(void)
z_center = .5 * sizez;
}
/* Go through all voxels and compare them to the volume dataset. If the
* the value is in the specified range, draw a cube at that location. */
for( x = 0; x < nx; x++ )
{
for( y = 0; y < ny; y++ )
......@@ -131,6 +132,7 @@ void DrawVolumeAsCubes(void)
Be sure to set num_vertices_in_array.
*/
/* Add an (x,y,z)-value to the vertices array */
void
addVertex(int *index, float x, float y, float z)
{
......@@ -140,69 +142,60 @@ addVertex(int *index, float x, float y, float z)
num_vertices_in_array++;
}
/* Add an (x,y,z)-value to the normals array */
void
addNormal(int index, float x, float y, float z)
{
//normals[index++] = (float)x;
//normals[index++] = (float)y;
//normals[index] = (float)z;
normals[index++] = x;
normals[index++] = y;
normals[index] = z;
}
/* Draw the corners of a quad in the X-dimension (all points have the
* same x-coordinate). Add the corner normals to the normals array. */
void
addQuadX(int *index, float x, float y, float z,
float w, float h, float normal_x)
{
addNormal(*index, normal_x, 0, 0);
//addNormal(*index, normal_x, -1, -1);
addVertex(index, x, y, z);
addNormal(*index, normal_x, 0, 0);
//addNormal(*index, normal_x, 1, -1);
addVertex(index, x, y + w, z);
addNormal(*index, normal_x, 0, 0);
//addNormal(*index, normal_x, 1, 1);
addVertex(index, x, y + w, z + h);
addNormal(*index, normal_x, 0, 0);
//addNormal(*index, normal_x, -1, 1);
addVertex(index, x, y, z + h);
}
/* Draw the corners of a quad in the Y-dimension (all points have the
* same y-coordinate). Add the corner normals to the normals array. */
void
addQuadY(int *index, float x, float y, float z,
float w, float h, float normal_y)
{
addNormal(*index, 0, normal_y, 0);
//addNormal(*index, -1, normal_y, -1);
addVertex(index, x, y, z);
addNormal(*index, 0, normal_y, 0);
//addNormal(*index, 1, normal_y, -1);
addVertex(index, x + w, y, z);
addNormal(*index, 0, normal_y, 0);
//addNormal(*index, 1, normal_y, 1);
addVertex(index, x + w, y, z + h);
addNormal(*index, 0, normal_y, 0);
//addNormal(*index, -1, normal_y, 1);
addVertex(index, x, y, z + h);
}
/* Draw the corners of a quad in the Z-dimension (all points have the
* same z-coordinate). Add the corner normals to the normals array. */
void
addQuadZ(int *index, float x, float y, float z,
float w, float h, float normal_z)
{
addNormal(*index, 0, 0, normal_z);
//addNormal(*index, -1, -1, normal_z);
addVertex(index, x, y, z);
addNormal(*index, 0, 0, normal_z);
//addNormal(*index, -1, 1, normal_z);
addVertex(index, x, y + h, z);
addNormal(*index, 0, 0, normal_z);
//addNormal(*index, 1, 1, normal_z);
addVertex(index, x + w, y + h, z);
addNormal(*index, 0, 0, normal_z);
//addNormal(*index, 1, -1, normal_z);
addVertex(index, x + w, y, z);
}
......@@ -211,6 +204,7 @@ void FillArrayWithPoints(void)
int x, y, z, index;
char value;
/* Initialize global help variables */
if( x_center == 0.0 || y_center == 0.0 || z_center == 0.0 )
{
x_center = .5 * sizex;
......@@ -218,8 +212,11 @@ void FillArrayWithPoints(void)
z_center = .5 * sizez;
}
/* Clear array counters */
num_vertices_in_array = index = 0;
/* Go through all voxels and compare them to the volume dataset. If the
* the value is in the specified range, add a point at that location. */
for( x = 0; x < nx; x++ )
{
for( y = 0; y < ny; y++ )
......@@ -230,6 +227,13 @@ void FillArrayWithPoints(void)
&& value <= isovalue + epsilon )
{
addVertex(&index, x + x_center, y + y_center, z + z_center);
/* Check if the next point will fit in the vertices array */
if( num_vertices_in_array == MAX_VERTICES_IN_ARRAY )
{
puts("vertex array full, stopped filling");
return;
}
}
}
}
......@@ -248,14 +252,19 @@ void FillArrayWithCubes(void)
int x, y, z, index;
char value;
/* Initialize global help variables */
if( normal_x_size == 0.0 || normal_y_size == 0.0 )
{
// Set normal sizes relative to the
normal_x_size = sizez / sizex;
normal_y_size = sizez / sizey;
}
/* Clear array counters */
num_vertices_in_array = index = 0;
/* Go through all voxels and compare them to the volume dataset. If the
* the value is in the specified range, add a cube at that location. */
for( x = 0; x < nx; x++ )
{
for( y = 0; y < ny; y++ )
......@@ -265,9 +274,19 @@ void FillArrayWithCubes(void)
if( (value = volume[voxel2idx(x, y, z)]) >= isovalue - epsilon
&& value <= isovalue + epsilon )
{
/* Check if the cube will fit in the vertices array */
if( num_vertices_in_array + 24 > MAX_VERTICES_IN_ARRAY )
{
puts("vertex array full, stopped filling");
return;
}
/* Back planes of the cube */
addQuadX(&index, x, y, z, sizey, sizez, -normal_x_size);
addQuadY(&index, x, y, z, sizex, sizez, -normal_y_size);
addQuadZ(&index, x, y, z, sizex, sizey, -1.0);
/* Front planes of the cube */
addQuadX(&index, x + sizex, y, z, sizey, sizez, normal_x_size);
addQuadY(&index, x, y + sizey, z, sizex, sizez, normal_y_size);
addQuadZ(&index, x, y, z + sizez, sizex, sizey, 1.0);
......@@ -277,6 +296,7 @@ void FillArrayWithCubes(void)
}
}
/* Restart the framerate timer (also used at keypress-events) */
void
reset_timer(void)
{
......@@ -300,23 +320,25 @@ void DrawScene(void)
glFinish();
/* Stop framerate timer */
if( display_fps_counter )
{
if( timer == TIMER_FRAMERATE )
{
gettimeofday(&end, NULL);
printf("Framerate: %.0f \n", round(TIMER_FRAMERATE / (double)(
end.tv_sec - start.tv_sec
+ (end.tv_usec - start.tv_usec) * 0.000001
)));
/* Print FPS (rounded to complete frames) */
printf("Framerate: %d \n", (int)(TIMER_FRAMERATE / (
end.tv_sec - start.tv_sec + (end.tv_usec - start.tv_usec) * 1e-6
) + .5));
fflush(stdout);
}
timer = (timer + 1) % (TIMER_FRAMERATE + 1);
}
if( display_fps_counter && !timer )
/* Start framerate timer */
if( display_fps_counter && !timer )
gettimeofday(&start, NULL);
/* finally, swap the draw buffers to make the frame appear on screen */
......@@ -345,17 +367,6 @@ DrawVolumeAxes(void)
glVertex3f(0, 0, 0);
glVertex3f(0, 0, nz*sizez);
if( show_normals )
{
glColor3f(0, 0, 0);
for( int x = 0, y = 0; x < num_vertices_in_array; x++, y += 3 )
{
glVertex3f(vertices[y], vertices[y+1], vertices[y+2]);
glVertex3f(vertices[y] + normals[y], vertices[y+1] + normals[y+1], vertices[y+2] + normals[y+2]);
}
}
glEnd();
glPopAttrib();
......@@ -408,7 +419,8 @@ void DrawVolumeUsingCurrentDisplayMode(void)
glPointSize(POINT_SIZE);
if (use_arrays)
glDrawArrays(GL_POINTS, 0, num_vertices_in_array);
else
else
if (display_mode == 0)
DrawVolumeAsPoints();
}
else if (display_mode == 1)
......@@ -536,10 +548,6 @@ void keyPressed(unsigned char key, int x, int y)
exit(-1);
break;
case 'n':
show_normals = 1 - show_normals;
break;
case 'b':
backface_culling = 1 - backface_culling;
if (backface_culling)
......
......@@ -4,14 +4,10 @@
* Date ............ 29.10.2008
* Created by ...... Paul Melis
*
* Student name ....
* Student email ...
* Collegekaart ....
* Date ............
* Comments ........
*
*
* (always fill in these fields before submitting!!)
* Student name .... Sander van Veen & Taddeus Kroes
* Student email ... sandervv@gmail.com & taddeuskroes@hotmail.com
* Collegekaart .... 6167969 & 6054129
* Date ............ 07.11.2010
*/
#include <stdio.h>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment