Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

DrawMolItemMSMS.C

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr                                                                       
00003  *cr            (C) Copyright 1995-2011 The Board of Trustees of the           
00004  *cr                        University of Illinois                       
00005  *cr                         All Rights Reserved                        
00006  *cr                                                                   
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  * RCS INFORMATION:
00011  *
00012  *      $RCSfile: DrawMolItemMSMS.C,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.48 $       $Date: 2011/06/08 18:41:42 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  *  Use a MSMSInterface object to get a surface triangulation information
00019  *  There are several rendering options:
00020  *    1) probe radius
00021  *    2) surface density
00022  *    3) "All Atoms" -- should the surface be of the selection or the
00023  *        contribution of this selection to the surface of all the atoms?
00024  *        0 == just the selection, 1 == contribution to the all atom surface
00025  *
00026  ***************************************************************************/
00027 
00028 
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include "DrawMolecule.h"
00032 #include "DrawMolItem.h"
00033 #include "MSMSInterface.h"
00034 #include "Inform.h"
00035 #include "Scene.h"
00036 
00037 void DrawMolItem::draw_msms(float *framepos, int draw_wireframe, int allatoms, float radius, float density) {
00038   int i;
00039   int msms_ok = 1;
00040 
00041   // regenerate sphere coordinates if necessary
00042   if (needRegenerate & MOL_REGEN ||
00043       needRegenerate & SEL_REGEN ||
00044       needRegenerate & REP_REGEN) {
00045 
00046     msms.clear();    
00047     // so I need to recalculate the MSMS surface
00048     float *xyzr = new float[4* mol -> nAtoms];
00049     int   * ids = new int[mol -> nAtoms];
00050     int   *flgs = NULL; // note: this is NOT ALLOCATED
00051     const float *aradius = mol->radius();
00052 
00053     // Should I compute the surface of all the atoms?
00054     int count = 0;
00055     if (allatoms) {
00056       // no (surface of only the selected atoms)
00057       // get the data for the selected atoms
00058       float r;
00059       for (i=atomSel->firstsel; i <= atomSel->lastsel; i++) {
00060         if (atomSel->on[i]) {
00061           xyzr[4*count+0] = framepos[3*i+0];
00062           xyzr[4*count+1] = framepos[3*i+1];
00063           xyzr[4*count+2] = framepos[3*i+2];
00064 
00065           r = aradius[i];
00066           if (r < 0.2f) 
00067             r = 0.2f; // work around an MSMS bug
00068 
00069           xyzr[4*count+3] = r;
00070           ids[count] = i;
00071           count++;
00072         }
00073       } // for
00074     } else {
00075       // yes (contribution of selected atoms to the complete surface)
00076       flgs = atomSel->on; // no translation is needed
00077       float r;
00078       for (i=0; i < mol->nAtoms; i++) {
00079         xyzr[4*count+0] = framepos[3*i+0];
00080         xyzr[4*count+1] = framepos[3*i+1];
00081         xyzr[4*count+2] = framepos[3*i+2];
00082 
00083         r = aradius[i];
00084         if (r < 0.2f) 
00085           r = 0.2f; // work around an MSMS bug
00086 
00087         xyzr[4*count+3] = r;
00088         ids[count] = i;
00089         count++;
00090       }
00091     }
00092 
00093     // compute the surface 
00094 #if defined(_MSC_VER)
00095       msms_ok = (MSMSInterface::COMPUTED == 
00096                   msms.compute_from_file(radius, density, count, ids, xyzr, flgs));
00097 #else
00098     if (getenv("VMDMSMSUSEFILE")) {
00099       msms_ok = (MSMSInterface::COMPUTED == 
00100                   msms.compute_from_file(radius, density, count, ids, xyzr, flgs));
00101     } else {
00102       msms_ok = (MSMSInterface::COMPUTED == 
00103                   msms.compute_from_socket(radius, density, count, ids, xyzr, flgs));
00104     }
00105 #endif
00106 
00107     if (!msms_ok)
00108       msgInfo << "Could not compute MSMS surface" << sendmsg;
00109  
00110     // do NOT delete flgs as it points to "atomsel->on"
00111     delete [] ids;
00112     delete [] xyzr;
00113 
00114     msgInfo << "Done with MSMS surface." << sendmsg;
00115   }
00116 
00117   if (msms_ok && msms.faces.num() > 0) {
00118     append(DMATERIALON);
00119 
00120     float *v, *c, *n;
00121     int ii, ind, fnum, vnum, vsize;
00122 
00123     vnum = msms.coords.num();
00124     fnum = msms.faces.num();
00125     vsize = vnum * 3;
00126 
00127     v = new float[vsize];
00128     n = new float[vsize];
00129     c = new float[vsize];
00130 
00131     for (ii=0; ii<vnum; ii++) {
00132       ind = ii * 3;
00133       v[ind    ] = msms.coords[ii].x[0]; // X
00134       v[ind + 1] = msms.coords[ii].x[1]; // Y
00135       v[ind + 2] = msms.coords[ii].x[2]; // Z
00136     }
00137 
00138     for (ii=0; ii<vnum; ii++) {
00139       ind = ii * 3;
00140       n[ind    ] = msms.norms[ii].x[0]; // X
00141       n[ind + 1] = msms.norms[ii].x[1]; // Y
00142       n[ind + 2] = msms.norms[ii].x[2]; // Z
00143     }
00144 
00145     for (ii=0; ii<vnum; ii++) {
00146       ind = ii * 3;
00147       int col = atomColor->color[msms.atomids[ii]];
00148       const float *fp = scene->color_value(col); 
00149       c[ind    ] = fp[0]; // Red
00150       c[ind + 1] = fp[1]; // Green
00151       c[ind + 2] = fp[2]; // Blue
00152     }
00153  
00154     if (draw_wireframe) {
00155       int lsize = fnum * 6; 
00156       int * l = new int[lsize];
00157 
00158       int facecount = 0;
00159       for (ii=0; ii<fnum; ii++) {
00160         // draw the face
00161         ind = facecount * 6;
00162         l[ind    ] = msms.faces[ii].vertex[0]; 
00163         l[ind + 1] = msms.faces[ii].vertex[1]; 
00164         l[ind + 2] = msms.faces[ii].vertex[1]; 
00165         l[ind + 3] = msms.faces[ii].vertex[2]; 
00166         l[ind + 4] = msms.faces[ii].vertex[2]; 
00167         l[ind + 5] = msms.faces[ii].vertex[0]; 
00168         facecount++;
00169       }
00170 
00171       // Create a wire mesh
00172       cmdLineType.putdata(SOLIDLINE, cmdList); // set line drawing parameters
00173       cmdLineWidth.putdata(1, cmdList);
00174       cmdWireMesh.putdata(v, n, c, vnum, l, fnum*3, cmdList);
00175       delete [] l;
00176     } else {
00177       int fsize = fnum * 3;
00178       int * f = new int[fsize];
00179 
00180       int facecount = 0;
00181       for (ii=0; ii<fnum; ii++) {
00182         // draw the face
00183         ind = facecount * 3;
00184         f[ind    ] = msms.faces[ii].vertex[0]; 
00185         f[ind + 1] = msms.faces[ii].vertex[1]; 
00186         f[ind + 2] = msms.faces[ii].vertex[2]; 
00187   
00188         facecount++;
00189       }
00190 
00191       // Check if we're actively animating this rep in colors or in 
00192       // geometry, and only use ACTC if we're going to draw it more than once
00193       if (atomColor->method() == AtomColor::THROB) {
00194         // create a triangle mesh without ACTC stripification
00195         cmdTriMesh.putdata(v, n, c, vnum, f, fnum, 0, cmdList);
00196       } else {
00197         // create a triangle mesh, allowing ACTC to stripify it.
00198         cmdTriMesh.putdata(v, n, c, vnum, f, fnum, 1, cmdList);
00199       }
00200 
00201       delete [] f;
00202     }
00203 
00204     delete [] v;
00205     delete [] n;
00206     delete [] c;
00207   }
00208 }
00209 
00210 
00211 

Generated on Sat May 26 01:47:55 2012 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002