Salome HOME
Doc: indicating how to pass MPI_Comm from mpi4py
[tools/medcoupling.git] / src / INTERP_KERNEL / BoundingBox.hxx
1 // Copyright (C) 2007-2022  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, or (at your option) any later version.
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
20 #ifndef __BOUNDINGBOX_HXX__
21 #define __BOUNDINGBOX_HXX__
22
23 #include "INTERPKERNELDefines.hxx"
24 #include <iostream>
25
26 namespace INTERP_KERNEL
27 {
28
29   /**
30    * \brief Class representing the bounding box of a number of points.
31    *
32    */
33   class INTERPKERNEL_EXPORT BoundingBox 
34   {
35   public:
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() { }
40
41     BoundingBox(const double** pts, const unsigned numPts);
42
43     BoundingBox(const BoundingBox& box1, const BoundingBox& box2);
44
45     ~BoundingBox() { }
46     
47     void fillInXMinXmaxYminYmaxZminZmaxFormat(double data[6]) const;
48
49     void initializeWith(const double** pts, const unsigned numPts);
50
51     bool isDisjointWith(const BoundingBox& box) const;
52     
53     inline void setCoordinate(const BoxCoord coord, double value);
54
55     inline double getCoordinate(const BoxCoord coord) const;
56
57     void updateWithPoint(const double* pt);
58
59     inline void dumpCoords() const;
60
61     void toCompactData(double data[6]) const;
62   
63     BoundingBox& operator=(const BoundingBox& box) = delete;
64
65   private:
66     
67     bool isValid() const;
68
69     /// disallow copying
70     BoundingBox(const BoundingBox& box);
71     
72     /// Vector containing the coordinates of the box
73     /// interlaced in the order XMIN, YMIN, ZMIN, XMAX, YMAX, ZMAX
74     double _coords[6];
75
76   };
77
78   /**
79    * Sets a coordinate of the box to a given value.
80    * 
81    * @param coord coordinate to set
82    * @param value new value for coordinate
83    *
84    */
85   inline void BoundingBox::setCoordinate(const BoxCoord coord, double value)
86   {
87     _coords[coord] = value;
88   }
89
90   /**
91    * Gets a coordinate of the box
92    * 
93    * @param coord coordinate to get
94    * @return value of coordinate
95    *
96    */
97   inline double BoundingBox::getCoordinate(const BoxCoord coord) const
98   {
99     return _coords[coord];
100   }
101
102   /**
103    * Prints the coordinates of the box to std::cout
104    *
105    */
106   inline void BoundingBox::dumpCoords() const
107   {
108     std::cout << "[xmin, xmax] = [" << _coords[XMIN] << ", " << _coords[XMAX] << "]" << " | ";
109     std::cout << "[ymin, ymax] = [" << _coords[YMIN] << ", " << _coords[YMAX] << "]" << " | ";
110     std::cout << "[zmin, zmax] = [" << _coords[ZMIN] << ", " << _coords[ZMAX] << "]";
111     std::cout << std::endl;
112   }
113
114 }
115
116 #endif