|
|
|
boundBox.HGo to the documentation of this file.00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2007 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 00111 // Query 00112 00113 //- Intersects other boundingbox? 00114 bool intersects(const boundBox& bb) const 00115 { 00116 if 00117 ( 00118 (min_.x() <= bb.max().x()) && 00119 (min_.y() <= bb.max().y()) && 00120 (min_.z() <= bb.max().z()) && 00121 00122 (max_.x() >= bb.min().x()) && 00123 (max_.y() >= bb.min().y()) && 00124 (max_.z() >= bb.min().z()) 00125 ) 00126 { 00127 return true; 00128 } 00129 else 00130 { 00131 return false; 00132 } 00133 } 00134 00135 00136 //- Contains a point? 00137 bool contains(const point& pt) const 00138 { 00139 return 00140 pt.x() >= min().x() 00141 && pt.y() >= min().y() 00142 && pt.z() >= min().z() 00143 && pt.x() <= max().x() 00144 && pt.y() <= max().y() 00145 && pt.z() <= max().z(); 00146 } 00147 00148 00149 // Ostream operator 00150 00151 friend Ostream& operator<<(Ostream& os, const boundBox& b); 00152 }; 00153 00154 00155 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00156 00157 } // End namespace Foam 00158 00159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00160 00161 #endif 00162 00163 // ************************************************************************* // |