atomes 1.3.1
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-2026 by CNRS and University of Strasbourg */
15
21
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 if (at.style == CYLINDERS || (plot -> style == CYLINDERS && at.style == NONE)) rad += (at.pick[0] || at.pick[1]) ? 0.9 : 1.0;
81 for (l=0; l<3; l++) shift[l] = plot -> labels[id].shift[l];
82 shift[2] += rad;
83
85 {
86 lcol = init_color (at.coord[4], num_field_objects);
87 lcol.alpha = al*0.75;
88 }
89 else if (plot -> labels[id].color == NULL)
90 {
91 lcol = get_atom_color (k+id*proj_sp, at.id, al, 0, FALSE);
92 }
93 else
94 {
95 lcol = (plot -> labels[id].n_colors) ? plot -> labels[id].color[0] : plot -> labels[id].color[k];
96 lcol.alpha = al;
97 }
98 switch (plot -> acl_format[id])
99 {
100 case ELEMENT_NAME:
101 str = g_strdup_printf ("%s", exact_name(proj_gl -> chemistry -> element[k]));
102 break;
103 case SYMBOL:
104 str = g_strdup_printf ("%s", exact_name(proj_gl -> chemistry -> label[k]));
105 break;
106 case SYMBOL_AND_NUM:
107 str = g_strdup_printf ("%s%d", exact_name(proj_gl -> chemistry -> label[k]), at.id+1);
108 break;
109 case SYMBOL_AND_IND:
110 str = g_strdup_printf ("%s<sub>%d</sub>", exact_name(proj_gl -> chemistry -> label[k]), at.id+1);
111 break;
112 case NUM:
113 str = g_strdup_printf ("%d", at.id+1);
114 break;
115 case ID_IN_MOLECULE:
116 if (field_object == 0)
117 {
118 str = g_strdup_printf ("%s%d", exact_name(proj_gl -> chemistry -> label[k]), at.id+1);
119 }
120 else
121 {
122 str = g_strdup_printf ("%s%d", exact_name(proj_gl -> chemistry -> label[k]), at.coord[4]+1);
123 }
124 break;
125 default:
126 str = g_strdup_printf ("%s%d", exact_name(proj_gl -> chemistry -> label[k]), at.id+1);
127 break;
128 }
129 if (id)
130 {
131 tmp = g_strdup_printf ("%s*", str);
132 g_free (str);
133 str = g_strdup_printf ("%s", tmp);
134 g_free (tmp);
135 }
136 prepare_string (str, id, lcol, vec3(at.x, at.y, at.z), shift, NULL, NULL, NULL);
137 g_free (str);
138}
139
147void clean_labels (int id)
148{
149 if (plot -> labels[id].list != NULL)
150 {
151 g_free (plot -> labels[id].list);
152 plot -> labels[id].list = NULL;
153 }
154}
155
162{
163 int nshaders = 0;
164 int i, j, k;
165 float x, y, z;
166 atom ato;
167
168#ifdef DEBUG
169 g_debug ("Label LIST");
170#endif
172 wingl -> create_shaders[LABEL] = FALSE;
173 clean_labels (0);
174 clean_labels (1);
175
176 if (in_movie_encoding && plot -> at_data != NULL)
177 {
178 for (i=0; i<proj_at; i++)
179 {
180 if (plot -> at_data[i].show[0] && plot -> at_data[i].label[0])
181 {
182 prepare_label (proj_gl -> atoms[step][i], 0, 1.0);
183 }
184 }
185 if (plot -> draw_clones)
186 {
187 for (i=0; i < wingl -> bonds[step][1]; i++)
188 {
189 x = wingl -> clones[step][i].x;
190 y = wingl -> clones[step][i].y;
191 z = wingl -> clones[step][i].z;
192 j = wingl -> bondid[step][1][i][0];
193 k = wingl -> bondid[step][1][i][1];
194 ato.x = proj_gl -> atoms[step][j].x - x;
195 ato.y = proj_gl -> atoms[step][j].y - y;
196 ato.z = proj_gl -> atoms[step][j].z - z;
197 ato.sp = proj_gl -> atoms[step][j].sp;
198 ato.id = k;
199 ato.pick[0] = plot -> at_data[k].pick[0];
200 ato.pick[1] = plot -> at_data[k].pick[1];
201 ato.style = plot -> at_data[k].style;
202 if (plot -> at_data[k].show[1] && plot -> at_data[k].label[1]) prepare_label (ato, 1, 0.75);
203 ato.x = proj_gl -> atoms[step][k].x + x;
204 ato.y = proj_gl -> atoms[step][k].y + y;
205 ato.z = proj_gl -> atoms[step][k].z + z;
206 ato.sp = proj_gl -> atoms[step][k].sp;
207 ato.id = j;
208 ato.pick[0] = plot -> at_data[j].pick[0];
209 ato.pick[1] = plot -> at_data[j].pick[1];
210 ato.style = plot -> at_data[j].style;
211 if (plot -> at_data[j].show[1] && plot -> at_data[j].label[1]) prepare_label (ato, 1, 0.75);
212 }
213 }
214 }
215 else
216 {
217 for (i=0; i<proj_at; i++)
218 {
219 if (proj_gl -> atoms[step][i].show[0] && proj_gl -> atoms[step][i].label[0])
220 {
221 prepare_label (proj_gl -> atoms[step][i], 0, 1.0);
222 }
223 }
224 if (plot -> draw_clones)
225 {
226 for (i=0; i < wingl -> bonds[step][1]; i++)
227 {
228 x = wingl -> clones[step][i].x;
229 y = wingl -> clones[step][i].y;
230 z = wingl -> clones[step][i].z;
231 j = wingl -> bondid[step][1][i][0];
232 k = wingl -> bondid[step][1][i][1];
233 ato.x = proj_gl -> atoms[step][j].x - x;
234 ato.y = proj_gl -> atoms[step][j].y - y;
235 ato.z = proj_gl -> atoms[step][j].z - z;
236 ato.sp = proj_gl -> atoms[step][k].sp;
237 ato.id = k;
238 ato.pick[0] = proj_gl -> atoms[step][k].pick[0];
239 ato.pick[1] = proj_gl -> atoms[step][k].pick[1];
240 ato.style = proj_gl -> atoms[step][k].style;
241 if (proj_gl -> atoms[step][k].show[1] && proj_gl -> atoms[step][k].label[1]) prepare_label (ato, 1, 0.75);
242 ato.x = proj_gl -> atoms[step][k].x + x;
243 ato.y = proj_gl -> atoms[step][k].y + y;
244 ato.z = proj_gl -> atoms[step][k].z + z;
245 ato.sp = proj_gl -> atoms[step][j].sp;
246 ato.id = j;
247 ato.pick[0] = proj_gl -> atoms[step][j].pick[0];
248 ato.pick[1] = proj_gl -> atoms[step][j].pick[1];
249 ato.style = proj_gl -> atoms[step][j].style;
250 if (proj_gl -> atoms[step][j].show[1] && proj_gl -> atoms[step][j].label[1]) prepare_label (ato, 1, 0.75);
251 }
252 }
253 }
254
255 if (plot -> labels[0].list != NULL || plot -> labels[1].list != NULL)
256 {
257 nshaders = 0;
258 if (plot -> labels[0].list != NULL) nshaders += (plot -> labels[0].render + 1) * (plot -> labels[0].list -> last -> id + 1);
259 if (plot -> draw_clones && plot -> labels[1].list != NULL)
260 {
261 nshaders += (plot -> labels[1].render + 1) * (plot -> labels[1].list -> last -> id + 1);
262 }
263 wingl -> ogl_glsl[LABEL][0] = g_malloc0(nshaders*sizeof*wingl -> ogl_glsl[LABEL][0]);
264 for (i=0; i<2; i++) render_all_strings (LABEL, i);
265 }
266 return nshaders;
267}
integer(kind=c_int) function chemistry()
Definition chemistry.F90:22
void clean_labels(int id)
clean atomic label shaders
Definition d_label.c:147
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:305
int create_label_lists()
prepare atomic label(s) OpenGL rendering
Definition d_label.c:161
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:75
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:1069
int num_field_objects
Definition dlp_field.c:1071
gboolean field_color
Definition dlp_field.c:1070
Variable declarations for the creation of the DL_POLY input file(s).
gboolean in_movie_encoding
Definition global.c:184
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:72
project * proj_gl
Definition ogl_draw.c:66
glwin * wingl
Definition ogl_draw.c:65
int proj_sp
Definition ogl_draw.c:67
void cleaning_shaders(glwin *view, int shader)
re-initialize an OpenGL shader
int step
Definition ogl_draw.c:76
labels
Definition glview.h:223
@ ELEMENT_NAME
Definition glview.h:224
@ NUM
Definition glview.h:228
@ SYMBOL_AND_NUM
Definition glview.h:226
@ SYMBOL_AND_IND
Definition glview.h:227
@ ID_IN_MOLECULE
Definition glview.h:229
@ SYMBOL
Definition glview.h:225
int proj_at
Definition ogl_draw.c:68
@ CYLINDERS
Definition glview.h:186
@ NONE
Definition glview.h:181
@ LABEL
Definition glwin.h:98
gchar * exact_name(gchar *name)
short cut to print string without spaces
Definition interface.c:434
Messaging function declarations.
double z
Definition ogl_draw.c:63
double y
Definition ogl_draw.c:63
double x
Definition ogl_draw.c:63
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:694
void render_all_strings(int glsl, int id)
render all string to be rendered for a label list
Definition ogl_text.c:552
float alpha
Definition global.h:139
Definition global.h:964
int sp
Definition global.h:966
int coord[5]
Definition global.h:978
int id
Definition global.h:965
int style
Definition global.h:1004
gboolean pick[2]
Definition global.h:1002
double z
Definition global.h:970
double y
Definition global.h:969
double x
Definition global.h:968
int element
Definition w_periodic.c:61