00001 /* 00002 * Copyright (c) 2012 00003 * Side Effects Software Inc. All rights reserved. 00004 * 00005 * Redistribution and use of Houdini Development Kit samples in source and 00006 * binary forms, with or without modification, are permitted provided that the 00007 * following conditions are met: 00008 * 1. Redistributions of source code must retain the above copyright notice, 00009 * this list of conditions and the following disclaimer. 00010 * 2. The name of Side Effects Software may not be used to endorse or 00011 * promote products derived from this software without specific prior 00012 * written permission. 00013 * 00014 * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS 00015 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00016 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00017 * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 00018 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00019 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00020 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00021 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00022 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 00023 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00024 * 00025 *---------------------------------------------------------------------------- 00026 * Sample of the CVEX interface to call VEX. 00027 * 00028 * CVEX is most efficient when operating on arrays of data. The interface 00029 * allows you to create a VEX function to perform some computation. Instead of 00030 * hard-coding the algorithm in your C++ code, you can alter the algorithm by 00031 * running different VEX code. It allows flexibility in design of your code. 00032 */ 00033 00034 #include <CVEX/CVEX_Context.h> 00035 #include <UT/UT_Vector3.h> 00036 #include <MOT/MOT_Director.h> 00037 00038 namespace HDK_Sample { 00039 00040 #define SIZE 32 00041 00042 static void 00043 initializeP(UT_Vector3 *P) 00044 { 00045 int i; 00046 uint seed = 0; 00047 for (i = 0; i < SIZE; i++) 00048 P[i].assign(i/(fpreal)SIZE, SYSfastRandom(seed), 1); 00049 } 00050 00051 static void 00052 dumpLen(const fpreal32 *len) 00053 { 00054 int i; 00055 printf("Length = ["); 00056 for (i = 0; i < SIZE; i++) 00057 { 00058 printf("%g,", len[i]); 00059 } 00060 printf("]\n"); 00061 } 00062 00063 } 00064 00065 using namespace HDK_Sample; 00066 00067 int 00068 main(int argc, char *argv[]) 00069 { 00070 CVEX_Context cvex; 00071 CVEX_Value *P_val, *len_val; 00072 UT_Vector3 Pbuffer[SIZE]; 00073 int32 seed = 1; 00074 fpreal32 len[SIZE]; 00075 00076 // Without the following function, CVEX will run in a lean-and-mean mode 00077 // without some critical functions. This function needs to be called 00078 // before any CVEX code is accessed. 00079 MOT_Director::installFullCVEX(); 00080 00081 cvex.addInput("P", CVEX_TYPE_VECTOR3, true); // Varying value 00082 cvex.addInput("seed", CVEX_TYPE_INTEGER, &seed, 1); // Uniform value 00083 00084 // Pass arguments to CVEX 00085 if (!cvex.load(argc-1, argv+1)) 00086 return 0; 00087 00088 // Check to see whether VEX function has a "vector P" parameter 00089 if (P_val = cvex.findInput("P", CVEX_TYPE_VECTOR3)) 00090 { 00091 initializeP(Pbuffer); // Set the values for "P" 00092 P_val->setData(Pbuffer, SIZE); // "bind" the buffer to the variable 00093 } 00094 // Check to see whether VEX function has a "export float len" parameter 00095 if (len_val = cvex.findOutput("len", CVEX_TYPE_FLOAT)) 00096 len_val->setData(len, SIZE); 00097 00098 // Run the CVEX program 00099 cvex.run(SIZE, false); 00100 00101 if (len_val) 00102 dumpLen(len); 00103 00104 return 0; 00105 }
1.5.9