00001 /* 00002 * Copyright (c) 2013, Fraunhofer FKIE 00003 * 00004 * Authors: Bastian Gaspers 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are met: 00008 * 00009 * * Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * * Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * * Neither the name of the Fraunhofer FKIE nor the names of its 00015 * contributors may be used to endorse or promote products derived from 00016 * this software without specific prior written permission. 00017 * 00018 * This file is part of the StructureColoring ROS package. 00019 * 00020 * The StructureColoring ROS package is free software: 00021 * you can redistribute it and/or modify it under the terms of the 00022 * GNU Lesser General Public License as published by the Free 00023 * Software Foundation, either version 3 of the License, or 00024 * (at your option) any later version. 00025 * 00026 * The StructureColoring ROS package is distributed in the hope that it will be useful, 00027 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00028 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00029 * GNU Lesser General Public License for more details. 00030 * 00031 * You should have received a copy of the GNU Lesser General Public License 00032 * along with The StructureColoring ROS package. 00033 * If not, see <http://www.gnu.org/licenses/>. 00034 */ 00035 00036 #include <structureColoring/grids/CylinderGridMap.h> 00037 #include <cmath> 00038 00039 void CylinderGridMap::pointToHeigthAngle(float& height, float& angle, const Vec3& p) const 00040 { 00041 static const float PI2 = 2*M_PI; 00042 Vec3 cP; 00043 mCylinder->transformToCylinder(cP, p); 00044 height = cP.z() - mCylinder->getAxisMin(); 00045 angle = std::atan2(cP.y(), cP.x()); 00046 if (angle < 0) 00047 angle += PI2; 00048 } 00049 00050 void CylinderGridMap::heigthAngleToXY(unsigned int& x, unsigned int& y, float height, float angle) const 00051 { 00052 x = static_cast<unsigned int>((angle*mCylinder->getRadius())/mCellSize); 00053 y = static_cast<unsigned int>(height/mCellSize); 00054 } 00055 00056 void CylinderGridMap::addVec3(const Vec3& p) 00057 { 00058 float height, angle; 00059 unsigned int x, y; 00060 this->pointToHeigthAngle(height, angle, p); 00061 this->heigthAngleToXY(x, y, height, angle); 00062 //ROS_INFO("height %f, angle %f, x %d, y %d", height, angle, x, y); 00063 assert(x < this->getWidth()); 00064 assert(y < this->getHeight()); 00065 this->operator()(x, y) = true; 00066 } 00067