1 // Copyright (C) 2009-2013 OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef __DIRECTEDBOUNDINGBOX_HXX__
21 #define __DIRECTEDBOUNDINGBOX_HXX__
23 #include "INTERPKERNELDefines.hxx"
27 namespace INTERP_KERNEL
31 * \brief Class representing the bounding box of a number of points
32 * with box axes parallel to principal axes of inertia of points
34 class DirectedBoundingBox
38 INTERPKERNEL_EXPORT DirectedBoundingBox();
40 INTERPKERNEL_EXPORT DirectedBoundingBox(const double* pts, const unsigned numPts, const unsigned dim);
42 INTERPKERNEL_EXPORT DirectedBoundingBox(const double** pts, const unsigned numPts, const unsigned dim);
44 //~DirectedBoundingBox();
46 INTERPKERNEL_EXPORT void enlarge(const double tol);
48 INTERPKERNEL_EXPORT bool isDisjointWith(const DirectedBoundingBox& box) const;
50 INTERPKERNEL_EXPORT bool isDisjointWith(const double* box) const;
52 INTERPKERNEL_EXPORT bool isOut(const double* point) const;
55 // return internal data
56 INTERPKERNEL_EXPORT std::vector<double> getData() const;
58 // initialize with data returned by getData()
59 INTERPKERNEL_EXPORT void setData(const double* data);
61 // return size of internal data
62 INTERPKERNEL_EXPORT static int dataSize(int dim);
66 //void computeAxes3D(const std::vector<double>& tensor);
68 //void computeAxes2D(const std::vector<double>& tensor);
70 inline void addPointToBox(const double* coord);
72 void toLocalCS(const double* p, double* pLoc) const;
74 void fromLocalCS(const double* p, double* pGlob) const;
76 inline bool isLocalOut(const double* pLoc) const;
78 void getCorners(std::vector<double>& corners, const double* minmax) const;
82 std::vector<double> _axes; //!< principal axes of inertia in full interlace
83 std::vector<double> _minmax; //!< pairs of min an max coordinates along the axes
87 //================================================================================
89 * \brief Test point in local CS against box extremities
92 //================================================================================
94 inline bool DirectedBoundingBox::isLocalOut(const double* pLoc) const
96 for ( int i = 0; i < (int)_dim; ++i )
97 if ( pLoc[i] < _minmax[i*2] || pLoc[i] > _minmax[i*2+1] )
102 //================================================================================
104 * \brief Update box extremities
106 //================================================================================
108 inline void DirectedBoundingBox::addPointToBox(const double* coord)
110 for ( int i = 0; i < (int)_dim; ++i )
113 for ( int j = 0; j < (int)_dim; ++j ) c += coord[j]*_axes[i*_dim+j];
114 if ( c < _minmax[i*2] ) _minmax[i*2] = c;
115 if ( c > _minmax[i*2+1] ) _minmax[i*2+1] = c;