VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
BoundingBox.cpp
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
33//=======================================================================================
34#include "BoundingBox.h"
35
36#include "../Triangle/Triangle.h"
37#include "../Vertex/Vertex.h"
39
40#include <limits>
41
42namespace vf::gpu {
43
44
45BoundingBox::BoundingBox(real minX, real maxX, real minY, real maxY, real minZ, real maxZ) : minX(minX), maxX(maxX), minY(minY), maxY(maxY), minZ(minZ), maxZ(maxZ) {}
46
48{
49 BoundingBox box = BoundingBox(std::numeric_limits<real>::max(),
50 std::numeric_limits<real>::lowest(),
51 std::numeric_limits<real>::max(),
52 std::numeric_limits<real>::lowest(),
53 std::numeric_limits<real>::max(),
54 std::numeric_limits<real>::lowest());
55 return box;
56 }
57
59 {
61 t.setMinMax(minX, maxX, minY, maxY, minZ, maxZ);
63 this->minX = minX;
65 this->minY = minY;
67 this->minZ = minZ;
68
69 if (maxX > this->maxX)
70 this->maxX = maxX;
71 if (maxY > this->maxY)
72 this->maxY = maxY;
73 if (maxZ > this->maxZ)
74 this->maxZ = maxZ;
75 }
76
78 {
79 if (isInside(t.v1) || isInside(t.v2) || isInside(t.v3))
80 return true;
81 return false;
82 }
83
84 bool BoundingBox::isInside(const Triangle &t) const
85 {
86 if (isInside(t.v1) && isInside(t.v2) && isInside(t.v3))
87 return true;
88 return false;
89 }
90
91 bool BoundingBox::isInside(const real x, const real y, const real z) const
92 {
93 return this->isInside(Vertex(x,y,z));
94 }
95
96 bool BoundingBox::isInside(const Vertex &v) const
97 {
99 return true;
100 return false;
101 }
102
103 std::vector<std::vector<Vertex> > BoundingBox::getIntersectionPoints(const BoundingBox &b) const
104 {
105 std::vector<std::vector<Vertex> > intersectionBox;
106 intersectionBox.resize(6);
107
108 int intersects = 0;
109 if (b.minX < maxX && b.maxX > maxX) { //maxX is intersect
110 intersectionBox[intersects].push_back(Vertex((real)maxX, (real)minY, (real)minZ));
111 intersectionBox[intersects].push_back(Vertex((real)maxX, (real)maxY, (real)minZ));
112 intersectionBox[intersects].push_back(Vertex((real)maxX, (real)minY, (real)maxZ));
113 intersects++;
114 }
115 if (b.minX < minX && b.maxX > minX) { //minX is intersect
116 intersectionBox[intersects].push_back(Vertex((real)minX, (real)minY, (real)minZ));
117 intersectionBox[intersects].push_back(Vertex((real)minX, (real)maxY, (real)minZ));
118 intersectionBox[intersects].push_back(Vertex((real)minX, (real)minY, (real)maxZ));
119 intersects++;
120 }
121 if (b.minY < minY && b.maxY > minY) { //minY is intersect
122 intersectionBox[intersects].push_back(Vertex((real)minX, (real)minY, (real)minZ));
123 intersectionBox[intersects].push_back(Vertex((real)maxX, (real)minY, (real)minZ));
124 intersectionBox[intersects].push_back(Vertex((real)minX, (real)minY, (real)maxZ));
125 intersects++;
126 }
127 if (b.minY < maxY && b.maxY > maxY) { //maxY is intersect
128 intersectionBox[intersects].push_back(Vertex((real)minX, (real)maxY, (real)minZ));
129 intersectionBox[intersects].push_back(Vertex((real)maxX, (real)maxY, (real)minZ));
130 intersectionBox[intersects].push_back(Vertex((real)minX, (real)maxY, (real)maxZ));
131 intersects++;
132 }
133 if (b.minZ < minZ && b.maxZ > minZ) { //minZ is intersect
134 intersectionBox[intersects].push_back(Vertex((real)minX, (real)minY, (real)minZ));
135 intersectionBox[intersects].push_back(Vertex((real)maxX, (real)minY, (real)minZ));
136 intersectionBox[intersects].push_back(Vertex((real)minX, (real)maxY, (real)minZ));
137 intersects++;
138 }
139 if (b.minZ < maxZ && b.maxZ > maxZ) { //maxZ is intersect
140 intersectionBox[intersects].push_back(Vertex((real)minX, (real)minY, (real)maxZ));
141 intersectionBox[intersects].push_back(Vertex((real)maxX, (real)minY, (real)maxZ));
142 intersectionBox[intersects].push_back(Vertex((real)minX, (real)maxY, (real)maxZ));
143 intersects++;
144 }
145
146 return intersectionBox;
147 }
148
150 {
151 struct Vertex v[8];
152 box.getPoints(v);
153
154 for (int i = 0; i < 8; i++) {
155 if (isInside(v[i]))
156 return true;
157 }
158 return false;
159 }
160
161 void BoundingBox::getPoints(Vertex v[8]) const
162 {
163 v[0] = Vertex(minX, minY, minZ);
164 v[1] = Vertex(maxX, minY, minZ);
165 v[2] = Vertex(minX, maxY, minZ);
166 v[3] = Vertex(maxX, maxY, minZ);
167
168 v[4] = Vertex(minX, minY, maxZ);
169 v[5] = Vertex(maxX, minY, maxZ);
170 v[6] = Vertex(minX, maxY, maxZ);
171 v[7] = Vertex(maxX, maxY, maxZ);
172 }
173
174
176 {
177 printf("min/max - x: %2.4f/ %2.4f, y: %2.4f, %2.4f, z: %2.4f, %2.4f \n", minX, maxX, minY, maxY, minZ, maxZ);
178 }
179
180
182 {
183 return vf::Math::equal(minX, box.minX)
184 && vf::Math::equal(maxX, box.maxX)
185 && vf::Math::equal(minY, box.minY)
186 && vf::Math::equal(maxY, box.maxY)
187 && vf::Math::equal(minZ, box.minZ)
188 && vf::Math::equal(maxZ, box.maxZ);
189 }
190
192 {
193 this->minX -= delta;
194 this->minY -= delta;
195 this->minZ -= delta;
196
197 this->maxX += delta;
198 this->maxY += delta;
199 this->maxZ += delta;
200 }
201
202}
203
bool isInside(const Triangle &t) const
bool intersect(const Triangle &t) const
void setMinMax(const Triangle &t)
std::vector< std::vector< Vertex > > getIntersectionPoints(const BoundingBox &b) const
void extend(real delta)
static BoundingBox makeInvalidMinMaxBox()
bool operator==(const BoundingBox &box) const
std::shared_ptr< T > SPtr
float real
Definition DataTypes.h:42
@ z
Definition Axis.h:44
@ x
Definition Axis.h:42
@ y
Definition Axis.h:43
static bool equal(const real &val1, const real &val2, real maxRelDiff=EPSILON)
Definition Math.cpp:40
bool isXbetween(real min, real max) const
Definition Vertex.cpp:149
bool isZbetween(real min, real max) const
Definition Vertex.cpp:159
bool isYbetween(real min, real max) const
Definition Vertex.cpp:154