SceneObject.cpp
Go to the documentation of this file.
00001 /*
00002  * OctoMap - An Efficient Probabilistic 3D Mapping Framework Based on Octrees
00003  * http://octomap.github.com/
00004  *
00005  * Copyright (c) 2009-2013, K.M. Wurm and A. Hornung, University of Freiburg
00006  * All rights reserved.
00007  * License (octovis): GNU GPL v2
00008  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
00009  *
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful, but
00017  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00018  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
00019  * for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License along
00022  * with this program; if not, write to the Free Software Foundation, Inc.,
00023  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00024  */
00025 
00026 #define NOMINMAX
00027 #include <octovis/SceneObject.h>
00028 
00029 #ifndef RAD2DEG
00030 #define RAD2DEG(x) ((x) * 57.29577951308232087721)
00031 #endif
00032 
00033 namespace octomap {
00034 
00035   SceneObject::SceneObject() :
00036     m_zMin(0.0), m_zMax(1.0), m_colorMode(CM_FLAT) {
00037   }
00038 
00039   void SceneObject::heightMapColor(double h, GLfloat* glArrayPos) const {
00040     if (m_zMin >= m_zMax)
00041       h = 0.5;
00042     else{
00043       h = (1.0 - std::min(std::max((h-m_zMin)/ (m_zMax - m_zMin), 0.0), 1.0)) *0.8;
00044     }
00045 
00046     // blend over HSV-values (more colors)
00047     double r, g, b;
00048     double s = 1.0;
00049     double v = 1.0;
00050 
00051     h -= floor(h);
00052     h *= 6;
00053     int i;
00054     double m, n, f;
00055 
00056     i = floor(h);
00057     f = h - i;
00058     if (!(i & 1))
00059       f = 1 - f; // if i is even
00060     m = v * (1 - s);
00061     n = v * (1 - s * f);
00062 
00063     switch (i) {
00064     case 6:
00065     case 0:
00066       r = v; g = n; b = m;
00067       break;
00068     case 1:
00069       r = n; g = v; b = m;
00070       break;
00071     case 2:
00072       r = m; g = v; b = n;
00073       break;
00074     case 3:
00075       r = m; g = n; b = v;
00076       break;
00077     case 4:
00078       r = n; g = m; b = v;
00079       break;
00080     case 5:
00081       r = v; g = m; b = n;
00082       break;
00083     default:
00084       r = 1; g = 0.5; b = 0.5;
00085       break;
00086     }
00087 
00088     glArrayPos[0] = r;
00089     glArrayPos[1] = g;
00090     glArrayPos[2] = b;
00091   }
00092 
00093   void SceneObject::heightMapGray(double h, GLfloat* glArrayPos) const {
00094     if (m_zMin >= m_zMax)
00095       h = 0.5;
00096     else{
00097       h = std::min(std::max((h-m_zMin)/ (m_zMax - m_zMin), 0.0), 1.0) * 0.4 + 0.3; // h \in [0.3, 0.7]
00098     }
00099 
00100     glArrayPos[0] = h;
00101     glArrayPos[1] = h;
00102     glArrayPos[2] = h;
00103   }
00104   
00105 
00106 }


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Thu Aug 27 2015 14:13:26