Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics
[Home] [Tutorials] [All Classes] [Grouped Classes]

X:/dropbox/visualizationlibrary/src/vlMolecule/Molecule.hpp

Go to the documentation of this file.
00001 /**************************************************************************************/
00002 /*                                                                                    */
00003 /*  Visualization Library                                                             */
00004 /*  http://www.visualizationlibrary.org                                               */
00005 /*                                                                                    */
00006 /*  Copyright (c) 2005-2010, Michele Bosi                                             */
00007 /*  All rights reserved.                                                              */
00008 /*                                                                                    */
00009 /*  Redistribution and use in source and binary forms, with or without modification,  */
00010 /*  are permitted provided that the following conditions are met:                     */
00011 /*                                                                                    */
00012 /*  - Redistributions of source code must retain the above copyright notice, this     */
00013 /*  list of conditions and the following disclaimer.                                  */
00014 /*                                                                                    */
00015 /*  - Redistributions in binary form must reproduce the above copyright notice, this  */
00016 /*  list of conditions and the following disclaimer in the documentation and/or       */
00017 /*  other materials provided with the distribution.                                   */
00018 /*                                                                                    */
00019 /*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND   */
00020 /*  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED     */
00021 /*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE            */
00022 /*  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR  */
00023 /*  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    */
00024 /*  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;      */
00025 /*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON    */
00026 /*  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT           */
00027 /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS     */
00028 /*  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                      */
00029 /*                                                                                    */
00030 /**************************************************************************************/
00031 
00032 #ifndef Molecule_INCLUDE_ONCE
00033 #define Molecule_INCLUDE_ONCE
00034 
00035 #include <vlMolecule/link_config.hpp>
00036 #include <vlMolecule/Atom.hpp>
00037 #include <vlMolecule/Bond.hpp>
00038 #include <vlGraphics/Geometry.hpp>
00039 #include <vlGraphics/Actor.hpp>
00040 #include <vlGraphics/ActorTree.hpp>
00041 #include <vlGraphics/Text.hpp>
00042 #include <vlCore/String.hpp>
00043 #include <vlCore/KeyValues.hpp>
00044 
00045 namespace vl
00046 {
00048   typedef enum
00049   {
00050     MS_AtomsOnly,
00051     MS_BallAndStick,
00052     MS_Sticks,
00053     MS_Wireframe,
00054   } EMoleculeStyle;
00055 
00064   class VLMOLECULE_EXPORT Molecule: public Object
00065   {
00066     VL_INSTRUMENT_CLASS(vl::Molecule, Object)
00067 
00068   public:
00069     Molecule();
00070     ~Molecule() { reset(); }
00071     Molecule(const Molecule& other): Object(other) { operator=(other); }
00072     Molecule& operator=(const Molecule& other);
00073 
00074     void reset();
00075 
00076     void setMoleculeName(const String& name) { mMoleculeName = name; }
00077     const String moleculeName() const { return mMoleculeName; }
00078 
00079     unsigned int id() const { return mId; }
00080     void setId(unsigned int id) { mId = id; }
00081 
00082     KeyValues* tags() { return mTags.get(); }
00083     const KeyValues* tags() const { return mTags.get(); }
00084 
00085     const std::vector< ref<Atom> >& atoms() const { return mAtoms; }
00086     std::vector< ref<Atom> >& atoms() { return mAtoms; }
00087 
00088     int atomCount() const { return (int)mAtoms.size(); }
00089     const Atom* atom(int index) const;
00090     Atom* atom(int index);
00091     void addAtom(Atom* atom);
00092     void eraseAtom(Atom*atom);
00093     void eraseAtom(int index);
00094     void eraseAllAtoms();
00095 
00096     const std::vector< ref<Bond> >& bonds() const { return mBonds; }
00097     std::vector< ref<Bond> >& bonds() { return mBonds; }
00098 
00099     int bondCount() const { return (int)mBonds.size(); }
00100     const Bond* bond(int index) const;
00101     Bond* bond(int index);
00102     const Bond* bond(Atom* a1, Atom* a2) const;
00103     Bond* bond(Atom* a1, Atom* a2);
00104     void addBond(Bond* bond);
00105     Bond* addBond(Atom* a1, Atom* a2);
00106     void eraseBond(Bond*bond);
00107     void eraseBond(int bond);
00108     void eraseBond(Atom* a1, Atom* a2);
00109     void eraseBond(int a1, int a2);
00110     void eraseAllBonds();
00111 
00112     void computeAtomAdjacency();
00113     void incidentBonds(std::vector<Bond*>& inc_bonds, Atom* atom);
00114 
00116     const std::vector< ref<Atom> >& cycle(int i) const { return mCycles[i]; }
00118     std::vector< ref<Atom> >& cycle(int i) { return mCycles[i]; }
00119 
00121     const std::vector< std::vector< ref<Atom> > >& cycles() const { return mCycles; }
00123     std::vector< std::vector< ref<Atom> > >& cycles() { return mCycles; }
00124 
00128     void prepareForRendering();
00129 
00131     const ActorTree* actorTree() const { return mActorTree.get(); }
00133     ActorTree* actorTree() { return mActorTree.get(); }
00134 
00136     void setCPKAtomColors();
00138     void setAtomColors(const fvec4& color);
00139 
00141     void setCalculatedAtomRadii(float percentage=1.0f);
00143     void setEmpiricalAtomRadii(float percentage=1.0f);
00145     void setCovalentAtomRadii(float percentage=1.0f);
00147     void setVanDerWaalsAtomRadii(float percentage=1.0f);
00149     void setAtomRadii(float radius);
00151     void setBondRadii(float radius);
00152 
00153     void setAtomTypeVisible(EAtomType type, bool visible);
00154 
00156     void setMoleculeStyle(EMoleculeStyle style) { mMoleculeStyle = style; }
00158     EMoleculeStyle moleculeStyle() const { return mMoleculeStyle; }
00159 
00161     void setAtomDetail(int detail) { mAtomDetail = detail; }
00163     int atomDetail() const { return mAtomDetail; }
00164 
00166     void setBondDetail(int detail) { mBondDetail = detail; }
00168     int bondDetail() const { return mBondDetail; }
00169 
00170     float ringOffset() const { return mRingOffset; }
00171     void setRingOffset(float offset) { mRingOffset = offset; }
00172 
00173     void setAromaticBondsColor(const fvec4& color);
00174     void setAromaticRingColor(const fvec4& color) { mAromaticRingColor = color; }
00175     const fvec4& aromaticRingColor() const { return mAromaticRingColor; }
00176 
00177     float lineWidth() const { return mLineWidth; }
00178     bool smoothLines() const { return mSmoothLines; }
00179 
00180     void setLineWidth(float w) { mLineWidth = w; }
00181     void setSmoothLines(bool smooth) { mSmoothLines = smooth; }
00182 
00184     Transform* transformTree() { return mTransformTree.get(); }
00186     const Transform* transformTree() const { return mTransformTree.get(); }
00187 
00189     const Text* atomLabelTemplate() const { return mAtomLabelTemplate.get(); }
00191     Text* atomLabelTemplate() { return mAtomLabelTemplate.get(); }
00192 
00194     void setShowAtomNames(bool show) { mShowAtomNames = show; }
00196     bool showAtomNames() const{ return mShowAtomNames; }
00197 
00199     const Effect* atomLabelEffect() const { return mAtomLabelEffect.get(); }
00201     Effect* atomLabelEffect() { return mAtomLabelEffect.get(); }
00202 
00204     void setMoleculeToActorMapEnabled(bool enabled) { mMoleculeToActorMapEnabled = enabled; }
00206     bool isMoleculeToActorMapEnabled() const { return mMoleculeToActorMapEnabled; }
00207 
00209     void setActorToMoleculeMapEnabled(bool enabled) { mActorToMoleculeMapEnabled = enabled; }
00211     bool isActorToMoleculeMapEnabled() const { return mActorToMoleculeMapEnabled; }
00212 
00214     const std::map< ref<Atom>, ref<Actor> >& atomToActorMap() const { return mAtomToActorMap; }
00216     const std::map< ref<Actor>, ref<Atom> >& actorToAtomMap() const { return mActorToAtomMap; }
00218     const std::map< ref<Bond>, ref<Actor> >& bondToActorMap() const { return mBondToActorMap; }
00220     const std::map< ref<Actor>, ref<Bond> >& actorToBondMap() const { return mActorToBondMap; }
00221 
00223     std::map< ref<Atom>, ref<Actor> >& atomToActorMap() { return mAtomToActorMap; }
00225     std::map< ref<Actor>, ref<Atom> >& actorToAtomMap() { return mActorToAtomMap; }
00227     std::map< ref<Bond>, ref<Actor> >& bondToActorMap() { return mBondToActorMap; }
00229     std::map< ref<Actor>, ref<Bond> >& actorToBondMap() { return mActorToBondMap; }
00230 
00231   protected:
00232     void prepareAtomInsert(int bonus=100)
00233     {
00234       if (atoms().size() == atoms().capacity())
00235         atoms().reserve(atoms().size() + bonus);
00236     }
00237     void prepareBondInsert(int bonus=100)
00238     {
00239       if (bonds().size() == bonds().capacity())
00240         bonds().reserve(bonds().size() + bonus);
00241     }
00242     void wireframeStyle();
00243     void atomsStyle();
00244     void ballAndStickStyle();
00245     void sticksStyle();
00246     void generateRings();
00247     void generateAtomLabels();
00248     void generateAtomLabel(const Atom* atom, Transform* tr);
00249 
00250   protected:
00251     fvec4 mAromaticRingColor;
00252     ref<ActorTree> mActorTree;
00253     ref<Transform> mTransformTree;
00254     std::vector< ref<Atom> > mAtoms;
00255     std::vector< ref<Bond> > mBonds;
00256     std::vector< std::vector< ref<Atom> > > mCycles; 
00257     std::map< ref<Atom>, ref<Actor> > mAtomToActorMap;
00258     std::map< ref<Actor>, ref<Atom> > mActorToAtomMap;
00259     std::map< ref<Bond>, ref<Actor> > mBondToActorMap;
00260     std::map< ref<Actor>, ref<Bond> > mActorToBondMap;
00261     String mMoleculeName;
00262     ref<KeyValues> mTags;
00263     ref<Text> mAtomLabelTemplate;
00264     ref<Effect> mAtomLabelEffect;
00265     unsigned int mId;
00266     EMoleculeStyle mMoleculeStyle;
00267     int mAtomDetail;
00268     int mBondDetail;
00269     float mRingOffset;
00270     float mLineWidth;
00271     bool mSmoothLines;
00272     bool mShowAtomNames;
00273     bool mMoleculeToActorMapEnabled;
00274     bool mActorToMoleculeMapEnabled;
00275   };
00276 
00281   VLMOLECULE_EXPORT bool loadMOL2(const String& path, std::vector< ref<Molecule> >& structures);
00282 
00287   VLMOLECULE_EXPORT bool loadMOL2(VirtualFile* vfile, std::vector< ref<Molecule> >& structures);
00288 }
00289 
00290 #endif

Visualization Library 2011.09.1160 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu May 2 2013 13:40:43.
Permission is granted to use this page to write and publish articles regarding Visualization Library.