Changes in / [9a8a6b:6a922b]


Ignore:
Location:
src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/Graph/BondGraph.hpp

    r9a8a6b r6a922b  
    221221              neighboriter != ListOfNeighbors.end();
    222222              ++neighboriter) {
    223             if ((*neighboriter) > Walker) {  // just to not add bonds from both sides
    224               const atom * const OtherWalker = dynamic_cast<const atom *>(*neighboriter);
    225               ASSERT(OtherWalker != NULL,
    226                   "BondGraph::CreateAdjacency() - TesselPoint "
    227                   +(*neighboriter)->getName()+" that was not an atom retrieved from LinkedList");
     223            const atom * const OtherWalker = dynamic_cast<const atom *>(*neighboriter);
     224            ASSERT(OtherWalker != NULL,
     225                "BondGraph::CreateAdjacency() - TesselPoint "
     226                +(*neighboriter)->getName()+" that was not an atom retrieved from LinkedList");
     227            if (OtherWalker->getId() > Walker->getId()) {  // just to not add bonds from both sides
    228228              LOG(4, "INFO: Current other atom is " << *OtherWalker << ".");
    229229
     
    245245              }
    246246            } else {
    247               LOG(5, "REJECT: Not Adding: Wrong order.");
     247              LOG(4, "REJECT: Not Adding: Wrong order.");
    248248            }
    249249          }
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.cpp

    r9a8a6b r6a922b  
    8585const Observable::channels_t GLMoleculeObject_molecule::AtomsChannels(getAtomsChannels());
    8686const Observable::channels_t GLMoleculeObject_molecule::HullChannels(getAllAtomicChangesChannels());
    87 const Observable::channels_t GLMoleculeObject_molecule::BoundingBoxChannels(getAllAtomicChangesChannels());
     87const Observable::channels_t GLMoleculeObject_molecule::BoundingBoxChannels(1, molecule::BoundingBoxChanged);
    8888const Observable::channels_t GLMoleculeObject_molecule::IndexChannels(1, molecule::IndexChanged);
    8989const Observable::channels_t GLMoleculeObject_molecule::NameChannels(1, molecule::MoleculeNameChanged);
     
    403403}
    404404
    405 GLMoleculeObject_molecule::BoundingBoxInfo GLMoleculeObject_molecule::initBoundingBox() const
    406 {
    407   BoundingBoxInfo info;
     405molecule::BoundingBoxInfo GLMoleculeObject_molecule::initBoundingBox() const
     406{
     407  molecule::BoundingBoxInfo info;
    408408  info.position = zeroVec;
    409409  info.radius = 0.;
     
    411411}
    412412
    413 GLMoleculeObject_molecule::BoundingBoxInfo GLMoleculeObject_molecule::updateBoundingBox() const
    414 {
    415   BoundingBoxInfo info = BoundingBox.get();
     413molecule::BoundingBoxInfo GLMoleculeObject_molecule::updateBoundingBox() const
     414{
     415  molecule::BoundingBoxInfo info = BoundingBox.get();
    416416  const molecule * const _molecule = getMolecule(MolIndex.get());
    417417  if (_molecule != NULL) {
     
    472472void GLMoleculeObject_molecule::resetBoundingBox()
    473473{
    474   BoundingBoxInfo info = BoundingBox.get();
     474  molecule::BoundingBoxInfo info = BoundingBox.get();
    475475  setPosition(QVector3D(info.position[0], info.position[1], info.position[2]));
    476476  setScale(info.radius + 0.3); // getBoundingSphere() only sees atoms as points, so make the box a bit bigger
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.hpp

    r9a8a6b r6a922b  
    2424#include "GLMoleculeObject_bond.hpp"
    2525
     26#include "molecule.hpp"
     27
    2628class atom;
    2729class bond;
    2830class GLMoleculeObject_atom;
    2931class GLWorldScene;
    30 class molecule;
    3132
    3233class GLMoleculeObject_molecule : public GLMoleculeObject, public Observer
     
    109110  typedef std::set<atomId_t> atoms_t;
    110111
    111   /** Structure for the required information on the bounding box.
    112    *
    113    */
    114   struct BoundingBoxInfo {
    115     //!> position of center
    116     Vector position;
    117     //!> radius of sphere
    118     double radius;
    119   };
    120 
    121   /** Structure for the required information on the tesselation hull.
    122    *
    123    */
    124   struct TesselationHullInfo {
    125   };
    126 
    127   BoundingBoxInfo initBoundingBox() const;
     112  molecule::BoundingBoxInfo initBoundingBox() const;
    128113
    129114  QGeometryData updateTesselationHull() const;
    130   BoundingBoxInfo updateBoundingBox() const;
     115  molecule::BoundingBoxInfo updateBoundingBox() const;
    131116  atoms_t updateAtoms();
    132117  moleculeId_t updateIndex() const;
     
    153138  boost::function<std::string ()> MolNameUpdater;
    154139  boost::function<QGeometryData ()> TesselationHullUpdater;
    155   boost::function<BoundingBoxInfo ()> BoundingBoxUpdater;
     140  boost::function<molecule::BoundingBoxInfo ()> BoundingBoxUpdater;
    156141  boost::function<atoms_t ()> PresentAtomsUpdater;
    157142
     
    163148  Cacheable<QGeometryData> TesselationHull;
    164149  //!> contains newest version of the bounding box on request
    165   ObservedValue<BoundingBoxInfo> BoundingBox;
     150  ObservedValue<molecule::BoundingBoxInfo> BoundingBox;
    166151  //!> contains the current live set of atoms for the molecule
    167152  ObservedValue<atoms_t> PresentAtoms;
  • src/World.cpp

    r9a8a6b r6a922b  
    396396  if (isAtomSelected(id))
    397397    selectedAtoms.erase(id);
     398  DeleteAtom(atom);
    398399  atoms.erase(id);
    399   DeleteAtom(atom);
    400400  atomIdPool.releaseId(id);
    401401  // remove molecule if empty
  • src/molecule.cpp

    r9a8a6b r6a922b  
    3636
    3737#include <algorithm>
     38#include <boost/assign.hpp>
    3839#include <boost/bind.hpp>
    3940#include <boost/foreach.hpp>
     
    5051#include "CodePatterns/enumeration.hpp"
    5152#include "CodePatterns/Log.hpp"
     53#include "CodePatterns/Observer/Observable.hpp"
    5254#include "CodePatterns/Observer/Notification.hpp"
    5355#include "config.hpp"
     
    6769#include "WorldTime.hpp"
    6870
     71using namespace boost::assign;
     72
     73// static entities
     74static Observable::channels_t getBoundingBoxChannels()
     75{
     76  Observable::channels_t channels;
     77  channels += molecule::AtomInserted, molecule::AtomRemoved, molecule::AtomMoved;
     78  return channels;
     79}
    6980
    7081/************************************* Functions for class molecule *********************************/
     
    8394  BondCount(this,boost::bind(&molecule::doCountBonds,this),"BondCount"),
    8495  atomIdPool(1, 20, 100),
     96  BoundingBoxSweepingAxis(std::vector<AtomDistanceMap_t>(NDIM)),
    8597  _lastchangedatomid(-1),
    8698  last_atom(0)
     
    92104    OurChannel->addChannel(type);
    93105
     106  // cannot initialize in initializer body as then channels have not been setup yet
     107  BoundingBox.reset(
     108      new Cacheable<BoundingBoxInfo>(
     109          this, boost::bind(&molecule::updateBoundingBox, boost::cref(this)), "molecule_BoundingBox", getBoundingBoxChannels()));
     110
    94111  strcpy(name,World::getInstance().getDefaultName().c_str());
    95 };
     112}
    96113
    97114molecule *NewMolecule(){
     
    177194  atomIds.erase( oldId );
    178195  atomIds.insert( newId );
     196  // also update BoundingBoxSweepingAxis
     197  for (int i=0;i<NDIM;++i) {
     198    AtomDistanceMap_t::left_iterator iter = BoundingBoxSweepingAxis[i].left.find(oldId);
     199    ASSERT(iter != BoundingBoxSweepingAxis[i].left.end(),
     200        "molecule::changeAtomId() - could not find atom "+toString(oldId)
     201        +" in BoundingBoxSweepingAxis.");
     202    const double component = iter->second;
     203    BoundingBoxSweepingAxis[i].left.erase(iter);
     204    BoundingBoxSweepingAxis[i].left.insert( std::make_pair(newId, component) );
     205  }
    179206  return true;
    180207}
     
    237264  atomIds.erase( _atom->getId() );
    238265  {
     266    BoundingBoxInfo oldinfo = updateBoundingBox();
     267    for (int i=0;i<NDIM;++i)
     268      BoundingBoxSweepingAxis[i].left.erase( _atom->getId() );
     269    BoundingBoxInfo newinfo = updateBoundingBox();
     270    if (oldinfo != newinfo)
     271      NOTIFY(BoundingBoxChanged);
     272  }
     273  {
    239274    NOTIFY(AtomNrChanged);
    240275    atomIdPool.releaseId(_atom->getNr());
     
    250285molecule::const_iterator molecule::erase( atom * key )
    251286{
    252   OBSERVE;
    253   {
    254     _lastchangedatomid = key->getId();
    255     NOTIFY(AtomRemoved);
    256   }
    257287  const_iterator iter = const_cast<const molecule &>(*this).find(key);
    258   if (iter != const_cast<const molecule &>(*this).end()){
    259     ++iter;
    260     atomIds.erase( key->getId() );
    261     {
    262       NOTIFY(AtomNrChanged);
    263       atomIdPool.releaseId(key->getNr());
    264       LocalToGlobalId.erase(key->getNr());
    265       key->setNr(-1);
    266     }
    267     NOTIFY(FormulaChanged);
    268     formula-=key->getType();
    269     key->removeFromMolecule();
    270   }
    271   return iter;
     288  if (iter != const_cast<const molecule &>(*this).end())
     289    return erase(iter);
     290  else
     291    return iter;
    272292}
    273293
     
    279299  std::pair<iterator,bool> res = atomIds.insert(key->getId());
    280300  if (res.second) { // push atom if went well
     301    {
     302      BoundingBoxInfo oldinfo = updateBoundingBox();
     303      for (int i=0;i<NDIM;++i)
     304        BoundingBoxSweepingAxis[i].left.insert( std::make_pair(key->getId(), key->getPosition()[i]));
     305      BoundingBoxInfo newinfo = updateBoundingBox();
     306      if (oldinfo != newinfo)
     307        NOTIFY(BoundingBoxChanged);
     308    }
    281309    NOTIFY(AtomNrChanged);
    282310    key->setNr(atomIdPool.getNextId());
     
    10481076}
    10491077
     1078molecule::BoundingBoxInfo molecule::updateBoundingBox() const
     1079{
     1080  BoundingBoxInfo info;
     1081  Vector min = zeroVec;
     1082  Vector max = zeroVec;
     1083  for (int i=0;i<NDIM;++i) {
     1084    if (!BoundingBoxSweepingAxis[i].right.empty()) {
     1085      min[i] = BoundingBoxSweepingAxis[i].right.begin()->first;
     1086      max[i] = BoundingBoxSweepingAxis[i].right.rbegin()->first;
     1087    }
     1088  }
     1089  info.radius = (.5*(max-min)).Norm();
     1090  info.position = .5*(max+min);
     1091  return info;
     1092}
     1093
     1094molecule::BoundingBoxInfo molecule::getBoundingBox() const
     1095{
     1096  return **BoundingBox;
     1097}
     1098
    10501099void molecule::update(Observable *publisher)
    10511100{
     
    10671116        // emit others about one of our atoms moved
    10681117        _lastchangedatomid = _atom->getId();
     1118        // update entry in map
     1119        BoundingBoxInfo oldinfo = updateBoundingBox();
     1120        for (int i=0;i<NDIM;++i) {
     1121          AtomDistanceMap_t::left_iterator iter = BoundingBoxSweepingAxis[i].left.find(_atom->getId());
     1122          ASSERT(iter != BoundingBoxSweepingAxis[i].left.end(),
     1123              "molecule::recieveNotification() - could not find atom "+toString(_atom->getId())
     1124              +" in BoundingBoxSweepingAxis.");
     1125          BoundingBoxSweepingAxis[i].left.erase(iter);
     1126          BoundingBoxSweepingAxis[i].left.insert(
     1127              std::make_pair(_atom->getId(), _atom->getPosition()[i]) );
     1128        }
     1129        BoundingBoxInfo newinfo = updateBoundingBox();
    10691130        OBSERVE;
    10701131        NOTIFY(AtomMoved);
     1132        if (oldinfo != newinfo)
     1133          NOTIFY(BoundingBoxChanged);
    10711134        break;
    10721135      }
  • src/molecule.hpp

    r9a8a6b r6a922b  
    2222
    2323#include <string>
     24
     25#include <boost/bimap/bimap.hpp>
     26#include <boost/bimap/unordered_set_of.hpp>
     27#include <boost/bimap/multiset_of.hpp>
     28#include <boost/optional.hpp>
     29#include <boost/shared_ptr.hpp>
    2430
    2531#include "AtomIdSet.hpp"
     
    115121    MoleculeNameChanged,
    116122    IndexChanged,
     123    BoundingBoxChanged,
    117124    AboutToBeRemoved,
    118125    NotificationType_MAX
     
    271278
    272279public:
     280
     281  /** Structure for the required information on the bounding box.
     282   *
     283   */
     284  struct BoundingBoxInfo {
     285    //!> position of center
     286    Vector position;
     287    //!> radius of sphere
     288    double radius;
     289
     290    /** Equivalence operator for bounding box.
     291     *
     292     * \return true - both bounding boxes have same position and radius
     293     */
     294    bool operator==(const BoundingBoxInfo &_other) const
     295    {  return (radius == _other.radius) && (position == _other.position); }
     296
     297    /** Inequivalence operator for bounding box.
     298     *
     299     * \return true - bounding boxes have either different positions or different radii or both
     300     */
     301    bool operator!=(const BoundingBoxInfo &_other) const
     302    { return !(*this == _other); }
     303  };
     304
     305private:
     306
     307  /** Returns the current bounding box.
     308   *
     309   * \return Shape with center and extension of box
     310   */
     311  BoundingBoxInfo updateBoundingBox() const;
     312
     313  // stuff for keeping bounding box up-to-date efficiently
     314
     315  //!> Cacheable for the bounding box, ptr such that
     316  boost::shared_ptr< Cacheable<BoundingBoxInfo> > BoundingBox;
     317  /** Bimap storing atomic ids and the component per axis.
     318   *
     319   * We need a bimap in order to have the components sorted and be able to
     320   * access max and min values in linear time and also access the ids in
     321   * constant time in order to update the map, when atoms move, are inserted,
     322   * or removed.
     323   */
     324  typedef boost::bimaps::bimap<
     325          boost::bimaps::unordered_set_of< atomId_t >,
     326          boost::bimaps::multiset_of< double, std::greater<double> >
     327      > AtomDistanceMap_t;
     328  std::vector<AtomDistanceMap_t> BoundingBoxSweepingAxis;
     329
     330public:
     331
     332  /** Returns the current bounding box of this molecule.
     333   *
     334   * \return bounding box info with center and radius
     335   */
     336  BoundingBoxInfo getBoundingBox() const;
    273337
    274338  /** Function to create a bounding spherical shape for the currently associated atoms.
Note: See TracChangeset for help on using the changeset viewer.