gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
SBoundingBox3d.h
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 
6 #ifndef SBOUNDING_BOX_3D_H
7 #define SBOUNDING_BOX_3D_H
8 
9 #include <float.h>
10 #include "SPoint3.h"
11 #include "SVector3.h"
12 #include "MVertex.h"
13 
14 #if defined(WIN32)
15 #undef min
16 #undef max
17 #endif
18 
19 // A bounding box class - add points and it grows to be the bounding
20 // box of the point set
22 private:
24 
25 public:
27  : MinPt(DBL_MAX, DBL_MAX, DBL_MAX), MaxPt(-DBL_MAX, -DBL_MAX, -DBL_MAX)
28  {
29  }
30  SBoundingBox3d(const SPoint3 &pt) : MinPt(pt), MaxPt(pt) {}
31  SBoundingBox3d(double xmin, double ymin, double zmin, double xmax,
32  double ymax, double zmax)
33  : MinPt(xmin, ymin, zmin), MaxPt(xmax, ymax, zmax)
34  {
35  }
36  bool empty()
37  {
38  if(MinPt.x() == DBL_MAX || MinPt.y() == DBL_MAX || MinPt.z() == DBL_MAX ||
39  MaxPt.x() == -DBL_MAX || MaxPt.y() == -DBL_MAX || MaxPt.z() == -DBL_MAX)
40  return true;
41  return false;
42  }
43  void reset()
44  {
45  MinPt = SPoint3(DBL_MAX, DBL_MAX, DBL_MAX);
46  MaxPt = SPoint3(-DBL_MAX, -DBL_MAX, -DBL_MAX);
47  }
48  void operator+=(const SPoint3 &pt)
49  {
50  // note: it is possible for pt[i] to be both > MaxPt[i] and < MinPt[i]
51  // the first point always will be both
52  if(pt[0] < MinPt[0]) MinPt[0] = pt[0];
53  if(pt[0] > MaxPt[0]) MaxPt[0] = pt[0];
54 
55  if(pt[1] < MinPt[1]) MinPt[1] = pt[1];
56  if(pt[1] > MaxPt[1]) MaxPt[1] = pt[1];
57 
58  if(pt[2] < MinPt[2]) MinPt[2] = pt[2];
59  if(pt[2] > MaxPt[2]) MaxPt[2] = pt[2];
60  }
62  {
63  (*this) += box.MinPt;
64  (*this) += box.MaxPt;
65  }
66  void operator*=(double scale)
67  {
68  SPoint3 center = (MinPt + MaxPt) * .5;
69  MaxPt -= center;
70  MinPt -= center;
71  MaxPt *= scale;
72  MinPt *= scale;
73  MaxPt += center;
74  MinPt += center;
75  }
76  void scale(double sx, double sy, double sz)
77  {
78  SPoint3 center = (MinPt + MaxPt) * .5;
79  MaxPt -= center;
80  MinPt -= center;
81  MaxPt[0] *= sx;
82  MaxPt[1] *= sy;
83  MaxPt[2] *= sz;
84  MinPt[0] *= sx;
85  MinPt[1] *= sy;
86  MinPt[2] *= sz;
87  MaxPt += center;
88  MinPt += center;
89  }
90  SPoint3 min() const { return MinPt; }
91  SPoint3 max() const { return MaxPt; }
92  SPoint3 center() const { return (MinPt + MaxPt) * .5; }
93  double diag() const { return MinPt.distance(MaxPt); }
94  void makeCube()
95  {
96  SVector3 len = MaxPt - MinPt;
97  SPoint3 cc = center();
98  MaxPt = cc + SPoint3(1, 1, 1);
99  MinPt = cc + SPoint3(-1, -1, -1);
100  double sc = len.norm() * 0.5;
101  scale(sc, sc, sc);
102  }
103  void thicken(double factor)
104  {
105  double d = factor * diag();
106  SPoint3 t(d, d, d);
107  MinPt -= t;
108  MaxPt += t;
109  }
110  bool contains(const SBoundingBox3d &bound)
111  {
112  if(bound.MinPt.x() >= MinPt.x() && bound.MinPt.y() >= MinPt.y() &&
113  bound.MinPt.z() >= MinPt.z() && bound.MaxPt.x() <= MaxPt.x() &&
114  bound.MaxPt.y() <= MaxPt.y() && bound.MaxPt.z() <= MaxPt.z())
115  return true;
116  return false;
117  }
118  bool contains(const SPoint3 &p)
119  {
120  if(p.x() >= MinPt.x() && p.y() >= MinPt.y() && p.z() >= MinPt.z() &&
121  p.x() <= MaxPt.x() && p.y() <= MaxPt.y() && p.z() <= MaxPt.z())
122  return true;
123  return false;
124  }
125  bool contains(double x, double y, double z)
126  {
127  if(x >= MinPt.x() && y >= MinPt.y() && z >= MinPt.z() && x <= MaxPt.x() &&
128  y <= MaxPt.y() && z <= MaxPt.z())
129  return true;
130  return false;
131  }
132  bool transform(const std::vector<double> &tfo)
133  {
134  if(tfo.size() != 16) return false;
135  MinPt.transform(tfo);
136  MaxPt.transform(tfo);
137  return true;
138  }
139 };
140 
141 #endif
SBoundingBox3d::diag
double diag() const
Definition: SBoundingBox3d.h:93
SBoundingBox3d::SBoundingBox3d
SBoundingBox3d(double xmin, double ymin, double zmin, double xmax, double ymax, double zmax)
Definition: SBoundingBox3d.h:31
SBoundingBox3d::thicken
void thicken(double factor)
Definition: SBoundingBox3d.h:103
SBoundingBox3d::operator*=
void operator*=(double scale)
Definition: SBoundingBox3d.h:66
box
Definition: gl2gif.cpp:311
SPoint3
Definition: SPoint3.h:14
SBoundingBox3d::min
SPoint3 min() const
Definition: SBoundingBox3d.h:90
SVector3
Definition: SVector3.h:16
SBoundingBox3d::operator+=
void operator+=(const SBoundingBox3d &box)
Definition: SBoundingBox3d.h:61
SVector3.h
SBoundingBox3d::contains
bool contains(const SPoint3 &p)
Definition: SBoundingBox3d.h:118
SBoundingBox3d::contains
bool contains(const SBoundingBox3d &bound)
Definition: SBoundingBox3d.h:110
SBoundingBox3d::SBoundingBox3d
SBoundingBox3d()
Definition: SBoundingBox3d.h:26
SBoundingBox3d::center
SPoint3 center() const
Definition: SBoundingBox3d.h:92
SPoint3::x
double x(void) const
Definition: SPoint3.h:125
SBoundingBox3d::empty
bool empty()
Definition: SBoundingBox3d.h:36
MVertex.h
SVector3::norm
double norm() const
Definition: SVector3.h:33
SPoint3::y
double y(void) const
Definition: SPoint3.h:127
SBoundingBox3d::operator+=
void operator+=(const SPoint3 &pt)
Definition: SBoundingBox3d.h:48
SBoundingBox3d::makeCube
void makeCube()
Definition: SBoundingBox3d.h:94
SPoint3::distance
double distance(const SPoint3 &p) const
Definition: SPoint3.h:176
SBoundingBox3d::transform
bool transform(const std::vector< double > &tfo)
Definition: SBoundingBox3d.h:132
SBoundingBox3d::reset
void reset()
Definition: SBoundingBox3d.h:43
SBoundingBox3d::contains
bool contains(double x, double y, double z)
Definition: SBoundingBox3d.h:125
z
const double z
Definition: GaussQuadratureQuad.cpp:56
SBoundingBox3d::scale
void scale(double sx, double sy, double sz)
Definition: SBoundingBox3d.h:76
SBoundingBox3d::MinPt
SPoint3 MinPt
Definition: SBoundingBox3d.h:23
SPoint3::z
double z(void) const
Definition: SPoint3.h:129
SBoundingBox3d::MaxPt
SPoint3 MaxPt
Definition: SBoundingBox3d.h:23
SBoundingBox3d::SBoundingBox3d
SBoundingBox3d(const SPoint3 &pt)
Definition: SBoundingBox3d.h:30
SBoundingBox3d::max
SPoint3 max() const
Definition: SBoundingBox3d.h:91
SPoint3.h
SBoundingBox3d
Definition: SBoundingBox3d.h:21
SPoint3::transform
bool transform(const std::vector< double > &tfo)
Definition: SPoint3.h:78