Grid.cpp
Go to the documentation of this file.
1 
35 #include "lvr2/display/Grid.hpp"
36 
37 namespace lvr2
38 {
39 
40 Grid::Grid(floatArr vertices, uintArr boxes, uint numPoints, uint numBoxes)
41  : m_vertices(vertices), m_boxes(boxes), m_numPoints(numPoints), m_numBoxes(numBoxes)
42 {
43  m_lineWidth = 2.0;
44  m_pointSize = 5.0;
45 
46  // Create display lists for points and grid
47  m_pointDisplayList = glGenLists(1);
48  m_gridDisplayList = glGenLists(1);
49 
50  // Render points
51  glNewList(m_pointDisplayList, GL_COMPILE);
52  glBegin(GL_POINTS);
53  for(int i = 0; i < m_numPoints; i++)
54  {
55  int pos = i * 4;
56  float x = m_vertices[pos];
57  float y = m_vertices[pos + 1];
58  float z = m_vertices[pos + 2];
59  float d = m_vertices[pos + 3];
60 
61  if(d > 0)
62  {
63  glColor3f(0.54f, 0.17f, 0.89f);
64  }
65  else
66  {
67  glColor3f(1.0f, 0.64f, 0.0f);
68  }
69  glVertex3f(x, y, z);
70 
71  }
72  glEnd();
73  glEndList();
74 
75  // Render boxes
76  glNewList(m_gridDisplayList, GL_COMPILE);
77  glColor3f(125.0, 125.0, 125.0);
78 
79  // Coordinates for box corners
80  float x[8];
81  float y[8];
82  float z[8];
83 
84  // Get box corner coordinates
85  for(unsigned int i = 0; i < m_numBoxes; i++)
86  {
87  int box_pos = i * 8;
88  for(int j = 0; j < 8; j++)
89  {
90  int vertex_pos = 4 * m_boxes[box_pos + j];
91  x[j] = m_vertices[vertex_pos];
92  y[j] = m_vertices[vertex_pos + 1];
93  z[j] = m_vertices[vertex_pos + 2];
94 
95  m_boundingBox->expand(Vec(x[j], y[j], z[j]));
96  }
97 
98  // Render quads
99  glBegin(GL_LINE_LOOP);
100  glVertex3f(x[0], y[0], z[0]);
101  glVertex3f(x[1], y[1], z[1]);
102  glVertex3f(x[2], y[2], z[2]);
103  glVertex3f(x[3], y[3], z[3]);
104  glEnd();
105 
106  glBegin(GL_LINE_LOOP);
107  glVertex3f(x[4], y[4], z[4]);
108  glVertex3f(x[5], y[5], z[5]);
109  glVertex3f(x[6], y[6], z[6]);
110  glVertex3f(x[7], y[7], z[7]);
111  glEnd();
112 
113  glBegin(GL_LINES);
114  glVertex3f(x[0], y[0], z[0]);
115  glVertex3f(x[4], y[4], z[4]);
116 
117  glVertex3f(x[1], y[1], z[1]);
118  glVertex3f(x[5], y[5], z[5]);
119 
120  glVertex3f(x[3], y[3], z[3]);
121  glVertex3f(x[7], y[7], z[7]);
122 
123  glVertex3f(x[2], y[2], z[2]);
124  glVertex3f(x[6], y[6], z[6]);
125  glEnd();
126  }
127 
128  glEndList();
129 
130 }
131 
133 {
134  if(m_active)
135  {
136  glLineWidth(m_lineWidth);
137  glCallList(m_gridDisplayList);
138  glPointSize(m_pointSize);
139  glCallList(m_pointDisplayList);
140  glPointSize(1.0);
141  glLineWidth(1.0);
142  }
143 }
144 
146 {
147  // TODO Auto-generated destructor stub
148 }
149 
150 } /* namespace lvr2 */
lvr2::floatArr
boost::shared_array< float > floatArr
Definition: DataStruct.hpp:133
lvr2::Grid::m_vertices
floatArr m_vertices
Definition: Grid.hpp:52
lvr2::Renderable::m_boundingBox
BoundingBox< Vec > * m_boundingBox
Definition: Renderable.hpp:165
lvr2::Grid::m_boxes
uintArr m_boxes
Definition: Grid.hpp:53
lvr2::Renderable::m_lineWidth
float m_lineWidth
Definition: Renderable.hpp:169
lvr2::Grid::Grid
Grid(floatArr vertices, uintArr boxes, uint numPoints, uint numBoxes)
Definition: Grid.cpp:40
lvr2::Grid::m_numBoxes
uint m_numBoxes
Definition: Grid.hpp:55
lvr2::Grid::m_numPoints
uint m_numPoints
Definition: Grid.hpp:54
lvr2::Renderable::m_active
bool m_active
Definition: Renderable.hpp:144
Grid.hpp
lvr2::Renderable::Vec
BaseVector< float > Vec
Definition: Renderable.hpp:69
lvr2::Grid::m_pointDisplayList
GLuint m_pointDisplayList
Definition: Grid.hpp:57
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::Renderable::m_pointSize
float m_pointSize
Definition: Renderable.hpp:170
uint
unsigned int uint
Definition: Model.hpp:46
lvr2::Grid::render
virtual void render()
Definition: Grid.cpp:132
lvr2::Grid::m_gridDisplayList
GLuint m_gridDisplayList
Definition: Grid.hpp:58
lvr2::Grid::~Grid
virtual ~Grid()
Definition: Grid.cpp:145
lvr2::uintArr
boost::shared_array< unsigned int > uintArr
Definition: DataStruct.hpp:130


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Wed Mar 2 2022 00:37:23