atomes 1.1.14
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
d_label.c
Go to the documentation of this file.
1/* This file is part of the 'atomes' software
2
3'atomes' is free software: you can redistribute it and/or modify it under the terms
4of the GNU Affero General Public License as published by the Free Software Foundation,
5either version 3 of the License, or (at your option) any later version.
6
7'atomes' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9See the GNU General Public License for more details.
10
11You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12If not, see <https://www.gnu.org/licenses/>
13
14Copyright (C) 2022-2024 by CNRS and University of Strasbourg */
15
22/*
23* This file: 'd_label.c'
24*
25* Contains:
26*
27
28 - The functions to prepare the OpenGL rendering of the atomic label(s)
29
30*
31* List of functions:
32
33 int create_label_lists ();
34
35 void prepare_label (atom at, int id, double al);
36 void clean_labels (int id);
37
38 mat4_t create_label_matrices ();
39
40*/
41
42#include "global.h"
43#include "glview.h"
44#include "interface.h"
45#include "dlp_field.h"
46
47extern ColRGBA init_color (int id, int numid);
48extern ColRGBA get_atom_color (int i, int j, double al, int picked, gboolean to_pick);
49extern float get_sphere_radius (int style, int sp, int ac, int sel);
50
57{
58 return m4_ortho (0.0, wingl -> view_port.y, 0.0, wingl -> view_port.z, 1.0, 0.0);
59}
60
70void prepare_label (atom at, int id, double al)
71{
72 int k, l;
73 char * str = NULL;
74 char * tmp = NULL;
75 float shift[3];
76 ColRGBA lcol;
77
78 k = at.sp;
79 double rad = get_sphere_radius ((at.style == NONE) ? plot -> style : at.style, k, id, (at.pick[0] || at.pick[1]));
80 for (l=0; l<3; l++) shift[l] = plot -> labels_shift[id][l];
81 shift[2] += rad;
82
83 if (field_color && (field_object < 7 || field_object > 14))
84 {
85 lcol = init_color (at.coord[4], num_field_objects);
86 lcol.alpha = al*0.75;
87 }
88 else if (plot -> labels_color[id] == NULL)
89 {
90 lcol = get_atom_color (k+id*proj_sp, at.id, al, 0, FALSE);
91 }
92 else
93 {
94 lcol = plot -> labels_color[id][k];
95 lcol.alpha = al;
96 }
97 switch (plot -> labels_format[id])
98 {
99 case ELEMENT_NAME:
100 str = g_strdup_printf ("%s", exact_name(proj_gl -> chemistry -> element[k]));
101 break;
102 case SYMBOL:
103 str = g_strdup_printf ("%s", exact_name(proj_gl -> chemistry -> label[k]));
104 break;
105 case SYMBOL_AND_NUM:
106 str = g_strdup_printf ("%s%d", exact_name(proj_gl -> chemistry -> label[k]), at.id+1);
107 break;
108 case NUM:
109 str = g_strdup_printf ("%d", at.id+1);
110 break;
111 case ID_IN_MOLECULE:
112 if (field_object == 0)
113 {
114 str = g_strdup_printf ("%s%d", exact_name(proj_gl -> chemistry -> label[k]), at.id+1);
115 }
116 else
117 {
118 str = g_strdup_printf ("%s%d", exact_name(proj_gl -> chemistry -> label[k]), at.coord[4]+1);
119 }
120 break;
121 default:
122 str = g_strdup_printf ("%s%d", exact_name(proj_gl -> chemistry -> label[k]), at.id+1);
123 break;
124 }
125 if (id)
126 {
127 tmp = g_strdup_printf ("%s*", str);
128 g_free (str);
129 str = g_strdup_printf ("%s", tmp);
130 g_free (tmp);
131 }
132 prepare_string (str, id, lcol, vec3(at.x, at.y, at.z), shift, NULL, NULL, NULL);
133 g_free (str);
134}
135
143void clean_labels (int id)
144{
145 if (plot -> labels_list[id] != NULL)
146 {
147 g_free (plot -> labels_list[id]);
148 plot -> labels_list[id] = NULL;
149 }
150}
151
158{
159 int nshaders = 0;
160 int i, j, k;
161 float x, y, z;
162 atom ato;
163
164#ifdef DEBUG
165 g_debug ("Label LIST");
166#endif
168 wingl -> create_shaders[LABEL] = FALSE;
169 clean_labels (0);
170 clean_labels (1);
171
172 if (in_movie_encoding && plot -> at_data != NULL)
173 {
174 for (i=0; i<proj_at; i++)
175 {
176 if (plot -> at_data[i].show[0] && plot -> at_data[i].label[0])
177 {
178 prepare_label (proj_gl -> atoms[step][i], 0, 1.0);
179 }
180 }
181 if (plot -> draw_clones)
182 {
183 for (i=0; i < wingl -> bonds[step][1]; i++)
184 {
185 x = wingl -> clones[step][i].x;
186 y = wingl -> clones[step][i].y;
187 z = wingl -> clones[step][i].z;
188 j = wingl -> bondid[step][1][i][0];
189 k = wingl -> bondid[step][1][i][1];
190 ato.x = proj_gl -> atoms[step][j].x - x;
191 ato.y = proj_gl -> atoms[step][j].y - y;
192 ato.z = proj_gl -> atoms[step][j].z - z;
193 ato.sp = proj_gl -> atoms[step][j].sp;
194 ato.id = k;
195 ato.pick[0] = plot -> at_data[k].pick[0];
196 ato.pick[1] = plot -> at_data[k].pick[1];
197 ato.style = plot -> at_data[k].style;
198 if (plot -> at_data[k].show[1] && plot -> at_data[k].label[1]) prepare_label (ato, 1, 0.75);
199 ato.x = proj_gl -> atoms[step][k].x + x;
200 ato.y = proj_gl -> atoms[step][k].y + y;
201 ato.z = proj_gl -> atoms[step][k].z + z;
202 ato.sp = proj_gl -> atoms[step][k].sp;
203 ato.id = j;
204 ato.pick[0] = plot -> at_data[j].pick[0];
205 ato.pick[1] = plot -> at_data[j].pick[1];
206 ato.style = plot -> at_data[j].style;
207 if (plot -> at_data[j].show[1] && plot -> at_data[j].label[1]) prepare_label (ato, 1, 0.75);
208 }
209 }
210 }
211 else
212 {
213 for (i=0; i<proj_at; i++)
214 {
215 if (proj_gl -> atoms[step][i].show[0] && proj_gl -> atoms[step][i].label[0])
216 {
217 prepare_label (proj_gl -> atoms[step][i], 0, 1.0);
218 }
219 }
220 if (plot -> draw_clones)
221 {
222 for (i=0; i < wingl -> bonds[step][1]; i++)
223 {
224 x = wingl -> clones[step][i].x;
225 y = wingl -> clones[step][i].y;
226 z = wingl -> clones[step][i].z;
227 j = wingl -> bondid[step][1][i][0];
228 k = wingl -> bondid[step][1][i][1];
229 ato.x = proj_gl -> atoms[step][j].x - x;
230 ato.y = proj_gl -> atoms[step][j].y - y;
231 ato.z = proj_gl -> atoms[step][j].z - z;
232 ato.sp = proj_gl -> atoms[step][k].sp;
233 ato.id = k;
234 ato.pick[0] = proj_gl -> atoms[step][k].pick[0];
235 ato.pick[1] = proj_gl -> atoms[step][k].pick[1];
236 ato.style = proj_gl -> atoms[step][k].style;
237 if (proj_gl -> atoms[step][k].show[1] && proj_gl -> atoms[step][k].label[1]) prepare_label (ato, 1, 0.75);
238 ato.x = proj_gl -> atoms[step][k].x + x;
239 ato.y = proj_gl -> atoms[step][k].y + y;
240 ato.z = proj_gl -> atoms[step][k].z + z;
241 ato.sp = proj_gl -> atoms[step][j].sp;
242 ato.id = j;
243 ato.pick[0] = proj_gl -> atoms[step][j].pick[0];
244 ato.pick[1] = proj_gl -> atoms[step][j].pick[1];
245 ato.style = proj_gl -> atoms[step][j].style;
246 if (proj_gl -> atoms[step][j].show[1] && proj_gl -> atoms[step][j].label[1]) prepare_label (ato, 1, 0.75);
247 }
248 }
249 }
250
251 if (plot -> labels_list[0] != NULL || plot -> labels_list[1] != NULL)
252 {
253 nshaders = 0;
254 if (plot -> labels_list[0] != NULL) nshaders += (plot -> labels_render[0] + 1) * (plot -> labels_list[0] -> last -> id + 1);
255 if (plot -> draw_clones && plot -> labels_list[1] != NULL)
256 {
257 nshaders += (plot -> labels_render[1] + 1) * (plot -> labels_list[1] -> last -> id + 1);
258 }
259 wingl -> ogl_glsl[LABEL][0] = g_malloc0 (nshaders*sizeof*wingl -> ogl_glsl[LABEL][0]);
260 for (i=0; i<2; i++) render_all_strings (LABEL, i);
261 }
262 return nshaders;
263}
integer(kind=c_int) function chemistry()
Definition chemistry.F90:22
void label(cairo_t *cr, double val, int axe, int p, project *this_proj)
draw axis label
Definition labels.c:56
void clean_labels(int id)
clean atomic label shaders
Definition d_label.c:143
void prepare_label(atom at, int id, double al)
prepare an atomic label OpenGL rendering
Definition d_label.c:70
ColRGBA init_color(int id, int numid)
initialize color based id number over total number of elements
Definition initcoord.c:81
float get_sphere_radius(int style, int sp, int ac, int sel)
get an atom sphere radius
Definition d_atoms.c:281
int create_label_lists()
prepare atomic label(s) OpenGL rendering
Definition d_label.c:157
mat4_t create_label_matrices()
create label projection matrices
Definition d_label.c:56
ColRGBA get_atom_color(int i, int j, double al, int picked, gboolean to_pick)
get atom (or clone) color
Definition d_atoms.c:74
int * shift
Definition d_measures.c:72
int atoms[NUM_STYLES][2]
int bonds[NUM_STYLES][2]
GtkTreeSelection * sel
Definition datab.c:102
int field_object
Definition dlp_field.c:979
int num_field_objects
Definition dlp_field.c:981
gboolean field_color
Definition dlp_field.c:980
Variable declarations for the creation of the DL_POLY input file(s)
gboolean in_movie_encoding
Definition global.c:180
Global variable declarations Global convenience function declarations Global data structure defin...
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
image * plot
Definition ogl_draw.c:66
project * proj_gl
Definition ogl_draw.c:60
glwin * wingl
Definition ogl_draw.c:59
int proj_sp
Definition ogl_draw.c:61
void cleaning_shaders(glwin *view, int shader)
re-initialize an OpenGL shader
int step
Definition ogl_draw.c:70
@ ELEMENT_NAME
Definition glview.h:215
@ NUM
Definition glview.h:218
@ SYMBOL_AND_NUM
Definition glview.h:217
@ ID_IN_MOLECULE
Definition glview.h:219
@ SYMBOL
Definition glview.h:216
int proj_at
Definition ogl_draw.c:62
@ NONE
Definition glview.h:172
@ LABEL
Definition glwin.h:98
gchar * exact_name(gchar *name)
short cut to print string without spaces
Definition interface.c:370
Messaging function declarations.
double z
Definition ogl_draw.c:57
double y
Definition ogl_draw.c:57
double x
Definition ogl_draw.c:57
void prepare_string(char *text, int id, ColRGBA col, vec3_t pos, float lshift[3], atom *at, atom *bt, atom *ct)
prepare a screen string to be rendered
Definition ogl_text.c:691
void render_all_strings(int glsl, int id)
render all string to be rendered for a label list
Definition ogl_text.c:549
float alpha
Definition global.h:119
Definition global.h:839
int sp
Definition global.h:841
int coord[5]
Definition global.h:853
int id
Definition global.h:840
int style
Definition global.h:879
gboolean pick[2]
Definition global.h:877
double z
Definition global.h:845
double y
Definition global.h:844
double x
Definition global.h:843
int style
Definition glwin.h:427
gchar * al[3]
Definition w_axis.c:67
int element
Definition w_periodic.c:61