Back to index

salome-med  6.5.0
DirectedBoundingBox.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2009-2012  OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #ifndef __DIRECTEDBOUNDINGBOX_HXX__
00021 #define __DIRECTEDBOUNDINGBOX_HXX__
00022 
00023 #include "INTERPKERNELDefines.hxx"
00024 
00025 #include <vector>
00026 
00027 namespace INTERP_KERNEL
00028 {
00029 
00034   class INTERPKERNEL_EXPORT DirectedBoundingBox
00035   {
00036   public:
00037 
00038     DirectedBoundingBox();
00039 
00040     DirectedBoundingBox(const double* pts, const unsigned numPts, const unsigned dim);
00041 
00042     DirectedBoundingBox(const double** pts, const unsigned numPts, const unsigned dim);
00043 
00044     //~DirectedBoundingBox();
00045 
00046     void enlarge(const double tol);
00047     
00048     bool isDisjointWith(const DirectedBoundingBox& box) const;
00049 
00050     bool isDisjointWith(const double* box) const;
00051 
00052     bool isOut(const double* point) const;
00053 
00054 
00055     // return internal data
00056     std::vector<double> getData() const;
00057 
00058     // initialize with data returned by getData()
00059     void setData(const double* data);
00060 
00061     // return size of internal data
00062     static int dataSize(int dim);
00063 
00064   private:
00065 
00066     //void computeAxes3D(const std::vector<double>& tensor);
00067 
00068     //void computeAxes2D(const std::vector<double>& tensor);
00069 
00070     inline void addPointToBox(const double* coord);
00071 
00072     void toLocalCS(const double* p, double* pLoc) const;
00073 
00074     void fromLocalCS(const double* p, double* pGlob) const;
00075 
00076     inline bool isLocalOut(const double* pLoc) const;
00077 
00078     void getCorners(std::vector<double>& corners, const double* minmax) const;
00079 
00080     unsigned _dim;
00081 
00082     std::vector<double> _axes; 
00083     std::vector<double> _minmax; 
00084 
00085   };
00086 
00087   //================================================================================
00092   //================================================================================
00093 
00094   inline bool DirectedBoundingBox::isLocalOut(const double* pLoc) const
00095     {
00096       for ( int i = 0; i < (int)_dim; ++i )
00097         if ( pLoc[i] < _minmax[i*2] || pLoc[i] > _minmax[i*2+1] )
00098           return true;
00099       return false;
00100     }
00101 
00102   //================================================================================
00106   //================================================================================
00107 
00108   inline void DirectedBoundingBox::addPointToBox(const double* coord)
00109   {
00110     for ( int i = 0; i < (int)_dim; ++i )
00111       {
00112         double c = 0;
00113         for ( int j = 0; j < (int)_dim; ++j ) c += coord[j]*_axes[i*_dim+j];
00114         if ( c < _minmax[i*2] )   _minmax[i*2] = c;
00115         if ( c > _minmax[i*2+1] ) _minmax[i*2+1] = c;
00116       }
00117   }
00118 }
00119 #endif