HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CVEX_Context Class Reference

Call VEX from C++. More...

#include <CVEX_Context.h>

+ Inheritance diagram for CVEX_Context:

Public Member Functions

 CVEX_Context ()
 
 ~CVEX_Context ()
 
void clear ()
 
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 (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_ValueListgetInputList ()
 
const CVEX_ValueListgetInputList () const
 
const CVEX_ValuefindInput (const UT_StringRef &name, CVEX_Type type) const
 Find an input by name/type. More...
 
CVEX_ValuefindInput (const UT_StringRef &name, CVEX_Type type)
 
const CVEX_ValuefindInput (const UT_StringRef &name) const
 Find an input by name. More...
 
CVEX_ValuefindInput (const UT_StringRef &name)
 
const CVEX_ValueListgetOutputList () const
 
CVEX_ValueListgetOutputList ()
 
const CVEX_ValuefindOutput (const UT_StringRef &name, CVEX_Type type) const
 Find an output by name/type. More...
 
CVEX_ValuefindOutput (const UT_StringRef &name, CVEX_Type type)
 
const CVEX_ValuefindOutput (const UT_StringRef &name) const
 Find and output by name. More...
 
CVEX_ValuefindOutput (const UT_StringRef &name)
 
void getParameterDefaults (const UT_StringRef &name, CVEX_Type ctype, UT_DoubleArray &values) const
 
bool run (int array_size, bool interruptable, CVEX_RunData *rundata=nullptr)
 
const char * getLastError () const
 
const UT_StringgetVexErrors () const
 
const UT_StringgetVexWarnings () const
 
void clearVexErrors ()
 } More...
 

Static Public Member Functions

static void clearAllFunctions ()
 

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

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 147 of file CVEX_Context.h.

Constructor & Destructor Documentation

CVEX_Context::CVEX_Context ( )
CVEX_Context::~CVEX_Context ( )

Member Function Documentation

bool CVEX_Context::addConstantInput ( const UT_StringHolder name,
CVEX_Type  type,
void data,
int  array_size 
)

Adds a constant input. You should still maintain the referenc,e 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.

bool CVEX_Context::addConstantInput ( const UT_StringHolder name,
CVEX_StringArray strings 
)
bool CVEX_Context::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.
bool CVEX_Context::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.

bool CVEX_Context::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.

bool CVEX_Context::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.

void CVEX_Context::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.
static void CVEX_Context::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()).
void CVEX_Context::clearVexErrors ( )

}

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

const CVEX_Value* CVEX_Context::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 250 of file CVEX_Context.h.

CVEX_Value* CVEX_Context::findInput ( const UT_StringRef name,
CVEX_Type  type 
)
inline

Definition at line 252 of file CVEX_Context.h.

const CVEX_Value* CVEX_Context::findInput ( const UT_StringRef name) const
inline

Find an input by name.

Definition at line 256 of file CVEX_Context.h.

CVEX_Value* CVEX_Context::findInput ( const UT_StringRef name)
inline

Definition at line 258 of file CVEX_Context.h.

const CVEX_Value* CVEX_Context::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 272 of file CVEX_Context.h.

CVEX_Value* CVEX_Context::findOutput ( const UT_StringRef name,
CVEX_Type  type 
)
inline

Definition at line 274 of file CVEX_Context.h.

const CVEX_Value* CVEX_Context::findOutput ( const UT_StringRef name) const
inline

Find and output by name.

Definition at line 278 of file CVEX_Context.h.

CVEX_Value* CVEX_Context::findOutput ( const UT_StringRef name)
inline

Definition at line 280 of file CVEX_Context.h.

CVEX_ValueList& CVEX_Context::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 246 of file CVEX_Context.h.

const CVEX_ValueList& CVEX_Context::getInputList ( ) const
inline

Definition at line 247 of file CVEX_Context.h.

const char* CVEX_Context::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 317 of file CVEX_Context.h.

const CVEX_ValueList& CVEX_Context::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 268 of file CVEX_Context.h.

CVEX_ValueList& CVEX_Context::getOutputList ( )
inline

Definition at line 269 of file CVEX_Context.h.

void CVEX_Context::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.

const UT_String& CVEX_Context::getVexErrors ( ) const

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

Examples:
SOP/SOP_PrimVOP.C.
const UT_String& CVEX_Context::getVexWarnings ( ) const
Examples:
SOP/SOP_PrimVOP.C.
bool CVEX_Context::hasFunction ( const UT_StringRef name) const

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

bool CVEX_Context::isLoaded ( ) const

Quick test to see if the function has been loaded.

bool CVEX_Context::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.
bool CVEX_Context::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.

bool CVEX_Context::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.

CVEX_Function CVEX_Context::preloadFunction ( UT_IStream is)

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

CVEX_Function CVEX_Context::preloadGlobalFunction ( const char *  funcname)

Loads the functin form the global function table.

bool CVEX_Context::run ( int  array_size,
bool  interruptable,
CVEX_RunData 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.
Examples:
CVEX/cvexsample.C, CVEX/simple.C, and SOP/SOP_PrimVOP.C.

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