KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
bounding_box.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Pooyan Dadvand
11 //
12 
13 #pragma once
14 
15 // System includes
16 
17 // External includes
18 
19 // Project includes
20 #include "includes/define.h"
21 
22 namespace Kratos
23 {
26 
29 
37 template <typename TPointType>
39 {
40 public:
43 
46 
50 
53  {
54  std::fill(GetMinPoint().begin(), GetMinPoint().end(), 0.0);
55  std::fill(GetMaxPoint().begin(), GetMaxPoint().end(), 0.0);
56  };
57 
59  BoundingBox(TPointType const& MinPoint, TPointType const& MaxPoint)
60  {
61  noalias(GetMinPoint().Coordinates()) = MinPoint.Coordinates();
62  noalias(GetMaxPoint().Coordinates()) = MaxPoint.Coordinates();
63  }
64 
66  BoundingBox( const BoundingBox &Other) :
67  mMinMaxPoints(Other.mMinMaxPoints) {}
68 
69 
71  template<typename TIteratorType>
72  BoundingBox(TIteratorType const& itPointsBegin, TIteratorType const& itPointsEnd)
73  {
74  Set(itPointsBegin, itPointsEnd);
75  }
76 
78  virtual ~BoundingBox(){}
79 
83 
86  {
87  GetMinPoint() = rOther.GetMinPoint();
88  GetMaxPoint() = rOther.GetMaxPoint();
89 
90  return *this;
91  }
92 
96 
107  template<typename TIteratorType>
108  void Set(TIteratorType const& itPointsBegin, TIteratorType const& itPointsEnd)
109  {
110  if (itPointsBegin == itPointsEnd) {
111  std::fill(GetMinPoint().begin(), GetMinPoint().end(), 0.0);
112  std::fill(GetMaxPoint().begin(), GetMaxPoint().end(), 0.0);
113  return;
114  }
115 
116  // Initialize the min and max points to the first point
117  auto& r_min_point = GetMinPoint();
118  auto& r_max_point = GetMaxPoint();
119  const auto& r_coordinates = itPointsBegin->Coordinates();
120  for (unsigned int i = 0; i < Dimension; i++) {
121  r_min_point[i] = r_coordinates[i];
122  r_max_point[i] = r_coordinates[i];
123  }
124 
125  Extend(itPointsBegin, itPointsEnd);
126  }
127 
138  template<typename TIteratorType>
139  void Extend(TIteratorType const& itPointsBegin, TIteratorType const& itPointsEnd)
140  {
141  // Extend the min and max points
142  auto& r_min_point = GetMinPoint();
143  auto& r_max_point = GetMaxPoint();
144  for (TIteratorType it_point = itPointsBegin; it_point != itPointsEnd; it_point++){
145  for (unsigned int i = 0; i < Dimension; i++) {
146  if ((*it_point)[i] < r_min_point[i]) r_min_point[i] = (*it_point)[i];
147  if ((*it_point)[i] > r_max_point[i]) r_max_point[i] = (*it_point)[i];
148  }
149  }
150  }
151 
159  void Extend(const double Margin)
160  {
161  // Extend the min and max points
162  auto& r_min_point = GetMinPoint();
163  auto& r_max_point = GetMaxPoint();
164  for (unsigned int i = 0; i < Dimension; i++){
165  r_min_point[i] -= Margin;
166  r_max_point[i] += Margin;
167  }
168  }
169 
173 
179  TPointType& GetMinPoint()
180  {
181  return mMinMaxPoints[0];
182  }
183 
189  TPointType const& GetMinPoint() const
190  {
191  return mMinMaxPoints[0];
192  }
193 
199  TPointType& GetMaxPoint()
200  {
201  return mMinMaxPoints[1];
202  }
203 
209  TPointType const& GetMaxPoint() const
210  {
211  return mMinMaxPoints[1];
212  }
213 
217 
221 
223  virtual std::string Info() const
224  {
225  std::stringstream buffer;
226  buffer << "BoundingBox" ;
227  return buffer.str();
228  }
229 
231  virtual void PrintInfo(std::ostream& rOStream) const {rOStream << "BoundingBox";}
232 
234  virtual void PrintData(std::ostream& rOStream) const {
235  rOStream << " MinPoint : [" << GetMinPoint()[0] << "," << GetMinPoint()[1] << "," << GetMinPoint()[2] << "]" << std::endl;
236  rOStream << " MaxPoint : [" << GetMaxPoint()[0] << "," << GetMaxPoint()[1] << "," << GetMaxPoint()[2] << "]" << std::endl;
237  }
238 
242 
244 private:
247 
248  static constexpr unsigned int Dimension = 3;
249 
253 
254  std::array<TPointType, 2> mMinMaxPoints;
255 
257 
258 }; // Class BoundingBox
259 
263 
267 
269 template <typename TPointType>
270 inline std::istream& operator >> (std::istream& rIStream,
271  BoundingBox<TPointType>& rThis){
272  return rIStream;
273  }
274 
276 template <typename TPointType>
277 inline std::ostream& operator << (std::ostream& rOStream,
278  const BoundingBox<TPointType>& rThis)
279 {
280  rThis.PrintInfo(rOStream);
281  rOStream << std::endl;
282  rThis.PrintData(rOStream);
283 
284  return rOStream;
285 }
287 
289 
290 } // namespace Kratos.
Representing a bounding box by storing the min and max points.
Definition: bounding_box.h:39
KRATOS_CLASS_POINTER_DEFINITION(BoundingBox)
Pointer definition of BoundingBox.
TPointType const & GetMinPoint() const
Gets a constant reference to the minimum point (read-only).
Definition: bounding_box.h:189
BoundingBox()
Default constructor.
Definition: bounding_box.h:52
void Extend(const double Margin)
Extends the bounding box by adding a margin to its dimensions.
Definition: bounding_box.h:159
virtual ~BoundingBox()
Destructor.
Definition: bounding_box.h:78
BoundingBox & operator=(BoundingBox const &rOther)
Assignment operator.
Definition: bounding_box.h:85
TPointType const & GetMaxPoint() const
Gets a constant reference to the maximum point (read-only).
Definition: bounding_box.h:209
BoundingBox(TIteratorType const &itPointsBegin, TIteratorType const &itPointsEnd)
Construction with container of points.
Definition: bounding_box.h:72
TPointType & GetMinPoint()
Gets a reference to the minimum point.
Definition: bounding_box.h:179
BoundingBox(const BoundingBox &Other)
Copy constructor.
Definition: bounding_box.h:66
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: bounding_box.h:231
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: bounding_box.h:234
virtual std::string Info() const
Turn back information as a string.
Definition: bounding_box.h:223
BoundingBox(TPointType const &MinPoint, TPointType const &MaxPoint)
Constructor with min and max points.
Definition: bounding_box.h:59
void Set(TIteratorType const &itPointsBegin, TIteratorType const &itPointsEnd)
Sets the minimum and maximum points based on a range of input points.
Definition: bounding_box.h:108
void Extend(TIteratorType const &itPointsBegin, TIteratorType const &itPointsEnd)
Extends the bounding box to include a range of input points.
Definition: bounding_box.h:139
TPointType & GetMaxPoint()
Gets a reference to the maximum point.
Definition: bounding_box.h:199
end
Definition: DEM_benchmarks.py:180
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
integer i
Definition: TensorModule.f:17