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
00030
00031
00032
00033
00034 #include <CVEX/CVEX_Context.h>
00035 #include <UT/UT_Vector3.h>
00036 #include <UT/UT_StringArray.h>
00037 #include <MOT/MOT_Director.h>
00038
00039 namespace HDK_Sample {
00040
00041
00042 #define CV_SIZE 8
00043
00044
00045 static void
00046 fillP(UT_Vector3 *P)
00047 {
00048 int i;
00049 fpreal t;
00050 for (i = 0; i < CV_SIZE; i++)
00051 {
00052 t = (fpreal)i / (CV_SIZE-1);
00053 P[i].assign(t, SYSsin(t*M_PI), 0);
00054 }
00055 }
00056
00057 static void
00058 fillN(UT_Vector3 *N)
00059 {
00060 int i;
00061 for (i = 0; i < CV_SIZE; i++)
00062 N[i].assign(0, 1, 0);
00063 }
00064
00065 static void
00066 fillST(fpreal32 *s, fpreal32 *t)
00067 {
00068 int i;
00069 for (i = 0; i < CV_SIZE; i++)
00070 {
00071 s[i] = (fpreal)i / (CV_SIZE-1);
00072 t[i] = 1-s[i];
00073 }
00074 }
00075
00076
00077
00078
00079 static void
00080 dumpFloat(const fpreal32 *v, int n)
00081 {
00082 int i;
00083
00084 printf("%g", v[0]);
00085 for (i = 1; i < n; i++)
00086 printf(", %g", v[i]);
00087 }
00088
00089 static void
00090 dumpVector(const UT_Vector3 *v, int n)
00091 {
00092 int i;
00093 printf("{%g,%g,%g}", v[0].x(), v[0].y(), v[0].z());
00094 for (i = 1; i < n; i++)
00095 printf(", {%g,%g,%g}", v[i].x(), v[i].y(), v[i].z());
00096 }
00097
00098 static void
00099 dumpValue(CVEX_Value *value)
00100 {
00101 if (!value || !value->isExport())
00102 return;
00103 printf("%s = [", value->getName());
00104 switch (value->getType())
00105 {
00106 case CVEX_TYPE_FLOAT:
00107 dumpFloat((fpreal32 *)value->getData(), value->getArraySize());
00108 break;
00109 case CVEX_TYPE_VECTOR3:
00110 dumpVector((UT_Vector3 *)value->getData(), value->getArraySize());
00111 break;
00112 default:
00113 printf("No output supported currently\n");
00114 }
00115 printf("]\n");
00116 }
00117
00118 static void
00119 dumpValueList(const char *label, CVEX_ValueList &list)
00120 {
00121 int i;
00122 CVEX_Value *value;
00123 printf("%s:\n", label);
00124 for (i = 0; i < list.entries(); i++)
00125 {
00126 value = list.getValue(i);
00127 printf("\t%2d.", i+1);
00128 if (value->isExport())
00129 printf("export ");
00130 switch (value->getType())
00131 {
00132 case CVEX_TYPE_INTEGER: printf("int"); break;
00133 case CVEX_TYPE_FLOAT: printf("float"); break;
00134 case CVEX_TYPE_VECTOR3: printf("vector"); break;
00135 case CVEX_TYPE_VECTOR4: printf("vector4"); break;
00136 case CVEX_TYPE_MATRIX3: printf("matrix3"); break;
00137 case CVEX_TYPE_MATRIX4: printf("matrix"); break;
00138 case CVEX_TYPE_STRING: printf("string"); break;
00139 default: printf("unknown"); break;
00140 }
00141 printf(" %s[%d]\n", value->getName(), value->getArraySize());
00142 }
00143 }
00144 }
00145
00146 using namespace HDK_Sample;
00147
00148 int
00149 main(int argc, char *argv[])
00150 {
00151 CVEX_Context cvex;
00152
00153
00154
00155
00156 MOT_Director::installFullCVEX();
00157
00158
00159
00160
00161
00162 UT_Vector3 P[CV_SIZE];
00163 UT_Vector3 N[CV_SIZE];
00164 fpreal32 s[CV_SIZE], t[CV_SIZE];
00165 fpreal32 zero[CV_SIZE];
00166 int32 seed = 1;
00167 UT_StringArray map;
00168
00169
00170
00171
00172 UT_Vector3 Cf[CV_SIZE];
00173 UT_Vector3 Of[CV_SIZE];
00174
00175
00176
00177
00178
00179
00180
00181 cvex.addInput("P", CVEX_TYPE_VECTOR3, true);
00182 cvex.addInput("N", CVEX_TYPE_VECTOR3, true);
00183 cvex.addInput("s", CVEX_TYPE_FLOAT, true);
00184 cvex.addInput("t", CVEX_TYPE_FLOAT, true);
00185
00186
00187
00188
00189 map.append("Mandril.pic");
00190 memset(zero, 0, sizeof(zero));
00191
00192
00193
00194
00195 cvex.addInput("seed", CVEX_TYPE_INTEGER, &seed, 1);
00196 cvex.addInput("zero", CVEX_TYPE_FLOAT, zero, CV_SIZE);
00197 cvex.addInput("map", map);
00198
00199
00200 if (!cvex.load(argc-1, argv+1))
00201 {
00202 fprintf(stderr, "Unable to load cvex function: %s\n", argv[1]);
00203 return 1;
00204 }
00205
00206
00207
00208 dumpValueList("Input Parameters", cvex.getInputList());
00209 dumpValueList("Output Parameters", cvex.getOutputList());
00210
00211
00212
00213 CVEX_Value *Pval, *Nval, *sval, *tval;
00214 Pval = cvex.findInput("P", CVEX_TYPE_VECTOR3);
00215 Nval = cvex.findInput("N", CVEX_TYPE_VECTOR3);
00216 sval = cvex.findInput("s", CVEX_TYPE_FLOAT);
00217 tval = cvex.findInput("t", CVEX_TYPE_FLOAT);
00218
00219 if (Pval)
00220 {
00221 fillP(P);
00222 Pval->setData(P, CV_SIZE);
00223 }
00224 if (Nval)
00225 {
00226 fillN(N);
00227 Nval->setData(N, CV_SIZE);
00228 }
00229 if (sval || tval)
00230 {
00231 fillST(s, t);
00232 if (sval) sval->setData(s, CV_SIZE);
00233 if (tval) tval->setData(t, CV_SIZE);
00234 }
00235
00236
00237 CVEX_Value *CfVal, *OfVal, *sout, *tout;
00238
00239 CfVal = cvex.findOutput("Cf", CVEX_TYPE_VECTOR3);
00240 OfVal = cvex.findOutput("Of", CVEX_TYPE_VECTOR3);
00241
00242
00243
00244
00245 sout = cvex.findOutput("s", CVEX_TYPE_FLOAT);
00246 tout = cvex.findOutput("t", CVEX_TYPE_FLOAT);
00247
00248 if (!CfVal && !OfVal)
00249 fprintf(stderr, "%s doesn't seem to write to Cf or Of\n", argv[1]);
00250
00251 if (CfVal)
00252 CfVal->setData(Cf, CV_SIZE);
00253 if (OfVal)
00254 OfVal->setData(Of, CV_SIZE);
00255
00256
00257
00258
00259
00260 if (sout)
00261 sout->setData(s, CV_SIZE);
00262 if (tout)
00263 tout->setData(t, CV_SIZE);
00264
00265
00266 printf("Calling VEX ----------------------------\n\n");
00267 cvex.run(CV_SIZE, false);
00268 printf("\n\nFinished VEX ----------------------------\n");
00269
00270
00271 dumpValue(CfVal);
00272 dumpValue(OfVal);
00273 dumpValue(sout);
00274 dumpValue(tout);
00275
00276 return 0;
00277 }