Changeset 34e7fdb


Ignore:
Timestamp:
Jan 10, 2015, 5:14:32 PM (10 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
c32d21
Parents:
739ee9
git-author:
Frederik Heber <heber@…> (11/05/14 23:22:55)
git-committer:
Frederik Heber <heber@…> (01/10/15 17:14:32)
Message:

GLMoleculeObject_molecule display tesselated surface in m_visible case.

  • set TesselationHull radius to 2., independent of mol's bounding sphere.
  • added bool to indicate when subjectKilled() had been called.
Location:
src/UIElements/Views/Qt4
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject.cpp

    r739ee9 r34e7fdb  
    7272{
    7373   //mesh->setParent(this);
    74    for (int i=0;i<DETAILTYPES_MAX;i++)
    75      m_mesh[i] = mesh[i];
     74  for (int i=0;i<DETAILTYPES_MAX;i++)
     75    m_mesh[i] = mesh[i];
    7676   m_scaleX = 1.0f;
    7777   m_scaleY = 1.0f;
     
    9191{
    9292   //mesh->setParent(this);
    93    for (int i=0;i<DETAILTYPES_MAX;i++)
    94      m_mesh[i] = mesh;
     93  for (int i=0;i<DETAILTYPES_MAX;i++)
     94    m_mesh[i] = mesh;
    9595   m_scaleX = 1.0f;
    9696   m_scaleY = 1.0f;
     
    108108   : QObject(parent)
    109109{
    110    scene->setParent(this);
    111    for (int i=0;i<DETAILTYPES_MAX;i++)
    112      m_mesh[i] = scene->mainNode();
     110  for (int i=0;i<DETAILTYPES_MAX;i++)
     111    m_mesh[i] = scene->mainNode();
    113112   m_scaleX = 1.0f;
    114113   m_scaleY = 1.0f;
     
    337336  }
    338337}
     338
     339void GLMoleculeObject::updateMesh(QGLSceneNode *mesh)
     340{
     341  if (m_mesh[0] != NULL) {
     342    if (m_mesh[0] != m_mesh[1]) {
     343      for (int i=0;i<DETAILTYPES_MAX;i++)
     344        delete m_mesh[i];
     345    } else {
     346      delete m_mesh[0];
     347    }
     348  }
     349  for (int i=0;i<DETAILTYPES_MAX;i++)
     350    m_mesh[i] = mesh;
     351}
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject.hpp

    r739ee9 r34e7fdb  
    7575
    7676   bool visible() const { return m_visible; }
    77    void setVisible(bool value);
     77   virtual void setVisible(bool value);
    7878
    7979   void initStaticMaterials();
     
    9696   static QGLMaterial* getMaterial(size_t);
    9797   static void cleanMaterialMap();
     98
     99   void updateMesh(QGLSceneNode *scene);
    98100
    99101   typedef std::map< size_t, QGLMaterial *> ElementMaterialMap;
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.cpp

    r739ee9 r34e7fdb  
    4141
    4242#include <Qt3D/qglscenenode.h>
     43#include <Qt3D/qglbuilder.h>
    4344
    4445#include "CodePatterns/MemDebug.hpp"
     
    5455#include "Element/element.hpp"
    5556#include "LinearAlgebra/Vector.hpp"
     57#include "LinkedCell/PointCloudAdaptor.hpp"
     58#include "LinkedCell/linkedcell.hpp"
     59#include "Tesselation/tesselation.hpp"
     60#include "Tesselation/BoundaryLineSet.hpp"
     61#include "Tesselation/BoundaryTriangleSet.hpp"
     62#include "Tesselation/CandidateForTesselation.hpp"
     63#include "Atom/TesselPoint.hpp"
    5664#include "World.hpp"
    5765
    5866#include "GLMoleculeObject_atom.hpp"
    5967
    60 GLMoleculeObject_molecule::GLMoleculeObject_molecule(QGLSceneNode *mesh[], QObject *parent, const molecule *molref) :
    61   GLMoleculeObject(mesh, parent),
     68static QGLSceneNode *createMoleculeMesh(const molecule *molref, QObject *parent)
     69{
     70//  Shape shape = molref->getBoundingSphere();
     71  double minradius = 2.; // TODO: set to maximum bond length value
     72  LOG(3, "DEBUG: Molecule fits into sphere of radius " << minradius);
     73  if (minradius < 1.)
     74    minradius = 1.;
     75
     76  QGeometryData geo;
     77  // we need at least three points for tesselation
     78  if (molref->getAtomCount() >= 3) {
     79    // Tesselate the points.
     80    Tesselation T;
     81    PointCloudAdaptor<molecule> cloud(const_cast<molecule *>(molref), molref->getName());
     82    T(cloud, minradius);
     83
     84    // Fill the points into a Qt geometry.
     85    LinkedCell_deprecated LinkedList(cloud, minradius);
     86    std::map<int, int> indices;
     87    std::map<int, Vector> normals;
     88    int index = 0;
     89    for (PointMap::const_iterator piter = T.PointsOnBoundary.begin();
     90        piter != T.PointsOnBoundary.end(); ++piter) {
     91      const Vector &point = piter->second->getPosition();
     92      // add data to the primitive
     93      geo.appendVertex(QVector3D(point[0], point[1], point[2]));
     94      Vector normalvector;
     95      for (LineMap::const_iterator lineiter = piter->second->lines.begin();
     96          lineiter != piter->second->lines.end(); ++lineiter)
     97        for (TriangleMap::const_iterator triangleiter = lineiter->second->triangles.begin();
     98            triangleiter != lineiter->second->triangles.end(); ++triangleiter)
     99          normalvector +=
     100              triangleiter->second->NormalVector;
     101      normalvector.Normalize();
     102      geo.appendNormal(QVector3D(normalvector[0], normalvector[1], normalvector[2]));
     103      geo.appendColor(QColor(1, 1, 1, 1));
     104      geo.appendTexCoord(QVector2D(0, 0));
     105      indices.insert( std::make_pair( piter->second->getNr(), index++));
     106    }
     107
     108    // Fill the tesselated triangles into the geometry.
     109    for (TriangleMap::const_iterator runner = T.TrianglesOnBoundary.begin();
     110        runner != T.TrianglesOnBoundary.end(); runner++) {
     111      int v[3];
     112      for (size_t i=0; i<3; ++i)
     113        v[i] = runner->second->endpoints[i]->getNr();
     114
     115      // Sort the vertices so the triangle is clockwise (relative to the normal vector).
     116      Vector cross = T.PointsOnBoundary[v[1]]->getPosition() - T.PointsOnBoundary[v[0]]->getPosition();
     117      cross.VectorProduct(T.PointsOnBoundary[v[2]]->getPosition() - T.PointsOnBoundary[v[0]]->getPosition());
     118      if (cross.ScalarProduct(runner->second->NormalVector) > 0)
     119        geo.appendIndices(indices[v[0]], indices[v[1]], indices[v[2]]);
     120      else
     121        geo.appendIndices(indices[v[0]], indices[v[2]], indices[v[1]]);
     122    }
     123  }
     124
     125  // Build a mesh from the geometry.
     126  QGLBuilder builder;
     127  builder.addTriangles(geo);
     128  QGLSceneNode *mesh = builder.finalizedSceneNode();
     129  return mesh;
     130}
     131
     132GLMoleculeObject_molecule::GLMoleculeObject_molecule(QObject *parent, const molecule *molref) :
     133  GLMoleculeObject(createMoleculeMesh(molref, parent), parent),
    62134  Observer(std::string("GLMoleculeObject_molecule")+toString(molref->getId())),
     135  isSignedOn(false),
    63136  _molecule(molref),
    64137  hoverAtom(NULL)
     
    67140  _molecule->signOn(this, molecule::AtomInserted);
    68141  _molecule->signOn(this, molecule::AtomRemoved);
     142  isSignedOn = true;
    69143  /*molref->signOn(this, AtomObservable::IndexChanged);
    70144  molref->signOn(this, AtomObservable::PositionChanged);
     
    81155}
    82156
     157GLMoleculeObject_molecule::GLMoleculeObject_molecule(QGLSceneNode *mesh[], QObject *parent, const molecule *molref) :
     158  GLMoleculeObject(mesh, parent),
     159  Observer(std::string("GLMoleculeObject_molecule")+toString(molref->getId())),
     160  isSignedOn(false),
     161  _molecule(molref),
     162  hoverAtom(NULL)
     163{
     164  // sign on as observer (obtain non-const instance before)
     165  _molecule->signOn(this, molecule::AtomInserted);
     166  _molecule->signOn(this, molecule::AtomRemoved);
     167  isSignedOn = true;
     168  /*molref->signOn(this, AtomObservable::IndexChanged);
     169  molref->signOn(this, AtomObservable::PositionChanged);
     170  molref->signOn(this, AtomObservable::ElementChanged);
     171  molref->signOn(this, AtomObservable::BondsAdded);*/
     172  setMaterial(getMaterial(1));
     173  World::getInstance().signOn(this, World::SelectionChanged);
     174  updateBoundingBox();
     175
     176  // initially, atoms and bonds should be visible
     177  m_visible = false;
     178
     179  init();
     180}
     181
    83182GLMoleculeObject_molecule::~GLMoleculeObject_molecule()
    84183{
    85   _molecule->signOff(this, molecule::AtomInserted);
    86   _molecule->signOff(this, molecule::AtomRemoved);
     184  if (isSignedOn) {
     185    _molecule->signOff(this, molecule::AtomInserted);
     186    _molecule->signOff(this, molecule::AtomRemoved);
     187  }
    87188  /*_atom->signOff(this, AtomObservable::IndexChanged);
    88189  _atom->signOff(this, AtomObservable::PositionChanged);
     
    196297
    197298void GLMoleculeObject_molecule::subjectKilled(Observable *publisher)
    198 {}
     299{
     300  isSignedOn = false;
     301}
    199302
    200303void GLMoleculeObject_molecule::recieveNotification(Observable *publisher, Notification_ptr notification)
     
    249352{
    250353  // Initialize all of the mesh objects that we have as children.
    251 //  GLMoleculeObject::initialize(view, painter);
     354  GLMoleculeObject::initialize(view, painter);
    252355   foreach (QObject *obj, children()) {
    253356     GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj);
     
    261364  // draw either molecule's mesh or all atoms and bonds
    262365  if (m_visible) {
    263     GLMoleculeObject::draw(painter, cameraPlane);
     366    painter->modelViewMatrix().push();
     367
     368    // Apply the material and effect to the painter.
     369    QGLMaterial *material;
     370    if (m_hovering)
     371        material = m_hoverMaterial;
     372    else if (m_selected)
     373        material = m_selectionMaterial;
     374    else
     375        material = m_material;
     376
     377    ASSERT(material, "GLMoleculeObject::draw: chosen material is NULL");
     378
     379    painter->setColor(material->diffuseColor());
     380    painter->setFaceMaterial(QGL::AllFaces, material);
     381    if (m_effect)
     382        painter->setUserEffect(m_effect);
     383    else
     384        painter->setStandardEffect(QGL::LitMaterial);
     385
     386    // Mark the object for object picking purposes.
     387    int prevObjectId = painter->objectPickId();
     388    if (m_objectId != -1)
     389        painter->setObjectPickId(m_objectId);
     390
     391    m_mesh[0]->draw(painter);
     392
     393    // Draw a box around the mesh, if selected.
     394    if (m_selected)
     395      drawSelectionBox(painter);
     396
     397    // Turn off the user effect, if present.
     398    if (m_effect)
     399        painter->setStandardEffect(QGL::LitMaterial);
     400
     401    // Revert to the previous object identifier.
     402    painter->setObjectPickId(prevObjectId);
     403
     404    // Restore the modelview matrix.
     405    painter->modelViewMatrix().pop();
     406
     407    //    GLMoleculeObject::draw(painter, cameraPlane);
    264408  } else {
    265409    // Draw all of the mesh objects that we have as children.
     
    415559}
    416560
     561void GLMoleculeObject_molecule::setVisible(bool value)
     562{
     563  // first update the mesh if we are going to be visible now
     564  if (value)
     565    updateMesh(createMoleculeMesh(_molecule, parent()));
     566  // then emit onward
     567  GLMoleculeObject::setVisible(value);
     568}
     569
    417570std::ostream &operator<<(std::ostream &ost, const GLMoleculeObject_molecule::BondIds &t)
    418571{
     
    420573  return ost;
    421574}
     575
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.hpp

    r739ee9 r34e7fdb  
    3030  Q_OBJECT
    3131public:
     32  GLMoleculeObject_molecule(QObject *parent, const molecule *molref);
    3233  GLMoleculeObject_molecule(QGLSceneNode *mesh[], QObject *parent, const molecule *molref);
    3334  virtual ~GLMoleculeObject_molecule();
     
    7071  void hoverChangedSignalled(GLMoleculeObject *ob);
    7172
     73  void setVisible(bool value);
     74
    7275private:
    7376  void init();
     
    8285  //!> states whether selection box is additionally drawn or not
    8386  bool isSelected;
     87
     88  //!> whether we are signed on to the associated molecule
     89  bool isSignedOn;
    8490
    8591  const molecule *_molecule;
  • src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_shape.cpp

    r739ee9 r34e7fdb  
    6363typedef QGLSceneNode *MeshList[GLMoleculeObject::DETAILTYPES_MAX];
    6464
    65 QGLSceneNode *createShapeMesh(Shape &shape, QObject *parent)
     65static QGLSceneNode *createShapeMesh(Shape &shape, QObject *parent)
    6666{
    6767  size_t NumPointsonSurface = 200;
  • src/UIElements/Views/Qt4/QtMoleculeList.cpp

    r739ee9 r34e7fdb  
    148148    molItem->setSelected(World::getInstance().isSelected(*iter));
    149149
    150 
    151150    // increase group occurrence
    152151    int count = groupItem->text(4).toInt() + 1;
Note: See TracChangeset for help on using the changeset viewer.