HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CVEX_ContextT< PREC > Class Template Reference

Call VEX from C++. More...

#include <CVEX_Context.h>

+ Inheritance diagram for CVEX_ContextT< PREC >:

Public Member Functions

 CVEX_ContextT ()
 
 ~CVEX_ContextT ()
 
void clear ()
 
bool isValid () const
 
bool addInput (const UT_StringHolder &name, CVEX_Type type, bool varying)
 
bool addInput (const UT_StringHolder &name, CVEX_Type type, void *data, int array_size)
 
bool addConstantInput (const UT_StringHolder &name, CVEX_Type type, void *data, int array_size)
 
bool addConstantInput (const UT_StringHolder &name, CVEX_StringArray &strings)
 
bool addInput (const UT_StringHolder &name, CVEX_StringArray &strings)
 
bool addRequiredOutput (const UT_StringHolder &name, CVEX_Type type)
 
bool hasFunction (const UT_StringRef &name) const
 Checks if the VEX function by the given name already exists. More...
 
bool preloadFile (UT_IStream &is, const char *name, UT_String *actual_name, bool override_old)
 
CVEX_Function preloadFunction (const UT_StringHolder &snippet)
 
CVEX_Function preloadFunction (UT_IStream &is)
 
CVEX_Function preloadGlobalFunction (const char *funcname)
 Loads the functin form the global function table. More...
 
bool load (int argc, const char *const argv[])
 
bool loadFunction (CVEX_Function function, int argc, const char *const argv[])
 
bool isLoaded () const
 Quick test to see if the function has been loaded. More...
 
CVEX_ValueListT< PREC > & getInputList ()
 
const CVEX_ValueListT< PREC > & getInputList () const
 
const CVEX_ValueT< PREC > * findInput (const UT_StringRef &name, CVEX_Type type) const
 Find an input by name/type. More...
 
CVEX_ValueT< PREC > * findInput (const UT_StringRef &name, CVEX_Type type)
 
const CVEX_ValueT< PREC > * findInput (const UT_StringRef &name) const
 Find an input by name. More...
 
CVEX_ValueT< PREC > * findInput (const UT_StringRef &name)
 
const CVEX_ValueListT< PREC > & getOutputList () const
 
CVEX_ValueListT< PREC > & getOutputList ()
 
const CVEX_ValueT< PREC > * findOutput (const UT_StringRef &name, CVEX_Type type) const
 Find an output by name/type. More...
 
CVEX_ValueT< PREC > * findOutput (const UT_StringRef &name, CVEX_Type type)
 
const CVEX_ValueT< PREC > * findOutput (const UT_StringRef &name) const
 Find and output by name. More...
 
CVEX_ValueT< PREC > * findOutput (const UT_StringRef &name)
 
CVEX_ProbeResult probeOutput (const UT_StringRef &name, CVEX_Type type) const
 
void getParameterDefaults (const UT_StringRef &name, CVEX_Type ctype, UT_DoubleArray &values) const
 
bool run (int array_size, bool interruptable, CVEX_RunDataT< PREC > *rundata=nullptr)
 
const char * getLastError () const
 
const UT_StringgetVexErrors () const
 
const UT_StringgetVexWarnings () const
 
void clearVexErrors ()
 } More...
 
bool addConstantInput (const UT_StringHolder &name, UT_PackedArrayOfArrays< VEXint< PREC > > &intdata)
 Add Constant Integer 32 Arrays. More...
 

Static Public Member Functions

static void clearAllFunctions ()
 
static void clearFunction (const UT_StringRef &fn_name)
 Removes the given function from the CVEX context. More...
 

Additional Inherited Members

- Protected Member Functions inherited from UT_NonCopyableNS::UT_NonCopyable
 UT_NonCopyable ()=default
 
 ~UT_NonCopyable ()=default
 
 UT_NonCopyable (const UT_NonCopyable &)=delete
 
UT_NonCopyableoperator= (const UT_NonCopyable &)=delete
 

Detailed Description

template<VEX_Precision PREC>
class CVEX_ContextT< PREC >

Call VEX from C++.

