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 |
|
---|
61 | typedef QGLSceneNode *MeshList[GLMoleculeObject::DETAILTYPES_MAX];
|
---|
62 |
|
---|
63 | QGLSceneNode *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 |
|
---|
106 | GLMoleculeObject_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 |
|
---|
119 | GLMoleculeObject_shape::~GLMoleculeObject_shape()
|
---|
120 | {
|
---|
121 | }
|
---|
122 |
|
---|
123 |
|
---|
124 | void 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 | }
|
---|