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

DrawMolItem.h

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: DrawMolItem.h,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.171 $      $Date: 2012/03/07 21:32:48 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  *
00019  * Child Displayable component of a molecule; this is responsible for doing
00020  * the actual drawing of a molecule.  It contains an atom color, atom
00021  * selection, and atom representation object to specify how this component
00022  * should look.
00023  *
00024  ***************************************************************************/
00025 #ifndef DRAWMOLITEM_H
00026 #define DRAWMOLITEM_H
00027 
00028 #include "config.h"         // to force recompilation on config changes
00029 #include "Displayable.h"
00030 #include "DispCmds.h"
00031 #include "AtomColor.h"
00032 #include "AtomRep.h"
00033 #include "AtomSel.h"
00034 #include "PickMode.h"
00035 #include "BaseMolecule.h"
00036 #include "VolumeTexture.h"
00037 
00038 class DrawMolecule;         
00039 
00040 #ifdef VMDSURF
00041 #include "Surf.h"
00042 #endif
00043 
00044 #ifdef VMDMSMS
00045 #include "MSMSInterface.h"
00046 #endif
00047 
00048 #include "QuickSurf.h"
00049 
00051 class DrawMolItem : public Displayable {
00052 public:
00053   AtomColor *atomColor;     
00054   AtomRep *atomRep;         
00055   AtomSel *atomSel;         
00056   int repNumber;            
00057   char commentBuffer[1024]; 
00058 
00059   char *name;               
00060 
00061 private:
00062   DrawMolecule *mol;        
00063   float *avg;               
00064   int avgsize;              
00065 
00066  
00067   char *framesel;           
00068 
00069 
00070   int structwarningcount;   
00071 
00072   int emitstructwarning(void); 
00073 
00075 
00076   DispCmdBeginRepGeomGroup cmdBeginRepGeomGroup;
00077   DispCmdColorIndex      cmdColorIndex;
00078   DispCmdComment         cmdCommentX;
00079   DispCmdCylinder        cmdCylinder;
00080   DispCmdLine            cmdLine;
00081   DispCmdLineType        cmdLineType;
00082   DispCmdLineWidth       cmdLineWidth;
00083   DispCmdPickPoint       pickPoint;
00084   DispCmdPointArray      cmdPointArray;
00085   DispCmdSphere          cmdSphere;
00086   DispCmdSphereRes       cmdSphres;
00087   DispCmdSphereType      cmdSphtype;
00088   DispCmdSphereArray     cmdSphereArray;
00089   DispCmdSquare          cmdSquare;
00090   DispCmdTriangle        cmdTriangle;
00091   DispCmdTriMesh         cmdTriMesh;
00092   DispCmdVolSlice        cmdVolSlice;
00093   DispCmdWireMesh        cmdWireMesh;
00095 
00097   struct ColorLookup {
00098     int num;
00099     int max;
00100     int *idlist;
00101     ColorLookup() {
00102       num = 0;
00103       max = 0;
00104       idlist = 0;
00105     }
00106     ~ColorLookup() {
00107       free(idlist);
00108     }
00109     void append(int id) {
00110       if (max == 0) {
00111         idlist = (int *)malloc(8*sizeof(int)); 
00112         max = 8;
00113       }
00114       if (num == max) {
00115         idlist = (int *)realloc(idlist, 2*num*sizeof(int));
00116         max = 2*num;
00117       }
00118       idlist[num++] = id;
00119     }
00120   };
00121  
00123   ColorLookup *colorlookups;      
00124   static void update_lookups(AtomColor *, AtomSel *, ColorLookup *);
00125 
00127   void update_pbc_transformations();
00128 
00129 #ifdef VMDSURF
00130   Surf surf;                   
00131 #endif
00132 
00133 #ifdef VMDMSMS
00134   MSMSInterface msms;          
00135 #endif
00136 
00137   int waveftype;               
00138   int wavefspin;               
00139   int wavefexcitation;         
00140   int gridorbid;               
00141   float orbgridspacing;        
00142   int orbgridisdensity;        
00143   VolumetricData *orbvol;      
00144 
00145   // cached volume texture information to avoid unnecessary updates
00146   int voltexVolid;
00147   int voltexColorMethod;
00148   float voltexDataMin, voltexDataMax;
00149 
00150   // encapsulate data for color by volume used by this rep
00151   VolumeTexture volumeTexture;
00152 
00153   // Auxiliary data structure for rendering tubes.
00154   // Since the control points are based on fixed atom indices, we can
00155   // find all those indices once, cache them, then just look up the
00156   // coordinates when it's time to draw a frame.  Should speed up
00157   // animation, as well as perhaps make it easier to add better-looking
00158   // tube reps later.
00159  
00160   // TubeIndexList holds a set of control point indices.
00161   typedef ResizeArray<int> TubeIndexList;
00162 
00166   ResizeArray<TubeIndexList *> *tubearray;
00167 
00169   void generate_tubearray();
00170 
00171   // commands to draw different representations for a given selection 
00172   void draw_solid_spheres(float *, int res, float radscale, float fixrad);
00173   void draw_residue_beads(float *, int res, float radscale);
00174   void draw_dotted_spheres(float *, float srad, int sres); 
00175   void draw_lines(float *, int thickness, float cutoff);   
00176   void draw_cpk_licorice(float *, int, float, int, float, int, int, float cutoff); 
00177 
00178 #ifdef VMDPOLYHEDRA
00179   void draw_polyhedra(float *, float); 
00180 #endif
00181   void draw_points(float *, float);                   
00182   void draw_bonds(float *, float brad, int bres, float cutoff);             
00183 
00185   void make_connection(float *prev, float *start, float *end, float *next,
00186                        float radius, int resolution, int is_cyl);
00187 
00189   void draw_spline_curve(int num, float *coords, int *idx,
00190                          int use_cyl, float b_rad, int b_res);
00191 
00193   void draw_spline_ribbon(int num, float *coords, float *perps,
00194                           int *idx, int use_cyl, float b_rad,
00195                           int b_res);
00196 
00198   void draw_spline_new(int num, const float *coords, 
00199                        const float *perps, const int *idx, 
00200                        const float *cpwidths, const float *cpheights, 
00201                        int numscalefactors, int b_res, int cyclic);
00202 
00204   void draw_ribbon_from_points(int numpoints, const float *points, 
00205                   const float *perps, const int *cols, int numpanels,
00206                   const float *heights, const float *widths, 
00207                   int numscalefactors);
00208 
00209   void draw_tube(float *, float radius, int res);   
00210   void draw_ribbons(float *, float brad, int bres, float thickness); 
00211   void draw_ribbons_new(float *, float, int, int, float);  
00212 
00213 
00214   int draw_protein_ribbons_old(float *, int, float, float, int);
00215   int draw_protein_ribbons_new(float *, int, float, float, int);
00216   int draw_nucleic_ribbons(float *, int, float, float, int, int, int);
00217   int draw_nucleotide_cylinders(float *, int, float, float, int);
00218   int draw_base_sugar_rings(float *, int, float, float, int);
00219   int draw_cartoon_ribbons(float *, int, float, float, int, int);
00221 
00222   void draw_structure(float *, float brad, int bres, int linethickness); 
00223 
00224   void draw_alpha_helix_cylinders(ResizeArray<float> &x,
00225                                   ResizeArray<float> &y,
00226                                   ResizeArray<float> &z,
00227                                   ResizeArray<int> &atom_on, int *color,
00228                                   float bond_rad, int bond_res,
00229                                   float *res_start, float *res_end);
00230 
00232   void draw_beta_sheet(ResizeArray<float> &x, ResizeArray<float> &y,
00233                        ResizeArray<float> &z, ResizeArray<int> &atom_on, 
00234                        int *color, float ribbon_width,
00235                        float *res_start, float *res_end);
00236 
00237   void draw_trace(float *pos, float brad, int bres, int linethickness); 
00238   void draw_dot_surface(float *pos, float srad, int sres, int method); 
00239   void draw_msms(float *pos, int draw_wireframe, int allatoms, float radius, float density); 
00240   void draw_quicksurf(float *pos, int quality, float radius, float isovalue, float spacing); 
00241   void draw_surface(float *pos, int draw_wireframe, float radius); 
00242   void draw_hbonds(float *, float maxangle, int thickness, float cutoff); 
00243   void draw_dynamic_bonds(float *, float brad, int bres, float cutoff); 
00244 
00245   // Drawing functions for volumetric and isosurface data 
00246   void draw_volslice(int volid, float slice, int axis, int texmode); 
00247 
00249   void updateVolumeTexture();
00250 
00251   void draw_isosurface(int, float, int, int, int, int); 
00252   void draw_volume_field_lines(int volid, float seedval, float minlen, float maxlen, float thickness); 
00253 
00254   void draw_orbital(int, int, int, int, int, float, int, int, float, int, int); 
00255 
00257   // helper functions for volume rendering
00258   void draw_volume_box_solid(const VolumetricData *);
00259   void draw_volume_box_lines(const VolumetricData *);
00260   void draw_volume_slice(const VolumetricData *, int, float, int);
00261   void draw_volume_texture(const VolumetricData *, int);
00262   void draw_volume_isosurface_points(const VolumetricData *, float, int, int);
00263   void draw_volume_isosurface_lit_points(const VolumetricData *, float, int, int);
00264   void draw_volume_isosurface_trimesh(const VolumetricData *, float, int, const float *voltex=NULL);
00265   void draw_volume_isosurface_lines(const VolumetricData *, float, int, int);
00266   int  draw_volume_get_colorid(void);
00267   void prepare_volume_texture(const VolumetricData *v, int method);
00268   int calcseeds_gradient_magnitude(const VolumetricData *v, ResizeArray<float> *seeds, float seedmin, float seedmax);
00269 
00271 
00272 #ifdef VMDWITHCARBS
00273 
00274   // functions for rendering small rings using the PaperChain algorithm
00275   void draw_rings_paperchain(float *framepos, float bipyramid_height, int maxringsize);
00276   void paperchain_get_ring_color(SmallRing &ring, float *framepos, float *rgb);
00277   void paperchain_draw_ring(SmallRing &ring, float *framepos, float bipyramid_height);
00279   
00281   // functions for rendering small rings using the Twister algorithm
00282   void draw_rings_twister(float *framepos, int start_end_centroid, int hide_shared_links, int rib_steps, float rib_width, float rib_height, int maxringsize, int maxpathlength);
00283   void twister_draw_path(LinkagePath &path, float *framepos, int start_end_centroid, int rib_steps, float rib_width, float rib_height);
00284   void twister_draw_ribbon_extensions(ResizeArray<float> &vertices, ResizeArray<float> &colors,
00285                                       ResizeArray<float> &normals, ResizeArray<int> &facets,
00286                                       float centroid[3], float normal[3], float right[3], float rib_point[3],
00287                                       float rib_height, float rib_width,
00288                                       float top_color[3], float bottom_color[3]);
00289   void twister_draw_hexagon(ResizeArray<float> &vertices, ResizeArray<float> &colors, ResizeArray<float> &normals,
00290                                       ResizeArray<int> &facets, float centroid[3], float normal[3],
00291                                       float first_atom[3], float rib_height, float rib_width,
00292                                       float top_color[3], float bottom_color[3]);
00294   
00296   // utility functions for Twister and Paper Chain
00297   void get_ring_centroid_and_normal(float *centroid, float *normal, SmallRing &ring, float *framepos);
00298   bool smallring_selected(SmallRing &ring);
00299   bool linkagepath_selected(LinkagePath &path);
00301 #endif
00302 
00303   void create_cmdlist(void);            
00304   void do_create_cmdlist();             
00305 
00306 public:
00314   enum RegenChoices {NO_REGEN = 0, MOL_REGEN = 1, SEL_REGEN = 2,
00315                      REP_REGEN = 4, COL_REGEN = 8};
00316 
00317 private:
00318   int needRegenerate;                   
00319   int update_pbc;                       
00320   int update_ss;                        
00321   int update_ts;                        
00322   int update_traj;                      
00323   void place_picks(float *pos);         
00324 
00325 protected:
00326   virtual void do_color_changed(int);
00327   virtual void do_color_rgb_changed(int);
00328   virtual void do_color_scale_changed();
00329 
00330 public:
00331   // constructor: name, parent molecule, and atom drawing methods
00332   DrawMolItem(const char *, DrawMolecule *, AtomColor *, AtomRep *, AtomSel *);
00333   virtual ~DrawMolItem(void);
00334   
00335   int change_color(AtomColor *);        
00336   int change_rep(AtomRep *);            
00337   int change_sel(const char *);         
00338   void force_recalc(int);               
00339   int atom_displayed(int);              
00340   int representation_index(void);       
00341 
00342   int set_smoothing(int n) {           
00343     if (n >= 0) {
00344       avgsize = n; 
00345       return TRUE;
00346     }
00347     return FALSE;
00348   }
00349   int get_smoothing() const {           
00350     return avgsize;
00351   }
00352 
00356   void set_drawframes(const char *frames);
00357   const char *get_drawframes() const { return framesel; }
00358    
00361   void set_pbc(int);
00362   int get_pbc() const;
00363 
00365   void set_pbc_images(int);
00366   int get_pbc_images() const;
00367 
00370   void change_pbc() { update_pbc = 1; }
00371 
00373   void change_ss() { update_ss = 1; }
00374 
00376   void change_ts() { update_ts = 1; }
00377 
00379   void change_traj() { update_traj = 1; }
00380 
00381   //
00382   // public virtual routines
00383   //
00384   virtual void prepare();               
00385 
00388   virtual int pickable_on();
00389 
00391 
00392   virtual void pick_start(PickMode *p, DisplayDevice *d,
00393                           int btn, int tag, const int *cell, int dim, 
00394                           const float *pos) {
00395     p->pick_molecule_start(mol, d, btn, tag, cell, dim, pos);
00396   }
00397 
00398   virtual void pick_move(PickMode *p, DisplayDevice *d,
00399                           int tag, int dim, const float *pos) {
00400     p->pick_molecule_move (mol, d, tag, dim, pos);
00401   }
00402 
00403   virtual void pick_end(PickMode *p, DisplayDevice *d) {
00404     p->pick_molecule_end  (mol, d);
00405   }
00407 
00408 protected:
00409   float spline_basis[4][4];          
00410 };
00411 
00412 #endif
00413 

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