bbox.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  * \file
00003  *
00004  * $Id:$
00005  *
00006  * Copyright (C) Brno University of Technology (BUT)
00007  *
00008  * This file is part of software developed by dcgm-robotics@FIT group.
00009  *
00010  * Author: Jan Gorig (xgorig01@stud.fit.vutbr.cz)
00011  * Supervised by: Michal Spanel (spanel@fit.vutbr.cz)
00012  * Date: 12/04/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 <cmath>
00029 #include <srs_env_model/but_server/objtree/bbox.h>
00030 
00031 namespace objtree
00032 {
00033 
00038 BBox::BBox(const Box &box) :
00039     m_box(box)
00040 {
00041     m_type = ALIGNED_BOUNDING_BOX;
00042 }
00043 
00049 bool BBox::fitsIntoBox(const Box &box) const
00050 {
00051     if(m_box.x >= box.x && m_box.y >= box.y && m_box.z >= box.z && m_box.x+m_box.w <= box.x+box.w && m_box.y+m_box.h <= box.y+box.h && m_box.z+m_box.d <= box.z+box.d)
00052     {
00053         return true;
00054     }
00055 
00056     return false;
00057 }
00058 
00064 bool BBox::interfereWithBox(const Box &box) const
00065 {
00066     if(m_box.x > box.x+box.w || m_box.x+m_box.w < box.x)
00067     {
00068         return false;
00069     }
00070 
00071     if(m_box.y > box.y+box.h || m_box.y+m_box.h < box.y)
00072     {
00073         return false;
00074     }
00075 
00076     if(m_box.z > box.z+box.d || m_box.z+m_box.d < box.z)
00077     {
00078         return false;
00079     }
00080 
00081     return true;
00082 }
00083 
00089 bool BBox::isSimilar(const Object *object) const
00090 {
00091     if(object->type() != ALIGNED_BOUNDING_BOX) return false;
00092 
00093     return isSimilarBBox((BBox*)object);
00094 }
00095 
00101 bool BBox::isSimilarBBox(const BBox *box) const
00102 {
00103 
00104     if(fabs(box->m_box.x-m_box.x) > 0.5f) return false;
00105     if(fabs(box->m_box.y-m_box.y) > 0.5f) return false;
00106     if(fabs(box->m_box.z-m_box.z) > 0.5f) return false;
00107 
00108     if(fabs(box->m_box.w-m_box.w) > 0.2f) return false;
00109     if(fabs(box->m_box.h-m_box.h) > 0.2f) return false;
00110     if(fabs(box->m_box.d-m_box.d) > 0.2f) return false;
00111 
00112     return true;
00113 }
00114 
00122 bool BBox::isPointInside(float x, float y, float z) const
00123 {
00124     return x >= m_box.x && x <= m_box.x+m_box.w
00125             && y >= m_box.y && y <= m_box.y+m_box.h
00126             && z >= m_box.z && z <= m_box.z+m_box.d;
00127 }
00128 
00133 const Box& BBox::box() const
00134 {
00135     return m_box;
00136 }
00137 
00138 }


srs_env_model
Author(s): Vit Stancl (stancl@fit.vutbr.cz), Tomas Lokaj, Jan Gorig, Michal Spanel (spanel@fit.vutbr.cz)
autogenerated on Sun Jan 5 2014 11:50:48