![]() |
|
00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2005 OpenCFD Ltd. 00006 \\/ M anipulation | 00007 ------------------------------------------------------------------------------- 00008 License 00009 This file is part of OpenFOAM. 00010 00011 OpenFOAM is free software; you can redistribute it and/or modify it 00012 under the terms of the GNU General Public License as published by the 00013 Free Software Foundation; either version 2 of the License, or (at your 00014 option) any later version. 00015 00016 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00019 for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with OpenFOAM; if not, write to the Free Software Foundation, 00023 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00024 00025 Class 00026 boundBox 00027 00028 Description 00029 A bounding box defined in terms of the points at it's extremities. 00030 00031 \*---------------------------------------------------------------------------*/ 00032 00033 #ifndef boundBox_H 00034 #define boundBox_H 00035 00036 #include "pointField.H" 00037 00038 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00039 00040 namespace Foam 00041 { 00042 00043 /*---------------------------------------------------------------------------*\ 00044 Class boundBox Declaration 00045 \*---------------------------------------------------------------------------*/ 00046 00047 class boundBox 00048 { 00049 // Private data 00050 00051 //- Minimum and maximum describing the bounding box 00052 point min_, max_; 00053 00054 00055 public: 00056 00057 // Constructors 00058 00059 //- Construct null setting points to zero 00060 boundBox() 00061 : 00062 min_(vector::zero), 00063 max_(vector::zero) 00064 {} 00065 00066 //- Construct from components 00067 boundBox(const point& min, const point& max) 00068 : 00069 min_(min), 00070 max_(max) 00071 {} 00072 00073 //- Construct as the bounding box of the given pointField. Does 00074 // parallel communication (doReduce = true) 00075 boundBox(const pointField& points, const bool doReduce = true); 00076 00077 //- Construct from Istream 00078 boundBox(Istream&); 00079 00080 00081 // Member functions 00082 00083 // Access 00084 00085 const point& min() const 00086 { 00087 return min_; 00088 } 00089 00090 const point& max() const 00091 { 00092 return max_; 00093 } 00094 00095 point& min() 00096 { 00097 return min_; 00098 } 00099 00100 point& max() 00101 { 00102 return max_; 00103 } 00104 00105 scalar mag() const 00106 { 00107 return ::Foam::mag(max_ - min_); 00108 } 00109 00110 //- Intersects other boundingbox? 00111 bool intersects(const boundBox& bb) const 00112 { 00113 if 00114 ( 00115 (min_.x() <= bb.max().x()) && 00116 (min_.y() <= bb.max().y()) && 00117 (min_.z() <= bb.max().z()) && 00118 00119 (max_.x() >= bb.min().x()) && 00120 (max_.y() >= bb.min().y()) && 00121 (max_.z() >= bb.min().z()) 00122 ) 00123 { 00124 return true; 00125 } 00126 else 00127 { 00128 return false; 00129 } 00130 } 00131 00132 00133 //- Contains a point? 00134 bool contains(const point& pt) const 00135 { 00136 return 00137 pt.x() >= min().x() 00138 && pt.y() >= min().y() 00139 && pt.z() >= min().z() 00140 && pt.x() <= max().x() 00141 && pt.y() <= max().y() 00142 && pt.z() <= max().z(); 00143 } 00144 00145 00146 // Ostream operator 00147 00148 friend Ostream& operator<<(Ostream& os, const boundBox& b); 00149 }; 00150 00151 00152 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00153 00154 } // End namespace Foam 00155 00156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00157 00158 #endif 00159 00160 // ************************************************************************* //