PolyVox  0.2.0
Open source voxel management library
AmbientOcclusionCalculator.h
Go to the documentation of this file.
1 /*******************************************************************************
2 Copyright (c) 2005-2009 David Williams
3 
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
7 
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
11 
12  1. The origin of this software must not be misrepresented; you must not
13  claim that you wrote the original software. If you use this software
14  in a product, an acknowledgment in the product documentation would be
15  appreciated but is not required.
16 
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19 
20  3. This notice may not be removed or altered from any source
21  distribution.
22 *******************************************************************************/
23 
24 #ifndef __AmbientOcclusionCalculator_H__
25 #define __AmbientOcclusionCalculator_H__
26 
27 #include "Impl/RandomUnitVectors.h"
28 #include "Impl/RandomVectors.h"
29 
30 #include "PolyVoxCore/Array.h"
31 #include "PolyVoxCore/Region.h"
32 #include "PolyVoxCore/Raycast.h"
33 
34 //These two should not be here!
35 #include "PolyVoxCore/Material.h"
37 
38 #include <algorithm>
39 
40 namespace PolyVox
41 {
48  template<typename IsVoxelTransparentCallback>
50  {
51  public:
52  AmbientOcclusionCalculatorRaycastCallback(IsVoxelTransparentCallback isVoxelTransparentCallback) : mIsVoxelTransparentCallback(isVoxelTransparentCallback)
53  {
54  }
55 
57  {
58  uint8_t sample = sampler.getVoxel();
59  bool func = mIsVoxelTransparentCallback(sample);
60  return func;
61  }
62 
63  IsVoxelTransparentCallback mIsVoxelTransparentCallback;
64  };
65 
66  // NOTE: The callback needs to be a functor not a function. I haven't been
67  // able to work the required template magic to get functions working as well.
68  //
69  // Matt: If you make the function take a "IsVoxelTransparentCallback&&" then
70  // it will forward it on. Works for functors, functions and lambdas.
71  // This will be 'perfect forwarding' using 'universal references'
72  // This will require C++11 rvalue references which is why I haven't made the
73  // change yet.
74 
76  template<typename VolumeType, typename IsVoxelTransparentCallback>
77  void calculateAmbientOcclusion(VolumeType* volInput, Array<3, uint8_t>* arrayResult, Region region, float fRayLength, uint8_t uNoOfSamplesPerOutputElement, IsVoxelTransparentCallback isVoxelTransparentCallback);
78 }
79 
81 
82 #endif //__AmbientOcclusionCalculator_H__