ARB
RNA3D_Renderer.cxx
Go to the documentation of this file.
1 #include "RNA3D_GlobalHeader.hxx"
2 #include "RNA3D_Global.hxx"
3 #include "RNA3D_Textures.hxx"
4 #include "RNA3D_Renderer.hxx"
7 #include "RNA3D_Graphics.hxx"
8 
9 #include <aw_root.hxx>
10 #include <aw_awar.hxx>
11 
12 using namespace std;
13 
14 GLRenderer::GLRenderer() {
15  fSkeletonSize = 0.5;
16  iBackBone = iColorise = 0;
17  ObjectSize = 8.0;
18  iDisplayBases = iBaseMode = 0;
19  iBaseHelix = iBaseUnpairHelix = iBaseNonHelix = 0;
20  iShapeHelix = iShapeUnpairHelix = iShapeNonHelix = 0;
21  iDisplayHelix = iHelixMidPoint = iHelixBackBone = iHelixNrs = 0;
22  iDispTerInt = 0;
23  iStartHelix = 1;
24  iEndHelix = 101;
25  fHelixSize = 1.0;
26  iDispPos = 0;
27  iDispCursorPos = 0;
28  iMapSpecies = iMapSpeciesBase = iMapSpeciesPos = 0;
29  iMapSpeciesDels = iMapSpeciesMiss = 0;
30  iMapSpeciesIns = iMapSpeciesInsInfo = 0;
31 
32  G = new OpenGLGraphics;
33 }
34 
35 GLRenderer::~GLRenderer() {
36 }
37 
38 void GLRenderer::DisplayHelices() {
39  G->SetColor(RNA3D_GC_HELIX);
40  glLineWidth(fHelixSize);
41  for (int i = iStartHelix; i <= iEndHelix; i++) {
42  glBegin(GL_LINES);
43  glListBase(RNA3D->cStructure->HelixBase);
44  glCallList(RNA3D->cStructure->HelixBase+i);
45  glEnd();
46  }
47 }
48 
49 void GLRenderer::DisplayHelixBackBone() {
50  G->SetColor(RNA3D_GC_HELIX_SKELETON);
51  glLineWidth(0.5);
52 
53  glPushAttrib(GL_LIST_BIT);
54  glListBase(RNA3D->cStructure->HelixBase);
55 
56  int rnaType = RNA3D->cStructure->FindTypeOfRNA();
57 
58  switch (rnaType) {
59  case LSU_23S:
60  for (int i = 1; i <= 101; i++) {
61  glBegin(GL_LINES);
62  glCallList(RNA3D->cStructure->HelixBase+i);
63  glEnd();
64  }
65  break;
66  case LSU_5S:
67  for (int i = 1; i <= 5; i++) {
68  glBegin(GL_LINES);
69  glCallList(RNA3D->cStructure->HelixBase+i);
70  glEnd();
71  }
72  break;
73  case SSU_16S:
74  for (int i = 1; i <= 50; i++) {
75  glBegin(GL_LINES);
76  glCallList(RNA3D->cStructure->HelixBase+i);
77  glEnd();
78  }
79  break;
80  }
81 
82  glPopAttrib();
83 }
84 
85 void GLRenderer::DisplayBasePositions() {
86 
87  G->SetColor(RNA3D_GC_MOL_BACKBONE);
88  glCallList(STRUCTURE_POS_ANCHOR);
89 
90  G->SetColor(RNA3D_GC_MOL_POS);
91  glCallList(STRUCTURE_POS);
92 
93 }
94 
95 void GLRenderer::DisplayMappedSpInsertions() {
96 
97  G->SetColor(RNA3D_GC_INSERTION);
99 
100  G->SetColor(RNA3D_GC_INSERTION);
101  glCallList(MAP_SPECIES_INSERTION_BASES);
102 }
103 
104 void GLRenderer::DisplayMappedSpBasePositions() {
105 
106  G->SetColor(RNA3D_GC_MOL_BACKBONE);
108 
109  G->SetColor(RNA3D_GC_MAPPED_SPECIES);
111 }
112 
113 void GLRenderer::DisplayHelixMidPoints(Texture2D *cImages) {
114  glPointSize(fHelixSize + 5); // size will be proportional to the Helix Thickness specified !!
115  glBindTexture(GL_TEXTURE_2D, cImages->texture[CIRCLE]);
116  G->SetColor(RNA3D_GC_HELIX_MIDPOINT);
117  glCallList(HELIX_NUMBERS_POINTS);
118 }
119 
120 void GLRenderer::DisplayHelixNumbers() {
121  G->SetColor(RNA3D_GC_FOREGROUND);
122  glCallList(HELIX_NUMBERS);
123 }
124 
125 void GLRenderer::DoHelixMapping() {
126  if (iDisplayHelix) {
127  if (iHelixNrs) {
128  DisplayHelixNumbers();
129  }
130  if (iHelixBackBone) {
131  DisplayHelixBackBone();
132  }
133  DisplayHelices();
134  }
135  // Displaying Tertiary Interactions of E.coli 16S ribosomal RNA
136  if (iDispTerInt) {
137  glLineWidth(fHelixSize + 1); // Thicker than the normal Helix Strands
138  G->SetColor(RNA3D_GC_PSEUDOKNOT);
140  G->SetColor(RNA3D_GC_TRIPLE_BASE);
142  }
143 }
144 
145 void GLRenderer::DisplayMoleculeName(int /* w */, int /* h */, Structure3D *cStr) {
146  char *pSpeciesName;
147 
148  if (cStr->iMapEnable && iMapSpecies) {
149  pSpeciesName = RNA3D->root->awar(AWAR_3D_SELECTED_SPECIES)->read_string();
150  }
151  else {
152  pSpeciesName = (char *) "Eschericia Coli : Master Template";
153  }
154 
155  float x, y, z; x=1.1; y=z=1.0;
156  float line = 0.05;
157 
158  glPushMatrix();
159  G->SetColor(RNA3D_GC_FOREGROUND);
160  G->PrintString(x, y, z, pSpeciesName, GLUT_BITMAP_8_BY_13);
161 
162  char buf[25];
163  if (cStr->iMapEnable && iMapSpecies) {
164  G->SetColor(RNA3D_GC_MAPPED_SPECIES);
165  sprintf(buf, "Mutations = %d", cStr->iTotalSubs);
166  G->PrintString(x, (y-(1*line)), z, buf, GLUT_BITMAP_8_BY_13);
167  sprintf(buf, "Deletions = %d", cStr->iTotalDels);
168  G->PrintString(x, (y-(2*line)), z, buf, GLUT_BITMAP_8_BY_13);
169  sprintf(buf, "Insertions = %d", cStr->iTotalIns);
170  G->PrintString(x, (y-(3*line)), z, buf, GLUT_BITMAP_8_BY_13);
171  }
172 
173  glPopMatrix();
174 }
175 
176 void GLRenderer::DisplayMoleculeMask(int w, int h) {
177  // displays a rectangular mask cutting thru the centre of the molecule
178  glPushMatrix();
179  glScalef(0.5, 0.5, 0.5);
180 
181  if (RNA3D->bDisplayMask) {
182  G->SetColor(RNA3D_GC_MASK);
183  G->DrawBox(0, 0, w, h);
184  }
185  glPopMatrix();
186 }
187 
188 void GLRenderer::DisplayMolecule(Structure3D *cStr) {
189  glLineWidth(fSkeletonSize);
190 
191  static ColorRGBf HelixOldColor = G->GetColor(RNA3D_GC_BASES_HELIX);
192  static ColorRGBf UnpairedHelixOldColor = G->GetColor(RNA3D_GC_BASES_UNPAIRED_HELIX);
193  static ColorRGBf NonHelixOldColor = G->GetColor(RNA3D_GC_BASES_NON_HELIX);
194 
195  if (iColorise) {
196  ColorRGBf HelixNewColor = G->GetColor(RNA3D_GC_BASES_HELIX);
197  ColorRGBf UnpairedHelixNewColor = G->GetColor(RNA3D_GC_BASES_UNPAIRED_HELIX);
198  ColorRGBf NonHelixNewColor = G->GetColor(RNA3D_GC_BASES_NON_HELIX);
199 
200  if ((HelixOldColor == HelixNewColor) &&
201  (UnpairedHelixOldColor == UnpairedHelixNewColor) &&
202  (NonHelixOldColor == NonHelixNewColor))
203  {
204  glCallList(STRUCTURE_BACKBONE_CLR);
205  }
206  else {
207  HelixOldColor = HelixNewColor;
208  UnpairedHelixOldColor = UnpairedHelixNewColor;
209  NonHelixOldColor = NonHelixNewColor;
210 
211  glDeleteLists(STRUCTURE_BACKBONE_CLR, 1);
212  cStr->GenerateMoleculeSkeleton();
213  glCallList(STRUCTURE_BACKBONE_CLR);
214  }
215  }
216  else if (iBackBone) {
217  G->SetColor(RNA3D_GC_MOL_BACKBONE);
218  glCallList(STRUCTURE_BACKBONE);
219  }
220 
221  if (iDispPos) {
222  DisplayBasePositions();
223  }
224 
225  if (cStr->iMapEnable) {
226  if (cStr->iMapSearch) {
227  glLineWidth(ObjectSize/3);
228  glCallList(MAP_SEARCH_STRINGS_BACKBONE);
229  }
230  if (iMapSpecies) {
231  if (iMapSpeciesIns && iMapSpeciesInsInfo) {
232  DisplayMappedSpInsertions();
233  }
234  if (iMapSpeciesPos) {
235  DisplayMappedSpBasePositions();
236  }
237  }
238  }
239 }
240 
241 void GLRenderer::BeginTexturizer() {
242  glDisable(GL_CULL_FACE);
243  glDisable(GL_LIGHTING);
244  glDisable(GL_POINT_SMOOTH);
245  glDepthMask(GL_TRUE);
246  glEnable(GL_TEXTURE_2D);
247 
249  glEnable(GL_ALPHA_TEST);
250  glAlphaFunc(GL_GREATER, 0.1);
251  glEnable(GL_BLEND);
252  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
253 
254  float quadratic[] = { 0.0f, 0.0f, 1.0f };
255  glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, quadratic);
256 
257  // Query for the max point size supported by the hardware
258  float maxSize = 0.0f;
259  glGetFloatv(GL_POINT_SIZE_MAX_EXT, &maxSize);
260  glPointSize(MIN(ObjectSize, maxSize));
261 
262  glPointParameterfEXT(GL_POINT_SIZE_MIN_EXT, 1.0f);
263  glPointParameterfEXT(GL_POINT_SIZE_MAX_EXT, MIN(65, maxSize));
264 
265  glTexEnvf(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE);
266  glEnable(GL_POINT_SPRITE_ARB);
267  }
268 }
269 
270 void GLRenderer::EndTexturizer() {
271  // glDisable(GL_TEXTURE_2D);
273  float defaultAttenuation[3] = { 1.0f, 0.0f, 0.0f };
274  glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, defaultAttenuation);
275 
276  glDisable(GL_POINT_SPRITE_ARB);
277  glDisable(GL_BLEND);
278  glDisable(GL_ALPHA_TEST);
279  }
280 }
281 
282 #define POLOFFON glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(1, 1); glDepthFunc(GL_LESS)
283 #define POLOFFOFF glDepthFunc(GL_LEQUAL); glPolygonOffset(0, 0); glDisable(GL_POLYGON_OFFSET_FILL)
284 
285 void GLRenderer::TexturizeStructure(Texture2D *cImages, Structure3D *cStructure) {
286 
287  if (cStructure->iMapEnable) {
288  glPointSize(ObjectSize*2);
289  if (cStructure->iMapSAI) {
290  glBindTexture(GL_TEXTURE_2D, cImages->texture[HEXAGON]);
291  glCallList(MAP_SAI_TO_STRUCTURE);
292  }
293  if (cStructure->iMapSearch) {
294  glPointSize(ObjectSize*1.5);
295  glBindTexture(GL_TEXTURE_2D, cImages->texture[CIRCLE]);
297  }
298  }
299 
300  if (iDispCursorPos) {
301  glPointSize(ObjectSize+8);
302  G->SetColor(RNA3D_GC_CURSOR_POSITION);
303  glBindTexture(GL_TEXTURE_2D, cImages->texture[DIAMOND]);
304  glCallList(ECOLI_CURSOR_POSITION);
305  }
306 
307  glPointSize(ObjectSize);
308  if (iDisplayBases) {
309  switch (iBaseMode) {
310  case CHARACTERS: {
311 
312  POLOFFON;
313  { // Print Background textures
314  ColorRGBf& ApplicationBGColor = G->ApplicationBGColor;
315  glColor4f(ApplicationBGColor.red, ApplicationBGColor.green, ApplicationBGColor.blue, 1);
316  glBindTexture(GL_TEXTURE_2D, cImages->texture[CIRCLE]);
317 
318  if (iBaseHelix) {
319  glCallList(HELIX_A);
320  glCallList(HELIX_G);
321  glCallList(HELIX_C);
322  glCallList(HELIX_U);
323  }
324 
325  if (iBaseUnpairHelix) {
326  glCallList(UNPAIRED_HELIX_A);
327  glCallList(UNPAIRED_HELIX_G);
328  glCallList(UNPAIRED_HELIX_C);
329  glCallList(UNPAIRED_HELIX_U);
330  }
331 
332  if (iBaseNonHelix) {
333  glCallList(NON_HELIX_A);
334  glCallList(NON_HELIX_G);
335  glCallList(NON_HELIX_C);
336  glCallList(NON_HELIX_U);
337  }
338  }
339  POLOFFOFF;
340 
341  { // Print textures representing the actual bases
342  glBindTexture(GL_TEXTURE_2D, cImages->texture[LETTER_A]);
343  {
344  if (iBaseHelix) {
345  G->SetColor(RNA3D_GC_BASES_HELIX);
346  glCallList(HELIX_A);
347  }
348  if (iBaseUnpairHelix) {
349  G->SetColor(RNA3D_GC_BASES_UNPAIRED_HELIX);
350  glCallList(UNPAIRED_HELIX_A);
351  }
352  if (iBaseNonHelix) {
353  G->SetColor(RNA3D_GC_BASES_NON_HELIX);
354  glCallList(NON_HELIX_A);
355  }
356  }
357 
358  glBindTexture(GL_TEXTURE_2D, cImages->texture[LETTER_G]);
359  {
360  if (iBaseHelix) {
361  G->SetColor(RNA3D_GC_BASES_HELIX);
362  glCallList(HELIX_G);
363  }
364  if (iBaseUnpairHelix) {
365  G->SetColor(RNA3D_GC_BASES_UNPAIRED_HELIX);
366  glCallList(UNPAIRED_HELIX_G);
367  }
368  if (iBaseNonHelix) {
369  G->SetColor(RNA3D_GC_BASES_NON_HELIX);
370  glCallList(NON_HELIX_G);
371  }
372  }
373 
374  glBindTexture(GL_TEXTURE_2D, cImages->texture[LETTER_C]);
375  {
376  if (iBaseHelix) {
377  G->SetColor(RNA3D_GC_BASES_HELIX);
378  glCallList(HELIX_C);
379  }
380  if (iBaseUnpairHelix) {
381  G->SetColor(RNA3D_GC_BASES_UNPAIRED_HELIX);
382  glCallList(UNPAIRED_HELIX_C);
383  }
384  if (iBaseNonHelix) {
385  G->SetColor(RNA3D_GC_BASES_NON_HELIX);
386  glCallList(NON_HELIX_C);
387  }
388  }
389 
390  glBindTexture(GL_TEXTURE_2D, cImages->texture[LETTER_U]);
391  {
392  if (iBaseHelix) {
393  G->SetColor(RNA3D_GC_BASES_HELIX);
394  glCallList(HELIX_U);
395  }
396  if (iBaseUnpairHelix) {
397  G->SetColor(RNA3D_GC_BASES_UNPAIRED_HELIX);
398  glCallList(UNPAIRED_HELIX_U);
399  }
400  if (iBaseNonHelix) {
401  G->SetColor(RNA3D_GC_BASES_NON_HELIX);
402  glCallList(NON_HELIX_U);
403  }
404  }
405  }
406  break;
407  }
408  case SHAPES:
409  if (iBaseHelix) {
410  glBindTexture(GL_TEXTURE_2D, cImages->texture[iShapeHelix]);
411  G->SetColor(RNA3D_GC_BASES_HELIX);
412  glCallList(HELIX_A); glCallList(HELIX_G); glCallList(HELIX_C); glCallList(HELIX_U);
413  }
414  if (iBaseUnpairHelix) {
415  glBindTexture(GL_TEXTURE_2D, cImages->texture[iShapeUnpairHelix]);
416  G->SetColor(RNA3D_GC_BASES_UNPAIRED_HELIX);
417  glCallList(UNPAIRED_HELIX_A); glCallList(UNPAIRED_HELIX_G); glCallList(UNPAIRED_HELIX_C); glCallList(UNPAIRED_HELIX_U);
418  }
419  if (iBaseNonHelix) {
420  glBindTexture(GL_TEXTURE_2D, cImages->texture[iShapeNonHelix]);
421  G->SetColor(RNA3D_GC_BASES_NON_HELIX);
422  glCallList(NON_HELIX_A); glCallList(NON_HELIX_G); glCallList(NON_HELIX_C); glCallList(NON_HELIX_U);
423  }
424  break;
425  }
426  }
427 
428  if (iDisplayHelix && iHelixMidPoint) {
429  DisplayHelixMidPoints(cImages); // Draw circles at the midpoint of each Helix
430  }
431 
432  if (cStructure->iMapEnable && iMapSpecies) {
433  if (iMapSpeciesBase) {
434  glBindTexture(GL_TEXTURE_2D, cImages->texture[CIRCLE]);
435 
436  glPointSize(ObjectSize+4);
437  G->SetColor(RNA3D_GC_MAPPED_SPECIES);
438  glCallList(MAP_SPECIES_BASE_A); glCallList(MAP_SPECIES_BASE_U);
439  glCallList(MAP_SPECIES_BASE_G); glCallList(MAP_SPECIES_BASE_C);
440 
441  glPointSize(ObjectSize);
442  G->SetColor(RNA3D_GC_FOREGROUND);
443  glCallList(MAP_SPECIES_BASE_A); glCallList(MAP_SPECIES_BASE_U);
444  glCallList(MAP_SPECIES_BASE_G); glCallList(MAP_SPECIES_BASE_C);
445 
446  glPointSize(ObjectSize);
447  G->SetColor(RNA3D_GC_MAPPED_SPECIES);
448  glBindTexture(GL_TEXTURE_2D, cImages->texture[LETTER_A]); glCallList(MAP_SPECIES_BASE_A);
449  glBindTexture(GL_TEXTURE_2D, cImages->texture[LETTER_G]); glCallList(MAP_SPECIES_BASE_G);
450  glBindTexture(GL_TEXTURE_2D, cImages->texture[LETTER_C]); glCallList(MAP_SPECIES_BASE_C);
451  glBindTexture(GL_TEXTURE_2D, cImages->texture[LETTER_U]); glCallList(MAP_SPECIES_BASE_U);
452  }
453 
454  if (iMapSpeciesMiss) {
455  glPointSize(ObjectSize);
456  G->SetColor(RNA3D_GC_MAPPED_SPECIES);
457  glBindTexture(GL_TEXTURE_2D, cImages->texture[CIRCLE]);
458  glCallList(MAP_SPECIES_MISSING);
459  glPointSize(ObjectSize-2);
460  G->SetColor(RNA3D_GC_FOREGROUND);
461  glBindTexture(GL_TEXTURE_2D, cImages->texture[QUESTION]);
462  glCallList(MAP_SPECIES_MISSING);
463  }
464 
465  if (iMapSpeciesDels) {
466  glPointSize(ObjectSize);
467  G->SetColor(RNA3D_GC_DELETION);
468  glBindTexture(GL_TEXTURE_2D, cImages->texture[CIRCLE]);
469  glCallList(MAP_SPECIES_DELETION);
470  glPointSize(ObjectSize-2);
471  G->SetColor(RNA3D_GC_FOREGROUND);
472  glBindTexture(GL_TEXTURE_2D, cImages->texture[DANGER]);
473  glCallList(MAP_SPECIES_DELETION);
474  }
475 
476  if (iMapSpeciesIns) {
477  glPointSize(ObjectSize*3);
478  G->SetColor(RNA3D_GC_INSERTION);
479  glBindTexture(GL_TEXTURE_2D, cImages->texture[CONE_DOWN]);
480  glCallList(MAP_SPECIES_INSERTION_POINTS);
481  }
482  }
483 }
#define LSU_5S
static char * y[maxsp+1]
Structure3D * cStructure
#define SHAPES
#define AWAR_3D_SELECTED_SPECIES
STL namespace.
static void DisplayMoleculeMask(AW_root *)
void GenerateMoleculeSkeleton()
#define SSU_16S
#define POLOFFOFF
char * read_string() const
Definition: AW_awar.cxx:198
AW_awar * awar(const char *awar)
Definition: AW_root.cxx:554
#define LSU_23S
static int FindTypeOfRNA()
bool bPointSpritesSupported
static int line
Definition: arb_a2ps.c:296
#define POLOFFON
Definition: trnsprob.h:20
RNA3D_Global * RNA3D
AW_root * root
#define CHARACTERS