HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
simple.C
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024
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_Main.h>
36 #include <UT/UT_Vector3.h>
37 #include <MOT/MOT_Director.h>
38 
39 namespace HDK_Sample {
40 
41 #define SIZE 32
42 
43 static void
44 initializeP(UT_Vector3 *P)
45 {
46  int i;
47  uint seed = 0;
48  for (i = 0; i < SIZE; i++)
49  P[i].assign(i/(fpreal)SIZE, SYSfastRandom(seed), 1);
50 }
51 
52 static void
53 dumpLen(const fpreal32 *len)
54 {
55  int i;
56  printf("Length = [");
57  for (i = 0; i < SIZE; i++)
58  {
59  printf("%g,", len[i]);
60  }
61  printf("]\n");
62 }
63 
64 }
65 
66 using namespace HDK_Sample;
67 
68 int
69 theMain(int argc, char *argv[])
70 {
71  CVEX_Context cvex;
72  CVEX_Value *P_val, *len_val;
73  UT_Vector3 Pbuffer[SIZE];
74  int32 seed = 1;
75  fpreal32 len[SIZE];
76 
77  cvex.addInput("P", CVEX_TYPE_VECTOR3, true); // Varying value
78  cvex.addInput("seed", CVEX_TYPE_INTEGER, &seed, 1); // Uniform value
79 
80  // Pass arguments to CVEX
81  if (!cvex.load(argc-1, argv+1))
82  return 0;
83 
84  // Check to see whether VEX function has a "vector P" parameter
85  P_val = cvex.findInput("P", CVEX_TYPE_VECTOR3);
86  if (P_val)
87  {
88  initializeP(Pbuffer); // Set the values for "P"
89  P_val->setTypedData(Pbuffer, SIZE); // "bind" the buffer to the variable
90  }
91  // Check to see whether VEX function has a "export float len" parameter
92  len_val = cvex.findOutput("len", CVEX_TYPE_FLOAT);
93  if (len_val)
94  len_val->setTypedData(len, SIZE);
95 
96  // Run the CVEX program
97  cvex.run(SIZE, false);
98 
99  if (len_val)
100  dumpLen(len);
101 
102  return 0;
103 }
int int32
Definition: SYS_Types.h:39
bool addInput(const UT_StringHolder &name, CVEX_Type type, bool varying)
auto printf(const S &fmt, const T &...args) -> int
Definition: printf.h:626
const CVEX_ValueT< PREC > * findOutput(const UT_StringRef &name, CVEX_Type type) const
Find an output by name/type.
Definition: CVEX_Context.h:340
float fpreal32
Definition: SYS_Types.h:200
A class representing a VEX value.
Definition: CVEX_Value.h:60
bool setTypedData(VEXint< PREC > *data, int array_size)
const CVEX_ValueT< PREC > * findInput(const UT_StringRef &name, CVEX_Type type) const
Find an input by name/type.
Definition: CVEX_Context.h:318
bool run(int array_size, bool interruptable, CVEX_RunDataT< PREC > *rundata=nullptr)
int theMain(int argc, char *argv[])
Definition: simple.C:69
fpreal64 fpreal
Definition: SYS_Types.h:277
#define SIZE
Definition: simple.C:41
bool load(int argc, const char *const argv[])
UT_MAIN(theMain)
Call VEX from C++.
Definition: CVEX_Context.h:203
unsigned int uint
Definition: SYS_Types.h:45