00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <UT/UT_DSOVersion.h>
00030 #include <GU/GU_Detail.h>
00031 #include <PRM/PRM_Include.h>
00032 #include <OP/OP_Operator.h>
00033 #include <OP/OP_OperatorTable.h>
00034 #include "SOP_Euclid.h"
00035
00036 #include "EUC_Expression.C"
00037 #include "EUC_Object.C"
00038 #include "GR_Euclid.C"
00039
00040 using namespace HDK_Sample;
00041
00042 void
00043 newSopOperator(OP_OperatorTable *table)
00044 {
00045 table->addOperator(new OP_Operator("euclidpoint",
00046 "x Point",
00047 SOP_EuclidPoint::myConstructor,
00048 SOP_EuclidPoint::myTemplateList,
00049 0,
00050 0,
00051 0,
00052 OP_FLAG_GENERATOR));
00053 table->addOperator(new OP_Operator("euclidpointfromobject",
00054 "x Point From Object",
00055 SOP_EuclidPointFromObject::myConstructor,
00056 SOP_EuclidPointFromObject::myTemplateList,
00057 1,
00058 1,
00059 0));
00060 table->addOperator(new OP_Operator("euclidlinefrompoints",
00061 "x Line From Points",
00062 SOP_EuclidLineFromPoints::myConstructor,
00063 SOP_EuclidLineFromPoints::myTemplateList,
00064 2,
00065 2,
00066 0));
00067 table->addOperator(new OP_Operator("euclidcirclefrompoints",
00068 "x Circle From Points",
00069 SOP_EuclidCircleFromPoints::myConstructor,
00070 SOP_EuclidCircleFromPoints::myTemplateList,
00071 2,
00072 2,
00073 0));
00074 table->addOperator(new OP_Operator("euclidintersect",
00075 "x Intersect",
00076 SOP_EuclidIntersect::myConstructor,
00077 SOP_EuclidIntersect::myTemplateList,
00078 2,
00079 2,
00080 0));
00081 table->addOperator(new OP_Operator("euclidselect",
00082 "x Select",
00083 SOP_EuclidSelect::myConstructor,
00084 SOP_EuclidSelect::myTemplateList,
00085 1,
00086 1,
00087 0));
00088 }
00089
00090
00091 static PRM_Name names[] =
00092 {
00093 PRM_Name("index", "Index"),
00094 PRM_Name("hide", "Hide"),
00095 PRM_Name("color", "Color"),
00096 PRM_Name(0)
00097 };
00098
00099
00100
00101
00102 SOP_EuclidBase::SOP_EuclidBase(OP_Network *net, const char *name, OP_Operator *op) : SOP_Node(net, name, op)
00103 {
00104 myExpression = 0;
00105 }
00106
00107 SOP_EuclidBase::~SOP_EuclidBase()
00108 {
00109 if (myExpression)
00110 myExpression->removeRef();
00111 }
00112
00113 EUC_Expression *
00114 SOP_EuclidBase::getInputExpression(int idx) const
00115 {
00116 EUC_Expression *expr;
00117 const GU_Detail *igdp;
00118 int aoff, euc;
00119
00120 igdp = inputGeo(idx);
00121 aoff = igdp->attribs().getOffset("euclid", GB_ATTRIB_INT);
00122 if (aoff < 0)
00123 return 0;
00124
00125 euc = *(igdp->attribs().castAttribData<int>(aoff));
00126 expr = EUC_Expression::getExprFromUid(euc);
00127 return expr;
00128 }
00129
00130 OP_ERROR
00131 SOP_EuclidBase::cookMySop(OP_Context &context)
00132 {
00133 int zero = 0;
00134 int aoff;
00135 float now = context.myTime;
00136
00137
00138
00139 if (lockInputs(context) >= UT_ERROR_ABORT)
00140 return error();
00141
00142
00143 if (myExpression)
00144 myExpression->removeRef();
00145
00146
00147 myExpression = cookExpression(context);
00148 if (myExpression)
00149 {
00150 myExpression->addRef();
00151 UT_Vector3 cd;
00152 cd.assign(CR(now), CG(now), CB(now));
00153 myExpression->setLook(!HIDE(now), cd);
00154 }
00155
00156
00157 gdp->clearAndDestroy();
00158 gdp->addAttrib("euclid", sizeof(int), GB_ATTRIB_INT, &zero);
00159
00160 aoff = gdp->attribs().getOffset("euclid", GB_ATTRIB_INT);
00161 if (myExpression)
00162 *(gdp->attribs().castAttribData<int>(aoff)) = myExpression->getUid();
00163 else
00164 *(gdp->attribs().castAttribData<int>(aoff)) = -1;
00165
00166 unlockInputs();
00167 return error();
00168 }
00169
00170
00171
00172
00173
00174 PRM_Template
00175 SOP_EuclidPoint::myTemplateList[] = {
00176 PRM_Template(PRM_TOGGLE, 1, &names[1]),
00177 PRM_Template(PRM_RGB_J, 3, &names[2], PRMoneDefaults),
00178 PRM_Template(PRM_XYZ_J, 3, &PRMcenterName),
00179 PRM_Template()
00180 };
00181
00182 SOP_EuclidPoint::SOP_EuclidPoint(OP_Network *net, const char *name, OP_Operator *op) : SOP_EuclidBase(net, name, op)
00183 {
00184 }
00185
00186 OP_Node *
00187 SOP_EuclidPoint::myConstructor(OP_Network *net, const char *name, OP_Operator *op)
00188 {
00189 return new SOP_EuclidPoint(net, name, op);
00190 }
00191
00192 EUC_Expression *
00193 SOP_EuclidPoint::cookExpression(OP_Context &context)
00194 {
00195 EUC_Expression *expr;
00196 UT_Vector2 pt;
00197
00198 pt.x() = TX(context.myTime);
00199 pt.y() = TY(context.myTime);
00200
00201 expr = new EUC_ExprPoint(pt);
00202
00203 return expr;
00204 }
00205
00206
00207
00208
00209
00210 PRM_Template
00211 SOP_EuclidPointFromObject::myTemplateList[] = {
00212 PRM_Template(PRM_TOGGLE, 1, &names[1]),
00213 PRM_Template(PRM_RGB_J, 3, &names[2], PRMoneDefaults),
00214 PRM_Template(PRM_INT_J, 1, &names[0]),
00215 PRM_Template()
00216 };
00217
00218 SOP_EuclidPointFromObject::SOP_EuclidPointFromObject(OP_Network *net, const char *name, OP_Operator *op) : SOP_EuclidBase(net, name, op)
00219 {
00220 }
00221
00222 OP_Node *
00223 SOP_EuclidPointFromObject::myConstructor(OP_Network *net, const char *name, OP_Operator *op)
00224 {
00225 return new SOP_EuclidPointFromObject(net, name, op);
00226 }
00227
00228 EUC_Expression *
00229 SOP_EuclidPointFromObject::cookExpression(OP_Context &context)
00230 {
00231 EUC_Expression *expr;
00232 int idx;
00233
00234 idx = IDX(context.myTime);
00235
00236 expr = getInputExpression(0);
00237 if (!expr)
00238 return 0;
00239 expr = new EUC_ExprPointFromObject(expr, idx);
00240
00241 return expr;
00242 }
00243
00244
00245
00246
00247
00248 PRM_Template
00249 SOP_EuclidLineFromPoints::myTemplateList[] = {
00250 PRM_Template(PRM_TOGGLE, 1, &names[1]),
00251 PRM_Template(PRM_RGB_J, 3, &names[2], PRMoneDefaults),
00252 PRM_Template()
00253 };
00254
00255 SOP_EuclidLineFromPoints::SOP_EuclidLineFromPoints(OP_Network *net, const char *name, OP_Operator *op) : SOP_EuclidBase(net, name, op)
00256 {
00257 }
00258
00259 OP_Node *
00260 SOP_EuclidLineFromPoints::myConstructor(OP_Network *net, const char *name, OP_Operator *op)
00261 {
00262 return new SOP_EuclidLineFromPoints(net, name, op);
00263 }
00264
00265 EUC_Expression *
00266 SOP_EuclidLineFromPoints::cookExpression(OP_Context &)
00267 {
00268 EUC_Expression *expr1, *expr2;
00269
00270 expr1 = getInputExpression(0);
00271 if (!expr1)
00272 return 0;
00273 expr2 = getInputExpression(1);
00274 if (!expr2)
00275 return 0;
00276 return new EUC_ExprLineFromPoints(expr1, expr2);
00277 }
00278
00279
00280
00281
00282
00283 PRM_Template
00284 SOP_EuclidCircleFromPoints::myTemplateList[] = {
00285 PRM_Template(PRM_TOGGLE, 1, &names[1]),
00286 PRM_Template(PRM_RGB_J, 3, &names[2], PRMoneDefaults),
00287 PRM_Template()
00288 };
00289
00290 SOP_EuclidCircleFromPoints::SOP_EuclidCircleFromPoints(OP_Network *net, const char *name, OP_Operator *op) : SOP_EuclidBase(net, name, op)
00291 {
00292 }
00293
00294 OP_Node *
00295 SOP_EuclidCircleFromPoints::myConstructor(OP_Network *net, const char *name, OP_Operator *op)
00296 {
00297 return new SOP_EuclidCircleFromPoints(net, name, op);
00298 }
00299
00300 EUC_Expression *
00301 SOP_EuclidCircleFromPoints::cookExpression(OP_Context &)
00302 {
00303 EUC_Expression *expr1, *expr2;
00304
00305 expr1 = getInputExpression(0);
00306 if (!expr1)
00307 return 0;
00308 expr2 = getInputExpression(1);
00309 if (!expr2)
00310 return 0;
00311 return new EUC_ExprCircleFromPoints(expr1, expr2);
00312 }
00313
00314
00315
00316
00317
00318 PRM_Template
00319 SOP_EuclidIntersect::myTemplateList[] = {
00320 PRM_Template(PRM_TOGGLE, 1, &names[1]),
00321 PRM_Template(PRM_RGB_J, 3, &names[2], PRMoneDefaults),
00322 PRM_Template()
00323 };
00324
00325 SOP_EuclidIntersect::SOP_EuclidIntersect(OP_Network *net, const char *name, OP_Operator *op) : SOP_EuclidBase(net, name, op)
00326 {
00327 }
00328
00329 OP_Node *
00330 SOP_EuclidIntersect::myConstructor(OP_Network *net, const char *name, OP_Operator *op)
00331 {
00332 return new SOP_EuclidIntersect(net, name, op);
00333 }
00334
00335 EUC_Expression *
00336 SOP_EuclidIntersect::cookExpression(OP_Context &)
00337 {
00338 EUC_Expression *expr1, *expr2;
00339
00340 expr1 = getInputExpression(0);
00341 if (!expr1)
00342 return 0;
00343 expr2 = getInputExpression(1);
00344 if (!expr2)
00345 return 0;
00346 return new EUC_ExprIntersect(expr1, expr2);
00347 }
00348
00349
00350
00351
00352
00353 PRM_Template
00354 SOP_EuclidSelect::myTemplateList[] = {
00355 PRM_Template(PRM_TOGGLE, 1, &names[1]),
00356 PRM_Template(PRM_RGB_J, 3, &names[2], PRMoneDefaults),
00357 PRM_Template(PRM_INT_J, 1, &names[0]),
00358 PRM_Template()
00359 };
00360
00361 SOP_EuclidSelect::SOP_EuclidSelect(OP_Network *net, const char *name, OP_Operator *op) : SOP_EuclidBase(net, name, op)
00362 {
00363 }
00364
00365 OP_Node *
00366 SOP_EuclidSelect::myConstructor(OP_Network *net, const char *name, OP_Operator *op)
00367 {
00368 return new SOP_EuclidSelect(net, name, op);
00369 }
00370
00371 EUC_Expression *
00372 SOP_EuclidSelect::cookExpression(OP_Context &context)
00373 {
00374 EUC_Expression *expr;
00375 int idx;
00376
00377 idx = IDX(context.myTime);
00378
00379 expr = getInputExpression(0);
00380 if (!expr)
00381 return 0;
00382 expr = new EUC_ExprSelect(expr, idx);
00383
00384 return expr;
00385 }
00386