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.
oriented_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: Vicente Mataix Ferrandiz
11 //
12 
13 #if !defined(OBB_CLASS_H_DEFINED )
14 #define OBB_CLASS_H_DEFINED
15 
16 // System includes
17 #include <iomanip>
18 
19 // External includes
20 
21 // Project includes
22 #include "geometries/point.h"
23 #include "includes/node.h"
24 #include "geometries/geometry.h"
27 
28 namespace Kratos
29 {
32 
36 
40 
48 
52 
56 
75 template<std::size_t TDim>
76 class KRATOS_API(KRATOS_CORE) OrientedBoundingBox
77 {
78 public:
79 
82 
83  // Node definition
84  typedef Node NodeType;
85 
88 
90  typedef std::size_t IndexType;
91 
93  typedef std::size_t SizeType;
94 
96  static constexpr double ZeroTolerance = std::numeric_limits<double>::epsilon();
97 
99  typedef typename std::conditional<TDim == 2, Quadrilateral2D4<Point>, Hexahedra3D8<Point> >::type OutputType;
100 
103 
107 
115  const array_1d<double, 3>& rCenterCoords,
116  const array_1d<array_1d<double, 3>, TDim>& rOrientationVectors,
117  const array_1d<double, TDim>& rHalfLength
118  );
119 
126  const array_1d<double, 3>& rCenterCoords,
127  const array_1d<array_1d<double, 3>, TDim>& rAxisCoordinates
128  );
129 
136  const GeometryType& rGeometry,
137  const double BoundingBoxFactor,
138  const bool BuildFromBoundingBox = true
139  );
140 
143  mPointCenter(rhs.mPointCenter),
144  mOrientationVectors(rhs.mOrientationVectors),
145  mHalfLength(rhs.mHalfLength)
146  {
147  }
148 
151  {
152  }
153 
157 
161 
166  const array_1d<double, 3>& GetCenter() const;
167 
172  void SetCenter(const array_1d<double, 3>& rCenterCoords);
173 
178  const array_1d<array_1d<double, 3>, TDim>& GetOrientationVectors() const;
179 
184  void SetOrientationVectors(const array_1d<array_1d<double, 3>, TDim>& rOrientationVectors);
185 
190  const array_1d<double, TDim>& GetHalfLength() const;
191 
196  void SetHalfLength(const array_1d<double, TDim>& rHalfLength);
197 
201  bool IsInside(const OrientedBoundingBox& rOtherOrientedBoundingBox) const;
202 
208  bool HasIntersection(
209  const OrientedBoundingBox& rOtherOrientedBoundingBox,
211  ) const;
212 
218 
224 
228 
232 
236 
238  virtual std::string Info() const
239  {
240  std::stringstream string_out_coordinates;
241  for (std::size_t i = 0; i < TDim; ++i) {
242  string_out_coordinates
243  << std::setiosflags(std::ios::scientific)
244  << std::setprecision(3)
245  << std::uppercase
246  << "\t" << mPointCenter[i];
247  }
248 
249  std::stringstream string_out_orientation_vectors;
250  for (std::size_t i = 0; i < TDim; ++i) {
251  string_out_orientation_vectors << "\nThe orientation axis " << i << " is: ";
252  for (std::size_t j = 0; j < TDim; ++j) {
253  string_out_orientation_vectors
254  << std::setiosflags(std::ios::scientific)
255  << std::setprecision(3)
256  << std::uppercase
257  << "\t" << mOrientationVectors[i][j];
258  }
259  }
260 
261  std::stringstream string_out_half_length;
262  for (std::size_t i = 0; i < TDim; ++i) {
263  string_out_half_length
264  << std::setiosflags(std::ios::scientific)
265  << std::setprecision(3)
266  << std::uppercase
267  << "\t" << mHalfLength[i];
268  }
269 
270  return "OrientedBoundingBox in " + std::to_string(TDim) + "D space" + "\nWhich center is:" + string_out_coordinates.str() + "\nThe orientation axis are: " + string_out_orientation_vectors.str() + "\nThe half lengths are: " + string_out_half_length.str();
271  }
272 
274  virtual void PrintInfo(std::ostream& rOStream) const
275  {
276  rOStream << Info() << std::endl;
277  }
278 
280  virtual void PrintData(std::ostream& rOStream) const
281  {
282  rOStream << Info() << std::endl;
283  }
284 
288 
290 protected:
291 
294 
298 
302 
306 
310 
314 
319 
320 private:
326 
327  array_1d<double, 3> mPointCenter;
328  array_1d<array_1d<double, 3>, TDim> mOrientationVectors;
329  array_1d<double, TDim> mHalfLength;
330 
334 
338 
344  bool DirectHasIntersection(const OrientedBoundingBox& rOtherOrientedBoundingBox) const;
345 
351  bool SeparatingAxisTheoremHasIntersection(const OrientedBoundingBox& rOtherOrientedBoundingBox) const;
352 
359  bool GetSeparatingPlane(
360  const array_1d<double, 3>& rRelativePosition,
361  const array_1d<double, 3>& rPlane,
362  const OrientedBoundingBox& rOtherOrientedBoundingBox
363  ) const;
364 
371  bool GetSeparatingPlane2D(
372  const array_1d<double, 3>& rRelativePosition,
373  const array_1d<double, 3>& rPlane,
374  const OrientedBoundingBox& rOtherOrientedBoundingBox
375  ) const;
376 
383  bool GetSeparatingPlane3D(
384  const array_1d<double, 3>& rRelativePosition,
385  const array_1d<double, 3>& rPlane,
386  const OrientedBoundingBox& rOtherOrientedBoundingBox
387  ) const;
388 
393  void RotateNode2D(array_1d<double, 3>& rCoords) const;
394 
400  void RotateNode3D(
401  array_1d<double, 3>& rCoords,
402  const BoundedMatrix<double, 4, 4>& rInvertedRotationMatrix
403  ) const;
404 
410  bool CheckIsInside2D(array_1d<double, 3>& rCoords) const;
411 
418  bool CheckIsInside3D(
419  array_1d<double, 3>& rCoords,
420  BoundedMatrix<double, 4, 4> rInvertedRotationMatrix
421  ) const;
422 
427 
431 
435 
439 }; // Class OrientedBoundingBox
440 
442 
445 
446 
450 
452 
453 } // namespace Kratos.
454 
455 #endif // OBB_CLASS_H_DEFINED defined
std::string Info() const override
Turn back information as a string.
Definition: periodic_interface_process.hpp:93
Geometry base class.
Definition: geometry.h:71
An eight node hexahedra geometry with linear shape functions.
Definition: hexahedra_3d_8.h:55
Definition: amatrix_interface.h:41
This class defines the node.
Definition: node.h:65
This class defines the Oriented bounding box class.
Definition: oriented_bounding_box.h:77
~OrientedBoundingBox()
Destructor.
Definition: oriented_bounding_box.h:150
KRATOS_CLASS_POINTER_DEFINITION(OrientedBoundingBox)
Counted pointer of OrientedBoundingBox.
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: oriented_bounding_box.h:274
void GetEquivalentRotatedGeometry(OutputType &rGeometry)
This method egnerates an equiavelent geometry (debugging)
Geometry< NodeType > GeometryType
Definition of geometries.
Definition: oriented_bounding_box.h:87
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: oriented_bounding_box.h:280
OutputType GetEquivalentGeometry() const
This method egnerates an equiavelent geometry (debugging)
Node NodeType
Definition: oriented_bounding_box.h:84
bool IsInside(const OrientedBoundingBox &rOtherOrientedBoundingBox) const
Computes the intersection between two OrientedBoundingBox (current and new)
virtual std::string Info() const
Turn back information as a string.
Definition: oriented_bounding_box.h:238
OrientedBoundingBox(const GeometryType &rGeometry, const double BoundingBoxFactor, const bool BuildFromBoundingBox=true)
Default constructors (with geometry)
std::size_t SizeType
Size type definition.
Definition: oriented_bounding_box.h:93
std::conditional< TDim==2, Quadrilateral2D4< Point >, Hexahedra3D8< Point > >::type OutputType
Definition of the output type.
Definition: oriented_bounding_box.h:99
OrientedBoundingBox(const OrientedBoundingBox &rhs)
Copy constructor (not really required)
Definition: oriented_bounding_box.h:142
std::size_t IndexType
Index type definition.
Definition: oriented_bounding_box.h:90
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
OBBHasIntersectionType
This enum defines the different types of checks that can be done for the HasIntersection:
Definition: oriented_bounding_box.h:47
rhs
Definition: generate_frictional_mortar_condition.py:297
type
Definition: generate_gid_list_file.py:35
int j
Definition: quadrature.py:648
integer i
Definition: TensorModule.f:17