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/Views/Qt4
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • 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.