Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
uva
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
uva
Commits
ec5c92d4
Commit
ec5c92d4
authored
Nov 14, 2010
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Finished graphics ass8.
parent
f5c7e003
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
56 deletions
+77
-56
graphics/ass8/framerates.txt
graphics/ass8/framerates.txt
+17
-0
graphics/ass8/main.c
graphics/ass8/main.c
+56
-48
graphics/ass8/volume.c
graphics/ass8/volume.c
+4
-8
No files found.
graphics/ass8/framerates.txt
0 → 100644
View file @
ec5c92d4
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.
graphics/ass8/main.c
View file @
ec5c92d4
...
@@ -5,14 +5,10 @@
...
@@ -5,14 +5,10 @@
* Date ............ 29.10.2008
* Date ............ 29.10.2008
* Created by ...... Paul Melis
* Created by ...... Paul Melis
*
*
* Student name ....
* Student name .... Sander van Veen & Taddeus Kroes
* Student email ...
* Student email ... sandervv@gmail.com & taddeuskroes@hotmail.com
* Collegekaart ....
* Collegekaart .... 6167969 & 6054129
* Date ............
* Date ............ 07.11.2010
* Comments ........
*
*
* (always fill in these fields before submitting!!)
*/
*/
#include <stdio.h>
#include <stdio.h>
...
@@ -42,8 +38,6 @@ int entered_number=0;
...
@@ -42,8 +38,6 @@ int entered_number=0;
int
display_fps_counter
=
0
;
int
display_fps_counter
=
0
;
int
backface_culling
=
0
;
int
backface_culling
=
0
;
int
show_normals
=
0
;
#define MAX_VERTICES_IN_ARRAY 5000000
#define MAX_VERTICES_IN_ARRAY 5000000
int
num_vertices_in_array
=
0
;
int
num_vertices_in_array
=
0
;
...
@@ -54,7 +48,8 @@ void SetupCamera(void);
...
@@ -54,7 +48,8 @@ void SetupCamera(void);
void
DrawVolumeAxes
(
void
);
void
DrawVolumeAxes
(
void
);
void
DrawVolumeUsingCurrentDisplayMode
(
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
#define POINT_SIZE 1.0
int
timer
=
TIMER_FRAMERATE
+
1
;
int
timer
=
TIMER_FRAMERATE
+
1
;
...
@@ -69,6 +64,7 @@ void DrawVolumeAsPoints(void)
...
@@ -69,6 +64,7 @@ void DrawVolumeAsPoints(void)
int
x
,
y
,
z
;
int
x
,
y
,
z
;
char
value
;
char
value
;
/* Initialize global help variables */
if
(
x_center
==
0
.
0
||
y_center
==
0
.
0
||
z_center
==
0
.
0
)
if
(
x_center
==
0
.
0
||
y_center
==
0
.
0
||
z_center
==
0
.
0
)
{
{
x_center
=
.
5
*
sizex
;
x_center
=
.
5
*
sizex
;
...
@@ -76,6 +72,8 @@ void DrawVolumeAsPoints(void)
...
@@ -76,6 +72,8 @@ void DrawVolumeAsPoints(void)
z_center
=
.
5
*
sizez
;
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
);
glBegin
(
GL_POINTS
);
for
(
x
=
0
;
x
<
nx
;
x
++
)
for
(
x
=
0
;
x
<
nx
;
x
++
)
...
@@ -95,6 +93,7 @@ void DrawVolumeAsCubes(void)
...
@@ -95,6 +93,7 @@ void DrawVolumeAsCubes(void)
int
x
,
y
,
z
;
int
x
,
y
,
z
;
char
value
;
char
value
;
/* Initialize global help variables */
if
(
x_center
==
0
.
0
||
y_center
==
0
.
0
||
z_center
==
0
.
0
)
if
(
x_center
==
0
.
0
||
y_center
==
0
.
0
||
z_center
==
0
.
0
)
{
{
x_center
=
.
5
*
sizex
;
x_center
=
.
5
*
sizex
;
...
@@ -102,6 +101,8 @@ void DrawVolumeAsCubes(void)
...
@@ -102,6 +101,8 @@ void DrawVolumeAsCubes(void)
z_center
=
.
5
*
sizez
;
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
(
x
=
0
;
x
<
nx
;
x
++
)
{
{
for
(
y
=
0
;
y
<
ny
;
y
++
)
for
(
y
=
0
;
y
<
ny
;
y
++
)
...
@@ -131,6 +132,7 @@ void DrawVolumeAsCubes(void)
...
@@ -131,6 +132,7 @@ void DrawVolumeAsCubes(void)
Be sure to set num_vertices_in_array.
Be sure to set num_vertices_in_array.
*/
*/
/* Add an (x,y,z)-value to the vertices array */
void
void
addVertex
(
int
*
index
,
float
x
,
float
y
,
float
z
)
addVertex
(
int
*
index
,
float
x
,
float
y
,
float
z
)
{
{
...
@@ -140,69 +142,60 @@ 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
++
;
num_vertices_in_array
++
;
}
}
/* Add an (x,y,z)-value to the normals array */
void
void
addNormal
(
int
index
,
float
x
,
float
y
,
float
z
)
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
++
]
=
x
;
normals
[
index
++
]
=
y
;
normals
[
index
++
]
=
y
;
normals
[
index
]
=
z
;
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
void
addQuadX
(
int
*
index
,
float
x
,
float
y
,
float
z
,
addQuadX
(
int
*
index
,
float
x
,
float
y
,
float
z
,
float
w
,
float
h
,
float
normal_x
)
float
w
,
float
h
,
float
normal_x
)
{
{
addNormal
(
*
index
,
normal_x
,
0
,
0
);
addNormal
(
*
index
,
normal_x
,
0
,
0
);
//addNormal(*index, normal_x, -1, -1);
addVertex
(
index
,
x
,
y
,
z
);
addVertex
(
index
,
x
,
y
,
z
);
addNormal
(
*
index
,
normal_x
,
0
,
0
);
addNormal
(
*
index
,
normal_x
,
0
,
0
);
//addNormal(*index, normal_x, 1, -1);
addVertex
(
index
,
x
,
y
+
w
,
z
);
addVertex
(
index
,
x
,
y
+
w
,
z
);
addNormal
(
*
index
,
normal_x
,
0
,
0
);
addNormal
(
*
index
,
normal_x
,
0
,
0
);
//addNormal(*index, normal_x, 1, 1);
addVertex
(
index
,
x
,
y
+
w
,
z
+
h
);
addVertex
(
index
,
x
,
y
+
w
,
z
+
h
);
addNormal
(
*
index
,
normal_x
,
0
,
0
);
addNormal
(
*
index
,
normal_x
,
0
,
0
);
//addNormal(*index, normal_x, -1, 1);
addVertex
(
index
,
x
,
y
,
z
+
h
);
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
void
addQuadY
(
int
*
index
,
float
x
,
float
y
,
float
z
,
addQuadY
(
int
*
index
,
float
x
,
float
y
,
float
z
,
float
w
,
float
h
,
float
normal_y
)
float
w
,
float
h
,
float
normal_y
)
{
{
addNormal
(
*
index
,
0
,
normal_y
,
0
);
addNormal
(
*
index
,
0
,
normal_y
,
0
);
//addNormal(*index, -1, normal_y, -1);
addVertex
(
index
,
x
,
y
,
z
);
addVertex
(
index
,
x
,
y
,
z
);
addNormal
(
*
index
,
0
,
normal_y
,
0
);
addNormal
(
*
index
,
0
,
normal_y
,
0
);
//addNormal(*index, 1, normal_y, -1);
addVertex
(
index
,
x
+
w
,
y
,
z
);
addVertex
(
index
,
x
+
w
,
y
,
z
);
addNormal
(
*
index
,
0
,
normal_y
,
0
);
addNormal
(
*
index
,
0
,
normal_y
,
0
);
//addNormal(*index, 1, normal_y, 1);
addVertex
(
index
,
x
+
w
,
y
,
z
+
h
);
addVertex
(
index
,
x
+
w
,
y
,
z
+
h
);
addNormal
(
*
index
,
0
,
normal_y
,
0
);
addNormal
(
*
index
,
0
,
normal_y
,
0
);
//addNormal(*index, -1, normal_y, 1);
addVertex
(
index
,
x
,
y
,
z
+
h
);
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
void
addQuadZ
(
int
*
index
,
float
x
,
float
y
,
float
z
,
addQuadZ
(
int
*
index
,
float
x
,
float
y
,
float
z
,
float
w
,
float
h
,
float
normal_z
)
float
w
,
float
h
,
float
normal_z
)
{
{
addNormal
(
*
index
,
0
,
0
,
normal_z
);
addNormal
(
*
index
,
0
,
0
,
normal_z
);
//addNormal(*index, -1, -1, normal_z);
addVertex
(
index
,
x
,
y
,
z
);
addVertex
(
index
,
x
,
y
,
z
);
addNormal
(
*
index
,
0
,
0
,
normal_z
);
addNormal
(
*
index
,
0
,
0
,
normal_z
);
//addNormal(*index, -1, 1, normal_z);
addVertex
(
index
,
x
,
y
+
h
,
z
);
addVertex
(
index
,
x
,
y
+
h
,
z
);
addNormal
(
*
index
,
0
,
0
,
normal_z
);
addNormal
(
*
index
,
0
,
0
,
normal_z
);
//addNormal(*index, 1, 1, normal_z);
addVertex
(
index
,
x
+
w
,
y
+
h
,
z
);
addVertex
(
index
,
x
+
w
,
y
+
h
,
z
);
addNormal
(
*
index
,
0
,
0
,
normal_z
);
addNormal
(
*
index
,
0
,
0
,
normal_z
);
//addNormal(*index, 1, -1, normal_z);
addVertex
(
index
,
x
+
w
,
y
,
z
);
addVertex
(
index
,
x
+
w
,
y
,
z
);
}
}
...
@@ -211,6 +204,7 @@ void FillArrayWithPoints(void)
...
@@ -211,6 +204,7 @@ void FillArrayWithPoints(void)
int
x
,
y
,
z
,
index
;
int
x
,
y
,
z
,
index
;
char
value
;
char
value
;
/* Initialize global help variables */
if
(
x_center
==
0
.
0
||
y_center
==
0
.
0
||
z_center
==
0
.
0
)
if
(
x_center
==
0
.
0
||
y_center
==
0
.
0
||
z_center
==
0
.
0
)
{
{
x_center
=
.
5
*
sizex
;
x_center
=
.
5
*
sizex
;
...
@@ -218,8 +212,11 @@ void FillArrayWithPoints(void)
...
@@ -218,8 +212,11 @@ void FillArrayWithPoints(void)
z_center
=
.
5
*
sizez
;
z_center
=
.
5
*
sizez
;
}
}
/* Clear array counters */
num_vertices_in_array
=
index
=
0
;
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
(
x
=
0
;
x
<
nx
;
x
++
)
{
{
for
(
y
=
0
;
y
<
ny
;
y
++
)
for
(
y
=
0
;
y
<
ny
;
y
++
)
...
@@ -230,6 +227,13 @@ void FillArrayWithPoints(void)
...
@@ -230,6 +227,13 @@ void FillArrayWithPoints(void)
&&
value
<=
isovalue
+
epsilon
)
&&
value
<=
isovalue
+
epsilon
)
{
{
addVertex
(
&
index
,
x
+
x_center
,
y
+
y_center
,
z
+
z_center
);
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)
...
@@ -248,14 +252,19 @@ void FillArrayWithCubes(void)
int
x
,
y
,
z
,
index
;
int
x
,
y
,
z
,
index
;
char
value
;
char
value
;
/* Initialize global help variables */
if
(
normal_x_size
==
0
.
0
||
normal_y_size
==
0
.
0
)
if
(
normal_x_size
==
0
.
0
||
normal_y_size
==
0
.
0
)
{
{
// Set normal sizes relative to the
normal_x_size
=
sizez
/
sizex
;
normal_x_size
=
sizez
/
sizex
;
normal_y_size
=
sizez
/
sizey
;
normal_y_size
=
sizez
/
sizey
;
}
}
/* Clear array counters */
num_vertices_in_array
=
index
=
0
;
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
(
x
=
0
;
x
<
nx
;
x
++
)
{
{
for
(
y
=
0
;
y
<
ny
;
y
++
)
for
(
y
=
0
;
y
<
ny
;
y
++
)
...
@@ -265,9 +274,19 @@ void FillArrayWithCubes(void)
...
@@ -265,9 +274,19 @@ void FillArrayWithCubes(void)
if
(
(
value
=
volume
[
voxel2idx
(
x
,
y
,
z
)])
>=
isovalue
-
epsilon
if
(
(
value
=
volume
[
voxel2idx
(
x
,
y
,
z
)])
>=
isovalue
-
epsilon
&&
value
<=
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
);
addQuadX
(
&
index
,
x
,
y
,
z
,
sizey
,
sizez
,
-
normal_x_size
);
addQuadY
(
&
index
,
x
,
y
,
z
,
sizex
,
sizez
,
-
normal_y_size
);
addQuadY
(
&
index
,
x
,
y
,
z
,
sizex
,
sizez
,
-
normal_y_size
);
addQuadZ
(
&
index
,
x
,
y
,
z
,
sizex
,
sizey
,
-
1
.
0
);
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
);
addQuadX
(
&
index
,
x
+
sizex
,
y
,
z
,
sizey
,
sizez
,
normal_x_size
);
addQuadY
(
&
index
,
x
,
y
+
sizey
,
z
,
sizex
,
sizez
,
normal_y_size
);
addQuadY
(
&
index
,
x
,
y
+
sizey
,
z
,
sizex
,
sizez
,
normal_y_size
);
addQuadZ
(
&
index
,
x
,
y
,
z
+
sizez
,
sizex
,
sizey
,
1
.
0
);
addQuadZ
(
&
index
,
x
,
y
,
z
+
sizez
,
sizex
,
sizey
,
1
.
0
);
...
@@ -277,6 +296,7 @@ void FillArrayWithCubes(void)
...
@@ -277,6 +296,7 @@ void FillArrayWithCubes(void)
}
}
}
}
/* Restart the framerate timer (also used at keypress-events) */
void
void
reset_timer
(
void
)
reset_timer
(
void
)
{
{
...
@@ -300,23 +320,25 @@ void DrawScene(void)
...
@@ -300,23 +320,25 @@ void DrawScene(void)
glFinish
();
glFinish
();
/* Stop framerate timer */
if
(
display_fps_counter
)
if
(
display_fps_counter
)
{
{
if
(
timer
==
TIMER_FRAMERATE
)
if
(
timer
==
TIMER_FRAMERATE
)
{
{
gettimeofday
(
&
end
,
NULL
);
gettimeofday
(
&
end
,
NULL
);
printf
(
"Framerate: %.0f
\n
"
,
round
(
TIMER_FRAMERATE
/
(
double
)(
/* Print FPS (rounded to complete frames) */
end
.
tv_sec
-
start
.
tv_sec
printf
(
"Framerate: %d
\n
"
,
(
int
)(
TIMER_FRAMERATE
/
(
+
(
end
.
tv_usec
-
start
.
tv_usec
)
*
0
.
000001
end
.
tv_sec
-
start
.
tv_sec
+
(
end
.
tv_usec
-
start
.
tv_usec
)
*
1e-6
)));
)
+
.
5
));
fflush
(
stdout
);
fflush
(
stdout
);
}
}
timer
=
(
timer
+
1
)
%
(
TIMER_FRAMERATE
+
1
);
timer
=
(
timer
+
1
)
%
(
TIMER_FRAMERATE
+
1
);
}
}
if
(
display_fps_counter
&&
!
timer
)
/* Start framerate timer */
if
(
display_fps_counter
&&
!
timer
)
gettimeofday
(
&
start
,
NULL
);
gettimeofday
(
&
start
,
NULL
);
/* finally, swap the draw buffers to make the frame appear on screen */
/* finally, swap the draw buffers to make the frame appear on screen */
...
@@ -345,17 +367,6 @@ DrawVolumeAxes(void)
...
@@ -345,17 +367,6 @@ DrawVolumeAxes(void)
glVertex3f
(
0
,
0
,
0
);
glVertex3f
(
0
,
0
,
0
);
glVertex3f
(
0
,
0
,
nz
*
sizez
);
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
();
glEnd
();
glPopAttrib
();
glPopAttrib
();
...
@@ -408,7 +419,8 @@ void DrawVolumeUsingCurrentDisplayMode(void)
...
@@ -408,7 +419,8 @@ void DrawVolumeUsingCurrentDisplayMode(void)
glPointSize
(
POINT_SIZE
);
glPointSize
(
POINT_SIZE
);
if
(
use_arrays
)
if
(
use_arrays
)
glDrawArrays
(
GL_POINTS
,
0
,
num_vertices_in_array
);
glDrawArrays
(
GL_POINTS
,
0
,
num_vertices_in_array
);
else
else
if
(
display_mode
==
0
)
DrawVolumeAsPoints
();
DrawVolumeAsPoints
();
}
}
else
if
(
display_mode
==
1
)
else
if
(
display_mode
==
1
)
...
@@ -536,10 +548,6 @@ void keyPressed(unsigned char key, int x, int y)
...
@@ -536,10 +548,6 @@ void keyPressed(unsigned char key, int x, int y)
exit
(
-
1
);
exit
(
-
1
);
break
;
break
;
case
'n'
:
show_normals
=
1
-
show_normals
;
break
;
case
'b'
:
case
'b'
:
backface_culling
=
1
-
backface_culling
;
backface_culling
=
1
-
backface_culling
;
if
(
backface_culling
)
if
(
backface_culling
)
...
...
graphics/ass8/volume.c
View file @
ec5c92d4
...
@@ -4,14 +4,10 @@
...
@@ -4,14 +4,10 @@
* Date ............ 29.10.2008
* Date ............ 29.10.2008
* Created by ...... Paul Melis
* Created by ...... Paul Melis
*
*
* Student name ....
* Student name .... Sander van Veen & Taddeus Kroes
* Student email ...
* Student email ... sandervv@gmail.com & taddeuskroes@hotmail.com
* Collegekaart ....
* Collegekaart .... 6167969 & 6054129
* Date ............
* Date ............ 07.11.2010
* Comments ........
*
*
* (always fill in these fields before submitting!!)
*/
*/
#include <stdio.h>
#include <stdio.h>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment