HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GAS_StencilUtils.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GAS_StencilUtil.h (GAS Library, C++)
7  *
8  * COMMENTS:
9  * This file contains convenience macros for performing stencilled operations
10  * in a generic way.
11  *
12  * These macros are meant to be used roughly as follows:
13  * UT_VoxelArrayIteratorF iter(dst->fieldNC());
14  * DECLARE_STENCIL_VARIABLES(dst)
15  * for(iter.rewind(); !iter.atEnd(); iter.advance())
16  * {
17  * if(iter.isStartOfTile())
18  * {
19  * CHECK_STENCIL_TILE(iter)
20  * }
21  * CHECK_STENCIL_VOXEL(iter)
22  * ...
23  * iter.setValue(...);
24  * }
25  *
26  * `SIM_RawField* dst` is the destination field that we're iterating over, and
27  * `const SIM_RawField* stencil` is the required signature of the stencil
28  * field. The following variables will also be defined
29  * (by DECLARE_STENCIL_VARIABLES):
30  * - `float cstencilval` -- last known constant value of the stencil (only
31  * applies when conststencil is true);
32  * - `bool conststencil` -- true if stencil values are known to be constant
33  * in the current tile (in this case, the constant value is cstencilval);
34  * - `SIM_ScalarFieldSampler stencilsampler` -- sampler object to probe
35  * stencil values.
36  */
37 
38 #include <SIM/SIM_FieldSampler.h>
39 
40 /// Declares the variables needed to check stencil values. These variables are
41 /// updated and used by the subsequent macros.
42 #define DECLARE_STENCIL_VARIABLES(dst) \
43  float cstencilval = 1; \
44  bool conststencil = true; \
45  SIM_ScalarFieldSampler stencilsampler; \
46  if (stencil) \
47  stencilsampler.init(dst, stencil);
48 
49 /// This macro checks the stencil value in the current destination tile. If the
50 /// stencil tile is constant and below the active threshold, the whole tile will
51 /// be skipped.
52 #define CHECK_STENCIL_TILE(iterator) \
53  if (stencil) \
54  { \
55  conststencil = stencilsampler.isTileConstant(iterator, cstencilval); \
56  if (conststencil && cstencilval <= 0.5f) \
57  { \
58  iterator.skipToEndOfTile(); \
59  continue; \
60  } \
61  }
62 
63 /// This macro checks the stencil value in the current destination tile. Whether
64 /// the tile can be skipped is stored in skip_value, but iterator is left
65 /// untouched.
66 #define CHECK_STENCIL_TILE_NOSKIP(iterator, skip_value) \
67  skip_value = false; \
68  if (stencil) \
69  { \
70  conststencil = stencilsampler.isTileConstant(iterator, cstencilval); \
71  skip_value = (conststencil && cstencilval <= 0.5f); \
72  }
73 
74 /// This macro will check the stencil value for the current voxel and skip if
75 /// it's not active.
76 #define CHECK_STENCIL_VOXEL(iterator) \
77  if (!conststencil && stencilsampler.getValue(iterator) <= 0.5f) \
78  continue;
79 
80 /// This macro will check the stencil value for the current voxel. Whether the
81 /// voxel can be skipped is stored in skip_value, but iterator is left
82 /// untouched.
83 #define CHECK_STENCIL_VOXEL_NOSKIP(iterator, skip_value) \
84  skip_value = (!conststencil && stencilsampler.getValue(iterator) <= 0.5f);
85