Changeset 897a01 for src/UIElements


Ignore:
Timestamp:
Apr 11, 2018, 6:29:56 AM (7 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
Candidate_v1.6.1, ChemicalSpaceEvaluator, Gui_displays_atomic_force_velocity, PythonUI_with_named_parameters, TremoloParser_IncreasedPrecision
Children:
8ac6d0e
Parents:
8450da
git-author:
Frederik Heber <frederik.heber@…> (08/08/17 21:26:57)
git-committer:
Frederik Heber <frederik.heber@…> (04/11/18 06:29:56)
Message:

Arrows display velocity and force of each atom.

Location:
src/UIElements
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Qt4/InstanceBoard/QtObservedAtom.cpp

    r8450da r897a01  
    8989QtObservedAtom::AtomPositionChannels(1, AtomObservable::PositionChanged);
    9090const Observable::channels_t
     91QtObservedAtom::AtomVelocityChannels(1, AtomObservable::VelocityChanged);
     92const Observable::channels_t
     93QtObservedAtom::AtomForceChannels(1, AtomObservable::ForceChanged);
     94const Observable::channels_t
    9195QtObservedAtom::AtomSelectedChannels(1, AtomObservable::SelectionChanged);
    9296
     
    124128  boost::any_cast<ObservedValue_wCallback<std::string, ObservedValue_Index_t> *>(ObservedValues[AtomName])->noteCallBackIsGone();
    125129  boost::any_cast<ObservedValue_wCallback<Vector, ObservedValue_Index_t> *>(ObservedValues[AtomPosition])->noteCallBackIsGone();
     130  boost::any_cast<ObservedValue_wCallback<Vector, ObservedValue_Index_t> *>(ObservedValues[AtomVelocity])->noteCallBackIsGone();
     131  boost::any_cast<ObservedValue_wCallback<Vector, ObservedValue_Index_t> *>(ObservedValues[AtomForce])->noteCallBackIsGone();
    126132  boost::any_cast<ObservedValue_wCallback<bool, ObservedValue_Index_t> *>(ObservedValues[AtomSelected])->noteCallBackIsGone();
    127133
     
    215221inline
    216222#endif
     223Vector QtObservedAtom::updateVelocity(
     224    const atom &_atom)
     225{
     226  return _atom.getAtomicVelocity();
     227}
     228
     229#ifdef HAVE_INLINE
     230inline
     231#endif
     232Vector QtObservedAtom::updateForce(
     233    const atom &_atom)
     234{
     235  return _atom.getAtomicForce();
     236}
     237
     238#ifdef HAVE_INLINE
     239inline
     240#endif
    217241bool QtObservedAtom::updateSelected(
    218242    const atom &_atom)
     
    269293    boost::any_cast<ObservedValue_wCallback<Vector, ObservedValue_Index_t> *>(
    270294        ObservedValues[AtomPosition])->forceUpdate();
     295    boost::any_cast<ObservedValue_wCallback<Vector, ObservedValue_Index_t> *>(
     296        ObservedValues[AtomVelocity])->forceUpdate();
     297    boost::any_cast<ObservedValue_wCallback<Vector, ObservedValue_Index_t> *>(
     298        ObservedValues[AtomForce])->forceUpdate();
    271299    boost::any_cast<ObservedValue_wCallback<QtObservedMolecule*, ObservedValue_Index_t> *>(
    272300        ObservedValues[MoleculeRef])->forceUpdate();
    273301    // then tell Qt part about updates
    274302    emit positionChanged();
     303    emit velocityChanged();
     304    emit forceChanged();
    275305    emit moleculeChanged();
    276306  } else {
     
    296326      case AtomObservable::PositionChanged:
    297327        emit positionChanged();
     328        break;
     329      case AtomObservable::VelocityChanged:
     330        emit velocityChanged();
     331        break;
     332      case AtomObservable::ForceChanged:
     333        emit forceChanged();
    298334        break;
    299335      case AtomObservable::SelectionChanged:
     
    362398  const boost::function<Vector ()> AtomPositionUpdater(
    363399      boost::bind(&QtObservedAtom::updatePosition, boost::cref(*_atomref)));
     400  const boost::function<Vector ()> AtomVelocityUpdater(
     401      boost::bind(&QtObservedAtom::updateVelocity, boost::cref(*_atomref)));
     402  const boost::function<Vector ()> AtomForceUpdater(
     403      boost::bind(&QtObservedAtom::updateForce, boost::cref(*_atomref)));
    364404  const boost::function<bool ()> AtomSelectedUpdater(
    365405      boost::bind(&QtObservedAtom::updateSelected, boost::cref(*_atomref)));
     
    401441      AtomPositionUpdater(),
    402442      AtomPositionChannels,
     443      _subjectKilled);
     444  _ObservedValues[AtomVelocity] = new ObservedValue_wCallback<Vector, ObservedValue_Index_t>(
     445      _atomref,
     446      AtomVelocityUpdater,
     447      "AtomVelocity_"+toString(_id),
     448      AtomVelocityUpdater(),
     449      AtomVelocityChannels,
     450      _subjectKilled);
     451  _ObservedValues[AtomForce] = new ObservedValue_wCallback<Vector, ObservedValue_Index_t>(
     452      _atomref,
     453      AtomForceUpdater,
     454      "AtomForce_"+toString(_id),
     455      AtomForceUpdater(),
     456      AtomForceChannels,
    403457      _subjectKilled);
    404458  _ObservedValues[AtomSelected] = new ObservedValue_wCallback<bool, ObservedValue_Index_t>(
     
    426480  delete boost::any_cast<ObservedValue_wCallback<std::string, ObservedValue_Index_t> *>(_ObservedValues[AtomName]);
    427481  delete boost::any_cast<ObservedValue_wCallback<Vector, ObservedValue_Index_t> *>(_ObservedValues[AtomPosition]);
     482  delete boost::any_cast<ObservedValue_wCallback<Vector, ObservedValue_Index_t> *>(_ObservedValues[AtomVelocity]);
     483  delete boost::any_cast<ObservedValue_wCallback<Vector, ObservedValue_Index_t> *>(_ObservedValues[AtomForce]);
    428484  delete boost::any_cast<ObservedValue_wCallback<bool, ObservedValue_Index_t> *>(_ObservedValues[AtomSelected]);
    429485  delete boost::any_cast<ObservedValue_wCallback<QtObservedMolecule*, ObservedValue_Index_t> *>(_ObservedValues[MoleculeRef]);
     
    463519}
    464520
     521const Vector& QtObservedAtom::getAtomVelocity() const
     522{
     523  return boost::any_cast<ObservedValue_wCallback<Vector, ObservedValue_Index_t> *>(ObservedValues[AtomVelocity])->get();
     524}
     525
     526const Vector& QtObservedAtom::getAtomForce() const
     527{
     528  return boost::any_cast<ObservedValue_wCallback<Vector, ObservedValue_Index_t> *>(ObservedValues[AtomForce])->get();
     529}
     530
    465531const bool QtObservedAtom::getAtomSelected() const
    466532{
  • src/UIElements/Qt4/InstanceBoard/QtObservedAtom.hpp

    r8450da r897a01  
    136136  const Vector& getAtomPosition() const;
    137137
     138  /** Getter to atom velocity contained in \a ObservedValues.
     139   *
     140   * \return atom's velocity
     141   */
     142  const Vector& getAtomVelocity() const;
     143
     144  /** Getter to atom force contained in \a ObservedValues.
     145   *
     146   * \return atom's force
     147   */
     148  const Vector& getAtomForce() const;
     149
    138150  /** Getter to the observed state of the associated molecule.
    139151   *
     
    155167  void nameChanged();
    156168  void positionChanged();
     169  void velocityChanged();
     170  void forceChanged();
    157171  void atomRemoved();
    158172  void selectedChanged();
     
    174188  static std::string updateName(const atom &_atom);
    175189  static Vector updatePosition(const atom &_atom);
     190  static Vector updateVelocity(const atom &_atom);
     191  static Vector updateForce(const atom &_atom);
    176192  static bool updateSelected(const atom &_atom);
    177193
     
    188204    //!> contains the current atom position
    189205    AtomPosition,
     206    //!> contains the current atom velocity
     207    AtomVelocity,
     208    //!> contains the current atom force
     209    AtomForce,
    190210    //!> contains the current atom's selection status
    191211    AtomSelected,
     
    253273  //!> list of channels when position needs to update
    254274  static const Observable::channels_t AtomPositionChannels;
     275  //!> list of channels when velocity needs to update
     276  static const Observable::channels_t AtomVelocityChannels;
     277  //!> list of channels when force needs to update
     278  static const Observable::channels_t AtomForceChannels;
    255279  //!> list of channels when selection needs to update
    256280  static const Observable::channels_t AtomSelectedChannels;
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject.cpp

    r8450da r897a01  
    6161QGLMaterial *GLMoleculeObject::m_selectionMaterial = NULL;
    6262QGLMaterial *GLMoleculeObject::m_selectionBoxMaterial = NULL;
     63QGLMaterial *GLMoleculeObject::m_velocityMaterial = NULL;
     64QGLMaterial *GLMoleculeObject::m_forceMaterial = NULL;
    6365
    6466QGLSceneNode *GLMoleculeObject::meshEmpty[GLMoleculeObject::DETAILTYPES_MAX];
    6567QGLSceneNode *GLMoleculeObject::meshSphere[GLMoleculeObject::DETAILTYPES_MAX];
    6668QGLSceneNode *GLMoleculeObject::meshCylinder[GLMoleculeObject::DETAILTYPES_MAX];
     69QGLSceneNode *GLMoleculeObject::meshArrow[GLMoleculeObject::DETAILTYPES_MAX];
    6770
    6871double GLMoleculeObject::detailMinDistance[GLMoleculeObject::DETAILTYPES_MAX] = {0, 15, 30, 42};
     
    309312    m_selectionBoxMaterial->setEmittedLight( QColor(155, 50, 50) );
    310313  }
     314  if (!m_velocityMaterial){
     315    m_velocityMaterial = new QGLMaterial(NULL);
     316    QColor colorvelocity(50,50,255,255);
     317    m_velocityMaterial->setColor(colorvelocity);
     318  }
     319  if (!m_forceMaterial){
     320    m_forceMaterial = new QGLMaterial(NULL);
     321    QColor colorforce(50,255,50,255);
     322    m_forceMaterial->setColor(colorforce);
     323  }
    311324}
    312325
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject.hpp

    r8450da r897a01  
    108108   static QGLSceneNode *meshSphere[DETAILTYPES_MAX];
    109109   static QGLSceneNode *meshCylinder[DETAILTYPES_MAX];
     110   static QGLSceneNode *meshArrow[DETAILTYPES_MAX];
    110111
    111112protected:
     
    130131   static QGLMaterial *m_selectionMaterial;
    131132   static QGLMaterial *m_selectionBoxMaterial;
     133   static QGLMaterial *m_velocityMaterial;
     134   static QGLMaterial *m_forceMaterial;
    132135   QGLAbstractEffect *m_effect;
    133136   int m_objectId;
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.cpp

    r8450da r897a01  
    5050#include "Element/element.hpp"
    5151#include "Element/periodentafel.hpp"
     52#include "LinearAlgebra/Line.hpp"
    5253#include "LinearAlgebra/Vector.hpp"
    5354#include "UIElements/Views/Qt4/Qt3D/GLMoleculeObject_bond.hpp"
     
    5758GLMoleculeObject_atom::GLMoleculeObject_atom(
    5859    QGLSceneNode *mesh[],
     60    QGLSceneNode *mesharrow[],
    5961    QObject *parent,
    6062    QtObservedAtom::ptr &_ObservedAtom) :
    6163  GLMoleculeObject(mesh, parent),
     64  GLMoleculeObjectVelocity(mesharrow, this),
     65  GLMoleculeObjectForce(mesharrow, this),
    6266  ObservedAtom(_ObservedAtom)
    6367{
     
    6973  setObjectId(_id);
    7074  resetPosition();
     75  resetVelocity();
     76  resetForce();
    7177  resetElement();
     78
     79  GLMoleculeObjectVelocity.setMaterial(GLMoleculeObject::m_velocityMaterial);
     80  GLMoleculeObjectForce.setMaterial(GLMoleculeObject::m_forceMaterial);
    7281
    7382  m_selected = ObservedAtom->getAtomSelected();
     
    7786  connect( ObservedAtom.get(), SIGNAL(elementChanged()), this, SLOT(resetElement()));
    7887  connect( ObservedAtom.get(), SIGNAL(positionChanged()), this, SLOT(resetPosition()));
     88  connect( ObservedAtom.get(), SIGNAL(velocityChanged()), this, SLOT(resetVelocity()));
     89  connect( ObservedAtom.get(), SIGNAL(forceChanged()), this, SLOT(resetForce()));
    7990  connect( ObservedAtom.get(), SIGNAL(selectedChanged()), this, SLOT(resetSelected()));
    8091}
     
    95106}
    96107
     108static void setArrow(
     109    const Vector &_position,
     110    const Vector &_arrow,
     111    const double _offset,
     112    GLMoleculeObject &_obj)
     113{
     114  // set position (cylinder offset is in its barymetric center)
     115  Vector OneFourth(_position + (_offset/_arrow.Norm()+.75) * _arrow);
     116  _obj.setPosition(QVector3D(OneFourth[0], OneFourth[1], OneFourth[2]));
     117}
     118
    97119void GLMoleculeObject_atom::resetPosition()
    98120{
     
    100122  LOG(4, "INFO: GLMoleculeObject_atom::resetPosition() - new position is "+toString(Position)+".");
    101123  setPosition(QVector3D(Position[0], Position[1], Position[2]));
     124  setArrow(Position, 10.*ObservedAtom->getAtomVelocity(), scaleX(), GLMoleculeObjectVelocity);
     125  setArrow(Position, 10.*ObservedAtom->getAtomForce(), scaleX(), GLMoleculeObjectForce);
     126}
     127
     128static void alignArrow(
     129    const Vector &_arrow,
     130    GLMoleculeObject &_obj)
     131{
     132  if (_arrow.IsZero()) {
     133    _obj.setScaleZ(0.);
     134    return;
     135  }
     136  // calculate position
     137  Vector Z(unitVec[2]); // cylinder are initially aligned along the Z axis
     138  Vector b;
     139  Vector OtherAxis;
     140  double alpha;
     141  // construct rotation axis
     142  b = -1.*_arrow;
     143  b.VectorProduct(Z);
     144  Line axis(zeroVec, b);
     145  // calculate rotation angle
     146  alpha = _arrow.Angle(Z);
     147  // construct other axis to check right-hand rule
     148  OtherAxis = b;
     149  OtherAxis.VectorProduct(Z);
     150  // assure right-hand rule for the rotation
     151  if (_arrow.ScalarProduct(OtherAxis) < MYEPSILON)
     152    alpha = M_PI-alpha;
     153  // check
     154  Vector a_rotated = axis.rotateVector(_arrow, alpha);
     155  LOG(5, "DEBUG: Aligning arrow " << _arrow << " to " << a_rotated
     156      << " around " << b << " by " << alpha/M_PI*180. << ".");
     157
     158  _obj.setScaleZ(10.*_arrow.Norm());
     159  _obj.setRotationVector(QVector3D(b[0], b[1], b[2]));
     160  _obj.setRotationAngle(alpha/M_PI*180.);
     161}
     162
     163void GLMoleculeObject_atom::resetVelocity()
     164{
     165  const Vector Velocity = ObservedAtom->getAtomVelocity();
     166  LOG(4, "INFO: GLMoleculeObject_atom::resetVelocity() - new velocity is "+toString(Velocity)+".");
     167  alignArrow(Velocity, GLMoleculeObjectVelocity);
     168//  GLMoleculeObjectForce.setScaleZ(Velocity.Norm());
     169}
     170
     171void GLMoleculeObject_atom::resetForce()
     172{
     173  const Vector Force = ObservedAtom->getAtomForce();
     174  LOG(4, "INFO: GLMoleculeObject_atom::resetForce() - new force is "+toString(Force)+".");
     175  alignArrow(Force, GLMoleculeObjectForce);
     176//  GLMoleculeObjectForce.setScaleZ(Force.Norm());
    102177}
    103178
     
    144219  // call old hook to do the actual paining
    145220  GLMoleculeObject::draw(painter, cameraPlane);
     221  GLMoleculeObjectVelocity.draw(painter, cameraPlane);
     222  GLMoleculeObjectForce.draw(painter, cameraPlane);
    146223}
    147224
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_atom.hpp

    r8450da r897a01  
    3434  GLMoleculeObject_atom(
    3535      QGLSceneNode *mesh[],
     36      QGLSceneNode *mesharrow[],
    3637      QObject *parent,
    3738      QtObservedAtom::ptr &_ObservedAtom
     
    4647  void resetElement();
    4748  void resetPosition();
     49  void resetVelocity();
     50  void resetForce();
    4851  void resetSelected();
    4952
     
    5861
    5962private:
     63  //!> internal GLMoleculeObject to represent the atom's velocity as an arrow
     64  GLMoleculeObject GLMoleculeObjectVelocity;
     65  //!> internal GLMoleculeObject to represent the atom's force as an arrow
     66  GLMoleculeObject GLMoleculeObjectForce;
     67
    6068  //!> current list of bonds to compare new onw against for changes
    6169  QtObservedAtom::ListOfBonds_t ListOfBonds;
  • src/UIElements/Views/Qt4/Qt3D/GLWorldScene.cpp

    r8450da r897a01  
    154154  int sphereDetails[] = {5, 3, 2, 0};
    155155  int cylinderDetails[] = {16, 8, 6, 3};
     156  int arrowDetails[] = {8, 5, 3, 0};
    156157  for (int i=0;i<GLMoleculeObject::DETAILTYPES_MAX;i++){
    157158    QGLBuilder emptyBuilder;
     
    165166    GLMoleculeObject::meshCylinder[i] = cylinderBuilder.finalizedSceneNode();
    166167    GLMoleculeObject::meshCylinder[i]->setOption(QGLSceneNode::CullBoundingBox, true);
     168    {
     169      QGLBuilder builderCyl;
     170      builderCyl << QGLCylinder(.15,.15,1.6,arrowDetails[i]);
     171      QGLSceneNode *cyl = builderCyl.finalizedSceneNode();
     172      QGLBuilder builderCone;
     173      builderCone << QGLCylinder(0,.4,0.4,arrowDetails[i]);
     174      QGLSceneNode *cone = builderCone.finalizedSceneNode();
     175      {
     176        QMatrix4x4 mat;
     177        mat.translate(0.0f, 0.0f, 1.0f);
     178        cone->setLocalTransform(mat);
     179      }
     180      GLMoleculeObject::meshArrow[i] = new QGLSceneNode(this);
     181      GLMoleculeObject::meshArrow[i]->addNode(cyl);
     182      GLMoleculeObject::meshArrow[i]->addNode(cone);
     183    }
     184    GLMoleculeObject::meshArrow[i]->setOption(QGLSceneNode::CullBoundingBox, true);
    167185  }
    168186  connect(board, SIGNAL(moleculeInserted(QtObservedMolecule::ptr)),
     
    279297    atomObject = new GLMoleculeObject_atom(
    280298            GLMoleculeObject::meshSphere,
     299            GLMoleculeObject::meshArrow,
    281300            parent,
    282301            _atom);
  • src/UIElements/Views/Qt4/QtInfoBox.cpp

    r8450da r897a01  
    6565
    6666  setMinimumWidth(200);
    67   setMinimumHeight(220);
     67  setMinimumHeight(350);
    6868
    6969  connect(timer, SIGNAL(timeout()), this, SLOT(timerTimeout()));
     
    220220  addInfo(this, "Position y", QString(toString(atomRef->getAtomPosition()[1]).c_str()));
    221221  addInfo(this, "Position z", QString(toString(atomRef->getAtomPosition()[2]).c_str()));
     222  addInfo(this, "Velocity x", QString(toString(atomRef->getAtomVelocity()[0]).c_str()));
     223  addInfo(this, "Velocity y", QString(toString(atomRef->getAtomVelocity()[1]).c_str()));
     224  addInfo(this, "Velocity z", QString(toString(atomRef->getAtomVelocity()[2]).c_str()));
     225  addInfo(this, "Force x", QString(toString(atomRef->getAtomForce()[0]).c_str()));
     226  addInfo(this, "Force y", QString(toString(atomRef->getAtomForce()[1]).c_str()));
     227  addInfo(this, "Force z", QString(toString(atomRef->getAtomForce()[2]).c_str()));
    222228}
    223229
Note: See TracChangeset for help on using the changeset viewer.