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
4d11ffe5
Commit
4d11ffe5
authored
Nov 21, 2010
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Worked on graohics ass9.
parent
3909dfd7
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
95 additions
and
61 deletions
+95
-61
graphics/ass9/source/main
graphics/ass9/source/main
+0
-0
graphics/ass9/source/main.c
graphics/ass9/source/main.c
+4
-0
graphics/ass9/source/marching_tetrahedra.c
graphics/ass9/source/marching_tetrahedra.c
+91
-61
No files found.
graphics/ass9/source/main
View file @
4d11ffe5
No preview for this file type
graphics/ass9/source/main.c
View file @
4d11ffe5
...
@@ -229,18 +229,22 @@ void FillArrayWithIsosurface(void)
...
@@ -229,18 +229,22 @@ void FillArrayWithIsosurface(void)
triangle
tri
[
12
];
triangle
tri
[
12
];
vec3
normal
,
*
p
;
vec3
normal
,
*
p
;
// Loop through cells
for
(
x
=
0
;
x
<
nx
-
1
;
x
++
)
for
(
x
=
0
;
x
<
nx
-
1
;
x
++
)
{
{
for
(
y
=
0
;
y
<
ny
-
1
;
y
++
)
for
(
y
=
0
;
y
<
ny
-
1
;
y
++
)
{
{
for
(
z
=
0
;
z
<
nz
-
1
;
z
++
)
for
(
z
=
0
;
z
<
nz
-
1
;
z
++
)
{
{
// Calculate triangles in cell
n
=
generate_cell_triangles
(
tri
,
get_cell
(
x
,
y
,
z
),
isovalue
);
n
=
generate_cell_triangles
(
tri
,
get_cell
(
x
,
y
,
z
),
isovalue
);
tri_count
+=
n
;
tri_count
+=
n
;
for
(
i
=
0
;
i
<
n
;
i
++
)
for
(
i
=
0
;
i
<
n
;
i
++
)
{
{
p
=
tri
[
i
].
p
;
p
=
tri
[
i
].
p
;
// Calculate the triangle normal and set it to every corner
normal
=
v3_normalize
(
v3_crossprod
(
normal
=
v3_normalize
(
v3_crossprod
(
v3_subtract
(
p
[
1
],
p
[
0
]),
v3_subtract
(
p
[
1
],
p
[
0
]),
v3_subtract
(
p
[
2
],
p
[
0
])
v3_subtract
(
p
[
2
],
p
[
0
])
...
...
graphics/ass9/source/marching_tetrahedra.c
View file @
4d11ffe5
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <assert.h>
#include <assert.h>
#include <math.h>
#include "marching_tetrahedra.h"
#include "marching_tetrahedra.h"
/* Compute a linearly interpolated position where an isosurface cuts
/* Compute a linearly interpolated position where an isosurface cuts
...
@@ -22,10 +23,14 @@ static vec3
...
@@ -22,10 +23,14 @@ static vec3
interpolate_points
(
unsigned
char
isovalue
,
vec3
p1
,
vec3
p2
,
interpolate_points
(
unsigned
char
isovalue
,
vec3
p1
,
vec3
p2
,
unsigned
char
v1
,
unsigned
char
v2
)
unsigned
char
v1
,
unsigned
char
v2
)
{
{
/* Initially, simply return the midpoint between p1 and p2.
//float diff1 = fabsf((float)(isovalue - v1)),
So no real interpolation is done yet */
// diff2 = fabsf((float)(isovalue - v2)),
// total = diff1 + diff2;
//vec3 v = v3_add(v3_multiply(p1, diff1/total), v3_multiply(p2, diff2/total));
return
v3_add
(
v3_multiply
(
p1
,
0
.
5
),
v3_multiply
(
p2
,
0
.
5
));
vec3
v
=
v3_add
(
v3_multiply
(
p1
,
0
.
5
),
v3_multiply
(
p2
,
0
.
5
));
return
v3_create
(
v
.
x
*
sizex
,
v
.
y
*
sizey
,
v
.
z
*
sizez
);
}
}
/* Using the given iso-value generate triangles for the tetrahedron
/* Using the given iso-value generate triangles for the tetrahedron
...
@@ -39,71 +44,94 @@ interpolate_points(unsigned char isovalue, vec3 p1, vec3 p2,
...
@@ -39,71 +44,94 @@ interpolate_points(unsigned char isovalue, vec3 p1, vec3 p2,
2 triangles.
2 triangles.
*/
*/
// Some abbreviating definitions that are used in the function below
#define ADD_VEC(i,a,b) (triangles[tri_count].p[(i)] = \
interpolate_points(isovalue, c.p[(a)], c.p[(b)], v[(a)], v[(b)]))
#define ADD_TRI(a,b,c,d,e,f) \
ADD_VEC(0,(a),(b)); ADD_VEC(1,(c),(d)); ADD_VEC(2,(e),(f)); tri_count++
static
int
static
int
generate_tetrahedron_triangles
(
triangle
*
triangles
,
unsigned
char
isovalue
,
generate_tetrahedron_triangles
(
triangle
*
triangles
,
unsigned
char
isovalue
,
cell
c
,
int
v0
,
int
v1
,
int
v2
,
int
v3
)
cell
c
,
int
v0
,
int
v1
,
int
v2
,
int
v3
)
{
{
unsigned
char
*
v
=
c
.
value
;
unsigned
char
*
v
=
c
.
value
;
vec3
*
p
=
triangles
[
0
].
p
;
//vec3 *p = triangles[0].p;
int
bitsystem
=
0
;
int
tri_count
=
0
;
if
(
c
.
value
[
v0
]
>
isovalue
)
bitsystem
+=
1
;
if
(
c
.
value
[
v1
]
>
isovalue
)
bitsystem
+=
2
;
if
(
c
.
value
[
v2
]
>
isovalue
)
bitsystem
+=
4
;
if
(
c
.
value
[
v3
]
>
isovalue
)
bitsystem
+=
8
;
switch
(
bitsystem
)
// Use a 4-bit bitmask to determine the order of "black/white" points of
// the tetrahedon. Generate 0, 1 or 2 triangle(s) according to the case.
switch
(
(
v
[
v0
]
<=
isovalue
?
1
:
0
)
|
(
v
[
v1
]
<=
isovalue
?
1
<<
1
:
0
)
|
(
v
[
v2
]
<=
isovalue
?
1
<<
2
:
0
)
|
(
v
[
v3
]
<=
isovalue
?
1
<<
3
:
0
)
)
{
{
case
1
:
case
14
:
// 0001
case
0x1
:
case
0xE
:
// 0001 or 1110
p
[
0
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v0
],
c
.
p
[
v1
],
v
[
v0
],
v
[
v1
]);
ADD_TRI
(
v0
,
v1
,
v0
,
v2
,
v0
,
v3
);
p
[
1
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v0
],
c
.
p
[
v2
],
v
[
v0
],
v
[
v2
]);
break
;
p
[
2
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v0
],
c
.
p
[
v3
],
v
[
v0
],
v
[
v3
]);
//p[0] = interpolate_points(isovalue, c.p[v0], c.p[v1], v[v0], v[v1]);
return
1
;
//p[1] = interpolate_points(isovalue, c.p[v0], c.p[v2], v[v0], v[v2]);
case
2
:
case
13
:
// 0010
//p[2] = interpolate_points(isovalue, c.p[v0], c.p[v3], v[v0], v[v3]);
p
[
0
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v1
],
c
.
p
[
v0
],
v
[
v1
],
v
[
v0
]);
//return 1;
p
[
1
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v1
],
c
.
p
[
v3
],
v
[
v1
],
v
[
v3
]);
case
0x2
:
case
0xD
:
// 0010 or 1101
p
[
2
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v1
],
c
.
p
[
v2
],
v
[
v1
],
v
[
v2
]);
ADD_TRI
(
v1
,
v0
,
v1
,
v3
,
v1
,
v2
);
return
1
;
break
;
case
4
:
case
11
:
// 0100
//p[0] = interpolate_points(isovalue, c.p[v1], c.p[v0], v[v1], v[v0]);
p
[
0
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v2
],
c
.
p
[
v0
],
v
[
v2
],
v
[
v0
]);
//p[1] = interpolate_points(isovalue, c.p[v1], c.p[v3], v[v1], v[v3]);
p
[
1
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v2
],
c
.
p
[
v1
],
v
[
v2
],
v
[
v1
]);
//p[2] = interpolate_points(isovalue, c.p[v1], c.p[v2], v[v1], v[v2]);
p
[
2
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v2
],
c
.
p
[
v3
],
v
[
v2
],
v
[
v3
]);
//return 1;
return
1
;
case
0x4
:
case
0xB
:
// 0100 or 1011
case
8
:
case
7
:
// 1000
ADD_TRI
(
v2
,
v0
,
v2
,
v1
,
v2
,
v3
);
p
[
0
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v3
],
c
.
p
[
v0
],
v
[
v3
],
v
[
v0
]);
break
;
p
[
1
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v3
],
c
.
p
[
v2
],
v
[
v3
],
v
[
v2
]);
//p[0] = interpolate_points(isovalue, c.p[v2], c.p[v0], v[v2], v[v0]);
p
[
2
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v3
],
c
.
p
[
v1
],
v
[
v3
],
v
[
v1
]);
//p[1] = interpolate_points(isovalue, c.p[v2], c.p[v1], v[v2], v[v1]);
return
1
;
//p[2] = interpolate_points(isovalue, c.p[v2], c.p[v3], v[v2], v[v3]);
case
5
:
case
10
:
// 0101
//return 1;
p
[
0
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v0
],
c
.
p
[
v1
],
v
[
v0
],
v
[
v1
]);
case
0x8
:
case
0x7
:
// 1000 or 0111
p
[
1
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v2
],
c
.
p
[
v3
],
v
[
v2
],
v
[
v3
]);
ADD_TRI
(
v3
,
v0
,
v3
,
v2
,
v3
,
v1
);
p
[
2
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v0
],
c
.
p
[
v3
],
v
[
v0
],
v
[
v3
]);
break
;
p
=
triangles
[
1
].
p
;
//p[0] = interpolate_points(isovalue, c.p[v3], c.p[v0], v[v3], v[v0]);
p
[
0
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v0
],
c
.
p
[
v1
],
v
[
v0
],
v
[
v1
]);
//p[1] = interpolate_points(isovalue, c.p[v3], c.p[v2], v[v3], v[v2]);
p
[
1
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v1
],
c
.
p
[
v2
],
v
[
v1
],
v
[
v2
]);
//p[2] = interpolate_points(isovalue, c.p[v3], c.p[v1], v[v3], v[v1]);
p
[
2
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v2
],
c
.
p
[
v3
],
v
[
v2
],
v
[
v3
]);
//return 1;
return
2
;
case
0x3
:
case
0xC
:
// 0011 or 1100
case
3
:
case
12
:
// 0011
ADD_TRI
(
v0
,
v3
,
v0
,
v2
,
v1
,
v3
);
p
[
0
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v0
],
c
.
p
[
v3
],
v
[
v0
],
v
[
v3
]);
ADD_TRI
(
v1
,
v3
,
v0
,
v2
,
v1
,
v2
);
p
[
1
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v0
],
c
.
p
[
v2
],
v
[
v0
],
v
[
v2
]);
break
;
p
[
2
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v1
],
c
.
p
[
v3
],
v
[
v1
],
v
[
v3
]);
//p[0] = interpolate_points(isovalue, c.p[v0], c.p[v3], v[v0], v[v3]);
p
=
triangles
[
1
].
p
;
//p[1] = interpolate_points(isovalue, c.p[v0], c.p[v2], v[v0], v[v2]);
p
[
0
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v1
],
c
.
p
[
v3
],
v
[
v1
],
v
[
v3
]);
//p[2] = interpolate_points(isovalue, c.p[v1], c.p[v3], v[v1], v[v3]);
p
[
2
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v1
],
c
.
p
[
v2
],
v
[
v1
],
v
[
v2
]);
//p = triangles[1].p;
p
[
1
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v0
],
c
.
p
[
v2
],
v
[
v0
],
v
[
v2
]);
//p[0] = interpolate_points(isovalue, c.p[v1], c.p[v3], v[v1], v[v3]);
return
2
;
//p[2] = interpolate_points(isovalue, c.p[v1], c.p[v2], v[v1], v[v2]);
case
6
:
case
9
:
// 0110
//p[1] = interpolate_points(isovalue, c.p[v0], c.p[v2], v[v0], v[v2]);
p
[
0
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v0
],
c
.
p
[
v1
],
v
[
v0
],
v
[
v1
]);
//return 2;
p
[
2
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v1
],
c
.
p
[
v3
],
v
[
v1
],
v
[
v3
]);
case
0x5
:
case
0xA
:
// 0101 or 1010
p
[
1
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v2
],
c
.
p
[
v3
],
v
[
v2
],
v
[
v3
]);
ADD_TRI
(
v0
,
v1
,
v2
,
v3
,
v0
,
v3
);
p
=
triangles
[
1
].
p
;
ADD_TRI
(
v0
,
v1
,
v1
,
v2
,
v2
,
v3
);
p
[
0
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v0
],
c
.
p
[
v1
],
v
[
v0
],
v
[
v1
]);
break
;
p
[
1
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v0
],
c
.
p
[
v2
],
v
[
v0
],
v
[
v2
]);
//p[0] = interpolate_points(isovalue, c.p[v0], c.p[v1], v[v0], v[v1]);
p
[
2
]
=
interpolate_points
(
isovalue
,
c
.
p
[
v2
],
c
.
p
[
v3
],
v
[
v2
],
v
[
v3
]);
//p[1] = interpolate_points(isovalue, c.p[v2], c.p[v3], v[v2], v[v3]);
return
2
;
//p[2] = interpolate_points(isovalue, c.p[v0], c.p[v3], v[v0], v[v3]);
default:
// 0000
//p = triangles[1].p;
return
0
;
//p[0] = interpolate_points(isovalue, c.p[v0], c.p[v1], v[v0], v[v1]);
//p[1] = interpolate_points(isovalue, c.p[v1], c.p[v2], v[v1], v[v2]);
//p[2] = interpolate_points(isovalue, c.p[v2], c.p[v3], v[v2], v[v3]);
//return 2;
case
0x6
:
case
0x9
:
// 0110 or 1001
ADD_TRI
(
v0
,
v1
,
v2
,
v3
,
v1
,
v3
);
ADD_TRI
(
v0
,
v1
,
v0
,
v2
,
v2
,
v3
);
break
;
//p[0] = interpolate_points(isovalue, c.p[v0], c.p[v1], v[v0], v[v1]);
//p[2] = interpolate_points(isovalue, c.p[v1], c.p[v3], v[v1], v[v3]);
//p[1] = interpolate_points(isovalue, c.p[v2], c.p[v3], v[v2], v[v3]);
//p = triangles[1].p;
//p[0] = interpolate_points(isovalue, c.p[v0], c.p[v1], v[v0], v[v1]);
//p[1] = interpolate_points(isovalue, c.p[v0], c.p[v2], v[v0], v[v2]);
//p[2] = interpolate_points(isovalue, c.p[v2], c.p[v3], v[v2], v[v3]);
//return 2;
default:
// 0000 or 1111
break
;
}
}
return
tri_count
;
}
}
/* Generate triangles for a single cell for the given iso-value. This function
/* Generate triangles for a single cell for the given iso-value. This function
...
@@ -118,9 +146,11 @@ generate_tetrahedron_triangles(triangle *triangles, unsigned char isovalue,
...
@@ -118,9 +146,11 @@ generate_tetrahedron_triangles(triangle *triangles, unsigned char isovalue,
int
int
generate_cell_triangles
(
triangle
*
triangles
,
cell
c
,
unsigned
char
isovalue
)
generate_cell_triangles
(
triangle
*
triangles
,
cell
c
,
unsigned
char
isovalue
)
{
{
// Indices to cell corners for each tetrahedon (6 * 4 indices)
const
int
points
[
24
]
=
{
0
,
1
,
3
,
7
,
0
,
2
,
6
,
7
,
0
,
1
,
5
,
7
,
0
,
2
,
3
,
7
,
0
,
4
,
5
,
7
,
0
,
4
,
6
,
7
};
const
int
points
[
24
]
=
{
0
,
1
,
3
,
7
,
0
,
2
,
6
,
7
,
0
,
1
,
5
,
7
,
0
,
2
,
3
,
7
,
0
,
4
,
5
,
7
,
0
,
4
,
6
,
7
};
int
i
,
tri_count
=
0
;
int
i
,
tri_count
=
0
;
// Generate triangles for each tetrahedon
for
(
i
=
0
;
i
<
21
;
i
+=
4
)
for
(
i
=
0
;
i
<
21
;
i
+=
4
)
{
{
tri_count
+=
generate_tetrahedron_triangles
(
triangles
+
tri_count
,
tri_count
+=
generate_tetrahedron_triangles
(
triangles
+
tri_count
,
...
...
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