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 
39 #include <stdexcept>
40 #include <Eigen/Eigen>
41 
42 using namespace std;
43 using namespace Eigen;
44 using shapes::Mesh;
45 
46 mesh_filter::GLMesh::GLMesh(const Mesh& mesh, unsigned int mesh_label)
47 {
48  if (!mesh.vertex_normals)
49  throw std::runtime_error("Vertex normals are not computed for input mesh. Call computeVertexNormals() before "
50  "passing as input to mesh_filter.");
51 
52  mesh_label_ = mesh_label;
53  list_ = glGenLists(1);
54  glNewList(list_, GL_COMPILE);
55  glBegin(GL_TRIANGLES);
56  glColor4ubv((GLubyte*)&mesh_label_);
57  for (unsigned tIdx = 0; tIdx < mesh.triangle_count; ++tIdx)
58  {
59  unsigned v1 = 3 * mesh.triangles[3 * tIdx];
60  unsigned v2 = 3 * mesh.triangles[3 * tIdx + 1];
61  unsigned v3 = 3 * mesh.triangles[3 * tIdx + 2];
62 
63  glNormal3f(mesh.vertex_normals[v1], mesh.vertex_normals[v1 + 1], mesh.vertex_normals[v1 + 2]);
64  glVertex3f(mesh.vertices[v1], mesh.vertices[v1 + 1], mesh.vertices[v1 + 2]);
65 
66  glNormal3f(mesh.vertex_normals[v2], mesh.vertex_normals[v2 + 1], mesh.vertex_normals[v2 + 2]);
67  glVertex3f(mesh.vertices[v2], mesh.vertices[v2 + 1], mesh.vertices[v2 + 2]);
68 
69  glNormal3f(mesh.vertex_normals[v3], mesh.vertex_normals[v3 + 1], mesh.vertex_normals[v3 + 2]);
70  glVertex3f(mesh.vertices[v3], mesh.vertices[v3 + 1], mesh.vertices[v3 + 2]);
71  }
72  glEnd();
73  glEndList();
74 }
75 
77 {
78  glDeleteLists(list_, 1);
79 }
80 
81 void mesh_filter::GLMesh::render(const Affine3d& transform) const
82 {
83  glMatrixMode(GL_MODELVIEW);
84  glPushMatrix();
85  if (!(transform.matrix().Flags & RowMajorBit))
86  glMultMatrixd(transform.matrix().data());
87  else
88  glMultTransposeMatrixd(transform.matrix().data());
89  glCallList(list_);
90  glPopMatrix();
91 }
unsigned int * triangles
~GLMesh()
Destructor.
Definition: gl_mesh.cpp:76
double * vertex_normals
void render(const Eigen::Affine3d &transform) const
renders the mesh in current OpenGL frame buffer (context)
Definition: gl_mesh.cpp:81
unsigned int triangle_count
double * vertices
GLMesh(const shapes::Mesh &mesh, unsigned int mesh_label)
Constucts a GLMesh object for given mesh and label.
Definition: gl_mesh.cpp:46


perception
Author(s): Ioan Sucan , Jon Binney , Suat Gedikli
autogenerated on Sun Oct 18 2020 13:17:23