24 #include <cairo-pdf.h> 61 #define PRINT_USAGE(rc) \ 62 fprintf(stderr, "Usage: %s [ -f format ] [ -s xscale yscale ] " \ 63 "GEOMETRY_TABLE OUTPUT_PLOT\n", argv[0]); \ 64 cpl_end(); return (rc); 66 int main(
int argc,
char **argv)
68 cpl_init(CPL_INIT_DEFAULT);
83 unsigned char oformat = PLOT_FORMAT_PDF;
87 for (i = 1; i < argc; i++) {
88 if (strncmp(argv[i],
"-f", 3) == 0) {
92 if (!strncmp(argv[i],
"pdf", 4)) {
93 oformat = PLOT_FORMAT_PDF;
94 }
else if (!strncmp(argv[i],
"png", 4)) {
95 oformat = PLOT_FORMAT_PNG;
102 }
else if (strncmp(argv[i],
"-s", 3) == 0) {
103 if (++i + 1 < argc) {
104 xscale = atof(argv[i++]);
105 yscale = atof(argv[i]);
106 if (xscale <= 0 || yscale <= 0) {
112 }
else if (strncmp(argv[i],
"-", 1) == 0) {
115 if (tiname && oname) {
129 cpl_table *table = cpl_table_load(tiname, 1, 1);
134 if (!cpl_table_has_column(table, MUSE_GEOTABLE_X) ||
135 !cpl_table_has_column(table, MUSE_GEOTABLE_Y) ||
136 !cpl_table_has_column(table, MUSE_GEOTABLE_WIDTH) ||
137 !cpl_table_has_column(table, MUSE_GEOTABLE_ANGLE)) {
138 cpl_table_delete(table);
143 double wmax = cpl_table_get_column_max(table, MUSE_GEOTABLE_WIDTH),
144 xmin = cpl_table_get_column_min(table, MUSE_GEOTABLE_X) - wmax / 2.,
145 ymin = cpl_table_get_column_min(table, MUSE_GEOTABLE_Y) - 2,
146 xmax = cpl_table_get_column_max(table, MUSE_GEOTABLE_X) + wmax / 2.,
147 ymax = cpl_table_get_column_max(table, MUSE_GEOTABLE_Y) + 2,
148 sx = xmax - xmin + 1,
149 sy = ymax - ymin + 1;
150 printf(
"Using scaling of %.3f in x- and %.3f in y-direction\n", xscale, yscale);
153 printf(
"Translating coordinates by %.3f in x- and %.3f in y-direction\n " 154 "(extrema: %f / %f ... %f / %f)\n", xt, yt, xmin, ymin, xmax, ymax);
157 cairo_status_t rc = CAIRO_STATUS_SUCCESS;
159 if (oformat == PLOT_FORMAT_PDF) {
160 cs = cairo_pdf_surface_create(oname, xscale * sx, yscale * sy);
161 rc = cairo_surface_status(cs);
162 if (rc != CAIRO_STATUS_SUCCESS) {
163 fprintf(stderr,
"opening PDF (\"%s\") returned %d!\n", oname, rc);
166 fprintf(stdout,
"writing PDF to \"%s\"\n", oname);
169 cs = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
170 xscale * sx, yscale * sy);
172 cairo_t *cr = cairo_create(cs);
174 cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
177 cairo_scale(cr, xscale, -yscale);
178 cairo_translate(cr, xt, yt);
180 cairo_matrix_t *cm = cpl_calloc(1,
sizeof(cairo_matrix_t));
181 cairo_get_matrix(cr, cm);
182 cairo_status_t cstat = cairo_status(cr);
183 fprintf(stderr,
"cm = %p, cstat = %d/%s, size is %f,%f\n",
184 cm, cstat, cairo_status_to_string(cstat), xscale * sx, yscale * sy);
185 double xtt = xmin, ytt = ymin + 2;
186 cairo_matrix_transform_point(cm, &xtt, &ytt);
187 fprintf(stderr,
"%f,%f is transformed to %f,%f\n", xmin, ymin + 2, xtt, ytt);
188 xtt = xmin, ytt = ymax - 2;
189 cairo_matrix_transform_point(cm, &xtt, &ytt);
190 fprintf(stderr,
"%f,%f is transformed to %f,%f\n", xmin, ymax - 2, xtt, ytt);
191 xtt = xmax, ytt = ymin + 2;
192 cairo_matrix_transform_point(cm, &xtt, &ytt);
193 fprintf(stderr,
"%f,%f is transformed to %f,%f\n", xmax, ymin + 2, xtt, ytt);
194 xtt = xmax, ytt = ymax - 2;
195 cairo_matrix_transform_point(cm, &xtt, &ytt);
196 fprintf(stderr,
"%f,%f is transformed to %f,%f\n", xmax, ymax - 2, xtt, ytt);
201 cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
203 cairo_move_to(cr, -1000., 0.);
204 cairo_rel_line_to(cr, +5000, 0.);
205 cairo_scale(cr, 1., 1. / yscale);
209 cairo_move_to(cr, 0., -1000);
210 cairo_rel_line_to(cr, 0., +5000);
211 cairo_scale(cr, 1. / xscale, 1.);
216 cairo_scale(cr, 1. / xscale, 1. / yscale);
217 cairo_set_source_rgb(cr, 0.0, 0.0, 0.9);
218 cairo_arc(cr, 0, 0, 5., 0, CPL_MATH_2PI);
224 int n = cpl_table_get_nrow(table);
225 for (i = 0; i < n; i++) {
226 double x = cpl_table_get(table, MUSE_GEOTABLE_X, i, NULL),
227 y = cpl_table_get(table, MUSE_GEOTABLE_Y, i, NULL),
228 width = cpl_table_get(table, MUSE_GEOTABLE_WIDTH, i, NULL),
229 angrad = cpl_table_get(table, MUSE_GEOTABLE_ANGLE, i, NULL)
231 unsigned short ifu = cpl_table_get_int(table, MUSE_GEOTABLE_FIELD, i, NULL);
232 if ((ifu - 0) % 3 == 0) {
233 cairo_set_source_rgba(cr, 0.2, 0.2, 0.4, 0.5);
234 }
else if ((ifu - 1) % 3 == 0) {
235 cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.5);
236 }
else if ((ifu - 2) % 3 == 0) {
237 cairo_set_source_rgba(cr, 1.0, 0.843, 0.0, 0.5);
239 cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.5);
242 printf(
"ifu %hu slicesky %hu angle %f\n",
243 ifu, cpl_table_get_int(table, MUSE_GEOTABLE_SKY, i, NULL),
244 angrad * CPL_MATH_DEG_RAD);
248 cairo_translate(cr, x, y);
249 cairo_rotate(cr, angrad);
250 cairo_rectangle(cr, -width / 2., -0.5, width, 1.);
256 cairo_set_source_rgba(cr, 0.0, 0.0, 0.9, 0.8);
257 cairo_move_to(cr, - width / 2., - 0.5);
258 cairo_set_line_width(cr, 1. / yscale);
259 cairo_rel_line_to(cr, width, 0.);
260 cairo_set_line_width(cr, 1. / xscale);
261 cairo_rel_line_to(cr, 0., 1.);
262 cairo_set_line_width(cr, 1. / yscale);
263 cairo_rel_line_to(cr, -width, 0.);
264 cairo_close_path(cr);
270 if (oformat == PLOT_FORMAT_PNG) {
271 cairo_surface_write_to_png(cs, oname);
272 if (rc != CAIRO_STATUS_SUCCESS) {
273 fprintf(stderr,
"writing PNG (\"%s\") returned %d!\n", oname, rc);
276 fprintf(stdout,
"written PNG to \"%s\"\n", oname);
280 cairo_surface_destroy(cs);
281 cairo_debug_reset_static_data();
282 cpl_table_delete(table);
283 cpl_errorstate_dump(0,0,0);
void muse_processing_recipeinfo(cpl_plugin *)
Output main pipeline configuration, inputs, and parameters.