26 #undef GL_GLEXT_VERSION // Previously defined by glu
29 #define OTD_RAD2DEG 57.2957795
34 m_occupiedThresSize(0), m_freeThresSize(0),
35 m_occupiedSize(0), m_freeSize(0), m_selectionSize(0),
36 octree_grid_vertex_size(0), m_alphaOccupied(0.8), map_id(0)
65 static int gl_list_index = -1;
67 gl_list_index = glGenLists(1);
72 glDeleteLists(gl_list_index,1);
78 std::cout <<
"Preparing batch rendering, please wait ...\n";
79 glNewList(gl_list_index, GL_COMPILE_AND_EXECUTE);
90 glTranslatef(relative_transform.
x(), relative_transform.
y(), relative_transform.
z());
93 float scale = sqrt(q.
x() * q.
x() + q.
y() * q.
y() + q.
z() * q.
z());
95 float axis_x = q.
x() / scale;
96 float axis_y = q.
y() / scale;
97 float axis_z = q.
z() / scale;
99 glRotatef(angle, axis_x, axis_y, axis_z);
102 glEnableClientState(GL_VERTEX_ARRAY);
117 glDisableClientState(GL_VERTEX_ARRAY);
123 std::cout <<
"Finished preparation of batch rendering.\n";
129 glCallList(gl_list_index);
152 bool showAll = (octree.
size() < 5 * 1e6);
159 unsigned int cnt_occupied(0), cnt_occupied_thres(0), cnt_free(0), cnt_free_thres(0);
160 for(OcTree::tree_iterator it = octree.
begin_tree(this->m_max_tree_depth),
161 end=octree.
end_tree(); it!= end; ++it) {
179 double minX, minY, minZ, maxX, maxY, maxZ;
187 std::vector<octomath::Vector3> cube_template;
190 unsigned int idx_occupied(0), idx_occupied_thres(0), idx_free(0), idx_free_thres(0);
191 unsigned int color_idx_occupied(0), color_idx_occupied_thres(0);
195 for(OcTree::tree_iterator it = octree.
begin_tree(this->m_max_tree_depth),
196 end=octree.
end_tree(); it!= end; ++it) {
256 unsigned int& glArraySize,
257 GLfloat*** glArray, GLfloat** glColorArray) {
259 clearCubes(glArray, glArraySize, glColorArray);
262 glArraySize = num_cubes * 4 * 3;
265 *glArray =
new GLfloat* [6];
266 for (
unsigned i = 0; i<6; ++i){
267 (*glArray)[i] =
new GLfloat[glArraySize];
270 if (glColorArray != NULL)
271 *glColorArray =
new GLfloat[glArraySize * 4 *4];
275 std::vector<octomath::Vector3>& cube_template) {
276 cube_template.clear();
277 cube_template.reserve(24);
309 const std::vector<octomath::Vector3>& cube_template,
310 const unsigned int& current_array_idx,
311 GLfloat*** glArray) {
319 double half_cube_size = GLfloat(v.second /2.0 -eps);
320 unsigned int i = current_array_idx;
325 p = v.first + cube_template[0] * half_cube_size;
326 (*glArray)[0][i] = p.
x();
327 (*glArray)[0][i+1] = p.
y();
328 (*glArray)[0][i+2] = p.
z();
330 p = v.first + cube_template[1] * half_cube_size;
331 (*glArray)[1][i] = p.
x();
332 (*glArray)[1][i+1] = p.
y();
333 (*glArray)[1][i+2] = p.
z();
335 p = v.first + cube_template[2] * half_cube_size;
336 (*glArray)[2][i] = p.
x();
337 (*glArray)[2][i+1] = p.
y();
338 (*glArray)[2][i+2] = p.
z();
340 p = v.first + cube_template[3] * half_cube_size;
341 (*glArray)[3][i] = p.
x();
342 (*glArray)[3][i+1] = p.
y();
343 (*glArray)[3][i+2] = p.
z();
345 p = v.first + cube_template[4] * half_cube_size;
346 (*glArray)[4][i] = p.
x();
347 (*glArray)[4][i+1] = p.
y();
348 (*glArray)[4][i+2] = p.
z();
350 p = v.first + cube_template[5] * half_cube_size;
351 (*glArray)[5][i] = p.
x();
352 (*glArray)[5][i+1] = p.
y();
353 (*glArray)[5][i+2] = p.
z();
356 p = v.first + cube_template[6] * half_cube_size;
357 (*glArray)[0][i] = p.
x();
358 (*glArray)[0][i+1] = p.
y();
359 (*glArray)[0][i+2] = p.
z();
361 p = v.first + cube_template[7] * half_cube_size;
362 (*glArray)[1][i] = p.
x();
363 (*glArray)[1][i+1] = p.
y();
364 (*glArray)[1][i+2] = p.
z();
366 p = v.first + cube_template[8] * half_cube_size;
367 (*glArray)[2][i] = p.
x();
368 (*glArray)[2][i+1] = p.
y();
369 (*glArray)[2][i+2] = p.
z();
371 p = v.first + cube_template[9] * half_cube_size;
372 (*glArray)[3][i] = p.
x();
373 (*glArray)[3][i+1] = p.
y();
374 (*glArray)[3][i+2] = p.
z();
376 p = v.first + cube_template[10] * half_cube_size;
377 (*glArray)[4][i] = p.
x();
378 (*glArray)[4][i+1] = p.
y();
379 (*glArray)[4][i+2] = p.
z();
381 p = v.first + cube_template[11] * half_cube_size;
382 (*glArray)[5][i] = p.
x();
383 (*glArray)[5][i+1] = p.
y();
384 (*glArray)[5][i+2] = p.
z();
387 p = v.first + cube_template[12] * half_cube_size;
388 (*glArray)[0][i] = p.
x();
389 (*glArray)[0][i+1] = p.
y();
390 (*glArray)[0][i+2] = p.
z();
392 p = v.first + cube_template[13] * half_cube_size;
393 (*glArray)[1][i] = p.
x();
394 (*glArray)[1][i+1] = p.
y();
395 (*glArray)[1][i+2] = p.
z();
397 p = v.first + cube_template[14] * half_cube_size;
398 (*glArray)[2][i] = p.
x();
399 (*glArray)[2][i+1] = p.
y();
400 (*glArray)[2][i+2] = p.
z();
402 p = v.first + cube_template[15] * half_cube_size;
403 (*glArray)[3][i] = p.
x();
404 (*glArray)[3][i+1] = p.
y();
405 (*glArray)[3][i+2] = p.
z();
407 p = v.first + cube_template[16] * half_cube_size;
408 (*glArray)[4][i] = p.
x();
409 (*glArray)[4][i+1] = p.
y();
410 (*glArray)[4][i+2] = p.
z();
412 p = v.first + cube_template[17] * half_cube_size;
413 (*glArray)[5][i] = p.
x();
414 (*glArray)[5][i+1] = p.
y();
415 (*glArray)[5][i+2] = p.
z();
418 p = v.first + cube_template[18] * half_cube_size;
419 (*glArray)[0][i] = p.
x();
420 (*glArray)[0][i+1] = p.
y();
421 (*glArray)[0][i+2] = p.
z();
423 p = v.first + cube_template[19] * half_cube_size;
424 (*glArray)[1][i] = p.
x();
425 (*glArray)[1][i+1] = p.
y();
426 (*glArray)[1][i+2] = p.
z();
428 p = v.first + cube_template[20] * half_cube_size;
429 (*glArray)[2][i] = p.
x();
430 (*glArray)[2][i+1] = p.
y();
431 (*glArray)[2][i+2] = p.
z();
433 p = v.first + cube_template[21] * half_cube_size;
434 (*glArray)[3][i] = p.
x();
435 (*glArray)[3][i+1] = p.
y();
436 (*glArray)[3][i+2] = p.
z();
438 p = v.first + cube_template[22] * half_cube_size;
439 (*glArray)[4][i] = p.
x();
440 (*glArray)[4][i+1] = p.
y();
441 (*glArray)[4][i+2] = p.
z();
443 p = v.first + cube_template[23] * half_cube_size;
444 (*glArray)[5][i] = p.
x();
445 (*glArray)[5][i+1] = p.
y();
446 (*glArray)[5][i+2] = p.
z();
454 const unsigned int& current_array_idx,
455 GLfloat** glColorArray) {
457 if (glColorArray == NULL)
return current_array_idx;
459 unsigned int colorIdx = current_array_idx;
461 for (
int k = 0; k < 4; ++k) {
474 const unsigned char& g,
475 const unsigned char& b,
476 const unsigned char& a,
477 const unsigned int& current_array_idx,
478 GLfloat** glColorArray) {
480 if (glColorArray == NULL)
return current_array_idx;
481 unsigned int colorIdx = current_array_idx;
483 for (
int k = 0; k < 4; ++k) {
484 (*glColorArray)[colorIdx ] = (double) r/255.;
485 (*glColorArray)[colorIdx + 1] = (double) g/255.;
486 (*glColorArray)[colorIdx + 2] = (double) b/255.;
487 (*glColorArray)[colorIdx + 3] = (double) a/255.;
495 unsigned int& glArraySize,
496 GLfloat** glColorArray) {
497 if (glArraySize != 0) {
498 for (
unsigned i = 0; i < 6; ++i) {
499 delete[] (*glArray)[i];
505 if (glColorArray != NULL && *glColorArray != NULL) {
506 delete[] *glColorArray;
507 *glColorArray = NULL;
514 GLfloat*** glArray,
unsigned int& glArraySize,
516 GLfloat** glColorArray) {
518 unsigned int colorIdx = 0;
520 std::vector<octomath::Vector3> cube_template;
523 for (std::list<octomap::OcTreeVolume>::const_iterator it=voxels.begin();
524 it != voxels.end(); it++) {
528 if (glColorArray != NULL) {
529 for (std::list<octomap::OcTreeVolume>::const_iterator it=voxels.begin();
530 it != voxels.end(); it++) {
546 std::list<octomap::OcTreeVolume>::iterator it_rec;
551 x = it_rec->first.x();
552 y = it_rec->first.y();
553 z = it_rec->first.z();
555 double half_voxel_size = it_rec->second / 2.0;
685 glColor3f(0.784f, 0.66f, 0);
687 else if (this->
map_id == 1) {
688 glColor3f(0.68f, 0., 0.62f);
691 glColor3f(0., 0.784f, 0.725f);
699 glColor3f(0.6f, 0.6f, 0.6f);
702 glColor3f(0.1f, 0.1f, 0.1f);
725 glColor3f(0.5f, 0.5f, 0.5f);
728 glColor3f(0.9f, 0.9f, 0.9f);
747 glColor4f(1.0, 0.0, 0.0, 1.0);
753 GLfloat* cubeColorArray)
const {
754 if (cubeArraySize == 0 || cubeArray == NULL){
755 std::cerr <<
"Warning: GLfloat array to draw cubes appears to be empty, nothing drawn.\n";
760 GLfloat* curcol =
new GLfloat[4];
761 glGetFloatv(GL_CURRENT_COLOR, curcol);
766 glEnableClientState(GL_COLOR_ARRAY);
767 glColorPointer(4, GL_FLOAT, 0, cubeColorArray);
771 glNormal3f(0.0f, 1.0f, 0.0f);
772 glVertexPointer(3, GL_FLOAT, 0, cubeArray[0]);
773 glDrawArrays(GL_QUADS, 0, cubeArraySize / 3);
775 glNormal3f(0.0f, -1.0f, 0.0f);
776 glVertexPointer(3, GL_FLOAT, 0, cubeArray[1]);
777 glDrawArrays(GL_QUADS, 0, cubeArraySize / 3);
779 glNormal3f(1.0f, 0.0f, 0.0f);
780 glVertexPointer(3, GL_FLOAT, 0, cubeArray[2]);
781 glDrawArrays(GL_QUADS, 0, cubeArraySize / 3);
783 glNormal3f(-1.0f, 0.0f, 0.0f);
784 glVertexPointer(3, GL_FLOAT, 0, cubeArray[3]);
785 glDrawArrays(GL_QUADS, 0, cubeArraySize / 3);
787 glNormal3f(0.0f, 0.0f, -1.0f);
788 glVertexPointer(3, GL_FLOAT, 0, cubeArray[4]);
789 glDrawArrays(GL_QUADS, 0, cubeArraySize / 3);
791 glNormal3f(0.0f, 0.0f, 1.0f);
792 glVertexPointer(3, GL_FLOAT, 0, cubeArray[5]);
793 glDrawArrays(GL_QUADS, 0, cubeArraySize / 3);
796 && (cubeColorArray != NULL)){
797 glDisableClientState(GL_COLOR_ARRAY);
802 glDisable(GL_LIGHTING);
803 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
804 glEnable (GL_LINE_SMOOTH);
805 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
807 glColor3f(0.0f, 0.0f, 0.0f);
808 glCullFace(GL_FRONT_AND_BACK);
812 glNormal3f(0.0f, 1.0f, 0.0f);
813 glVertexPointer(3, GL_FLOAT, 0, cubeArray[0]);
814 glDrawArrays(GL_QUADS, 0, cubeArraySize / 3);
816 glNormal3f(0.0f, -1.0f, 0.0f);
817 glVertexPointer(3, GL_FLOAT, 0, cubeArray[1]);
818 glDrawArrays(GL_QUADS, 0, cubeArraySize / 3);
820 glNormal3f(1.0f, 0.0f, 0.0f);
821 glVertexPointer(3, GL_FLOAT, 0, cubeArray[2]);
822 glDrawArrays(GL_QUADS, 0, cubeArraySize / 3);
824 glNormal3f(-1.0f, 0.0f, 0.0f);
825 glVertexPointer(3, GL_FLOAT, 0, cubeArray[3]);
826 glDrawArrays(GL_QUADS, 0, cubeArraySize / 3);
831 glDisable(GL_LINE_SMOOTH);
832 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
833 glEnable(GL_LIGHTING);
844 glDisable(GL_LIGHTING);
845 glEnable(GL_LINE_SMOOTH);
849 glColor3f(0.0, 0.0, 0.0);
852 glDisable(GL_LINE_SMOOTH);
853 glEnable(GL_LIGHTING);
867 std::cout <<
"OcTreeDrawer: setting new global origin: " << t << std::endl;
871 std::cout <<
"origin : " <<
origin << std::endl;
873 std::cout <<
"relative trans: " << relative_transform << std::endl;
882 float length = 0.15f;
884 GLboolean lighting, colorMaterial;
885 glGetBooleanv(GL_LIGHTING, &lighting);
886 glGetBooleanv(GL_COLOR_MATERIAL, &colorMaterial);
888 glDisable(GL_COLOR_MATERIAL);
898 if (angle > 0) glRotatef(
OTD_RAD2DEG*angle, ax, ay, az);
901 color[0] = 0.7f; color[1] = 0.7f; color[2] = 1.0f; color[3] = 1.0f;
902 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
905 color[0] = 1.0f; color[1] = 0.7f; color[2] = 0.7f; color[3] = 1.0f;
906 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
908 glRotatef(90.0, 0.0, 1.0, 0.0);
912 color[0] = 0.7f; color[1] = 1.0f; color[2] = 0.7f; color[3] = 1.0f;
913 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
915 glRotatef(-90.0, 1.0, 0.0, 0.0);
919 glTranslatef(relative_transform.
trans().
x(), relative_transform.
trans().
y(), relative_transform.
trans().
z());
922 glEnable(GL_COLOR_MATERIAL);
924 glDisable(GL_LIGHTING);