The CVEX_Context class provides the main interface to let C++ code call VEX to perform computations. This allows users to modify algorithms by performing computations in VEX.

  • VEX automatically takes advantage of SSE
  • VEX can perform run-time optimization
Examples:
CVEX/cvexsample.C, CVEX/simple.C, SOP/SOP_PrimVOP.C, and SOP/SOP_PrimVOP.h.

Definition at line 203 of file CVEX_Context.h.

Constructor & Destructor Documentation

template<VEX_Precision PREC>
CVEX_ContextT< PREC >::CVEX_ContextT ( )
template<VEX_Precision PREC>
CVEX_ContextT< PREC >::~CVEX_ContextT ( )

Member Function Documentation

template<VEX_Precision PREC>
bool CVEX_ContextT< PREC >::addConstantInput ( const UT_StringHolder name,
CVEX_Type  type,
void data,
int  array_size 
)

Adds a constant input. You should still maintain the reference but the data may be constant folded into the assemble, so the values must be set ahead of time and possibly will not update if you change the original.

template<VEX_Precision PREC>
bool CVEX_ContextT< PREC >::addConstantInput ( const UT_StringHolder name,
CVEX_StringArray strings 
)
template<VEX_Precision PREC>
bool CVEX_ContextT< PREC >::addConstantInput ( const UT_StringHolder name,
UT_PackedArrayOfArrays< VEXint< PREC > > &  intdata 
)

Add Constant Integer 32 Arrays.

template<VEX_Precision PREC>
bool CVEX_ContextT< PREC >::addInput ( const UT_StringHolder name,
CVEX_Type  type,
bool  varying 
)

Add possible input parameters to the function. These are parameters whose values are overridden by values you pass in. If the user's VEX function has these parameters the C++ code should assign the values after calling load(), but before calling run().

Calling this version of addInput() allows you to defer computing the value of the variable until you know whether it will actually be used by the VEX function.

Examples:
CVEX/cvexsample.C, CVEX/simple.C, and SOP/SOP_PrimVOP.C.
template<VEX_Precision PREC>
bool CVEX_ContextT< PREC >::addInput ( const UT_StringHolder name,
CVEX_Type  type,
void data,
int  array_size 
)

If you know the value beforehand, you can add the symbol and it's value at the same time. Note: The data is referenced, not copied, so keep it live until after run() has been called.

template<VEX_Precision PREC>
bool CVEX_ContextT< PREC >::addInput ( const UT_StringHolder name,
CVEX_StringArray strings 
)

Add an "string <name>" input. An array length of 1 makes the variable uniform. Note: The strings are referenced, not copied, so keep it live until after run() has been called.

template<VEX_Precision PREC>
bool CVEX_ContextT< PREC >::addRequiredOutput ( const UT_StringHolder name,
CVEX_Type  type 
)

Add a required output. If no required output is specified, all exports/outputs are computed. Note: Due to the varying/uniform state of an output depending significantly on the inputs' varying/uniform state – and operations performed – then, unlike addInput, no storage can be allocated until after load. Note: If no storage is allocated, the output is still computed but the result is thrown away.

template<VEX_Precision PREC>
void CVEX_ContextT< PREC >::clear ( )

clearing the context will allow you to set up the input and output parameters again.

Note
load() must be called again before you can run the VEX code.
template<VEX_Precision PREC>
static void CVEX_ContextT< PREC >::clearAllFunctions ( )
static

calling clearAllFunctions() will force all CVEX object code to be flushed out of memory and to be reloaded. Be cautioned that this may have side-effects, and should only be called at a safe time.

Note
This will also cause all functions to be cleared (see clear()).
template<VEX_Precision PREC>
static void CVEX_ContextT< PREC >::clearFunction ( const UT_StringRef fn_name)
static

Removes the given function from the CVEX context.

template<VEX_Precision PREC>
void CVEX_ContextT< PREC >::clearVexErrors ( )

}

Clear the errors reported by getVexErrors() / getVexWarnings().

template<VEX_Precision PREC>
const CVEX_ValueT<PREC>* CVEX_ContextT< PREC >::findInput ( const UT_StringRef name,
CVEX_Type  type 
) const
inline

