00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _TS_Expression_h_
00020 #define _TS_Expression_h_
00021
00022 #include "TS_API.h"
00023 #include <UT/UT_Matrix4.h>
00024 #include <UT/UT_Matrix3.h>
00025 #include <UT/UT_Vector4.h>
00026 #include <UT/UT_Vector3.h>
00027 #include <UT/UT_BoundingBox.h>
00028 #include <UT/UT_Interval.h>
00029
00030 #include <UT/UT_PtrArray.h>
00031 #include "TS_Resource.h"
00032 #include "TS_Quadric.h"
00033 #include "TS_Ray.h"
00034
00035 class UT_FloatArray;
00036 class UT_LUT;
00037
00038
00039
00040
00041 class TS_API TS_MetaKernel {
00042 public:
00043 const char *myToken;
00044 const char *myLabel;
00045
00046 float (*p)(float );
00047 UT_Interval (*pr)(const UT_Interval &);
00048 float (*dp)(float);
00049 UT_Interval (*dpr)(const UT_Interval &);
00050 };
00051
00052
00053
00054 class TS_Octree;
00055 class TS_SweepNode;
00056 class TS_MetaExpression;
00057 class TS_MetaPrimitive;
00058 class TS_MetaSum;
00059 class TS_MetaMin;
00060 class TS_MetaMax;
00061 class ts_PrimNode;
00062
00063 typedef UT_PtrArray<TS_MetaExpression *> TS_ExpressionList;
00064 typedef UT_PtrArray<TS_SweepNode *> TS_SweepList;
00065
00066 class TS_API TS_MetaExpression: public TS_Resource {
00067 public:
00068 virtual TS_MetaPrimitive *isPrimitive();
00069 virtual TS_MetaSum *isSum();
00070 virtual TS_MetaMin *isMin();
00071 virtual TS_MetaMax *isMax();
00072
00073 virtual float density(const UT_Vector3 &p) const = 0;
00074 virtual UT_Interval density(const UT_BoundingBox &p) const = 0;
00075
00076
00077
00078 virtual float listDensity(const UT_Vector3 &p,
00079 UT_PtrArray<TS_MetaPrimitive *> &) = 0;
00080
00081 virtual float grad(const UT_Vector3 &point,
00082 UT_Vector3 &grad) const = 0;
00083
00084 virtual void raySweepInit(const TS_Ray &ray,
00085 float clip, float &t0, float &t1) = 0;
00086 virtual void raySweepComplete();
00087
00088 virtual float rayDensity(float t) const = 0;
00089 virtual UT_Interval rayDensity(const UT_Interval &t) const = 0;
00090
00091 virtual int rayIntersect(const TS_Ray &ray,
00092 const UT_Interval &start,
00093 float &result,
00094 float tol = -1.0f);
00095 virtual int rayIntersect(const TS_Ray &ray,
00096 const UT_Interval &start,
00097 UT_FloatArray &result,
00098 float tol = -1.0f);
00099
00100 const UT_BoundingBox &getBBox() const { return myBBox; }
00101 virtual UT_Interval getBBox(UT_BoundingBox &) const = 0;
00102
00103 virtual TS_MetaExpression *prune(const UT_BoundingBox &,
00104 UT_Interval &range) = 0;
00105
00106 virtual TS_MetaExpression *copy() = 0;
00107 virtual TS_MetaExpression *duplicate() const = 0;
00108
00109 virtual int setRay(const TS_Ray &ray) = 0;
00110
00111 virtual TS_SweepNode *allocSweepNode(const TS_Ray &ray);
00112 virtual const TS_ExpressionList *getAllKids() const;
00113
00114 const TS_ExpressionList *getCellPrimitives(const UT_Vector3 &pos);
00115
00116 #if 0
00117 void getCellPrimitives(const UT_Vector3 &pos,
00118 TS_ExpressionList &primList);
00119 #endif
00120 TS_Octree *getOctree()
00121 {
00122 if (!myOctree) buildOctree();
00123 return myOctree;
00124 }
00125
00126 void setOctreeIndex(int idx) { myOctreeRayIndex = idx; }
00127 int getOctreeIndex() const { return myOctreeRayIndex; }
00128
00129 virtual void getAllPrimitives(UT_PtrArray<TS_MetaPrimitive *> &prims) {}
00130
00131
00132
00133 virtual int getRibOpcode() const { return -1; }
00134
00135
00136 int getThreadNum() const { return myThreadNum; }
00137
00138
00139 virtual void setThreadNum(int threadNum)
00140 { myThreadNum = threadNum; }
00141
00142
00143
00144
00145 static void setupThreads(int numThreads);
00146
00147 public:
00148
00149
00150
00151
00152 int myThreadNum;
00153
00154 protected:
00155 TS_MetaExpression();
00156 virtual ~TS_MetaExpression();
00157
00158 void clearOctree();
00159 virtual void buildOctree();
00160
00161 TS_Octree *myOctree;
00162
00163 UT_BoundingBox myBBox;
00164 int myRayIndex, myOctreeRayIndex;
00165
00166 private:
00167
00168 };
00169
00170 class TS_API TS_MetaOp: public TS_MetaExpression {
00171 public:
00172 virtual void append(TS_MetaExpression *);
00173 virtual const TS_ExpressionList *getAllKids() const;
00174 virtual int setRay(const TS_Ray &ray);
00175
00176 virtual void raySweepInit(const TS_Ray &ray,
00177 float clip, float &t0, float &t1);
00178 virtual void raySweepComplete();
00179
00180 virtual void getAllPrimitives(UT_PtrArray<TS_MetaPrimitive *> &prims);
00181
00182
00183
00184 virtual void setThreadNum(int threadNum);
00185
00186
00187
00188
00189 void reset();
00190
00191 public:
00192 void initSweepList(const TS_Ray &ray);
00193 TS_ExpressionList myArray;
00194 TS_SweepNode *myActive;
00195 TS_SweepNode *myQueue;
00196
00197 protected:
00198 TS_MetaOp(int n);
00199 virtual ~TS_MetaOp();
00200
00201
00202 void freeList(ts_PrimNode *listStart);
00203 void clearAndDestroy();
00204
00205 private:
00206 };
00207
00208 class TS_API TS_MetaSum: public TS_MetaOp {
00209 public:
00210 TS_MetaSum(int n = 0);
00211 TS_MetaSum *isSum();
00212 float density(const UT_Vector3 &p) const;
00213 UT_Interval density(const UT_BoundingBox &p) const;
00214 virtual float listDensity(const UT_Vector3 &p,
00215 UT_PtrArray<TS_MetaPrimitive *> &);
00216 float grad(const UT_Vector3 &point, UT_Vector3 &grad) const;
00217 float rayDensity(float t) const;
00218 UT_Interval rayDensity(const UT_Interval &t) const;
00219 UT_Interval getBBox(UT_BoundingBox &) const;
00220 TS_MetaExpression *prune(const UT_BoundingBox &, UT_Interval &range);
00221 TS_MetaExpression *copy();
00222 TS_MetaExpression *duplicate() const;
00223
00224
00225 virtual int getRibOpcode() const { return 0; }
00226 protected:
00227 ~TS_MetaSum();
00228 };
00229
00230 class TS_API TS_MetaMax: public TS_MetaOp {
00231 public:
00232 TS_MetaMax(int n = 0);
00233 TS_MetaMax *isMax();
00234 float density(const UT_Vector3 &p) const;
00235 UT_Interval density(const UT_BoundingBox &p) const;
00236 virtual float listDensity(const UT_Vector3 &p,
00237 UT_PtrArray<TS_MetaPrimitive *> &);
00238 float grad(const UT_Vector3 &point, UT_Vector3 &grad) const;
00239 float rayDensity(float t) const;
00240 UT_Interval rayDensity(const UT_Interval &t) const;
00241 UT_Interval getBBox(UT_BoundingBox &) const;
00242 TS_MetaExpression *prune(const UT_BoundingBox &, UT_Interval &range);
00243 TS_MetaExpression *copy();
00244 TS_MetaExpression *duplicate() const;
00245
00246
00247 virtual int getRibOpcode() const { return 2; }
00248 protected:
00249 ~TS_MetaMax();
00250 };
00251
00252 class TS_API TS_MetaMin: public TS_MetaOp {
00253 public:
00254 TS_MetaMin(int n = 0);
00255 virtual void append(TS_MetaExpression *);
00256 TS_MetaMin *isMin();
00257 float density(const UT_Vector3 &p) const;
00258 UT_Interval density(const UT_BoundingBox &p) const;
00259 virtual float listDensity(const UT_Vector3 &p,
00260 UT_PtrArray<TS_MetaPrimitive *> &);
00261 float grad(const UT_Vector3 &point, UT_Vector3 &grad) const;
00262 float rayDensity(float t) const;
00263 UT_Interval rayDensity(const UT_Interval &t) const;
00264 UT_Interval getBBox(UT_BoundingBox &) const;
00265 TS_MetaExpression *prune(const UT_BoundingBox &, UT_Interval &range);
00266 TS_MetaExpression *copy();
00267 TS_MetaExpression *duplicate() const;
00268
00269
00270 virtual int getRibOpcode() const { return 3; }
00271 protected:
00272 ~TS_MetaMin();
00273 };
00274
00275
00276
00277
00278 #define TS_MetaPotentialThreshold 1.0F
00279
00280 #endif // _TS_Expression_h_