CompoundSystem.h

Go to the documentation of this file.
00001 #ifndef SimTK_MOLMODEL_COMPOUNDSYSTEM_H_
00002 #define SimTK_MOLMODEL_COMPOUNDSYSTEM_H_
00003 
00004 #include "SimTKsimbody.h"
00005 #include "molmodel/internal/common.h"
00006 #include "molmodel/internal/Compound.h"
00007 #include "molmodel/internal/MolecularMechanicsSystem.h"
00008 #include "molmodel/internal/DuMMForceFieldSubsystem.h"
00009 
00010 #include <map>
00011 
00012 namespace SimTK {
00013 
00019 class SimTK_MOLMODEL_EXPORT CompoundSystem : public MolecularMechanicsSystem {
00020 public:
00022     CompoundSystem() 
00023 //        : matter(*this), decorations(*this)
00024     {}
00025 
00027     ~CompoundSystem() {
00028         for (int i=0; i < (int)compounds.size(); ++i)
00029             delete compounds[i];
00030     }
00031 
00032     // const SimbodyMatterSubsystem& getMatter() const {return matter;}
00033     // SimbodyMatterSubsystem& updMatter() {return matter;}
00034 
00035     // const DecorationSubsystem& getDecorations() const {return decorations;}
00036     // DecorationSubsystem& updDecorations() {return decorations;}
00037 
00044     Compound::Index adoptCompound(
00045         Compound& child, 
00046         const Transform& compoundTransform = Transform() 
00047         ) 
00048     {
00049         const Compound::Index id((int)compounds.size());
00050 
00051         compounds.push_back(new Compound((CompoundRep*)0)); // grow
00052         Compound& c = *compounds.back(); // refer to the empty handle we just created
00053 
00054         child.disown(c); // transfer ownership to c
00055 
00056         // Now tell the Compound object its owning CompoundSystem and id within
00057         // that System.
00058         c.setCompoundSystem(*this, id);
00059 
00060         // Save transform
00061         // March 6, 2008 -- adjust internal Transform of Compound, rather than 
00062         // saving the Transform in CompoundSystem
00063         c.setTopLevelTransform(compoundTransform * c.getTopLevelTransform());
00064         // assert((int) compoundTransforms.size() == (int) id);
00065         // compoundTransforms.push_back(compoundTransform);
00066 
00067         return id;
00068     }
00069 
00071     void modelCompounds();
00072 
00076     size_t             getNumCompounds() const {return compounds.size();}
00077 
00079     const Compound& getCompound(Compound::Index i 
00080         ) const {return *compounds.at(i);}
00081 
00083     Compound&       updCompound(Compound::Index i 
00084         )       {return *compounds.at(i);}
00085 
00086 private:
00087 
00088     void modelOneCompound(Compound::Index compoundId);
00089 
00090     void setClusterCompound(DuMM::ClusterIndex clusterIx, const Compound& compound) 
00091     {
00092         assert(! clusterHasCompound(clusterIx));
00093         compoundPtrsByClusterIndex[clusterIx] = &compound;
00094         assert(clusterHasCompound(clusterIx));
00095     }
00096 
00097     bool clusterHasCompound(DuMM::ClusterIndex clusterIx) {
00098         return compoundPtrsByClusterIndex.find(clusterIx) != compoundPtrsByClusterIndex.end();
00099     }
00100 
00101     void generateTopologyFromCompounds();
00102 
00103     // suppress
00104     CompoundSystem(const CompoundSystem&);
00105     CompoundSystem& operator=(const CompoundSystem&);
00106 
00107     // std::vector<Transform> compoundTransforms;
00108 
00109     // retarded visual studio compiler complains about being unable to 
00110     // export private stl class members
00111 #if defined(_MSC_VER)
00112 #pragma warning(push)
00113 #pragma warning(disable:4251)
00114 #endif
00115 
00116     std::vector<Compound*> compounds;
00117     std::map<DuMM::ClusterIndex, const Compound*> compoundPtrsByClusterIndex;
00118     std::map<DuMM::ClusterIndex, int> clusterAtomCounts;
00119     std::map<DuMM::ClusterIndex, MobilizedBodyIndex> clusterBodies;
00120 
00121 #if defined(_MSC_VER)
00122 #pragma warning(pop)
00123 #endif
00124 
00125     // SimbodyMatterSubsystem matter;
00126     // DecorationSubsystem decorations;
00127 };
00128 
00129 } // namespace SimTK
00130 
00131 #endif // SimTK_MOLMODEL_COMPOUNDSYSTEM_H_
00132 

Generated on Fri Sep 26 07:44:08 2008 for SimTKcore by  doxygen 1.5.6