~ubuntu-branches/ubuntu/breezy/garlic/breezy

« back to all changes in this revision

Viewing changes to atoms_style7.c

  • Committer: Bazaar Package Importer
  • Author(s): zhaoway
  • Date: 2001-04-24 07:09:13 UTC
  • Revision ID: james.westby@ubuntu.com-20010424070913-uzpupnwdfhmliebz
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000 Damir Zucic */
 
2
 
 
3
/*=============================================================================
 
4
 
 
5
                                atoms_style7.c
 
6
 
 
7
Purpose:
 
8
        Draw atoms, using style 7 (11x11 circle).
 
9
 
 
10
Input:
 
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
 
19
            a given pixel.
 
20
 
 
21
Output:
 
22
        (1) Atoms drawn to the hidden pixmap.
 
23
        (2) Return value.
 
24
 
 
25
Return value:
 
26
        (1) The number of atoms drawn.
 
27
 
 
28
Notes:
 
29
        (1) Indentation is exceptionally 4 spaces.
 
30
 
 
31
        (2) The second index of  indexAA and  circle_maskAA is treated as
 
32
            row index.  This is somewhat unusual,  but more  practical in
 
33
            this function.
 
34
 
 
35
=============================================================================*/
 
36
 
 
37
#include <stdio.h>
 
38
 
 
39
#include <X11/Xlib.h>
 
40
#include <X11/Xutil.h>
 
41
#include <X11/Xos.h>
 
42
#include <X11/Xatom.h>
 
43
 
 
44
#include "defines.h"
 
45
#include "typedefs.h"
 
46
 
 
47
/*======draw atoms using style 7 (11x11 circle):=============================*/
 
48
 
 
49
size_t DrawAtomsStyle7_ (MolComplexS *mol_complexSP, int mol_complexesN,
 
50
                         ConfigS *configSP, GUIS *guiSP,
 
51
                         NearestAtomS *nearest_atomSP, size_t pixelsN,
 
52
                         unsigned int refreshI)
 
