forked from Dwayne-Phillips/CIPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iso2.c
executable file
·198 lines (156 loc) · 4.94 KB
/
iso2.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*********************************************
*
* file iso2.c
*
* Functions: This file contains
* main
* lineup
*
* Purpose:
* This program performs an isometric
* transform on a 3D image.
*
* External Calls:
* imageio.c
* create_resized_image_file
* read_image_array
* write_image_array
* get_image_size
* allocate_image_array
* free_image_array
*
* Modifications:
* 24 May 1999 - created
*
***********************************************/
#include "cips.h"
#define FILL 200
#define FILL2 150
#define MOREROWS 100
#define DEGREESPERRADIAN 57.29577952
int does_not_exist();
int create_image_file();
int get_image_size();
int read_image_array();
int free_image_array();
int write_image_array();
int create_resized_image_file();
int lineup();
short **the_image;
short **out_image;
int main(argc, argv)
int argc;
char *argv[];
{
char in_name[MAX_NAME_LENGTH],
out_name[MAX_NAME_LENGTH];
double tantheta, cosa, cosb, sina, sinb;
float scale;
int alpha, beta, col0,
i, ii, j, jj,
row0, space, value;
long length1, length2, width1, width2;
short height, max;
/* Check the command line and obtain
the parameters. */
if(argc != 7){
printf(
"\n\nusage: iso2 in-file out-file "
"alpha beta space value"
"\n alpha is angle down from horizontal"
"\n beta is angle up from horizontal"
"\n space is spacing to draw lines on output"
"\n value = 0 use black dots on top of image"
"\n value = 1 use actual image values\n");
exit(0);
}
strcpy(in_name, argv[1]);
strcpy(out_name, argv[2]);
alpha = atoi(argv[3]);
beta = atoi(argv[4]);
space = atoi(argv[5]);
value = atoi(argv[6]);
/* check input file */
if(does_not_exist(in_name)){
printf("\nERROR input file %s does not exist",
in_name);
exit(0);
} /* ends if does_not_exist */
/* calculate the sin and cosine of the angles
one time */
sina = sin((double)(alpha)/DEGREESPERRADIAN);
cosa = cos((double)(alpha)/DEGREESPERRADIAN);
sinb = sin((double)(beta)/DEGREESPERRADIAN);
cosb = cos((double)(beta)/DEGREESPERRADIAN);
/* get size of input file and calculate size
of output file. output file will depend
on the angle theta */
get_image_size(in_name, &length1, &width1);
length2 = (double)(width1)*sinb +
(double)(length1)*sina +
MOREROWS + MOREROWS;
width2 = (double)(width1)*cosb +
(double)(length1)*cosa;
row0 = MOREROWS/2 +
MOREROWS +
(double)(width1)*sinb;
col0 = 0;
create_resized_image_file(in_name, out_name,
length2, width2);
/* allocate the image arrays */
the_image = allocate_image_array(length1, width1);
out_image = allocate_image_array(length2, width2);
/* fill the output image with FILL */
for(i=0; i<length2; i++)
for(j=0; j<width2; j++)
out_image[i][j] = FILL;
read_image_array(in_name, the_image);
/* Scale the height of the output image */
max = 0;
for(i=0; i<length1; i++){
for(j=0; j<width1; j++){
if(the_image[i][j] > max)
max = the_image[i][j];
} /* ends loop over j */
} /* ends loop over i */
if(max > MOREROWS)
scale = (float)(max)/(float)(MOREROWS);
else
scale = max;
if(scale < 1.0)
scale = 1.0;
/* Loop through the input image and place
the pixels in the output image. */
for(i=0; i<length1; i++){
for(j=0; j<width1; j++){
if(i%space == 0){
ii = row0 +
(double)(i)*sina -
(double)(j)*sinb;
jj = col0 +
(double)(i)*cosa +
(double)(j)*cosb;
out_image[ii][jj] = the_image[i][j];
height = the_image[i][j]/scale;
lineup(out_image, ii, ii-height, jj);
if(value == 0)
out_image[ii-height][jj] = 0;
else
out_image[ii-height][jj] =
the_image[i][j];
} /* ends if j mod space */
} /* ends loop over j */
} /* ends loop over i */
write_image_array(out_name, out_image);
free_image_array(the_image, length1);
free_image_array(out_image, length2);
} /* ends main */
int lineup(image, start_row, end_row, column)
int start_row, end_row, column;
short **image;
{
int i;
for(i=start_row; i>end_row; i--)
image[i][column] = FILL2;
return(1);
} /* ends lineup */