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

« back to all changes in this revision

Viewing changes to atoms_style5.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_style5.c
 
6
 
 
7
Purpose:
 
8
        Draw atoms, using style 5 (7x7 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 5 (7x7 circle):===============================*/
 
48
 
 
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)
 
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[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}};
 
69
int                     atom_drawnF;
 
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}};
 
79
size_t                  pixelI;
 
80
NearestAtomS            *curr_pixelSP;
 
81
double                  z;
 
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}};
 
90
 
 
91
/* Number of images: */
 
92
if (configSP->stereoF) imagesN = 2;
 
93
else imagesN = 1;
 
94
 
 
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];
 
100
 
 
101
/* Atomic radius: */
 
102
half_atomic_radius = 2.5 * configSP->screen_to_atomic_scale_x;
 
103
 
 
104
/* Draw each macromolecular complex: */
 
105
for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++)
 
106
    {
 
107
    /* Pointer to current macromolecular complex: */
 
108
    curr_mol_complexSP = mol_complexSP + mol_complexI;
 
109
 
 
110
    /* Prepare and check the number of atoms: */
 
111
    atomsN = curr_mol_complexSP->atomsN;
 
112
    if (atomsN == 0) continue;
 
113
 
 
114
    /* Draw atoms which have the given style: */
 
115
    for (atomI = 0; atomI < atomsN; atomI++)
 
116
        {
 
117
        /* Pointer to the current atom: */
 
118
        curr_atomSP = curr_mol_complexSP->atomSP + atomI;
 
119
 
 
120
        /* Check style: */
 
121
        if (curr_atomSP->raw_atomS.atom_styleI != 5) continue;
 
122
 
 
123
        /* Check is atom hidden: */
 
124
        if (curr_atomSP->hiddenF) continue;
 
125
 
 
126
        /* Check is atom inside slab: */
 
127
        if (!curr_atomSP->inside_slabF) continue;
 
128
 
 
129
        /* Check is atom inside window: */
 
130
        if (!curr_atomSP->inside_windowF) continue;
 
131
 
 
132
        /* Prepare colors: */
 
133
        colorIDA[0] = curr_atomSP->left_colorID;
 
134
        colorIDA[1] = curr_atomSP->middle_colorID;
 
135
        colorIDA[2] = curr_atomSP->right_colorID;
 
136
 
 
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]);
 
141
 
 
142
        /* Reset the flag: */
 
143
        atom_drawnF = 0;
 
144
 
 
145
        /* Draw one (mono) or two pixels (stereo): */
 
146
        for (imageI = 0; imageI < imagesN; imageI++)
 
147
            {
 
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;
 
151
 
 
152
            /* Horizontal scan of the neighbourhood: */
 
153
            for (i = 0; i < 7; i++)
 
154
                {
 
155
                /* Vertical scan of the neighbourhood: */
 
156
                for (j = 0; j < 7; j++)
 
157
                    {
 
158
                    /* Single pass loop: */
 
159
                    do
 
160
                        {
 
161
                        /* Current pixel coordinates: */
 
162
                        screen_x = screen_x0 + i - 3;
 
163
                        screen_y = screen_y0 + j - 3;
 
164
 
 
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;
 
170
 
 
171
                        /* Check the circle mask: */
 
172
                        if (circle_maskAA[j][i] == 0) break;
 
173
 
 
174
                        /* Prepare index  to the array */
 
175
                        /* of NearestAtomS structures: */
 
176
                        pixelI = guiSP->main_win_free_area_width * screen_y +
 
177
                                 screen_x;
 
178
 
 
179
                        /* Check the pixel index: */
 
180
                        if (pixelI >= pixelsN) break;
 
181
 
 
182
                        /* Pointer to  NearestAtomS struct. */
 
183
                        /* assigned to current coordinates: */
 
184
                        curr_pixelSP = nearest_atomSP + pixelI;
 
185
 
 
186
                        /* Current atom z: */
 
187
                        z = curr_atomSP->raw_atomS.z[imageI] +
 
188
                                half_atomic_radius * (double) levelAA[j][i];
 
189
 
 
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)
 
195
                            {
 
196
                            if (z >= curr_pixelSP->z) break;
 
197
                            }
 
198
 
 
199
                        /* Draw the pixel: */
 
200
                        XDrawPoint (guiSP->displaySP,
 
201
                                    guiSP->main_hidden_pixmapID,
 
202
                                    guiSP->theGCA[indexAA[j][i]],
 
203
                                    screen_x, screen_y);
 
204
 
 
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;
 
211
                        curr_pixelSP->z = z;
 
212
                        curr_pixelSP->colorID = colorIDA[indexAA[j][i]];
 
213
 
 
214
                        /* Set the flag: */
 
215
                        atom_drawnF = 1;
 
216
 
 
217
                        } while (0);
 
218
                    }
 
219
                }
 
220
            }
 
221
 
 
222
/*---------------------------------------------------------------------------*/
 
223
 
 
224
        /* Check is at least  one pixel drawn; */
 
225
        /* increase the counter if it is true: */
 
226
        if (atom_drawnF != 0) atoms_drawnN++;
 
227
 
 
228
        }
 
229
    }
 
230
 
 
231
return atoms_drawnN;
 
232
}
 
233
 
 
234
/*===========================================================================*/
 
235
 
 
236