Code_TYMPAN  4.4.0
Industrial site acoustic simulation
BvhAccelerator.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14  */
15 
16 #ifndef BVHACCELERATOR_H
17 #define BVHACCELERATOR_H
18 
19 #include "Geometry/BBox.h"
20 #include <vector>
21 #include "Geometry/Shape.h"
22 #include "Accelerator.h"
23 
24 struct BVHBuildNode;
25 
26 // BVHAccel Forward Declarations
27 struct BVHPrimitiveInfo;
28 struct LinearBVHNode;
29 
34 {
35 
36 public:
38  BvhAccelerator(std::vector<Shape*>* _initialMesh = NULL, BBox _globalBox = BBox(),
39  unsigned int maxProf = 8, const string& sm = "sah");
41  virtual ~BvhAccelerator()
42  {
43  free(nodes);
44  }
45 
46  virtual bool build();
47 
48  virtual decimal traverse(Ray* r, std::list<Intersection>& result) const;
49 
51  void setMaxProfondeur(int _maxProfondeur)
52  {
53  maxProfondeur = _maxProfondeur;
54  }
57  {
58  return maxProfondeur;
59  }
61  void setMaxPrimPerLeaf(int _maxPrimPerLeaf)
62  {
63  maxPrimPerLeaf = _maxPrimPerLeaf;
64  }
67  {
68  return maxPrimPerLeaf;
69  }
71  std::vector<BBox>& getBBox()
72  {
73  return tableBox;
74  }
75 
77  void print();
78  /* Uncommented cause not used:
79  bool alreadyFail;
80  unsigned int nbFail;
81  Ray r;
82  bool trace;
83  */
84 protected:
85  // BVHAccel Private Methods
86  BVHBuildNode* recursiveBuild(std::vector<BVHPrimitiveInfo>& buildData, unsigned int start,
87  unsigned int end, unsigned int* totalNodes,
88  std::vector<Shape*>& orderedPrims);
89  unsigned int flattenBVHTree(BVHBuildNode* node, unsigned int* offset);
90 
91  // BVHAccel Private Data
92  unsigned int maxPrimsInNode;
94  {
97  SPLIT_SAH
98  };
101 
102  std::vector<Shape*>
105 
106  std::vector<BBox> tableBox;
107 
110 
112  /* Uncommented cause not used:
113  float isectCost;
114  float emptyBonus;
115  float traversalCost; */
116 };
117 
118 #endif
Base class for accelerators.
Definition: Accelerator.h:27
Definition of a bounding box which is aligned along the axis (BBox AABB).
Definition: BBox.h:32
A Bounding Volume Hierarchy (BVH) Accelerator.
virtual decimal traverse(Ray *r, std::list< Intersection > &result) const
Run this accelerator.
BVHBuildNode * recursiveBuild(std::vector< BVHPrimitiveInfo > &buildData, unsigned int start, unsigned int end, unsigned int *totalNodes, std::vector< Shape * > &orderedPrims)
std::vector< Shape * > primitives
Pointer to all the shapes (different from initialMesh) as it is reordered.
virtual bool build()
Build this accelerator.
SplitMethod splitMethod
Split method.
virtual ~BvhAccelerator()
Destructor.
BBox globalBox
Global bounding box.
void setMaxPrimPerLeaf(int _maxPrimPerLeaf)
Set maximal primitives per leaf.
std::vector< BBox > tableBox
Bounding boxes vector.
void print()
Print not implemented:
unsigned int maxPrimsInNode
Maximal primitives in node.
int getMaxProfondeur()
Get maximal depth.
unsigned int flattenBVHTree(BVHBuildNode *node, unsigned int *offset)
int getMaxPrimPerLeaf()
Get maximal primitives per leaf.
std::vector< BBox > & getBBox()
Get the vector of bounding boxes.
BvhAccelerator(std::vector< Shape * > *_initialMesh=NULL, BBox _globalBox=BBox(), unsigned int maxProf=8, const string &sm="sah")
Default constructor.
LinearBVHNode * nodes
Nodes list.
int maxPrimPerLeaf
Maximal primitives per leaf.
int realMaxProfondeur
Real maximal depth.
int maxProfondeur
Maximal depth.
void setMaxProfondeur(int _maxProfondeur)
Set maximal depth.
: Describes a ray by a pair of unsigned int. The first one gives the source number (in the range 0-40...
Definition: Ray.h:38
float decimal
Definition: mathlib.h:45