atomes 1.2.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-2025 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 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 NUM:
110 str = g_strdup_printf ("%d", at.id+1);
111 break;
112 case ID_IN_MOLECULE:
113 if (field_object == 0)
114 {
115 str = g_strdup_printf ("%s%d", exact_name(proj_gl -> chemistry -> label[k]), at.id+1);
116 }
117 else
118 {
119 str = g_strdup_printf ("%s%d", exact_name(proj_gl -> chemistry -> label[k]), at.coord[4]+1);
120 }
121 break;
122 default:
123 str = g_strdup_printf ("%s%d", exact_name(proj_gl -> chemistry -> label[k]), at.id+1);
124 break;
125 }
126 if (id)
127 {
128 tmp = g_strdup_printf ("%s*", str);
129 g_free (str);
130 str = g_strdup_printf ("%s", tmp);
131 g_free (tmp);
132 }
133 prepare_string (str, id, lcol, vec3(at.x, at.y, at.z), shift, NULL, NULL, NULL);
134 g_free (str);
135}
136
144void clean_labels (int id)
145{
146 if (plot -> labels[id].list != NULL)
147 {
148 g_free (plot -> labels[id].list);
149 plot -> labels[id].list = NULL;
150 }
151}
152
159{
160 int nshaders = 0;
161 int i, j, k;
162 float x, y, z;
163 atom ato;
164
165#ifdef DEBUG
166 g_debug ("Label LIST");
167#endif
169 wingl -> create_shaders[LABEL] = FALSE;
170 clean_labels (0);
171 clean_labels (1);
172
173 if (in_movie_encoding && plot -> at_data != NULL)
174 {
175 for (i=0; i<proj_at; i++)
176 {
177 if (plot -> at_data[i].show[0] && plot -> at_data[i].label[0])
178 {
179 prepare_label (proj_gl -> atoms[step][i], 0, 1.0);
180 }
181 }
182 if (plot -> draw_clones)
183 {
184 for (i=0; i < wingl -> bonds[step][1]; i++)
185 {
186 x = wingl -> clones[step][i].x;
187 y = wingl -> clones[step][i].y;
188 z = wingl -> clones[step][i].z;
189 j = wingl -> bondid[step][1][i][0];
190 k = wingl -> bondid[step][1][i][1];
191 ato.x = proj_gl -> atoms[step][j].x - x;
192 ato.y = proj_gl -> atoms[step][j].y - y;
193 ato.z = proj_gl -> atoms[step][j].z - z;
194 ato.sp = proj_gl -> atoms[step][j].sp;
195 ato.id = k;
196 ato.pick[0] = plot -> at_data[k].pick[0];
197 ato.pick[1] = plot -> at_data[k].pick[1];
198 ato.style = plot -> at_data[k].style;
199 if (plot -> at_data[k].show[1] && plot -> at_data[k].label[1]) prepare_label (ato, 1, 0.75);
200 ato.x = proj_gl -> atoms[step][k].x + x;
201 ato.y = proj_gl -> atoms[step][k].y + y;
202 ato.z = proj_gl -> atoms[step][k].z + z;
203 ato.sp = proj_gl -> atoms[step][k].sp;
204 ato.id = j;
205 ato.pick[0] = plot -> at_data[j].pick[0];
206 ato.pick[1] = plot -> at_data[j].pick[1];
207 ato.style = plot -> at_data[j].style;
208 if (plot -> at_data[j].show[1] && plot -> at_data[j].label[1]) prepare_label (ato, 1, 0.75);
209 }
210 }
211 }
212 else
213 {
214 for (i=0; i<proj_at; i++)
215 {
216 if (proj_gl -> atoms[step][i].show[0] && proj_gl -> atoms[step][i].label[0])
217 {
218 prepare_label (proj_gl -> atoms[step][i], 0, 1.0);
219 }
220 }
221 if (plot -> draw_clones)
222 {
223 for (i=0; i < wingl -> bonds[step][1]; i++)
224 {
225 x = wingl -> clones[step][i].x;
226 y = wingl -> clones[step][i].y;
227 z = wingl -> clones[step][i].z;
228 j = wingl -> bondid[step][1][i][0];
229 k = wingl -> bondid[step][1][i][1];
230 ato.x = proj_gl -> atoms[step][j].x - x;
231 ato.y = proj_gl -> atoms[step][j].y - y;
232 ato.z = proj_gl -> atoms[step][j].z - z;
233 ato.sp = proj_gl -> atoms[step][k].sp;
234 ato.id = k;
235 ato.pick[0] = proj_gl -> atoms[step][k].pick[0];
236 ato.pick[1] = proj_gl -> atoms[step][k].pick[1];
237 ato.style = proj_gl -> atoms[step][k].style;
238 if (proj_gl -> atoms[step][k].show[1] && proj_gl -> atoms[step][k].label[1]) prepare_label (ato, 1, 0.75);
239 ato.x = proj_gl -> atoms[step][k].x + x;
240 ato.y = proj_gl -> atoms[step][k].y + y;
241 ato.z = proj_gl -> atoms[step][k].z + z;
242 ato.sp = proj_gl -> atoms[step][j].sp;
243 ato.id = j;
244 ato.pick[0] = proj_gl -> atoms[step][j].pick[0];
245 ato.pick[1] = proj_gl -> atoms[step][j].pick[1];
246 ato.style = proj_gl -> atoms[step][j].style;
247 if (proj_gl -> atoms[step][j].show[1] && proj_gl -> atoms[step][j].label[1]) prepare_label (ato, 1, 0.75);
248 }
249 }
250 }
251
252 if (plot -> labels[0].list != NULL || plot -> labels[1].list != NULL)
253 {
254 nshaders = 0;
255 if (plot -> labels[0].list != NULL) nshaders += (plot -> labels[0].render + 1) * (plot -> labels[0].list -> last -> id + 1);
256 if (plot -> draw_clones && plot -> labels[1].list != NULL)
257 {
258 nshaders += (plot -> labels[1].render + 1) * (plot -> labels[1].list -> last -> id + 1);
259 }
260 wingl -> ogl_glsl[LABEL][0] = g_malloc0 (nshaders*sizeof*wingl -> ogl_glsl[LABEL][0]);
261 for (i=0; i<2; i++) render_all_strings (LABEL, i);
262 }
263 return nshaders;
264}
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:144
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:270
int create_label_lists()
prepare atomic label(s) OpenGL rendering
Definition d_label.c:158
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: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:70
project * proj_gl
Definition ogl_draw.c:64
glwin * wingl
Definition ogl_draw.c:63
int proj_sp
Definition ogl_draw.c:65
void cleaning_shaders(glwin *view, int shader)
re-initialize an OpenGL shader
int step
Definition ogl_draw.c:74
labels
Definition glview.h:223
@ ELEMENT_NAME
Definition glview.h:224
@ NUM
Definition glview.h:227
@ SYMBOL_AND_NUM
Definition glview.h:226
@ ID_IN_MOLECULE
Definition glview.h:228
@ SYMBOL
Definition glview.h:225
int proj_at
Definition ogl_draw.c:66
@ 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:370
Messaging function declarations.
double z
Definition ogl_draw.c:61
double y
Definition ogl_draw.c:61
double x
Definition ogl_draw.c:61
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:127
Definition global.h:891
int sp
Definition global.h:893
int coord[5]
Definition global.h:905
int id
Definition global.h:892
int style
Definition global.h:931
gboolean pick[2]
Definition global.h:929
double z
Definition global.h:897
double y
Definition global.h:896
double x
Definition global.h:895
GLint render
Definition glwin.h:478
int style
Definition glwin.h:465
gchar * al[3]
Definition w_axis.c:73
int element
Definition w_periodic.c:61