HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
simple.C
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018
3  * Side Effects Software Inc. All rights reserved.
4  *
5  * Redistribution and use of Houdini Development Kit samples in source and
6  * binary forms, with or without modification, are permitted provided that the
7  * following conditions are met:
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. The name of Side Effects Software may not be used to endorse or
11  * promote products derived from this software without specific prior
12  * written permission.
13  *
14  * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
15  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17  * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  *----------------------------------------------------------------------------
26  * Sample of the CVEX interface to call VEX.
27  *
28  * CVEX is most efficient when operating on arrays of data. The interface
29  * allows you to create a VEX function to perform some computation. Instead of
30  * hard-coding the algorithm in your C++ code, you can alter the algorithm by
31  * running different VEX code. It allows flexibility in design of your code.
32  */
33 
34 #include <CVEX/CVEX_Context.h>
35 #include <UT/UT_Vector3.h>
36 #include <MOT/MOT_Director.h>
37 
38 namespace HDK_Sample {
39 
40 #define SIZE 32
41 
42 static void
43 initializeP(UT_Vector3 *P)
44 {
45  int i;
46  uint seed = 0;
47  for (i = 0; i < SIZE; i++)
48  P[i].assign(i/(fpreal)SIZE, SYSfastRandom(seed), 1);
49 }
50 
51 static void
52 dumpLen(const fpreal32 *len)
53 {
54  int i;
55  printf("Length = [");
56  for (i = 0; i < SIZE; i++)
57  {
58  printf("%g,", len[i]);
59  }
60  printf("]\n");
61 }
62 
63 }
64 
65 using namespace HDK_Sample;
66 
67 int
68 main(int argc, char *argv[])
69 {
70  CVEX_Context cvex;
71  CVEX_Value *P_val, *len_val;
72  UT_Vector3 Pbuffer[SIZE];
73  int32 seed = 1;
74  fpreal32 len[SIZE];
75 
76  cvex.addInput("P", CVEX_TYPE_VECTOR3, true); // Varying value
77  cvex.addInput("seed", CVEX_TYPE_INTEGER, &seed, 1); // Uniform value
78 
79  // Pass arguments to CVEX
80  if (!cvex.load(argc-1, argv+1))
81  return 0;
82 
83  // Check to see whether VEX function has a "vector P" parameter
84  P_val = cvex.findInput("P", CVEX_TYPE_VECTOR3);
85  if (P_val)
86  {
87  initializeP(Pbuffer); // Set the values for "P"
88  P_val->setTypedData(Pbuffer, SIZE); // "bind" the buffer to the variable
89  }
90  // Check to see whether VEX function has a "export float len" parameter
91  len_val = cvex.findOutput("len", CVEX_TYPE_FLOAT);
92  if (len_val)
93  len_val->setTypedData(len, SIZE);
94 
95  // Run the CVEX program
96  cvex.run(SIZE, false);
97 
98  if (len_val)
99  dumpLen(len);
100 
101  return 0;
102 }
bool setTypedData(int *data, int array_size)
bool addInput(const UT_StringHolder &name, CVEX_Type type, bool varying)
png_uint_32 i
Definition: png.h:2877
Call VEX from C++.
Definition: CVEX_Context.h:147
bool run(int array_size, bool interruptable, CVEX_RunData *rundata=nullptr)
const CVEX_Value * findOutput(const UT_StringRef &name, CVEX_Type type) const
Find an output by name/type.
Definition: CVEX_Context.h:272
int int32
Definition: SYS_Types.h:28
unsigned int uint
Definition: SYS_Types.h:33
A class representing a VEX value.
Definition: CVEX_Value.h:50
double fpreal
Definition: SYS_Types.h:263
const CVEX_Value * findInput(const UT_StringRef &name, CVEX_Type type) const
Find an input by name/type.
Definition: CVEX_Context.h:250
#define SIZE
Definition: simple.C:40
float fpreal32
Definition: SYS_Types.h:184
bool load(int argc, const char *const argv[])
int main(int argc, char *argv[])
Definition: simple.C:68