HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SIM_Noise.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  */
7 
8 #ifndef __SIM_Noise_h__
9 #define __SIM_Noise_h__
10 
11 #include "SIM_API.h"
12 #include "SIM_DataUtils.h"
13 #include "SIM_OptionsUser.h"
14 #include "SIM_PhysicalParms.h"
15 
16 class SIM_NoiseResolver;
17 class SIM_NoiseResolverGeneric;
18 
19 /// This class defines the interface for noise generation functions.
20 class SIM_API SIM_Noise : public SIM_Data,
21  public SIM_OptionsUser
22 {
23 public:
27 
28  /// Gets the 1D value of the noise field at the specified position.
29  /// The returned value is between the minvalue and the maxvalue.
30  fpreal getNoise(const UT_Vector3 &pos) const;
31  /// Gets the 3D value of the noise field at the specified position.
32  /// The returned value is between the minvalue and the maxvalue.
33  void getNoise(const UT_Vector3 &pos,
34  UT_Vector3 &noise) const;
35 
36  /// Returns an accelerated property resolver to get the noise
37  /// at any given place in a hopefully threadsafe manner.
38  SIM_PropertyResolver *getNoiseResolver() const;
39 
40 protected:
41  explicit SIM_Noise(const SIM_DataFactory *factory);
42  virtual ~SIM_Noise();
43 
44  /// Get the extents of the values generated by the noise function.
45  /// These values are required to properly scale the returned values.
46  void getNoiseLimits(fpreal &min, fpreal &max) const;
47 
48  /// Override this function to return the actual bounds of the noise.
49  virtual void getNoiseLimitsSubclass(fpreal &min,
50  fpreal &max) const = 0;
51  /// Override this function to implement a new noise function.
52  /// The returned value must be in the range [0..1].
53  /// The default implementation returns the X component of the 3D noise.
54  virtual fpreal getNoiseSubclass(const UT_Vector3 &pos) const;
55  /// Override this function to implement a new noise function.
56  /// The returned values must all be in the range [0..1].
57  /// The default implementation returns the 1D noise value for all
58  /// three components.
59  virtual void getNoiseSubclass(const UT_Vector3 &pos,
60  UT_Vector3 &noise) const;
61  /// Create a SIM_PropertyResolver to quickly compute the noise,
62  /// defaults to a generic one that just calls back to SIM_Noise.
63  virtual SIM_PropertyResolver *getNoiseResolverSubclass() const;
64 
65 private:
68 
69  friend class SIM_NoiseResolverGeneric;
70  friend class SIM_NoiseResolver;
71 };
72 
74 {
75 public:
76  SIM_NoiseResolver(const SIM_Noise *noise);
77 
78  /// Handles the resizing to the given range using the min/max,
79  /// and proper support of scalar fields being set.
80  virtual fpreal getF(const UT_Vector3 &pos);
81  virtual UT_Vector3 getV3(const UT_Vector3 &pos);
82 
83  /// These are the methods to override with the noise-specific
84  /// behaviour. They should behave like SIM_Noise::getNoiseSubclass
85  virtual fpreal getNoiseF(const UT_Vector3 &pos) = 0;
86  virtual UT_Vector3 getNoiseV3(const UT_Vector3 &pos) = 0;
87 
88 protected:
89  bool myIsScalar;
90  UT_Vector3 myMaxValue, myMinValue;
91  fpreal myNoiseLimitsMin, myNoiseLimitsMax;
92 };
93 
94 #endif
#define DECLARE_STANDARD_GETCASTTOTYPE()
Definition: SIM_DataUtils.h:45
#define DECLARE_CLASSNAME(DataClass, SuperClass)
Definition: SIM_DataUtils.h:20
#define GETSET_DATA_FUNCS_B(DataName, FuncName)
#define SIM_NAME_SCALARNOISE
Definition: SIM_Names.h:181
virtual UT_Vector3 getV3(const UT_Vector3 &pos)=0
#define SIM_NAME_MINVALUE
Definition: SIM_Names.h:148
#define SIM_NAME_MAXVALUE
Definition: SIM_Names.h:145
#define GETSET_DATA_FUNCS_V3(DataName, FuncName)
This class defines the interface for noise generation functions.
Definition: SIM_Noise.h:20
const std::enable_if<!VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:133
double fpreal
Definition: SYS_Types.h:270
UT_Vector3 myMinValue
Definition: SIM_Noise.h:90
virtual fpreal getF(const UT_Vector3 &pos)=0
#define SIM_API
Definition: SIM_API.h:10
fpreal myNoiseLimitsMin
Definition: SIM_Noise.h:91
const std::enable_if<!VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:129