Find an input by name/type.

Examples:
CVEX/cvexsample.C, CVEX/simple.C, and SOP/SOP_PrimVOP.C.

Definition at line 318 of file CVEX_Context.h.

template<VEX_Precision PREC>
CVEX_ValueT<PREC>* CVEX_ContextT< PREC >::findInput ( const UT_StringRef name,
CVEX_Type  type 
)
inline

Definition at line 320 of file CVEX_Context.h.

template<VEX_Precision PREC>
const CVEX_ValueT<PREC>* CVEX_ContextT< PREC >::findInput ( const UT_StringRef name) const
inline

Find an input by name.

Definition at line 324 of file CVEX_Context.h.

template<VEX_Precision PREC>
CVEX_ValueT<PREC>* CVEX_ContextT< PREC >::findInput ( const UT_StringRef name)
inline

Definition at line 326 of file CVEX_Context.h.

template<VEX_Precision PREC>
const CVEX_ValueT<PREC>* CVEX_ContextT< PREC >::findOutput ( const UT_StringRef name,
CVEX_Type  type 
) const
inline

Find an output by name/type.

Examples:
CVEX/cvexsample.C, CVEX/simple.C, and SOP/SOP_PrimVOP.C.

Definition at line 340 of file CVEX_Context.h.

template<VEX_Precision PREC>
CVEX_ValueT<PREC>* CVEX_ContextT< PREC >::findOutput ( const UT_StringRef name,
CVEX_Type  type 
)
inline

Definition at line 342 of file CVEX_Context.h.

template<VEX_Precision PREC>
const CVEX_ValueT<PREC>* CVEX_ContextT< PREC >::findOutput ( const UT_StringRef name) const
inline

Find and output by name.

Definition at line 346 of file CVEX_Context.h.

template<VEX_Precision PREC>
CVEX_ValueT<PREC>* CVEX_ContextT< PREC >::findOutput ( const UT_StringRef name)
inline

Definition at line 348 of file CVEX_Context.h.

template<VEX_Precision PREC>
CVEX_ValueListT<PREC>& CVEX_ContextT< PREC >::getInputList ( )
inline

The list of input parameters to the function. It's possible that these values may be shared between the input and output lists.

Examples:
CVEX/cvexsample.C.

Definition at line 314 of file CVEX_Context.h.

template<VEX_Precision PREC>
const CVEX_ValueListT<PREC>& CVEX_ContextT< PREC >::getInputList ( ) const
inline

Definition at line 315 of file CVEX_Context.h.

template<VEX_Precision PREC>
const char* CVEX_ContextT< PREC >::getLastError ( ) const
inline

If load() or run() return false, this will return the error that triggered the CVEX failure. Note that this is distinct from errors

Definition at line 391 of file CVEX_Context.h.

template<VEX_Precision PREC>
const CVEX_ValueListT<PREC>& CVEX_ContextT< PREC >::getOutputList ( ) const
inline

The list of output parameters from the function. After the function has been run, the output parameters will have their values written to by VEX.

If the output has not had CVEX_Value::setData() called, then the data will have been written to internal storage and can be retrieved calling CVEX_Value::getData().

Examples:
CVEX/cvexsample.C.

Definition at line 336 of file CVEX_Context.h.

template<VEX_Precision PREC>
CVEX_ValueListT<PREC>& CVEX_ContextT< PREC >::getOutputList ( )
inline

Definition at line 337 of file CVEX_Context.h.

template<VEX_Precision PREC>
void CVEX_ContextT< PREC >::getParameterDefaults ( const UT_StringRef name,
CVEX_Type  ctype,
UT_DoubleArray values 
) const

Initializes the values array with the defaults of the given parameter. Leaves values empty if it can't find the parameter.

template<VEX_Precision PREC>
const UT_String& CVEX_ContextT< PREC >::getVexErrors ( ) const

