wandersonp 11 Posted January 21 Hey guys the original example from VEX_Sort is not working at least in my windows machine I change the code #include <UT/UT_DSOVersion.h> #include <UT/UT_Array.h> #include <UT/UT_Vector3.h> #include <UT/UT_Vector4.h> #include <UT/UT_Matrix3.h> #include <UT/UT_Matrix4.h> #include <UT/UT_Assert.h> #include <VEX/VEX_VexOp.h> using namespace UT::Literal; namespace HDK_Sample { template <typename T> int compareValues(const T *a, const T *b) { if (*a < *b) return -1; if (*a > *b) return 1; return 0; //Direct access to pointer value is not working in compare operator //return *a > *b; } template <> int compareValues<const char *>(const char * const *a, const char * const *b) { return strcmp(*a, *b); } template <> int compareValues<UT_Vector3>(const UT_Vector3 *a, const UT_Vector3 *b) { if (a->length2() < b->length2()) return -1; if (a->length2() > b->length2()) return 1; return 0; //Direct access to pointer value is not working in compare operator //return a->length2() > b->length2(); } template <> int compareValues<UT_Vector4>(const UT_Vector4 *a, const UT_Vector4 *b) { if (a->length2() < b->length2()) return -1; if (a->length2() > b->length2()) return 1; return 0; //Direct access to pointer value is not working in compare operator //return a->length2() > b->length2(); } template <> int compareValues<UT_Matrix3>(const UT_Matrix3 *a, const UT_Matrix3 *b) { if (a->determinant() < b->determinant()) return -1; if (a->determinant() > b->determinant()) return 1; return 0; //Direct access to pointer value is not working in compare operator //return a->determinant() > b->determinant(); } template <> int compareValues<UT_Matrix4>(const UT_Matrix4 *a, const UT_Matrix4 *b) { if (a->determinant() < b->determinant()) return -1; if (a->determinant() > b->determinant()) return 1; return 0; //Direct access to pointer value is not working in compare operator //return a->determinant() > b->determinant(); } template <typename T> static void sort(int argc, void *argv[], void *) { UT_Array<T> *arr = (UT_Array<T> *)argv[0]; // This will work with all types (including strings). Since no strings // are created or destroyed by this method, it's not necessary to call // VEX_VexOp::stringAlloc() or VEX_VexOp::stringFree() to free them - // the pointers are just reordered in the array. arr->sort(compareValues<T>); } static void decimate(int argc, void *argv[], void *) { const UT_Array<const char *> &src = *(UT_Array<const char *> *)argv[1]; UT_Array<const char *> &dst = *(UT_Array<const char *> *)argv[0]; UT_ASSERT(dst.entries() == 0); for (int i = 0; i < src.entries() / 2; i++) { // Acquire a new reference to the string for storage in the // destination array. const char *str = VEX_VexOp::stringAlloc(src(i * 2)); dst.append(str); } } } // // Installation function // using namespace HDK_Sample; void newVEXOp(void *) { // Sort the array by value for scalars, length for vectors, or // determinant for matrices. new VEX_VexOp("hdksort@*[I"_sh, // Signature sort<VEXint>); // Evaluator new VEX_VexOp("hdksort@*[F"_sh, // Signature sort<VEXfloat>); // Evaluator new VEX_VexOp("hdksort@*[S"_sh, // Signature sort<const char *>); // Evaluator new VEX_VexOp("hdksort@*[V"_sh, // Signature sort<VEXvec3>); // Evaluator new VEX_VexOp("hdksort@*[P"_sh, // Signature sort<VEXvec4>); // Evaluator new VEX_VexOp("hdksort@*[3"_sh, // Signature sort<VEXmat3>); // Evaluator new VEX_VexOp("hdksort@*[4"_sh, // Signature sort<VEXmat4>); // Evaluator // Remove every second string in the source array and store the result // in the destination. new VEX_VexOp("hdkdecimate@&[S[S"_sh, // Signature decimate); // Evaluator } Share this post Link to post Share on other sites