OpenLB 1.7
Loading...
Searching...
No Matches
octree.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2015 Thomas Henn
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 */
23
28#ifndef OCTREE_H
29#define OCTREE_H
30
31#include <iostream>
32#include <set>
33
34#include "core/singleton.h"
35#include "core/vector.h"
36
37
38// All OpenLB code is contained in this namespace.
39namespace olb {
40
41template<typename T>
42class STLmesh;
43
44template<typename T>
45struct STLtriangle;
46
47template <typename T>
48class Octree {
49public:
50 /*
51 * Constructs Octree containing triangles of an STLmesh.
52 * \param center Centerpoint
53 * \param rad Radius
54 * \param mesh STLmesh
55 * \param maxDepth Maximal depth of tree
56 * \param overlap Triangles within rad+overlap are added to this Octree
57 */
58 Octree(Vector<T,3> center, T rad, STLmesh<T>* mesh, short maxDepth, T overlap = 0., Octree<T>* parent=nullptr);
60 ~Octree();
62 Octree<T>* find(const Vector<T,3>&,const int& maxDepth = 0);
64 void write(const Vector<T,3>& pt, const std::string no);
66 void write(const int, const std::string);
68 void write(const std::string);
71 int testIntersection(const Vector<T,3>& pt,const Vector<T,3>& dir, bool print = false);
74 bool closestIntersection(const Vector<T,3>& pt, const Vector<T,3>& direction, Vector<T,3>& q, T& a);
78 bool closestIntersection(const Vector<T,3>& pt, const Vector<T,3>& direction, Vector<T,3>& q, T& a, STLtriangle<T>& tri, const T& rad = 0., bool print = false);
82 bool closestIntersectionSphere(const Vector<T,3>& pt, const T& rad, const Vector<T,3>& direction, Vector<T,3>& q, T& a, STLtriangle<T>& tri);
84 void checkRay(const Vector<T,3>& pt,const Vector<T,3>& dir, unsigned short& rayInside);
86 void intersectRayNode(const Vector<T,3>& pt, const Vector<T,3>& dir, Vector<T,3>& s);
88 void getCenterpoints(std::vector<std::vector<T> >& pts);
90 void getLeafs(std::vector<Octree<T>* >& pts);
92 bool isLeaf();
94 inline void setInside(bool ins)
95 {
96 _inside = ins;
97 };
99 inline bool getInside()
100 {
101 return _inside;
102 };
104 inline bool getBoundaryNode()
105 {
106 return _boundaryNode;
107 };
109 inline int getMaxdepth() const
110 {
111 return _maxDepth;
112 };
114 inline const std::vector<unsigned int>& getTriangles() const
115 {
116 return _triangles;
117 };
119 inline const Vector<T,3>& getCenter() const
120 {
121 return _center;
122 };
124 inline const T getRadius() const
125 {
126 return _radius;
127 };
129 void print();
131 void trianglesOnLine(const Vector<T,3>& pt1, const Vector<T,3>& pt2, std::set<unsigned int>& tris);
134 {
135 return _mesh;
136 }
137
138protected:
140 std::vector<unsigned int> _triangles;
150 void findTriangles(T overlap = 0.);
151 bool AABBTri(const STLtriangle<T>& tri, T overlap = 0.);
152};
153
154
155}
156#endif
STLmesh< T > * _mesh
Definition octree.h:143
bool _isLeaf
Definition octree.h:145
void print()
Prints console output.
Definition octree.hh:740
bool closestIntersection(const Vector< T, 3 > &pt, const Vector< T, 3 > &direction, Vector< T, 3 > &q, T &a)
Test intersection of ray with all triangles in Octree q contains point of closest intersection to pt ...
Definition octree.hh:669
bool AABBTri(const STLtriangle< T > &tri, T overlap=0.)
Definition octree.hh:143
Octree(Vector< T, 3 > center, T rad, STLmesh< T > *mesh, short maxDepth, T overlap=0., Octree< T > *parent=nullptr)
Definition octree.hh:48
void findTriangles(T overlap=0.)
Definition octree.hh:122
bool getInside()
Gets Inside.
Definition octree.h:99
Octree< T > * _parent
Definition octree.h:148
bool closestIntersectionSphere(const Vector< T, 3 > &pt, const T &rad, const Vector< T, 3 > &direction, Vector< T, 3 > &q, T &a, STLtriangle< T > &tri)
Test intersection of sphere moving along ray with radius rad q contains point of closest intersection...
Definition octree.hh:619
STLmesh< T > * getMesh()
Returns reference to _mesh.
Definition octree.h:133
bool _inside
Definition octree.h:147
void intersectRayNode(const Vector< T, 3 > &pt, const Vector< T, 3 > &dir, Vector< T, 3 > &s)
Computes intersection of ray with Octree boundaries.
Definition octree.hh:676
void setInside(bool ins)
Sets Inside.
Definition octree.h:94
int testIntersection(const Vector< T, 3 > &pt, const Vector< T, 3 > &dir, bool print=false)
Test intersection of ray with all triangles in Octree returns number of intersections.
Definition octree.hh:324
void getLeafs(std::vector< Octree< T > * > &pts)
Collectes all leafs.
Definition octree.hh:425
std::vector< unsigned int > _triangles
_vector _triangles contains number of triangles
Definition octree.h:140
int getMaxdepth() const
Gets Maxdepth.
Definition octree.h:109
Octree< T > * find(const Vector< T, 3 > &, const int &maxDepth=0)
Find the node containing the first param with remaining maxDepth.
Definition octree.hh:263
bool isLeaf()
Return status of _isLeaf;.
Definition octree.hh:438
short _maxDepth
Definition octree.h:144
void getCenterpoints(std::vector< std::vector< T > > &pts)
Computes all centerpoints of Octree.
Definition octree.hh:412
void checkRay(const Vector< T, 3 > &pt, const Vector< T, 3 > &dir, unsigned short &rayInside)
It's complicated. Computes intersections of a ray with triangles inside this Octree....
Definition octree.hh:377
const Vector< T, 3 > & getCenter() const
Gets centerpoint.
Definition octree.h:119
Octree< T > ** _child
Definition octree.h:149
void write(const Vector< T, 3 > &pt, const std::string no)
Write Octree.
Definition octree.hh:444
bool getBoundaryNode()
Gets _boundarNode.
Definition octree.h:104
~Octree()
Destructor destructs.
Definition octree.hh:111
Vector< T, 3 > _center
Definition octree.h:141
bool _boundaryNode
Definition octree.h:146
void trianglesOnLine(const Vector< T, 3 > &pt1, const Vector< T, 3 > &pt2, std::set< unsigned int > &tris)
Returns set of indices of all triangles in nodes containing a line.
Definition octree.hh:747
const T getRadius() const
Gets radius.
Definition octree.h:124
const std::vector< unsigned int > & getTriangles() const
Gets numbers of triangles contained by this Octree.
Definition octree.h:114
Plain old scalar vector.
Definition vector.h:47
Top level namespace for all of OpenLB.
Definition of singletons: global, publicly available information.
efficient implementation of a vector class