Salome HOME
Merge from BR_V5_DEV 16Feb09
[tools/medcoupling.git] / src / INTERP_KERNEL / BoundingBox.hxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #ifndef __BOUNDINGBOX_HXX__
20 #define __BOUNDINGBOX_HXX__
21
22 #include "INTERPKERNELDefines.hxx"
23 #include <iostream>
24
25 namespace INTERP_KERNEL
26 {
27
28   /**
29    * \brief Class representing the bounding box of a number of points.
30    *
31    */
32   class INTERPKERNEL_EXPORT BoundingBox 
33   {
34   public:
35
36     /// Enumeration representing the six coordinates that define the bounding box
37     enum BoxCoord { XMIN = 0, YMIN = 1, ZMIN = 2, XMAX = 3, YMAX = 4, ZMAX = 5 };
38         
39     BoundingBox(const double** pts, const unsigned numPts);
40
41     BoundingBox(const BoundingBox& box1, const BoundingBox& box2);
42
43     ~BoundingBox();
44
45     bool isDisjointWith(const BoundingBox& box) const;
46     
47     inline void setCoordinate(const BoxCoord coord, double value);
48
49     inline double getCoordinate(const BoxCoord coord) const;
50
51     void updateWithPoint(const double* pt);
52
53     inline void dumpCoords() const;
54
55   private:
56     
57     bool isValid() const;
58
59     /// disallow copying
60     BoundingBox(const BoundingBox& box);
61     
62     /// disallow assignment
63     BoundingBox& operator=(const BoundingBox& box);
64     
65     /// Vector containing the coordinates of the box
66     /// interlaced in the order XMIN, YMIN, ZMIN, XMAX, YMAX, ZMAX
67     double* _coords;
68
69   };
70
71   /**
72    * Sets a coordinate of the box to a given value.
73    * 
74    * @param coord coordinate to set
75    * @param value new value for coordinate
76    *
77    */
78   inline void BoundingBox::setCoordinate(const BoxCoord coord, double value)
79   {
80     _coords[coord] = value;
81   }
82
83   /**
84    * Gets a coordinate of the box
85    * 
86    * @param coord coordinate to get
87    * @return value of coordinate
88    *
89    */
90   inline double BoundingBox::getCoordinate(const BoxCoord coord) const
91   {
92     return _coords[coord];
93   }
94
95   /**
96    * Prints the coordinates of the box to std::cout
97    *
98    */
99   inline void BoundingBox::dumpCoords() const
100   {
101     std::cout << "[xmin, xmax] = [" << _coords[XMIN] << ", " << _coords[XMAX] << "]" << " | ";
102     std::cout << "[ymin, ymax] = [" << _coords[YMIN] << ", " << _coords[YMAX] << "]" << " | ";
103     std::cout << "[zmin, zmax] = [" << _coords[ZMIN] << ", " << _coords[ZMAX] << "]";
104     std::cout << std::endl;
105   }
106
107 }
108
109 #endif