$search
00001 /****************************************************************************** 00002 * \file 00003 * 00004 * $Id:$ 00005 * 00006 * Copyright (C) Brno University of Technology 00007 * 00008 * This file is part of software developed by dcgm-robotics@FIT group. 00009 * 00010 * Author: Vit Stancl (stancl@fit.vutbr.cz) 00011 * Supervised by: Michal Spanel (spanel@fit.vutbr.cz) 00012 * Date: dd/mm/2012 00013 * 00014 * This file is free software: you can redistribute it and/or modify 00015 * it under the terms of the GNU Lesser General Public License as published by 00016 * the Free Software Foundation, either version 3 of the License, or 00017 * (at your option) any later version. 00018 * 00019 * This file is distributed in the hope that it will be useful, 00020 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 * GNU Lesser General Public License for more details. 00023 * 00024 * You should have received a copy of the GNU Lesser General Public License 00025 * along with this file. If not, see <http://www.gnu.org/licenses/>. 00026 */ 00027 00028 #include <srs_env_model/but_server/plugins/octomap_plugin_tools/testing_planes.h> 00029 #include <iostream> 00030 00034 srs_env_model::CTestingPlane::CTestingPlane() 00035 : m_plane() 00036 , m_d( 0.0 ) 00037 { 00038 00039 } 00040 00044 srs_env_model::CTestingPlane::CTestingPlane(const CTestingPlane & plane) 00045 : m_plane( plane.m_plane ) 00046 , m_d( plane.m_d ) 00047 { 00048 00049 } 00050 00051 00055 srs_env_model::CTestingPlane srs_env_model::CTestingPlane::operator =(const CTestingPlane & plane) 00056 { 00057 m_plane = plane.m_plane; 00058 m_d = plane.m_d; 00059 00060 return plane; 00061 } 00062 00063 00067 srs_env_model::CTestingPlane::CTestingPlane(const tPoint & p1, const tPoint & p2, const tPoint & p3) 00068 { 00069 // Just call method 00070 set( p1, p2, p3 ); 00071 } 00072 00073 00077 srs_env_model::CTestingPlane::CTestingPlane(const tPoint & point, const tPoint & normal) 00078 { 00079 // Just call method 00080 set( point, normal ); 00081 } 00082 00083 00100 void srs_env_model::CTestingPlane::set(const tPoint & p1, const tPoint & p2, const tPoint & p3) 00101 { 00102 // Compute directional vectors 00103 tPoint dir1( p2 - p1 ), dir2( p3 - p1 ); 00104 00105 // Get normal vector from cross-product 00106 m_plane = dir1; 00107 m_plane = m_plane.cross(dir2); 00108 m_plane.normalize(); 00109 00110 // std::cerr << "Point: " << p1 << std::endl << "Normal: " << m_plane << std::endl; 00111 00112 // Compute last parameter 00113 m_d = - p1.dot( m_plane ); 00114 } 00115 00116 00120 void srs_env_model::CTestingPlane::set(const tPoint & point, const tPoint & normal) 00121 { 00122 m_plane = normal; 00123 m_plane.normalize(); 00124 m_d = - point.dot( m_plane ); 00125 } 00126 00127 00131 bool srs_env_model::CTestingPlane::isIn(double x, double y, double z) 00132 { 00133 tPoint p( x, y, z ); 00134 00135 return p.dot( m_plane ) + m_d >= 0; 00136 } 00137 00138 00140 00141 /* 00142 * Simple constructor 00143 */ 00144 srs_env_model::CTestingPlanes::CTestingPlanes() 00145 { 00146 } 00147 00148 00152 srs_env_model::CTestingPlanes::CTestingPlanes(const tPlanesStack & planes) 00153 { 00154 // Just call method 00155 set( planes ); 00156 } 00157 00158 00162 void srs_env_model::CTestingPlanes::set(const tPlanesStack & planes) 00163 { 00164 if( planes.size() == 0 ) 00165 return; 00166 00167 m_planes.clear(); 00168 m_planes.reserve( planes.size() ); 00169 std::copy( planes.begin(), planes.end(), m_planes.begin() ); 00170 } 00171 00172 /* 00173 * Test point 00174 */ 00175 bool srs_env_model::CTestingPlanes::isIn( double x, double y, double z ) 00176 { 00177 tPlanesStack::iterator i, end; 00178 for( i = m_planes.begin(), end = m_planes.end(); i != end; ++i) 00179 { 00180 // One wrong is enough 00181 if( ! i->isIn( x, y, z ) ) 00182 return false; 00183 } 00184 00185 return true; 00186 }