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 <stdio.h>
00030 #include <stdlib.h>
00031 #include <unistd.h>
00032 #include <time.h>
00033 #include <math.h>
00034 #include <UT/UT_Thread.h>
00035 #include <VEX/VEX_VexOp.h>
00036
00037 namespace HDK_Sample {
00038
00039 #if !defined(WIN32)
00040 static void
00041 drand_Evaluate(int, void *argv[], void *)
00042 {
00043 float *result = (float *)argv[0];
00044 const int *seed = (const int *)argv[1];
00045
00046 srand48(*seed);
00047 *result = drand48();
00048 }
00049 #endif
00050
00051 static void
00052 time_Evaluate(int, void *argv[], void *)
00053 {
00054 int *result = (int *)argv[0];
00055
00056 *result = time(0);
00057 }
00058
00059
00060
00061 class gamma_Table {
00062 public:
00063 gamma_Table() : myRefCount(1) { }
00064 ~gamma_Table() { }
00065
00066 float evaluate(float v) { return 0; }
00067
00068 int myRefCount;
00069 };
00070
00071 static gamma_Table *theGammaTable = NULL;
00072
00073 static void *
00074 gamma_Init()
00075 {
00076
00077 if (!theGammaTable)
00078 theGammaTable = new gamma_Table();
00079 else
00080 theGammaTable->myRefCount++;
00081 return theGammaTable;
00082 }
00083
00084 static void
00085 gamma_Cleanup(void *data)
00086 {
00087 gamma_Table *table = (gamma_Table *)data;
00088
00089 UT_ASSERT(table == theGammaTable);
00090 table->myRefCount--;
00091 if (!table->myRefCount)
00092 {
00093 delete table;
00094 theGammaTable = NULL;
00095 }
00096 }
00097
00098 static void
00099 gamma_Evaluate(int, void *argv[], void *data)
00100 {
00101 float *result = (float *)argv[0];
00102 const float *value = (const float *)argv[1];
00103
00104 gamma_Table *table = (gamma_Table *)data;
00105 *result = table->evaluate(*value);
00106 }
00107 }
00108
00109
00110
00111
00112 using namespace HDK_Sample;
00113 void
00114 newVEXOp(void *)
00115 {
00116 #if !defined(WIN32)
00117
00118 new VEX_VexOp("drand@&FI",
00119 drand_Evaluate,
00120 VEX_ALL_CONTEXT,
00121 NULL,
00122 NULL);
00123 #endif
00124
00125
00126
00127 new VEX_VexOp("time@&I",
00128 time_Evaluate,
00129 VEX_ALL_CONTEXT,
00130 NULL,
00131 NULL,
00132 VEX_OPTIMIZE_1);
00133
00134
00135 new VEX_VexOp("gamma@&FF",
00136 gamma_Evaluate,
00137 VEX_ALL_CONTEXT,
00138 gamma_Init,
00139 gamma_Cleanup);
00140 }