VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
GbPolygon3D.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 <GbPolygon3D.h>
35
36using namespace std;
37
39
41{
42 init();
43 counter++;
44 this->ps = new gb_system_3d::PointSet3(0);
45}
46void GbPolygon3D::init()
47{
48 x1s = 0.0;
49 x2s = 0.0;
50 x3s = 0.0;
51 x1min = 0.0;
52 x1max = 0.0;
53 x2min = 0.0;
54 x2max = 0.0;
55 x3min = 0.0;
56 x3max = 0.0;
57 // points = NULL;
58 consistent = false;
59 ps = NULL;
60}
61
67{
68 init();
69 counter++;
70 this->ps = new gb_system_3d::PointSet3(capacity);
71 // this.po = new PointObserver(this);
72}
78{
79 init();
80 counter++;
81 this->ps = new gb_system_3d::PointSet3((int)points.size());
82 this->addPoints(points);
83}
89{
90 this->init();
91 counter++;
92 this->ps = new gb_system_3d::PointSet3((int)polygon->size());
93 vector<GbPoint3D> temp = polygon->getPoints();
94 this->addPoints(temp);
95}
96
98{
99 counter--;
100 // if(points)
101 // for(unsigned u=0; u<points->size(); u++)
102 //{
103 // delete (*points)[u];
104 //}
105 // delete this->points;
106 delete this->ps;
107}
108
109/*======================================================================*/
114int GbPolygon3D::size() { return (this->ps->size()); }
120int GbPolygon3D::contains(GbPoint3D *point) { return (this->ps->contains(point)); }
143{
144 return (this->ps->containsLine(line->getPoint1(), line->getPoint2()));
145}
163{
164 if (index < 0 || index > this->ps->size())
165 throw UbException(UB_EXARGS, "ArrayIndexOutOfBoundsException-GbPolygon3D.getPoint()");
166 return (this->ps->getPoint(index));
167}
173{
174 if (!this->consistent)
175 this->calculateValues();
176 return (this->points);
177}
185{
186 return (this->getPoints(p1->x1, p1->x2, p1->x3, p2->x1, p2->x2, p2->x3));
187}
198vector<GbPoint3D> GbPolygon3D::getPoints(const double &p1x1, const double &p1x2, const double &p1x3, const double &p2x1,
199 const double &p2x2, const double &p2x3)
200{
201 double x1min, x1max, x2min, x2max, x3min, x3max;
202
203 if (ub_math::less(p1x1, p2x1)) {
204 x1min = p1x1;
205 x1max = p2x1;
206 } else {
207 x1min = p2x1;
208 x1max = p1x1;
209 }
210 if (ub_math::less(p1x2, p2x2)) {
211 x2min = p1x2;
212 x2max = p2x2;
213 } else {
214 x2min = p2x2;
215 x2max = p1x2;
216 }
217 if (ub_math::less(p1x3, p2x3)) {
218 x3min = p1x3;
219 x3max = p2x3;
220 } else {
221 x3min = p2x3;
222 x3max = p1x3;
223 }
224
226
227 if (!this->consistent)
228 this->calculateValues();
229 for (int i = this->size() - 1; i >= 0; i--) {
230 if (ub_math::lessEqual(x1min, (this->points)[i].x1) && ub_math::greaterEqual(x1max, (this->points)[i].x1) &&
231 ub_math::lessEqual(x2min, (this->points)[i].x2) && ub_math::greaterEqual(x2max, (this->points)[i].x2) &&
232 ub_math::lessEqual(x3min, (this->points)[i].x3) && ub_math::greaterEqual(x3max, (this->points)[i].x3))
233 pts->add((this->points)[i]);
234 }
235 return (pts->getPoints());
236}
242// double getArea()
243//{
244// if(!this.consistent) this.calculateValues();
245// return(this.area);
246//}
248{
249 if (!this->consistent)
250 this->calculateValues();
251 return (this->x1s);
252}
254{
255 if (!this->consistent)
256 this->calculateValues();
257 return (this->x1min);
258}
260{
261 if (!this->consistent)
262 this->calculateValues();
263 return (this->x1max);
264}
266{
267 if (!this->consistent)
268 this->calculateValues();
269 return (this->x2s);
270}
272{
273 if (!this->consistent)
274 this->calculateValues();
275 return (this->x2min);
276}
278{
279 if (!this->consistent)
280 this->calculateValues();
281 return (this->x2max);
282}
284{
285 if (!this->consistent)
286 this->calculateValues();
287 return (this->x3s);
288}
290{
291 if (!this->consistent)
292 this->calculateValues();
293 return (this->x3min);
294}
296{
297 if (!this->consistent)
298 this->calculateValues();
299 return (this->x3max);
300}
301
307{
308 // if((this instanceof GbPolygon3D) && !(point instanceof GbPoint3D)) throw new
309 // IllegalArgumentException("GbPolygon3D.addPoint(): points of 3D polygons have to be 3D points!");
310
311 this->ps->add(point);
312 // point.addObserver(this.po);
313 this->consistent = false;
314 // super.notifyObservers();
315}
321{
322 // if((this instanceof GbPolygon3D) && (points.getClass().getComponentType() != GbPoint3D.class)) throw new
323 // IllegalArgumentException("GbPolygon3D.addPoints(): points of 3D polygons have to be 3D points!");
324
325 this->ps->add(points);
326 // for(int i=0; i<points.length; i++) points[i].addObserver(this.po);
327 this->consistent = false;
328 // super.notifyObservers();
329}
334{
335 // delete this->points;
336 this->ps->clearAndTrim();
337 delete this->ps;
338
339 // for(int i=points.length-1; i>=0; i--) points[i].removeObserver(this.po);
340 this->consistent = false;
341 // super.notifyObservers();
342}
348{
350 ss << "GbPolygon3D[";
351 ss << this->size() << " points";
352 ss << "]" << endl;
353 for (int u = 0; u < this->size(); u++)
354 ss << this->ps->getPoint(u)->toString() << endl;
355
356 return (ss.str());
357}
358/*======================================================================*/
359
361{
362 this->x1s = 0.0;
363 this->x2s = 0.0;
364 this->x3s = 0.0;
365 this->x1min = 0.0;
366 this->x1max = 0.0;
367 this->x2min = 0.0;
368 this->x2max = 0.0;
369 this->x3min = 0.0;
370 this->x3max = 0.0;
371 throw UbException(UB_EXARGS, "should be implemented");
372}
373/*======================================================================*/
374
This Class provides basic 3D line objects.
Definition GbLine3D.h:59
GbPoint3D * getPoint1()
Definition GbLine3D.h:95
GbPoint3D * getPoint2()
Definition GbLine3D.h:96
This Class provides basic 3D point objects.
Definition GbPoint3D.h:49
double x1
Definition GbPoint3D.h:121
double x3
Definition GbPoint3D.h:123
double x2
Definition GbPoint3D.h:122
This Class provides basic 3D polygon objects.
Definition GbPolygon3D.h:53
std::shared_ptr< T > SPtr
int contains(GbPoint3D *point)
GbPoint3D * getFirstPoint()
int contains(GbPoint3D *point)
double getX2Minimum() override
void addPoint(GbPoint3D *point)
void addPoints(std::vector< GbPoint3D > &points)
std::vector< GbPoint3D > getPoints()
double getX1Maximum() override
GbPoint3D * getPoint(const int &index)
double getX3Maximum() override
static int counter
Definition GbPolygon3D.h:86
double getX2Centroid() override
GbPoint3D * getLastPoint()
void calculateValues()
double getX3Centroid() override
int containsEqual(GbPoint3D *point)
double getX3Minimum() override
void add(const GbPoint3D &point)
GbPoint3D * getPoint(int index)
int containsEqual(const GbPoint3D &point)
double getX2Maximum() override
double getX1Centroid() override
bool containsLine(GbPoint3D *point1, GbPoint3D *point2)
bool containsLine(GbPoint3D *point1, GbPoint3D *point2)
std::string toString() override
~GbPolygon3D() override
std::string toString() override
double getX1Minimum() override
GbPoint3D * getFirstPoint()
#define UB_EXARGS
Definition UbException.h:73
bool greaterEqual(const T1 &value, const T2 &reference)
Definition UbMath.h:223
bool lessEqual(const T1 &value, const T2 &reference)
Definition UbMath.h:209
bool less(const T1 &value, const T2 &reference)
Definition UbMath.h:202