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) 2023
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 }
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:339
float fpreal32
Definition: SYS_Types.h:200
A class representing a VEX value.
Definition: CVEX_Value.h:59
bool setTypedData(VEXint< PREC > *data, int array_size)
GLenum GLsizei len
Definition: glew.h:7782
const CVEX_ValueT< PREC > * findInput(const UT_StringRef &name, CVEX_Type type) const
Find an input by name/type.
Definition: CVEX_Context.h:317
bool run(int array_size, bool interruptable, CVEX_RunDataT< PREC > *rundata=nullptr)
fpreal64 fpreal
Definition: SYS_Types.h:277
#define SIZE
Definition: simple.C:40
bool load(int argc, const char *const argv[])
Call VEX from C++.
Definition: CVEX_Context.h:203
unsigned int uint
Definition: SYS_Types.h:45
int main(int argc, char *argv[])
Definition: simple.C:68