53
{
 
54
size_t                  atoms_drawnN = 0;
 
55
int                     imageI, imagesN;
 
56
int                     left_edge[2], right_edge[2];
 
57
int                     mol_complexI;
 
58
MolComplexS             *curr_mol_complexSP;
 
59
size_t                  atomsN, atomI;
 
60
AtomS                   *curr_atomSP;
 
61
unsigned long           colorIDA[3];
 
62
static int              indexAA[11][11] =
 
63
                                        {{0, 0, 1, 1, 1, 1, 1, 2, 2, 0, 0},
 
64
                                         {0, 1, 0, 0, 0, 0, 1, 1, 2, 2, 0},
 
65
                                         {1, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2},
 
66
                                         {1, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2},
 
67
        /* Be sure to read Note 2 ! */   {1, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2},
 
68
                                         {1, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2},
 
69
                                         {1, 1, 0, 0, 0, 0, 1, 1, 1, 2, 2},
 
70
                                         {2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2},
 
71
                                         {2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2},
 
72
                                         {0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0},
 
73
                                         {0, 0, 2, 2, 2, 2, 2, 2, 2, 0, 0}};
 
74
int                     atom_drawnF;
 
75
int                     screen_x0, screen_y0;
 
76
int                     i, j, screen_x, screen_y;
 
77
static int              circle_maskAA[11][11] =
 
78
                                        {{0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
 
79
                                         {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
 
80
                                         {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
 
81
                                         {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
 
82
                                         {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
 
83
        /* Be sure to read Note 2 ! */   {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
 
84
                                         {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
 
85
                                         {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
 
86
                                         {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
 
87
                                         {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
 
88
                                         {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0}};
 
89
size_t                  pixelI;
 
90
NearestAtomS            *curr_pixelSP;
 
91
double                  z;
 
92
double                  third_atomic_radius;
 
93
int                     levelAA[11][11] =
 
94
                                        {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
 
95
                                         {0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
 
96
                                         {0, 0, 1, 2, 2, 2, 2, 2, 1, 0, 0},
 
97
                                         {0, 1, 2, 2, 3, 3, 3, 2, 2, 1, 0},
 
98
                                         {0, 1, 2, 3, 3, 4, 3, 3, 2, 1, 0},
 
99
                                         {0, 1, 2, 3, 4, 4, 4, 3, 2, 1, 0},
 
100
                                         {0, 1, 2, 3, 3, 4, 3, 3, 2, 1, 0},
 
101
                                         {0, 1, 2, 2, 3, 3, 3, 2, 2, 1, 0},
 
102
                                         {0, 0, 1, 2, 2, 2, 2, 2, 1, 0, 0},
 
103
                                         {0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0},
 
104
                                         {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
 
105
 
 
106
/* Number of images: */
 
107
if (configSP->stereoF) imagesN = 2;
 
108
else imagesN = 1;
 
109
 
 
110
/* Left and right image edge (in stereo mode there are two images): */
 
111
left_edge[0]  = configSP->image_screen_x0[0];
 
112
right_edge[0] = configSP->image_screen_x1[0];
 
113
left_edge[1]  = configSP->image_screen_x0[1];
 
114
right_edge[1] = configSP->image_screen_x1[1];
 
115
 
 
116
/* Atomic radius: */
 
117
third_atomic_radius = 2.5 * configSP->screen_to_atomic_scale_x;
 
118
 
 
119
/* Draw each macromolecular complex: */
 
120
for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++)
 
121
    {
 
122
    /* Pointer to current macromolecular complex: */
 
123
    curr_mol_complexSP = mol_complexSP + mol_complexI;
 
124
 
 
125
    /* Prepare and check the number of atoms: */
 
126
    atomsN = curr_mol_complexSP->atomsN;
 
127
    if (atomsN == 0) continue;
 
128
 
 
129
    /* Draw atoms which have the given style: */
 
130
    for (atomI = 0; atomI < atomsN; atomI++)
 
131
        {
 
132
        /* Pointer to the current atom: */
 
133
        curr_atomSP = curr_mol_complexSP->atomSP + atomI;
 
134
 
 
135
        /* Check style: */
 
136
        if (curr_atomSP->raw_atomS.atom_styleI != 7) continue;
 
137
 
 
138
        /* Check is atom hidden: */
 
139
        if (curr_atomSP->hiddenF) continue;
 
140
 
 
141
        /* Check is atom inside slab: */
 
142
        if (!curr_atomSP->inside_slabF) continue;
 
143
 
 
144
        /* Check is atom inside window: */
 
145
        if (!curr_atomSP->inside_windowF) continue;
 
146
 
 
147
        /* Prepare colors: */
 
148
        colorIDA[0] = curr_atomSP->left_colorID;
 
149
        colorIDA[1] = curr_atomSP->middle_colorID;
 
150
        colorIDA[2] = curr_atomSP->right_colorID;
 
151
 
 
152
        /* Set these colors as foreground colors in three auxiliary GC's: */
 
153
        XSetForeground (guiSP->displaySP, guiSP->theGCA[0], colorIDA[0]);
 
154
        XSetForeground (guiSP->displaySP, guiSP->theGCA[1], colorIDA[1]);
 
155
        XSetForeground (guiSP->displaySP, guiSP->theGCA[2], colorIDA[2]);
 
156
 
 
157
        /* Reset the flag: */
 
158
        atom_drawnF = 0;
 
159
 
 
160
        /* Draw one (mono) or two pixels (stereo): */
 
161
        for (imageI = 0; imageI < imagesN; imageI++)
 
162
            {
 
163
            /* Prepare the coordinates and 9x9 box edge indices: */
 
164
            screen_x0 = curr_atomSP->raw_atomS.screen_x[imageI];
 
165
            screen_y0 = curr_atomSP->raw_atomS.screen_y;
 
166
 
 
167
            /* Horizontal scan of the neighbourhood: */
 
168
            for (i = 0; i < 11; i++)
 
169
                {
 
170
                /* Vertical scan of the neighbourhood: */
 
171
                for (j = 0; j < 11; j++)
 
172
                    {
 
173
                    /* Single pass loop: */
 
174
                    do
 
175
                        {
 
176
                        /* Current pixel coordinates: */
 
177
                        screen_x = screen_x0 + i - 5;
 
178
                        screen_y = screen_y0 + j - 5;
 
179
 
 
180
                        /* Check is the pixel inside the area */
 
181
                        /* reserved for the current image (in */
 
182
                        /* stereo mode there are two images): */
 
183
                        if (screen_x < left_edge[imageI]) break;
 
184
                        if (screen_x > right_edge[imageI]) break;
 
185
 
 
186
                        /* Check the circle mask: */
 
187
                        if (circle_maskAA[j][i] == 0) break;
 
188
 
 
189
                        /* Prepare index  to the array */
 
190
                        /* of NearestAtomS structures: */
 
191
                        pixelI = guiSP->main_win_free_area_width * screen_y +
 
192
                                 screen_x;
 
193
 
 
194
                        /* Check the pixel index: */
 
195
                        if (pixelI >= pixelsN) break;
 
196
 
 
197
                        /* Pointer to  NearestAtomS struct. */
 
198
                        /* assigned to current coordinates: */
 
199
                        curr_pixelSP = nearest_atomSP + pixelI;
 
200
 
 
201
                        /* Current atom z: */
 
202
                        z = curr_atomSP->raw_atomS.z[imageI] +
 
203
                                third_atomic_radius * (double) levelAA[j][i];
 
204
 
 
205
                        /* Check was  this pixel used  already in */
 
206
                        /* this drawing step;  if it was, compare */
 
207
                        /* the z value of the current atom with z */
 
208
                        /* value previously stored to this pixel: */
 
209
                        if (refreshI == curr_pixelSP->last_refreshI)
 
210
                            {
 
211
                            if (z >= curr_pixelSP->z) break;
 
212
                            }
 
213
 
 
214
                        /* Draw the pixel: */
 
215
                        XDrawPoint (guiSP->displaySP,
 
216
                                    guiSP->main_hidden_pixmapID,
 
217
                                    guiSP->theGCA[indexAA[j][i]],
 
218
                                    screen_x, screen_y);
 
219
 
 
220
                        /* Refresh the content of NearestAtomS */
 
221
                        /* array  associated  with this pixel: */
 
222
                        curr_pixelSP->styleI = 7;
 
223
                        curr_pixelSP->last_refreshI = refreshI;
 
224
                        curr_pixelSP->mol_complexI = mol_complexI;
 
225
                        curr_pixelSP->atomI = atomI;
 
226
                        curr_pixelSP->z = z;
 
227
                        curr_pixelSP->colorID = colorIDA[indexAA[j][i]];
 
228
 
 
229
                        /* Set the flag: */
 
230
                        atom_drawnF = 1;
 
231
 
 
232
                        } while (0);
 
233
                    }
 
234
                }
 
235
            }
 
236
 
 
237
/*---------------------------------------------------------------------------*/
 
238
 
 
239
        /* Check is at least  one pixel drawn; */
 
240
        /* increase the counter if it is true: */
 
241
        if (atom_drawnF != 0) atoms_drawnN++;
 
242
 
 
243
        }
 
244
    }
 
245
 
 
246
return atoms_drawnN;
 
247
}
 
248
 
 
249
/*===========================================================================*/
 
250
 
 
251