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

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 1e1098 was 5aaa43, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: Fixed new copyright line since start of 2013 in CodeChecks test.

  • we must look for either Uni Bonn or myself.
  • added second copyright line since from 1st of Jan 2013 I am not employed by University of Bonn anymore, hence changes to the code are my own copyright.
  • Property mode set to 100644
File size: 5.6 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 * Copyright (C) 2013 Frederik Heber. All rights reserved.
6 *
7 *
8 * This file is part of MoleCuilder.
9 *
10 * MoleCuilder is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * MoleCuilder is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24/*
25 * GLMoleculeObject_shape.cpp
26 *
27 * Created on: Aug 3, 2012
28 * Author: ankele
29 */
30
31
32
33// include config.h
34#ifdef HAVE_CONFIG_H
35#include <config.h>
36#endif
37
38#include "GLMoleculeObject_shape.hpp"
39
40#include <Qt3D/qglview.h>
41#include <Qt3D/qglscenenode.h>
42#include <Qt3D/qglpainter.h>
43#include <Qt3D/qglmaterial.h>
44#include <Qt3D/qglbuilder.h>
45#include <Qt3D/qglsphere.h>
46
47#include "CodePatterns/MemDebug.hpp"
48
49#include "CodePatterns/Assert.hpp"
50#include "CodePatterns/Log.hpp"
51
52#include "Shapes/Shape.hpp"
53#include "LinearAlgebra/Vector.hpp"
54#include "LinkedCell/PointCloudAdaptor.hpp"
55#include "LinkedCell/linkedcell.hpp"
56#include "Tesselation/tesselation.hpp"
57#include "Tesselation/BoundaryLineSet.hpp"
58#include "Tesselation/BoundaryTriangleSet.hpp"
59#include "Tesselation/CandidateForTesselation.hpp"
60#include "Atom/TesselPoint.hpp"
61
62typedef QGLSceneNode *MeshList[GLMoleculeObject::DETAILTYPES_MAX];
63
64QGLSceneNode *createShapeMesh(Shape &shape, QObject *parent)
65{
66 size_t NumPointsonSurface = 200;
67 // guess the surface area which divided by 200 determines rolling sphere's size
68 const double surfacearea = shape.getSurfaceArea();
69 const size_t EstimatedNumberTriangles = NumPointsonSurface*1;
70 const double MeanAreaPerTriangle = surfacearea/((double)EstimatedNumberTriangles);
71 // assume two triangles to form a square and take its diameter as the radius
72 double minradius = sqrt(2. * 2.*MeanAreaPerTriangle);
73 LOG(3, "DEBUG: Surface area is " << surfacearea << ", minradius is " << minradius << ".");
74 if (minradius < 1.)
75 minradius = 1.;
76 LOG(2, "DEBUG: Tesselating shape " << shape.getName() << " with sphere of radius " << minradius << ".");
77
78 // Create some points on our shape.
79 std::vector<Vector> points = shape.getHomogeneousPointsOnSurface(NumPointsonSurface);
80
81 // Fill the points into a tesselate-able container.
82 TesselPointSTLList Corners;
83 for (size_t i=0;i<points.size();++i){
84 TesselPoint *Walker = new TesselPoint;
85 Walker->setPosition(points[i]);
86 Walker->setName(toString(i));
87 Walker->setNr(i);
88 Corners.push_back(Walker);
89 }
90
91 // Fill the points into a Qt geometry.
92 QGeometryData geo;
93 for(size_t i=0;i<points.size();++i){
94 // add data to the primitive
95 geo.appendVertex(QVector3D(points[i][0], points[i][1], points[i][2]));
96 Vector n = shape.getNormal(points[i]);
97 geo.appendNormal(QVector3D(n[0], n[1], n[2]));
98 geo.appendColor(QColor(1, 1, 1, 1));
99 geo.appendTexCoord(QVector2D(0, 0));
100 }
101
102 // Tesselate the points.
103 Tesselation *T = new Tesselation;
104 PointCloudAdaptor<TesselPointSTLList> cloud(&Corners, "TesselPointSTLList");
105 (*T)(cloud, minradius);
106
107 // Fill the tesselated triangles into the geometry.
108 for (TriangleMap::const_iterator runner = T->TrianglesOnBoundary.begin(); runner != T->TrianglesOnBoundary.end(); runner++) {
109 int v[3];
110 for (size_t i=0; i<3; ++i)
111 v[i] = runner->second->endpoints[i]->node->getNr();
112
113 // Sort the vertices so the triangle is clockwise (relative to the normal vector).
114 Vector cross = points[v[1]] - points[v[0]];
115 cross.VectorProduct(points[v[2]] - points[v[0]]);
116 if (cross.ScalarProduct(shape.getNormal(points[v[0]]) + shape.getNormal(points[v[1]]) + shape.getNormal(points[v[2]])) > 0)
117 geo.appendIndices(v[0], v[1], v[2]);
118 else
119 geo.appendIndices(v[0], v[2], v[1]);
120 }
121
122 // Build a mesh from the geometry.
123 QGLBuilder builder;
124 builder.addTriangles(geo);
125 QGLSceneNode *mesh = builder.finalizedSceneNode();
126 return mesh;
127}
128
129GLMoleculeObject_shape::GLMoleculeObject_shape(Shape &shape, QObject *parent) :
130 GLMoleculeObject(createShapeMesh(shape, parent), parent),
131 m_shape(shape)
132{
133 // Create the material.
134 QGLMaterial *material = new QGLMaterial(NULL);
135 material->setAmbientColor( QColor(50, 60, 100, 255) );
136 material->setDiffuseColor( QColor(150, 160, 200, 180) );
137 material->setSpecularColor( QColor(60, 60, 60) );
138 material->setShininess( 128 );
139 setMaterial(material);
140
141 m_enabled = false;
142}
143
144GLMoleculeObject_shape::~GLMoleculeObject_shape()
145{
146}
147
148void GLMoleculeObject_shape::enable(bool enabled)
149{
150 m_enabled = enabled;
151}
152
153
154void GLMoleculeObject_shape::draw(QGLPainter *painter, const QVector4D &cameraPlane)
155{
156 if (!m_enabled)
157 return;
158 painter->modelViewMatrix().push();
159
160 painter->setColor(m_material->diffuseColor());
161 painter->setFaceMaterial(QGL::AllFaces, m_material);
162
163 // Draw the transparent cube.
164 painter->setStandardEffect(QGL::LitMaterial);
165 glCullFace(GL_BACK);
166 glEnable(GL_CULL_FACE);
167 glEnable(GL_BLEND);
168 glDepthMask(0);
169 glDisable(GL_DEPTH_TEST);
170 m_mesh[0]->draw(painter);
171 glEnable(GL_DEPTH_TEST);
172 glDepthMask(1);
173 glDisable(GL_BLEND);
174 glDisable(GL_CULL_FACE);
175
176
177 painter->modelViewMatrix().pop();
178}
Note: See TracBrowser for help on using the repository browser.