00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Side Effects Software Inc 00008 * 123 Front Street West, Suite 1401 00009 * Toronto, Ontario 00010 * Canada M5J 2M2 00011 * 416-504-9876 00012 * 00013 * NAME: CVEX_Context.h ( CVEX Library, C++) 00014 * 00015 * COMMENTS: C++ interface to VEX. This class defines a parameter to the 00016 * VEX function. 00017 * 00018 */ 00019 00020 #ifndef __CVEX_Context__ 00021 #define __CVEX_Context__ 00022 00023 #include "CVEX_API.h" 00024 #include "CVEX_ValueList.h" 00025 00026 class cvex_RunData; 00027 class UT_OpCaller; 00028 00029 class CVEX_API CVEX_Context { 00030 public: 00031 CVEX_Context(); 00032 ~CVEX_Context(); 00033 00034 // clearing the context will allow you to set up the input and output 00035 // parameters again. load() must be called again before you can run the 00036 // VEX code. 00037 void clear(); 00038 00039 // calling reloadAllVEX() will force all CVEX object code to be flushed out 00040 // of memory and to be reloaded. Be cautioned that this may have 00041 // side-effects, and should only be called at a safe time. This will also 00042 // cause *all* functions to be cleared() (see above). 00043 static void clearAllFunctions(); 00044 00045 // 00046 // Add possible input parameters to the function. These are parameters 00047 // whose values are overridden by values you pass in. 00048 // If it's relatively expensive to compute a value, you can postpone 00049 // computation until after you know whether the value will actually be 00050 // used by the function loaded. 00051 bool addInput(const char *name, CVEX_Type type, bool varying); 00052 00053 // If you know the value beforehand, you can add the symbol and it's 00054 // value at the same time. 00055 bool addInput(const char *name, CVEX_Type type, 00056 void *data, int array_size); 00057 bool addInput(const char *name, UT_StringArray &strings); 00058 00059 // Set the evaluation time. This is what will be used by 00060 // op: references triggered by VEX commands like volumesample. 00061 // If not set, the current channel time is used instead. 00062 void setTime(float time); 00063 00064 // Load the VEX function. This is done AFTER the input parameters have 00065 // been specified. After loading, the input list will have flags set 00066 // telling you whether the input parameter is used. At this point, you 00067 // can compute data if you choose. The list of outputs will also be 00068 // defined, meaning that you can figure out what's going to be written by 00069 // the VEX function. 00070 // 00071 // If errors occured in loading they are added to the 00072 // current vex error manager (see VEX_Error.h). 00073 // 00074 // NOTE: If no error manager is set, the default behaviour is to 00075 // exit the program! 00076 bool load(int argc, char *argv[]); 00077 bool load(int argc, char *argv[], int threadid); 00078 00079 // Quick test to see if the function has been loaded. 00080 bool isLoaded() const { return myRunData != 0; } 00081 00082 // The list of input parameters to the function. It's possible that 00083 // these values may be shared between the input and output lists. 00084 CVEX_ValueList &getInputList() { return myInputs; } 00085 CVEX_Value *findInput(const char *name, CVEX_Type type) 00086 { return myInputs.getValue(name, type); } 00087 00088 // The list of output parameters from the function. After the function 00089 // has been run, the output parameters will have their values written to 00090 // by VEX. 00091 CVEX_ValueList &getOutputList() { return myOutputs; } 00092 CVEX_Value *findOutput(const char *name, CVEX_Type type) 00093 { return myOutputs.getValue(name, type); } 00094 00095 // Sets our op callback. This is used to setup dependencies on 00096 // any referenced op: expressions. Can be applied to the context 00097 // at any time. 00098 void setOpCaller(UT_OpCaller *caller); 00099 00100 // Gets and clears the VEX_Instance flags on the underlying instance. 00101 // This can only be done after the vex function has been successfully 00102 // loaded. 00103 bool getFlag(int flag) const; 00104 void clearFlag(int flag); 00105 00106 // Run the VEX function given a list of input variables and a list of 00107 // output parameters. Each input/output parameter under your control 00108 // should have an array size of either 1 or at least the array_size given 00109 // to the run() method. It's possible to run on fewer array elements 00110 // than have been allocated, but an error will be returned if there are 00111 // input parameters which don't have enough allocation. 00112 // 00113 // Pass in true for interruptable when running from within Houdini. 00114 // 00115 // The run() function may be called multiple times, provided that the 00116 // input parameters don't change. So, if you need to evaluate the data 00117 // in chunks, you can do this by re-initializing the input parameter data 00118 // between calls to run(). However, you should not change the 00119 // uniform/varying state of any input parameters without doing a re-load 00120 // of the VEX function. 00121 bool run(int array_size, bool interruptable); 00122 00123 private: 00124 bool bindData(CVEX_Value &value); 00125 void moveData(CVEX_Value &value, 00126 int start, int nproc); 00127 void extractStrings(CVEX_Value &value, 00128 int start, int nproc); 00129 void unbindData(CVEX_Value &value); 00130 00131 CVEX_ValueList myInputs; 00132 CVEX_ValueList myOutputs; 00133 cvex_RunData *myRunData; 00134 UT_OpCaller *myOpCaller; 00135 bool myTimeSpecified; 00136 fpreal myTime; 00137 }; 00138 00139 #endif
1.5.9