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

DrawMolItemSurface.C

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr                                                                       
00003  *cr            (C) Copyright 1995-2019 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: DrawMolItemSurface.C,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.46 $       $Date: 2021/10/28 21:12:15 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  * This contains the surface code for DrawMolItem
00019  *
00020  * The surfaces are made with SURF, an external program.  It was
00021  * written by Amitabh Varshney when he was at UNC.  The code is
00022  * available from ftp.cs.unc.edu .
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 // In general, the method is
00037 //    write the file for surf input
00038 //    call surf
00039 //    read the triangles
00040 //    write them to the draw list
00041 
00042 void DrawMolItem::draw_surface(float *framepos, int draw_wireframe, float radius) {
00043   // early-exit if nothing selected
00044   if (atomSel->selected == 0)
00045     return;
00046 
00047   // mapping from order printed out (selected) to atom id
00048   int *map = new int[atomSel->selected];
00049 
00050   int i;
00051   int count = 0; // count is number of atoms selected
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   // regenerate sphere coordinates if necessary 
00061   if ( needRegenerate & MOL_REGEN ||
00062        needRegenerate & SEL_REGEN ||
00063        needRegenerate & REP_REGEN) {
00064 
00065     // then we need to recalculate the SURF
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     // We add all displayed atoms to the sphere array
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     // make the new surface -- returns 0 on failure
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   // and display everything
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; // 3 vertices per triangle
00103     vsize = vnum * 3;              // 3 floats per vertex
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]; // Red
00113       c[ind + 1] = fp[1]; // Green
00114       c[ind + 2] = fp[2]; // Blue
00115 
00116       ind+=3;
00117       c[ind    ] = fp[0]; // Red
00118       c[ind + 1] = fp[1]; // Green
00119       c[ind + 2] = fp[2]; // Blue
00120 
00121       ind+=3;
00122       c[ind    ] = fp[0]; // Red
00123       c[ind + 1] = fp[1]; // Green
00124       c[ind + 2] = fp[2]; // Blue
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       // Create a wire mesh
00142       cmdLineType.putdata(SOLIDLINE, cmdList); // set line drawing parameters
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       // Create a triangle mesh, but don't try to stripify it since
00149       // Surf doesn't generate connected geometry.
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 

Generated on Sat Apr 20 02:42:43 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002