/******************************************************************************* * CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * * version 0.1 * * Copyright (C) 2009-2011, IGG Team, LSIIT, University of Strasbourg * * * * This library is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published by the * * Free Software Foundation; either version 2.1 of the License, or (at your * * option) any later version. * * * * This library is distributed in the hope that it will be useful, but WITHOUT * * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * * for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this library; if not, write to the Free Software Foundation, * * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * * * Web site: http://cgogn.u-strasbg.fr/ * * Contact information: cgogn@unistra.fr * * * *******************************************************************************/ namespace CGoGN { namespace Geom { template BoundingBox::BoundingBox() : m_initialized(false), m_pMin(0), m_pMax(0) {} template BoundingBox::BoundingBox(const VEC& p) : m_initialized(true), m_pMin(p), m_pMax(p) {} template VEC& BoundingBox::min() { return m_pMin ; } template const VEC& BoundingBox::min() const { return m_pMin ; } template VEC& BoundingBox::max() { return m_pMax ; } template const VEC& BoundingBox::max() const { return m_pMax ; } template typename VEC::DATA_TYPE BoundingBox::size(unsigned int coord) const { assert(coord < m_pMax.dimension()) ; return m_pMax[coord] - m_pMin[coord] ; } template typename VEC::DATA_TYPE BoundingBox::maxSize() const { typename VEC::DATA_TYPE max = m_pMax[0] - m_pMin[0] ; for(unsigned int i = 1; i < m_pMax.dimension(); ++i) { typename VEC::DATA_TYPE size = m_pMax[i] - m_pMin[i] ; if(size > max) max = size ; } return max ; } template typename VEC::DATA_TYPE BoundingBox::minSize() const { typename VEC::DATA_TYPE min = m_pMax[0] - m_pMin[0] ; for(unsigned int i = 1; i < m_pMax.dimension(); ++i) { typename VEC::DATA_TYPE size = m_pMax[i] - m_pMin[i] ; if(size < min) min = size ; } return min ; } template VEC BoundingBox::diag() const { return m_pMax - m_pMin ; } template typename VEC::DATA_TYPE BoundingBox::diagSize() const { return (m_pMax - m_pMin).norm() ; } template VEC BoundingBox::center() const { VEC center = (m_pMax + m_pMin) / typename VEC::DATA_TYPE(2) ; return center ; } template bool BoundingBox::isInitialized() const { return m_initialized; } /**********************************************/ /* FUNCTIONS */ /**********************************************/ template void BoundingBox::addPoint(const VEC& p) { if(!m_initialized) { m_pMin = p ; m_pMax = p ; m_initialized = true ; } else { for(unsigned int i = 0; i < p.dimension(); ++i) { if(p[i] < m_pMin[i]) m_pMin[i] = p[i] ; if(p[i] > m_pMax[i]) m_pMax[i] = p[i] ; } } } template bool BoundingBox::intersects(const BoundingBox& bb) { VEC bbmin = bb.min() ; VEC bbmax = bb.max() ; for(unsigned int i = 0; i < bbmin.dimension(); ++i) { if(m_pMax[i] < bbmin[i]) return false ; if(m_pMin[i] > bbmax[i]) return false ; } return true ; } template void BoundingBox::fusion(const BoundingBox& bb) { VEC bbmin = bb.min() ; VEC bbmax = bb.max() ; for(unsigned int i = 0; i < bbmin.size(); ++i) { if(bbmin[i] < m_pMin[i]) m_pMin[i] = bbmin[i] ; if(bbmax[i] > m_pMax[i]) m_pMax[i] = bbmax[i] ; } } template bool BoundingBox::contains(const VEC& p) { for(unsigned int i = 0; i < m_pMin.dimension(); ++i) { if(m_pMin[i] > p[i]) return false ; if(p[i] > m_pMax[i]) return false ; } return true; } template bool BoundingBox::contains(const BoundingBox& bb) { return this->contains(bb.min()) && this->contains(bb.max()); } //template //friend std::ostream& BoundingBox::operator<<(std::ostream& out, const BoundingBox& bb) //{ // out << bb.min() << " " << bb.max() ; // return out ; //} // //template //friend std::istream& BoundingBox::operator>>(std::istream& in, BoundingBox& bb) //{ // in >> bb.min() >> bb.max() ; // return in ; //} } // namespace Geom } // namespace CGoGN