-
Notifications
You must be signed in to change notification settings - Fork 3
/
clip_polygons.c
69 lines (54 loc) · 1.98 KB
/
clip_polygons.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
#include <special_geometry.h>
int main(
int argc,
char *argv[] )
{
Status status;
char *input_filename, *output_filename;
int i, n_objects, clip_status;
Real volume;
polygons_struct clipped;
File_formats format;
object_struct **object_list;
static Vector plane_normal = { 0.34118703, -0.06975647, 0.93740362 };
static Real plane_constant = 23.435121182316;
status = OK;
initialize_argument_processing( argc, argv );
if( !get_string_argument( "", &input_filename ) )
{
(void) fprintf( stderr, "Must have a filename argument.\n" );
return( 1 );
}
(void) get_string_argument( input_filename, &output_filename );
status = input_graphics_file( input_filename, &format, &n_objects,
&object_list );
if( status == OK )
print( "Objects input.\n" );
if( status == OK )
{
for_less( i, 0, n_objects )
{
if( status == OK && get_object_type(object_list[i]) )
{
clip_status = clip_polygons_to_plane(
get_polygons_ptr(object_list[i]),
&plane_normal, plane_constant,
&clipped );
volume = get_closed_polyhedron_volume( &clipped );
print( "Clipped Volume: %g\n", volume );
delete_polygons( get_polygons_ptr(object_list[i]) );
*get_polygons_ptr(object_list[i]) = clipped;
}
}
if( status == OK )
print( "Objects processed.\n" );
}
if( status == OK )
status = output_graphics_file( output_filename, format,
n_objects, object_list );
if( status == OK )
delete_object_list( n_objects, object_list );
if( status == OK )
print( "Objects output.\n" );
return( status != OK );
}