From 94d3e79a8617f88dc0219cfdeedfa3147833719d Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Mon, 24 Jun 2019 14:43:36 +0200 Subject: Initialize at openlb-1-3 --- src/io/octree.h | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 src/io/octree.h (limited to 'src/io/octree.h') diff --git a/src/io/octree.h b/src/io/octree.h new file mode 100644 index 0000000..f3d47b1 --- /dev/null +++ b/src/io/octree.h @@ -0,0 +1,157 @@ +/* This file is part of the OpenLB library + * + * Copyright (C) 2015 Thomas Henn + * E-mail contact: info@openlb.net + * The most recent release of OpenLB can be downloaded at + * + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the Free + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +/** \file + * Octree + */ + +#ifndef OCTREE_H +#define OCTREE_H + +#include +#include + +#include "core/singleton.h" +#include "core/vector.h" + + +using namespace olb::util; +/// All OpenLB code is contained in this namespace. +namespace olb { + +template +class STLmesh; + +template +struct STLtriangle; + +template +class Octree { +public: + /* + * Constructs Octree containing triangles of an STLmesh. + * \param center Centerpoint + * \param rad Radius + * \param mesh STLmesh + * \param maxDepth Maximal depth of tree + * \param overlap Triangles within rad+overlap are added to this Octree + */ + Octree(Vector center, T rad, STLmesh* mesh, short maxDepth, T overlap = 0., Octree* parent=nullptr); + /// Destructor destructs + ~Octree(); + /// Find the node containing the first param with remaining maxDepth + Octree* find(const Vector&,const int& maxDepth = 0); + /// Write Octree + void write(const Vector& pt, const std::string no); + /// Write Octree + void write(const int, const std::string); + /// Write Octree + void write(const std::string); + /// Test intersection of ray with all triangles in Octree + /// returns number of intersections + int testIntersection(const Vector& pt,const Vector& dir, bool print = false); + /// Test intersection of ray with all triangles in Octree + /// q contains point of closest intersection to pt in direction direction + bool closestIntersection(const Vector& pt, const Vector& direction, Vector& q, T& a); + /// Test intersection of ray with all triangles in Octree + /// q contains point of closest intersection to pt in direction direction + /// tri contains triangle with closest intersection + bool closestIntersection(const Vector& pt, const Vector& direction, Vector& q, T& a, STLtriangle& tri, const T& rad = 0., bool print = false); + /// Test intersection of sphere moving along ray with radius rad + /// q contains point of closest intersection to pt in direction direction + /// tri contains triangle with closest intersection + bool closestIntersectionSphere(const Vector& pt, const T& rad, const Vector& direction, Vector& q, T& a, STLtriangle& tri); + /// It's complicated. Computes intersections of a ray with triangles inside this Octree. Sets _inside depending on value of rayInside and changes rayInside depending on the number of intersections. Also takes into account if the intersections happen before or after the center. + void checkRay(const Vector& pt,const Vector& dir, unsigned short& rayInside); + /// Computes intersection of ray with Octree boundaries + void intersectRayNode(const Vector& pt, const Vector& dir, Vector& s); + /// Computes all centerpoints of Octree + void getCenterpoints(std::vector >& pts); + /// Collectes all leafs + void getLeafs(std::vector* >& pts); + /// Return status of _isLeaf; + bool isLeaf(); + /// Sets Inside + inline void setInside(bool ins) + { + _inside = ins; + }; + /// Gets Inside + inline bool getInside() + { + return _inside; + }; + /// Gets _boundarNode + inline bool getBoundaryNode() + { + return _boundaryNode; + }; + /// Gets Maxdepth + inline int getMaxdepth() const + { + return _maxDepth; + }; + /// Gets numbers of triangles contained by this Octree + inline const std::vector& getTriangles() const + { + return _triangles; + }; + /// Gets centerpoint + inline const Vector& getCenter() const + { + return _center; + }; + /// Gets radius + inline const T getRadius() const + { + return _radius; + }; + /// Prints console output + void print(); + /// Returns set of indices of all triangles in nodes containing a line. + void trianglesOnLine(const Vector& pt1, const Vector& pt2, std::set& tris); + /// Returns reference to _mesh + inline STLmesh* getMesh() + { + return _mesh; + } + +protected: + ///_vector _triangles contains number of triangles + std::vector _triangles; + Vector _center; + T _radius; + STLmesh* _mesh; + short _maxDepth; + bool _isLeaf; + bool _boundaryNode; + bool _inside; + Octree *_parent; + Octree **_child; + void findTriangles(T overlap = 0.); + bool AABBTri(const STLtriangle& tri, T overlap = 0.); +}; + + +} +#endif -- cgit v1.2.3