moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
gl_mesh.cpp
Go to the documentation of this file.
1/*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2013, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34
35/* Author: Suat Gedikli */
36
38#include <geometric_shapes/shapes.h>
39#include <stdexcept>
40#include <Eigen/Eigen>
41
42using namespace std;
43using namespace Eigen;
44using shapes::Mesh;
45
46mesh_filter::GLMesh::GLMesh(const Mesh& mesh, unsigned int mesh_label)
47{
48 if (!mesh.vertex_normals)
49 {
50 throw std::runtime_error("Vertex normals are not computed for input mesh. Call computeVertexNormals() before "
51 "passing as input to mesh_filter.");
52 }
53
54 mesh_label_ = mesh_label;
55 list_ = glGenLists(1);
56 glNewList(list_, GL_COMPILE);
57 glBegin(GL_TRIANGLES);
58 glColor4ubv(reinterpret_cast<GLubyte*>(&mesh_label_));
59 for (unsigned t_idx = 0; t_idx < mesh.triangle_count; ++t_idx)
60 {
61 unsigned v1 = 3 * mesh.triangles[3 * t_idx];
62 unsigned v2 = 3 * mesh.triangles[3 * t_idx + 1];
63 unsigned v3 = 3 * mesh.triangles[3 * t_idx + 2];
64
65 glNormal3f(mesh.vertex_normals[v1], mesh.vertex_normals[v1 + 1], mesh.vertex_normals[v1 + 2]);
66 glVertex3f(mesh.vertices[v1], mesh.vertices[v1 + 1], mesh.vertices[v1 + 2]);
67
68 glNormal3f(mesh.vertex_normals[v2], mesh.vertex_normals[v2 + 1], mesh.vertex_normals[v2 + 2]);
69 glVertex3f(mesh.vertices[v2], mesh.vertices[v2 + 1], mesh.vertices[v2 + 2]);
70
71 glNormal3f(mesh.vertex_normals[v3], mesh.vertex_normals[v3 + 1], mesh.vertex_normals[v3 + 2]);
72 glVertex3f(mesh.vertices[v3], mesh.vertices[v3 + 1], mesh.vertices[v3 + 2]);
73 }
74 glEnd();
75 glEndList();
76}
77
79{
80 glDeleteLists(list_, 1);
81}
82
83void mesh_filter::GLMesh::render(const Isometry3d& transform) const
84{
85 glMatrixMode(GL_MODELVIEW);
86 glPushMatrix();
87 if (!(transform.matrix().Flags & RowMajorBit))
88 {
89 glMultMatrixd(transform.matrix().data());
90 }
91 else
92 {
93 glMultTransposeMatrixd(transform.matrix().data());
94 }
95 glCallList(list_);
96 glPopMatrix();
97}
void render(const Eigen::Isometry3d &transform) const
renders the mesh in current OpenGL frame buffer (context)
Definition gl_mesh.cpp:83
GLMesh(const shapes::Mesh &mesh, unsigned int mesh_label)
Constructs a GLMesh object for given mesh and label.
Definition gl_mesh.cpp:46
~GLMesh()
Destructor.
Definition gl_mesh.cpp:78