1
/* Copyright (C) 2000 Damir Zucic */
3
/*=============================================================================
8
Draw atoms, using style 5 (7x7 circle).
11
(1) Pointer to MolComplexS structure.
12
(2) Number of macromolecular complexes.
13
(3) Pointer to ConfigS structure, with configuration data.
14
(4) Pointer to GUIS structure.
15
(5) Pointer to NearestAtomS structure, with information about the
16
atom occupying the given pixel.
17
(6) The number of pixels in the main window free area.
18
(7) The refreshI, used to check the NearestAtomS associated with
22
(1) Atoms drawn to the hidden pixmap.
26
(1) The number of atoms drawn.
29
(1) Indentation is exceptionally 4 spaces.
31
(2) The second index of indexAA and circle_maskAA is treated as
32
row index. This is somewhat unusual, but more practical in
35
=============================================================================*/
40
#include <X11/Xutil.h>
42
#include <X11/Xatom.h>
47
/*======draw atoms using style 5 (7x7 circle):===============================*/
49
size_t DrawAtomsStyle5_ (MolComplexS *mol_complexSP, int mol_complexesN,
50
ConfigS *configSP, GUIS *guiSP,
51
NearestAtomS *nearest_atomSP, size_t pixelsN,
52
unsigned int refreshI)
54
size_t atoms_drawnN = 0;
56
int left_edge[2], right_edge[2];
58
MolComplexS *curr_mol_complexSP;
61
unsigned long colorIDA[3];
62
static int indexAA[7][7] = {{0, 0, 1, 1, 2, 0, 0},
63
{0, 0, 0, 0, 1, 2, 0},
64
{1, 0, 0, 0, 1, 2, 2},
65
/* Be sure to read Note 2 ! */ {1, 0, 0, 1, 1, 2, 2},
66
{2, 1, 1, 1, 2, 2, 2},
67
{0, 2, 2, 2, 2, 2, 0},
68
{0, 0, 2, 2, 2, 0, 0}};
70
int screen_x0, screen_y0;
71
int i, j, screen_x, screen_y;
72
static int circle_maskAA[7][7] = {{0, 0, 1, 1, 1, 0, 0},
73
{0, 1, 1, 1, 1, 1, 0},
74
{1, 1, 1, 1, 1, 1, 1},
75
/* Be sure to read Note 2 ! */ {1, 1, 1, 1, 1, 1, 1},
76
{1, 1, 1, 1, 1, 1, 1},
77
{0, 1, 1, 1, 1, 1, 0},
78
{0, 0, 1, 1, 1, 0, 0}};
80
NearestAtomS *curr_pixelSP;
82
double half_atomic_radius;
83
int levelAA[7][7] = {{0, 0, 0, 0, 0, 0, 0},
84
{0, 0, 1, 1, 1, 0, 0},
85
{0, 1, 2, 2, 2, 1, 0},
86
{0, 1, 2, 2, 2, 1, 0},
87
{0, 1, 2, 2, 2, 1, 0},
88
{0, 0, 1, 1, 1, 0, 0},
89
{0, 0, 0, 0, 0, 0, 0}};
91
/* Number of images: */
92
if (configSP->stereoF) imagesN = 2;
95
/* Left and right image edge (in stereo mode there are two images): */
96
left_edge[0] = configSP->image_screen_x0[0];
97
right_edge[0] = configSP->image_screen_x1[0];
98
left_edge[1] = configSP->image_screen_x0[1];
99
right_edge[1] = configSP->image_screen_x1[1];
102
half_atomic_radius = 2.5 * configSP->screen_to_atomic_scale_x;
104
/* Draw each macromolecular complex: */
105
for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++)
107
/* Pointer to current macromolecular complex: */
108
curr_mol_complexSP = mol_complexSP + mol_complexI;
110
/* Prepare and check the number of atoms: */
111
atomsN = curr_mol_complexSP->atomsN;
112
if (atomsN == 0) continue;
114
/* Draw atoms which have the given style: */
115
for (atomI = 0; atomI < atomsN; atomI++)
117
/* Pointer to the current atom: */
118
curr_atomSP = curr_mol_complexSP->atomSP + atomI;
121
if (curr_atomSP->raw_atomS.atom_styleI != 5) continue;
123
/* Check is atom hidden: */
124
if (curr_atomSP->hiddenF) continue;
126
/* Check is atom inside slab: */
127
if (!curr_atomSP->inside_slabF) continue;
129
/* Check is atom inside window: */
130
if (!curr_atomSP->inside_windowF) continue;
132
/* Prepare colors: */
133
colorIDA[0] = curr_atomSP->left_colorID;
134
colorIDA[1] = curr_atomSP->middle_colorID;
135
colorIDA[2] = curr_atomSP->right_colorID;
137
/* Set these colors as foreground colors in three auxiliary GC's: */
138
XSetForeground (guiSP->displaySP, guiSP->theGCA[0], colorIDA[0]);
139
XSetForeground (guiSP->displaySP, guiSP->theGCA[1], colorIDA[1]);
140
XSetForeground (guiSP->displaySP, guiSP->theGCA[2], colorIDA[2]);
142
/* Reset the flag: */
145
/* Draw one (mono) or two pixels (stereo): */
146
for (imageI = 0; imageI < imagesN; imageI++)
148
/* Prepare the coordinates and 7x7 box edge indices: */
149
screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI];
150
screen_y0 = curr_atomSP->raw_atomS.screen_y;
152
/* Horizontal scan of the neighbourhood: */
153
for (i = 0; i < 7; i++)
155
/* Vertical scan of the neighbourhood: */
156
for (j = 0; j < 7; j++)
158
/* Single pass loop: */
161
/* Current pixel coordinates: */
162
screen_x = screen_x0 + i - 3;
163
screen_y = screen_y0 + j - 3;
165
/* Check is the pixel inside the area */
166
/* reserved for the current image (in */
167
/* stereo mode there are two images): */
168
if (screen_x < left_edge[imageI]) break;
169
if (screen_x > right_edge[imageI]) break;
171
/* Check the circle mask: */
172
if (circle_maskAA[j][i] == 0) break;
174
/* Prepare index to the array */
175
/* of NearestAtomS structures: */
176
pixelI = guiSP->main_win_free_area_width * screen_y +
179
/* Check the pixel index: */
180
if (pixelI >= pixelsN) break;
182
/* Pointer to NearestAtomS struct. */
183
/* assigned to current coordinates: */
184
curr_pixelSP = nearest_atomSP + pixelI;
186
/* Current atom z: */
187
z = curr_atomSP->raw_atomS.z[imageI] +
188
half_atomic_radius * (double) levelAA[j][i];
190
/* Check was this pixel used already in */
191
/* this drawing step; if it was, compare */
192
/* the z value of the current atom with z */
193
/* value previously stored to this pixel: */
194
if (refreshI == curr_pixelSP->last_refreshI)
196
if (z >= curr_pixelSP->z) break;
199
/* Draw the pixel: */
200
XDrawPoint (guiSP->displaySP,
201
guiSP->main_hidden_pixmapID,
202
guiSP->theGCA[indexAA[j][i]],
205
/* Refresh the content of NearestAtomS */
206
/* array associated with this pixel: */
207
curr_pixelSP->styleI = 5;
208
curr_pixelSP->last_refreshI = refreshI;
209
curr_pixelSP->mol_complexI = mol_complexI;
210
curr_pixelSP->atomI = atomI;
212
curr_pixelSP->colorID = colorIDA[indexAA[j][i]];
222
/*---------------------------------------------------------------------------*/
224
/* Check is at least one pixel drawn; */
225
/* increase the counter if it is true: */
226
if (atom_drawnF != 0) atoms_drawnN++;
234
/*===========================================================================*/