2 * Copyright (C) 2008 Liam Girdwood
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330,
17 * Boston, MA 02111-1307, USA.
26 struct ngc_pixmap_cache
{
27 cairo_t
*cr
[NGC_TYPES
][RENDER_MAG_BANDS
];
28 cairo_surface_t
*surface
[NGC_TYPES
][RENDER_MAG_BANDS
];
29 gint offset
[NGC_TYPES
][RENDER_MAG_BANDS
];
30 gdouble object_size
[NGC_TYPES
][RENDER_MAG_BANDS
];
32 struct ngc_render_size
{
37 static struct ngc_pixmap_cache cache
;
39 const gchar
*ngc_type
[NGC_TYPES
][2] = {
41 { " OC", "Open star cluster"},
42 { " Gb", "Globular star cluster, usually in the Milky Way Galaxy"},
43 { " Nb", "Bright emission or reflection nebula"},
44 { " Pl", "Planetary nebula"},
45 { "C+N", "Cluster associated with nebulosity"},
46 { "Ast", "Asterism or group of a few stars"},
47 { " Kt", "Knot or nebulous region in an external galaxy"},
48 { "***", "Triple star"},
49 { " D*", "Double star"},
50 { " *", "Single star"},
51 { " ?", "Uncertain type or may not exist"},
52 { " ", "Unidentified at the place given, or type unknown"},
53 { " -", "Object called nonexistent in the RNGC (Sulentic and Tifft 1973)"},
54 { " PD", "Photographic plate defect"},
57 static struct astrodb_schema_object ngc_fields
[] = {
59 astrodb_member("Name", "Name", struct ngc_object
, dobject
.aobject
.name
,
60 CT_STRING
, "", 0, NULL
),
61 astrodb_member("Type", "Type", struct ngc_object
, dobject
.aobject
.id
,
62 CT_STRING
, "", 0, NULL
),
63 astrodb_member("RA", "RA", struct ngc_object
, dobject
.posn
.ra
,
64 CT_DOUBLE
, "degrees", 0, NULL
),
65 astrodb_member("DEC", "DEC", struct ngc_object
, dobject
.posn
.dec
,
66 CT_DOUBLE
, "degrees", 0, NULL
),
67 astrodb_gmember("RA Hours", "RAh", struct ngc_object
, dobject
.posn
.ra
,
68 CT_DOUBLE_HMS_HRS
, "hours", 2, NULL
),
69 astrodb_gmember("RA Minutes", "RAm", struct ngc_object
, dobject
.posn
.ra
,
70 CT_DOUBLE_HMS_MINS
, "minutes", 1, NULL
),
71 astrodb_gmember("RA Seconds", "RAs", struct ngc_object
, dobject
.posn
.ra
,
72 CT_DOUBLE_HMS_SECS
, "seconds", 0, NULL
),
73 astrodb_gmember("DEC Degrees", "DEd", struct ngc_object
, dobject
.posn
.dec
,
74 CT_DOUBLE_DMS_DEGS
, "degrees", 3, NULL
),
75 astrodb_gmember("DEC Minutes", "DEm", struct ngc_object
, dobject
.posn
.dec
,
76 CT_DOUBLE_DMS_MINS
, "minutes", 2, NULL
),
77 astrodb_gmember("DEC Seconds", "DEs", struct ngc_object
, dobject
.posn
.dec
,
78 CT_DOUBLE_DMS_SECS
, "seconds", 1, NULL
),
79 astrodb_gmember("DEC sign", "DE-", struct ngc_object
, dobject
.posn
.dec
,
80 CT_SIGN
, "", 0, NULL
),
81 astrodb_member("Visual Mag", "mag", struct ngc_object
, dobject
.Vmag
,
82 CT_FLOAT
, "", 0, NULL
),
84 astrodb_member("Size", "size", struct ngc_object
, axis
,
85 CT_FLOAT
, "", 0, NULL
),
89 void ngc_object_render(struct render_object
*robject
)
91 struct ngc_object
*object
= (struct ngc_object
*)robject
->object
;
92 // guint i = object->type;
96 (robject
->context
.faintest_magnitude
- object
->dobject
.Vmag
)
99 if (size
>= RENDER_MAG_BANDS
)
100 size
= RENDER_MAG_BANDS
- 1;
106 robject
->coord
[0].object_size
= cache
.object_size
[i
][size
];
108 cairo_set_source_surface(robject
->cr
, cache
.surface
[i
][size
],
109 robject
->coord
[0].x
- cache
.offset
[i
][size
],
110 robject
->coord
[0].y
- cache
.offset
[i
][size
]);
111 cairo_paint(robject
->cr
);
115 static gint
render_pixmap(gint spi
, gint mag
)
118 gint size
= ngc_sizes
[mag
].size
;
119 gint surface_size
= size
+ 3;
120 gdouble radius
= (gdouble
)size
/ 2.0;
121 gdouble centre
= ((gdouble
)size
/ 2.0) + 1.5;
123 cache
.surface
[spi
][mag
] =
124 cairo_image_surface_create(CAIRO_FORMAT_ARGB32
, surface_size
,
127 if (cache
.surface
[spi
][mag
] == NULL
)
130 cache
.cr
[spi
][mag
] = cairo_create(cache
.surface
[spi
][mag
]);
131 if (cache
.cr
[spi
][mag
] == NULL
)
134 cache
.offset
[spi
][mag
] = centre
;
135 cache
.object_size
[spi
][mag
] = radius
* 2.0;
137 /* render_object transparent background */
138 cairo_set_source_rgba(cache
.cr
[spi
][mag
], 0.0, 0.0, 0.0, 0.0);
139 cairo_rectangle(cache
.cr
[spi
][mag
], 0, 0, surface_size
, surface_size
);
140 cairo_fill (cache
.cr
[spi
][mag
]);
143 cairo_set_source_rgba(cache
.cr
[spi
][mag
], 0.0, 0.0, 0.0, 1.0);
144 cairo_arc (cache
.cr
[spi
][mag
], centre
, centre
,
145 radius
* 1.1, 0, 2 * M_PI
);
146 cairo_fill (cache
.cr
[spi
][mag
]);
149 cairo_set_source_rgba(cache
.cr
[spi
][mag
],
150 sp
[spi
].r
, sp
[spi
].g
, sp
[spi
].b
,
151 ngc_sizes
[mag
].alpha
);
152 cairo_arc(cache
.cr
[spi
][mag
], centre
, centre
, radius
, 0, 2 * M_PI
);
153 cairo_fill(cache
.cr
[spi
][mag
]);
158 static gint
render_cache(struct astrodb_table
*table
)
162 for (spi
= 0; spi
< NGC_TYPES
; spi
++) {
163 for (mag
= 0; mag
< RENDER_MAG_BANDS
; mag
++) {
164 ret
= render_pixmap(spi
, mag
);
172 void ngc_object_free(struct astrodb_table
*table
)
176 for (spi
= 0; spi
< NGC_TYPES
; spi
++) {
177 for (mag
= 0; mag
< RENDER_MAG_BANDS
; mag
++) {
178 cairo_destroy(cache
.cr
[spi
][mag
]);
183 gint
ngc_object_init(struct astrodb_table
*table
)
185 if (astrodb_table_register_schema(table
, ngc_fields
,
186 astrodb_size(ngc_fields
),
187 sizeof(struct ngc_object
)) < 0)
188 g_critical("%s: failed to register object type\n", __func__
);
190 /* We want to quickly search the dataset based on object name */
191 if (astrodb_table_hash_key(table
, "Name"))
192 g_warning("%s: failed to hash on Name\n", __func__
);
194 if (astrodb_table_open(table
, 90, 45, 20) < 0)
195 g_critical("%s: table init failed\n", __func__
);
197 /* create pixmap cache for fast rendering */
198 if (render_cache(table
) < 0)
199 g_critical("%s: failed to render cache\n", __func__
);