HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SOP_Euclid.C
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 sops that attach euclidean expressions to gdps.
27  */
28 
29 #include "SOP_Euclid.h"
30 
31 #include <GU/GU_Detail.h>
32 #include <OP/OP_AutoLockInputs.h>
33 #include <OP/OP_Operator.h>
34 #include <OP/OP_OperatorTable.h>
35 #include <PRM/PRM_Include.h>
36 #include <UT/UT_DSOVersion.h>
37 
38 #include "EUC_Expression.C"
39 #include "EUC_Object.C"
40 
41 using namespace HDK_Sample;
42 
43 void
45 {
46  table->addOperator(new OP_Operator("euclidpoint",
47  "x Point",
50  0,
51  0,
52  0,
54  table->addOperator(new OP_Operator("euclidpointfromobject",
55  "x Point From Object",
58  1,
59  1,
60  0));
61  table->addOperator(new OP_Operator("euclidlinefrompoints",
62  "x Line From Points",
65  2,
66  2,
67  0));
68  table->addOperator(new OP_Operator("euclidcirclefrompoints",
69  "x Circle From Points",
72  2,
73  2,
74  0));
75  table->addOperator(new OP_Operator("euclidintersect",
76  "x Intersect",
79  2,
80  2,
81  0));
82  table->addOperator(new OP_Operator("euclidselect",
83  "x Select",
86  1,
87  1,
88  0));
89 }
90 
91 
92 static PRM_Name names[] =
93 {
94  PRM_Name("index", "Index"),
95  PRM_Name("hide", "Hide"),
96  PRM_Name("color", "Color"),
97  PRM_Name(0)
98 };
99 
100 //
101 // SOP_Euclid
102 //
104  : SOP_Node(net, name, op)
105  , myExpression(NULL)
106 {
107  // This SOP always generates fresh geometry, so setting this flag
108  // is a bit redundant, but one could change it to check for the old
109  // attribute and only bump its data ID if the value changed.
111 }
112 
114 {
115  if (myExpression)
117 }
118 
121 {
122  const GU_Detail *igdp = inputGeo(idx);
123  GA_ROHandleI attrib(igdp->findIntTuple(GA_ATTRIB_GLOBAL, "euclid", 1));
124  if (attrib.isInvalid())
125  return 0;
126 
127  // NOTE: The detail is *always* at GA_Offset(0)
128  int euc = attrib.get(GA_Offset(0));
130  return expr;
131 }
132 
133 OP_ERROR
135 {
136  fpreal now = context.getTime();
137 
138  // We must lock our inputs before we try to access their geometry.
139  // OP_AutoLockInputs will automatically unlock our inputs when we return.
140  // NOTE: Don't call unlockInputs yourself when using this!
141  OP_AutoLockInputs inputs(this);
142  if (inputs.lock(context) >= UT_ERROR_ABORT)
143  return error();
144 
145  // Reset our old expression
146  if (myExpression)
148 
149  // Get the new expression.
150  myExpression = cookExpression(context);
151  if (myExpression)
152  {
153  myExpression->addRef();
154  UT_Vector3 cd(CR(now), CG(now), CB(now));
155  myExpression->setLook(!HIDE(now), cd);
156  }
157 
158  // Add to our gdp the signifier.
159  // NOTE: This will bump the data IDs for P and the topology attributes.
160  gdp->clearAndDestroy();
161 
162  // NOTE: This attribute will have a new data ID, because there's no
163  // previous attribute that it might reuse in this case.
164  GA_RWHandleI attrib(gdp->addIntTuple(GA_ATTRIB_DETAIL, "euclid", 1, GA_Defaults(0)));
165 
166  // NOTE: The detail is *always* at GA_Offset(0)
167  if (myExpression)
168  attrib.set(GA_Offset(0), myExpression->getUid());
169  else
170  attrib.set(GA_Offset(0), -1);
171 
172  return error();
173 }
174 
175 //
176 // SOP_EuclidPoint
177 //
178 
181  PRM_Template(PRM_TOGGLE, 1, &names[1]),
182  PRM_Template(PRM_RGB_J, 3, &names[2], PRMoneDefaults),
184  PRM_Template()
185 };
186 
188 {
189 }
190 
191 OP_Node *
193 {
194  return new SOP_EuclidPoint(net, name, op);
195 }
196 
199 {
200  UT_Vector2 pt;
201  pt.x() = TX(context.getTime());
202  pt.y() = TY(context.getTime());
203 
204  EUC_Expression *expr = new EUC_ExprPoint(pt);
205 
206  return expr;
207 }
208 
209 //
210 // SOP_EuclidPointFromObject
211 //
212 
215  PRM_Template(PRM_TOGGLE, 1, &names[1]),
216  PRM_Template(PRM_RGB_J, 3, &names[2], PRMoneDefaults),
217  PRM_Template(PRM_INT_J, 1, &names[0]),
218  PRM_Template()
219 };
220 
222 {
223 }
224 
225 OP_Node *
227 {
228  return new SOP_EuclidPointFromObject(net, name, op);
229 }
230 
233 {
234  int idx = IDX(context.getTime());
235 
237  if (!expr)
238  return 0;
239  expr = new EUC_ExprPointFromObject(expr, idx);
240 
241  return expr;
242 }
243 
244 //
245 // SOP_EuclidLineFromPoints
246 //
247 
250  PRM_Template(PRM_TOGGLE, 1, &names[1]),
251  PRM_Template(PRM_RGB_J, 3, &names[2], PRMoneDefaults),
252  PRM_Template()
253 };
254 
256 {
257 }
258 
259 OP_Node *
261 {
262  return new SOP_EuclidLineFromPoints(net, name, op);
263 }
264 
267 {
269  if (!expr1)
270  return 0;
272  if (!expr2)
273  return 0;
274  return new EUC_ExprLineFromPoints(expr1, expr2);
275 }
276 
277 //
278 // SOP_EuclidCircleFromPoints
279 //
280 
283  PRM_Template(PRM_TOGGLE, 1, &names[1]),
284  PRM_Template(PRM_RGB_J, 3, &names[2], PRMoneDefaults),
285  PRM_Template()
286 };
287 
289 {
290 }
291 
292 OP_Node *
294 {
295  return new SOP_EuclidCircleFromPoints(net, name, op);
296 }
297 
300 {
302  if (!expr1)
303  return 0;
305  if (!expr2)
306  return 0;
307  return new EUC_ExprCircleFromPoints(expr1, expr2);
308 }
309 
310 //
311 // SOP_EuclidIntersect
312 //
313 
316  PRM_Template(PRM_TOGGLE, 1, &names[1]),
317  PRM_Template(PRM_RGB_J, 3, &names[2], PRMoneDefaults),
318  PRM_Template()
319 };
320 
322 {
323 }
324 
325 OP_Node *
327 {
328  return new SOP_EuclidIntersect(net, name, op);
329 }
330 
333 {
335  if (!expr1)
336  return 0;
338  if (!expr2)
339  return 0;
340  return new EUC_ExprIntersect(expr1, expr2);
341 }
342 
343 //
344 // SOP_EuclidSelect
345 //
346 
349  PRM_Template(PRM_TOGGLE, 1, &names[1]),
350  PRM_Template(PRM_RGB_J, 3, &names[2], PRMoneDefaults),
351  PRM_Template(PRM_INT_J, 1, &names[0]),
352  PRM_Template()
353 };
354 
356 {
357 }
358 
359 OP_Node *
361 {
362  return new SOP_EuclidSelect(net, name, op);
363 }
364 
367 {
368  int idx = IDX(context.getTime());
369 
371  if (!expr)
372  return 0;
373  expr = new EUC_ExprSelect(expr, idx);
374 
375  return expr;
376 }
377 
EUC_Expression * getInputExpression(int idx) const
Definition: SOP_Euclid.C:120
virtual EUC_Expression * cookExpression(OP_Context &context)
Definition: SOP_Euclid.C:332
virtual OP_ERROR error()
static PRM_Template myTemplateList[]
Definition: SOP_Euclid.h:93
fpreal CR(fpreal t)
Definition: SOP_Euclid.h:52
Class which stores the default values for a GA_Attribute.
Definition: GA_Defaults.h:35
static OP_Node * myConstructor(OP_Network *, const char *, OP_Operator *)
Definition: SOP_Euclid.C:260
OP_ERROR lock(OP_Context &context)
Locks all inputs.
fpreal TX(fpreal t)
Definition: SOP_Euclid.h:70
fpreal getTime() const
Definition: OP_Context.h:34
static PRM_Template myTemplateList[]
Definition: SOP_Euclid.h:79
fpreal CG(fpreal t)
Definition: SOP_Euclid.h:53
static EUC_Expression * getExprFromUid(int uid)
void clearAndDestroy()
Clear all the points/primitives out of this detail.
Definition: GEO_Detail.h:236
SOP_EuclidSelect(OP_Network *net, const char *name, OP_Operator *op)
Definition: SOP_Euclid.C:355
virtual EUC_Expression * cookExpression(OP_Context &context)
Definition: SOP_Euclid.C:299
T & x(void)
Definition: UT_Vector2.h:284
static OP_Node * myConstructor(OP_Network *, const char *, OP_Operator *)
Definition: SOP_Euclid.C:226
#define OP_FLAG_GENERATOR
Definition: OP_Operator.h:67
static PRM_Template myTemplateList[]
Definition: SOP_Euclid.h:64
UT_ErrorSeverity
Definition: UT_Error.h:25
SOP_EuclidCircleFromPoints(OP_Network *net, const char *name, OP_Operator *op)
Definition: SOP_Euclid.C:288
virtual EUC_Expression * cookExpression(OP_Context &context)
Definition: SOP_Euclid.C:366
bool addOperator(OP_Operator *op, std::ostream *err=nullptr)
PRM_API const PRM_Type PRM_XYZ_J
PRM_API const PRM_Type PRM_INT_J
PRM_API const PRM_Type PRM_RGB_J
const GA_Attribute * findIntTuple(GA_AttributeOwner owner, GA_AttributeScope scope, const UT_StringRef &name, int min_size=1, int max_size=-1) const
SOP_EuclidIntersect(OP_Network *net, const char *name, OP_Operator *op)
Definition: SOP_Euclid.C:321
GA_Size GA_Offset
Definition: GA_Types.h:617
void setLook(bool visible, const UT_Vector3 &cd)
void newSopOperator(OP_OperatorTable *table)
Definition: SOP_Euclid.C:44
static OP_Node * myConstructor(OP_Network *, const char *, OP_Operator *)
Definition: SOP_Euclid.C:326
fpreal CB(fpreal t)
Definition: SOP_Euclid.h:54
static PRM_Template myTemplateList[]
Definition: SOP_Euclid.h:105
const GU_Detail * inputGeo(int index, OP_Context &)
Definition: SOP_Node.h:1134
virtual EUC_Expression * cookExpression(OP_Context &context)
Definition: SOP_Euclid.C:232
static PRM_Template myTemplateList[]
Definition: SOP_Euclid.h:129
SOP_NodeFlags mySopFlags
Definition: SOP_Node.h:1601
SOP_EuclidPointFromObject(OP_Network *net, const char *name, OP_Operator *op)
Definition: SOP_Euclid.C:221
SYS_FORCE_INLINE T get(GA_Offset off, int comp=0) const
Definition: GA_Handle.h:194
virtual EUC_Expression * cookExpression(OP_Context &context)=0
virtual EUC_Expression * cookExpression(OP_Context &context)
Definition: SOP_Euclid.C:198
GLuint const GLchar * name
Definition: glcorearb.h:785
static OP_Node * myConstructor(OP_Network *, const char *, OP_Operator *)
Definition: SOP_Euclid.C:293
static OP_Node * myConstructor(OP_Network *, const char *, OP_Operator *)
Definition: SOP_Euclid.C:192
void setManagesDataIDs(bool onOff)
Definition: SOP_NodeFlags.h:34
GU_Detail * gdp
Definition: SOP_Node.h:1598
PRM_API PRM_Default PRMoneDefaults[]
double fpreal
Definition: SYS_Types.h:263
virtual EUC_Expression * cookExpression(OP_Context &context)
Definition: SOP_Euclid.C:266
SYS_FORCE_INLINE void set(GA_Offset off, const T &val) const
Definition: GA_Handle.h:351
SOP_EuclidLineFromPoints(OP_Network *net, const char *name, OP_Operator *op)
Definition: SOP_Euclid.C:255
PRM_API const PRM_Type PRM_TOGGLE
SOP_EuclidPoint(OP_Network *net, const char *name, OP_Operator *op)
Definition: SOP_Euclid.C:187
T & y(void)
Definition: UT_Vector2.h:286
SOP_EuclidBase(OP_Network *net, const char *name, OP_Operator *op)
Definition: SOP_Euclid.C:103
static PRM_Template myTemplateList[]
Definition: SOP_Euclid.h:117
EUC_Expression * myExpression
Definition: SOP_Euclid.h:56
static OP_Node * myConstructor(OP_Network *, const char *, OP_Operator *)
Definition: SOP_Euclid.C:360
GA_Attribute * addIntTuple(GA_AttributeOwner owner, GA_AttributeScope scope, const UT_StringHolder &name, int tuple_size, const GA_Defaults &defaults=GA_Defaults(0), const UT_Options *creation_args=0, const GA_AttributeOptions *attribute_options=0, GA_Storage storage=GA_STORE_INT32, const GA_ReuseStrategy &reuse=GA_ReuseStrategy())
virtual OP_ERROR cookMySop(OP_Context &context)
Definition: SOP_Euclid.C:134
fpreal TY(fpreal t)
Definition: SOP_Euclid.h:71
PRM_API PRM_Name PRMcenterName