PointCloud.cpp
Go to the documentation of this file.
1 
28  /*
29  * PointCloud.cpp
30  *
31  * Created on: 20.08.2011
32  * Author: Thomas Wiemann
33  */
34 
37 
38 #include <string.h>
39 
40 namespace lvr2
41 {
42 
44 {
45  m_numNormals = 0;
48 }
49 
50 PointCloud::PointCloud( PointBufferPtr buffer, string name) : Renderable(name)
51 {
52  m_model = ModelPtr(new Model(buffer));
53  init(buffer);
54 }
55 
57 {
58 
59  m_model = model;
60  init(m_model->m_pointCloud);
61 }
62 
64 {
65  init(buffer);
66 
67 }
68 
70 {
71  int maxColors = 255;
72  m_numNormals = 0;
73 
76 
77  if(buffer)
78  {
79  size_t n_points = buffer->numPoints();
80  floatArr points = buffer->getPointArray();
81  m_numNormals = 0;
82  m_normals = buffer->getNormalArray();
83 
84  if (m_normals)
85  m_numNormals = n_points;
86 
87  size_t w_color, dummy;
88  ucharArr colors = buffer->getColorArray(w_color);
89  floatArr intensities = buffer->getFloatArray("intensities", n_points, dummy);
90 
91  ColorMap c_map(maxColors);
92 
93  for(size_t i = 0; i < n_points; i++)
94  {
95  float x = points[i*3 + 0];
96  float y = points[i*3 + 1];
97  float z = points[i*3 + 2];
98 
99  m_boundingBox->expand(Vec(x,y,z));
100 
101  unsigned char r, g, b;
102 
103  if(colors)
104  {
105  r = colors[i*w_color + 0];
106  g = colors[i*w_color + 1];
107  b = colors[i*w_color + 2];
108  }
109  else if (intensities)
110  {
111  // Get intensity
112  float color[3];
113  c_map.getColor(color, (size_t)intensities[i], SHSV);
114 
115  r = (unsigned char)(color[0] * 255);
116  g = (unsigned char)(color[1] * 255);
117  b = (unsigned char)(color[2] * 255);
118 
119  }
120  else
121  {
122  r = 0;
123  g = 0;
124  b = 0;
125  }
126 
127 
128  m_points.push_back(uColorVertex(x, y, z, r, g, b));
129  }
130  }
132 }
133 
135 
136  // Check for existing display list for normal rendering
137  if(m_listIndex != -1) {
138  cout<<"PointCloud::initDisplayList() delete display list"<<endl;
139  glDeleteLists(m_listIndex,1);
140  }
141 
142  // Create new display list and render points
143  m_listIndex = glGenLists(1);
144  glNewList(m_listIndex, GL_COMPILE);
145  glBegin(GL_POINTS);
146 
147  for(size_t i = 0; i < m_points.size(); i++)
148  {
149  float r = m_points[i].r / 255.0f;
150  float g = m_points[i].g / 255.0f;
151  float b = m_points[i].b / 255.0f;
152 
153  glColor3f(r, g, b);
154  glVertex3f(m_points[i].x,
155  m_points[i].y,
156  m_points[i].z);
157  }
158  glEnd();
159  glEndList();
160 
161  // Check for existing list index for rendering a selected point
162  // cloud
163  if(m_activeListIndex != -1)
164  {
165  glDeleteLists(m_activeListIndex,1);
166  }
167 
168  m_activeListIndex = glGenLists(1);
169  glNewList(m_activeListIndex, GL_COMPILE);
170  glBegin(GL_POINTS);
171 
172  glColor3f(1.0, 1.0, 0.0);
173  for(size_t i = 0; i < m_points.size(); i++)
174  {
175 
176  glVertex3f(m_points[i].x,
177  m_points[i].y,
178  m_points[i].z);
179  }
180  glEnd();
181  glEndList();
182 
183  float length = 0.01f * m_boundingBox->getRadius();
184 
185  // Create a new display list for normals
186  if(m_numNormals)
187  {
188  m_normalListIndex = glGenLists(1);
189  glNewList(m_normalListIndex, GL_COMPILE);
190  glColor3f(1.0, 0.0, 1.0);
191  for(int i = 0; i < m_numNormals; i++)
192  {
193  Vec start(m_points[i].x, m_points[i].y, m_points[i].z);
194  Normal<float> normal(m_normals[i*3 + 0], m_normals[i*3 + 1], m_normals[i*3 + 2]);
195  Vec end = start + normal * length;
196  glBegin(GL_LINES);
197  glVertex3f(start[0], start[1], start[2]);
198  glVertex3f(end[0], end[1], end[2]);
199  glEnd();
200  }
201  glEndList();
202  }
203 
204 }
205 
207  // TODO Auto-generated destructor stub
208 }
209 
210 } // namespace lvr2
void getColor(float *color, size_t bucket, GradientType gradient=GREY)
Returns three float values for the color of the given bucket.
Definition: ColorMap.cpp:43
void updateBuffer(PointBufferPtr buffer)
Definition: PointCloud.cpp:63
floatArr m_normals
Definition: PointCloud.hpp:105
BaseVector< float > Vec
Definition: Renderable.hpp:69
boost::shared_array< unsigned char > ucharArr
Definition: DataStruct.hpp:137
std::shared_ptr< PointBuffer > PointBufferPtr
A dynamic bounding box class.
Definition: BoundingBox.hpp:49
virtual ~PointCloud()
Definition: PointCloud.cpp:206
void init(PointBufferPtr buffer)
Definition: PointCloud.cpp:69
boost::shared_array< float > floatArr
Definition: DataStruct.hpp:133
vector< uColorVertex > m_points
Definition: PointCloud.hpp:94
std::shared_ptr< Model > ModelPtr
Definition: Model.hpp:80
BoundingBox< Vec > * m_boundingBox
Definition: Renderable.hpp:165
virtual ModelPtr model()
Definition: Renderable.hpp:126
GLuint m_normalListIndex
Definition: PointCloud.hpp:104
void updateDisplayLists()
Definition: PointCloud.cpp:134
ColorVertex< float, unsigned char > uColorVertex
Definition: PointCloud.hpp:61


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 Mon Feb 28 2022 22:46:08