Changeset 34e7fdb
- Timestamp:
- Jan 10, 2015, 5:14:32 PM (10 years ago)
- 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)
- Location:
- src/UIElements/Views/Qt4
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject.cpp
r739ee9 r34e7fdb 72 72 { 73 73 //mesh->setParent(this); 74 75 74 for (int i=0;i<DETAILTYPES_MAX;i++) 75 m_mesh[i] = mesh[i]; 76 76 m_scaleX = 1.0f; 77 77 m_scaleY = 1.0f; … … 91 91 { 92 92 //mesh->setParent(this); 93 94 93 for (int i=0;i<DETAILTYPES_MAX;i++) 94 m_mesh[i] = mesh; 95 95 m_scaleX = 1.0f; 96 96 m_scaleY = 1.0f; … … 108 108 : QObject(parent) 109 109 { 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(); 113 112 m_scaleX = 1.0f; 114 113 m_scaleY = 1.0f; … … 337 336 } 338 337 } 338 339 void 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 75 75 76 76 bool visible() const { return m_visible; } 77 v oid setVisible(bool value);77 virtual void setVisible(bool value); 78 78 79 79 void initStaticMaterials(); … … 96 96 static QGLMaterial* getMaterial(size_t); 97 97 static void cleanMaterialMap(); 98 99 void updateMesh(QGLSceneNode *scene); 98 100 99 101 typedef std::map< size_t, QGLMaterial *> ElementMaterialMap; -
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.cpp
r739ee9 r34e7fdb 41 41 42 42 #include <Qt3D/qglscenenode.h> 43 #include <Qt3D/qglbuilder.h> 43 44 44 45 #include "CodePatterns/MemDebug.hpp" … … 54 55 #include "Element/element.hpp" 55 56 #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" 56 64 #include "World.hpp" 57 65 58 66 #include "GLMoleculeObject_atom.hpp" 59 67 60 GLMoleculeObject_molecule::GLMoleculeObject_molecule(QGLSceneNode *mesh[], QObject *parent, const molecule *molref) : 61 GLMoleculeObject(mesh, parent), 68 static 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 132 GLMoleculeObject_molecule::GLMoleculeObject_molecule(QObject *parent, const molecule *molref) : 133 GLMoleculeObject(createMoleculeMesh(molref, parent), parent), 62 134 Observer(std::string("GLMoleculeObject_molecule")+toString(molref->getId())), 135 isSignedOn(false), 63 136 _molecule(molref), 64 137 hoverAtom(NULL) … … 67 140 _molecule->signOn(this, molecule::AtomInserted); 68 141 _molecule->signOn(this, molecule::AtomRemoved); 142 isSignedOn = true; 69 143 /*molref->signOn(this, AtomObservable::IndexChanged); 70 144 molref->signOn(this, AtomObservable::PositionChanged); … … 81 155 } 82 156 157 GLMoleculeObject_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 83 182 GLMoleculeObject_molecule::~GLMoleculeObject_molecule() 84 183 { 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 } 87 188 /*_atom->signOff(this, AtomObservable::IndexChanged); 88 189 _atom->signOff(this, AtomObservable::PositionChanged); … … 196 297 197 298 void GLMoleculeObject_molecule::subjectKilled(Observable *publisher) 198 {} 299 { 300 isSignedOn = false; 301 } 199 302 200 303 void GLMoleculeObject_molecule::recieveNotification(Observable *publisher, Notification_ptr notification) … … 249 352 { 250 353 // Initialize all of the mesh objects that we have as children. 251 //GLMoleculeObject::initialize(view, painter);354 GLMoleculeObject::initialize(view, painter); 252 355 foreach (QObject *obj, children()) { 253 356 GLMoleculeObject *meshobj = qobject_cast<GLMoleculeObject *>(obj); … … 261 364 // draw either molecule's mesh or all atoms and bonds 262 365 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); 264 408 } else { 265 409 // Draw all of the mesh objects that we have as children. … … 415 559 } 416 560 561 void 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 417 570 std::ostream &operator<<(std::ostream &ost, const GLMoleculeObject_molecule::BondIds &t) 418 571 { … … 420 573 return ost; 421 574 } 575 -
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_molecule.hpp
r739ee9 r34e7fdb 30 30 Q_OBJECT 31 31 public: 32 GLMoleculeObject_molecule(QObject *parent, const molecule *molref); 32 33 GLMoleculeObject_molecule(QGLSceneNode *mesh[], QObject *parent, const molecule *molref); 33 34 virtual ~GLMoleculeObject_molecule(); … … 70 71 void hoverChangedSignalled(GLMoleculeObject *ob); 71 72 73 void setVisible(bool value); 74 72 75 private: 73 76 void init(); … … 82 85 //!> states whether selection box is additionally drawn or not 83 86 bool isSelected; 87 88 //!> whether we are signed on to the associated molecule 89 bool isSignedOn; 84 90 85 91 const molecule *_molecule; -
src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_shape.cpp
r739ee9 r34e7fdb 63 63 typedef QGLSceneNode *MeshList[GLMoleculeObject::DETAILTYPES_MAX]; 64 64 65 QGLSceneNode *createShapeMesh(Shape &shape, QObject *parent)65 static QGLSceneNode *createShapeMesh(Shape &shape, QObject *parent) 66 66 { 67 67 size_t NumPointsonSurface = 200; -
src/UIElements/Views/Qt4/QtMoleculeList.cpp
r739ee9 r34e7fdb 148 148 molItem->setSelected(World::getInstance().isSelected(*iter)); 149 149 150 151 150 // increase group occurrence 152 151 int count = groupItem->text(4).toInt() + 1;
Note:
See TracChangeset
for help on using the changeset viewer.