-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcompute_bounding_view.c
148 lines (128 loc) · 4.61 KB
/
compute_bounding_view.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
143
144
145
146
147
148
#include <volume_io/internal_volume_io.h>
#include <bicpl.h>
public Status process_object(
object_struct *object );
private void usage(
STRING executable )
{
STRING usage_str = "\n\
Usage: %s input.obj xview yview zview xup yup zup\n\
\n\
Computes the world limits of the object in the orthogonal view \n\
defined by ( xview yview zview xup yup zup )\n\n";
print_error( usage_str, executable );
}
int main(
int argc,
char *argv[] )
{
STRING input_filename, transform_filename;
Real xview, yview, zview, xup, yup, zup, x, y, z;
int point, n_points, n_objects, dim, i;
Real min_position[N_DIMENSIONS];
Real max_position[N_DIMENSIONS];
Real min_pos, max_pos;
Point *points, trans_point;
Vector x_axis, y_axis, z_axis;
Vector axis[N_DIMENSIONS];
General_transform transform;
File_formats format;
object_struct **object_list;
BOOLEAN first, have_transform;
initialize_argument_processing( argc, argv );
if( !get_string_argument( NULL, &input_filename ) ||
!get_real_argument( 0.0, &xview ) ||
!get_real_argument( 0.0, &yview ) ||
!get_real_argument( 0.0, &zview ) ||
!get_real_argument( 0.0, &xup ) ||
!get_real_argument( 0.0, &yup ) ||
!get_real_argument( 0.0, &zup ) )
{
usage( argv[0] );
return( 1 );
}
have_transform = get_string_argument( NULL, &transform_filename );
if( have_transform &&
input_transform_file( transform_filename, &transform ) != OK )
{
return( 1 );
}
if( input_graphics_file( input_filename, &format, &n_objects,
&object_list ) != OK )
return( 1 );
fill_Vector( z_axis, xview, yview, zview );
fill_Vector( y_axis, xup, yup, zup );
CROSS_VECTORS( x_axis, z_axis, y_axis );
CROSS_VECTORS( y_axis, x_axis, z_axis );
NORMALIZE_VECTOR( x_axis, x_axis );
NORMALIZE_VECTOR( y_axis, y_axis );
NORMALIZE_VECTOR( z_axis, z_axis );
axis[0] = x_axis;
axis[1] = y_axis;
axis[2] = z_axis;
for_less( dim, 0, N_DIMENSIONS )
{
min_position[dim] = 0.0;
max_position[dim] = 0.0;
}
first = TRUE;
for_less( i, 0, n_objects )
{
n_points = get_object_points( object_list[i], &points );
for_less( point, 0, n_points )
{
if( have_transform )
{
general_transform_point( &transform,
RPoint_x( points[point] ),
RPoint_y( points[point] ),
RPoint_z( points[point] ),
&x, &y, &z );
fill_Point( trans_point, x, y, z );
}
else
trans_point = points[point];
for_less( dim, 0, N_DIMENSIONS )
{
min_pos = DOT_VECTORS( axis[dim], trans_point );
max_pos = min_pos;
if( get_object_type(object_list[i]) == LINES )
{
min_pos -= get_lines_ptr(object_list[i])->
line_thickness / 2.0;
max_pos += get_lines_ptr(object_list[i])->
line_thickness / 2.0;
}
if( first )
{
min_position[dim] = min_pos;
max_position[dim] = max_pos;
}
else
{
if( min_pos < min_position[dim] )
min_position[dim] = min_pos;
if( max_pos > max_position[dim])
max_position[dim] = max_pos;
}
}
first = FALSE;
}
if( get_object_type(object_list[i]) == LINES )
{
for_less( dim, 0, N_DIMENSIONS )
{
min_position[dim] -= get_lines_ptr(object_list[i])->
line_thickness / 2.0;
max_position[dim] += get_lines_ptr(object_list[i])->
line_thickness / 2.0;
}
}
}
print( "Bounding_box: %g %g %g %g %g %g\n",
min_position[0], max_position[0],
min_position[1], max_position[1],
min_position[2], max_position[2] );
delete_object_list( n_objects, object_list );
return( 0 );
}