HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EUC_Expression.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024
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.
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.
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:
104  EUC_ObjectList &totalobj) override;
105 protected:
107 };
108 
109 // Creates a point from an object, extracting it as necessary.
111 {
112 public:
114  ~EUC_ExprPointFromObject() override;
115 
116 protected:
118  EUC_ObjectList &totalobj) override;
119 protected:
121  int myIndex;
122 };
123 
124 // Creates a line from a pair of points
126 {
127 public:
129  ~EUC_ExprLineFromPoints() override;
130 
131 protected:
133  EUC_ObjectList &totalobj) override;
134 protected:
136 };
137 
138 // Creates a circle from a pair of points
140 {
141 public:
143  ~EUC_ExprCircleFromPoints() override;
144 
145 protected:
147  EUC_ObjectList &totalobj) override;
148 protected:
150 };
151 
152 // Intersects two objects.
154 {
155 public:
157  ~EUC_ExprIntersect() override;
158 
159 protected:
161  EUC_ObjectList &totalobj) override;
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  ~EUC_ExprSelect() override;
172 
173 protected:
175  EUC_ObjectList &totalobj) override;
176 protected:
178  int myIndex;
179 };
180 
181 }
182 
183 #endif
void applyLook(EUC_Object *obj)
void evaluateSubclass(EUC_ObjectList &result, EUC_ObjectList &totalobj) override
void evaluateSubclass(EUC_ObjectList &result, EUC_ObjectList &totalobj) override
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)
**But if you need a result
Definition: thread.h:613
EUC_ExprPointFromObject(EUC_Expression *src, int idx)
void evaluateSubclass(EUC_ObjectList &result, EUC_ObjectList &totalobj) override
virtual void evaluateSubclass(EUC_ObjectList &result, EUC_ObjectList &totalobj)=0
void setLook(bool visible, const UT_Vector3 &cd)
EUC_ExprCircleFromPoints(EUC_Expression *center, EUC_Expression *pt)
void evaluateSubclass(EUC_ObjectList &result, EUC_ObjectList &totalobj) override
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)
void evaluateSubclass(EUC_ObjectList &result, EUC_ObjectList &totalobj) override
void evaluateSubclass(EUC_ObjectList &result, EUC_ObjectList &totalobj) override
GLenum src
Definition: glcorearb.h:1793