If load() or run() failed or reported warnings, these methods will return the errors reported by VEX. {

Examples:
SOP/SOP_PrimVOP.C.
template<VEX_Precision PREC>
const UT_String& CVEX_ContextT< PREC >::getVexWarnings ( ) const
Examples:
SOP/SOP_PrimVOP.C.
template<VEX_Precision PREC>
bool CVEX_ContextT< PREC >::hasFunction ( const UT_StringRef name) const

Checks if the VEX function by the given name already exists.

template<VEX_Precision PREC>
bool CVEX_ContextT< PREC >::isLoaded ( ) const

Quick test to see if the function has been loaded.

template<VEX_Precision PREC>
bool CVEX_ContextT< PREC >::isValid ( ) const

This method will return true if the code referenced by the context has been deleted (see ()). If you've cached a CVEX_Context, then this can be used to see if it's still valid.

template<VEX_Precision PREC>
bool CVEX_ContextT< PREC >::load ( int  argc,
const char *const  argv[] 
)

Load the VEX function. Inputs must be specified before this function is called. After loading, the input list will have flags set telling you whether the input parameter is used. At this point, you should set the data for all used inputs.

The list of outputs will also be defined, meaning that you can figure out what's going to be written by the VEX function.

Examples:
CVEX/cvexsample.C, CVEX/simple.C, and SOP/SOP_PrimVOP.C.
template<VEX_Precision PREC>
bool CVEX_ContextT< PREC >::loadFunction ( CVEX_Function  function,
int  argc,
const char *const  argv[] 
)

With load function we already have pre-loaded the CVEX_Function so the argv[0] is ignored.

template<VEX_Precision PREC>
bool CVEX_ContextT< PREC >::preloadFile ( UT_IStream is,
const char *  name,
UT_String actual_name,
bool  override_old 
)

Load the definition of the VEX function. Usually VEX functions are loaded from compiled VEX code stored in files on the search path. But, callers can use this method to define a VEX function from the stream. The module name can be optionally overriden with a name argument (if it's NULL, the name in the stream is used implicitly). The final name of the module is returned in actual_name (if not NULL). If override_old is true, if the old function by that name is found, then it will be overriden and updated with the new one.

template<VEX_Precision PREC>
CVEX_Function CVEX_ContextT< PREC >::preloadFunction ( const UT_StringHolder snippet)

Loads the given file. Instead of registering the loaded function in the global function table, returns it as a CVEX_Function

template<VEX_Precision PREC>
CVEX_Function CVEX_ContextT< PREC >::preloadFunction ( UT_IStream is)
template<VEX_Precision PREC>
CVEX_Function CVEX_ContextT< PREC >::preloadGlobalFunction ( const char *  funcname)

Loads the functin form the global function table.

template<VEX_Precision PREC>
CVEX_ProbeResult CVEX_ContextT< PREC >::probeOutput ( const UT_StringRef name,
CVEX_Type  type 
) const

Query the assignment status of an output. This must be called after the code has been loaded.

template<VEX_Precision PREC>
bool CVEX_ContextT< PREC >::run ( int  array_size,
bool  interruptable,
CVEX_RunDataT< PREC > *  rundata = nullptr 
)

Run the VEX function given a list of input variables and a list of output parameters. Each input/output parameter under your control should have an array size of either 1 or at least the array_size given to the run() method. It's possible to run on fewer array elements than have been allocated, but an error will be returned if there are input parameters which don't have enough allocation.

Pass in true for interruptable when running from within Houdini.

The run() function may be called multiple times, provided that the input parameters don't change. So, if you need to evaluate the data in chunks, you can do this by re-initializing the input parameter data between calls to run(). However, you should not change the uniform/varying state of any input parameters without doing a re-load of the VEX function.

Parameters
array_sizeThe size of varying arrays. All varying arrays must be this size.
interruptableIf true, VEX will check the state of the UT_Interrupt. This should be enabled when called from within Houdini. If interruptable is false, then the user will not be able to break out of endless loops in VEX. It's better to leave it true if you are unsure.
rundataData that matches the precision PREC.
Examples:
CVEX/cvexsample.C, CVEX/simple.C, and SOP/SOP_PrimVOP.C.

The documentation for this class was generated from the following file: