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 <UT/UT_Math.h>
00031 #include <UT/UT_Matrix3.h>
00032 #include <UT/UT_Matrix4.h>
00033 #include <GEO/GEO_AttributeHandle.h>
00034 #include <GU/GU_Detail.h>
00035 #include <GU/GU_PrimPoly.h>
00036 #include <PRM/PRM_Include.h>
00037 #include <OP/OP_Operator.h>
00038 #include <OP/OP_OperatorTable.h>
00039 #include <OP/OP_Director.h>
00040 #include <SOP/SOP_Error.h>
00041 #include "SOP_TimeCompare.h"
00042
00043 using namespace HDK_Sample;
00044
00045 void
00046 newSopOperator(OP_OperatorTable *table)
00047 {
00048 table->addOperator(new OP_Operator("hdk_timecompare",
00049 "Time Compare",
00050 SOP_TimeCompare::myConstructor,
00051 SOP_TimeCompare::myTemplateList,
00052 2,
00053 2,
00054 0));
00055 }
00056
00057 static PRM_Default frameDefault(0, "$FF");
00058
00059 static PRM_Name names[] = {
00060 PRM_Name("attrib", "Comparison Point Attribute"),
00061 PRM_Name("resultattrib", "Result Attribute"),
00062 PRM_Name("frame", "Second Input Frame"),
00063 };
00064
00065 PRM_Template
00066 SOP_TimeCompare::myTemplateList[] = {
00067 PRM_Template(PRM_STRING, 1, &PRMgroupName, 0, &SOP_Node::pointGroupMenu),
00068 PRM_Template(PRM_STRING, 1, &names[0]),
00069 PRM_Template(PRM_STRING, 1, &names[1]),
00070 PRM_Template(PRM_FLT_J, 1, &names[2], &frameDefault),
00071 PRM_Template(),
00072 };
00073
00074
00075 OP_Node *
00076 SOP_TimeCompare::myConstructor(OP_Network *net, const char *name, OP_Operator *op)
00077 {
00078 return new SOP_TimeCompare(net, name, op);
00079 }
00080
00081 SOP_TimeCompare::SOP_TimeCompare(OP_Network *net, const char *name, OP_Operator *op)
00082 : SOP_Node(net, name, op), myGroup(0)
00083 {
00084 }
00085
00086 SOP_TimeCompare::~SOP_TimeCompare() {}
00087
00088 OP_ERROR
00089 SOP_TimeCompare::cookInputGroups(OP_Context &context, int alone)
00090 {
00091
00092
00093 return cookInputPointGroups(context, myGroup, myDetailGroupPair, alone);
00094 }
00095
00096 OP_ERROR
00097 SOP_TimeCompare::cookMySop(OP_Context &context)
00098 {
00099 GEO_Point *ppt;
00100 float t;
00101 float secondinput_t;
00102 OP_Context secondinput_context;
00103 GEO_AttributeHandle dst_gah, a_gah, b_gah;
00104 UT_String attribname, resultname;
00105 const GU_Detail *agdp, *bgdp;
00106
00107
00108
00109 if (lockInput(0, context) >= UT_ERROR_ABORT)
00110 return error();
00111
00112 t = context.myTime;
00113
00114
00115 secondinput_context = context;
00116
00117
00118 secondinput_t = FRAME(t);
00119
00120
00121 secondinput_t = OPgetDirector()->getChannelManager()->getTime(secondinput_t);
00122
00123
00124 secondinput_context.myTime = secondinput_t;
00125
00126
00127
00128
00129 if (lockInput(1, secondinput_context) >= UT_ERROR_ABORT)
00130 {
00131 unlockInput(0);
00132 return error();
00133 }
00134
00135
00136 duplicateSource(0, context);
00137
00138
00139 ATTRIB(attribname, t);
00140 RESULTATTRIB(resultname, t);
00141
00142
00143
00144 if (!attribname.isstring() || !resultname.isstring())
00145 {
00146 unlockInput(0);
00147 unlockInput(1);
00148 return error();
00149 }
00150
00151
00152
00153 attribname.forceValidVariableName();
00154 resultname.forceValidVariableName();
00155
00156
00157 agdp = inputGeo(0);
00158 bgdp = inputGeo(1);
00159 a_gah = agdp->getPointAttribute(attribname);
00160 b_gah = bgdp->getPointAttribute(attribname);
00161
00162
00163 if (!a_gah.isAttributeValid() ||
00164 !b_gah.isAttributeValid())
00165 {
00166 addError(SOP_ATTRIBUTE_INVALID, (const char *) attribname);
00167 unlockInput(0);
00168 unlockInput(1);
00169 return error();
00170 }
00171
00172
00173
00174 dst_gah = gdp->getPointAttribute(resultname);
00175 if (!dst_gah.isAttributeValid())
00176 {
00177
00178
00179
00180 if (a_gah.isP())
00181 {
00182 float def[3] = { 0, 0, 0 };
00183
00184 gdp->addPointAttrib((const char *) resultname,
00185 3 * sizeof(float),
00186 GB_ATTRIB_VECTOR,
00187 GB_ATTRIB_INFO_NONE,
00188 def);
00189 }
00190 else
00191 {
00192 gdp->addPointAttrib((const char *) resultname,
00193 a_gah.getAttribute()->getSize(),
00194 a_gah.getAttribute()->getType(),
00195 a_gah.getAttribute()->getTypeInfo(),
00196 a_gah.getAttribute()->getDefault());
00197 }
00198
00199
00200 dst_gah = gdp->getPointAttribute(resultname);
00201 if (!dst_gah.isAttributeValid())
00202 {
00203 addError(SOP_ATTRIBUTE_INVALID, (const char *) resultname);
00204 unlockInput(0);
00205 unlockInput(1);
00206 return error();
00207 }
00208 }
00209
00210 int i, alen;
00211
00212
00213
00214
00215 alen = dst_gah.entries();
00216
00217
00218
00219 if (error() < UT_ERROR_ABORT && cookInputGroups(context) < UT_ERROR_ABORT)
00220 {
00221 FOR_ALL_OPT_GROUP_POINTS(gdp, myGroup, ppt)
00222 {
00223 const GEO_Point *apt, *bpt;
00224
00225
00226
00227
00228
00229 apt = agdp->points()(ppt->getNum());
00230 if (ppt->getNum() >= bgdp->points().entries())
00231 continue;
00232 bpt = bgdp->points()(ppt->getNum());
00233
00234
00235 a_gah.setElement(apt);
00236 b_gah.setElement(bpt);
00237 dst_gah.setElement(ppt);
00238
00239 for (i = 0; i < alen; i++)
00240 {
00241 dst_gah.setF( a_gah.getF(i) - b_gah.getF(i), i );
00242 }
00243 }
00244 }
00245 unlockInput(0);
00246 unlockInput(1);
00247
00248 return error();
00249 }