HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EUC_Expression.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2006
3  * Side Effects Software Inc. All rights reserved.
4  *
5  * Redistribution and use of Houdini Development Kit samples in source and
6  * binary forms, with or without modification, are permitted provided that the
7  * following conditions are met:
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. The name of Side Effects Software may not be used to endorse or
11  * promote products derived from this software without specific prior
12  * written permission.
13  *
14  * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
15  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17  * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  *----------------------------------------------------------------------------
26  * Defines the expressions that can be performed on sets of
27  * euclidean objects.
28  */
29 
30 #ifndef __EUC_Expression__
31 #define __EUC_Expression__
32 
33 #include "EUC_Object.h"
34 
35 #include <UT/UT_ValArray.h>
36 
37 namespace HDK_Sample {
38 
41 
42 // Generic expression.
44 {
45 public:
47 protected:
48  virtual ~EUC_Expression();
49 public:
50  // This is a refence counted object.
51  void addRef();
52  void removeRef();
53 
54  // Each expression gets a global id which is constant for this
55  // runtime invocation. This lets one marshal an expression pointer
56  // as an id and safely determine if it still exists.
57  int getUid() const { return myUid; }
58  static EUC_Expression *getExprFromUid(int uid);
59 
60  void applyLook(EUC_Object *obj);
61  void setLook(bool visible, const UT_Vector3 &cd);
62 
63  // Evaluates the set of rules given, generating a bunch of
64  // EUC_Objects.
65  void evaluate(EUC_ObjectList &results);
66 
67 protected:
68  // Evaluates this expression. Initializes result to the output
69  // of this expression. totalobj gets any net-new objects
70  // added to it.
71  virtual void evaluateSubclass(EUC_ObjectList &result,
72  EUC_ObjectList &totalobj) = 0;
73 
74 public:
75  // Handles the recursive evaluation including caching the results
76  // so we don't evaluate an expression twice in a single invocation.
77  void evaluateRecurse(EUC_ObjectList &result,
78  EUC_ObjectList &totalobj);
79 private:
80  int myRefCount;
81  int myUid;
82 
83  // Our look for net-new objects
84  bool myVisible;
85  UT_Vector3 myCd;
86 
87  // Global list of expressions
88  static EUC_ExpressionList ourExpressionList;
89 
90  // Our cache of results
91  EUC_ObjectList myObjectCache;
92  int myLastEvaluateTime;
93  static int ourEvaluateTime;
94 };
95 
96 // Creates a point.
98 {
99 public:
100  EUC_ExprPoint(const UT_Vector2 &pos);
101 
102 protected:
103  virtual void evaluateSubclass(EUC_ObjectList &result,
104  EUC_ObjectList &totalobj);
105 protected:
107 };
108 
109 // Creates a point from an object, extracting it as necessary.
111 {
112 public:
114  virtual ~EUC_ExprPointFromObject();
115 
116 protected:
117  virtual void evaluateSubclass(EUC_ObjectList &result,
118  EUC_ObjectList &totalobj);
119 protected:
121  int myIndex;
122 };
123 
124 // Creates a line from a pair of points
126 {
127 public:
129  virtual ~EUC_ExprLineFromPoints();
130 
131 protected:
132  virtual void evaluateSubclass(EUC_ObjectList &result,
133  EUC_ObjectList &totalobj);
134 protected:
136 };
137 
138 // Creates a circle from a pair of points
140 {
141 public:
143  virtual ~EUC_ExprCircleFromPoints();
144 
145 protected:
146  virtual void evaluateSubclass(EUC_ObjectList &result,
147  EUC_ObjectList &totalobj);
148 protected:
150 };
151 
152 // Intersects two objects.
154 {
155 public:
157  virtual ~EUC_ExprIntersect();
158 
159 protected:
160  virtual void evaluateSubclass(EUC_ObjectList &result,
161  EUC_ObjectList &totalobj);
162 protected:
164 };
165 
166 // Selects on object out of an expressions result list.
168 {
169 public:
170  EUC_ExprSelect(EUC_Expression *src, int idx);
171  virtual ~EUC_ExprSelect();
172 
173 protected:
174  virtual void evaluateSubclass(EUC_ObjectList &result,
175  EUC_ObjectList &totalobj);
176 protected:
178  int myIndex;
179 };
180 
181 }
182 
183 #endif
void applyLook(EUC_Object *obj)
virtual void evaluateSubclass(EUC_ObjectList &result, EUC_ObjectList &totalobj)
static EUC_Expression * getExprFromUid(int uid)
void evaluate(EUC_ObjectList &results)
EUC_ExprLineFromPoints(EUC_Expression *pta, EUC_Expression *ptb)
EUC_ExprIntersect(EUC_Expression *expra, EUC_Expression *exprb)
EUC_ExprPointFromObject(EUC_Expression *src, int idx)
virtual void evaluateSubclass(EUC_ObjectList &result, EUC_ObjectList &totalobj)=0
void setLook(bool visible, const UT_Vector3 &cd)
virtual void evaluateSubclass(EUC_ObjectList &result, EUC_ObjectList &totalobj)
virtual void evaluateSubclass(EUC_ObjectList &result, EUC_ObjectList &totalobj)
EUC_ExprCircleFromPoints(EUC_Expression *center, EUC_Expression *pt)
virtual void evaluateSubclass(EUC_ObjectList &result, EUC_ObjectList &totalobj)
UT_ValArray< EUC_Expression * > EUC_ExpressionList
EUC_ExprPoint(const UT_Vector2 &pos)
void evaluateRecurse(EUC_ObjectList &result, EUC_ObjectList &totalobj)
EUC_ExprSelect(EUC_Expression *src, int idx)
virtual void evaluateSubclass(EUC_ObjectList &result, EUC_ObjectList &totalobj)
virtual void evaluateSubclass(EUC_ObjectList &result, EUC_ObjectList &totalobj)
GLenum src
Definition: glcorearb.h:1792