28 #define OTD_RAD2DEG 57.2957795 33 m_occupiedThresSize(0), m_freeThresSize(0),
34 m_occupiedSize(0), m_freeSize(0), m_selectionSize(0),
35 octree_grid_vertex_size(0), m_alphaOccupied(0.8), map_id(0)
71 glTranslatef(relative_transform.
x(), relative_transform.
y(), relative_transform.
z());
74 float scale = sqrt(q.
x() * q.
x() + q.
y() * q.
y() + q.
z() * q.
z());
76 float axis_x = q.
x() / scale;
77 float axis_y = q.
y() / scale;
78 float axis_z = q.
z() / scale;
80 glRotatef(angle, axis_x, axis_y, axis_z);
83 glEnableClientState(GL_VERTEX_ARRAY);
98 glDisableClientState(GL_VERTEX_ARRAY);
122 bool showAll = (octree.
size() < 5 * 1e6);
123 bool uses_origin = ( (origin.
rot().
x() != 0.) && (origin.
rot().
y() != 0.)
124 && (origin.
rot().
z() != 0.) && (origin.
rot().
u() != 1.) );
129 unsigned int cnt_occupied(0), cnt_occupied_thres(0), cnt_free(0), cnt_free_thres(0);
130 for(OcTree::tree_iterator it = octree.
begin_tree(this->m_max_tree_depth),
131 end=octree.
end_tree(); it!= end; ++it) {
149 double minX, minY, minZ, maxX, maxY, maxZ;
157 std::vector<octomath::Vector3> cube_template;
160 unsigned int idx_occupied(0), idx_occupied_thres(0), idx_free(0), idx_free_thres(0);
161 unsigned int color_idx_occupied(0), color_idx_occupied_thres(0);
165 for(OcTree::tree_iterator it = octree.
begin_tree(this->m_max_tree_depth),
166 end=octree.
end_tree(); it!= end; ++it) {
220 unsigned int& glArraySize,
221 GLfloat*** glArray, GLfloat** glColorArray) {
223 clearCubes(glArray, glArraySize, glColorArray);
226 glArraySize = num_cubes * 4 * 3;
229 *glArray =
new GLfloat* [6];
230 for (
unsigned i = 0; i<6; ++i){
231 (*glArray)[i] =
new GLfloat[glArraySize];
234 if (glColorArray != NULL)
235 *glColorArray =
new GLfloat[glArraySize * 4 *4];
239 std::vector<octomath::Vector3>& cube_template) {
240 cube_template.clear();
241 cube_template.reserve(24);
273 const std::vector<octomath::Vector3>& cube_template,
274 const unsigned int& current_array_idx,
275 GLfloat*** glArray) {
283 double half_cube_size = GLfloat(v.second /2.0 -eps);
284 unsigned int i = current_array_idx;
289 p = v.first + cube_template[0] * half_cube_size;
290 (*glArray)[0][i] = p.
x();
291 (*glArray)[0][i+1] = p.
y();
292 (*glArray)[0][i+2] = p.
z();
294 p = v.first + cube_template[1] * half_cube_size;
295 (*glArray)[1][i] = p.
x();
296 (*glArray)[1][i+1] = p.
y();
297 (*glArray)[1][i+2] = p.
z();
299 p = v.first + cube_template[2] * half_cube_size;
300 (*glArray)[2][i] = p.
x();
301 (*glArray)[2][i+1] = p.
y();
302 (*glArray)[2][i+2] = p.
z();
304 p = v.first + cube_template[3] * half_cube_size;
305 (*glArray)[3][i] = p.
x();
306 (*glArray)[3][i+1] = p.
y();
307 (*glArray)[3][i+2] = p.
z();
309 p = v.first + cube_template[4] * half_cube_size;
310 (*glArray)[4][i] = p.
x();
311 (*glArray)[4][i+1] = p.
y();
312 (*glArray)[4][i+2] = p.
z();
314 p = v.first + cube_template[5] * half_cube_size;
315 (*glArray)[5][i] = p.
x();
316 (*glArray)[5][i+1] = p.
y();
317 (*glArray)[5][i+2] = p.
z();
320 p = v.first + cube_template[6] * half_cube_size;
321 (*glArray)[0][i] = p.
x();
322 (*glArray)[0][i+1] = p.
y();
323 (*glArray)[0][i+2] = p.
z();
325 p = v.first + cube_template[7] * half_cube_size;
326 (*glArray)[1][i] = p.
x();
327 (*glArray)[1][i+1] = p.
y();
328 (*glArray)[1][i+2] = p.
z();
330 p = v.first + cube_template[8] * half_cube_size;
331 (*glArray)[2][i] = p.
x();
332 (*glArray)[2][i+1] = p.
y();
333 (*glArray)[2][i+2] = p.
z();
335 p = v.first + cube_template[9] * half_cube_size;
336 (*glArray)[3][i] = p.
x();
337 (*glArray)[3][i+1] = p.
y();
338 (*glArray)[3][i+2] = p.
z();
340 p = v.first + cube_template[10] * half_cube_size;
341 (*glArray)[4][i] = p.
x();
342 (*glArray)[4][i+1] = p.
y();
343 (*glArray)[4][i+2] = p.
z();
345 p = v.first + cube_template[11] * half_cube_size;
346 (*glArray)[5][i] = p.
x();
347 (*glArray)[5][i+1] = p.
y();
348 (*glArray)[5][i+2] = p.
z();
351 p = v.first + cube_template[12] * half_cube_size;
352 (*glArray)[0][i] = p.
x();
353 (*glArray)[0][i+1] = p.
y();
354 (*glArray)[0][i+2] = p.
z();
356 p = v.first + cube_template[13] * half_cube_size;
357 (*glArray)[1][i] = p.
x();
358 (*glArray)[1][i+1] = p.
y();
359 (*glArray)[1][i+2] = p.
z();
361 p = v.first + cube_template[14] * half_cube_size;
362 (*glArray)[2][i] = p.
x();
363 (*glArray)[2][i+1] = p.
y();
364 (*glArray)[2][i+2] = p.
z();
366 p = v.first + cube_template[15] * half_cube_size;
367 (*glArray)[3][i] = p.
x();
368 (*glArray)[3][i+1] = p.
y();
369 (*glArray)[3][i+2] = p.
z();
371 p = v.first + cube_template[16] * half_cube_size;
372 (*glArray)[4][i] = p.
x();
373 (*glArray)[4][i+1] = p.
y();
374 (*glArray)[4][i+2] = p.
z();
376 p = v.first + cube_template[17] * half_cube_size;
377 (*glArray)[5][i] = p.
x();
378 (*glArray)[5][i+1] = p.
y();
379 (*glArray)[5][i+2] = p.
z();
382 p = v.first + cube_template[18] * half_cube_size;
383 (*glArray)[0][i] = p.
x();
384 (*glArray)[0][i+1] = p.
y();
385 (*glArray)[0][i+2] = p.
z();
387 p = v.first + cube_template[19] * half_cube_size;
388 (*glArray)[1][i] = p.
x();
389 (*glArray)[1][i+1] = p.
y();
390 (*glArray)[1][i+2] = p.
z();
392 p = v.first + cube_template[20] * half_cube_size;
393 (*glArray)[2][i] = p.
x();
394 (*glArray)[2][i+1] = p.
y();
395 (*glArray)[2][i+2] = p.
z();
397 p = v.first + cube_template[21] * half_cube_size;
398 (*glArray)[3][i] = p.
x();
399 (*glArray)[3][i+1] = p.
y();
400 (*glArray)[3][i+2] = p.
z();
402 p = v.first + cube_template[22] * half_cube_size;
403 (*glArray)[4][i] = p.
x();
404 (*glArray)[4][i+1] = p.
y();
405 (*glArray)[4][i+2] = p.
z();
407 p = v.first + cube_template[23] * half_cube_size;
408 (*glArray)[5][i] = p.
x();
409 (*glArray)[5][i+1] = p.
y();
410 (*glArray)[5][i+2] = p.
z();
418 const unsigned int& current_array_idx,
419 GLfloat** glColorArray) {
421 if (glColorArray == NULL)
return current_array_idx;
423 unsigned int colorIdx = current_array_idx;
425 for (
int k = 0; k < 4; ++k) {
438 const unsigned char& g,
439 const unsigned char& b,
440 const unsigned char& a,
441 const unsigned int& current_array_idx,
442 GLfloat** glColorArray) {
444 if (glColorArray == NULL)
return current_array_idx;
445 unsigned int colorIdx = current_array_idx;
447 for (
int k = 0; k < 4; ++k) {
448 (*glColorArray)[colorIdx ] = (double) r/255.;
449 (*glColorArray)[colorIdx + 1] = (double) g/255.;
450 (*glColorArray)[colorIdx + 2] = (double) b/255.;
451 (*glColorArray)[colorIdx + 3] = (double) a/255.;
459 unsigned int& glArraySize,
460 GLfloat** glColorArray) {
461 if (glArraySize != 0) {
462 for (
unsigned i = 0; i < 6; ++i) {
463 delete[] (*glArray)[i];
469 if (glColorArray != NULL && *glColorArray != NULL) {
470 delete[] *glColorArray;
471 *glColorArray = NULL;
478 GLfloat*** glArray,
unsigned int& glArraySize,
480 GLfloat** glColorArray) {
482 unsigned int colorIdx = 0;
484 std::vector<octomath::Vector3> cube_template;
487 for (std::list<octomap::OcTreeVolume>::const_iterator it=voxels.begin();
488 it != voxels.end(); it++) {
492 if (glColorArray != NULL) {
493 for (std::list<octomap::OcTreeVolume>::const_iterator it=voxels.begin();
494 it != voxels.end(); it++) {
510 std::list<octomap::OcTreeVolume>::iterator it_rec;
515 x = it_rec->first.x();
516 y = it_rec->first.y();
517 z = it_rec->first.z();
519 double half_voxel_size = it_rec->second / 2.0;
649 glColor3f(0.784f, 0.66f, 0);
651 else if (this->
map_id == 1) {
652 glColor3f(0.68f, 0., 0.62f);
655 glColor3f(0., 0.784f, 0.725f);
663 glColor3f(0.6f, 0.6f, 0.6f);
666 glColor3f(0.1f, 0.1f, 0.1f);
689 glColor3f(0.5f, 0.5f, 0.5f);
692 glColor3f(0.9f, 0.9f, 0.9f);
711 glColor4f(1.0, 0.0, 0.0, 0.5);
717 GLfloat* cubeColorArray)
const {
718 if (cubeArraySize == 0 || cubeArray == NULL){
719 std::cerr <<
"Warning: GLfloat array to draw cubes appears to be empty, nothing drawn.\n";
724 GLfloat* curcol =
new GLfloat[4];
725 glGetFloatv(GL_CURRENT_COLOR, curcol);
730 glEnableClientState(GL_COLOR_ARRAY);
731 glColorPointer(4, GL_FLOAT, 0, cubeColorArray);
735 glNormal3f(0.0f, 1.0f, 0.0f);
736 glVertexPointer(3, GL_FLOAT, 0, cubeArray[0]);
737 glDrawArrays(GL_QUADS, 0, cubeArraySize / 3);
739 glNormal3f(0.0f, -1.0f, 0.0f);
740 glVertexPointer(3, GL_FLOAT, 0, cubeArray[1]);
741 glDrawArrays(GL_QUADS, 0, cubeArraySize / 3);
743 glNormal3f(1.0f, 0.0f, 0.0f);
744 glVertexPointer(3, GL_FLOAT, 0, cubeArray[2]);
745 glDrawArrays(GL_QUADS, 0, cubeArraySize / 3);
747 glNormal3f(-1.0f, 0.0f, 0.0f);
748 glVertexPointer(3, GL_FLOAT, 0, cubeArray[3]);
749 glDrawArrays(GL_QUADS, 0, cubeArraySize / 3);
751 glNormal3f(0.0f, 0.0f, -1.0f);
752 glVertexPointer(3, GL_FLOAT, 0, cubeArray[4]);
753 glDrawArrays(GL_QUADS, 0, cubeArraySize / 3);
755 glNormal3f(0.0f, 0.0f, 1.0f);
756 glVertexPointer(3, GL_FLOAT, 0, cubeArray[5]);
757 glDrawArrays(GL_QUADS, 0, cubeArraySize / 3);
760 && (cubeColorArray != NULL)){
761 glDisableClientState(GL_COLOR_ARRAY);
766 glDisable(GL_LIGHTING);
767 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
768 glEnable (GL_LINE_SMOOTH);
769 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
771 glColor3f(0.0f, 0.0f, 0.0f);
772 glCullFace(GL_FRONT_AND_BACK);
776 glNormal3f(0.0f, 1.0f, 0.0f);
777 glVertexPointer(3, GL_FLOAT, 0, cubeArray[0]);
778 glDrawArrays(GL_QUADS, 0, cubeArraySize / 3);
780 glNormal3f(0.0f, -1.0f, 0.0f);
781 glVertexPointer(3, GL_FLOAT, 0, cubeArray[1]);
782 glDrawArrays(GL_QUADS, 0, cubeArraySize / 3);
784 glNormal3f(1.0f, 0.0f, 0.0f);
785 glVertexPointer(3, GL_FLOAT, 0, cubeArray[2]);
786 glDrawArrays(GL_QUADS, 0, cubeArraySize / 3);
788 glNormal3f(-1.0f, 0.0f, 0.0f);
789 glVertexPointer(3, GL_FLOAT, 0, cubeArray[3]);
790 glDrawArrays(GL_QUADS, 0, cubeArraySize / 3);
795 glDisable(GL_LINE_SMOOTH);
796 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
797 glEnable(GL_LIGHTING);
808 glDisable(GL_LIGHTING);
809 glEnable(GL_LINE_SMOOTH);
813 glColor3f(0.0, 0.0, 0.0);
816 glDisable(GL_LINE_SMOOTH);
817 glEnable(GL_LIGHTING);
830 std::cout <<
"OcTreeDrawer: setting new global origin: " << t << std::endl;
834 std::cout <<
"origin : " <<
origin << std::endl;
836 std::cout <<
"relative trans: " << relative_transform << std::endl;
845 float length = 0.15f;
847 GLboolean lighting, colorMaterial;
848 glGetBooleanv(GL_LIGHTING, &lighting);
849 glGetBooleanv(GL_COLOR_MATERIAL, &colorMaterial);
851 glDisable(GL_COLOR_MATERIAL);
861 if (angle > 0) glRotatef(
OTD_RAD2DEG*angle, ax, ay, az);
864 color[0] = 0.7f; color[1] = 0.7f; color[2] = 1.0f; color[3] = 1.0f;
865 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
868 color[0] = 1.0f; color[1] = 0.7f; color[2] = 0.7f; color[3] = 1.0f;
869 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
871 glRotatef(90.0, 0.0, 1.0, 0.0);
875 color[0] = 0.7f; color[1] = 1.0f; color[2] = 0.7f; color[3] = 1.0f;
876 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
878 glRotatef(-90.0, 1.0, 0.0, 0.0);
882 glTranslatef(relative_transform.
trans().
x(), relative_transform.
trans().
y(), relative_transform.
trans().
z());
885 glEnable(GL_COLOR_MATERIAL);
887 glDisable(GL_LIGHTING);
const tree_iterator end_tree() const
void setOcTree(const AbstractOcTree &octree)
sets a new OcTree that should be drawn by this drawer
unsigned int setCubeColorHeightmap(const octomap::OcTreeVolume &v, const unsigned int ¤t_array_idx, GLfloat **glColorArray)
unsigned int octree_grid_vertex_size
void clearCubes(GLfloat ***glArray, unsigned int &glArraySize, GLfloat **glColorArray=NULL)
clear OpenGL visualization
GLfloat ** m_occupiedArray
GLfloat * octree_grid_vertex_array
OpenGL representation of Octree (grid structure)
void clearOcTreeSelection()
clear the visualization of the OcTree selection
void clearOcTreeStructure()
std::pair< point3d, double > OcTreeVolume
octomap::pose6d initial_origin
GLfloat * m_occupiedColorArray
void enableOcTree(bool enabled=true)
void initCubeTemplate(const octomath::Pose6D &origin, std::vector< octomath::Vector3 > &cube_template)
setup cube template
Vector3 rotate(const Vector3 &v) const
bool isNodeAtThreshold(const OcTreeNode *occupancyNode) const
void setOcTreeSelection(const std::list< octomap::OcTreeVolume > &selectedPoints)
sets a new selection of the current OcTree to be drawn
virtual void getMetricMin(double &x, double &y, double &z)
void generateCubes(const std::list< octomap::OcTreeVolume > &voxels, GLfloat ***glArray, unsigned int &glArraySize, octomath::Pose6D &origin, GLfloat **glColorArray=NULL)
GLfloat ** m_freeThresArray
void drawFreeVoxels() const
void drawOctreeGrid() const
bool m_octree_grid_vis_initialized
GLfloat ** m_occupiedThresArray
OpenGL representation of Octree cells (cubes)
unsigned int m_selectionSize
void heightMapGray(double h, GLfloat *glArrayPos) const
void drawOccupiedVoxels() const
unsigned int generateCube(const octomap::OcTreeVolume &v, const std::vector< octomath::Vector3 > &cube_template, const unsigned int ¤t_array_idx, GLfloat ***glArray)
add one cube to arrays
tree_iterator begin_tree(unsigned char maxDepth=0) const
virtual void getMetricMax(double &x, double &y, double &z)
void drawSelection() const
void initGLArrays(const unsigned int &num_cubes, unsigned int &glArraySize, GLfloat ***glArray, GLfloat **glColorArray)
setup OpenGL arrays
void heightMapColor(double h, GLfloat *glArrayPos) const
std::list< octomap::OcTreeVolume > m_grid_voxels
void drawCubes(GLfloat **cubeArray, unsigned int cubeArraySize, GLfloat *cubeColorArray=NULL) const
unsigned int m_occupiedThresSize
void setAlphaOccupied(double alpha)
sets alpha level for occupied cells
unsigned int m_occupiedSize
unsigned int setCubeColorRGBA(const unsigned char &r, const unsigned char &g, const unsigned char &b, const unsigned char &a, const unsigned int ¤t_array_idx, GLfloat **glColorArray)
GLfloat ** m_selectionArray
GLfloat * m_occupiedThresColorArray
Color array for occupied cells (height)
void setOrigin(octomap::pose6d t)
bool isNodeOccupied(const OcTreeNode *occupancyNode) const
virtual size_t size() const
unsigned int m_freeThresSize
static void drawArrow(qreal length=1.0, qreal radius=-1.0, int nbSubdivisions=12)