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 
56 PointCloud::PointCloud( ModelPtr model, string name) : Renderable(name)
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
lvr2::floatArr
boost::shared_array< float > floatArr
Definition: DataStruct.hpp:133
lvr2::PointCloud::updateBuffer
void updateBuffer(PointBufferPtr buffer)
Definition: PointCloud.cpp:63
lvr2::PointCloud::m_renderMode
int m_renderMode
Definition: PointCloud.hpp:103
lvr2::BaseVector< float >
lvr2::Renderable::m_model
ModelPtr m_model
Definition: Renderable.hpp:167
lvr2::PointCloud::m_numNormals
size_t m_numNormals
Definition: PointCloud.hpp:106
lvr2::PointCloud::~PointCloud
virtual ~PointCloud()
Definition: PointCloud.cpp:206
ColorMap.hpp
lvr2::color
Definition: DataStruct.hpp:81
lvr2::PointBufferPtr
std::shared_ptr< PointBuffer > PointBufferPtr
Definition: PointBuffer.hpp:130
lvr2::PointCloud::m_normals
floatArr m_normals
Definition: PointCloud.hpp:105
lvr2::SHSV
@ SHSV
Definition: ColorMap.hpp:65
lvr2::PointCloud::updateDisplayLists
void updateDisplayLists()
Definition: PointCloud.cpp:134
lvr2::Model
Definition: Model.hpp:51
lvr2::RenderPoints
@ RenderPoints
Definition: PointCloud.hpp:55
lvr2::Normal< float >
lvr2::Renderable::m_boundingBox
BoundingBox< Vec > * m_boundingBox
Definition: Renderable.hpp:165
lvr2::Renderable
Definition: Renderable.hpp:65
lvr2::ColorMap
Definition: ColorMap.hpp:65
scripts.create_png.colors
colors
Definition: create_png.py:41
lvr2::BoundingBox
A dynamic bounding box class.
Definition: BoundingBox.hpp:49
lvr2::Renderable::m_activeListIndex
int m_activeListIndex
Definition: Renderable.hpp:149
lvr2::Renderable::Vec
BaseVector< float > Vec
Definition: Renderable.hpp:69
lvr2::Renderable::model
virtual ModelPtr model()
Definition: Renderable.hpp:126
lvr2::ucharArr
boost::shared_array< unsigned char > ucharArr
Definition: DataStruct.hpp:137
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::ModelPtr
std::shared_ptr< Model > ModelPtr
Definition: Model.hpp:80
lvr2::PointCloud::m_normalListIndex
GLuint m_normalListIndex
Definition: PointCloud.hpp:104
lvr2::PointCloud::init
void init(PointBufferPtr buffer)
Definition: PointCloud.cpp:69
lvr2::ColorMap::getColor
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
lvr2::Renderable::m_listIndex
int m_listIndex
Definition: Renderable.hpp:148
lvr2::PointCloud::m_points
vector< uColorVertex > m_points
Definition: PointCloud.hpp:94
lvr2::PointCloud::uColorVertex
ColorVertex< float, unsigned char > uColorVertex
Definition: PointCloud.hpp:61
lvr2::PointCloud::PointCloud
PointCloud()
Definition: PointCloud.cpp:43
PointCloud.hpp


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:24