source: src/UIElements/Views/Qt4/Qt3D/GLMoleculeObject_shape.cpp@ afd3d2

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
Last change on this file since afd3d2 was afd3d2, checked in by Frederik Heber <heber@…>, 12 years ago

GLMoleculeObject_shape added

  • Property mode set to 100644
File size: 4.3 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * GLMoleculeObject_shape.cpp
25 *
26 * Created on: Aug 3, 2012
27 * Author: ankele
28 */
29
30
31
32// include config.h
33#ifdef HAVE_CONFIG_H
34#include <config.h>
35#endif
36
37#include "GLMoleculeObject_shape.hpp"
38
39#include <Qt3D/qglview.h>
40#include <Qt3D/qglscenenode.h>
41#include <Qt3D/qglpainter.h>
42#include <Qt3D/qglmaterial.h>
43#include <Qt3D/qglbuilder.h>
44#include <Qt3D/qglsphere.h>
45
46#include "CodePatterns/MemDebug.hpp"
47
48#include "CodePatterns/Assert.hpp"
49#include "CodePatterns/Log.hpp"
50
51#include "Shapes/Shape.hpp"
52#include "LinearAlgebra/Vector.hpp"
53#include "LinkedCell/PointCloudAdaptor.hpp"
54#include "LinkedCell/linkedcell.hpp"
55#include "Tesselation/tesselation.hpp"
56#include "Tesselation/BoundaryLineSet.hpp"
57#include "Tesselation/BoundaryTriangleSet.hpp"
58#include "Tesselation/CandidateForTesselation.hpp"
59#include "Atom/TesselPoint.hpp"
60
61typedef QGLSceneNode *MeshList[GLMoleculeObject::DETAILTYPES_MAX];
62
63QGLSceneNode *createShapeMesh(const Shape &shape, QObject *parent)
64{
65 // Create some points on our shape.
66 std::vector<Vector> points = shape.getHomogeneousPointsOnSurface(200);
67
68 // Fill the points into a tesselate-able container.
69 TesselPointSTLList Corners;
70 for (int i=0;i<points.size();i++){
71 TesselPoint *Walker = new TesselPoint;
72 Walker->setPosition(points[i]);
73 Walker->setName(toString(i));
74 Walker->setNr(i);
75 Corners.push_back(Walker);
76 }
77
78 // Fill the points into a Qt geometry.
79 QGeometryData geo;
80 for(int i=0;i<points.size();i++){
81 // add data to the primitive
82 geo.appendVertex(QVector3D(points[i][0], points[i][1], points[i][2]));
83 Vector n = shape.getNormal(points[i]);
84 geo.appendNormal(QVector3D(n[0], n[1], n[2]));
85 geo.appendColor(QColor(1, 1, 1, 1));
86 geo.appendTexCoord(QVector2D(0, 0));
87 }
88
89 // Tesselate the points.
90 Tesselation *T = new Tesselation;
91 PointCloudAdaptor<TesselPointSTLList> cloud(&Corners, "TesselPointSTLList");
92 (*T)(cloud, 2);
93
94 // Fill the tesselated triangles into the geometry.
95 for (TriangleMap::const_iterator runner = T->TrianglesOnBoundary.begin(); runner != T->TrianglesOnBoundary.end(); runner++) {
96 geo.appendIndices(runner->second->endpoints[0]->node->getNr(), runner->second->endpoints[1]->node->getNr(), runner->second->endpoints[2]->node->getNr());
97 }
98
99 // Build a mesh from the geometry.
100 QGLBuilder builder;
101 builder.addTriangles(geo);
102 QGLSceneNode *mesh = builder.finalizedSceneNode();
103 return mesh;
104}
105
106GLMoleculeObject_shape::GLMoleculeObject_shape(const Shape &shape, QObject *parent) :
107 GLMoleculeObject(createShapeMesh(shape, parent), parent),
108 m_shape(shape)
109{
110 // Create the material.
111 QGLMaterial *material = new QGLMaterial(NULL);
112 material->setAmbientColor( QColor(50, 60, 100, 255) );
113 material->setDiffuseColor( QColor(150, 160, 200, 180) );
114 material->setSpecularColor( QColor(60, 60, 60) );
115 material->setShininess( 128 );
116 setMaterial(material);
117}
118
119GLMoleculeObject_shape::~GLMoleculeObject_shape()
120{
121}
122
123
124void GLMoleculeObject_shape::draw(QGLPainter *painter, const QVector4D &cameraPlane)
125{
126 painter->modelViewMatrix().push();
127
128 painter->setColor(m_material->diffuseColor());
129 painter->setFaceMaterial(QGL::AllFaces, m_material);
130
131 // Draw the transparent cube.
132/* painter->setStandardEffect(QGL::LitMaterial);
133 glCullFace(GL_BACK);
134 //glEnable(GL_CULL_FACE);
135 glEnable(GL_BLEND);
136 glDepthMask(0);
137 glDisable(GL_DEPTH_TEST);*/
138 m_mesh[0]->draw(painter);
139 /*glEnable(GL_DEPTH_TEST);
140 glDepthMask(1);
141 glDisable(GL_BLEND);
142 //glDisable(GL_CULL_FACE);*/
143
144
145 painter->modelViewMatrix().pop();
146}
Note: See TracBrowser for help on using the repository browser.