Memosa-FVM  0.2
Octree.h
Go to the documentation of this file.
1 // This file os part of FVM
2 // Copyright (c) 2012 FVM Authors
3 // See LICENSE file for terms.
4 
5 #ifndef _OCTREE_H_
6 #define _OCTREE_H_
7 // -----------------------------------------------------------------------------
8 // The octree class
9 // -----------------------------------------------------------------------------
10 
11 #include "Array.h"
12 #include "Vector.h"
13 #include "Mesh.h"
14 #include "StorageSite.h"
15 #include "GeomFields.h"
16 #include <iostream>
17 #include <string>
18 #include <math.h>
19 
20 
21 
22 class Octree
23 {
24  public:
25  typedef double T;
26  typedef Array<T> TArray;
29 
30  //this defines a point, which contains cellcentroid coordinate, cellIndex and code
31  struct Point
32  {
34  int cellIndex;
35  int code; // Used during octree generation
36  };
37 // -----------------------------------------------------------------------------
38 // This defines a cubic bounding volume (center, radius)
39 // -----------------------------------------------------------------------------
40 
41  struct Bounds
42  {
43  VectorT3 center; // Center of a cubic bounding volume
44  double radius; // Radius of a cubic bounding volume
45  };
46 
47 
48 
49 
50 
51  // Construction/Destruction
52  Octree();
53 
54  virtual ~Octree();
55 
56  // Accessors
57 
58  //inline const Point * points() const {return _points;}
59  //inline const unsigned int pointCount() const {return _pointCount;}
60 
61  // Implementation
62 
63  //build octree
64 
65  shared_ptr<ArrayBase> getArrayPtr(const VectorT3Array&);
66 
67  virtual bool build(Point *points,
68  const unsigned int count,
69  const unsigned int threshold,
70  const unsigned int maximumDepth,
71  const Bounds &bounds,
72  const unsigned int currentDepth = 0
73  );
74 
75  //calculate bounds
76  const Bounds calcCubicBounds(const Point * points,
77  const unsigned int count);
78 
79  //report octree
80  bool report(FILE *fp);
81 
82  const int getNode(const double x, const double y, const double z);
83 
84  const int getNode(const VectorT3 coordinate);
85 
86  const int getNode(const VectorT3 coordinate, double& shortestDistance);
87 
88  const double borderDistance(const VectorT3 coordinate);
89 
90  void getNodes(const VectorT3 coordinate, const double radius, vector<int>& cellList);
91  void getNodes(const double x, const double y, const double z,
92  const double radius, vector<int>& cellList);
93  const int Naive_getNode(const VectorT3 coordinate, const int count, const Point * points);
94 
95  const vector<int> Naive_getNodes(const VectorT3 coordinate, const int count, const Point * points, const double radius);
96 
97 
98 
99  void Impl(const Mesh& mesh, const GeomFields& geomFields);
100 
101  void Create(const Mesh& mesh, const GeomFields& geomFields, const int faceGroupID);
102 
103  //void Impl(const int nCells, shared_ptr<VectorT3Array> cellCentroid);
104 //virtual const bool traverse(callback proc, void *data) const;
105 
106  protected:
107  Octree *_child[8]; //child node
108  unsigned int _pointCount; //how many points in this node
109  Point *_points; //store the points
110  VectorT3 _center; //node center
111  T _radius; //node radius
112  unsigned int _nodeType; //1=leaf 0=node
113  int _currentDepth; //depth or level of node
114 };
115 #endif
void Impl(const Mesh &mesh, const GeomFields &geomFields)
Definition: Octree.cpp:557
void Create(const Mesh &mesh, const GeomFields &geomFields, const int faceGroupID)
Definition: Octree.cpp:593
int cellIndex
Definition: Octree.h:34
T _radius
Definition: Octree.h:111
double T
Definition: Octree.h:25
Octree * _child[8]
Definition: Octree.h:107
const vector< int > Naive_getNodes(const VectorT3 coordinate, const int count, const Point *points, const double radius)
Definition: Octree.cpp:538
const double borderDistance(const VectorT3 coordinate)
A utility method to figure out the closest distance of a border to a point. If the point is inside th...
Definition: Octree.cpp:342
Definition: Mesh.h:49
int code
Definition: Octree.h:35
virtual ~Octree()
Definition: Octree.cpp:45
Definition: Octree.h:22
double radius
Definition: Octree.h:44
void getNodes(const VectorT3 coordinate, const double radius, vector< int > &cellList)
Get all objects closest to a x/y/z within a radius. search mechanism similar to getNode(coordinate) ...
Definition: Octree.cpp:466
const int Naive_getNode(const VectorT3 coordinate, const int count, const Point *points)
Get all objects closest to a x/y/z within a radius. by simply looping over all the points ...
Definition: Octree.cpp:516
VectorT3 _center
Definition: Octree.h:110
VectorT3 coordinate
Definition: Octree.h:33
unsigned int _pointCount
Definition: Octree.h:108
shared_ptr< ArrayBase > getArrayPtr(const VectorT3Array &)
int _currentDepth
Definition: Octree.h:113
bool report(FILE *fp)
Definition: Octree.cpp:309
Definition: Array.h:14
VectorT3 center
Definition: Octree.h:43
const Bounds calcCubicBounds(const Point *points, const unsigned int count)
Definition: Octree.cpp:255
const int getNode(const double x, const double y, const double z)
Definition: Octree.cpp:441
Array< T > TArray
Definition: Octree.h:26
Array< VectorT3 > VectorT3Array
Definition: Octree.h:28
Vector< T, 3 > VectorT3
Definition: Octree.h:27
virtual bool build(Point *points, const unsigned int count, const unsigned int threshold, const unsigned int maximumDepth, const Bounds &bounds, const unsigned int currentDepth=0)
Definition: Octree.cpp:56
unsigned int _nodeType
Definition: Octree.h:112
Point * _points
Definition: Octree.h:109
Octree()
Definition: Octree.cpp:31