HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TS_Expression.h
Go to the documentation of this file.
1 /* TS_Meta.h * * Copyright 1993-1995 Algorithmic Arts, Inc.
2  * All Rights Reserved.
3  *
4  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Algorithmic Arts, Inc.;
5  * the contents of this file may not be disclosed to third parties, copied or
6  * duplicated in any form, in whole or in part, without the prior written
7  * permission of Algorithmic Arts, Inc.
8  *
9  * AUTHOR:
10  * Dave Gordon
11  *
12  * Public interface to the TS_Meta2 Library
13  *
14  * $XRevision: 1.4 $
15  * $XDate: 1996/04/27 03:51:52 $
16  *
17  */
18 
19 #ifndef _TS_Expression_h_
20 #define _TS_Expression_h_
21 
22 #include "TS_API.h"
23 #include <UT/UT_Matrix4.h>
24 #include <UT/UT_Matrix3.h>
25 #include <UT/UT_Vector4.h>
26 #include <UT/UT_Vector3.h>
27 #include <UT/UT_BoundingBox.h>
28 #include <UT/UT_Interval.h>
29 #include <UT/UT_IntrusivePtr.h>
30 
31 #include <UT/UT_ValArray.h>
32 #include "TS_Quadric.h"
33 #include "TS_Ray.h"
34 
35 class UT_MemoryCounter;
36 class TS_MetaExpression;
37 class TS_SweepNode;
38 class TS_Octree;
39 class TS_MetaPrimitive;
40 class TS_MetaSum;
41 class TS_MetaMin;
42 class TS_MetaMax;
43 class ts_PrimNode;
44 
48 
50 {
51  TS_OP_INVALID = -1, // Invalid operation
52  TS_OP_SUM = 0, // Sum operation
53  TS_OP_MAX = 1, // Max operation
54  TS_OP_MIN = 2, // Min operation
55 
56  TS_SERIALIZE_MAGIC = 99, // Magic number for serialization arrays
57 };
58 
59 /////////////////////////////////////////////////////////////////////
60 
62 {
63 public:
64  const char *myToken;
65  const char *myLabel;
66 
67  float (*p)(float /* squared distance */);
68  UT_Interval (*pr)(const UT_Interval &);
69  float (*dp)(float);
70  UT_Interval (*dpr)(const UT_Interval &);
71 };
72 
73 /////////////////////////////////////////////////////////////////////
74 
75 
77  : public UT_IntrusiveRefCounter<TS_MetaExpression>
78 {
79 public:
81  virtual ~TS_MetaExpression();
82 
83  virtual const TS_MetaPrimitive *isPrimitive() const;
84  virtual TS_MetaPrimitive *isPrimitive();
85  virtual TS_MetaSum *isSum();
86  virtual TS_MetaMin *isMin();
87  virtual TS_MetaMax *isMax();
88 
89  virtual float density(const UT_Vector3 &p) const = 0;
90  virtual UT_Interval density(const UT_BoundingBox &p) const = 0;
91 
92  // This density function both computes a density at the given point and
93  // also populates a list of primitives affecting that point.
94  virtual float listDensity(const UT_Vector3 &p,
96 
97  virtual float grad(const UT_Vector3 &point,
98  UT_Vector3 &grad) const = 0;
99 
100  virtual void raySweepInit(const TS_Ray &ray, float clip,
101  float &t0, float &t1) = 0;
102  virtual void raySweepComplete();
103 
104  virtual float rayDensity(float t) const = 0;
105  virtual UT_Interval rayDensity(const UT_Interval &t) const = 0;
106 
107  virtual int rayIntersect(const TS_Ray &ray,
108  const UT_Interval &start,
109  float &result,
110  float tol = -1.0f);
111  virtual int rayIntersect(const TS_Ray &ray,
112  const UT_Interval &start,
113  UT_FloatArray &result,
114  float tol = -1.0f);
115 
116  const UT_BoundingBox &getBBox() const { return myBBox; }
117  virtual UT_Interval getBBox(UT_BoundingBox &) const = 0;
118 
119  virtual TS_MetaExpression *prune(const UT_BoundingBox &,
120  UT_Interval &range) = 0;
121 
122  virtual TS_MetaExpression *duplicate() const = 0;
123 
124  virtual int setRay(const TS_Ray &ray) = 0;
125 
126  virtual TS_SweepNode *allocSweepNode(const TS_Ray &ray);
127  virtual const TS_ExpressionList *getAllKids() const;
128 
129  const TS_ExpressionList *getCellPrimitives(const UT_Vector3 &pos);
130 
132  {
133  if (!myOctree)
134  buildOctree();
135  return myOctree;
136  }
137 
138  void setOctreeIndex(int idx) { myOctreeRayIndex = idx; }
139  int getOctreeIndex() const { return myOctreeRayIndex; }
140 
142 
143  // Returns the renderman expression opcode associated with this
144  // expression - return -1 unless this is actually a MetaOp
145  virtual int getRibOpcode() const { return -1; }
146  /// Return the serialization operation
147  virtual TS_SerialOp getOpCode() const { return TS_OP_INVALID; }
148 
149  // Returns this expression's thread number
150  int getThreadNum() const { return myThreadNum; }
151 
152  // Sets this expression's thread number
153  virtual void setThreadNum(int thread_num)
154  { myThreadNum = thread_num; }
155 
156  // A static function, used to set up the TS expression
157  // architecture to allow ray intersection with the specified
158  // number of threads
159  static void setupThreads(int num_threads);
160 
161  /// Compute memory usage (includes all shared memory)
162  virtual int64 getMemoryUsage(bool inclusive) const;
163 
164  /// Count memory usage using a UT_MemoryCounter in order to count
165  /// shared memory correctly.
166  /// If inclusive is true, the size of this object is counted,
167  /// else only memory owned by this object is counted.
168  /// If this is pointed to by the calling object, inclusive should be true.
169  /// If this is contained in the calling object, inclusive should be false.
170  /// (Its memory was already counted in the size of the calling object.)
171  virtual void countMemory(UT_MemoryCounter &counter, bool inclusive) const;
172 
173 public:
174  // Stores the thread number to be used for this
175  // expression. This is used to determine, for
176  // instance, which SweepNode object pool should
177  // be used when doing ray intersection
179 
180 protected:
181  void clearOctree();
182  virtual void buildOctree();
183 
186  int myRayIndex, myOctreeRayIndex;
187 
188 private:
189 
190 };
191 
193  : public TS_MetaExpression
194 {
195 public:
196  TS_MetaOp(int n);
197  ~TS_MetaOp() override;
198 
199  virtual void append(const TS_MetaExpressionPtr &arg);
200 
201  const TS_ExpressionList *getAllKids() const override;
202  int setRay(const TS_Ray &ray) override;
203  void raySweepInit(const TS_Ray &ray,
204  float clip, float &t0, float &t1) override;
205  void raySweepComplete() override;
206 
207  void getAllPrimitives(
208  UT_Array<TS_MetaPrimitive *> &prims) override;
209 
210  // Override the setThreadNum function here, so that
211  // meta ops can also set it on all children
212  void setThreadNum(int thread_num) override;
213 
214  // A reset function, to return this expression back to
215  // a basically empty state as if it were just
216  // constructed
217  void reset();
218 
219  /// Compute memory usage (includes all shared memory)
220  int64 getMemoryUsage(bool inclusive) const override;
221 
222  /// Count memory usage using a UT_MemoryCounter in order to count
223  /// shared memory correctly.
224  /// If inclusive is true, the size of this object is counted,
225  /// else only memory owned by this object is counted.
226  /// If this is pointed to by the calling object, inclusive should be true.
227  /// If this is contained in the calling object, inclusive should be false.
228  /// (Its memory was already counted in the size of the calling object.)
229  void countMemory(UT_MemoryCounter &counter,
230  bool inclusive) const override;
231 
232 public:
233  void initSweepList(const TS_Ray &ray);
237 
238 protected:
239  // Functions used to clean up active metaball information
240  void freeList(ts_PrimNode *list_start);
241  void clearAndDestroy();
242 
243 private:
244 };
245 
247  : public TS_MetaOp
248 {
249 public:
250  TS_MetaSum(int n = 0);
251  ~TS_MetaSum() override;
252 
253  TS_MetaSum *isSum() override final;
254  float density(const UT_Vector3 &p) const override final;
255  UT_Interval density(const UT_BoundingBox &p) const override final;
256  float listDensity(const UT_Vector3 &p,
258  override final;
259  float grad(const UT_Vector3 &point, UT_Vector3 &grad) const
260  override final;
261  float rayDensity(float t) const
262  override final;
263  UT_Interval rayDensity(const UT_Interval &t) const override final;
264  UT_Interval getBBox(UT_BoundingBox &) const override final;
266  override final;
267  TS_MetaExpression *duplicate() const override final;
268 
269  // Returns the renderman opcode for this expression
270  int getRibOpcode() const override final
271  { return 0; }
272  TS_SerialOp getOpCode() const override final
273  { return TS_OP_SUM; }
274 };
275 
277  : public TS_MetaOp
278 {
279 public:
280  TS_MetaMax(int n = 0);
281  ~TS_MetaMax() override;
282 
283  TS_MetaMax *isMax() override final;
284  float density(const UT_Vector3 &p) const override final;
285  UT_Interval density(const UT_BoundingBox &p) const override final;
286  float listDensity(const UT_Vector3 &p,
287  UT_ValArray<TS_MetaPrimitive *> &) override final;
288  float grad(const UT_Vector3 &point,
289  UT_Vector3 &grad) const override final;
290  float rayDensity(float t) const override final;
291  UT_Interval rayDensity(const UT_Interval &t) const override final;
292  UT_Interval getBBox(UT_BoundingBox &) const override final;
294  UT_Interval &range) override final;
295  TS_MetaExpression *duplicate() const override final;
296 
297  // Returns the renderman opcode for this expression
298  int getRibOpcode() const override final { return 2; }
299  TS_SerialOp getOpCode() const override final { return TS_OP_MAX; }
300 };
301 
303  : public TS_MetaOp
304 {
305 public:
306  TS_MetaMin(int n = 0);
307  ~TS_MetaMin() override;
308 
309  void append(const TS_MetaExpressionPtr &arg) override final;
310  TS_MetaMin *isMin() override final;
311  float density(const UT_Vector3 &p) const override final;
312  UT_Interval density(const UT_BoundingBox &p) const override final;
313  float listDensity(const UT_Vector3 &p,
315  override final;
316  float grad(const UT_Vector3 &point,
317  UT_Vector3 &grad) const override final;
318  float rayDensity(float t) const override final;
319  UT_Interval rayDensity(const UT_Interval &t) const override final;
320  UT_Interval getBBox(UT_BoundingBox &) const override final;
321 
323  UT_Interval &range) override final;
324  TS_MetaExpression *duplicate() const override final;
325 
326  // Returns the renderman opcode for this expression
327  int getRibOpcode() const override final { return 3; }
328  TS_SerialOp getOpCode() const override final { return TS_OP_MIN; }
329 };
330 
331 //----------------------------------------------------------------------//
332 
333 
334 #define TS_MetaPotentialThreshold 1.0F
335 
336 #endif // _TS_Expression_h_
virtual int getRibOpcode() const
int getRibOpcode() const overridefinal
const char * myLabel
Definition: TS_Expression.h:65
UT_IntrusivePtr< TS_MetaExpression > TS_MetaExpressionPtr
Definition: TS_Expression.h:43
virtual int64 getMemoryUsage(bool inclusive) const
Compute memory usage (includes all shared memory)
TS_ExpressionList myArray
GLenum GLint * range
Definition: glcorearb.h:1925
TS_Octree * myOctree
virtual int setRay(const TS_Ray &ray)=0
GLuint start
Definition: glcorearb.h:475
int getRibOpcode() const overridefinal
virtual void getAllPrimitives(UT_Array< TS_MetaPrimitive * > &prims)
void setOctreeIndex(int idx)
TS_SweepNode * myActive
const UT_BoundingBox & getBBox() const
int getOctreeIndex() const
virtual float density(const UT_Vector3 &p) const =0
TS_SerialOp getOpCode() const overridefinal
Return the serialization operation.
**But if you need a result
Definition: thread.h:613
TS_SerialOp getOpCode() const overridefinal
Return the serialization operation.
virtual void raySweepInit(const TS_Ray &ray, float clip, float &t0, float &t1)=0
A reference counter base class for use with UT_IntrusivePtr.
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
Definition: core.h:1736
virtual void append(const TS_MetaExpressionPtr &arg)
virtual void raySweepComplete()
UT_BoundingBox myBBox
Definition: TS_Ray.h:21
GLdouble n
Definition: glcorearb.h:2008
GLfloat f
Definition: glcorearb.h:1926
const char * myToken
Definition: TS_Expression.h:64
IMATH_NAMESPACE::V2f float
GLboolean reset
Definition: glad.h:5138
virtual float listDensity(const UT_Vector3 &p, UT_ValArray< TS_MetaPrimitive * > &)=0
virtual TS_MetaMin * isMin()
long long int64
Definition: SYS_Types.h:116
UT_Array< TS_MetaExpressionPtr > TS_ExpressionList
Definition: TS_Expression.h:46
int getThreadNum() const
virtual TS_MetaExpression * prune(const UT_BoundingBox &, UT_Interval &range)=0
UT_Array< TS_SweepNode * > TS_SweepList
Definition: TS_Expression.h:47
virtual void countMemory(UT_MemoryCounter &counter, bool inclusive) const
virtual float rayDensity(float t) const =0
virtual TS_MetaExpression * duplicate() const =0
TS_Octree * getOctree()
GLdouble t
Definition: glad.h:2397
#define TS_API
Definition: api.h:41
TS_SerialOp
Definition: TS_Expression.h:49
virtual float grad(const UT_Vector3 &point, UT_Vector3 &grad) const =0
virtual TS_MetaMax * isMax()
int getRibOpcode() const overridefinal
virtual const TS_ExpressionList * getAllKids() const
TS_SerialOp getOpCode() const overridefinal
Return the serialization operation.
UT_IntervalT< float > UT_Interval
Definition: UT_Interval.h:135
void prune(TreeT &tree, typename TreeT::ValueType tolerance=zeroVal< typename TreeT::ValueType >(), bool threaded=true, size_t grainSize=1)
Reduce the memory footprint of a tree by replacing with tiles any nodes whose values are all the same...
Definition: Prune.h:335
TS_SweepNode * myQueue
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER IMATH_HOSTDEVICE IMATH_CONSTEXPR14 T clip(const T &p, const Box< T > &box) IMATH_NOEXCEPT
Definition: ImathBoxAlgo.h:29
virtual TS_SerialOp getOpCode() const
Return the serialization operation.
virtual TS_MetaSum * isSum()
virtual void setThreadNum(int thread_num)