HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GAS_Calculate.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_Calculate.h ( GAS Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GAS_Calculate__
12 #define __GAS_Calculate__
13 
14 #include "GAS_API.h"
15 
17 #include <GU/GU_Detail.h>
18 
19 #include <SIM/SIM_RawField.h>
20 #include <SIM/SIM_PhysicalParms.h>
21 
22 #include "GAS_SubSolver.h"
23 #include "GAS_Utils.h"
24 
26 {
27 public:
28  GET_DATA_FUNC_S(GAS_NAME_FIELDDEST, FieldDstName);
30  GET_DATA_FUNC_S("dstblend", DstBlend);
31  GET_DATA_FUNC_S("srcblend", SrcBlend);
32 
33  GET_DATA_FUNC_S("srcindex", SrcIndexName);
34  GET_DATA_FUNC_I("property", Property);
35 
36  GET_DATA_FUNC_I("srctimescale", SrcTimeScale);
37  GET_DATA_FUNC_I("dsttimescale", DstTimeScale);
38  GET_DATA_FUNC_I("posttimescale", PostTimeScale);
39 
40  GET_DATA_FUNC_I("calculationtype", CalculationType);
41  GET_DATA_FUNC_I("blendmethod", BlendMethod);
42  GET_DATA_FUNC_F("dstpreadd", DstPreAdd);
43  GET_DATA_FUNC_F("dstpremul", DstPreMul);
44  GET_DATA_FUNC_I("dstconvert", DstConvert);
45  GET_DATA_FUNC_I("dstscale", DstScale);
46  GET_DATA_FUNC_F("srcpreadd", SrcPreAdd);
47  GET_DATA_FUNC_F("srcpremul", SrcPreMul);
48  GET_DATA_FUNC_I("srcconvert", SrcConvert);
49  GET_DATA_FUNC_I("srcscale", SrcScale);
50  GET_DATA_FUNC_F("postadd", PostAdd);
51  GET_DATA_FUNC_F("postmul", PostMul);
52  GET_DATA_FUNC_I("postconvert", PostConvert);
53  GET_DATA_FUNC_I("postscale", PostScale);
54 
55  GET_DATA_FUNC_F("dstblendpreadd", DstBlendPreAdd);
56  GET_DATA_FUNC_F("dstblendpremul", DstBlendPreMul);
57  GET_DATA_FUNC_I("dstblendconvert", DstBlendConvert);
58  GET_DATA_FUNC_I("dstblendscale", DstBlendScale);
59  GET_DATA_FUNC_F("srcblendpreadd", SrcBlendPreAdd);
60  GET_DATA_FUNC_F("srcblendpremul", SrcBlendPreMul);
61  GET_DATA_FUNC_I("srcblendconvert", SrcBlendConvert);
62  GET_DATA_FUNC_I("srcblendscale", SrcBlendScale);
63 
66 
67  // Blend methods
69  {
75  NUM_BLEND
76  };
77 
78  // Extra mix methods to handle SDF specific functions
84  NUM_CONVERT
85  };
86 
87  /// Helper methods to apply conversion and blend methods.
88  SYS_STATIC_FORCE_INLINE float convertValues(CONVERT_NAMES type, LENGTHSCALE_NAMES lengthscale, float premul, float preadd, float d, float width)
89  {
90  // Ensure we have a consistent idea of how to perform these.
91  d *= premul;
92  d += preadd;
93 
94  // Use our extra mix types...
95  switch (type)
96  {
97  case CONVERT_NONE:
98  // Nice and simple
99  break;
100 
101  case CONVERT_SDFTOFOG:
102  // Something exactly 0 should be 0.5, total width of kernel
103  // is width
104  d = SIM_RawField::toHeaviside(d, width);
105  break;
106 
107  case CONVERT_SDFTOSURFACE:
108  // Computes our surface layer. Reducing this with SUM
109  // should give us our total surface area modulo the
110  // voxelsize.
111  // The choice of function is so that a flat plane aligned
112  // with the voxel grid will have the same surface area
113  // regardless of its sub-voxel location.
114  d = SYSabs(d);
115  if (d > width/2)
116  d = 0;
117  else
118  d = 1.0 - (d / (width/2));
119  break;
120 
121  case CONVERT_ABS:
122  d = SYSabs(d);
123  break;
124 
125  default:
126  UT_ASSERT(!"Unhandled mix type!");
127  d = 0.0;
128  break;
129  }
130 
131  // Apply the length scale.
132  d = applyLengthScale(d, width, lengthscale);
133 
134  return d;
135  }
136 
137  static bool blendValues(BLEND_NAMES blendmethod, float &d, float dblend, float &sfactor, float sblend);
138 
139 protected:
140  explicit GAS_Calculate(const SIM_DataFactory *factory);
141  ~GAS_Calculate() override;
142 
143  /// Calculates the desired procedure with dest & src, result
144  /// going into dest.
145  bool solveGasSubclass(SIM_Engine &engine,
146  SIM_Object *obj,
147  SIM_Time time,
148  SIM_Time timestep) override;
149 
150  THREADED_METHOD4(GAS_Calculate, dst->shouldMultiThread(),
151  mixEachVoxel,
152  SIM_RawField *, dst,
153  const SIM_RawField *, src,
154  const GU_SDF *, sdf,
155  const UT_DMatrix4 &, tosdf)
156  void mixEachVoxelPartial(SIM_RawField *dst,
158  const GU_SDF *sdf,
159  const UT_DMatrix4 &tosdf,
160  const UT_JobInfo &info);
161 
162  THREADED_METHOD6(GAS_Calculate, dst->shouldMultiThread(),
163  mixEachVoxelIndex,
164  SIM_Engine &, engine,
165  SIM_RawField *, dst,
166  const UT_DMatrix4 &, towolrd,
167  const SIM_IndexField *, src,
168  int, srcaxis,
169  fpreal, velscale)
170  void mixEachVoxelIndexPartial(SIM_Engine &engine,
172  const UT_DMatrix4 &toworld,
173  const SIM_IndexField *src,
174  int srcaxis,
175  fpreal velscale,
176  const UT_JobInfo &info);
177 
178 
179  THREADED_METHOD6(GAS_Calculate, dst->shouldMultiThread(),
180  blendEachVoxel,
181  SIM_RawField *, dst,
182  const SIM_RawField *, src,
183  const GU_SDF *, sdf,
184  const UT_DMatrix4 &, tosdf,
185  const SIM_RawField *, dstblend,
186  const SIM_RawField *, srcblend)
187  void blendEachVoxelPartial(SIM_RawField *dst,
189  const GU_SDF *sdf,
190  const UT_DMatrix4 &tosdf,
191  const SIM_RawField *dstblend,
192  const SIM_RawField *srcblend,
193  const UT_JobInfo &info);
194 
195  THREADED_METHOD8(GAS_Calculate, dst->shouldMultiThread(),
196  blendEachVoxelIndex,
197  SIM_Engine &, engine,
198  SIM_RawField *, dst,
199  const UT_DMatrix4 &, toworld,
200  const SIM_IndexField *, src,
201  int, srcaxis,
202  const SIM_RawField *, dstblend,
203  const SIM_RawField *, srcblend,
204  fpreal, velscale)
205  void blendEachVoxelIndexPartial(SIM_Engine &engine,
207  const UT_DMatrix4 &toworld,
208  const SIM_IndexField *src,
209  int srcaxis,
210  const SIM_RawField *dstblend,
211  const SIM_RawField *srcblend,
212  fpreal velscale,
213  const UT_JobInfo &info);
214 
215  /// Returns true if the current getProperty() is safe to do in
216  /// a multithreaded manner. Ideally would have to invoke
217  /// SIM_PropertyResolver for all potential indices, but currently
218  /// relies on apriori knowledge that only the fancy velocity
219  /// operations are not threadsafe.
220  bool isPropertyThreadsafe() const;
221 
222 private:
223  static const SIM_DopDescription *getDopDescription();
224 
228  "Gas Calculate",
229  getDopDescription());
230 
231  // Cache our timestep for so we can calculate the timescale
232  // effects.
233  float myTimeStep;
234 };
235 
236 #endif
#define DECLARE_STANDARD_GETCASTTOTYPE()
Definition: SIM_DataUtils.h:50
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
#define THREADED_METHOD8(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1, PARMTYPE2, PARMNAME2, PARMTYPE3, PARMNAME3, PARMTYPE4, PARMNAME4, PARMTYPE5, PARMNAME5, PARMTYPE6, PARMNAME6, PARMTYPE7, PARMNAME7, PARMTYPE8, PARMNAME8)
GT_API const UT_StringHolder time
#define GAS_NAME_USETIMESTEP
Definition: GAS_Utils.h:39
#define GAS_API
Definition: GAS_API.h:10
virtual bool solveGasSubclass(SIM_Engine &engine, SIM_Object *obj, SIM_Time time, SIM_Time timestep)=0
#define SYSabs(a)
Definition: SYS_Math.h:1572
This class holds a three dimensional scalar field.
SYS_STATIC_FORCE_INLINE float convertValues(CONVERT_NAMES type, LENGTHSCALE_NAMES lengthscale, float premul, float preadd, float d, float width)
Helper methods to apply conversion and blend methods.
Definition: GAS_Calculate.h:88
Definition: GU_SDF.h:302
static fpreal toHeaviside(fpreal val, fpreal diam)
Perform heaviside & inverse heaviside in a consistent fashion.
#define DECLARE_DATAFACTORY(DataClass, SuperClass, Description, DopParms)
Definition: SIM_DataUtils.h:63
#define GET_DATA_FUNC_I(DataName, FuncName)
#define GAS_NAME_FIELDSOURCE
Definition: GAS_Utils.h:29
#define GAS_NAME_FIELDDEST
Definition: GAS_Utils.h:28
#define SYS_STATIC_FORCE_INLINE
Definition: SYS_Inline.h:48
#define THREADED_METHOD4(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1, PARMTYPE2, PARMNAME2, PARMTYPE3, PARMNAME3, PARMTYPE4, PARMNAME4)
GLenum GLenum dst
Definition: glcorearb.h:1793
fpreal64 fpreal
Definition: SYS_Types.h:277
#define GET_DATA_FUNC_B(DataName, FuncName)
#define GET_DATA_FUNC_F(DataName, FuncName)
#define THREADED_METHOD6(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1, PARMTYPE2, PARMNAME2, PARMTYPE3, PARMNAME3, PARMTYPE4, PARMNAME4, PARMTYPE5, PARMNAME5, PARMTYPE6, PARMNAME6)
#define GAS_NAME_TIMESCALE
Definition: GAS_Utils.h:40
GLint GLsizei width
Definition: glcorearb.h:103
static float applyLengthScale(float val, float width, int scaletype)
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
type
Definition: core.h:1059
#define GET_DATA_FUNC_S(DataName, FuncName)
GLenum src
Definition: glcorearb.h:1793