static void plot_constellations(cairo_t* cairo, plot_args_t* pargs, plotann_t* ann) { int i, N; double ra,dec,radius; double xyzf[3]; // Find the field center and radius anwcs_get_radec_center_and_radius(pargs->wcs, &ra, &dec, &radius); logverb("Plotting constellations: field center %g,%g, radius %g\n", ra, dec, radius); radecdeg2xyzarr(ra, dec, xyzf); radius = deg2dist(radius); N = constellations_n(); for (i=0; i<N; i++) { int j, k; // Find the approximate center and radius of this constellation // and see if it overlaps with the field. il* stars = constellations_get_unique_stars(i); double xyzj[3]; double xyzc[3]; double maxr2 = 0; dl* rds; xyzc[0] = xyzc[1] = xyzc[2] = 0.0; xyzj[0] = xyzj[1] = xyzj[2] = 0.0; for (j=0; j<il_size(stars); j++) { constellations_get_star_radec(il_get(stars, j), &ra, &dec); radecdeg2xyzarr(ra, dec, xyzj); for (k=0; k<3; k++) xyzc[k] += xyzj[k]; } normalize_3(xyzc); for (j=0; j<il_size(stars); j++) { constellations_get_star_radec(il_get(stars, j), &ra, &dec); maxr2 = MAX(maxr2, distsq(xyzc, xyzj, 3)); } il_free(stars); maxr2 = square(sqrt(maxr2) + radius); if (distsq(xyzf, xyzc, 3) > maxr2) { xyzarr2radecdeg(xyzc, &ra, &dec); logverb("Constellation %s (center %g,%g, radius %g) out of bounds\n", constellations_get_shortname(i), ra, dec, dist2deg(sqrt(maxr2) - radius)); logverb(" dist from field center to constellation center is %g deg\n", distsq2deg(distsq(xyzf, xyzc, 3))); logverb(" max radius: %g\n", distsq2deg(maxr2)); continue; } if (ann->constellation_pastel) { float r,g,b; xyzarr2radecdeg(xyzc, &ra, &dec); color_for_radec(ra, dec, &r,&g,&b); plotstuff_set_rgba2(pargs, r,g,b, 0.8); plotstuff_builtin_apply(cairo, pargs); } // Phew, plot it. if (ann->constellation_lines) { rds = constellations_get_lines_radec(i); logverb("Constellation %s: plotting %zu lines\n", constellations_get_shortname(i), dl_size(rds)/4); for (j=0; j<dl_size(rds)/4; j++) { double r1,d1,r2,d2; double r3,d3,r4,d4; double off = ann->constellation_lines_offset; r1 = dl_get(rds, j*4+0); d1 = dl_get(rds, j*4+1); r2 = dl_get(rds, j*4+2); d2 = dl_get(rds, j*4+3); if (anwcs_find_discontinuity(pargs->wcs, r1, d1, r2, d2, &r3, &d3, &r4, &d4)) { logverb("Discontinuous: %g,%g -- %g,%g\n", r1, d1, r2, d2); logverb(" %g,%g == %g,%g\n", r3,d3, r4,d4); plot_offset_line_rd(NULL, pargs, r1,d1,r3,d3, off, 0.); plot_offset_line_rd(NULL, pargs, r4,d4,r2,d2, 0., off); } else { plot_offset_line_rd(NULL, pargs, r1,d1,r2,d2, off, off); } plotstuff_stroke(pargs); } dl_free(rds); } if (ann->constellation_labels || ann->constellation_markers) { // Put the label at the center of mass of the stars that // are in-bounds int Nin = 0; stars = constellations_get_unique_stars(i); xyzc[0] = xyzc[1] = xyzc[2] = 0.0; logverb("Labeling %s: %zu stars\n", constellations_get_shortname(i), il_size(stars)); for (j=0; j<il_size(stars); j++) { constellations_get_star_radec(il_get(stars, j), &ra, &dec); if (!anwcs_radec_is_inside_image(pargs->wcs, ra, dec)) continue; if (ann->constellation_markers) plotstuff_marker_radec(pargs, ra, dec); radecdeg2xyzarr(ra, dec, xyzj); for (k=0; k<3; k++) xyzc[k] += xyzj[k]; Nin++; } logverb(" %i stars in-bounds\n", Nin); if (ann->constellation_labels && Nin) { const char* label; normalize_3(xyzc); xyzarr2radecdeg(xyzc, &ra, &dec); if (ann->constellation_labels_long) label = constellations_get_longname(i); else label = constellations_get_shortname(i); plotstuff_text_radec(pargs, ra, dec, label); } il_free(stars); } } }
static int plot_builtin_command(const char* cmd, const char* cmdargs, plot_args_t* pargs, void* baton) { if (streq(cmd, "plot_color")) { if (parse_color_rgba(cmdargs, pargs->rgba)) { ERROR("Failed to parse plot_color: \"%s\"", cmdargs); return -1; } } else if (streq(cmd, "plot_bgcolor")) { if (parse_color_rgba(cmdargs, pargs->bg_rgba)) { ERROR("Failed to parse plot_bgcolor: \"%s\"", cmdargs); return -1; } } else if (streq(cmd, "plot_fontsize")) { pargs->fontsize = atof(cmdargs); } else if (streq(cmd, "plot_alpha")) { if (plotstuff_set_alpha(pargs, atof(cmdargs))) { ERROR("Failed to set alpha"); return -1; } } else if (streq(cmd, "plot_op")) { if (streq(cmdargs, "add")) { pargs->op = CAIRO_OPERATOR_ADD; } else if (streq(cmdargs, "reset")) { pargs->op = CAIRO_OPERATOR_OVER; } else { ERROR("Didn't understand op: %s", cmdargs); return -1; } } else if (streq(cmd, "plot_lw")) { pargs->lw = atof(cmdargs); } else if (streq(cmd, "plot_bglw")) { pargs->bg_lw = atof(cmdargs); } else if (streq(cmd, "plot_marker")) { if (plotstuff_set_marker(pargs, cmdargs)) { return -1; } } else if (streq(cmd, "plot_markersize")) { pargs->markersize = atof(cmdargs); } else if (streq(cmd, "plot_size")) { int W, H; if (sscanf(cmdargs, "%i %i", &W, &H) != 2) { ERROR("Failed to parse plot_size args \"%s\"", cmdargs); return -1; } plotstuff_set_size(pargs, W, H); } else if (streq(cmd, "plot_wcs")) { if (plotstuff_set_wcs_file(pargs, cmdargs, 0)) { return -1; } } else if (streq(cmd, "plot_wcs_box")) { float ra, dec, width; if (sscanf(cmdargs, "%f %f %f", &ra, &dec, &width) != 3) { ERROR("Failed to parse plot_wcs_box args \"%s\"", cmdargs); return -1; } if (plotstuff_set_wcs_box(pargs, ra, dec, width)) { return -1; } } else if (streq(cmd, "plot_wcs_setsize")) { assert(pargs->wcs); plotstuff_set_size_wcs(pargs); } else if (streq(cmd, "plot_label_radec")) { assert(pargs->wcs); double ra, dec; int nc; const char* label; if (sscanf(cmdargs, "%lf %lf %n", &ra, &dec, &nc) != 3) { ERROR("Failed to parse plot_label_radec args \"%s\"", cmdargs); return -1; } label = cmdargs + nc; return plotstuff_text_radec(pargs, ra, dec, label); } else { ERROR("Did not understand command: \"%s\"", cmd); return -1; } if (pargs->cairo) plotstuff_builtin_apply(pargs->cairo, pargs); return 0; }