src/opengl/TargetStructGL.cc

00001 #if __linux
00002 #define  GL_GLEXT_PROTOTYPES
00003 #include <GL/gl.h>
00004 #include <GL/glu.h>
00005 #include <GL/glext.h>
00006 #include <GL/glut.h>
00007 #else
00008 #include <opengl/gl.h>
00009 #include <opengl/glu.h>
00010 #endif
00011 #include <stdio.h>
00012 
00013 #include "open_prospect_gl.h"
00014 
00015 
00016 
00017 typedef struct
00018 {
00019   GLfloat x;                    // X Component
00020   GLfloat y;                    // Y Component
00021   GLfloat z;                    // Z Component
00022 } GLVec3;
00023 
00024 
00025 void
00026 TargetStructGL::SetColor (int num, float red, float green, float blue)
00027 {
00028   colors[num][0] = red;
00029   colors[num][1] = green;
00030   colors[num][2] = blue;
00031 }
00032 
00033 void
00034 TargetStructGL::SetLen (int len)
00035 {
00036   TargetStruct::SetLen (len);
00037 
00038   if (colors != NULL)
00039     free (colors);
00040 
00041   colors = (vec3 *) malloc (sizeof (vec3) * len);
00042   for (int i = 0; i < len; i++)
00043     {
00044       colors[i][0] = 1.0;
00045       colors[i][2] = 0.5;
00046       colors[i][1] = 0.5;
00047     }
00048 }
00049 
00050 
00051 void
00052 TargetStructGL::VOB_Init (void)
00053 {
00054   m_nVertexCount = len * 8;
00055   GLVec3 *m_pVertices = new GLVec3[m_nVertexCount];
00056   int vertex_count = 0;
00057   for (int i = 0; i < len - 1; i++)
00058     {
00059       ResidueAtoms *the_res = &structure[i];
00060       ResidueAtoms *next_res = &structure[i + 1];
00061       m_pVertices[vertex_count].x = the_res->atom[the_res->bb_num[anN]][0];
00062       m_pVertices[vertex_count].y = the_res->atom[the_res->bb_num[anN]][1];
00063       m_pVertices[vertex_count].z = the_res->atom[the_res->bb_num[anN]][2];
00064       m_pVertices[vertex_count + 1].x =
00065         the_res->atom[the_res->bb_num[anCa]][0];
00066       m_pVertices[vertex_count + 1].y =
00067         the_res->atom[the_res->bb_num[anCa]][1];
00068       m_pVertices[vertex_count + 1].z =
00069         the_res->atom[the_res->bb_num[anCa]][2];
00070       vertex_count += 2;
00071 
00072       m_pVertices[vertex_count].x = the_res->atom[the_res->bb_num[anCa]][0];
00073       m_pVertices[vertex_count].y = the_res->atom[the_res->bb_num[anCa]][1];
00074       m_pVertices[vertex_count].z = the_res->atom[the_res->bb_num[anCa]][2];
00075       m_pVertices[vertex_count + 1].x =
00076         the_res->atom[the_res->bb_num[anC]][0];
00077       m_pVertices[vertex_count + 1].y =
00078         the_res->atom[the_res->bb_num[anC]][1];
00079       m_pVertices[vertex_count + 1].z =
00080         the_res->atom[the_res->bb_num[anC]][2];
00081       vertex_count += 2;
00082 
00083 
00084       m_pVertices[vertex_count].x = the_res->atom[the_res->bb_num[anC]][0];
00085       m_pVertices[vertex_count].y = the_res->atom[the_res->bb_num[anC]][1];
00086       m_pVertices[vertex_count].z = the_res->atom[the_res->bb_num[anC]][2];
00087       m_pVertices[vertex_count + 1].x =
00088         the_res->atom[the_res->bb_num[anO]][0];
00089       m_pVertices[vertex_count + 1].y =
00090         the_res->atom[the_res->bb_num[anO]][1];
00091       m_pVertices[vertex_count + 1].z =
00092         the_res->atom[the_res->bb_num[anO]][2];
00093       vertex_count += 2;
00094 
00095 
00096       m_pVertices[vertex_count].x = the_res->atom[the_res->bb_num[anC]][0];
00097       m_pVertices[vertex_count].y = the_res->atom[the_res->bb_num[anC]][1];
00098       m_pVertices[vertex_count].z = the_res->atom[the_res->bb_num[anC]][2];
00099       m_pVertices[vertex_count + 1].x =
00100         next_res->atom[next_res->bb_num[anN]][0];
00101       m_pVertices[vertex_count + 1].y =
00102         next_res->atom[next_res->bb_num[anN]][1];
00103       m_pVertices[vertex_count + 1].z =
00104         next_res->atom[next_res->bb_num[anN]][2];
00105       vertex_count += 2;
00106     }
00107 
00108 
00109 
00110   glGenBuffersARB (1, &m_nVBOVertices); // Get A Valid Name
00111   glBindBufferARB (GL_ARRAY_BUFFER_ARB, m_nVBOVertices);        // Bind The Buffer
00112   // Load The Data
00113   glBufferDataARB (GL_ARRAY_BUFFER_ARB, m_nVertexCount * sizeof (vec3),
00114                    m_pVertices, GL_STATIC_DRAW_ARB);
00115 
00116   // Our Copy Of The Data Is No Longer Necessary, It Is Safe In The Graphics Card
00117   delete[]m_pVertices;
00118   m_pVertices = NULL;
00119 
00120 }
00121 
00122 void
00123 TargetStructGL::SphereList_Init (void)
00124 {
00125 
00126   //setup the sphere drawing list
00127   if (sphere_list == -1)
00128     {
00129       glDeleteLists (sphere_list, 1);
00130     }
00131 
00132   sphere_list = glGenLists (1);
00133   glNewList (sphere_list, GL_COMPILE);
00134 
00135   GLUquadricObj *quadratic = gluNewQuadric ();  // Create A Pointer To The Quadric Object ( NEW )
00136   gluQuadricNormals (quadratic, GLU_SMOOTH);    // Create Smooth Normals ( NEW )
00137 
00138   glInitNames ();
00139 
00140   for (int i = 0; i < len; i++)
00141     {
00142       ResidueAtoms *the_res = &structure[i];
00143       glPushName (i);
00144       glColor3f (colors[i][0], colors[i][1], colors[i][2]);
00145       for (int j = 0; j < the_res->atom_count; j++)
00146         {
00147           glPushMatrix ();
00148           glTranslatef (the_res->atom[j][0], the_res->atom[j][1],
00149                         the_res->atom[j][2]);
00150           gluSphere (quadratic, 1, 7, 7);
00151           glPopMatrix ();
00152         }
00153       glPopName ();
00154     }
00155   gluDeleteQuadric (quadratic); // Delete Quadratic - Free Resources
00156   glEndList ();
00157 }
00158 
00159 
00160 
00161 void
00162 TargetStructGL::DrawAtomSphere (void)
00163 {
00164   float red[3] = { 1, 0, 0 }, blue[3] =
00165   {
00166   0, 0, 1}, green[3] =
00167   {
00168   0, 1, 0};
00169   glColor4f (red[0], red[1], red[2], 0.4);
00170   glMaterialf (GL_FRONT, GL_SHININESS, 128.f);
00171   glCallList (sphere_list);
00172 }
00173 
00174 void
00175 TargetStructGL::DrawBackBoneLine (void)
00176 {
00177   int i, j, k, len;
00178   float alpha = 1;
00179   float red[3] = { 1, 0, 0 }, blue[3] =
00180   {
00181   0, 0, 1}, green[3] =
00182   {
00183   0, 1, 0};
00184   char string[1024];
00185 
00186   glLineWidth (2);
00187   glColor3f (1.0, 1.0, 1.0);
00188 #if 1
00189   glBindBufferARB (GL_ARRAY_BUFFER_ARB, m_nVBOVertices);
00190   glVertexPointer (3, GL_FLOAT, 0, 0);
00191   glDrawArrays (GL_LINES, 0, m_nVertexCount);
00192 #else
00193   for (int i = 0; i < the_target->len - 1; i++)
00194     {
00195       ResidueAtoms *the_res = &the_target->structure[i];
00196       ResidueAtoms *next_res = &the_target->structure[i + 1];
00197       //for (int j = 0; j < the_res->atom_count; j++) {       
00198 
00199       //glColor4f( the_res->atom[ the_res->bb_num[ anCa ] ].color[0],
00200       //                                 pdb1->atom[ pdb1->chain_residue[i][0].ca ].color[1],
00201       //                                 pdb1->atom[ pdb1->chain_residue[i][0].ca ].color[2],
00202       //                                 alpha);
00203 
00204       glBegin (GL_LINES);
00205       glVertex3f (the_res->atom[the_res->bb_num[anN]][0],
00206                   the_res->atom[the_res->bb_num[anN]][1],
00207                   the_res->atom[the_res->bb_num[anN]][2]);
00208       glVertex3f (the_res->atom[the_res->bb_num[anCa]][0],
00209                   the_res->atom[the_res->bb_num[anCa]][1],
00210                   the_res->atom[the_res->bb_num[anCa]][2]);
00211 
00212       glVertex3f (the_res->atom[the_res->bb_num[anCa]][0],
00213                   the_res->atom[the_res->bb_num[anCa]][1],
00214                   the_res->atom[the_res->bb_num[anCa]][2]);
00215       glVertex3f (the_res->atom[the_res->bb_num[anC]][0],
00216                   the_res->atom[the_res->bb_num[anC]][1],
00217                   the_res->atom[the_res->bb_num[anC]][2]);
00218 
00219 
00220       glVertex3f (the_res->atom[the_res->bb_num[anC]][0],
00221                   the_res->atom[the_res->bb_num[anC]][1],
00222                   the_res->atom[the_res->bb_num[anC]][2]);
00223       glVertex3f (the_res->atom[the_res->bb_num[anO]][0],
00224                   the_res->atom[the_res->bb_num[anO]][1],
00225                   the_res->atom[the_res->bb_num[anO]][2]);
00226 
00227 
00228       glVertex3f (the_res->atom[the_res->bb_num[anC]][0],
00229                   the_res->atom[the_res->bb_num[anC]][1],
00230                   the_res->atom[the_res->bb_num[anC]][2]);
00231       glVertex3f (next_res->atom[next_res->bb_num[anN]][0],
00232                   next_res->atom[next_res->bb_num[anN]][1],
00233                   next_res->atom[next_res->bb_num[anN]][2]);
00234 
00235       glEnd ();
00236     }
00237 #endif
00238 }

Generated on Wed Apr 11 16:50:50 2007 for open_prospect by  doxygen 1.4.6