Debian Codegraph @

imagery/i.ortho.photo/i.ortho.init/main.c

raw symbols SCIP
1 /****************************************************************************
2 *
3 * MODULE: i.ortho.init (former i.photo.init)
4 * AUTHOR(S): Mike Baba, DBA Systems, Inc. (original contributor)
5 * Markus Neteler <neteler itc.it>,
6 * Roberto Flor <flor itc.it>,
7 * Bernhard Reiter <bernhard intevation.de>,
8 * Glynn Clements <glynn gclements.plus.com>
9 * Hamish Bowman
10 *
11 * PURPOSE: Creates or modifies entries in a camera initial exposure
12 * station file for imagery group referenced by a sub-block
13 * COPYRIGHT: (C) 1999-2008 by the GRASS Development Team
14 *
15 * This program is free software under the GNU General Public
16 * License (>=v2). Read the file COPYING that comes with GRASS
17 * for details.
18 *
19 *****************************************************************************/
20
21 #include <stdlib.h>
22 #include <string.h>
23 #include <stdio.h>
24 #include <grass/gis.h>
25 #include <grass/glocale.h>
26 #include "orthophoto.h"
27
28 int main(int argc, char *argv[])
29 {
30 struct GModule *module;
31 struct Option *group_opt, *xc_opt, *yc_opt, *zc_opt, *xcsd_opt, *ycsd_opt,
32 *zcsd_opt, *omega_opt, *phi_opt, *kappa_opt, *omegasd_opt, *phisd_opt,
33 *kappasd_opt;
34 struct Flag *use_flag, *print_flag;
35
36 struct Ortho_Image_Group group;
37 struct Ortho_Camera_Exp_Init *init_info;
38 double deg2rad, rad2deg;
39
40 G_gisinit(argv[0]);
41
42 module = G_define_module();
43 G_add_keyword(_("imagery"));
44 G_add_keyword(_("orthorectify"));
45 module->description =
46 _("Interactively creates or modifies entries in a camera "
47 "initial exposure station file for imagery group referenced "
48 "by a sub-block.");
49
50 group_opt = G_define_standard_option(G_OPT_I_GROUP);
51 group_opt->required = YES;
52 group_opt->description = _("Name of imagery group for ortho-rectification");
53
54 xc_opt = G_define_option();
55 xc_opt->key = "xc";
56 xc_opt->type = TYPE_DOUBLE;
57 xc_opt->description = _("Initial Camera Exposure X-coordinate");
58
59 yc_opt = G_define_option();
60 yc_opt->key = "yc";
61 yc_opt->type = TYPE_DOUBLE;
62 yc_opt->description = _("Initial Camera Exposure Y-coordinate");
63
64 zc_opt = G_define_option();
65 zc_opt->key = "zc";
66 zc_opt->type = TYPE_DOUBLE;
67 zc_opt->description = _("Initial Camera Exposure Z-coordinate");
68
69 xcsd_opt = G_define_option();
70 xcsd_opt->key = "xc_sd";
71 xcsd_opt->type = TYPE_DOUBLE;
72 xcsd_opt->description = _("Apriori X-coordinate standard deviation");
73
74 ycsd_opt = G_define_option();
75 ycsd_opt->key = "yc_sd";
76 ycsd_opt->type = TYPE_DOUBLE;
77 ycsd_opt->description = _("Apriori Y-coordinate standard deviation");
78
79 zcsd_opt = G_define_option();
80 zcsd_opt->key = "zc_sd";
81 zcsd_opt->type = TYPE_DOUBLE;
82 zcsd_opt->description = _("Apriori Z-coordinate standard deviation");
83
84 omega_opt = G_define_option();
85 omega_opt->key = "omega";
86 omega_opt->type = TYPE_DOUBLE;
87 omega_opt->description = _("Initial Camera Omega (pitch) degrees");
88
89 phi_opt = G_define_option();
90 phi_opt->key = "phi";
91 phi_opt->type = TYPE_DOUBLE;
92 phi_opt->description = _("Initial Camera Phi (roll) degrees");
93
94 kappa_opt = G_define_option();
95 kappa_opt->key = "kappa";
96 kappa_opt->type = TYPE_DOUBLE;
97 kappa_opt->description = _("Initial Camera Kappa (yaw) degrees");
98
99 omegasd_opt = G_define_option();
100 omegasd_opt->key = "omega_sd";
101 omegasd_opt->type = TYPE_DOUBLE;
102 omegasd_opt->description = _("Apriori Omega (pitch) standard deviation");
103
104 phisd_opt = G_define_option();
105 phisd_opt->key = "phi_sd";
106 phisd_opt->type = TYPE_DOUBLE;
107 phisd_opt->description = _("Apriori Phi (roll) standard deviation");
108
109 kappasd_opt = G_define_option();
110 kappasd_opt->key = "kappa_sd";
111 kappasd_opt->type = TYPE_DOUBLE;
112 kappasd_opt->description = _("Apriori Kappa (yaw) standard deviation");
113
114 use_flag = G_define_flag();
115 use_flag->key = 'r';
116 use_flag->description = _("Use initial values at run time");
117
118 print_flag = G_define_flag();
119 print_flag->key = 'p';
120 print_flag->description = _("Print initial values");
121
122 if (G_parser(argc, argv))
123 exit(EXIT_FAILURE);
124
125 deg2rad = M_PI / 180.;
126 rad2deg = 180. / M_PI;
127
128 /* get group ref */
129 strcpy(group.name, group_opt->answer);
130
131 if (!I_find_group(group.name)) {
132 G_fatal_error(_("Group [%s] not found"), group.name);
133 }
134 G_debug(1, "Found group %s", group.name);
135
136 /* get initial camera exposure info */
137 if (I_find_initial(group.name)) {
138 I_get_init_info(group.name, &group.camera_exp);
139 }
140 else {
141 /* create new initial camera exposure info */
142
143 /* all values must be given */
144 if (!xc_opt->answer) {
145 G_fatal_error(_("Option '%s' is required for new exposure info"),
146 xc_opt->key);
147 }
148 if (!yc_opt->answer) {
149 G_fatal_error(_("Option '%s' is required for new exposure info"),
150 yc_opt->key);
151 }
152 if (!zc_opt->answer) {
153 G_fatal_error(_("Option '%s' is required for new exposure info"),
154 zc_opt->key);
155 }
156 if (!xcsd_opt->answer) {
157 G_fatal_error(_("Option '%s' is required for new exposure info"),
158 xcsd_opt->key);
159 }
160 if (!ycsd_opt->answer) {
161 G_fatal_error(_("Option '%s' is required for new exposure info"),
162 ycsd_opt->key);
163 }
164 if (!zcsd_opt->answer) {
165 G_fatal_error(_("Option '%s' is required for new exposure info"),
166 zcsd_opt->key);
167 }
168 if (!omega_opt->answer) {
169 G_fatal_error(_("Option '%s' is required for new exposure info"),
170 omega_opt->key);
171 }
172 if (!phi_opt->answer) {
173 G_fatal_error(_("Option '%s' is required for new exposure info"),
174 phi_opt->key);
175 }
176 if (!kappa_opt->answer) {
177 G_fatal_error(_("Option '%s' is required for new exposure info"),
178 kappa_opt->key);
179 }
180 if (!omegasd_opt->answer) {
181 G_fatal_error(_("Option '%s' is required for new exposure info"),
182 omegasd_opt->key);
183 }
184 if (!phisd_opt->answer) {
185 G_fatal_error(_("Option '%s' is required for new exposure info"),
186 phisd_opt->key);
187 }
188 if (!kappasd_opt->answer) {
189 G_fatal_error(_("Option '%s' is required for new exposure info"),
190 kappasd_opt->key);
191 }
192 }
193
194 /* modify info */
195 init_info = &group.camera_exp;
196
197 if (xc_opt->answer) {
198 init_info->XC_init = atof(xc_opt->answer);
199 }
200 if (yc_opt->answer) {
201 init_info->YC_init = atof(yc_opt->answer);
202 }
203 if (zc_opt->answer) {
204 init_info->ZC_init = atof(zc_opt->answer);
205 }
206 if (xcsd_opt->answer) {
207 init_info->XC_var = atof(xcsd_opt->answer);
208 }
209 if (ycsd_opt->answer) {
210 init_info->YC_var = atof(ycsd_opt->answer);
211 }
212 if (zcsd_opt->answer) {
213 init_info->ZC_var = atof(zcsd_opt->answer);
214 }
215 if (omega_opt->answer) {
216 init_info->omega_init = atof(omega_opt->answer) * deg2rad;
217 }
218 if (phi_opt->answer) {
219 init_info->phi_init = atof(phi_opt->answer) * deg2rad;
220 }
221 if (kappa_opt->answer) {
222 init_info->kappa_init = atof(kappa_opt->answer) * deg2rad;
223 }
224 if (omegasd_opt->answer) {
225 init_info->omega_var = atof(omegasd_opt->answer) * deg2rad;
226 }
227 if (phisd_opt->answer) {
228 init_info->phi_var = atof(phisd_opt->answer) * deg2rad;
229 }
230 if (kappasd_opt->answer) {
231 init_info->kappa_var = atof(kappasd_opt->answer) * deg2rad;
232 }
233 init_info->status = use_flag->answer != 0;
234
235 if (print_flag->answer) {
236 /* do not translate, scripts might want to parse the output */
237 fprintf(stdout, "xc=%.17g\n", init_info->XC_init);
238 fprintf(stdout, "yc=%.17g\n", init_info->YC_init);
239 fprintf(stdout, "zc=%.17g\n", init_info->ZC_init);
240 fprintf(stdout, "xc_sd=%.17g\n", init_info->XC_var);
241 fprintf(stdout, "yc_sd=%.17g\n", init_info->YC_var);
242 fprintf(stdout, "zc_sd=%.17g\n", init_info->ZC_var);
243
244 fprintf(stdout, "omega=%.17g\n", init_info->omega_init * rad2deg);
245 fprintf(stdout, "phi=%.17g\n", init_info->phi_init * rad2deg);
246 fprintf(stdout, "kappa=%.17g\n", init_info->kappa_init * rad2deg);
247 fprintf(stdout, "omega_sd=%.17g\n", init_info->omega_var * rad2deg);
248 fprintf(stdout, "phi_sd=%.17g\n", init_info->phi_var * rad2deg);
249 fprintf(stdout, "kappa_sd=%.17g\n", init_info->kappa_var * rad2deg);
250
251 fprintf(stdout, "use=%d", init_info->status);
252 }
253
254 /* save info */
255 I_put_init_info(group.name, &group.camera_exp);
256
257 exit(EXIT_SUCCESS);
258 }