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 #include <stdio.h>
00028 #include <stdlib.h>
00029 #include "DrawMolecule.h"
00030 #include "DrawMolItem.h"
00031 #include "utilities.h"
00032 #include "Surf.h"
00033 #include "Inform.h"
00034 #include "Scene.h"
00035
00036
00037
00038
00039
00040
00041
00042 void DrawMolItem::draw_surface(float *framepos, int draw_wireframe, float radius) {
00043
00044 if (atomSel->selected == 0)
00045 return;
00046
00047
00048 int *map = new int[atomSel->selected];
00049
00050 int i;
00051 int count = 0;
00052 for (i=atomSel->firstsel; i <= atomSel->lastsel; i++) {
00053 if (atomSel->on[i]) {
00054 map[count++] = i;
00055 }
00056 }
00057
00058 int surfs_up = 1;
00059
00060
00061 if ( needRegenerate & MOL_REGEN ||
00062 needRegenerate & SEL_REGEN ||
00063 needRegenerate & REP_REGEN) {
00064
00065
00066 surf.clear();
00067 float *x = new float[atomSel->selected];
00068 float *y = new float[atomSel->selected];
00069 float *z = new float[atomSel->selected];
00070 float *r = new float[atomSel->selected];
00071 const float *aradius = mol->radius();
00072
00073
00074 int j;
00075 for (int i=0; i<atomSel->selected; i++) {
00076 j = map[i];
00077 r[i] = aradius[j];
00078 x[i] = framepos[3L*j+0];
00079 y[i] = framepos[3L*j+1];
00080 z[i] = framepos[3L*j+2];
00081 }
00082
00083
00084 surfs_up = surf.compute(radius, atomSel->selected, r, x, y, z);
00085
00086 delete [] r;
00087 delete [] x;
00088 delete [] y;
00089 delete [] z;
00090 }
00091
00092
00093 if (surfs_up && surf.numtriangles > 0) {
00094 int i, ind, vnum, vsize;
00095 float *c;
00096
00097 sprintf(commentBuffer,"Mol[%d] Rep[%d] Surf", mol->id(), repNumber);
00098 cmdCommentX.putdata(commentBuffer, cmdList);
00099
00100 append(DMATERIALON);
00101
00102 vnum = surf.numtriangles * 3;
00103 vsize = vnum * 3;
00104
00105 c = new float[vsize];
00106
00107 for (i=0; i<surf.numtriangles; i++) {
00108 int col = atomColor->color[map[surf.ind[i]]];
00109 const float *fp = scene->color_value(col);
00110
00111 ind = i * 9;
00112 c[ind ] = fp[0];
00113 c[ind + 1] = fp[1];
00114 c[ind + 2] = fp[2];
00115
00116 ind+=3;
00117 c[ind ] = fp[0];
00118 c[ind + 1] = fp[1];
00119 c[ind + 2] = fp[2];
00120
00121 ind+=3;
00122 c[ind ] = fp[0];
00123 c[ind + 1] = fp[1];
00124 c[ind + 2] = fp[2];
00125 }
00126
00127 if (draw_wireframe) {
00128 int *l = new int[surf.numtriangles * 6L];
00129 int i;
00130 for (i=0; i<surf.numtriangles; i++) {
00131 int li = i * 6;
00132 int ll = i * 3;
00133 l[li ] = ll + 0;
00134 l[li + 1] = ll + 1;
00135 l[li + 2] = ll + 1;
00136 l[li + 3] = ll + 2;
00137 l[li + 4] = ll + 2;
00138 l[li + 5] = ll + 0;
00139 }
00140
00141
00142 cmdLineType.putdata(SOLIDLINE, cmdList);
00143 cmdLineWidth.putdata(1, cmdList);
00144 cmdWireMesh.putdata(&surf.v[0], &surf.n[0], c, vnum,
00145 l, surf.numtriangles * 3, cmdList);
00146 delete [] l;
00147 } else {
00148
00149
00150 cmdTriMesh.putdata(&surf.v[0], &surf.n[0], c, vnum,
00151 &surf.f[0], surf.numtriangles,
00152 0, cmdList);
00153 }
00154
00155 delete [] c;
00156 delete [] map;
00157 }
00158
00159 msgInfo << "Done." << sendmsg;
00160 }
00161