1 /* EXTRAITS DE LA LICENCE
2 Copyright CEA, contributeurs : Damien
3 CALISTE, laboratoire L_Sim, (2016)
4
5 Adresse mèl :
6 BILLARD, non joignable par mèl ;
7 CALISTE, damien P caliste AT cea P fr.
8
9 Ce logiciel est un programme informatique servant à visualiser des
10 structures atomiques dans un rendu pseudo-3D.
11
12 Ce logiciel est régi par la licence CeCILL soumise au droit français et
13 respectant les principes de diffusion des logiciels libres. Vous pouvez
14 utiliser, modifier et/ou redistribuer ce programme sous les conditions
15 de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
16 sur le site "http://www.cecill.info".
17
18 Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
19 pris connaissance de la licence CeCILL, et que vous en avez accepté les
20 termes (cf. le fichier Documentation/licence.fr.txt fourni avec ce logiciel).
21 */
22
23 /* LICENCE SUM UP
24 Copyright CEA, contributors : Damien
25 CALISTE, laboratoire L_Sim, (2016)
26
27 E-mail address:
28 BILLARD, not reachable any more ;
29 CALISTE, damien P caliste AT cea P fr.
30
31 This software is a computer program whose purpose is to visualize atomic
32 configurations in 3D.
33
34 This software is governed by the CeCILL license under French law and
35 abiding by the rules of distribution of free software. You can use,
36 modify and/ or redistribute the software under the terms of the CeCILL
37 license as circulated by CEA, CNRS and INRIA at the following URL
38 "http://www.cecill.info".
39
40 The fact that you are presently reading this means that you have had
41 knowledge of the CeCILL license and that you accept its terms. You can
42 find a copy of this licence shipped with this software at Documentation/licence.en.txt.
43 */
44
45 #include "wire_renderer.h"
46 #include "iface_wire.h"
47 #include <coreTools/toolShade.h>
48
49 #include <math.h>
50 #include <GL/gl.h>
51
52 /**
53 * SECTION:wire_renderer
54 * @short_description: a class to render #VisuPairLink as wires.
55 *
56 * <para>This class is used to render #VisuPairLink as wires.</para>
57 */
58
59 static void _start(VisuPairLinkRenderer *self, VisuPairLink *data,
60 VisuElementRenderer *ele1, VisuElementRenderer *ele2,
61 VisuDataColorizer *colorizer);
62 static void _stop(VisuPairLinkRenderer *self, VisuPairLink *data);
63 static void _draw(VisuPairLinkRenderer *self, const VisuPairLinkIter *iter);
64
G_DEFINE_TYPE(VisuPairWireRenderer,visu_pair_wire_renderer,VISU_TYPE_PAIR_LINK_RENDERER)65 G_DEFINE_TYPE(VisuPairWireRenderer, visu_pair_wire_renderer, VISU_TYPE_PAIR_LINK_RENDERER)
66
67 static void visu_pair_wire_renderer_class_init(VisuPairWireRendererClass *klass)
68 {
69 DBG_fprintf(stderr, "Visu Wire Renderer: creating the class of the object.\n");
70
71 /* Connect the overloading methods. */
72 VISU_PAIR_LINK_RENDERER_CLASS(klass)->start = _start;
73 VISU_PAIR_LINK_RENDERER_CLASS(klass)->stop = _stop;
74 VISU_PAIR_LINK_RENDERER_CLASS(klass)->draw = _draw;
75 }
visu_pair_wire_renderer_init(VisuPairWireRenderer * obj _U_)76 static void visu_pair_wire_renderer_init(VisuPairWireRenderer *obj _U_)
77 {
78 DBG_fprintf(stderr, "Visu Wire Renderer: initializing a new object (%p).\n",
79 (gpointer)obj);
80 }
81 /**
82 * visu_pair_wire_renderer_new:
83 *
84 * Creates a renderer to draw links as wires.
85 *
86 * Since: 3.8
87 *
88 * Returns: (transfer full): a newly created #VisuPairWireRenderer object.
89 */
visu_pair_wire_renderer_new()90 VisuPairWireRenderer* visu_pair_wire_renderer_new()
91 {
92 return VISU_PAIR_WIRE_RENDERER(g_object_new(VISU_TYPE_PAIR_WIRE_RENDERER,
93 "id", "Wire pairs",
94 "label", _("Wire pairs"),
95 "description", _("Pairs are rendered by flat lines."
96 " The color and the width can by chosen."), NULL));
97 }
98
_start(VisuPairLinkRenderer * self _U_,VisuPairLink * data,VisuElementRenderer * ele1 _U_,VisuElementRenderer * ele2 _U_,VisuDataColorizer * colorizer _U_)99 static void _start(VisuPairLinkRenderer *self _U_, VisuPairLink *data,
100 VisuElementRenderer *ele1 _U_, VisuElementRenderer *ele2 _U_,
101 VisuDataColorizer *colorizer _U_)
102 {
103 ToolColor *color;
104 guint16 stipple;
105
106 glLineWidth(visu_pair_wire_getWidth(VISU_PAIR_WIRE(data)));
107 color = visu_pair_link_getColor(data);
108 glColor3fv(color->rgba);
109 stipple = visu_pair_wire_getStipple(VISU_PAIR_WIRE(data));
110 if (stipple != 65535)
111 {
112 glEnable(GL_LINE_STIPPLE);
113 glLineStipple(1, stipple);
114 }
115 glDisable(GL_LIGHTING);
116 glDisable(GL_DITHER);
117 }
118
_stop(VisuPairLinkRenderer * self _U_,VisuPairLink * data _U_)119 static void _stop(VisuPairLinkRenderer *self _U_, VisuPairLink *data _U_)
120 {
121 glDisable(GL_LINE_STIPPLE);
122 glEnable(GL_DITHER); /* WARNING: it is the default! */
123 glEnable(GL_LIGHTING);
124 }
125
_draw(VisuPairLinkRenderer * self _U_,const VisuPairLinkIter * iter)126 static void _draw(VisuPairLinkRenderer *self _U_, const VisuPairLinkIter *iter)
127 {
128 float ratio;
129 ToolColor *color;
130 float rgba[4], mM[2];
131 ToolShade *shade;
132
133 color = visu_pair_link_getColor(iter->parent);
134 shade = visu_pair_wire_getShade(VISU_PAIR_WIRE(iter->parent));
135 if (shade)
136 {
137 mM[0] = visu_pair_link_getDistance(iter->parent, VISU_DISTANCE_MIN);
138 mM[1] = visu_pair_link_getDistance(iter->parent, VISU_DISTANCE_MAX);
139 ratio = (sqrt(iter->d2) - mM[0]) / (mM[1] - mM[0]);
140 tool_shade_valueToRGB(shade, rgba, ratio);
141 rgba[3] = iter->coeff * color->rgba[3];
142 glColor4fv(rgba);
143 }
144 else
145 glColor4f(color->rgba[0], color->rgba[1], color->rgba[2], iter->coeff * color->rgba[3]);
146
147 glBegin(GL_LINES);
148 glVertex3fv(iter->xyz1);
149 if (iter->periodic)
150 glVertex3f(iter->xyz1[0] + iter->dxyz[0] / 2.f,
151 iter->xyz1[1] + iter->dxyz[1] / 2.f,
152 iter->xyz1[2] + iter->dxyz[2] / 2.f);
153 else
154 glVertex3fv(iter->xyz2);
155 glEnd();
156
157 if (iter->periodic)
158 {
159 glBegin(GL_LINES);
160 glVertex3fv(iter->xyz2);
161 glVertex3f(iter->xyz2[0] - iter->dxyz[0] / 2.f,
162 iter->xyz2[1] - iter->dxyz[1] / 2.f,
163 iter->xyz2[2] - iter->dxyz[2] / 2.f);
164 glEnd();
165 }
166 }
167