-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcolour_curvature.c
142 lines (115 loc) · 4.71 KB
/
colour_curvature.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <bicpl.h>
#define GRAY_STRING "gray"
#define HOT_STRING "hot"
#define SPECTRAL_STRING "spectral"
int main(
int argc,
char *argv[] )
{
Status status;
Real low_threshold, smoothing_distance;
Real *curvatures;
STRING src_filename, dest_filename;
int i, p, n_src_objects, n_dest_objects;
File_formats format;
object_struct **src_object_list, **dest_object_list;
polygons_struct *polygons1, *polygons2;
Colour_coding_types coding_type;
colour_coding_struct colour_coding;
STRING coding_type_string;
Real low, high, min_curvature, max_curvature;
BOOLEAN low_present, high_present;
initialize_argument_processing( argc, argv );
if( !get_string_argument( "", &src_filename ) ||
!get_string_argument( "", &dest_filename ) )
{
print_error( "Usage: %s in.obj out.obj [dist] [gray|hot] [lo] [hi]\n",
argv[0] );
print_error( " [low_threshold]\n" );
return( 1 );
}
(void) get_real_argument( 0.0, &smoothing_distance );
(void) get_string_argument( GRAY_STRING, &coding_type_string );
low_present = get_real_argument( -0.2, &low );
high_present = get_real_argument( 0.2, &high );
if( equal_strings( coding_type_string, GRAY_STRING ) )
coding_type = GRAY_SCALE;
else if( equal_strings( coding_type_string, HOT_STRING ) )
coding_type = HOT_METAL;
else if( equal_strings( coding_type_string, SPECTRAL_STRING ) )
coding_type = SPECTRAL;
else
{
print( "Invalid coding type: %s\n", coding_type_string );
return( 1 );
}
(void) get_real_argument( 0.0, &low_threshold );
if( input_graphics_file( src_filename, &format, &n_src_objects,
&src_object_list ) != OK )
return( 1 );
if( input_graphics_file( dest_filename, &format, &n_dest_objects,
&dest_object_list ) != OK )
return( 1 );
print( "%d Objects input.\n", n_src_objects );
if( n_src_objects != n_dest_objects )
{
print( "Different number of objects in the two files.\n" );
return( 1 );
}
for_less( i, 0, n_src_objects )
{
if( src_object_list[i]->object_type == POLYGONS &&
dest_object_list[i]->object_type == POLYGONS &&
polygons_are_same_topology(
get_polygons_ptr(src_object_list[i]),
get_polygons_ptr(dest_object_list[i]) ) )
{
polygons1 = get_polygons_ptr(src_object_list[i]);
polygons2 = get_polygons_ptr(dest_object_list[i]);
ALLOC( curvatures, polygons1->n_points );
if( smoothing_distance > 0.0 )
compute_polygon_normals( polygons1 );
get_polygon_vertex_curvatures( polygons1, smoothing_distance,
low_threshold, curvatures );
if( polygons2->colour_flag != PER_VERTEX_COLOURS )
{
polygons2->colour_flag = PER_VERTEX_COLOURS;
REALLOC( polygons2->colours, polygons2->n_points );
}
if( !low_present || !high_present )
{
min_curvature = 0.0;
max_curvature = 0.0;
for_less( p, 0, polygons1->n_points )
{
if( p == 0 || curvatures[p] < min_curvature )
min_curvature = curvatures[p];
if( p == 0 || curvatures[p] > max_curvature )
max_curvature = curvatures[p];
}
if( !low_present )
low = min_curvature;
if( !high_present )
high = max_curvature;
}
initialize_colour_coding( &colour_coding, coding_type,
BLACK, WHITE, low, high );
for_less( p, 0, polygons1->n_points )
{
polygons2->colours[p] = get_colour_code( &colour_coding,
curvatures[p] );
}
FREE( curvatures );
}
else
print( "Objects don't match.\n" );
}
print( "Objects processed.\n" );
status = output_graphics_file( dest_filename, format,
n_dest_objects, dest_object_list );
delete_object_list( n_src_objects, src_object_list );
delete_object_list( n_dest_objects, dest_object_list );
if( status == OK )
print( "Objects output.\n" );
return( status != OK );
}