Open lshmouse opened 1 year ago
I think this example is good to understand and to add user defined macros or functions in cel cpp for 3D IOU prototype. example :-
// Custom function to compute 3D IOU
cel::Status Compute3DIoU(cel::CelValue* result, const std::vector
// Custom function to compute included angle of two 3D vectors
cel::Status ComputeIncludedAngle(cel::CelValue* result, const std::vector
int main() {
// Create a CEL function registry
auto registry = std::make_shared
// Register custom functions with the registry
registry->RegisterFunction("Compute3DIoU", Compute3DIoU);
registry->RegisterFunction("ComputeIncludedAngle", ComputeIncludedAngle);
// Create a CEL evaluator with custom function registry
cel::InterpreterOptions options;
options.mutable_function_registry()->Register(std::move(registry));
cel::Interpreter interpreter(options);
// Example expression with custom functions
std::string expression = "Compute3DIoU(obj1, obj2) > 0.5 && ComputeIncludedAngle(vec1, vec2) < 90";
// Evaluate the expression
cel::Activation activation;
auto status_or = interpreter.Evaluate(expression, activation);
if (status_or.ok()) {
// Handle result
} else {
// Handle error
}
return 0;
}
We use cel-cpp to write some rules for trigger the action when some condition matched. For some sophisticated rules,we need use some user-defined macros or functions, for example: compute the 3D IOU for two 3D objects(proto message), compute the included angle of two 3D vector and so on.
After search the codebase, we can not find examples about how to add user-defined macros or functions in cel-cpp.