00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
00042 if (needRegenerate & MOL_REGEN ||
00043 needRegenerate & SEL_REGEN ||
00044 needRegenerate & REP_REGEN) {
00045
00046 msms.clear();
00047
00048 float *xyzr = new float[4* mol -> nAtoms];
00049 int * ids = new int[mol -> nAtoms];
00050 int *flgs = NULL;
00051 const float *aradius = mol->radius();
00052
00053
00054 int count = 0;
00055 if (allatoms) {
00056
00057
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;
00068
00069 xyzr[4*count+3] = r;
00070 ids[count] = i;
00071 count++;
00072 }
00073 }
00074 } else {
00075
00076 flgs = atomSel->on;
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;
00086
00087 xyzr[4*count+3] = r;
00088 ids[count] = i;
00089 count++;
00090 }
00091 }
00092
00093
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
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];
00134 v[ind + 1] = msms.coords[ii].x[1];
00135 v[ind + 2] = msms.coords[ii].x[2];
00136 }
00137
00138 for (ii=0; ii<vnum; ii++) {
00139 ind = ii * 3;
00140 n[ind ] = msms.norms[ii].x[0];
00141 n[ind + 1] = msms.norms[ii].x[1];
00142 n[ind + 2] = msms.norms[ii].x[2];
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];
00150 c[ind + 1] = fp[1];
00151 c[ind + 2] = fp[2];
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
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
00172 cmdLineType.putdata(SOLIDLINE, cmdList);
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
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
00192
00193 if (atomColor->method() == AtomColor::THROB) {
00194
00195 cmdTriMesh.putdata(v, n, c, vnum, f, fnum, 0, cmdList);
00196 } else {
00197
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