-
Notifications
You must be signed in to change notification settings - Fork 3
/
chamfer.c
97 lines (78 loc) · 2.91 KB
/
chamfer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <bicpl.h>
int main( argc, argv )
int argc;
char *argv[];
{
Status status;
char *input_filename, *output_filename;
Real threshold;
Volume volume;
initialize_argument_processing( argc, argv );
if( !get_string_argument( "", &input_filename ) ||
!get_string_argument( "", &output_filename ) ||
!get_real_argument( 0.0, &isovalue ) )
{
print( "Usage: chamfer input_filename output_filename threshold\n");
return( 1 );
}
status = input_volume( input_filename, 3, XYZ_dimension_names,
NC_UNSPECIFIED, FALSE, 0.0, 0.0, TRUE,
&volume, (minc_input_options *) NULL );
new_volume = create_chamfer_volume( volume, threshold );
status = output_volume( output_filename, NC_UNSPECIFIED, FALSE,
0.0, 0.0, new_volume, "chamfered",
(minc_output_options *) NULL );
return( status != OK );
}
private Volume create_chamfer_volume(
Volume volume,
Real threshold )
{
int sizes[MAX_DIMENSIONS], ind[MAX_DIMENSIONS], neigh[MAX_DIMENSIONS];
int dir, c;
Volume chamfer;
BOOLEAN surface_flag;
Real value, neigh_value;
chamfer = copy_volume_definition( volume, NC_UNSPECIFIED, FALSE, 0.0, 0.0 );
get_volume_sizes( volume, sizes );
for_less( ind[X], 0, sizes[X] )
{
for_less( ind[Y], 0, sizes[Y] )
{
for_less( ind[Z], 0, sizes[Z] )
{
surface_flag = FALSE;
min_diff = 0.0;
value = get_volume_real_value( volume, ind[X], ind[Y], ind[Z],
0, 0 );
neigh[X] = ind[X];
neigh[Y] = ind[Y];
neigh[Z] = ind[Z];
for( dir = -1; dir <= 1; dir += 2 )
{
for_less( c, 0, N_DIMENSIONS )
{
neigh[c] += dir;
if( neigh[c] >= 0 && neigh[c] < sizes[c] )
{
neigh_value = get_volume_real_value( volume,
neigh[X], neigh[Y], neigh[Z], 0, 0 );
if( value <= threshold && neigh_value >= threshold||
value >= threshold && neigh_value <= threshold )
{
surface_flag = TRUE;
}
}
neigh[c] -= dir;
}
}
if( !surface_flag )
{
set_volume_voxel_value( volume, ind[X], ind[Y], ind[Z],
0, 0, 255.0 );
}
}
}
}
return( chamfer );
}